From 0c7322109660b80e359118de04c0b9cc16a030e3 Mon Sep 17 00:00:00 2001
From: xwt <2740516069@qq.com>
Date: 星期五, 10 十月 2025 15:45:31 +0800
Subject: [PATCH] SJ,XJ,RKJ调用FTP附件
---
StandardInterface/MESApplication/Controllers/QC/RKJController.cs | 356 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 355 insertions(+), 1 deletions(-)
diff --git a/StandardInterface/MESApplication/Controllers/QC/RKJController.cs b/StandardInterface/MESApplication/Controllers/QC/RKJController.cs
index 3aea949..9ed886f 100644
--- a/StandardInterface/MESApplication/Controllers/QC/RKJController.cs
+++ b/StandardInterface/MESApplication/Controllers/QC/RKJController.cs
@@ -5,6 +5,7 @@
using MES.Service.util;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
+using System.Web;
namespace MESApplication.Controllers.QC;
@@ -87,7 +88,15 @@
public ResponseResult setJYItem([FromBody] JObject data)
{
var itemNo = data["itemNo"].ToString();
- var quantity = Convert.ToDecimal(data["quantity"].ToString());
+ var quantityStr = data["quantity"]?.ToString();
+
+ // 澶勭悊quantity涓虹┖鎴栨棤鏁堢殑鎯呭喌
+ decimal quantity = 0;
+ if (!string.IsNullOrEmpty(quantityStr) && decimal.TryParse(quantityStr, out var parsedQuantity))
+ {
+ quantity = parsedQuantity;
+ }
+
try
{
dynamic resultInfos = new ExpandoObject();
@@ -364,4 +373,349 @@
return ResponseResult.ResponseError(ex);
}
}
+
+ /// <summary>
+ /// 鑾峰彇鏈夌嚎浣撶殑閮ㄩ棬鍒楄〃锛堢敓浜ц溅闂达級
+ /// </summary>
+ /// <returns>閮ㄩ棬鍒楄〃</returns>
+ [HttpPost("GetDepartmentsWithLines")]
+ public ResponseResult GetDepartmentsWithLines()
+ {
+ try
+ {
+ dynamic resultInfos = new ExpandoObject();
+ var tbBillList = new RKJService().GetDepartmentsWithLines();
+ resultInfos.tbBillList = tbBillList;
+ return new ResponseResult
+ {
+ status = 0,
+ message = "OK",
+ data = resultInfos
+ };
+ }
+ catch (Exception ex)
+ {
+ return ResponseResult.ResponseError(ex);
+ }
+ }
+
+ /// <summary>
+ /// 鏍规嵁閮ㄩ棬ID鑾峰彇璇ラ儴闂ㄤ笅鐨勭嚎浣撳垪琛�
+ /// </summary>
+ /// <param name="data">鍖呭惈departmentId鐨凧SON瀵硅薄</param>
+ /// <returns>绾夸綋鍒楄〃</returns>
+ [HttpPost("GetLinesByDepartment")]
+ public ResponseResult GetLinesByDepartment([FromBody] JObject data)
+ {
+ var departmentId = data["departmentId"]?.ToString();
+ try
+ {
+ dynamic resultInfos = new ExpandoObject();
+ var tbBillList = new RKJService().GetLinesByDepartment(departmentId);
+ resultInfos.tbBillList = tbBillList;
+ return new ResponseResult
+ {
+ status = 0,
+ message = "OK",
+ data = resultInfos
+ };
+ }
+ catch (Exception ex)
+ {
+ return ResponseResult.ResponseError(ex);
+ }
+ }
+
+ /// <summary>
+ /// 淇濆瓨閮ㄩ棬閫夋嫨
+ /// </summary>
+ /// <param name="data">鍖呭惈id銆乨epartmentId銆乨epartmentName鐨凧SON瀵硅薄</param>
+ /// <returns>淇濆瓨缁撴灉</returns>
+ [HttpPost("SaveDepartmentSelection")]
+ public ResponseResult SaveDepartmentSelection([FromBody] JObject data)
+ {
+ var id = Convert.ToDecimal(data["id"]?.ToString());
+ var departmentId = data["departmentId"]?.ToString();
+ var departmentName = data["departmentName"]?.ToString();
+ try
+ {
+ dynamic resultInfos = new ExpandoObject();
+ var tbBillList = new RKJService().SaveDepartmentSelection(id, departmentId, departmentName);
+ resultInfos.tbBillList = tbBillList;
+ return new ResponseResult
+ {
+ status = 0,
+ message = "OK",
+ data = resultInfos
+ };
+ }
+ catch (Exception ex)
+ {
+ return ResponseResult.ResponseError(ex);
+ }
+ }
+
+ /// <summary>
+ /// 鎻愪氦妫�楠屽崟
+ /// </summary>
+ /// <param name="data">鍖呭惈id銆乽serNo鐨凧SON瀵硅薄</param>
+ /// <returns>鎻愪氦缁撴灉</returns>
+ [HttpPost("submitInspection")]
+ public ResponseResult SubmitInspection([FromBody] JObject data)
+ {
+ var id = Convert.ToDecimal(data["id"]?.ToString());
+ var userNo = data["userNo"]?.ToString();
+ try
+ {
+ dynamic resultInfos = new ExpandoObject();
+ var tbBillList = new RKJService().SubmitInspection(id, userNo);
+ resultInfos.tbBillList = tbBillList;
+ return new ResponseResult
+ {
+ status = 0,
+ message = "OK",
+ data = resultInfos
+ };
+ }
+ catch (Exception ex)
+ {
+ return ResponseResult.ResponseError(ex);
+ }
+ }
+
+ /// <summary>
+ /// 鍒锋柊妫�楠岄」鐩� - 璋冪敤瀛樺偍杩囩▼
+ /// </summary>
+ /// <param name="data">鍖呭惈id銆乶o銆乽ser鐨凧SON瀵硅薄</param>
+ /// <returns>鍒锋柊缁撴灉</returns>
+ [HttpPost("genUpdate")]
+ public ResponseResult GenUpdate([FromBody] JObject data)
+ {
+ try
+ {
+ decimal? id = data["id"]?.ToObject<decimal>();
+ string? no = data["no"]?.ToString();
+ string? user = data["user"]?.ToString();
+
+ var (result, message) = new RKJService().GenUpdate(id, no, user);
+
+ dynamic resultInfos = new ExpandoObject();
+ resultInfos.result = result;
+ resultInfos.message = message;
+
+ return new ResponseResult
+ {
+ status = 0,
+ message = "OK",
+ data = resultInfos
+ };
+ }
+ catch (Exception ex)
+ {
+ return ResponseResult.ResponseError(ex);
+ }
+ }
+
+ /// <summary>
+ /// 淇濆瓨涓嬫媺妗嗗瓧娈碉紙涓嶈壇鍘熷洜銆佽瘎瀹$姸鎬併�佹墍灞炶溅闂达級
+ /// </summary>
+ /// <param name="rkjDto">鍖呭惈瀛楁鏁版嵁鐨凞TO</param>
+ /// <returns>淇濆瓨缁撴灉</returns>
+ [HttpPost("saveDropdownFields")]
+ public ResponseResult SaveDropdownFields([FromBody] RKJDto rkjDto)
+ {
+ try
+ {
+ dynamic resultInfos = new ExpandoObject();
+ var tbBillList = new RKJService().SaveDropdownFields(rkjDto);
+ resultInfos.tbBillList = tbBillList;
+ return new ResponseResult
+ {
+ status = 0,
+ message = "OK",
+ data = resultInfos
+ };
+ }
+ catch (Exception ex)
+ {
+ return ResponseResult.ResponseError(ex);
+ }
+ }
+
+ /// <summary>
+ /// 淇濆瓨涓嶈壇鎻忚堪
+ /// </summary>
+ /// <param name="data">鍖呭惈gid鍜宖ngDesc鐨凧SON瀵硅薄</param>
+ /// <returns>淇濆瓨缁撴灉</returns>
+ [HttpPost("saveFngDesc")]
+ public ResponseResult SaveFngDesc([FromBody] JObject data)
+ {
+ try
+ {
+ var gid = Convert.ToDecimal(data["gid"]?.ToString());
+ var fngDesc = data["fngDesc"]?.ToString();
+
+ dynamic resultInfos = new ExpandoObject();
+ var tbBillList = new RKJService().SaveFngDesc(gid, fngDesc);
+ resultInfos.tbBillList = tbBillList;
+ return new ResponseResult
+ {
+ status = 0,
+ message = "OK",
+ data = resultInfos
+ };
+ }
+ catch (Exception ex)
+ {
+ return ResponseResult.ResponseError(ex);
+ }
+ }
+
+ /// <summary>
+ /// 鑾峰彇闄勪欢淇℃伅
+ /// </summary>
+ /// <param name="data">鍖呭惈itemNo銆乸rojName銆乫romPage鐨凧SON瀵硅薄</param>
+ /// <returns>闄勪欢鍒楄〃</returns>
+ [HttpPost("getAttachments")]
+ public ResponseResult GetAttachments([FromBody] JObject data)
+ {
+ var itemNo = data["itemNo"]?.ToString();
+ var projName = data["projName"]?.ToString();
+ var fromPage = data["fromPage"]?.ToString(); // 鏂板鍙傛暟
+
+ // 鏉′欢杩囨护閫昏緫锛氭牴鎹甪romPage鍐冲畾鏄惁杩囨护
+ string filterProjName = null;
+ if (fromPage == "Detail" && !string.IsNullOrEmpty(projName))
+ {
+ filterProjName = projName; // Detail椤甸潰闇�瑕佽繃婊�
+ }
+
+ try
+ {
+ dynamic resultInfos = new System.Dynamic.ExpandoObject();
+ var tbBillList = new RKJService().GetAttachments(itemNo, filterProjName);
+ if (tbBillList == null || tbBillList.Count == 0)
+ {
+ return new ResponseResult
+ {
+ status = 1,
+ message = "璇ユ楠屽崟鏈笂浼犻檮浠朵俊鎭紒",
+ data = null
+ };
+ }
+ resultInfos.tbBillList = tbBillList;
+ return new ResponseResult
+ {
+ status = 0,
+ message = "OK",
+ data = resultInfos
+ };
+ }
+ catch (Exception ex)
+ {
+ return ResponseResult.ResponseError(ex);
+ }
+ }
+
+ /// <summary>
+ /// 棰勮FTP鏂囦欢
+ /// </summary>
+ /// <param name="itemNo">鐗╂枡缂栫爜</param>
+ /// <param name="fileName">鏂囦欢鍚�</param>
+ /// <param name="projName">椤圭洰鍚嶇О</param>
+ /// <returns>鏂囦欢鍐呭</returns>
+ [HttpGet("previewFtpFile")]
+ public IActionResult PreviewFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string projName = null)
+ {
+ try
+ {
+ // 娣诲姞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 RKJService();
+ var fileBytes = service.GetFtpFile(itemNo, fileName, projName);
+
+ if (fileBytes == null || fileBytes.Length == 0)
+ {
+ return NotFound("鏂囦欢鍦‵TP鏈嶅姟鍣ㄤ笂涓嶅瓨鍦�");
+ }
+
+ var contentType = service.GetContentType(fileName);
+ fileName = fileName?.Trim().Replace("\r", "").Replace("\n", "");
+
+ return File(fileBytes, contentType);
+ }
+ catch (Exception ex)
+ {
+ return StatusCode(500, $"棰勮鏂囦欢澶辫触锛歿ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 涓嬭浇FTP鏂囦欢
+ /// </summary>
+ /// <param name="itemNo">鐗╂枡缂栫爜</param>
+ /// <param name="fileName">鏂囦欢鍚�</param>
+ /// <param name="projName">椤圭洰鍚嶇О</param>
+ /// <returns>鏂囦欢涓嬭浇</returns>
+ [HttpGet("downloadFtpFile")]
+ public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string projName = null)
+ {
+ 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 RKJService();
+ var fileBytes = service.GetFtpFile(itemNo, fileName, projName);
+
+ 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}");
+ }
+ }
+
+ /// <summary>
+ /// 澶勭悊CORS棰勬璇锋眰
+ /// </summary>
+ /// <returns>OK</returns>
+ [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