Skip to content

Commit

Permalink
bugfix: get wrong partipant when participant_type is department and p…
Browse files Browse the repository at this point in the history
…articipant assigned more than one
  • Loading branch information
blackholll committed Jul 25, 2020
1 parent bc10577 commit e89cfd9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 38 deletions.
12 changes: 12 additions & 0 deletions service/account/account_base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ def get_dept_by_id(cls, dept_id: int)->tuple:
"""
return True, LoonDept.objects.filter(id=dept_id, is_deleted=False).first()

@classmethod
@auto_log
def get_dept_by_ids(cls, dept_ids: str)->tuple:
"""
get department's queryset by dept_ids
:param dept_ids:
:return:
"""
if dept_ids:
dept_id_list = dept_ids.split(',')
return True, LoonDept.objects.filter(id__in=dept_id_list, is_deleted=False).all()

@classmethod
@auto_log
def get_role_by_id(cls, role_id: int)->tuple:
Expand Down
41 changes: 19 additions & 22 deletions service/ticket/ticket_base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1991,40 +1991,37 @@ def get_ticket_state_participant_info(cls, state_id: int, ticket_id: int=0, tick
destination_participant_type_id = constant_service_ins.PARTICIPANT_TYPE_PERSONAL
destination_participant = ','.join(destination_participant_list)

elif participant_type_id == constant_service_ins.PARTICIPANT_TYPE_DEPT:
# 支持多部门
flag, destination_participant_list = account_base_service_ins.get_dept_username_list(
destination_participant)
destination_participant = ','.join(destination_participant_list)
destination_participant_type_id = constant_service_ins.PARTICIPANT_TYPE_PERSONAL
if flag is False:
return False, destination_participant_list
elif destination_participant_type_id == constant_service_ins.PARTICIPANT_TYPE_ROLE:
flag, destination_participant_list = account_base_service_ins.get_role_username_list(
int(destination_participant))
destination_participant = ','.join(destination_participant_list)
destination_participant_type_id = constant_service_ins.PARTICIPANT_TYPE_PERSONAL
if flag is False:
return False, destination_participant_list

elif participant_type_id == constant_service_ins.PARTICIPANT_TYPE_HOOK:
destination_participant = '***' # 敏感数据,不保存工单基础表中

# 参与人去重复+类型修正
if participant_type_id != constant_service_ins.PARTICIPANT_TYPE_HOOK:
if destination_participant_type_id in (constant_service_ins.PARTICIPANT_TYPE_PERSONAL, constant_service_ins.PARTICIPANT_TYPE_MULTI):
destination_participant_list_new = destination_participant.split(',')
destination_participant_list_new = list(set(destination_participant_list_new))
if len(destination_participant_list_new) > 1:
destination_participant_type_id = constant_service_ins.PARTICIPANT_TYPE_MULTI
destination_participant = ','.join(destination_participant_list_new)

if destination_participant_type_id in (
constant_service_ins.PARTICIPANT_TYPE_MULTI, constant_service_ins.PARTICIPANT_TYPE_DEPT,
constant_service_ins.PARTICIPANT_TYPE_ROLE) and state_obj.distribute_type_id in (
constant_service_ins.STATE_DISTRIBUTE_TYPE_RANDOM, constant_service_ins.STATE_DISTRIBUTE_TYPE_ALL):
# 处理人为角色,部门,或者角色都可能是为多个人,需要根据状态的分配方式计算实际的处理人
if destination_participant_type_id == constant_service_ins.PARTICIPANT_TYPE_MULTI:
destination_participant_list = destination_participant.split(',')
elif destination_participant_type_id == constant_service_ins.PARTICIPANT_TYPE_DEPT:
# 支持多部门
flag, destination_participant_list = account_base_service_ins.get_dept_username_list(
destination_participant)
if flag is False:
return False, destination_participant_list
elif destination_participant_type_id == constant_service_ins.PARTICIPANT_TYPE_ROLE:
flag, destination_participant_list = account_base_service_ins.get_role_username_list(
int(destination_participant))
if flag is False:
return False, destination_participant_list
if destination_participant_type_id == constant_service_ins.PARTICIPANT_TYPE_MULTI:
if state_obj.distribute_type_id == constant_service_ins.STATE_DISTRIBUTE_TYPE_RANDOM:
# 如果是随机处理,则随机设置处理人
destination_participant = random.sample(destination_participant_list, 1)[0]
destination_participant_type_id = constant_service_ins.PARTICIPANT_TYPE_PERSONAL
if state_obj.distribute_type_id == constant_service_ins.STATE_DISTRIBUTE_TYPE_ALL:
elif state_obj.distribute_type_id == constant_service_ins.STATE_DISTRIBUTE_TYPE_ALL:
multi_all_person_dict = {}
for destination_participant_0 in destination_participant_list:
multi_all_person_dict[destination_participant_0] = {}
Expand Down
46 changes: 30 additions & 16 deletions service/workflow/workflow_state_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,30 +243,44 @@ def get_format_participant_info(cls, participant_type_id: int, participant: str)
participant_alias = ','.join(participant_alias_list)
elif participant_type_id == constant_service_ins.PARTICIPANT_TYPE_DEPT:
participant_type_name = '部门'
flag, dept_obj = account_base_service_ins.get_dept_by_id(int(participant))
# 支持多部门
flag, dept_queryset = account_base_service_ins.get_dept_by_ids(participant)
dept_info_dict = {}
for dept0 in dept_queryset:
dept_info_dict[str(dept0.id)] = dept0.name
participant_split_id_str_list = participant.split(',')

if flag is False:
return False, dept_obj
if dept_obj:
participant_name = dept_obj.name
participant_alias = participant_name
else:
participant_name = 'dept_id:{}'.format(participant)
participant_alias = ''
participant_dept_info_list = []
for participant_split_id_str in participant_split_id_str_list:
if dept_info_dict.get(participant_split_id_str):
participant_dept_info_list.append(dept_info_dict.get(participant_split_id_str))
else:
participant_dept_info_list.append('未知')

participant_alias = ','.join(participant_dept_info_list)

elif participant_type_id == constant_service_ins.PARTICIPANT_TYPE_ROLE:
participant_type_name = '角色'
flag, role_obj = account_base_service_ins.get_role_by_id(int(participant))
if flag is False or (not role_obj):
return False, 'role is not existedor has been deleted'
participant_name = role_obj.name
participant_alias = participant_name
participant_alias = '未知'
else:
participant_alias = role_obj.name
elif participant_type_id == constant_service_ins.PARTICIPANT_TYPE_VARIABLE:
participant_type_name = '变量'
if participant_name == 'creator':
participant_alias = '工单创建人'
elif participant_name == 'creator_tl':
participant_alias = '工单创建人的tl'
# 支持多变量的展示
participant_name_list = participant_name.split(',')
participant_name_alias_list = []
for participant_name0 in participant_name_list:
if participant_name0 == 'creator':
participant_name_alias_list.append('工单创建人')
elif participant_name0 == 'creator_tl':
participant_name_alias_list.append('工单创建人tl')
else:
participant_name_alias_list.append('未知')
participant_alias = ','.join(participant_name_alias_list)


elif participant_type_id == constant_service_ins.PARTICIPANT_TYPE_ROBOT:
if participant:
flag, result = workflow_run_script_service_ins.get_run_script_by_id(int(participant))
Expand Down

0 comments on commit e89cfd9

Please sign in to comment.