From 9f18954857e9c4c691fc2c8e83d7728abdc18f74 Mon Sep 17 00:00:00 2001
From: kazelee <1847801760@qq.com>
Date: 星期二, 08 七月 2025 17:54:22 +0800
Subject: [PATCH] 添加后台图片前台调用的图床接口备用,修复测试出现的问题

---
 HH.WCS.Mobox3.AnGang.csproj |    1 
 util/HttpHelper.cs          |   36 ++++++++
 dispatch/GZRobot.cs         |   18 +++-
 /dev/null                   |    0 
 api/AgvController.cs        |    2 
 api/ApiHelper.cs            |    2 
 .gitignore                  |    3 
 api/ImageController.cs      |  109 +++++++++++++++++++++++++++
 api/ApiModel.cs             |   20 ++--
 process/TaskProcess.cs      |   16 ++--
 10 files changed, 181 insertions(+), 26 deletions(-)

diff --git a/.gitignore b/.gitignore
index 1c38a68..25e3e17 100644
--- a/.gitignore
+++ b/.gitignore
@@ -184,3 +184,6 @@
 
 # Microsoft Fakes
 FakesAssemblies/
+FileContentIndex/
+/.vs/HH.WCS.Mobox3.AnGang/CopilotIndices/17.14.794.21998
+/.vs/HH.WCS.Mobox3.AnGang/v17
diff --git a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/2c811ea3-de97-45a8-bcd7-7c88a2af5604.vsidx b/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/2c811ea3-de97-45a8-bcd7-7c88a2af5604.vsidx
deleted file mode 100644
index 74230ec..0000000
--- a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/2c811ea3-de97-45a8-bcd7-7c88a2af5604.vsidx
+++ /dev/null
Binary files differ
diff --git a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/31c8165b-2f2b-45b9-85b4-57a0470f4da9.vsidx b/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/31c8165b-2f2b-45b9-85b4-57a0470f4da9.vsidx
deleted file mode 100644
index a9af623..0000000
--- a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/31c8165b-2f2b-45b9-85b4-57a0470f4da9.vsidx
+++ /dev/null
Binary files differ
diff --git a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/751eaf15-0a04-4bab-a16d-9f01e4e7f818.vsidx b/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/751eaf15-0a04-4bab-a16d-9f01e4e7f818.vsidx
deleted file mode 100644
index 6c1b67d..0000000
--- a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/751eaf15-0a04-4bab-a16d-9f01e4e7f818.vsidx
+++ /dev/null
Binary files differ
diff --git a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/db48a26a-6552-4d65-a5d9-3721c951a7fd.vsidx b/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/db48a26a-6552-4d65-a5d9-3721c951a7fd.vsidx
deleted file mode 100644
index 75249f2..0000000
--- a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/db48a26a-6552-4d65-a5d9-3721c951a7fd.vsidx
+++ /dev/null
Binary files differ
diff --git a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/read.lock b/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/read.lock
deleted file mode 100644
index e69de29..0000000
--- a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/read.lock
+++ /dev/null
diff --git a/HH.WCS.Mobox3.AnGang.csproj b/HH.WCS.Mobox3.AnGang.csproj
index a203388..3cf0433 100644
--- a/HH.WCS.Mobox3.AnGang.csproj
+++ b/HH.WCS.Mobox3.AnGang.csproj
@@ -260,6 +260,7 @@
     <Compile Include="api\ApiHelper.cs" />
     <Compile Include="api\DebugController.cs" />
     <Compile Include="api\ErpController.cs" />
+    <Compile Include="api\ImageController.cs" />
     <Compile Include="api\MoboxController.cs" />
     <Compile Include="api\AgvController.cs" />
     <Compile Include="api\ApiModel.cs" />
diff --git a/api/AgvController.cs b/api/AgvController.cs
index c222b93..653838f 100644
--- a/api/AgvController.cs
+++ b/api/AgvController.cs
@@ -30,7 +30,7 @@
         [Route("orderStatusReport")]
         public GzResult orderStatusReport(orderStatusReportParme model) {
             //LogHelper.Info("RCS鍥借嚜AGV浠诲姟鐘舵�鍥炴姤锛� + JsonConvert.SerializeObject(model), "HosttoagvTask");
-            LogRequestHeaders();
+            //LogRequestHeaders();
             return GZRobot.orderStatusReport(model);
         }
         
