public async Task <ResponseMessage> UploadFile(UserInfo user, [FromBody] DealFileInfoRequest fileInfoRequest, [FromQuery] string source, [FromRoute] string dest, [FromRoute] string Id) { Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})上传文件信息(UploadFile):请求参数为:\r\n(source){source},(dest){dest},(Id){Id}," + (fileInfoRequest != null ? JsonHelper.ToJson(fileInfoRequest) : "")); ResponseMessage response = new ResponseMessage(); if (fileInfoRequest == null) { response.Code = ResponseCodeDefines.ArgumentNullError; response.Message = ModelState.GetAllErrors(); Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})上传文件信息(UploadFile)模型验证失败:\r\n{response.Message ?? ""},请求参数为:\r\n(source){source},(dest){dest},(Id){Id}," + (fileInfoRequest != null ? JsonHelper.ToJson(fileInfoRequest) : "")); return(response); } try { // await _fileScopeManager.CreateAsync(userId, fileInfoRequest, HttpContext.RequestAborted); await _fileScopeManager.CreateAsync(user, dest, Id, fileInfoRequest, HttpContext.RequestAborted); NameValueCollection nameValueCollection = new NameValueCollection(); nameValueCollection.Add("appToken", "app:nwf"); var nwf = CreateNwf(user, source, fileInfoRequest); Logger.Info("nwf协议:\r\n{0}", JsonHelper.ToJson(nwf)); string response2 = await _restClient.Post(ApplicationContext.Current.NWFUrl, nwf, "POST", nameValueCollection); Logger.Info("返回:\r\n{0}", response2); } catch (Exception e) { response.Code = ResponseCodeDefines.ServiceError; response.Message = e.ToString(); Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})上传文件信息(UploadFile)报错:\r\n{e.ToString()},请求参数为:\r\n(source){source ?? ""},(dest){dest ?? ""},(Id){Id ?? ""}," + (fileInfoRequest != null ? JsonHelper.ToJson(fileInfoRequest) : "")); } return(response); }
private NWF CreateNwf(UserInfo user, string source, DealFileInfoRequest fileInfoRequest) { NWF nwf = new NWF(); var bodyinfo = new BodyInfoType(); var header = new HeaderType(); bodyinfo.FileInfo = new List <FileInfoType>(); nwf.BodyInfo = bodyinfo; nwf.Header = header; header.TaskGuid = ""; header.ContentGuid = fileInfoRequest.SourceId; header.Action = "ImageProcess"; header.SourceSystem = source; header.ExtraAttribute = new List <AttributeType>(); header.ExtraAttribute.Add(new AttributeType() { Name = "UserID", Value = user.Id }); header.ExtraAttribute.Add(new AttributeType() { Name = "SubSystem", Value = "xyhcustomer" }); bodyinfo.Priority = 0; bodyinfo.TaskName = fileInfoRequest.Name; if (String.IsNullOrEmpty(bodyinfo.TaskName)) { bodyinfo.TaskName = $"{user.UserName}-{source ?? ""}"; } var extra = new List <AttributeType>(); extra.Add(new AttributeType { Name = "WXAppID", Value = fileInfoRequest.AppId }); extra.Add(new AttributeType { Name = "From", Value = fileInfoRequest.From }); extra.Add(new AttributeType { Name = "Source", Value = fileInfoRequest.Source }); extra.Add(new AttributeType { Name = "Name", Value = fileInfoRequest.Name }); extra.Add(new AttributeType { Name = "FileExt", Value = fileInfoRequest.FileExt }); bodyinfo.ExtraAttribute = extra; FileInfoType fileInfoType = new FileInfoType(); fileInfoType.FilePath = fileInfoRequest.WXPath; fileInfoType.FileExt = fileInfoRequest.FileExt; fileInfoType.FileGuid = fileInfoRequest.FileGuid; fileInfoType.QualityType = 0; fileInfoType.FileTypeId = "ROW"; fileInfoType.ExtraAttribute = new List <AttributeType>(); nwf.BodyInfo.FileInfo.Add(fileInfoType); return(nwf); }
public virtual async Task CreateAsync(UserInfo user, string source, string Id, DealFileInfoRequest fileInfoRequest, CancellationToken cancellationToken = default(CancellationToken)) { if (fileInfoRequest == null) { throw new ArgumentNullException(nameof(fileInfoRequest)); } if (source == "customer") { var customerfile = _mapper.Map <CustomerFileScope>(fileInfoRequest); customerfile.FileType = DealFileType.Image; customerfile.CreateTime = DateTime.Now; customerfile.CreateUser = user.Id; customerfile.CustomerId = fileInfoRequest.SourceId; await _icustomerFilescopeStore.SaveAsync(_mapper.Map <SimpleUser>(user), Id, new List <CustomerFileScope>() { customerfile }, cancellationToken); } else { var dealfile = _mapper.Map <DealFileScope>(fileInfoRequest); dealfile.IsDeleted = false; dealfile.DealId = fileInfoRequest.SourceId; dealfile.FileType = DealFileType.Image; dealfile.CreateTime = DateTime.Now; dealfile.CreateUser = user.Id; await _dealFileScopeStore.SaveAsync(_mapper.Map <SimpleUser>(user), Id, new List <DealFileScope>() { dealfile }, cancellationToken); } }