From d85f52454c9e9e62991a388bd92bf6e94ddde372 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 27 Aug 2021 17:17:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=B8=85=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0009_ticketflow_participant_type.py | 18 ++++++++++++++++++ hb_server/apps/wf/models.py | 1 + hb_server/apps/wf/services.py | 11 +++++------ hb_server/apps/wf/views.py | 4 ++-- 4 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 hb_server/apps/wf/migrations/0009_ticketflow_participant_type.py diff --git a/hb_server/apps/wf/migrations/0009_ticketflow_participant_type.py b/hb_server/apps/wf/migrations/0009_ticketflow_participant_type.py new file mode 100644 index 0000000..62b04be --- /dev/null +++ b/hb_server/apps/wf/migrations/0009_ticketflow_participant_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.6 on 2021-08-27 09:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wf', '0008_auto_20210827_1104'), + ] + + operations = [ + migrations.AddField( + model_name='ticketflow', + name='participant_type', + field=models.IntegerField(choices=[(0, '无处理人'), (1, '个人'), (2, '多人'), (3, '部门'), (4, '角色'), (5, '变量'), (6, '脚本'), (7, '工单的字段'), (8, '父工单的字段')], default=0, help_text='0.无处理人,1.个人,2.多人', verbose_name='处理人类型'), + ), + ] diff --git a/hb_server/apps/wf/models.py b/hb_server/apps/wf/models.py index 7c5e313..2591a75 100644 --- a/hb_server/apps/wf/models.py +++ b/hb_server/apps/wf/models.py @@ -168,6 +168,7 @@ class TicketFlow(BaseModel): ticket = models.ForeignKey(Ticket, on_delete=models.CASCADE, verbose_name='关联工单') transition = models.ForeignKey(Transition, verbose_name='流转id', help_text='与worklow.Transition关联, 为0时表示认为干预的操作', on_delete=models.CASCADE) suggestion = models.CharField('处理意见', max_length=10000, default='', blank=True) + participant_type = models.IntegerField('处理人类型', default=0, help_text='0.无处理人,1.个人,2.多人', choices=State.type2_choices) participant = models.ForeignKey(User, verbose_name='处理人', on_delete=models.SET_NULL, null=True, blank=True) state = models.ForeignKey(State, verbose_name='当前状态', default=0, blank=True, on_delete=models.CASCADE) ticket_data = models.JSONField('工单数据', default=dict, blank=True, help_text='可以用于记录当前表单数据,json格式') \ No newline at end of file diff --git a/hb_server/apps/wf/services.py b/hb_server/apps/wf/services.py index 1fd04dc..2569772 100644 --- a/hb_server/apps/wf/services.py +++ b/hb_server/apps/wf/services.py @@ -121,18 +121,17 @@ class WfService(object): 到达结束状态 """ return dict(destination_participant_type=State.PARTICIPANT_TYPE_PERSONAL, - destination_participant=None, + destination_participant=0, multi_all_person={}) multi_all_person_dict = {} - destination_participant_type, destination_participant = State.participant_type, State.participant - + destination_participant_type, destination_participant = state.participant_type, state.participant if destination_participant_type == State.PARTICIPANT_TYPE_FIELD: destination_participant = ticket_data.get(destination_participant, None) if destination_participant in ticket_data else Ticket.ticket_data.get(destination_participant, None) - if destination_participant_type == State.PARTICIPANT_TYPE_DEPT:#单部门 + elif destination_participant_type == State.PARTICIPANT_TYPE_DEPT:#单部门 destination_participant = list(User.objects.filter(dept=destination_participant).values_list('id', flat=True)) - if destination_participant_type == State.PARTICIPANT_TYPE_ROLE:#单角色 + elif destination_participant_type == State.PARTICIPANT_TYPE_ROLE:#单角色 destination_participant = list(User.objects.filter(roles=destination_participant).values_list('id', flat=True)) if type(destination_participant) == list: @@ -140,13 +139,13 @@ class WfService(object): destination_participant = list(set(destination_participant)) else: destination_participant_type = State.PARTICIPANT_TYPE_PERSONAL - if destination_participant_type == State.PARTICIPANT_TYPE_MULTI: if state.distribute_type == State.STATE_DISTRIBUTE_TYPE_RANDOM: destination_participant = random.choice(destination_participant) elif state.distribute_type == State.STATE_DISTRIBUTE_TYPE_ALL: for i in destination_participant: multi_all_person_dict[i]={} + return dict(destination_participant_type=destination_participant_type, destination_participant=destination_participant, multi_all_person=multi_all_person_dict) diff --git a/hb_server/apps/wf/views.py b/hb_server/apps/wf/views.py index d629edc..c2afc1f 100644 --- a/hb_server/apps/wf/views.py +++ b/hb_server/apps/wf/views.py @@ -145,8 +145,8 @@ class TicketViewSet(OptimizationMixin, CreateUpdateCustomMixin, CreateModelMixin # 新增流转记录 TicketFlow.objects.create(ticket=ticket, state=start_state, ticket_data=ticket_data, suggestion=rdata.get('suggestion',''), participant_type=State.PARTICIPANT_TYPE_PERSONAL, - particant=ticket.create_by) - return Response(serializer.data) + participant=ticket.create_by, transition=transition) + return Response(TicketSerializer(instance=ticket).data) @action(methods=['get'], detail=True, perms_map={'get':'*'})