diff --git a/api/ApiHelper.cs b/api/ApiHelper.cs
index a5aa9e5..dd1f197 100644
--- a/api/ApiHelper.cs
+++ b/api/ApiHelper.cs
@@ -877,7 +877,7 @@
 
                     //cgDetailList.Add(cgDetail);
                 }
-                 
+                
                 using (var tran = db.Ado.UseTran()) {
                     if (deleteRecordOldList.Count != 0 && db.Deleteable<TN_Inbound_DataRecord>(deleteRecordOldList).ExecuteCommand() <= 0) {
                         tran.RollbackTran();
diff --git a/api/ApiModel.cs b/api/ApiModel.cs
index 07d84eb..b4d438b 100644
--- a/api/ApiModel.cs
+++ b/api/ApiModel.cs
@@ -55,6 +55,7 @@
         }
 
         public class orderStatusReportParme {
+            public int id { get; set; }
             /// <summary>
             /// 璁㈠崟ID
             /// </summary>
@@ -88,17 +89,6 @@
             /// 閿欒鐮�             /// </summary>
             public int errorCode { get; set; }
-
-            /// <summary>
-            /// 璁㈠崟鐨勬埅鑷虫椂闂�-            /// </summary>
-            public string deadLine { get; set; }
-
-            /// <summary>
-            /// 璁㈠崟鐨勫垱寤烘椂闂�-            /// </summary>
-            public string createdTime { get; set; }
-
             /// <summary>
             /// 棰濆淇℃伅1
             /// </summary>
@@ -108,8 +98,16 @@
             /// 棰濆淇℃伅2
             /// </summary>
             public string extraInfo2 { get; set; }
+            /// <summary>
+            /// 璁㈠崟鐨勬埅鑷虫椂闂�+            /// </summary>
+            public string deadLine { get; set; }
 
             /// <summary>
+            /// 璁㈠崟鐨勫垱寤烘椂闂�+            /// </summary>
+            public string createdTime { get; set; }
+            /// <summary>
             /// 鍒涘缓鐢ㄦ埛
             /// </summary>
             public string createUser { get; set; }
diff --git a/api/ImageController.cs b/api/ImageController.cs
new file mode 100644
index 0000000..41b034f
--- /dev/null
+++ b/api/ImageController.cs
@@ -0,0 +1,109 @@
+锘縰sing System;
+using System.IO;
+using System.Net;
+using System.Net.Http;
+using System.Web;
+using System.Web.Http;
+
+public class ImageController : ApiController {
+    private readonly string _baseStoragePath = HttpContext.Current.Server.MapPath("~/StaticStorage");
+    private readonly string[] _allowedExtensions = { ".jpg", ".jpeg", ".png", ".gif", ".bmp" };
+
+    // 涓婁紶鍥剧墖鎺ュ彛
+    [HttpPost]
+    [Route("api/image/upload")]
+    public HttpResponseMessage UploadImage() {
+        try {
+            if (!Request.Content.IsMimeMultipartContent()) {
+                return Request.CreateErrorResponse(HttpStatusCode.UnsupportedMediaType, "璇锋眰蹇呴』鍖呭惈澶氶儴鍒嗗唴瀹�);
+            }
+
+            var provider = new MultipartFormDataStreamProvider(Path.GetTempPath());
+            var result = Request.Content.ReadAsMultipartAsync(provider).Result;
+
+            if (result.FileData.Count == 0) {
+                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "鏈帴鏀跺埌鏂囦欢");
+            }
+
+            var fileData = result.FileData[0];
+            var fileName = fileData.Headers.ContentDisposition.FileName.Trim('"');
+            var fileExt = Path.GetExtension(fileName).ToLower();
+
+            if (Array.IndexOf(_allowedExtensions, fileExt) == -1) {
+                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "涓嶆敮鎸佺殑鏂囦欢绫诲瀷");
+            }
+
+            // 鐢熸垚鏃ユ湡璺緞
+            var now = DateTime.Now;
+            var year = now.ToString("yyyy");
+            var month = now.ToString("MM");
+            var day = now.ToString("dd");
+
+            // 鐢熸垚鍞竴鏂囦欢鍚�+            var newFileName = $"{now:yyyy-MM-dd-HHmmssfff}{fileExt}";
+
+            // 鐩爣璺緞
+            var targetPath = Path.Combine(_baseStoragePath, "image", year, month, day);
+
+            // 纭繚鐩綍瀛樺湪
+            Directory.CreateDirectory(targetPath);
+
+            // 瀹屾暣鏂囦欢璺緞
+            var fullPath = Path.Combine(targetPath, newFileName);
+
+            // 绉诲姩鏂囦欢鍒扮洰鏍囦綅缃�+            File.Move(fileData.LocalFileName, fullPath);
+
+            // 杩斿洖璁块棶URL
+            var url = $"{Request.RequestUri.Scheme}://{Request.RequestUri.Authority}/static/image/{year}/{month}/{day}/{newFileName}";
+
+            return Request.CreateResponse(HttpStatusCode.OK, new { Url = url });
+        }
+        catch (Exception ex) {
+            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
+        }
+    }
+
+    // 鑾峰彇鍥剧墖鎺ュ彛 - 瀹為檯鐢遍潤鎬佹枃浠跺鐞嗭紝杩欓噷鍙槸绀轰緥
+    [HttpGet]
+    [Route("static/image/{year}/{month}/{day}/{filename}")]
+    public HttpResponseMessage GetImage(string year, string month, string day, string filename) {
+        try {
+            var filePath = Path.Combine(_baseStoragePath, "image", year, month, day, filename);
+
+            if (!File.Exists(filePath)) {
+                return Request.CreateErrorResponse(HttpStatusCode.NotFound, "鏂囦欢涓嶅瓨鍦�);
+            }
+
+            var response = new HttpResponseMessage(HttpStatusCode.OK);
+            var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
+            response.Content = new StreamContent(stream);
+
+            // 鏍规嵁鏂囦欢鎵╁睍鍚嶈缃瓹ontentType
+            var ext = Path.GetExtension(filename).ToLower();
+            switch (ext) {
+                case ".jpg":
+                case ".jpeg":
+                    response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/jpeg");
+                    break;
+                case ".png":
+                    response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/png");
+                    break;
+                case ".gif":
+                    response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif");
+                    break;
+                case ".bmp":
+                    response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/bmp");
+                    break;
+                default:
+                    response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
+                    break;
+            }
+
+            return response;
+        }
+        catch (Exception ex) {
+            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
+        }
+    }
+}
\ No newline at end of file
diff --git a/dispatch/GZRobot.cs b/dispatch/GZRobot.cs
index 11692a7..f4a519f 100644
--- a/dispatch/GZRobot.cs
+++ b/dispatch/GZRobot.cs
@@ -1,13 +1,17 @@
 锘縰sing System;
 using System.Collections.Generic;
 using System.IdentityModel.Protocols.WSTrust;
+using System.Security.Policy;
 using System.Threading.Tasks;
-using HH.WCS.Mobox3.AnGang.util;
+
 using HH.WCS.Mobox3.AnGang.core;
 using HH.WCS.Mobox3.AnGang.models;
+using HH.WCS.Mobox3.AnGang.util;
+
 using Newtonsoft.Json;
-using static HH.WCS.Mobox3.AnGang.api.ApiModel;
+
 using static System.Net.WebRequestMethods;
+using static HH.WCS.Mobox3.AnGang.api.ApiModel;
 
 namespace HH.WCS.Mobox3.AnGang.dispatch {
     /// <summary>
@@ -261,7 +265,8 @@
             }
             else {
                 msg = "[guozi-UpdateInteractInfo]鏇存柊浜や簰淇℃伅澶辫触";
-                Console.WriteLine(msg);
+                //Console.WriteLine(msg);
+                LogHelper.Info(msg);
             }
             return result;
         }
@@ -270,13 +275,18 @@
         // DOC 5.	绉伴噸淇℃伅鏌ヨ
         public static List<CustomData> CustomBuf() {
             var res = new List<CustomData>();
+            
             string msg = "";
-            var result = apiHelper.Get(baseUrl + $"/api/engine/agvs/custom-buf/");
+            //var result = apiHelper.Get(baseUrl + $"/api/engine/agvs/custom-buf/", "application/json");
+            LogHelper.Info($"姝e湪璇锋眰GET: \"/api/engine/agvs/custom-buf/\"", "API");
+            var result = apiHelper.GetNew(baseUrl + $"api/engine/agvs/custom-buf/");
             if (!string.IsNullOrEmpty(result)) {
                 Console.WriteLine(result);
                 
                 try {
+                    LogHelper.Info($"绉伴噸淇℃伅锛� + result);
                     var data = JsonConvert.DeserializeObject<gzResult<CustomData>>(result);
+                    
                     if (data.data != null) {
                         res = data.data;
                     }
diff --git a/process/TaskProcess.cs b/process/TaskProcess.cs
index fb46b5b..bd092bd 100644
--- a/process/TaskProcess.cs
+++ b/process/TaskProcess.cs
@@ -115,15 +115,15 @@
                 var endSite = LocationHelper.GetAgvSite(mst.S_END_LOC); // 濡傛灉鎵句笉鍒颁細杩斿洖0锛屽氨鏄亣缁堢偣
 
                 var code = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, JsonConvert.SerializeObject(new { src = startSite, order_name = $"tet" }), "p2pdst2", "pgapi");
-
+                
                 //var code = -1;
-                //if (taskType == TaskName.浜у搧鍏ュ簱) {
-                //    code = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, JsonConvert.SerializeObject(new { src = startSite, order_name = $"{mst.S_CODE}" }), "p2pdst", "pgapi");
-                //}
-                //else {
-                //    code = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, JsonConvert.SerializeObject(new { src = startSite, dst = endSite }), "p2p", "pgapi");
-                //}
-
+                if (taskType == TaskName.浜у搧鍏ュ簱) {
+                    code = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, JsonConvert.SerializeObject(new { src = startSite, order_name = $"{mst.S_CODE}" }), "p2pdst", "pgapi");
+                }
+                else {
+                    code = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, JsonConvert.SerializeObject(new { src = startSite, dst = endSite }), "p2p", "pgapi");
+                }
+                LogHelper.Info($"eq_task_code={code}");
                 // car_type 榛樿涓�
                 // src_ort 璐ф灦鎺掑彿
                 // dst_orc 璐ф灦灞傛暟锛堝悗涓や釜淇℃伅搴旇涓哄浗鑷狝GV鍐呴儴缁存姢锛屼互鍚庨潰鏇存敼鐨勭粨鏋滀负鍑嗭級
diff --git a/util/HttpHelper.cs b/util/HttpHelper.cs
index d71f403..38f6542 100644
--- a/util/HttpHelper.cs
+++ b/util/HttpHelper.cs
@@ -102,7 +102,41 @@
                 if (rsp != null) rsp.Close();
             }
         }
