def _update(self, session, ins):
        subject_id = self.request.params.get('subject_id')
        flag = self.request.params.get('flag')
        exist = session.execute('select stock_change_type_id from stock_changes where stock_change_type_id=:id and status=6 limit 1', {"id": ins.id}).fetchone()
        # 此类写法允许更新时忽略传递subject_id, flag
        if subject_id is not None:
            if int(subject_id) != ins.subject_id and exist:
                raise Exception(u'该库存变动类型已经被使用,不能修改科目')
        if flag is not None:
            if int(flag) != ins.flag and exist:
                raise Exception(u'该库存变动类型已经被使用,不能修改方向')
        super(StockChangeTypeService, self)._update(session, ins)
        if not ins.subject_id:
            raise Exception(u'必须提供科目')

        subject_id_valid_check(self, session, session.query(Subject).get(ins.subject_id))
    def _create(self, session, ins):
        super(StockChangeTypeService, self)._create(session, ins)
        if not ins.subject_id:
            raise Exception(u'必须提供科目')

        subject_id_valid_check(self, session, session.query(Subject).get(ins.subject_id))