def get(self, request, *args, **kwargs): """ 获取工作流自定义字段列表 :param request: :param args: :param kwargs: :return: """ request_data = request.GET # username = request_data.get('username', '') # 后续会根据username做必要的权限控制 username = request.META.get('HTTP_USERNAME') if not username: username = request.user.username search_value = request_data.get('search_value', '') per_page = int(request_data.get('per_page', 10)) if request_data.get( 'per_page', 10) else 10 page = int(request_data.get('page', 1)) if request_data.get('page', 1) else 1 if not username: return api_response(-1, '请提供username', '') result, msg = WorkflowCustomFieldService.get_workflow_custom_field_list( kwargs.get('workflow_id'), search_value, page, per_page) if result is not False: data = dict(value=result, per_page=msg['per_page'], page=msg['page'], total=msg['total']) code, msg, = 0, '' else: code, data = -1, '' return api_response(code, msg, data)
def get_workflow_init_state(cls, workflow_id): """ 获取工作的初始状态信息,包括允许的transition :param workflow_id: :return: """ init_state_obj = State.objects.filter(workflow_id=workflow_id, is_deleted=False, type_id=CONSTANT_SERVICE.STATE_TYPE_START).first() if not init_state_obj: return False, '该工作流尚未配置初始状态' transition_queryset, msg = WorkflowTransitionService.get_state_transition_queryset(init_state_obj.id) transition_info_list = [] for transition in transition_queryset: transition_info_list.append(dict(transition_id=transition.id, transition_name=transition.name)) # 工单基础字段及属性 field_list = [] field_list.append(dict(field_key='title', field_name=u'标题', field_value=None, order_id=20, field_type_id=CONSTANT_SERVICE.FIELD_TYPE_STR, field_attribute=CONSTANT_SERVICE.FIELD_ATTRIBUTE_RO, description='工单的标题', field_choice={}, boolean_field_display={}, default_value=None, field_template='', label={})) custom_field_dict, msg = WorkflowCustomFieldService.get_workflow_custom_field(workflow_id) for key, value in custom_field_dict.items(): field_list.append(dict(field_key=key, field_name=custom_field_dict[key]['field_name'], field_value=None, order_id=custom_field_dict[key]['order_id'], field_type_id=custom_field_dict[key]['field_type_id'], field_attribute=CONSTANT_SERVICE.FIELD_ATTRIBUTE_RO, default_value=custom_field_dict[key]['default_value'], description=custom_field_dict[key]['description'], field_template=custom_field_dict[key]['field_template'], boolean_field_display=json.loads(custom_field_dict[key]['boolean_field_display']) if custom_field_dict[key]['boolean_field_display'] else {}, # 之前model允许为空了,为了兼容先这么写, field_choice=json.loads(custom_field_dict[key]['field_choice']), label=json.loads(custom_field_dict[key]['label']) )) state_field_dict = json.loads(init_state_obj.state_field_str) state_field_key_list = state_field_dict.keys() new_field_list = [] for field0 in field_list: if field0['field_key'] in state_field_key_list: field0['field_attribute'] = state_field_dict[field0['field_key']] new_field_list.append(field0) # 字段排序 new_field_list = sorted(new_field_list, key=lambda r: r['order_id']) state_info_dict = dict(id=init_state_obj.id, name=init_state_obj.name, workflow_id=init_state_obj.workflow_id, sub_workflow_id=init_state_obj.sub_workflow_id, distribute_type_id=init_state_obj.distribute_type_id, is_hidden=init_state_obj.is_hidden, order_id=init_state_obj.order_id, type_id=init_state_obj.type_id, participant_type_id=init_state_obj.participant_type_id, participant=init_state_obj.participant, field_list=new_field_list, label=json.loads(init_state_obj.label), creator=init_state_obj.creator, gmt_created=str(init_state_obj.gmt_created)[:19], transition=transition_info_list ) return state_info_dict, ''
def patch(self, request, *args, **kwargs): """ 更新自定义字段 :param request: :param args: :param kwargs: :return: """ custom_field_id = kwargs.get('custom_field_id') app_name = request.META.get('HTTP_APPNAME') username = request.META.get('HTTP_USERNAME') workflow_id = kwargs.get('workflow_id') # 判断是否有工作流的权限 from service.account.account_base_service import AccountBaseService app_permission, msg = AccountBaseService.app_workflow_permission_check( app_name, workflow_id) if not app_permission: return api_response( -1, 'APP:{} have no permission to get this workflow info'.format( app_name), '') json_str = request.body.decode('utf-8') if not json_str: return api_response(-1, 'post参数为空', {}) request_data_dict = json.loads(json_str) field_key = request_data_dict.get('field_key', '') field_name = request_data_dict.get('field_name', '') field_type_id = request_data_dict.get('field_type_id', '') order_id = int(request_data_dict.get('order_id', 0)) label = request_data_dict.get('label', '') description = request_data_dict.get('description', '') field_template = request_data_dict.get('field_template', '') default_value = request_data_dict.get('default_value', '') boolean_field_display = request_data_dict.get('boolean_field_display', '') field_choice = request_data_dict.get('field_choice', '') result, msg = WorkflowCustomFieldService.edit_record( custom_field_id, workflow_id, field_type_id, field_key, field_name, order_id, default_value, description, field_template, boolean_field_display, field_choice, label, username) if result is not False: data = dict(value={'custom_field_id': result}) code, msg, = 0, '' else: code, data = -1, '' return api_response(code, msg, data)
def delete(self, request, *args, **kwargs): """删除记录""" app_name = request.META.get('HTTP_APPNAME') username = request.META.get('HTTP_USERNAME') workflow_id = kwargs.get('workflow_id') custom_field_id = kwargs.get('custom_field_id') # 判断是否有工作流的权限 from service.account.account_base_service import AccountBaseService app_permission, msg = AccountBaseService.app_workflow_permission_check( app_name, workflow_id) if not app_permission: return api_response( -1, 'APP:{} have no permission to get this workflow info'.format( app_name), '') result, msg = WorkflowCustomFieldService.delete_record(custom_field_id) if result is not False: data = dict(value={'custom_field_id': result}) code, msg, = 0, '' else: code, data = -1, '' return api_response(code, msg, data)