def describe_ticket_select(ticket_type): resp = [] for key, value in TICKET_SELECT_ITEM.items(): if key == 'app_system': value = [] from console.finance.cmdb.helper import list_items payload = {'type': 'sys'} cmdb_resp = list_items(payload) for single_resp in cmdb_resp['ret_set']: value.append(single_resp.get('name')) elif key == 'cur_node': value = [] node_list = FlowNodeModel.get_all_node_by_ticket_type(ticket_type) lenth = len(node_list) for node in node_list[1:lenth - 1]: value.append(node.name) resp.append({key: value}) return resp
def init_node(sql_type): try: user = Account.objects.get(id=1) for this_node in NODE_STATUS: node = FlowNodeModel.create_flow_node( ticket_type=this_node['ticket_type'], name=this_node['name'], combination=this_node['combination'], status=this_node['status'], com_type='id', is_fallback=this_node['is_fallback']) ticket_name = TicketTypeModel.objects.get( ticket_type=this_node['ticket_type']).ticket_name if node is None: return False resp = PermissionService.create_ticket_node_permission( user, node.node_id, ticket_name + '->' + node.name) if resp is False: print 'create node permission error!' return False return True except Exception as exp: print exp return False
def describe_ticket_create_node(ticket_type): node_id = FlowNodeModel.get_create_node_by_type(ticket_type).node_id return [{'node_id': node_id}]
def get_bpm_second_node(): create_node = FlowNodeModel.get_create_node_by_type(BPM_TYPE) cur_edge = FlowEdgeModel.get_edge_by_start_node(create_node).first() return cur_edge.end_node.node_id
def get_bpm_create_node(): return FlowNodeModel.get_create_node_by_type(BPM_TYPE).node_id
def get_monitor_second_node(): create_node = FlowNodeModel.get_create_node_by_type(MONITOR_TYPE) cur_edge = FlowEdgeModel.get_edge_by_start_node(create_node).first() return cur_edge.end_node.node_id
def get_monitor_create_node(): return FlowNodeModel.get_create_node_by_type(MONITOR_TYPE).node_id
def get_cmdb_create_node(): return FlowNodeModel.get_create_node_by_type(CMDB_TYPE).node_id
def describe_ticket_process(owner, ticket_id, ticket_type, zone): ticket = None if ticket_id is not None: ticket = FinanceTicketModel.get_ticket_by_id(ticket_id) record_model = TicketRecordModel flow_instance = FlowEngine(ticket=ticket, ticket_type=ticket_type, record_model=record_model) node_list = flow_instance.get_node_fill_info() if ticket is None: node_id = FlowNodeModel.get_create_node_by_type(ticket_type).node_id else: node_id = ticket.cur_node.node_id user = Account.objects.get(user__username=owner) for node in node_list: if 'operation_usr_info' not in node: continue usr_info = node.get('operation_usr_info') this_user_id = usr_info.pop('user_id') this_user = Account.objects.get(user__username=this_user_id) usr_info.update({ "name": this_user.name, "worker_num": this_user.worker_id, "phone": this_user.phone, "department": getattr(this_user.department, 'name', None) }) operation_time = usr_info.get('operation_time') usr_info.update( {"operation_time": datetime_to_timestamp(operation_time)}) if UserPermissionService.check_node_permissions(user, [node_id], False)[0] is False: node_list.pop() else: # 这里用来增加一些需要其他接口提供数据的字段 need_fill_node = node_list[-1] for single_unit in need_fill_node['node_combination']: if single_unit['unit_name'] == u'所属应用系统' or single_unit[ 'unit_name'] == u'影响应用系统': payload = {'type': 'sys'} from console.finance.cmdb.helper import list_items resp = list_items(payload) for single_resp in resp['ret_set']: single_unit['unit_choice_list'].append( single_resp.get('name')) break elif single_unit['unit_name'] == u'配置文件内容': create_node_info = node_list[0] system_name = '' for create_unit in create_node_info['node_data']: if create_unit['unit_name'] == u'所属应用系统': system_name = create_unit['unit_fill_value'] break if system_name: from console.finance.cmdb.helper import get_application_by_name application = get_application_by_name(system_name) single_unit['unit_fill_value'] = application['cfg'] else: single_unit['unit_fill_value'] = None break return node_list