From 4998d0e8529e8cd369ee2285809ba60e8b982ad4 Mon Sep 17 00:00:00 2001 From: cnf <3200815559@qq.com> Date: 星期三, 05 三月 2025 14:00:13 +0800 Subject: [PATCH] --- MESApplication/Controllers/PLM/PLMController.cs | 65 ++++++++++++++++++++++++++++++++ 1 files changed, 65 insertions(+), 0 deletions(-) diff --git a/MESApplication/Controllers/PLM/PLMController.cs b/MESApplication/Controllers/PLM/PLMController.cs index 52846e6..e264562 100644 --- a/MESApplication/Controllers/PLM/PLMController.cs +++ b/MESApplication/Controllers/PLM/PLMController.cs @@ -37,6 +37,71 @@ } } + //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); + } + + [HttpDelete("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) -- Gitblit v1.9.3