| | |
| | | try |
| | | { |
| | | dynamic resultInfos = new ExpandoObject(); |
| | | var tbBillList = |
| | | new SJService().getPage(queryObj); |
| | | resultInfos.tbBillList = tbBillList; |
| | | var (items, totalCount) = new SJService().getPage(queryObj); |
| | | resultInfos.tbBillList = items; |
| | | return new ResponseResult |
| | | { |
| | | status = 0, |
| | | message = "OK", |
| | | data = resultInfos |
| | | data = resultInfos, |
| | | TotalCount = totalCount |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | |
| | | 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(); |
| | | decimal? mnum = data["mnum"]?.ToObject<decimal?>(); |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取附件信息 |
| | | /// </summary> |
| | | /// <param name="data">包含itemNo和projName的JSON对象</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(); |
| | | |
| | | // 根据来源页面决定是否过滤 |
| | | string filterProjName = null; |
| | | if (fromPage == "Detail" && !string.IsNullOrEmpty(projName)) |
| | | { |
| | | filterProjName = projName; // Detail页面需要过滤 |
| | | } |
| | | // Add页面不传递filterProjName,显示所有附件 |
| | | |
| | | try |
| | | { |
| | | dynamic resultInfos = new System.Dynamic.ExpandoObject(); |
| | | var tbBillList = new SJService().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="ftpServer">FTP服务器地址</param> |
| | | /// <param name="projName">项目名称</param> |
| | | /// <returns>文件内容</returns> |
| | | [HttpGet("PreviewFtpFile")] |
| | | public IActionResult PreviewFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer, [FromQuery] string projName = null) |
| | | { |
| | | try |
| | | { |
| | | var fileBytes = new SJService().GetFtpFile(itemNo, fileName, ftpServer, projName); |
| | | 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 |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 下载FTP文件 |
| | | /// </summary> |
| | | /// <param name="itemNo">物料编码</param> |
| | | /// <param name="fileName">文件名</param> |
| | | /// <param name="ftpServer">FTP服务器地址</param> |
| | | /// <param name="projName">项目名称</param> |
| | | /// <returns>文件下载</returns> |
| | | [HttpGet("DownloadFtpFile")] |
| | | public IActionResult DownloadFtpFile([FromQuery] string itemNo, [FromQuery] string fileName, [FromQuery] string ftpServer, [FromQuery] string projName = null) |
| | | { |
| | | try |
| | | { |
| | | var fileBytes = new SJService().GetFtpFile(itemNo, fileName, ftpServer, projName); |
| | | 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 |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传图片到检验项目的PICTURE字段 |
| | | /// </summary> |
| | | /// <param name="file">上传的图片文件</param> |
| | | /// <param name="id">检验项目ID</param> |
| | | /// <param name="gid">检验单ID</param> |
| | | /// <param name="billNo">工单号</param> |
| | | /// <param name="createBy">创建人</param> |
| | | /// <returns>上传结果</returns> |
| | | [HttpPost("UploadImageToPicture")] |
| | | public ResponseResult UploadImageToPicture(IFormFile file, [FromForm] string id, [FromForm] string gid, [FromForm] string billNo, [FromForm] string createBy) |
| | | { |
| | | try |
| | | { |
| | | // 参数验证 |
| | | if (file == null || file.Length == 0) |
| | | { |
| | | return new ResponseResult |
| | | { |
| | | status = 1, |
| | | message = "请选择要上传的图片文件", |
| | | data = null |
| | | }; |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(id)) |
| | | { |
| | | return new ResponseResult |
| | | { |
| | | status = 1, |
| | | message = "检验项目ID不能为空", |
| | | data = null |
| | | }; |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(createBy)) |
| | | { |
| | | return new ResponseResult |
| | | { |
| | | status = 1, |
| | | message = "创建人不能为空", |
| | | data = null |
| | | }; |
| | | } |
| | | |
| | | // 读取文件字节数组 |
| | | byte[] imageBytes; |
| | | using (var memoryStream = new MemoryStream()) |
| | | { |
| | | file.CopyTo(memoryStream); |
| | | imageBytes = memoryStream.ToArray(); |
| | | } |
| | | |
| | | // 调用服务方法保存图片 |
| | | var service = new SJService(); |
| | | var (status, message) = service.UploadImageToPicture(Convert.ToDecimal(id), imageBytes, file.FileName, createBy); |
| | | |
| | | return new ResponseResult |
| | | { |
| | | status = status, |
| | | message = message, |
| | | data = null |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return new ResponseResult |
| | | { |
| | | status = 1, |
| | | message = $"上传图片失败:{ex.Message}", |
| | | data = null |
| | | }; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除检验项目的图片 |
| | | /// </summary> |
| | | /// <param name="data">包含检验项目ID的JSON数据</param> |
| | | /// <returns>删除结果</returns> |
| | | [HttpPost("DeleteImageFromPicture")] |
| | | public ResponseResult DeleteImageFromPicture([FromBody] JObject data) |
| | | { |
| | | try |
| | | { |
| | | if (data["id"] == null) |
| | | { |
| | | return new ResponseResult |
| | | { |
| | | status = 1, |
| | | message = "检验项目ID不能为空", |
| | | data = null |
| | | }; |
| | | } |
| | | |
| | | var id = Convert.ToDecimal(data["id"].ToString()); |
| | | |
| | | // 调用服务方法删除图片 |
| | | var service = new SJService(); |
| | | var (status, message) = service.DeleteImageFromPicture(id); |
| | | |
| | | return new ResponseResult |
| | | { |
| | | status = status, |
| | | message = message, |
| | | data = null |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return new ResponseResult |
| | | { |
| | | status = 1, |
| | | message = $"删除图片失败:{ex.Message}", |
| | | data = null |
| | | }; |
| | | } |
| | | } |
| | | } |