feat(OA): 添加附件上传功能并更新OA配置
添加新的附件上传接口实现,包括上传方法和响应模型 更新OA配置添加UploadUrl字段并修改SystemToken 使用新的附件上传方式替代原有的Base64编码方式
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YLErp.Modules.TradeModule
|
||||
{
|
||||
@@ -41,4 +42,23 @@ namespace YLErp.Modules.TradeModule
|
||||
public string msg { get; set; }
|
||||
public string requestid { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 附件上传接口响应模型
|
||||
/// </summary>
|
||||
public class UploadAttachmentResponse
|
||||
{
|
||||
public int code { get; set; }
|
||||
public List<UploadAttachmentData> data { get; set; }
|
||||
public string status { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 附件上传接口响应数据模型
|
||||
/// </summary>
|
||||
public class UploadAttachmentData
|
||||
{
|
||||
public string annexId { get; set; }
|
||||
public string annexName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,78 @@ namespace YLErp.Modules.TradeModule
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传附件到OA系统
|
||||
/// </summary>
|
||||
/// <param name="filePath">文件路径</param>
|
||||
/// <returns>附件ID列表</returns>
|
||||
private async Task<List<string>> UploadAttachmentAsync(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 从配置文件读取上传配置
|
||||
var oaConfigSection = AppManager.GetConfiguration().GetSection("oa_confg");
|
||||
var uploadUrl = oaConfigSection["UploadUrl"];
|
||||
var systemToken = oaConfigSection["SystemToken"];
|
||||
|
||||
if (string.IsNullOrEmpty(uploadUrl))
|
||||
{
|
||||
logger.Error("OA接口配置中UploadUrl为空");
|
||||
throw new Exception("OA接口配置中上传地址为空");
|
||||
}
|
||||
if (string.IsNullOrEmpty(systemToken))
|
||||
{
|
||||
logger.Error("OA接口配置中SystemToken为空");
|
||||
throw new Exception("OA接口配置中上传令牌为空");
|
||||
}
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
logger.Error($"附件文件不存在:{filePath}");
|
||||
throw new Exception("附件文件不存在");
|
||||
}
|
||||
|
||||
// 创建multipart/form-data请求
|
||||
using (var httpClient = new HttpClient())
|
||||
using (var form = new MultipartFormDataContent())
|
||||
{
|
||||
// 添加文件
|
||||
var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
||||
var fileName = Path.GetFileName(filePath);
|
||||
form.Add(new StreamContent(fileStream), "file", fileName);
|
||||
|
||||
// 添加systemToken
|
||||
form.Add(new StringContent(systemToken), "systemToken");
|
||||
|
||||
// 发送请求
|
||||
var response = await httpClient.PostAsync(uploadUrl, form);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
logger.Info($"附件上传接口返回: {responseContent}");
|
||||
|
||||
// 解析响应
|
||||
var uploadResponse = JsonHelper.Deserialize<UploadAttachmentResponse>(responseContent);
|
||||
if (uploadResponse.code == 0 && uploadResponse.data != null)
|
||||
{
|
||||
// 提取annexId
|
||||
var annexIds = uploadResponse.data.Select(item => item.annexId).ToList();
|
||||
logger.Info($"成功上传附件,获取到{annexIds.Count}个附件ID");
|
||||
return annexIds;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error($"附件上传失败:{uploadResponse.status}");
|
||||
throw new Exception($"附件上传失败:{uploadResponse.status}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error($"上传附件时发生异常:{ex.Message}", ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调用OA接口
|
||||
/// </summary>
|
||||
@@ -130,29 +202,18 @@ namespace YLErp.Modules.TradeModule
|
||||
}
|
||||
|
||||
// 处理附件
|
||||
string attachmentBase64 = null;
|
||||
string attachmentFileName = null;
|
||||
List<string> annexIds = null;
|
||||
if (tdoc != null && !string.IsNullOrEmpty(tdoc.AbsolutePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(tdoc.AbsolutePath))
|
||||
{
|
||||
var fileBytes = await File.ReadAllBytesAsync(tdoc.AbsolutePath);
|
||||
attachmentBase64 = Convert.ToBase64String(fileBytes);
|
||||
attachmentFileName = Path.GetFileName(tdoc.AbsolutePath);
|
||||
logger.Info($"成功读取附件文件:{tdoc.AbsolutePath},文件大小:{fileBytes.Length} 字节");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error($"附件文件不存在:{tdoc.AbsolutePath}");
|
||||
return new GuoLianOAResponse() { code = -1, data = new GuoLianOAData { msg = "附件文件不存在" } };
|
||||
}
|
||||
annexIds = await UploadAttachmentAsync(tdoc.AbsolutePath);
|
||||
logger.Info($"成功上传附件并获取到annexId:{string.Join(", ", annexIds)}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error($"读取附件文件失败:{tdoc.AbsolutePath},错误:{ex.Message}", ex);
|
||||
return new GuoLianOAResponse() { code = -1, data = new GuoLianOAData { msg = "读取附件文件失败" } };
|
||||
logger.Error($"上传附件失败:{tdoc.AbsolutePath},错误:{ex.Message}", ex);
|
||||
return new GuoLianOAResponse() { code = -1, data = new GuoLianOAData { msg = "上传附件失败" } };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +245,8 @@ namespace YLErp.Modules.TradeModule
|
||||
contractSignDate = DateTime.Now.ToString("yyyyMMdd"),
|
||||
signIntegrityAgreement = "无需签订",
|
||||
contractBackground = $"我司与{trade.ClientName}已完成NAFMII协议签署,并开展TRS交易:{contractCode},参与标的{trade.UnderlyingCode} {trade.UnderlyingName},参与标的数量面额{trade.OriginalStockEqvNotional}元人民币",
|
||||
//需要上传接口加附件
|
||||
// 使用annexId替代Base64编码
|
||||
annexIds = annexIds
|
||||
};
|
||||
|
||||
// 构建查询参数(不包含dataMap,dataMap放在请求体中)
|
||||
|
||||
@@ -77,10 +77,11 @@
|
||||
"oa_confg": {
|
||||
"BaseUrl": "http://10.52.130.11",
|
||||
"SubUrl": "/ZSZQ/fileDraft",
|
||||
"SystemToken": "fF2U9HXs7dm6Hjz5X", //OA系统key
|
||||
"SystemToken": "123", //OA系统key
|
||||
"SystemName": "ZSZQ_CWYSPJYQRSDZWF", //OA文件类别
|
||||
"IsNextFlow": 0, //是否自动提交 默认0
|
||||
"FlowId": 723606
|
||||
"FlowId": 723606,
|
||||
"UploadUrl": "http://172.28.40.132:13590/gateway/oaflow/uploadDoc"
|
||||
},
|
||||
"GeneralSSO": {
|
||||
"enable": true, //是否启用通用SSO登录
|
||||
|
||||
Reference in New Issue
Block a user