From 41975878bf0b8d3632d8c5f21714502a57632070 Mon Sep 17 00:00:00 2001 From: xwt <2740516069@qq.com> Date: 星期三, 23 七月 2025 16:08:39 +0800 Subject: [PATCH] 紧急放行修改 --- StandardInterface/MESApplication/Controllers/QC/LljController.cs | 99 +++++++++++++++++++++++++++++++++++++------------ 1 files changed, 75 insertions(+), 24 deletions(-) diff --git a/StandardInterface/MESApplication/Controllers/QC/LljController.cs b/StandardInterface/MESApplication/Controllers/QC/LljController.cs index 576e5c6..838c228 100644 --- a/StandardInterface/MESApplication/Controllers/QC/LljController.cs +++ b/StandardInterface/MESApplication/Controllers/QC/LljController.cs @@ -320,11 +320,11 @@ [HttpPost("getAttachments")] public ResponseResult GetAttachments([FromBody] JObject data) { - var releaseNo = data["releaseNo"]?.ToString(); + var itemNo = data["itemNo"]?.ToString(); try { dynamic resultInfos = new System.Dynamic.ExpandoObject(); - var tbBillList = new LljService().GetAttachments(releaseNo); + var tbBillList = new LljService().GetAttachments(itemNo); if (tbBillList == null || tbBillList.Count == 0) { return new ResponseResult @@ -348,36 +348,87 @@ } } - [HttpGet("DownloadFtpFile")] - public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName) + [HttpGet("PreviewFtpFile")] + public IActionResult PreviewFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer) { - // FTP鏈嶅姟鍣ㄤ俊鎭紙璇锋浛鎹负瀹為檯淇℃伅锛� - string ftpServer = "ftp://36.26.21.214"; - string ftpUser = "hm_ftp"; - string ftpPwd = "dell_123"; // 宸叉洿鏂颁负鐪熷疄瀵嗙爜 - string ftpPath = $"{ftpServer}/IQC/{itemNo}/{fileName}"; try { - var request = (System.Net.FtpWebRequest)System.Net.WebRequest.Create(ftpPath); - request.Method = System.Net.WebRequestMethods.Ftp.DownloadFile; - request.Credentials = new System.Net.NetworkCredential(ftpUser, ftpPwd); - request.UseBinary = true; - request.UsePassive = true; - using (var response = (System.Net.FtpWebResponse)request.GetResponse()) - using (var ftpStream = response.GetResponseStream()) - using (var ms = new System.IO.MemoryStream()) + // 娣诲姞CORS鍝嶅簲澶� + Response.Headers.Add("Access-Control-Allow-Origin", "*"); + Response.Headers.Add("Access-Control-Allow-Methods", "GET, OPTIONS"); + Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type"); + Response.Headers.Add("Access-Control-Expose-Headers", "Content-Type, Content-Length"); + + var service = new LljService(); + var fileBytes = service.GetFtpFile(itemNo, fileName, ftpServer); + + if (fileBytes == null || fileBytes.Length == 0) { - ftpStream.CopyTo(ms); - ms.Position = 0; - string contentType = "application/octet-stream"; - // 闃插尽鎬у鐞嗭紝鍘婚櫎fileName涓殑鍥炶溅鎹㈣鍜岀┖鏍� - fileName = fileName?.Trim().Replace("\r", "").Replace("\n", ""); - return File(ms.ToArray(), contentType, fileName); + return NotFound("鏂囦欢鍦‵TP鏈嶅姟鍣ㄤ笂涓嶅瓨鍦�"); } + + var contentType = service.GetContentType(fileName); + fileName = fileName?.Trim().Replace("\r", "").Replace("\n", ""); + + return File(fileBytes, contentType); } catch (Exception ex) { - return BadRequest($"FTP涓嬭浇澶辫触锛歿ex.Message}锛宖tpPath={ftpPath}锛宖ileName={fileName}"); + return StatusCode(500, $"棰勮鏂囦欢澶辫触锛歿ex.Message}"); } } + + [HttpGet("DownloadFtpFile")] + public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer) + { + try + { + // 娣诲姞CORS鍝嶅簲澶� - 鍏抽敭閰嶇疆鐢ㄤ簬瑙e喅璺ㄥ煙闂 + Response.Headers.Add("Access-Control-Allow-Origin", "*"); + Response.Headers.Add("Access-Control-Allow-Methods", "GET, OPTIONS"); + Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Authorization"); + Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition, Content-Length, Content-Type"); + + var service = new LljService(); + var fileBytes = service.GetFtpFile(itemNo, fileName, ftpServer); + + if (fileBytes == null || fileBytes.Length == 0) + { + return NotFound("鏂囦欢鍦‵TP鏈嶅姟鍣ㄤ笂涓嶅瓨鍦�"); + } + + var contentType = service.GetContentType(fileName); + fileName = fileName?.Trim().Replace("\r", "").Replace("\n", ""); + + // 璁剧疆姝g‘鐨凜ontent-Disposition鍝嶅簲澶翠互鏀寔鏂囦欢涓嬭浇 + var result = File(fileBytes, "application/octet-stream", fileName); + + // 纭繚Content-Disposition澶存纭缃紝鏀寔涓枃鏂囦欢鍚� + if (!string.IsNullOrEmpty(fileName)) + { + var encodedFileName = System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8); + Response.Headers.Add("Content-Disposition", $"attachment; filename*=UTF-8''{encodedFileName}"); + } + + return result; + } + catch (Exception ex) + { + return StatusCode(500, $"涓嬭浇鏂囦欢澶辫触锛歿ex.Message}"); + } + } + + [HttpOptions("PreviewFtpFile")] + [HttpOptions("DownloadFtpFile")] + public IActionResult HandleOptions() + { + // 澶勭悊CORS棰勬璇锋眰 + Response.Headers.Add("Access-Control-Allow-Origin", "*"); + Response.Headers.Add("Access-Control-Allow-Methods", "GET, OPTIONS"); + Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Authorization"); + Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition, Content-Length, Content-Type"); + Response.Headers.Add("Access-Control-Max-Age", "86400"); + + return Ok(); + } } \ No newline at end of file -- Gitblit v1.9.3