| | |
| | | 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 |
| | | { |
| | |
| | | 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 () => |
| | |
| | | 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); |
| | |
| | | // 日志记录失败不影响主流程 |
| | | } |
| | | } |
| | | |
| | | 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(); |
| | | } |
| | | } |
| | | } |