| | |
| | | using Serilog; |
| | | using System.Text.Json; |
| | | using System.Text.Encodings.Web; |
| | | using System.Text.Unicode; |
| | | using WIDESEA_Common.Constants; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Common.TaskEnum; |
| | |
| | | { |
| | | public partial class TaskService |
| | | { |
| | | /// <summary> |
| | | /// JSON序列化选项(中文不转义) |
| | | /// </summary> |
| | | private static readonly JsonSerializerOptions _jsonOptions = new() |
| | | { |
| | | Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) |
| | | }; |
| | | #region 分容柜接口 |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | public async Task<WebResponseContent> InOrOutCompletedAsync(GradingMachineInputDto input) |
| | | { |
| | | var log = Log.ForContext("SourceContext", "分容柜完成信号"); |
| | | log.Information("[InOrOutCompleted] 请求参数: {Request}", JsonSerializer.Serialize(input, _jsonOptions)); |
| | | WebResponseContent content = new WebResponseContent(); |
| | | if (string.IsNullOrWhiteSpace(input.LocationCode)) |
| | | { |
| | | return content.Error($"货位编号不能为空"); |
| | | var errResult = content.Error($"货位编号不能为空"); |
| | | log.Warning("[InOrOutCompleted] 响应: {Response}", JsonSerializer.Serialize(errResult, _jsonOptions)); |
| | | return errResult; |
| | | } |
| | | |
| | | try |
| | |
| | | |
| | | int locationStatus; |
| | | if (stockInfo == null) |
| | | return content.Error("WMS未找到库存信息"); |
| | | { |
| | | var errResult = content.Error("WMS未找到库存信息"); |
| | | log.Warning("[InOrOutCompleted] 响应: {Response}", JsonSerializer.Serialize(errResult, _jsonOptions)); |
| | | return errResult; |
| | | } |
| | | locationStatus = MapLocationStatus(stockInfo.StockStatus); |
| | | |
| | | int MapLocationStatus(int stockStatus) => stockStatus switch |
| | |
| | | IsNormalProcedure = 1, |
| | | LocationStatus = locationStatus |
| | | }; |
| | | return content.OK(data: outPutDto); |
| | | var result = content.OK(data: outPutDto); |
| | | log.Information("[InOrOutCompleted] 响应: {Response}", JsonSerializer.Serialize(result, _jsonOptions)); |
| | | return result; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | log.Error(ex, "[InOrOutCompleted] 异常"); |
| | | } |
| | | |
| | | return content; |
| | |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> SendLocationStatusAsync(GradingMachineInputDto input) |
| | | { |
| | | var log = Log.ForContext("SourceContext", "分容柜状态更新"); |
| | | log.Information("[SendLocationStatus] 请求参数: {Request}", JsonSerializer.Serialize(input, _jsonOptions)); |
| | | WebResponseContent content = new WebResponseContent(); |
| | | if (string.IsNullOrWhiteSpace(input.LocationCode)) |
| | | { |
| | | return content.Error($"货位编号不能为空"); |
| | | var errResult = content.Error($"货位编号不能为空"); |
| | | log.Warning("[SendLocationStatus] 响应: {Response}", JsonSerializer.Serialize(errResult, _jsonOptions)); |
| | | return errResult; |
| | | } |
| | | |
| | | try |
| | |
| | | { |
| | | content.Error("更新失败"); |
| | | } |
| | | log.Information("[SendLocationStatus] 响应: {Response}", JsonSerializer.Serialize(content, _jsonOptions)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | log.Error(ex, "[SendLocationStatus] 异常"); |
| | | } |
| | | return content; |
| | | } |
| | |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> RequestOutboundAsync(GradingMachineInputDto input) |
| | | { |
| | | var log = Log.ForContext("SourceContext", "分容柜出库请求"); |
| | | log.Information("[RequestOutbound] 请求参数: {Request}", JsonSerializer.Serialize(input, _jsonOptions)); |
| | | WebResponseContent content = new WebResponseContent(); |
| | | if (string.IsNullOrWhiteSpace(input.LocationCode) || string.IsNullOrWhiteSpace(input.PalletCode)) |
| | | { |
| | | return content.Error($"托盘号或者货位编号不能为空"); |
| | | var errResult = content.Error($"托盘号或者货位编号不能为空"); |
| | | log.Warning("[RequestOutbound] 响应: {Response}", JsonSerializer.Serialize(errResult, _jsonOptions)); |
| | | return errResult; |
| | | } |
| | | try |
| | | { |
| | | var stock = await _stockInfoService.GetStockInfoAsync(input.PalletCode, input.LocationCode); |
| | | if (stock == null) |
| | | { |
| | | return content.Error("未找到对应的托盘"); |
| | | var errResult = content.Error("未找到对应的托盘"); |
| | | log.Warning("[RequestOutbound] 响应: {Response}", JsonSerializer.Serialize(errResult, _jsonOptions)); |
| | | return errResult; |
| | | } |
| | | |
| | | var taskList = new Dt_Task |
| | |
| | | var httpResponse = _httpClientHelper.Post<WebResponseContent>("http://localhost:9292/api/Task/ReceiveTask", JsonSerializer.Serialize(wmsTaskDtos)).Data; |
| | | if (result && httpResponse != null) |
| | | { |
| | | return content.OK("出库请求成功"); |
| | | var okResult = content.OK("出库请求成功"); |
| | | log.Information("[RequestOutbound] 响应: {Response}", JsonSerializer.Serialize(okResult, _jsonOptions)); |
| | | return okResult; |
| | | } |
| | | else |
| | | { |
| | | return content.Error("出库请求失败"); |
| | | var errResult = content.Error("出库请求失败"); |
| | | log.Warning("[RequestOutbound] 响应: {Response}", JsonSerializer.Serialize(errResult, _jsonOptions)); |
| | | return errResult; |
| | | } |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | log.Error(ex, "[RequestOutbound] 异常"); |
| | | } |
| | | return content; |
| | | } |
| | |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> GetPalletCodeCellAsync(GradingMachineInputDto input) |
| | | { |
| | | var log = Log.ForContext("SourceContext", "分容柜电芯查询"); |
| | | log.Information("[GetPalletCodeCell] 请求参数: {Request}", JsonSerializer.Serialize(input, _jsonOptions)); |
| | | WebResponseContent content = new WebResponseContent(); |
| | | if (string.IsNullOrWhiteSpace(input.PalletCode) || string.IsNullOrWhiteSpace(input.LocationCode)) |
| | | { |
| | | return content.Error($"托盘号或者货位编号不能为空"); |
| | | var errResult = content.Error($"托盘号或者货位编号不能为空"); |
| | | log.Warning("[GetPalletCodeCell] 响应: {Response}", JsonSerializer.Serialize(errResult, _jsonOptions)); |
| | | return errResult; |
| | | } |
| | | try |
| | | { |
| | | var stockInfo = await _stockInfoService.GetStockInfoAsync(input.PalletCode, input.LocationCode); |
| | | if (stockInfo == null) |
| | | { |
| | | return content.Error("未找到对应的托盘"); |
| | | var errResult = content.Error("未找到对应的托盘"); |
| | | log.Warning("[GetPalletCodeCell] 响应: {Response}", JsonSerializer.Serialize(errResult, _jsonOptions)); |
| | | return errResult; |
| | | } |
| | | |
| | | var outPutDtos = new |
| | |
| | | Channel = x.InboundOrderRowNo.ToString() |
| | | }).ToList() |
| | | }; |
| | | return content.OK(data: outPutDtos); |
| | | var result = content.OK(data: outPutDtos); |
| | | log.Information("[GetPalletCodeCell] 响应: {Response}", JsonSerializer.Serialize(result, _jsonOptions)); |
| | | return result; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.Error(ex, "[GetPalletCodeCell] 异常"); |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |