public async Task <ResponseMessage <HumanInfoBlackResponse> > CreateHumanInfoBlack(UserInfo user, [FromBody] HumanInfoBlackRequest humanInfoBlackRequest)
        {
            Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})新增黑名单(CreateHumanInfoBlack),\r\n请求参数为:\r\n" + (humanInfoBlackRequest != null ? JsonHelper.ToJson(humanInfoBlackRequest) : ""));
            var response = new ResponseMessage <HumanInfoBlackResponse>();

            if (!ModelState.IsValid)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = ModelState.GetAllErrors();
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})新增黑名单(CreateHumanInfoBlack)模型验证失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (humanInfoBlackRequest != null ? JsonHelper.ToJson(humanInfoBlackRequest) : ""));
                return(response);
            }
            try
            {
                await _humanInfoBlackManager.SaveAsync(user, humanInfoBlackRequest, HttpContext.RequestAborted);
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.Message;
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})新增黑名单(CreateHumanInfoBlack)请求失败:\r\n{e.ToString() ?? ""},\r\n请求参数为:\r\n" + (humanInfoBlackRequest != null ? JsonHelper.ToJson(humanInfoBlackRequest) : ""));
            }
            return(response);
        }
Ejemplo n.º 2
0
        public async Task <ResponseMessage <HumanInfoBlackResponse> > SaveAsync(UserInfo user, HumanInfoBlackRequest humanInfoBlackRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            ResponseMessage <HumanInfoBlackResponse> response = new ResponseMessage <HumanInfoBlackResponse>();

            if (user == null || humanInfoBlackRequest == null)
            {
                throw new ArgumentNullException(nameof(UserInfo) + nameof(HumanInfoRequest));
            }


            if (string.IsNullOrEmpty(humanInfoBlackRequest.Id))
            {
                humanInfoBlackRequest.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       = humanInfoBlackRequest.Id;
            examineSubmitRequest.ContentType     = "HumanBlack";
            examineSubmitRequest.ContentName     = humanInfoBlackRequest.Name;
            examineSubmitRequest.Content         = "新增员工人事黑名单信息";
            examineSubmitRequest.Source          = user.FilialeName;
            examineSubmitRequest.SubmitDefineId  = humanInfoBlackRequest.Id;
            examineSubmitRequest.CallbackUrl     = gatwayurl + "/api/humaninfoblack/humanblackcallback";
            examineSubmitRequest.StepCallbackUrl = gatwayurl + "/api/humaninfoblack/humanblackstepcallback";
            examineSubmitRequest.Action          = "HumanBlack";
            examineSubmitRequest.TaskName        = $"新增员工人事黑名单信息:{humanInfoBlackRequest.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 <HumanInfoBlackResponse>(await Store.SaveAsync(user, _mapper.Map <HumanInfoBlack>(humanInfoBlackRequest), cancellationToken));
            return(response);
        }