From 2f11a821259c77d8e48bb0b83e7f01b0f529b10a Mon Sep 17 00:00:00 2001
From: wbc <2597324127@qq.com>
Date: 星期三, 23 四月 2025 11:16:02 +0800
Subject: [PATCH] 3月27号首检巡检增加ftp获取文件列表
---
MESApplication/Controllers/QC/XJController.cs | 128 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 128 insertions(+), 0 deletions(-)
diff --git a/MESApplication/Controllers/QC/XJController.cs b/MESApplication/Controllers/QC/XJController.cs
index 9849c34..ce0142a 100644
--- a/MESApplication/Controllers/QC/XJController.cs
+++ b/MESApplication/Controllers/QC/XJController.cs
@@ -495,4 +495,132 @@
return ResponseResult.ResponseError(ex);
}
}
+
+ //FTPLIST
+ [HttpPost("ftpList")]
+ public async Task<ResponseResult> getFtpList([FromBody] JObject data)
+ {
+ var itemno = data["itemno"]?.ToString();
+
+ if (itemno == null || itemno == "") return new ResponseResult
+ {
+ status = 1,
+ message = "鏈壘鍒拌浜у搧鐨勬枃浠朵俊鎭�",
+ data = "鏈壘鍒拌浜у搧鐨勬枃浠朵俊鎭�"
+ };
+
+ var ftpAddress = "ftp://192.168.1.223:21";
+ var username = "administrator";
+ var password = "Rdyl8888";
+ var remotePath = "PQC/XJ/" + itemno;
+
+
+ try
+ {
+ dynamic resultInfos = new ExpandoObject();
+
+ var ftpFiles = new SJService().GetFtpFileList(ftpAddress, username, password, remotePath);
+ resultInfos.tbBillList = ftpFiles;
+ return new ResponseResult
+ {
+ status = 0,
+ message = "OK",
+ data = resultInfos
+ };
+ }
+ catch (Exception ex)
+ {
+ return ResponseResult.ResponseError(ex);
+ }
+ }
+
+
+
+ [HttpPost("download")]
+ public async Task<IActionResult> DownloadFile([FromBody] JObject data)
+ {
+ var fileName = data["fileName"]?.ToString();
+ var itemno = data["itemno"]?.ToString();
+
+ var ftpAddress = "ftp://192.168.1.223:21";
+ var username = "administrator";
+ var password = "Rdyl8888";
+ var remotePath = "PQC/XJ/" + itemno;
+
+ try
+ {
+ byte[] fileData = new SJService().DownloadFtpFile(ftpAddress, username, password, $"{remotePath}/{fileName}"); // 鎷兼帴瀹屾暣璺緞
+
+ // 鐢熸垚涓存椂璁块棶 URL锛堢ず渚嬮�昏緫锛�
+ var tempFileId = Guid.NewGuid().ToString();
+ // 灏嗘枃浠剁紦瀛樺埌涓存椂鐩綍锛堝疄闄呴」鐩渶鑰冭檻娓呯悊鏈哄埗锛�
+ var tempPath = Path.Combine(Path.GetTempPath(), tempFileId);
+ System.IO.File.WriteAllBytes(tempPath, fileData);
+
+ // 杩斿洖鍙洿鎺ヨ闂殑 URL
+ var baseUrl = $"{Request.Scheme}://{Request.Host}";
+
+
+
+ return Ok(new ResponseResult
+ {
+ status = 0,
+ message = "OK",
+ data = new
+ {
+ url = $"{baseUrl}/api/XJ/downloadTemp?fileId={tempFileId}&fileName={fileName}",
+ mimeType = GetMimeType(fileName)
+ }
+ });
+ }
+ catch (Exception ex)
+ {
+ return BadRequest(ResponseResult.ResponseError(ex));
+ }
+ }
+
+
+ private string GetMimeType(string fileName)
+ {
+ string mimeType = "application/octet-stream";
+ if (fileName.EndsWith(".jpg") || fileName.EndsWith(".jpeg"))
+ {
+ mimeType = "image/jpeg";
+ }
+ else if (fileName.EndsWith(".png"))
+ {
+ mimeType = "image/png";
+ }
+ else if (fileName.EndsWith(".gif"))
+ {
+ mimeType = "image/gif";
+ }
+ else if (fileName.EndsWith(".pdf"))
+ {
+ mimeType = "application/pdf";
+ }
+ else if (fileName.EndsWith(".doc") || fileName.EndsWith(".docx"))
+ {
+ mimeType = "application/msword";
+ }
+ else if (fileName.EndsWith(".xls") || fileName.EndsWith(".xlsx"))
+ {
+ mimeType = "application/vnd.ms-excel";
+ }
+ return mimeType;
+ }
+
+
+ [HttpGet("downloadTemp")]
+ public IActionResult DownloadTemp(string fileId, string fileName)
+ {
+ var tempPath = Path.Combine(Path.GetTempPath(), fileId);
+ if (!System.IO.File.Exists(tempPath))
+ {
+ return NotFound();
+ }
+ var fileBytes = System.IO.File.ReadAllBytes(tempPath);
+ return File(fileBytes, GetMimeType(fileName), fileName);
+ }
+
}
\ No newline at end of file
--
Gitblit v1.9.3