| | |
| | | return Ok(); |
| | | } |
| | | |
| | | /// <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 XJService(); |
| | | 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 |
| | | { |
| | | var id = data["id"]?.ToString(); |
| | | |
| | | if (string.IsNullOrEmpty(id)) |
| | | { |
| | | return new ResponseResult |
| | | { |
| | | status = 1, |
| | | message = "检验项目ID不能为空", |
| | | data = null |
| | | }; |
| | | } |
| | | |
| | | // 调用服务方法删除图片 |
| | | var service = new XJService(); |
| | | var (status, message) = service.DeleteImageFromPicture(Convert.ToDecimal(id)); |
| | | |
| | | return new ResponseResult |
| | | { |
| | | status = status, |
| | | message = message, |
| | | data = null |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return new ResponseResult |
| | | { |
| | | status = 1, |
| | | message = $"删除图片失败:{ex.Message}", |
| | | data = null |
| | | }; |
| | | } |
| | | } |
| | | |
| | | |
| | | } |