def patch(self, request, *args, **kwargs): """ 更新部门 :param request: :param args: :param kwargs: :return: """ dept_id = kwargs.get('dept_id') json_str = request.body.decode('utf-8') request_data_dict = json.loads(json_str) name = request_data_dict.get('name') parent_dept_id = request_data_dict.get('parent_dept_id') leader_id = request_data_dict.get('leader') approver = request_data_dict.get('approver') if approver: approver_list = approver.split(',') approver_id_list = [ int(approver_str) for approver_str in approver_list ] else: approver_id_list = [] label = request_data_dict.get('label') if leader_id: ok, result = account_base_service_ins.get_user_by_user_id( int(leader_id)) if not ok: return api_response(-1, result, {}) leader = result.username else: leader = None if approver_id_list: flag, result = account_base_service_ins.get_user_name_list_by_id_list( approver_id_list) if flag is False: return api_response(-1, result, {}) approver_username_list = result.get('username_list') approver_username_str = ','.join(approver_username_list) else: approver_username_str = '' flag, result = account_base_service_ins.update_dept( dept_id, name, parent_dept_id, leader, approver_username_str, label) if flag is False: return api_response(-1, result, {}) return api_response(0, '', {})
def patch(self, request, *args, **kwargs): """ 更新部门 :param request: :param args: :param kwargs: :return: """ dept_id = kwargs.get('dept_id') json_str = request.body.decode('utf-8') request_data_dict = json.loads(json_str) name = request_data_dict.get('name') parent_dept_id = request_data_dict.get('parent_dept_id') leader = request_data_dict.get('leader') approver = request_data_dict.get('approver') label = request_data_dict.get('label') flag, result = account_base_service_ins.update_dept( dept_id, name, parent_dept_id, leader, approver, label) if flag is False: return api_response(-1, result, {}) return api_response(0, '', {})