@@ -39,39 +39,52 @@ def exist_unfinished(self):
3939 def get_operators (self , todo_type , ticket , operators ):
4040 # 获得提单人,dba,业务协助人. TODO: 后续还会细分主、备、二线DBA,以及明确区分协助人角色
4141 creator = [ticket .creator ]
42- dba = DBAdministrator .get_biz_db_type_admins (ticket .bk_biz_id , ticket .group )
42+ # dba = DBAdministrator.get_biz_db_type_admins(ticket.bk_biz_id, ticket.group)
43+ dba , second_dba , other_dba = DBAdministrator .get_dba_for_db_type (ticket .bk_biz_id , ticket .group )
4344 biz_helpers = BizSettings .get_assistance (ticket .bk_biz_id )
4445
4546 # 构造单据状态与处理人之间的对应关系
4647 # - 审批中:提单人可撤销,dba可处理,
4748 # 考虑某些单据审批人是特定配置(数据导出 -- 运维审批),所以从ItsmBuilder获得审批人
48- # - 待执行:提单人 + 单据协助人
49- # - 待继续:dba + 提单人 + 单据协助人
50- # - 待补货:dba + 提单人 + 单据协助人
51- # - 已失败:dba + 提单人 + 单据协助人
49+ # - 待执行:operators[ 提单人] + helpers[ 单据协助人]
50+ # - 待继续:operators[提单人 + dba] + helpers[ 单据协助人 + second_dba + other_dba]
51+ # - 待补货:operators[提单人 + dba] + helpers[ 单据协助人 + second_dba + other_dba]
52+ # - 已失败:operators[提单人 + dba] + helpers[ 单据协助人 + second_dba + other_dba]
5253 itsm_builder = BuilderFactory .get_builder_cls (ticket .ticket_type ).itsm_flow_builder (ticket )
54+ itsm_operators = itsm_builder .get_approvers ().split ("," )
5355 todo_operators_map = {
54- TodoType .ITSM : itsm_builder .get_approvers ().split ("," ),
55- TodoType .APPROVE : creator + biz_helpers ,
56- TodoType .INNER_APPROVE : dba + creator + biz_helpers ,
57- TodoType .RESOURCE_REPLENISH : dba + creator + biz_helpers ,
58- TodoType .INNER_FAILED : dba + creator + biz_helpers ,
56+ TodoType .ITSM : itsm_operators [:1 ],
57+ TodoType .APPROVE : creator ,
58+ TodoType .INNER_APPROVE : creator + dba ,
59+ TodoType .RESOURCE_REPLENISH : creator + dba ,
60+ TodoType .INNER_FAILED : creator + dba ,
61+ }
62+ todo_helpers_map = {
63+ TodoType .ITSM : itsm_operators [1 :],
64+ TodoType .APPROVE : biz_helpers ,
65+ TodoType .INNER_APPROVE : biz_helpers + second_dba + other_dba ,
66+ TodoType .RESOURCE_REPLENISH : biz_helpers + second_dba + other_dba ,
67+ TodoType .INNER_FAILED : biz_helpers + second_dba + other_dba ,
5968 }
6069 # 按照顺序去重
6170 operators = list (dict .fromkeys (operators + todo_operators_map .get (todo_type , [])))
62- return operators
71+ helpers = [item for item in todo_helpers_map .get (todo_type , []) if item not in operators ]
72+ return creator , biz_helpers , helpers , operators
6373
6474 def create (self , ** kwargs ):
65- operators = self .get_operators (kwargs ["type" ], kwargs ["ticket" ], kwargs .get ("operators" , []))
75+ creator , biz_helpers , helpers , operators = self .get_operators (
76+ kwargs ["type" ], kwargs ["ticket" ], kwargs .get ("operators" , [])
77+ )
6678 kwargs ["operators" ] = operators
79+ kwargs ["helpers" ] = helpers
6780 todo = super ().create (** kwargs )
6881 send_msg_for_flow .apply_async (
6982 kwargs = {
7083 "flow_id" : todo .flow .id ,
7184 "flow_msg_type" : FlowMsgType .TODO .value ,
7285 "flow_status" : FlowMsgStatus .UNCONFIRMED .value ,
73- "processor" : "," .join (todo .operators ),
74- "receiver" : todo . creator ,
86+ "processor" : "," .join (todo .operators + todo . helpers ),
87+ "receiver" : "," . join ( creator + biz_helpers ) ,
7588 }
7689 )
7790 return todo
@@ -86,6 +99,7 @@ class Todo(AuditedModel):
8699 flow = models .ForeignKey ("Flow" , help_text = _ ("关联流程任务" ), related_name = "todo_of_flow" , on_delete = models .CASCADE )
87100 ticket = models .ForeignKey ("Ticket" , help_text = _ ("关联工单" ), related_name = "todo_of_ticket" , on_delete = models .CASCADE )
88101 operators = models .JSONField (_ ("待办人" ), default = list )
102+ helpers = models .JSONField (_ ("协助人" ), default = list )
89103 type = models .CharField (
90104 _ ("待办类型" ),
91105 choices = TodoType .get_choices (),
0 commit comments