From 3f9d7eb876f6d60d92e7f8a71240097b6ac50eb6 Mon Sep 17 00:00:00 2001 From: chengsc <11752@DESKTOP-DS49RCP> Date: 星期五, 23 五月 2025 18:16:42 +0800 Subject: [PATCH] 修改测试问题 --- Wms/Wms/Controllers/BllQualityController.cs | 149 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 140 insertions(+), 9 deletions(-) diff --git a/Wms/Wms/Controllers/BllQualityController.cs b/Wms/Wms/Controllers/BllQualityController.cs index 9f93f4b..61409bf 100644 --- a/Wms/Wms/Controllers/BllQualityController.cs +++ b/Wms/Wms/Controllers/BllQualityController.cs @@ -9,6 +9,11 @@ using Model.ModelVm; using Wms.Tools; using Microsoft.Extensions.Options; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Linq; + namespace Wms.Controllers { @@ -164,13 +169,8 @@ } } - /// <summary> - /// 鍙戦�佽楠屽崟鎹� - /// </summary> - /// <param name="model">涓婚敭ID</param> - /// <returns></returns> [HttpPost] - public IActionResult SendInspectionRequest(IdVm model) + public IActionResult upLoadRequest(IdVm model) { try { @@ -186,16 +186,16 @@ } var userName = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier)?.Value; - string url = _config.WcsHost + _config.IssueComApiUrl; - var models = _inspectionRequestServer.SendInspectionRequest(model, int.Parse(userId),url,userName); - return Ok(new { code = 0, count=0, msg = "鍚慙imes璇烽獙鎴愬姛!", data = models }); + return Ok(new { code = 0, count = 0, msg = "涓婁紶鍥剧墖鎴愬姛!"}); } catch (Exception e) { return Ok(new { code = 1, msg = e.Message }); } } + + /// <summary> /// 鍒犻櫎璇烽獙鍗曚俊鎭� @@ -292,6 +292,137 @@ return Ok(new { code = 1, msg = e.Message }); } } + + /// <summary> + /// 鍥剧墖涓婁紶 + /// </summary> + /// <param name="file"></param> + /// <param name="qualityId"></param> + /// <returns></returns> + [HttpPost] + public async Task<IActionResult> UploadImage([FromForm] IFormFile file, [FromForm] int qualityId) + { + try + { + var claimsIdentity = this.User.Identity as ClaimsIdentity; + var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; + if (file == null || file.Length == 0) + return BadRequest(new { code = 1, msg = "璇烽�夋嫨涓婁紶鏂囦欢" }); + + // 楠岃瘉鏂囦欢绫诲瀷 + var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif" }; + var fileExtension = Path.GetExtension(file.FileName).ToLower(); + if (!allowedExtensions.Contains(fileExtension)) + return BadRequest(new { code = 2, msg = "鍙厑璁镐笂浼犲浘鐗囨枃浠�" }); + + // 闄愬埗鏂囦欢澶у皬 (5MB) + if (file.Length > 5 * 1024 * 1024) + return BadRequest(new { code = 3, msg = "鏂囦欢澶у皬涓嶈兘瓒呰繃5MB" }); + + // 鍒涘缓璐ㄩ噺鐩稿叧鐨勫浘鐗囩洰褰� + var uploadPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwRoot", "uploads", "quality", qualityId.ToString()); + if (!Directory.Exists(uploadPath)) + Directory.CreateDirectory(uploadPath); + + // 鐢熸垚鍞竴鏂囦欢鍚� + var fileName = $"{DateTime.Now:yyyyMMddHHmmss}_{userId}{fileExtension}"; + var filePath = Path.Combine(uploadPath, fileName); + + // 淇濆瓨鏂囦欢 + using (var stream = new FileStream(filePath, FileMode.Create)) + { + await file.CopyToAsync(stream); + } + + // 杩斿洖鏂囦欢璁块棶璺緞 + var fileUrl = $"/wwwRoot/uploads/quality/{qualityId}/{fileName}"; + + // 杩欓噷鍙互娣诲姞鏁版嵁搴撹褰曠瓑鎿嶄綔 + // _qualityService.AddImageRecord(qualityId, userId, fileUrl, fileName); + + return Ok(new + { + code = 0, + msg = "涓婁紶鎴愬姛", + data = new + { + url = fileUrl, + fileName = fileName + } + }); + } + catch (Exception ex) + { + return StatusCode(500, new { code = 500, msg = $"涓婁紶澶辫触: {ex.Message}" }); + } + } + + /// <summary> + /// 鍥剧墖鑾峰彇 + /// </summary> + /// <param name="model"></param> + /// <returns></returns> + [HttpPost] + public IActionResult GetImage(BllQualityInspect model) + { + try + { + + var fullPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwRoot", "uploads", "quality", model.Id.ToString()); + if (!Directory.Exists(fullPath)) + { + return StatusCode(1, new { code = 1, msg = "鍥剧墖涓嶅瓨鍦�" }); + } + var files = Directory.GetFiles(fullPath); + if (files.Length <= 0) + return StatusCode(1, new { code = 1, msg = "鍥剧墖涓嶅瓨鍦�" }); + List<string> images = new List<string>(); + foreach (var file in files) + { + images.Add($"{Request.Scheme}://{Request.Host}/uploads/quality/{model.Id.ToString()}/{Path.GetFileName(file)}"); + } + return Ok(new + { + code = 0, + msg = "鍥剧墖" + files.Length + "寮�", + data = images + }); + } + catch (Exception ex) + { + return StatusCode(500, new { code = 500, msg = $"鑾峰彇鍥剧墖澶辫触: {ex.Message}" }); + } + } + + /// <summary> + /// 鍒犻櫎鍥剧墖 + /// </summary> + /// <param name="data">鍥剧墖淇℃伅</param> + /// <returns></returns> + [HttpPost] + public IActionResult DeleteImage(QualityImageVM data) + { + try + { + string fileName = Path.GetFileName(data.ImageUrl); + + var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwRoot", "uploads", "quality", data.QualityId.ToString(), fileName); + if (System.IO.File.Exists(filePath)) + { + System.IO.File.Delete(filePath); + + return Ok(new { code = 0, msg = "鍒犻櫎鎴愬姛" }); + } + else + { + return Ok(new { code = 1, msg = "鍥剧墖涓嶅瓨鍦�" }); + } + } + catch (Exception ex) + { + return Ok(new { code = 1, msg = ex.Message }); + } + } #endregion } } -- Gitblit v1.8.0