-        
+
+        public string GetNew(string url, string contentType = null) {
+            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
+            request.Method = "GET";
+
+            // 鍙湁鎸囧畾浜哻ontentType鏃舵墠璁剧疆
+            if (!string.IsNullOrEmpty(contentType)) {
+                request.ContentType = contentType;
+            }
+
+            try {
+                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
+                using (Stream stream = response.GetResponseStream())
+                using (StreamReader reader = new StreamReader(stream)) {
+                    return reader.ReadToEnd();
+                }
+            }
+            catch (WebException ex) when (ex.Response is HttpWebResponse response) {
+                // 璁板綍璇︾粏鐨勯敊璇俊鎭�+                LogHelper.Info($"GET璇锋眰澶辫触銆傜姸鎬佺爜: {response.StatusCode}, URL: {url}", "API");
+
+                // 璇诲彇閿欒鍝嶅簲鍐呭
+                using (Stream stream = response.GetResponseStream())
+                using (StreamReader reader = new StreamReader(stream)) {
+                    string errorResponse = reader.ReadToEnd();
+                    LogHelper.Info($"閿欒鍝嶅簲鍐呭: {errorResponse}", "API");
+                }
+                return string.Empty;
+            }
+            catch (Exception ex) {
+                LogHelper.Info($"GET璇锋眰澶辫触銆俇RL: {url}, 閿欒: {ex.Message}", "API");
+                return string.Empty;
+            }
+        }
+
         public string Post(string url, string postData, string contentType = "application/json", string sessionId = "") {
             Console.WriteLine(url);
             WebRequest request = WebRequest.Create(url);

--
Gitblit v1.9.1