diff --git a/YLErpDAL/Modules/TradeModule/OAModels.cs b/YLErpDAL/Modules/TradeModule/OAModels.cs
index 35dab7a2..ca9c68d9 100644
--- a/YLErpDAL/Modules/TradeModule/OAModels.cs
+++ b/YLErpDAL/Modules/TradeModule/OAModels.cs
@@ -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; }
}
+
+ ///
+ /// 附件上传接口响应模型
+ ///
+ public class UploadAttachmentResponse
+ {
+ public int code { get; set; }
+ public List data { get; set; }
+ public string status { get; set; }
+ }
+
+ ///
+ /// 附件上传接口响应数据模型
+ ///
+ public class UploadAttachmentData
+ {
+ public string annexId { get; set; }
+ public string annexName { get; set; }
+ }
}
\ No newline at end of file
diff --git a/YLErpDAL/Modules/TradeModule/TradeOAService.cs b/YLErpDAL/Modules/TradeModule/TradeOAService.cs
index 669fb837..90f6df0a 100644
--- a/YLErpDAL/Modules/TradeModule/TradeOAService.cs
+++ b/YLErpDAL/Modules/TradeModule/TradeOAService.cs
@@ -97,6 +97,78 @@ namespace YLErp.Modules.TradeModule
}
}
+ ///
+ /// 上传附件到OA系统
+ ///
+ /// 文件路径
+ /// 附件ID列表
+ private async Task> 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(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;
+ }
+ }
+
///
/// 调用OA接口
///
@@ -130,29 +202,18 @@ namespace YLErp.Modules.TradeModule
}
// 处理附件
- string attachmentBase64 = null;
- string attachmentFileName = null;
+ List 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放在请求体中)
diff --git a/YLErpWeb/appsettings.dev.json b/YLErpWeb/appsettings.dev.json
index 25774d4a..99e05c75 100644
--- a/YLErpWeb/appsettings.dev.json
+++ b/YLErpWeb/appsettings.dev.json
@@ -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登录