111
cnf
2025-02-19 9f7ba7872cbaab50a470f4df822621fbcd28d0e3
111
已添加1个文件
已修改9个文件
180 ■■■■■ 文件已修改
MES.Service/bin/Debug/net8.0/MES.Service.dll 补丁 | 查看 | 原始文档 | blame | 历史
MES.Service/bin/Debug/net8.0/MES.Service.pdb 补丁 | 查看 | 原始文档 | blame | 历史
MES.Service/service/PLM/PLMManager.cs 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MES.Service/service/PLM/WarehouseDownloadDoc.cs 145 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MESApplication/Controllers/PLM/PLMController.cs 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MESApplication/bin/Debug/net8.0/MES.Service.dll 补丁 | 查看 | 原始文档 | blame | 历史
MESApplication/bin/Debug/net8.0/MES.Service.pdb 补丁 | 查看 | 原始文档 | blame | 历史
MESApplication/bin/Debug/net8.0/MESApplication.dll 补丁 | 查看 | 原始文档 | blame | 历史
MESApplication/bin/Debug/net8.0/MESApplication.exe 补丁 | 查看 | 原始文档 | blame | 历史
MESApplication/bin/Debug/net8.0/MESApplication.pdb 补丁 | 查看 | 原始文档 | blame | 历史
MES.Service/bin/Debug/net8.0/MES.Service.dll
Binary files differ
MES.Service/bin/Debug/net8.0/MES.Service.pdb
Binary files differ
MES.Service/service/PLM/PLMManager.cs
@@ -1,6 +1,6 @@
using 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.通过物料编码(需要唯一)获取物料id
    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
}
MES.Service/service/PLM/WarehouseDownloadDoc.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,145 @@
using 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 è¯·æ±‚çš„URL
        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
}
MESApplication/Controllers/PLM/PLMController.cs
@@ -1,7 +1,9 @@
using MES.Service.service.PLM;
using 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
            });
        }
    }
}
MESApplication/bin/Debug/net8.0/MES.Service.dll
Binary files differ
MESApplication/bin/Debug/net8.0/MES.Service.pdb
Binary files differ
MESApplication/bin/Debug/net8.0/MESApplication.dll
Binary files differ
MESApplication/bin/Debug/net8.0/MESApplication.exe
Binary files differ
MESApplication/bin/Debug/net8.0/MESApplication.pdb
Binary files differ