public async Task <ResponseMessage> SubmitContractCallback([FromBody] ExamineResponse examineResponse)
        {
            Logger.Trace($"合同提交审核中心回调(SubmitContractCallback):\r\n请求参数为:\r\n" + (examineResponse != null ? JsonHelper.ToJson(examineResponse) : ""));

            ResponseMessage response = new ResponseMessage();

            if (examineResponse == null)
            {
                response.Code = ResponseCodeDefines.ModelStateInvalid;
                Logger.Trace($"合同提交审核中心回调(SubmitContractCallback)模型验证失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (examineResponse != null ? JsonHelper.ToJson(examineResponse) : ""));
                return(response);
            }
            try
            {
                var building = await _contractInfoManager.FindByIdAsync(examineResponse.ContentId);

                response.Code = ResponseCodeDefines.SuccessCode;
                if (building == null)
                {
                    response.Code    = ResponseCodeDefines.NotFound;
                    response.Message = "合同不存在:" + examineResponse.ContentId;
                    Logger.Trace($"合同提交审核中心回调(SubmitBuildingCallback)失败:合同不存在,\r\n请求参数为:\r\n" + (examineResponse != null ? JsonHelper.ToJson(examineResponse) : ""));
                    return(response);
                }

                if (examineResponse.ExamineStatus == ExamineStatus.Examined)
                {
                    var modifyre = await _contractInfoManager.OperModifyInfoAsync(examineResponse.SubmitDefineId, examineResponse.ContentId, ExamineStatusEnum.Approved);

                    if (modifyre.Type == ContractInfoManager.ModifyContract)
                    {
                        await _contractInfoManager.ModifyContractAfterCheckAsync(modifyre.ID, modifyre.ContractID, modifyre.Ext1, ExamineStatusEnum.Approved);
                    }
                    else if (modifyre.Type == ContractInfoManager.AddAnnexContract)
                    {
                        List <FileInfoRequest> fileInfoRequests = JsonHelper.ToObject <List <FileInfoRequest> >(modifyre.Ext1);
                        List <string>          deleteList       = JsonHelper.ToObject <List <string> >(modifyre.Ext5);
                        //List<NWF> listnf = JsonHelper.ToObject<List<NWF>>(modifyre.Ext2);
                        UserInfo user = JsonHelper.ToObject <UserInfo>(modifyre.Ext3);
                        List <FileInfoCallbackRequest> filCallBackReq = new List <FileInfoCallbackRequest>();

                        int nindex = 0;
                        foreach (var item in fileInfoRequests)
                        {
                            try
                            {
                                //NameValueCollection nameValueCollection = new NameValueCollection();
                                //nameValueCollection.Add("appToken", "app:nwf");
                                //Logger.Info("nwf协议");
                                //string response2 = await _restClient.Post(ApplicationContext.Current.NWFUrl, listnf.ElementAt(nindex++), "POST", nameValueCollection);
                                //Logger.Info("返回:\r\n{0}", response2);


                                await _fileScopeManager.CreateAsync(user, modifyre.Ext4, modifyre.ContractID, modifyre.ID, item);

                                //response.Message = response2;
                            }
                            catch (Exception e)
                            {
                                response.Code     = ResponseCodeDefines.PartialFailure;
                                response.Message += $"文件:{item.FileGuid}处理出错,错误信息:{e.ToString()}。\r\n";
                                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})批量上传文件信息(UploadFiles)报错:\r\n{e.ToString()},请求参数为:\r\n,(dest){modifyre.Ext4 ?? ""},(contractId){ modifyre.ContractID ?? ""}," + (fileInfoRequests != null ? JsonHelper.ToJson(fileInfoRequests) : ""));
                            }
                        }
                        try
                        {
                            await _fileInfoManager.CreateListAsync(user.Id, fileInfoRequests, HttpContext.RequestAborted);

                            await _fileScopeManager.DeleteContractFileListAsync(user.Id, modifyre.ContractID, deleteList, HttpContext.RequestAborted);
                        }
                        catch (Exception e)
                        {
                            response.Code    = ResponseCodeDefines.ServiceError;
                            response.Message = e.ToString();
                            Logger.Trace($"合同文件添加或删除失败,审核中心回调(SubmitBuildingCallback)报错:\r\n{e.ToString()},\r\n请求参数为:\r\n" + fileInfoRequests != null ? JsonHelper.ToJson(fileInfoRequests) : "\r\n" + deleteList != null ? JsonHelper.ToJson(deleteList) : "");
                        }
                    }
                    else if (modifyre.Type == ContractInfoManager.UpdateComplementContract)
                    {
                        UserInfo User = JsonHelper.ToObject <UserInfo>(modifyre.Ext1);
                        List <ContractComplementRequest> request = JsonHelper.ToObject <List <ContractComplementRequest> >(modifyre.Ext2);
                        await _contractInfoManager.AddComplementAsync(User, modifyre.ContractID, modifyre.ID, "TEST", request);
                    }
                }
                else if (examineResponse.ExamineStatus == ExamineStatus.Reject)
                {
                    await _contractInfoManager.SubmitAsync(examineResponse.SubmitDefineId, ExamineStatusEnum.Reject);
                }
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Trace($"合同提交审核中心回调(SubmitBuildingCallback)报错:\r\n{e.ToString()},\r\n请求参数为:\r\n" + examineResponse != null ? JsonHelper.ToJson(examineResponse) : "");
            }
            return(response);
        }
