kazelee
2025-07-08 9f18954857e9c4c691fc2c8e83d7728abdc18f74
添加后台图片前台调用的图床接口备用,修复测试出现的问题
1个文件已添加
8个文件已修改
5个文件已删除
201 ■■■■ 已修改文件
.gitignore 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/2c811ea3-de97-45a8-bcd7-7c88a2af5604.vsidx 补丁 | 查看 | 原始文档 | blame | 历史
.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/31c8165b-2f2b-45b9-85b4-57a0470f4da9.vsidx 补丁 | 查看 | 原始文档 | blame | 历史
.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/751eaf15-0a04-4bab-a16d-9f01e4e7f818.vsidx 补丁 | 查看 | 原始文档 | blame | 历史
.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/db48a26a-6552-4d65-a5d9-3721c951a7fd.vsidx 补丁 | 查看 | 原始文档 | blame | 历史
.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/read.lock 补丁 | 查看 | 原始文档 | blame | 历史
HH.WCS.Mobox3.AnGang.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/AgvController.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/ApiHelper.cs 补丁 | 查看 | 原始文档 | blame | 历史
api/ApiModel.cs 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/ImageController.cs 109 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dispatch/GZRobot.cs 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
process/TaskProcess.cs 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
util/HttpHelper.cs 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.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
.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/2c811ea3-de97-45a8-bcd7-7c88a2af5604.vsidx
Binary files differ
.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/31c8165b-2f2b-45b9-85b4-57a0470f4da9.vsidx
Binary files differ
.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/751eaf15-0a04-4bab-a16d-9f01e4e7f818.vsidx
Binary files differ
.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/db48a26a-6552-4d65-a5d9-3721c951a7fd.vsidx
Binary files differ
.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/read.lock
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" />
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);
        }
        
api/ApiHelper.cs
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; }
api/ImageController.cs
New file
@@ -0,0 +1,109 @@
using 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);
            // 根据文件扩展名设置ContentType
            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);
        }
    }
}
dispatch/GZRobot.cs
@@ -1,13 +1,17 @@
using 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($"正在请求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;
                    }
process/TaskProcess.cs
@@ -117,13 +117,13 @@
                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 默认为1
                // src_ort 货架排号
                // dst_orc 货架层数(后两个信息应该为国自AGV内部维护,以后面更改的结果为准)
util/HttpHelper.cs
@@ -103,6 +103,40 @@
            }
        }
        
        public string GetNew(string url, string contentType = null) {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "GET";
            // 只有指定了contentType时才设置
            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请求失败。URL: {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);