| | |
| | | public byte[]? Picture { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 图片名称 |
| | | /// gongxu |
| | | /// </summary> |
| | | [Column("PICTURENAME")] |
| | | [SugarColumn(ColumnName = "PICTURENAME")] //用于SqlSugar |
| | | [StringLength(32, ErrorMessage = "Picturename长度不能超出32")] |
| | | public string? Picturename { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 图片名称 |
| | | /// </summary> |
| | | [Column("PICTURENAME")] |
| | | [SugarColumn(ColumnName = "TPICTURENAME")] //用于SqlSugar |
| | | [StringLength(32, ErrorMessage = "Picturename长度不能超出32")] |
| | | public string? TPicturename { get; set; } |
| | | |
| | | [Column("Remarks")] |
| | | [SugarColumn(ColumnName = "Remarks")] //用于SqlSugar |
| | | [StringLength(200, ErrorMessage = "备注不能超出200")] |
| | |
| | | if (StringUtil.IsNotNullOrEmpty(queryObj.createUser)) |
| | | lineNo = _baseService.getUserLineNo(queryObj.createUser); |
| | | |
| | | |
| | | return db |
| | | .Queryable<QsItemOqcReq, Womdaa, MesItems>((a, da, b) => |
| | | new JoinQueryInfos( |
| | |
| | | !"未完成".Equals(queryObj.result), |
| | | (a, da, b) => a.FcheckResu != null && a.FcheckResu != "") |
| | | .WhereIF(id > 0, (a, da, b) => a.Id == id) |
| | | // 添加fsubmit字段过滤逻辑 |
| | | // 添加fsubmit字段过滤逻辑 - 只有在明确指定fsubmit参数时才过滤,且没有传递id时才过滤 |
| | | .WhereIF( |
| | | StringUtil.IsNotNullOrEmpty(queryObj.fsubmit) && queryObj.fsubmit == "1", |
| | | id <= 0 && StringUtil.IsNotNullOrEmpty(queryObj.fsubmit) && queryObj.fsubmit == "1", |
| | | (a, da, b) => a.Fsubmit == 1) |
| | | .WhereIF( |
| | | StringUtil.IsNullOrEmpty(queryObj.fsubmit) || queryObj.fsubmit == "0", |
| | | id <= 0 && StringUtil.IsNotNullOrEmpty(queryObj.fsubmit) && queryObj.fsubmit == "0", |
| | | (a, da, b) => a.Fsubmit == 0 || a.Fsubmit == null) |
| | | // 添加搜索条件 - 根据选择的搜索字段进行精确搜索 |
| | | .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "billNo", // 工单 |
| | |
| | | .ExecuteCommand(); |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传图片到检验项目的PICTURE字段 |
| | | /// </summary> |
| | | /// <param name="id">检验项目ID</param> |
| | | /// <param name="imageBytes">图片字节数组</param> |
| | | /// <param name="fileName">原始文件名</param> |
| | | /// <param name="createBy">创建人</param> |
| | | /// <returns>操作结果</returns> |
| | | public (int status, string message) UploadImageToPicture(decimal id, byte[] imageBytes, string fileName, string createBy) |
| | | { |
| | | try |
| | | { |
| | | if (imageBytes == null || imageBytes.Length == 0) |
| | | { |
| | | return (1, "图片数据为空"); |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(fileName)) |
| | | { |
| | | return (1, "文件名为空"); |
| | | } |
| | | |
| | | // 验证图片格式 |
| | | var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp" }; |
| | | var extension = System.IO.Path.GetExtension(fileName).ToLower(); |
| | | if (!allowedExtensions.Contains(extension)) |
| | | { |
| | | return (1, "不支持的图片格式,仅支持:jpg, jpeg, png, gif, bmp, webp"); |
| | | } |
| | | |
| | | // 验证图片大小(限制为5MB) |
| | | if (imageBytes.Length > 5 * 1024 * 1024) |
| | | { |
| | | return (1, "图片大小不能超过5MB"); |
| | | } |
| | | |
| | | // 生成时间戳文件名,格式:1746945271304.jpg |
| | | var timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); |
| | | var timestampFileName = $"{timestamp}{extension}"; |
| | | |
| | | var result = SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | // 检查检验项目是否存在 |
| | | var exists = db.Queryable<QsItemOqcItem>() |
| | | .Where(s => s.Id == id) |
| | | .Any(); |
| | | |
| | | if (!exists) |
| | | { |
| | | throw new Exception("检验项目不存在"); |
| | | } |
| | | |
| | | // 更新PICTURE字段(LONG RAW类型)和TPICTURENAME字段(时间戳文件名) |
| | | var updateResult = db.Updateable<QsItemOqcItem>() |
| | | .SetColumns(s => s.Picture == imageBytes) |
| | | .SetColumns(s => s.TPicturename == timestampFileName) |
| | | .Where(s => s.Id == id) |
| | | .ExecuteCommand(); |
| | | |
| | | return updateResult; |
| | | }); |
| | | |
| | | if (result > 0) |
| | | { |
| | | return (0, "图片保存成功"); |
| | | } |
| | | else |
| | | { |
| | | return (1, "图片保存失败,未找到对应的检验项目"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return (1, $"图片保存失败:{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除检验项目的图片 |
| | | /// </summary> |
| | | /// <param name="id">检验项目ID</param> |
| | | /// <returns>操作结果</returns> |
| | | public (int status, string message) DeleteImageFromPicture(decimal id) |
| | | { |
| | | try |
| | | { |
| | | var result = SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | // 检查检验项目是否存在 |
| | | var exists = db.Queryable<QsItemOqcItem>() |
| | | .Where(s => s.Id == id) |
| | | .Any(); |
| | | |
| | | if (!exists) |
| | | { |
| | | throw new Exception("检验项目不存在"); |
| | | } |
| | | |
| | | // 清空PICTURE字段和TPICTURENAME字段 |
| | | var updateResult = db.Updateable<QsItemOqcItem>() |
| | | .SetColumns(s => s.Picture == null) |
| | | .SetColumns(s => s.TPicturename == null) |
| | | .Where(s => s.Id == id) |
| | | .ExecuteCommand(); |
| | | |
| | | return updateResult; |
| | | }); |
| | | |
| | | if (result > 0) |
| | | { |
| | | return (0, "图片删除成功"); |
| | | } |
| | | else |
| | | { |
| | | return (1, "图片删除失败,未找到对应的检验项目"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return (1, $"图片删除失败:{ex.Message}"); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传图片到检验项目的PICTURE字段 |
| | | /// </summary> |
| | | /// <param name="id">检验项目ID</param> |
| | | /// <param name="imageBytes">图片字节数组</param> |
| | | /// <param name="fileName">原始文件名</param> |
| | | /// <param name="createBy">创建人</param> |
| | | /// <returns>操作结果</returns> |
| | | public (int status, string message) UploadImageToPicture(decimal id, byte[] imageBytes, string fileName, string createBy) |
| | | { |
| | | try |
| | | { |
| | | if (imageBytes == null || imageBytes.Length == 0) |
| | | { |
| | | return (1, "图片数据为空"); |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(fileName)) |
| | | { |
| | | return (1, "文件名为空"); |
| | | } |
| | | |
| | | // 验证图片格式 |
| | | var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp" }; |
| | | var extension = System.IO.Path.GetExtension(fileName).ToLower(); |
| | | if (!allowedExtensions.Contains(extension)) |
| | | { |
| | | return (1, "不支持的图片格式,仅支持:jpg, jpeg, png, gif, bmp, webp"); |
| | | } |
| | | |
| | | // 验证图片大小(限制为5MB) |
| | | if (imageBytes.Length > 5 * 1024 * 1024) |
| | | { |
| | | return (1, "图片大小不能超过5MB"); |
| | | } |
| | | |
| | | // 生成时间戳文件名,格式:1746945271304.jpg |
| | | var timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); |
| | | var timestampFileName = $"{timestamp}{extension}"; |
| | | |
| | | var result = SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | // 检查检验项目是否存在 |
| | | var exists = db.Queryable<QsItemIpiItem>() |
| | | .Where(s => s.Id == id) |
| | | .Any(); |
| | | |
| | | if (!exists) |
| | | { |
| | | throw new Exception("检验项目不存在"); |
| | | } |
| | | |
| | | // 更新PICTURE字段(LONG RAW类型)和PICTURENAME字段(时间戳文件名) |
| | | var updateResult = db.Updateable<QsItemIpiItem>() |
| | | .SetColumns(s => s.Picture == imageBytes) |
| | | .SetColumns(s => s.Picturename == timestampFileName) |
| | | .Where(s => s.Id == id) |
| | | .ExecuteCommand(); |
| | | |
| | | return updateResult; |
| | | }); |
| | | |
| | | if (result > 0) |
| | | { |
| | | return (0, "图片保存成功"); |
| | | } |
| | | else |
| | | { |
| | | return (1, "图片保存失败,未找到对应的检验项目"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return (1, $"图片保存失败:{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除检验项目的图片 |
| | | /// </summary> |
| | | /// <param name="id">检验项目ID</param> |
| | | /// <returns>操作结果</returns> |
| | | public (int status, string message) DeleteImageFromPicture(decimal id) |
| | | { |
| | | try |
| | | { |
| | | var result = SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | // 检查检验项目是否存在 |
| | | var exists = db.Queryable<QsItemIpiItem>() |
| | | .Where(s => s.Id == id) |
| | | .Any(); |
| | | |
| | | if (!exists) |
| | | { |
| | | throw new Exception("检验项目不存在"); |
| | | } |
| | | |
| | | // 清空PICTURE字段和PICTURENAME字段 |
| | | var updateResult = db.Updateable<QsItemIpiItem>() |
| | | .SetColumns(s => s.Picture == null) |
| | | .SetColumns(s => s.Picturename == null) |
| | | .Where(s => s.Id == id) |
| | | .ExecuteCommand(); |
| | | |
| | | return updateResult; |
| | | }); |
| | | |
| | | if (result > 0) |
| | | { |
| | | return (0, "图片删除成功"); |
| | | } |
| | | else |
| | | { |
| | | return (1, "图片删除失败,未找到对应的检验项目"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return (1, $"图片删除失败:{ex.Message}"); |
| | | } |
| | | } |
| | | } |
| | |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传图片到检验项目的PICTURE字段 |
| | | /// </summary> |
| | | /// <param name="id">检验项目ID</param> |
| | | /// <param name="imageBytes">图片字节数组</param> |
| | | /// <param name="fileName">原始文件名</param> |
| | | /// <param name="createBy">创建人</param> |
| | | /// <returns>操作结果</returns> |
| | | public (int status, string message) UploadImageToPicture(decimal id, byte[] imageBytes, string fileName, string createBy) |
| | | { |
| | | try |
| | | { |
| | | if (imageBytes == null || imageBytes.Length == 0) |
| | | { |
| | | return (1, "图片数据为空"); |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(fileName)) |
| | | { |
| | | return (1, "文件名为空"); |
| | | } |
| | | |
| | | // 验证图片格式 |
| | | var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp" }; |
| | | var extension = System.IO.Path.GetExtension(fileName).ToLower(); |
| | | if (!allowedExtensions.Contains(extension)) |
| | | { |
| | | return (1, "不支持的图片格式,仅支持:jpg, jpeg, png, gif, bmp, webp"); |
| | | } |
| | | |
| | | // 验证图片大小(限制为5MB) |
| | | if (imageBytes.Length > 5 * 1024 * 1024) |
| | | { |
| | | return (1, "图片大小不能超过5MB"); |
| | | } |
| | | |
| | | // 生成时间戳文件名,格式:1746945271304.jpg |
| | | var timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); |
| | | var timestampFileName = $"{timestamp}{extension}"; |
| | | |
| | | var result = SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | // 检查检验项目是否存在 |
| | | var exists = db.Queryable<QsQaItemXj01>() |
| | | .Where(s => s.Id == id) |
| | | .Any(); |
| | | |
| | | if (!exists) |
| | | { |
| | | throw new Exception("检验项目不存在"); |
| | | } |
| | | |
| | | // 更新PICTURE字段(LONG RAW类型)和PICTURENAME字段(时间戳文件名) |
| | | var updateResult = db.Updateable<QsQaItemXj01>() |
| | | .SetColumns(s => s.Picture == imageBytes) |
| | | .SetColumns(s => s.Picturename == timestampFileName) |
| | | .Where(s => s.Id == id) |
| | | .ExecuteCommand(); |
| | | |
| | | return updateResult; |
| | | }); |
| | | |
| | | if (result > 0) |
| | | { |
| | | return (0, "图片保存成功"); |
| | | } |
| | | else |
| | | { |
| | | return (1, "图片保存失败,未找到对应的检验项目"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return (1, $"图片保存失败:{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除检验项目的图片 |
| | | /// </summary> |
| | | /// <param name="id">检验项目ID</param> |
| | | /// <returns>操作结果</returns> |
| | | public (int status, string message) DeleteImageFromPicture(decimal id) |
| | | { |
| | | try |
| | | { |
| | | var result = SqlSugarHelper.UseTransactionWithOracle(db => |
| | | { |
| | | // 检查检验项目是否存在 |
| | | var exists = db.Queryable<QsQaItemXj01>() |
| | | .Where(s => s.Id == id) |
| | | .Any(); |
| | | |
| | | if (!exists) |
| | | { |
| | | throw new Exception("检验项目不存在"); |
| | | } |
| | | |
| | | // 清空PICTURE字段和PICTURENAME字段 |
| | | var updateResult = db.Updateable<QsQaItemXj01>() |
| | | .SetColumns(s => s.Picture == null) |
| | | .SetColumns(s => s.Picturename == null) |
| | | .Where(s => s.Id == id) |
| | | .ExecuteCommand(); |
| | | |
| | | return updateResult; |
| | | }); |
| | | |
| | | if (result > 0) |
| | | { |
| | | return (0, "图片删除成功"); |
| | | } |
| | | else |
| | | { |
| | | return (1, "图片删除失败,未找到对应的检验项目"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return (1, $"图片删除失败:{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | 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 RKJService(); |
| | | 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 RKJService(); |
| | | 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 |
| | | }; |
| | | } |
| | | } |
| | | } |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /// <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 |
| | | }; |
| | | } |
| | | } |
| | | } |
| | |
| | | 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 |
| | | }; |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | "AppSettings": { |
| | | "TestErpUrl": "http://192.168.11.120:8098/WebService1.asmx/mesToErpinfo", |
| | | "ProductionErpUrl": "http://192.168.11.120:8098/WebService1.asmx/mesToErpinfoFormal", |
| | | "DataBaseConn": "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521))(CONNECT_DATA = (SERVICE_NAME = ORCL))); Persist Security Info=True;User ID = hm_prd; Password=hmprd" |
| | | "DataBaseConn": "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521))(CONNECT_DATA = (SERVICE_NAME = ORCL))); Persist Security Info=True;User ID = test_dev; Password=hmprd" |
| | | } |
| | | } |