| | |
| | | using MES.Service.util; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Newtonsoft.Json.Linq; |
| | | using System.Web; |
| | | |
| | | namespace MESApplication.Controllers.QC; |
| | | |
| | |
| | | return ResponseResult.ResponseError(ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存下拉框字段(不良原因、评审状态、所属车间) |
| | | /// </summary> |
| | | /// <param name="rkjDto">包含字段数据的DTO</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和fngDesc的JSON对象</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的JSON对象</param> |
| | | /// <returns>附件列表</returns> |
| | | [HttpPost("getAttachments")] |
| | | public ResponseResult GetAttachments([FromBody] JObject data) |
| | | { |
| | | var itemNo = data["itemNo"]?.ToString(); |
| | | try |
| | | { |
| | | dynamic resultInfos = new System.Dynamic.ExpandoObject(); |
| | | var tbBillList = new RKJService().GetAttachments(itemNo); |
| | | 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="ftpServer">FTP服务器地址</param> |
| | | /// <returns>文件内容</returns> |
| | | [HttpGet("PreviewFtpFile")] |
| | | public IActionResult PreviewFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer) |
| | | { |
| | | 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, ftpServer); |
| | | |
| | | if (fileBytes == null || fileBytes.Length == 0) |
| | | { |
| | | return NotFound("文件在FTP服务器上不存在"); |
| | | } |
| | | |
| | | 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="ftpServer">FTP服务器地址</param> |
| | | /// <returns>文件下载</returns> |
| | | [HttpGet("DownloadFtpFile")] |
| | | public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer) |
| | | { |
| | | 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, Authorization"); |
| | | Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition, Content-Length, Content-Type"); |
| | | |
| | | var service = new RKJService(); |
| | | var fileBytes = service.GetFtpFile(itemNo, fileName, ftpServer); |
| | | |
| | | if (fileBytes == null || fileBytes.Length == 0) |
| | | { |
| | | return NotFound("文件在FTP服务器上不存在"); |
| | | } |
| | | |
| | | var contentType = service.GetContentType(fileName); |
| | | fileName = fileName?.Trim().Replace("\r", "").Replace("\n", ""); |
| | | |
| | | // 设置正确的Content-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(); |
| | | } |
| | | } |