From 597f8e08e6264b2143454e40a7be553d1e8b6df7 Mon Sep 17 00:00:00 2001 From: sjz <1240968267@qq.com> Date: 星期五, 09 五月 2025 17:04:19 +0800 Subject: [PATCH] 2025/5/9 沈 --- StandardInterface/MESApplication/Controllers/PLM/PLMController.cs | 125 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 125 insertions(+), 0 deletions(-) diff --git a/StandardInterface/MESApplication/Controllers/PLM/PLMController.cs b/StandardInterface/MESApplication/Controllers/PLM/PLMController.cs new file mode 100644 index 0000000..902e37a --- /dev/null +++ b/StandardInterface/MESApplication/Controllers/PLM/PLMController.cs @@ -0,0 +1,125 @@ +锘縰sing ConsoleApp1; +using MES.Service.service.PLM; +using MES.Service.util; +using Microsoft.AspNetCore.Mvc; +using System.Dynamic; +using System.IO; + +namespace MESApplication.Controllers.PLM; + + +[ApiController] +[Route("api/PLM")] +public class PLMController : ControllerBase +{ + private readonly PLMManager m = new(); + private readonly WarehouseDownloadDoc wdd = new(); + + //RetrieveDrawings 璋冨彇鍥剧焊 + [HttpPost("RetrieveDrawings")] + public ResponseResult RetrieveDrawings(string ItemNo) + { + try + { + dynamic resultInfos = new ExpandoObject(); + resultInfos = m.RetrieveDrawings(ItemNo); + + return new ResponseResult + { + status = 0, + message = "OK", + data = resultInfos + }; + } + catch (Exception ex) + { + return ResponseResult.ResponseError(ex); + } + } + + //RetrieveImageFile 璋冨彇涓婁紶鍒版湇鍔″櫒鐨勬媿鎽勬枃浠� + [HttpGet("GetImageNames")] + public IActionResult GetImageNames(string releaseNo) + { + // 鎷兼帴鏈湴鏂囦欢绯荤粺璺緞 + string basePath = @"D:\MES_FTP\IQC\"; // 鏈嶅姟鍣―鐩樹笅鐨勫熀纭�璺緞 + string folderPath = Path.Combine(basePath, releaseNo); // 鍔ㄦ�佹嫾鎺ュ崟鍙峰搴旂殑鏂囦欢澶硅矾寰� + + // 妫�鏌ユ枃浠跺す鏄惁瀛樺湪 + if (!Directory.Exists(folderPath)) + { + return NotFound($"鏂囦欢澶� {folderPath} 涓嶅瓨鍦ㄣ�傝妫�鏌ヨ矾寰勬槸鍚︽纭��"); + } + + // 鑾峰彇鏂囦欢澶逛腑鐨勬墍鏈夊浘鐗囨枃浠跺悕绉� + string[] imageExtensions = { ".jpg", ".jpeg", ".png", ".gif", ".bmp" }; + // 鑾峰彇鏂囦欢鐨勫畬鏁磋矾寰勶紝骞惰繑鍥炰竴涓寘鍚枃浠跺悕鍜屽畬鏁磋矾寰勭殑瀵硅薄 + var imageFiles = Directory.GetFiles(folderPath) + .Where(file => imageExtensions.Any(ext => file.ToLower().EndsWith(ext))) + .Select(file => new + { + FileName = Path.GetFileName(file), // 鏂囦欢鍚� + FilePath = file, + FileBasePath = ConvertFileToBase64(file) // 鏂囦欢鐨� Base64 鏁版嵁 // 鏂囦欢鐨勫畬鏁磋矾寰� + }); + + return Ok(new { success = true, data = imageFiles }); + } + private string ConvertFileToBase64(string filePath) + { + byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); + return Convert.ToBase64String(fileBytes); + } + + [HttpPost("DeleteImageFile")] + public IActionResult DeleteImageFile([FromQuery] string filePath) + { + // 妫�鏌ユ枃浠惰矾寰勬槸鍚︿负绌� + if (string.IsNullOrWhiteSpace(filePath)) + { + return BadRequest("鏂囦欢璺緞涓嶈兘涓虹┖"); + } + + // 纭繚璺緞鏄粷瀵硅矾寰勶紙鍙互鏍规嵁闇�瑕佽皟鏁达級 + filePath = Path.GetFullPath(filePath); + + // 妫�鏌ユ枃浠舵槸鍚﹀瓨鍦� + if (!System.IO.File.Exists(filePath)) + { + return NotFound("鏂囦欢涓嶅瓨鍦�"); + } + + try + { + // 鍒犻櫎鏂囦欢 + System.IO.File.Delete(filePath); + return Ok("鏂囦欢鍒犻櫎鎴愬姛"); + } + catch (System.Exception ex) + { + // 鎹曡幏寮傚父骞惰繑鍥為敊璇俊鎭� + return StatusCode(500, $"鍒犻櫎鏂囦欢鏃跺彂鐢熼敊璇�: {ex.Message}"); + } + } + + //RetrieveDrawings 璋冨彇鍥剧焊 + [HttpPost("OpenDrawings")] + public IActionResult OpenDrawings(string fileId,string fName) + { + try + { + var resultInfos = wdd.SendRequest("Download", fileId); + + return File(resultInfos, "application/octet-stream", fName); + } + catch (Exception ex) + { + return StatusCode(500, new ResponseResult + { + status = 1, + message = ex.Message, + data = null + }); + } + } +} -- Gitblit v1.9.3