| | |
| | | using MES.Service.util; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Newtonsoft.Json.Linq; |
| | | using System.Web; |
| | | |
| | | namespace MESApplication.Controllers.QC; |
| | | |
| | |
| | | [HttpPost("getAll")] |
| | | public ResponseResult getAll([FromBody] JObject data) |
| | | { |
| | | var modify1Flag = Convert.ToInt32(data["modify1Flag"].ToString()); |
| | | var modify1Flag = Convert.ToInt32(data["modify1Flag"]?.ToString() ?? "0"); |
| | | try |
| | | { |
| | | dynamic resultInfos = new ExpandoObject(); |
| | |
| | | [HttpPost("getDaa001")] |
| | | public ResponseResult getDaa001([FromBody] JObject data) |
| | | { |
| | | var daa020 = data["daa020"].ToString(); |
| | | var item = data["item"].ToString(); |
| | | var daa020 = data["daa020"]?.ToString() ?? ""; |
| | | try |
| | | { |
| | | dynamic resultInfos = new ExpandoObject(); |
| | | var tbBillList = |
| | | new XJService().getDaa001(daa020, item); |
| | | var tbBillList = new XJService().getDaa001(daa020); |
| | | resultInfos.tbBillList = tbBillList; |
| | | return new ResponseResult |
| | | { |
| | | status = 0, |
| | | message = "OK", |
| | | data = resultInfos |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return ResponseResult.ResponseError(ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取工单详细信息(包含物料信息) |
| | | /// </summary> |
| | | [HttpPost("getWorkOrderWithItem")] |
| | | public ResponseResult getWorkOrderWithItem([FromBody] JObject data) |
| | | { |
| | | var daa020 = data["daa020"]?.ToString() ?? ""; |
| | | try |
| | | { |
| | | dynamic resultInfos = new ExpandoObject(); |
| | | var tbBillList = new XJService().getWorkOrderWithItem(daa020); |
| | | resultInfos.tbBillList = tbBillList; |
| | | return new ResponseResult |
| | | { |
| | |
| | | [HttpPost("getBoardItem")] |
| | | public ResponseResult getBoardItem([FromBody] JObject data) |
| | | { |
| | | var lineNo = data["lineNo"].ToString(); |
| | | var lineNo = data["lineNo"]?.ToString() ?? ""; |
| | | try |
| | | { |
| | | dynamic resultInfos = new ExpandoObject(); |
| | | var tbBillList = |
| | | new XJService().getBoardItem(lineNo); |
| | | // 按 itemNo 去重 |
| | | tbBillList = tbBillList.GroupBy(x => x.ItemNo).Select(g => g.First()).ToList(); |
| | | resultInfos.tbBillList = tbBillList; |
| | | return new ResponseResult |
| | | { |
| | |
| | | [HttpPost("getItem")] |
| | | public ResponseResult getItem([FromBody] JObject data) |
| | | { |
| | | var daa001 = data["daa001"].ToString(); |
| | | var daa001 = data["daa001"]?.ToString() ?? ""; |
| | | try |
| | | { |
| | | dynamic resultInfos = new ExpandoObject(); |
| | |
| | | [HttpPost("setJYItem")] |
| | | public ResponseResult setJYItem([FromBody] JObject data) |
| | | { |
| | | var itemNo = data["itemNo"].ToString(); |
| | | var itemNo = data["itemNo"]?.ToString() ?? ""; |
| | | try |
| | | { |
| | | dynamic resultInfos = new ExpandoObject(); |
| | |
| | | try |
| | | { |
| | | dynamic resultInfos = new ExpandoObject(); |
| | | var tbBillList = |
| | | new XJService().save(xjDto); |
| | | resultInfos.tbBillList = tbBillList; |
| | | var result = new XJService().save(xjDto); |
| | | |
| | | // 返回完整的XJDto对象,包含更新后的items |
| | | resultInfos.tbBillList = result; |
| | | resultInfos.xjDto = xjDto; // 包含完整的检验项目信息 |
| | | |
| | | return new ResponseResult |
| | | { |
| | | status = 0, |
| | |
| | | return ResponseResult.ResponseError(ex); |
| | | } |
| | | } |
| | | |
| | | //刷新检验项目 |
| | | [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 XJService().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); |
| | | } |
| | | } |
| | | |
| | | //提交检验 |
| | | [HttpPost("SjSubmit")] |
| | | public ResponseResult SjSubmit([FromBody] SJDto sjDto) |
| | | { |
| | | try |
| | | { |
| | | dynamic resultInfos = new ExpandoObject(); |
| | | var tbBillList = new XJService().SjSubmit(sjDto); |
| | | resultInfos.tbBillList = tbBillList; |
| | | return new ResponseResult |
| | | { |
| | | status = 0, |
| | | message = "OK", |
| | | data = resultInfos |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return ResponseResult.ResponseError(ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取有线体的部门列表 |
| | | /// </summary> |
| | | [HttpPost("getDepartmentsWithLines")] |
| | | public ResponseResult GetDepartmentsWithLines() |
| | | { |
| | | try |
| | | { |
| | | dynamic resultInfos = new ExpandoObject(); |
| | | var tbBillList = new XJService().GetDepartmentsWithLines(); |
| | | resultInfos.tbBillList = tbBillList; |
| | | return new ResponseResult |
| | | { |
| | | status = 0, |
| | | message = "OK", |
| | | data = resultInfos |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return ResponseResult.ResponseError(ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存部门选择 |
| | | /// </summary> |
| | | [HttpPost("saveDepartmentSelection")] |
| | | public ResponseResult SaveDepartmentSelection([FromBody] JObject data) |
| | | { |
| | | try |
| | | { |
| | | var id = Convert.ToDecimal(data["id"]); |
| | | var departmentId = data["departmentId"]?.ToString() ?? ""; |
| | | var departmentName = data["departmentName"]?.ToString() ?? ""; |
| | | |
| | | dynamic resultInfos = new ExpandoObject(); |
| | | var result = new XJService().SaveDepartmentSelection(id, departmentId, departmentName); |
| | | resultInfos.tbBillList = result; |
| | | return new ResponseResult |
| | | { |
| | | status = 0, |
| | | message = "OK", |
| | | data = resultInfos |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return ResponseResult.ResponseError(ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据部门ID获取该部门下的线体列表 |
| | | /// </summary> |
| | | [HttpPost("getLinesByDepartment")] |
| | | public ResponseResult GetLinesByDepartment([FromBody] JObject data) |
| | | { |
| | | try |
| | | { |
| | | var departmentId = data["departmentId"]?.ToString() ?? ""; |
| | | |
| | | dynamic resultInfos = new ExpandoObject(); |
| | | var tbBillList = new XJService().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">包含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 XJService().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 XJService(); |
| | | 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 XJService(); |
| | | 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}"); |
| | | } |
| | | } |
| | | |
| | | [HttpOptions("PreviewFtpFile")] |
| | | [HttpOptions("DownloadFtpFile")] |
| | | public IActionResult HandleOptions() |
| | | { |
| | | 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-Max-Age", "86400"); |
| | | return Ok(); |
| | | } |
| | | |
| | | |
| | | } |