Beispiel #2
0
        public async Task <ResponseMessage> UploadFiles(UserInfo user, [FromBody] FileUploadRequest fileInfoRequests, [FromQuery] string source, [FromRoute] string dest, [FromRoute] string contractId)
        {
            ResponseMessage response = new ResponseMessage();

            if (fileInfoRequests == null || ((fileInfoRequests.AddFileList == null && fileInfoRequests.AddFileList.Count == 0) && (fileInfoRequests.DeleteFileList == null && fileInfoRequests.DeleteFileList.Count == 0)))
            {
                response.Code    = ResponseCodeDefines.ArgumentNullError;
                response.Message = "请求参数错误";
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})批量上传文件信息(UploadFiles)模型验证失败:\r\n{response.Message ?? ""},请求参数为:\r\n(source){source ?? ""},(dest){dest ?? ""},(contractId){contractId ?? ""}," + (fileInfoRequests != null ? JsonHelper.ToJson(fileInfoRequests) : ""));
                return(response);
            }
            var info = await _contractInfoManager.FindByIdAsync(contractId, HttpContext.RequestAborted);

            if (info == null)
            {
                response.Code    = ResponseCodeDefines.NotFound;
                response.Message = "合同不存在:" + contractId;
                Logger.Error($"合同文件上传失败:合同不存在,\r\n请求参数为:\r\n" + (fileInfoRequests != null ? JsonHelper.ToJson(fileInfoRequests) : ""));
                return(response);
            }


            List <FileInfo>         fileInfos = new List <FileInfo>();
            List <FileItemResponse> fileItems = new List <FileItemResponse>();

            fileInfos = await _fileScopeManager.FindByContractIdAsync(user.Id, contractId);

            if (fileInfoRequests.DeleteFileList != null && fileInfoRequests.DeleteFileList.Count > 0)
            {
                //删除信息此处只存待审核通过后一并删除
            }
            if (fileInfoRequests.AddFileList != null && fileInfoRequests.AddFileList.Count > 0)
            {
            }

            string strModifyGuid = Guid.NewGuid().ToString();

            try
            {
                if (fileInfoRequests.ModifyFileList != null && fileInfoRequests.ModifyFileList.Count > 0)
                {
                    await _fileScopeManager.UpdateFileExtInfo(fileInfoRequests.ModifyFileList, HttpContext.RequestAborted);
                }
                GatewayInterface.Dto.ExamineSubmitRequest exarequest = new GatewayInterface.Dto.ExamineSubmitRequest();
                exarequest.ContentId      = contractId;
                exarequest.ContentType    = "ContractCommit";
                exarequest.ContentName    = "UploadFiles";
                exarequest.SubmitDefineId = strModifyGuid;
                exarequest.Source         = "";
                exarequest.CallbackUrl    = "";
                exarequest.Action         = "TEST"; /* exarequest.ContentType*/;
                exarequest.TaskName       = $"{user.UserName}添加合同附件{exarequest.ContentName}的动态{exarequest.ContentType}";

                GatewayInterface.Dto.UserInfo userinfo = new GatewayInterface.Dto.UserInfo()
                {
                    Id               = user.Id,
                    KeyWord          = user.KeyWord,
                    OrganizationId   = user.OrganizationId,
                    OrganizationName = user.OrganizationName,
                    UserName         = user.UserName
                };

                var examineInterface = ApplicationContext.Current.Provider.GetRequiredService <IExamineInterface>();
                var reponse          = await examineInterface.Submit(userinfo, exarequest);

                if (reponse.Code != ResponseCodeDefines.SuccessCode)
                {
                    response.Code    = ResponseCodeDefines.ServiceError;
                    response.Message = "向审核中心发起审核请求失败:" + reponse.Message;
                    return(response);
                }

                response.Message = "发起审核成功";



                await _fileScopeManager.CreateModifyAsync(user, contractId, strModifyGuid, "TEST", JsonHelper.ToJson(fileInfoRequests.AddFileList),
                                                          null, JsonHelper.ToJson(user), dest, JsonHelper.ToJson(fileInfoRequests.DeleteFileList), HttpContext.RequestAborted);//添加修改历史

                response.Message = "添加附件修改成功";
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"上传文件信息回调(FileCallback)模型验证失败:\r\n{e.ToString()},请求参数为:\r\n" + (fileInfoRequests != null ? JsonHelper.ToJson(fileInfoRequests) : ""));
            }


            return(response);
        }