肖洋
2025-01-09 1164314b1f0183dadf760171e5a494eda53a1c95
更新多个文件,增强请求处理和日志记录

在本次提交中,主要进行了以下更改:

- 更新 .gitignore 文件,添加忽略特定调试文件和会话数据的路径。
- 在 HttpHelper.cs 中添加对 AngleSharp 和 Newtonsoft.Json 的引用,并实现 PostAsync 方法,增加请求次数限制逻辑。
- 修改 CommonStackerCrane.cs 和 CommonStackerStationCrane.cs 中设备请求的超时时间,从 1000 毫秒增加到 1500 毫秒。
- 在 CommonConveyorLine_GWJob.cs 中修改日志输出,显示任务号而非托盘号。
- 在 HttpsClient.cs 中添加请求次数跟踪逻辑,并更新 LogRequestParameters 方法的参数格式。
- 修正 AgingOutputDto.cs 和 Dt_TaskService.cs 中 LowerLimit 属性的拼写和赋值错误。
- 在 IProcessApplyService.cs 和 ProcessApplyController.cs 中新增 StockOutDataBackfillInterfaceAsync 方法的声明和实现,提供出库数据的补录接口。
- 修改 LocationInfoService.cs 中创建位置的循环起始值,从 3 改为 7。
已修改12个文件
123 ■■■■ 文件已修改
.gitignore 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/HttpHelper.cs 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerStationCrane.cs 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Common/HttpClient/HttpsClient.cs 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_DTO/MOM/AgingOutputDto.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_IStoragIntegrationServices/MOM/ProcessApply/IProcessApplyService.cs 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Location/LocationInfoService.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Integration/ProcessApplyController.cs 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -1650,3 +1650,5 @@
/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/obj/Debug/net6.0/WIDESEA_StorageTaskServices.csproj.CopyComplete
/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/obj/Debug/net6.0/WIDESEA_StoragIntegrationServices.csproj.CopyComplete
/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/obj/Debug/net6.0/WIDESEA_WMSServer.csproj.CopyComplete
/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/22de66c6-d93f-400b-aaa1-cc12e218c2e7
/Code Management/WCS/WIDESEAWCS_Server/.vs/WIDESEAWCS_Server/copilot-chat/bef6627e/sessions/36708593-3f69-4656-815a-651b3ad17c7d
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/HttpHelper.cs
@@ -1,4 +1,6 @@
using System;
using AngleSharp.Dom;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
@@ -37,10 +39,42 @@
            return null;
        }
        // 用于追踪每个请求的调用次数和最后请求时间。
        private static readonly Dictionary<string, (int Count, DateTime LastRequestTime)> requestTracker = new();
        public static async Task<string> PostAsync(string serviceAddress, string requestJson = null, string contentType = "application/json", Dictionary<string, string>? headers = null)
        {
            try
            {
                // 将 JSON 字符串转换为字典
                var parameters = JsonConvert.DeserializeObject<Dictionary<string, object>>(requestJson);
                // 创建一个新的字典,排除 RequestTime 和 SessionId
                var filteredParameters = parameters.Where(p => p.Key != "RequestTime" && p.Key != "SessionId").ToDictionary(p => p.Key, p => p.Value);
                string requestKey = $"{serviceAddress}:{JsonConvert.SerializeObject(filteredParameters)}";
                // 检查请求次数和时间限制
                if (requestTracker.TryGetValue(requestKey, out var requestInfo))
                {
                    if (requestInfo.Count >= 5 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(10))
                    {
                        // 如果请求次数超过限制且未超过10分钟,抛出异常
                        throw new InvalidOperationException("请求次数已达到限制,请稍后再试。");
                    }
                }
                // 更新请求跟踪信息
                if (requestTracker.ContainsKey(requestKey))
                {
                    requestTracker[requestKey] = (requestInfo.Count + 1, DateTime.Now);
                }
                else
                {
                    requestTracker[requestKey] = (1, DateTime.Now);
                }
                string result = string.Empty;
                using (HttpContent httpContent = new StringContent(requestJson))
                {
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs
@@ -396,22 +396,22 @@
                            switch (typeCode)
                            {
                                case TypeCode.Boolean:
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1000, 20 * 6000, Convert.ToBoolean(deviceProtocolDetail.ProtocalDetailValue));
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1500, 20 * 6000, Convert.ToBoolean(deviceProtocolDetail.ProtocalDetailValue));
                                    break;
                                case TypeCode.Byte:
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1000, 20 * 6000, Convert.ToByte(deviceProtocolDetail.ProtocalDetailValue));
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1500, 20 * 6000, Convert.ToByte(deviceProtocolDetail.ProtocalDetailValue));
                                    break;
                                case TypeCode.Int16:
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1000, 20 * 6000, Convert.ToInt16(deviceProtocolDetail.ProtocalDetailValue));
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1500, 20 * 6000, Convert.ToInt16(deviceProtocolDetail.ProtocalDetailValue));
                                    break;
                                case TypeCode.Int32:
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1000, 20 * 6000, Convert.ToInt32(deviceProtocolDetail.ProtocalDetailValue));
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1500, 20 * 6000, Convert.ToInt32(deviceProtocolDetail.ProtocalDetailValue));
                                    break;
                                case TypeCode.UInt16:
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1000, 20 * 6000, Convert.ToUInt16(deviceProtocolDetail.ProtocalDetailValue));
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1500, 20 * 6000, Convert.ToUInt16(deviceProtocolDetail.ProtocalDetailValue));
                                    break;
                                case TypeCode.UInt32:
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1000, 20 * 6000, Convert.ToUInt32(deviceProtocolDetail.ProtocalDetailValue));
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1500, 20 * 6000, Convert.ToUInt32(deviceProtocolDetail.ProtocalDetailValue));
                                    break;
                                default:
                                    break;
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerStationCrane.cs
@@ -396,22 +396,22 @@
                            switch (typeCode)
                            {
                                case TypeCode.Boolean:
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1000, 20 * 6000, Convert.ToBoolean(deviceProtocolDetail.ProtocalDetailValue));
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1500, 20 * 6000, Convert.ToBoolean(deviceProtocolDetail.ProtocalDetailValue));
                                    break;
                                case TypeCode.Byte:
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1000, 20 * 6000, Convert.ToByte(deviceProtocolDetail.ProtocalDetailValue));
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1500, 20 * 6000, Convert.ToByte(deviceProtocolDetail.ProtocalDetailValue));
                                    break;
                                case TypeCode.Int16:
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1000, 20 * 6000, Convert.ToInt16(deviceProtocolDetail.ProtocalDetailValue));
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1500, 20 * 6000, Convert.ToInt16(deviceProtocolDetail.ProtocalDetailValue));
                                    break;
                                case TypeCode.Int32:
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1000, 20 * 6000, Convert.ToInt32(deviceProtocolDetail.ProtocalDetailValue));
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1500, 20 * 6000, Convert.ToInt32(deviceProtocolDetail.ProtocalDetailValue));
                                    break;
                                case TypeCode.UInt16:
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1000, 20 * 6000, Convert.ToUInt16(deviceProtocolDetail.ProtocalDetailValue));
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1500, 20 * 6000, Convert.ToUInt16(deviceProtocolDetail.ProtocalDetailValue));
                                    break;
                                case TypeCode.UInt32:
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1000, 20 * 6000, Convert.ToUInt32(deviceProtocolDetail.ProtocalDetailValue));
                                    operateResult = Communicator.Wait(devicePro.DeviceProAddress, 1500, 20 * 6000, Convert.ToUInt32(deviceProtocolDetail.ProtocalDetailValue));
                                    break;
                                default:
                                    break;
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs
@@ -198,7 +198,7 @@
                var task = _taskService.QueryBarCodeConveyorLineTask(command.ConveyorLineBarcode, childDeviceCode);
                //HandleTaskOut(conveyorLine, command, childDeviceCode, task);
                // && command.ConveyorLineBarcode != "NoRead" && !command.ConveyorLineBarcode.IsNotEmptyOrNull()
                ConsoleHelper.WriteSuccessLine($"【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】设备编码:【{childDeviceCode}】");
                ConsoleHelper.WriteSuccessLine($"【{conveyorLine.DeviceName}】托盘号:【{command.ConveyorLineBarcode}】任务号:【{command.ConveyorLineTaskNum}】设备编码:【{childDeviceCode}】");
                if (task == null)
                {
                    HandleNewTask(conveyorLine, command, childDeviceCode);
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Common/HttpClient/HttpsClient.cs
@@ -42,9 +42,36 @@
        }
    }
    // 用于追踪每个请求的调用次数和最后请求时间。
    private static readonly Dictionary<string, (int Count, DateTime LastRequestTime)> requestTracker = new();
    // 封装一个用HttpClient发送Post请求的方法有参数
    public static async Task<string> PostAsync(string url, Dictionary<string, object> parameters)
    {
        // 创建一个新的字典,排除 RequestTime 和 SessionId
        var filteredParameters = parameters.Where(p => p.Key != "RequestTime"&& p.Key != "SessionId").ToDictionary(p => p.Key, p => p.Value);
        string requestKey = $"{url}:{JsonConvert.SerializeObject(filteredParameters)}";
        // 检查请求次数和时间限制
        if (requestTracker.TryGetValue(requestKey, out var requestInfo))
        {
            if (requestInfo.Count >= 5 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(10))
            {
                // 如果请求次数超过限制且未超过10分钟,抛出异常
                throw new InvalidOperationException("请求次数已达到限制,请稍后再试。");
            }
        }
        // 更新请求跟踪信息
        if (requestTracker.ContainsKey(requestKey))
        {
            requestTracker[requestKey] = (requestInfo.Count + 1, DateTime.Now);
        }
        else
        {
            requestTracker[requestKey] = (1, DateTime.Now);
        }
        // 记录请求参数
        LogRequestParameters(parameters, url);
@@ -78,7 +105,7 @@
        }
    }
    private static void LogRequestParameters(Dictionary<string, object> parameters,string url = "")
    private static void LogRequestParameters(Dictionary<string, object> parameters, string url = "")
    {
        StringBuilder builder = new StringBuilder();
        builder.Append(Environment.NewLine);
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_DTO/MOM/AgingOutputDto.cs
@@ -66,7 +66,7 @@
    /// <summary>
    /// 下限
    /// </summary>
    public string LowerLomit { get; set; }
    public string LowerLimit { get; set; }
    /// <summary>
    /// 目标值
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_IStoragIntegrationServices/MOM/ProcessApply/IProcessApplyService.cs
@@ -19,4 +19,12 @@
    /// <param name="areaID">区域主键</param>
    /// <returns></returns>
    Task<WebResponseContent> StockInDataBackfillInterfaceAsync(string palletCode, int areaID);
    /// <summary>
    /// 补录出库数据
    /// </summary>
    /// <param name="palletCode">托盘号</param>
    /// <param name="areaID">区域主键</param>
    /// <returns></returns>
    Task<WebResponseContent> StockOutDataBackfillInterfaceAsync(string palletCode, int areaID);
}
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs
@@ -129,7 +129,7 @@
                                    ParameterDesc = parameterInfo.Description,
                                    ParameterResult  = "OK", //isNG.ToString(),
                                    TargetValue = parameterInfo.TargetValue,
                                    LowerLomit = parameterInfo.LowerSpecificationsLimit,
                                    LowerLimit = parameterInfo.LowerSpecificationsLimit,
                                    UpperLimit = parameterInfo.UpperSpecificationsLimit,
                                    DefectCode = defectCode,
                                    UOMCode = parameterInfo.UOMCode,
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Location/LocationInfoService.cs
@@ -182,7 +182,7 @@
    {
        string[] chineseNumbers = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
        var locationList = new List<DtLocationInfo>();
        for (int line = 3; line <= x; line++)
        for (int line = 7; line <= x; line++)
        {
            for (int column = 1; column <= y; column++)
            {
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -258,7 +258,7 @@
                        ParameterDesc = parameterInfo.Description,
                        ParameterResult  = "OK", //isNG.ToString(),
                        TargetValue = parameterInfo.TargetValue,
                        LowerLomit = parameterInfo.LowerSpecificationsLimit,
                        LowerLimit = parameterInfo.LowerSpecificationsLimit,
                        UpperLimit = parameterInfo.UpperSpecificationsLimit,
                        DefectCode = defectCode,
                        UOMCode = parameterInfo.UOMCode,
@@ -2417,7 +2417,7 @@
                        ParameterDesc = parameterInfo.Description,
                        ParameterResult  = "OK",
                        TargetValue = parameterInfo.TargetValue,
                        LowerLomit = parameterInfo.LowerSpecificationsLimit,
                        LowerLimit = parameterInfo.LowerSpecificationsLimit,
                        UpperLimit = parameterInfo.UpperSpecificationsLimit,
                        DefectCode = defectCode,
                    }
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Integration/ProcessApplyController.cs
@@ -37,4 +37,16 @@
    {
        return await _processApplyService.StockInDataBackfillInterfaceAsync(palletCode, areaID);
    }
    /// <summary>
    /// 补录出库数据
    /// </summary>
    /// <param name="palletCode">托盘号</param>
    /// <param name="areaID">区域主键</param>
    /// <returns></returns>
    [HttpPost("StockOutDataBack")]
    public async Task<WebResponseContent> StockOutDataBackfillInterfaceAsync(string palletCode, int areaID)
    {
        return await _processApplyService.StockOutDataBackfillInterfaceAsync(palletCode, areaID);
    }
}