wanshenmean
17 小时以前 c96b149557eb570ec3ae28e0d0c03adef734766a
Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/MesUploadHelper.cs
@@ -1,9 +1,10 @@
using Newtonsoft.Json.Linq;
using System.Diagnostics;
using WIDESEA_Common.StockEnum;
using WIDESEA_Core;
using WIDESEA_DTO.MES;
using WIDESEA_IStockService;
using WIDESEA_IBasicService;
using WIDESEA_IStockService;
namespace WIDESEA_StockService
{
@@ -34,7 +35,7 @@
            MesUploadStatusEnum successStatus,
            string apiType,
            string requestJson,
            Func<(bool isSuccess, string responseJson, string errorMessage)> mesCall,
            Func<(bool isSuccess, string responseJson, string errorMessage, string httpRequest)> mesCall,
            string creator = "System")
        {
            _ = Task.Run(async () =>
@@ -42,12 +43,14 @@
                var stopwatch = Stopwatch.StartNew();
                try
                {
                    var (isSuccess, responseJson, errorMessage) = mesCall();
                    var (isSuccess, responseJson, errorMessage, httpRequest) = mesCall();
                    stopwatch.Stop();
                    // 奇数=成功,偶数=失败
                    int status = isSuccess ? (int)successStatus : (int)successStatus + 1;
                    await _stockInfoService.UpdateMesUploadStatusAsync(palletCode, status);
                    requestJson = MergeJsonObjects(requestJson, httpRequest);
                    await LogAsync(palletCode, apiType, requestJson, responseJson,
                        stopwatch.ElapsedMilliseconds, isSuccess, errorMessage, creator);
@@ -89,5 +92,16 @@
                // 日志记录失败不影响主流程
            }
        }
        public static string MergeJsonObjects(string json1, string json2)
        {
            var obj1 = JObject.Parse(json1);
            var obj2 = JObject.Parse(json2);
            obj1.Merge(obj2, new JsonMergeSettings
            {
                MergeArrayHandling = MergeArrayHandling.Union   // 数组合并方式,可按需修改
            });
            return obj1.ToString();
        }
    }
}