public async Task <ResponseMessage <HumanPositionResponse> > UpdateAsync(UserInfo user, string id, HumanPositionRequest humanPositionRequest, CancellationToken cancellationToken = default(CancellationToken)) { ResponseMessage <HumanPositionResponse> response = new ResponseMessage <HumanPositionResponse>(); if (user == null) { throw new ArgumentNullException(nameof(user)); } if (humanPositionRequest == null) { throw new ArgumentNullException(nameof(humanPositionRequest)); } var org = await _permissionExpansionManager.GetOrganizationOfPermission(user.Id, "HumanPosition"); if (org == null || org.Count == 0 || !org.Contains(humanPositionRequest.DepartmentId)) { response.Code = ResponseCodeDefines.NotAllow; response.Message = "没有权限"; return(response); } var humanPosition = _mapper.Map <HumanPosition>(humanPositionRequest); humanPosition.Id = id; response.Extension = _mapper.Map <HumanPositionResponse>(await Store.UpdateAsync(user, humanPosition, cancellationToken)); return(response); }
public async Task <ResponseMessage <HumanPositionResponse> > CreateAsync(UserInfo user, HumanPositionRequest humanPositionRequest, CancellationToken cancellationToken = default(CancellationToken)) { ResponseMessage <HumanPositionResponse> response = new ResponseMessage <HumanPositionResponse>(); if (user == null) { throw new ArgumentNullException(nameof(user)); } if (humanPositionRequest == null) { throw new ArgumentNullException(nameof(humanPositionRequest)); } var org = await _permissionExpansionManager.GetOrganizationOfPermission(user.Id, "HumanPosition"); if (org == null || org.Count == 0 || !org.Contains(humanPositionRequest.DepartmentId)) { response.Code = ResponseCodeDefines.NotAllow; response.Message = "没有权限"; return(response); } if (string.IsNullOrEmpty(humanPositionRequest.Id)) { humanPositionRequest.Id = Guid.NewGuid().ToString(); } var gatwayurl = ApplicationContext.Current.AppGatewayUrl.EndsWith("/") ? ApplicationContext.Current.AppGatewayUrl.TrimEnd('/') : ApplicationContext.Current.AppGatewayUrl; GatewayInterface.Dto.ExamineSubmitRequest examineSubmitRequest = new GatewayInterface.Dto.ExamineSubmitRequest(); examineSubmitRequest.ContentId = humanPositionRequest.Id; examineSubmitRequest.ContentType = "HumanPosition"; examineSubmitRequest.ContentName = humanPositionRequest.Name; examineSubmitRequest.Content = "新增职位信息"; examineSubmitRequest.Source = user.FilialeName; examineSubmitRequest.SubmitDefineId = humanPositionRequest.Id; examineSubmitRequest.CallbackUrl = gatwayurl + "/api/humanposition/humanpositioncallback"; examineSubmitRequest.StepCallbackUrl = gatwayurl + "/api/humanposition/humanpositionstepcallback"; examineSubmitRequest.Action = "HumanPosition"; examineSubmitRequest.TaskName = $"新增职位信息:{humanPositionRequest.Name}"; examineSubmitRequest.Desc = $"新增职位信息"; GatewayInterface.Dto.UserInfo userInfo = new GatewayInterface.Dto.UserInfo() { Id = user.Id, KeyWord = user.KeyWord, OrganizationId = user.OrganizationId, OrganizationName = user.OrganizationName, UserName = user.UserName }; examineSubmitRequest.UserInfo = userInfo; string tokenUrl = $"{ApplicationContext.Current.AuthUrl}/connect/token"; string examineCenterUrl = $"{ApplicationContext.Current.ExamineCenterUrl}"; Logger.Info($"新增员工人事调动信息提交审核,\r\ntokenUrl:{tokenUrl ?? ""},\r\nexamineCenterUrl:{examineCenterUrl ?? ""},\r\nexamineSubmitRequest:" + (examineSubmitRequest != null ? JsonHelper.ToJson(examineSubmitRequest) : "")); var tokenManager = new TokenManager(tokenUrl, ApplicationContext.Current.ClientID, ApplicationContext.Current.ClientSecret); var response2 = await tokenManager.Execute(async (token) => { return(await _restClient.PostWithToken <ResponseMessage>(examineCenterUrl, examineSubmitRequest, token)); }); if (response2.Code != ResponseCodeDefines.SuccessCode) { response.Code = ResponseCodeDefines.ServiceError; response.Message = "向审核中心发起审核请求失败:" + response2.Message; Logger.Info($"新增职位信息提交审核失败:" + response2.Message); return(response); } response.Extension = _mapper.Map <HumanPositionResponse>(await Store.CreateAsync(user, _mapper.Map <HumanPosition>(humanPositionRequest), cancellationToken)); return(response); }
public async Task <ResponseMessage <HumanPositionResponse> > CreateHumanPosition(UserInfo user, [FromBody] HumanPositionRequest humanPositionRequest) { Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})新增人事职位信息(CreateHumanPosition),请求体为:\r\n" + (humanPositionRequest != null ? JsonHelper.ToJson(humanPositionRequest) : "")); ResponseMessage <HumanPositionResponse> response = new ResponseMessage <HumanPositionResponse>(); if (!ModelState.IsValid) { response.Code = ResponseCodeDefines.ModelStateInvalid; response.Message = ModelState.GetAllErrors(); Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})新增人事职位信息(CreateHumanPosition)模型验证失败:{response.Message}请求体为:\r\n" + (humanPositionRequest != null ? JsonHelper.ToJson(humanPositionRequest) : "")); return(response); } try { return(await _humanPositionManager.CreateAsync(user, humanPositionRequest, HttpContext.RequestAborted)); } catch (Exception e) { response.Code = ResponseCodeDefines.ServiceError; response.Message = e.Message; Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})新增人事职位信息(CreateHumanPosition)失败:{response.Message}请求体为:\r\n" + (humanPositionRequest != null ? JsonHelper.ToJson(humanPositionRequest) : "")); } return(response); }