using System.Dynamic; using MES.Service.Dto.service; using MES.Service.Modes; using MES.Service.service.QC; using MES.Service.util; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; namespace MESApplication.Controllers.QC; [Route("api/[controller]")] [ApiController] public class SJController : ControllerBase { [HttpPost("GetMaxBillNo")] public ResponseResult GetMaxBillNo() { try { dynamic resultInfos = new ExpandoObject(); var tbBillList = new SJService().getMaxBillNo(); resultInfos.tbBillList = tbBillList; return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } [HttpPost("GetPage")] public ResponseResult GetPage([FromBody] SJPageResult queryObj) { try { dynamic resultInfos = new ExpandoObject(); var (items, totalCount) = new SJService().getPage(queryObj); resultInfos.tbBillList = items; return new ResponseResult { status = 0, message = "OK", data = resultInfos, TotalCount = totalCount }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } //SetQSItems [HttpPost("SetQSItems")] public ResponseResult SetQSItems([FromBody] JObject data) { var itemNo = data["itemNo"].ToString(); try { dynamic resultInfos = new ExpandoObject(); var tbBillList = new SJService(); var detail021 = tbBillList.SetQSItems(itemNo); resultInfos.tbBillList = detail021; return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } [HttpPost("Save")] public ResponseResult Save([FromBody] QsItem item) { try { dynamic resultInfos = new ExpandoObject(); var tbBillList = new SJService(); var detail021 = tbBillList.Save(item); resultInfos.tbBillList = detail021; return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } //SaveItem [HttpPost("SaveItem")] public ResponseResult SaveItem([FromBody] QsItem item) { try { dynamic resultInfos = new ExpandoObject(); var tbBillList = new SJService(); var detail021 = tbBillList.SaveItem(item); resultInfos.tbBillList = detail021; return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } //getQSItems [HttpPost("getQSItems")] public ResponseResult getQSItems([FromBody] JObject data) { var pid = data["pid"]?.ToString(); var id = data["id"]?.ToString(); try { dynamic resultInfos = new ExpandoObject(); var tbBillList = new SJService(); var detail021 = tbBillList.getQSItems(Convert.ToDecimal(pid), Convert.ToDecimal(id)); resultInfos.tbBillList = detail021; return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } [HttpPost("SetQSItemDetail")] public ResponseResult SetQSItemDetail([FromBody] QsItemIpiItemDetail detail) { try { dynamic resultInfos = new ExpandoObject(); var tbBillList = new SJService(); var detail021 = tbBillList.SetQSItemDetail(detail); resultInfos.tbBillList = detail021; return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } [HttpPost("getQSItemDetail")] public ResponseResult getQSItemDetail([FromBody] JObject data) { var pid = data["pid"]?.ToString(); var gid = data["gid"]?.ToString(); try { dynamic resultInfos = new ExpandoObject(); var tbBillList = new SJService(); var detail021 = tbBillList.getQSItemDetail(Convert.ToDecimal(pid), Convert.ToDecimal(gid)); resultInfos.tbBillList = detail021; return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } [HttpPost("UpdateQSItemDetail")] public ResponseResult UpdateQSItemDetail( [FromBody] QsItemIpiItemDetail detail) { try { dynamic resultInfos = new ExpandoObject(); var tbBillList = new SJService(); var detail021 = tbBillList.UpdateQSItemDetail(detail); resultInfos.tbBillList = detail021; return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } //saveRemarksGid [HttpPost("saveRemarksGid")] public ResponseResult saveRemarksGid([FromBody] QsItem rkjDto) { try { dynamic resultInfos = new ExpandoObject(); var tbBillList = new SJService().saveRemarksGid(rkjDto); resultInfos.tbBillList = tbBillList; return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } //saveRemarksPid [HttpPost("saveRemarksPid")] public ResponseResult saveRemarksPid([FromBody] QsItem rkjDto) { try { dynamic resultInfos = new ExpandoObject(); var tbBillList = new SJService().saveRemarksPid(rkjDto); resultInfos.tbBillList = tbBillList; return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } //saveRemarksById [HttpPost("saveRemarksById")] public ResponseResult saveRemarksById([FromBody] QsItem rkjDto) { try { dynamic resultInfos = new ExpandoObject(); var tbBillList = new SJService().saveRemarksById(rkjDto); resultInfos.tbBillList = tbBillList; return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } //removeSJ [HttpPost("removeSJ")] public ResponseResult removeSJ([FromBody] JObject data) { var id = data["id"]?.ToString(); try { dynamic resultInfos = new ExpandoObject(); var tbBillList = new SJService().removeXJ(Convert.ToDecimal(id)); resultInfos.tbBillList = tbBillList; return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } //刷新检验项目 [HttpPost("GenUpdate")] public ResponseResult GenUpdate([FromBody] JObject data) { try { decimal? id = data["id"]?.ToObject(); string? no = data["no"]?.ToString(); string? user = data["user"]?.ToString(); decimal? mnum = data["mnum"]?.ToObject(); string? dnum = data["dnum"]?.ToString(); var (result, message) = new SJService().GenUpdate(id, no, user, mnum, dnum); 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 SJService().SjSubmit(sjDto); resultInfos.tbBillList = tbBillList; return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { return ResponseResult.ResponseError(ex); } } /// /// 获取附件信息 /// /// 包含itemNo的JSON对象 /// 附件列表 [HttpPost("getAttachments")] public ResponseResult GetAttachments([FromBody] JObject data) { var itemNo = data["itemNo"]?.ToString(); try { dynamic resultInfos = new System.Dynamic.ExpandoObject(); var tbBillList = new SJService().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); } } /// /// 预览FTP文件 /// /// 物料编码 /// 文件名 /// FTP服务器地址 /// 文件内容 [HttpGet("PreviewFtpFile")] public IActionResult PreviewFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer) { try { var fileBytes = new SJService().GetFtpFile(itemNo, fileName, ftpServer); if (fileBytes == null) { return NotFound(new ResponseResult { status = 1, message = "文件不存在或无法访问", data = null }); } var contentType = new SJService().GetContentType(fileName); return File(fileBytes, contentType, fileName); } catch (Exception ex) { return StatusCode(500, new ResponseResult { status = 1, message = ex.Message, data = null }); } } /// /// 下载FTP文件 /// /// 物料编码 /// 文件名 /// FTP服务器地址 /// 文件下载 [HttpGet("DownloadFtpFile")] public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer) { try { var fileBytes = new SJService().GetFtpFile(itemNo, fileName, ftpServer); if (fileBytes == null) { return NotFound(new ResponseResult { status = 1, message = "文件不存在或无法访问", data = null }); } var contentType = new SJService().GetContentType(fileName); // 设置下载响应头 Response.Headers.Add("Content-Disposition", $"attachment; filename=\"{fileName}\""); return File(fileBytes, contentType, fileName); } catch (Exception ex) { return StatusCode(500, new ResponseResult { status = 1, message = ex.Message, data = null }); } } }