from apps.system.models import User from apps.wf.models import State, Ticket, TicketFlow, Transition from apps.wpm.models import WProduct class GetParticipants: all_funcs = [ {'func':'get_create_by', 'name':'获取工单创建人'} ] # def all_funcs(self): # # return list(filter(lambda x: x.startswith('get_') and callable(getattr(self, x)), dir(self))) # return [(func, getattr(self, func).__doc__) for func in dir(self) if callable(getattr(self, func)) and func.startswith('get_')] @classmethod def get_create_by(cls, state:dict={}, ticket:dict={}, new_ticket_data:dict={}, handler:User={}): """工单创建人""" participant = ticket.create_by.id return participant class HandleScripts: all_funcs = [ {'func': 'handle_wproduct', 'name':'处理不合格品'} ] @classmethod def to_next(cls, ticket:Ticket, by_timer:bool=False, by_task:bool=False, by_hook:bool=False, script_str:str=''): # 获取信息 transition_obj = Transition.objects.filter(source_state=ticket.state, is_deleted=False).first() TicketFlow.objects.create(ticket=ticket, state=ticket.state, participant_type=State.PARTICIPANT_TYPE_ROBOT, participant_str='func:{}'.format(script_str), transition=transition_obj) from .services import WfService # 自动执行流转 WfService.handle_ticket(ticket=ticket, transition=transition_obj, new_ticket_data=ticket.ticket_data, by_task=True) return ticket @classmethod def handle_wproduct(cls, ticket:Ticket): """处理不合格品""" # 任务处理 ticket_data = ticket.ticket_data wt = ticket.wt_ticket wp = wt.wproduct if 'shenli2' in ticket_data and ticket_data['shenli2']: wt.decision = ticket_data['shenli2'] if ticket_data['shenli2'] in ['返工', '返修']: pass elif ticket_data['shenli2'] in ['让步接收']: wp.act_state = WProduct.WPR_ACT_STATE_OK elif 'shenli1' in ticket_data and ticket_data['shenli1']: wp.decision = ticket_data['shenli1'] if ticket_data['shenli1'] in ['返工', '返修']: pass elif ticket_data['shenli1'] in ['让步接收']: wp.act_state = WProduct.WPR_ACT_STATE_OK wt.save() wp.save() # 调用自动流转 ticket = cls.to_next(ticket=ticket, by_task=True, script_str= 'handle_wproduct') if ticket.act_state == Ticket.TICKET_ACT_STATE_FINISH: # 如果工单完成 wp.ticket = None wp.save()