¶Ô±ÈÐÂÎļþ |
| | |
| | | using 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\"; // æå¡å¨Dçä¸çåºç¡è·¯å¾ |
| | | 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 |
| | | }); |
| | | } |
| | | } |
| | | } |