From a376d24964db749ed38a5873d2e6aaa1b82b2e83 Mon Sep 17 00:00:00 2001
From: sjz <1240968267@qq.com>
Date: 星期四, 13 二月 2025 18:04:41 +0800
Subject: [PATCH] 调取plm接口 返回文件流给前端
---
MESApplication/bin/Debug/net8.0/MESApplication.pdb | 0
MESApplication/bin/Debug/net8.0/MESApplication.exe | 0
MESApplication/bin/Debug/net8.0/MES.Service.pdb | 0
MESApplication/bin/Debug/net8.0/MESApplication.dll | 0
MES.Service/service/PLM/WarehouseDownloadDoc.cs | 145 ++++++++++++++++++++++++++++++++++++++++++++++++
MES.Service/bin/Debug/net8.0/MES.Service.dll | 0
MESApplication/bin/Debug/net8.0/MES.Service.dll | 0
MES.Service/bin/Debug/net8.0/MES.Service.pdb | 0
MES.Service/service/PLM/PLMManager.cs | 9 ++
MESApplication/Controllers/PLM/PLMController.cs | 26 ++++++++
10 files changed, 177 insertions(+), 3 deletions(-)
diff --git a/MES.Service/bin/Debug/net8.0/MES.Service.dll b/MES.Service/bin/Debug/net8.0/MES.Service.dll
index 298ad08..a2a587b 100644
--- a/MES.Service/bin/Debug/net8.0/MES.Service.dll
+++ b/MES.Service/bin/Debug/net8.0/MES.Service.dll
Binary files differ
diff --git a/MES.Service/bin/Debug/net8.0/MES.Service.pdb b/MES.Service/bin/Debug/net8.0/MES.Service.pdb
index 1bf036c..d931bc6 100644
--- a/MES.Service/bin/Debug/net8.0/MES.Service.pdb
+++ b/MES.Service/bin/Debug/net8.0/MES.Service.pdb
Binary files differ
diff --git a/MES.Service/service/PLM/PLMManager.cs b/MES.Service/service/PLM/PLMManager.cs
index eb82984..97a7c28 100644
--- a/MES.Service/service/PLM/PLMManager.cs
+++ b/MES.Service/service/PLM/PLMManager.cs
@@ -1,6 +1,6 @@
锘縰sing Kingdee.CDP.WebApi.SDK;
using MES.Service.Dto.webApi.PLM;
-using Newtonsoft.Json;
+
using System.Text;
namespace MES.Service.service.PLM;
@@ -22,7 +22,7 @@
return stdDocuments;
}
-
+ #region 1.閫氳繃鐗╂枡缂栫爜锛堥渶瑕佸敮涓�锛夎幏鍙栫墿鏂檌d
public List<BaseObject> GetPlmCfgBase(string ItemNo)
{
//娉ㄦ剰 1锛氭澶勪笉鍐嶄娇鐢ㄥ弬鏁板舰寮忎紶鍏ョ敤鎴峰悕鍙婂瘑鐮佺瓑鏁忔劅淇℃伅锛屾敼涓哄湪鐧诲綍閰嶇疆鏂囦欢涓缃��
@@ -69,7 +69,9 @@
return entity;
}).ToList();
}
+ #endregion
+ #region 2.閫氳繃鐗╂枡id鑾峰彇鐩稿叧瀵硅薄銆愪笅杞介渶瑕佺殑鏂囨。銆戠殑id
public List<RelatedObject> GetPlmCfgRelatedObject(long? FRelatedObject)
{
//娉ㄦ剰 1锛氭澶勪笉鍐嶄娇鐢ㄥ弬鏁板舰寮忎紶鍏ョ敤鎴峰悕鍙婂瘑鐮佺瓑鏁忔劅淇℃伅锛屾敼涓哄湪鐧诲綍閰嶇疆鏂囦欢涓缃��
@@ -116,7 +118,9 @@
return entity;
}).ToList();
}
+ #endregion
+ #region 3.鏍规嵁鏂囨。id鑾峰彇鏂囨。鐗╃悊鏂囦欢id
public List<StdDocument> GetPlmStdDocument(List<RelatedObject> relatedObjects)
{
//娉ㄦ剰 1锛氭澶勪笉鍐嶄娇鐢ㄥ弬鏁板舰寮忎紶鍏ョ敤鎴峰悕鍙婂瘑鐮佺瓑鏁忔劅淇℃伅锛屾敼涓哄湪鐧诲綍閰嶇疆鏂囦欢涓缃��
@@ -168,4 +172,5 @@
return entity;
}).ToList();
}
+ #endregion
}
diff --git a/MES.Service/service/PLM/WarehouseDownloadDoc.cs b/MES.Service/service/PLM/WarehouseDownloadDoc.cs
new file mode 100644
index 0000000..18d835b
--- /dev/null
+++ b/MES.Service/service/PLM/WarehouseDownloadDoc.cs
@@ -0,0 +1,145 @@
+锘縰sing Newtonsoft.Json.Linq;
+using System.Net;
+using System.Text;
+
+namespace ConsoleApp1
+{
+ #region 1.鏍规嵁鏂囨。鐗╃悊鏂囦欢id鑾峰彇鏂囨。娴佹暟鎹�
+ public class WarehouseDownloadDoc()
+ {
+ private string _cloudUrl = "http://121.36.245.199/k3cloud";
+ private string _warehouse = "http://192.168.30.251/CloudPLMWarehouse";
+
+ #region 鏂囨。鏈嶅姟鍣ㄤ笂涓嬫枃
+ private string WarehouseCTX
+ {
+ get
+ {
+ string json = "{\"ap1\":{ \"AcctID\":\"" + "6722eada66becb" + "\",\"Username\":\"Administrator\",\"Password\":\"Yc123456@\",\"Lcid\":2052,\"AuthenticateType\":1,\"PasswordIsEncrypted\":\"false\",\"ClientInfo\":{\"ClientType\":8}}";
+ var resp = GetResponse("http://121.36.245.199/k3cloud/Kingdee.BOS.ServiceFacade.ServicesStub.User.UserService.ValidateLoginInfo.common.kdsvc", json, new Dictionary<string, string>());
+ string ret = (new StreamReader(resp.GetResponseStream(), Encoding.UTF8)).ReadToEnd();
+ var result = JObject.Parse(ret)["Context"];
+ string token = result["UserToken"].ToString();
+ var warehouseCtx = string.Format("LoginUrl={0}/&UserToken={1}", _cloudUrl, token);
+ return Convert.ToBase64String(Encoding.UTF8.GetBytes(warehouseCtx));
+ }
+ }
+ #endregion
+
+ #region 鐗╃悊鏂囦欢id
+ private string GetFileId(string fileId)
+ {
+ return Convert.ToBase64String(Encoding.UTF8.GetBytes(fileId));
+ }
+ #endregion
+
+ #region 鐢靛瓙浠撹闂嚟璇�
+ private string Token
+ {
+ get
+ {
+ var token = Guid.NewGuid().ToString();
+ return token;
+ }
+ }
+ #endregion
+
+ #region 鍙戦�佽姹�
+ public Stream SendRequest(string op, string fileId)
+ {
+ var header = new Dictionary<string, string>()
+ {
+ {"FileID" ,GetFileId(fileId) },
+ { "CTX",WarehouseCTX},
+ { "token", Token },
+ { "PLM_ACCESS_TYPE","pure" }
+ };
+ return PostDataViaHttpWebRequest(RequestUrl(op), string.Empty, header, !op.Equals("Download"));
+ }
+ #endregion
+
+ #region 璇锋眰鐨刄RL
+ private string RequestUrl(string op)
+ {
+ return _warehouse + "/" + op;
+ }
+ #endregion
+
+ #region 鑾峰彇鍝嶅簲
+ private HttpWebResponse GetResponse(string url, string bodyJson, Dictionary<string, string> header)
+ {
+ byte[] data = Encoding.UTF8.GetBytes(bodyJson);
+
+ HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
+ request.Method = WebRequestMethods.Http.Post;
+ request.ContentType = "application/json";
+ request.ContentLength = data.Length;
+ if (header != null)
+ {
+ foreach (var p in header)
+ {
+ request.Headers.Add(p.Key, p.Value);
+ }
+ }
+
+ using (Stream reqStream = request.GetRequestStream())
+ {
+ reqStream.Write(data, 0, data.Length);
+ reqStream.Close();
+ }
+
+ HttpWebResponse resp = null;
+ try
+ {
+ resp = (HttpWebResponse)request.GetResponse();
+ }
+ catch (WebException ex)
+ {
+ var res = ex.Response;
+ if (res != null)
+ {
+ string statusBase64 = ((HttpWebResponse)ex.Response).StatusDescription;//base64缂栫爜鍚庣殑鎶ラ敊淇℃伅
+ }
+ }
+ return resp;
+ }
+ #endregion
+
+ #region 淇濆瓨鏂囦欢鍒版湰鍦�
+ /*private void PostDataViaHttpWebRequest(string url, string bodyJson, Dictionary<string, string> header, bool isGetContent)
+ {
+
+ var resp = GetResponse(url, bodyJson, header);
+ var resultJson = string.Empty;
+ Stream stream = File.Open("D://DownloadDocDemo.pdf", FileMode.OpenOrCreate);
+ int packageSize = 1024 * 1024;
+ byte[] buffer = new byte[packageSize];
+ using (stream)
+ {
+ using (Stream outputStream = resp.GetResponseStream())
+ {
+ int readLength = 0;
+ while ((readLength = outputStream.Read(buffer, 0, packageSize)) > 0)
+ {
+ stream.Write(buffer, 0, readLength);
+ stream.Flush();
+ }
+ outputStream.Close();
+ }
+ stream.Close();
+ }
+ }*/
+ #endregion
+
+ #region 杩斿洖鏂囦欢娴佺粰鍓嶇
+ private Stream PostDataViaHttpWebRequest(string url, string bodyJson, Dictionary<string, string> header, bool isGetContent)
+ {
+
+ var resp = GetResponse(url, bodyJson, header);
+
+ return resp.GetResponseStream(); // 鐩存帴杩斿洖鍝嶅簲娴�
+ }
+ #endregion
+ }
+ #endregion
+}
diff --git a/MESApplication/Controllers/PLM/PLMController.cs b/MESApplication/Controllers/PLM/PLMController.cs
index 102d88b..52846e6 100644
--- a/MESApplication/Controllers/PLM/PLMController.cs
+++ b/MESApplication/Controllers/PLM/PLMController.cs
@@ -1,7 +1,9 @@
-锘縰sing MES.Service.service.PLM;
+锘縰sing ConsoleApp1;
+using MES.Service.service.PLM;
using MES.Service.util;
using Microsoft.AspNetCore.Mvc;
using System.Dynamic;
+using System.IO;
namespace MESApplication.Controllers.PLM;
@@ -11,6 +13,7 @@
public class PLMController : ControllerBase
{
private readonly PLMManager m = new();
+ private readonly WarehouseDownloadDoc wdd = new();
//RetrieveDrawings 璋冨彇鍥剧焊
[HttpPost("RetrieveDrawings")]
@@ -33,4 +36,25 @@
return ResponseResult.ResponseError(ex);
}
}
+
+ //RetrieveDrawings 璋冨彇鍥剧焊
+ [HttpPost("OpenDrawings")]
+ public IActionResult OpenDrawings(string fileId,string fName)
+ {
+ try
+ {
+ var resultInfos = wdd.SendRequest("Download", fileId);
+
+ return File(resultInfos, "application/octet-stream", fName);
+ }
+ catch (Exception ex)
+ {
+ return StatusCode(500, new ResponseResult
+ {
+ status = 1,
+ message = ex.Message,
+ data = null
+ });
+ }
+ }
}
diff --git a/MESApplication/bin/Debug/net8.0/MES.Service.dll b/MESApplication/bin/Debug/net8.0/MES.Service.dll
index 298ad08..a2a587b 100644
--- a/MESApplication/bin/Debug/net8.0/MES.Service.dll
+++ b/MESApplication/bin/Debug/net8.0/MES.Service.dll
Binary files differ
diff --git a/MESApplication/bin/Debug/net8.0/MES.Service.pdb b/MESApplication/bin/Debug/net8.0/MES.Service.pdb
index 1bf036c..d931bc6 100644
--- a/MESApplication/bin/Debug/net8.0/MES.Service.pdb
+++ b/MESApplication/bin/Debug/net8.0/MES.Service.pdb
Binary files differ
diff --git a/MESApplication/bin/Debug/net8.0/MESApplication.dll b/MESApplication/bin/Debug/net8.0/MESApplication.dll
index d90536b..fed2aee 100644
--- a/MESApplication/bin/Debug/net8.0/MESApplication.dll
+++ b/MESApplication/bin/Debug/net8.0/MESApplication.dll
Binary files differ
diff --git a/MESApplication/bin/Debug/net8.0/MESApplication.exe b/MESApplication/bin/Debug/net8.0/MESApplication.exe
index 0f9911f..1019d54 100644
--- a/MESApplication/bin/Debug/net8.0/MESApplication.exe
+++ b/MESApplication/bin/Debug/net8.0/MESApplication.exe
Binary files differ
diff --git a/MESApplication/bin/Debug/net8.0/MESApplication.pdb b/MESApplication/bin/Debug/net8.0/MESApplication.pdb
index 743ccdd..a5eacaf 100644
--- a/MESApplication/bin/Debug/net8.0/MESApplication.pdb
+++ b/MESApplication/bin/Debug/net8.0/MESApplication.pdb
Binary files differ
--
Gitblit v1.9.3