wanshenmean
3 天以前 b690250002ee04f4309e6a90fd16fbfd9bd959e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
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;
using WIDESEA_Core;
using WIDESEA_DTO.GradingMachine;
using WIDESEA_DTO.Task;
using WIDESEA_Model.Models;
 
namespace WIDESEA_TaskInfoService
{
    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))
            {
                var errResult = content.Error($"货位编号不能为空");
                log.Warning("[InOrOutCompleted] 响应: {Response}", JsonSerializer.Serialize(errResult, _jsonOptions));
                return errResult;
            }
 
            try
            {
                var stockInfo = await _stockInfoService.GetStockInfoAsync(3, input.LocationCode);
 
                int locationStatus;
                if (stockInfo == null)
                {
                    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
                {
                    (int)StockStatusEmun.入库完成 => 10,
                    (int)StockStatusEmun.空托盘库存 => 11,
                    _ => 0
                };
 
                OutputDto outPutDto = new OutputDto()
                {
                    LocationCode = input.LocationCode,
                    PalletCode = stockInfo.PalletCode,
                    IsNormalProcedure = 1,
                    LocationStatus = locationStatus
                };
                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;
        }
 
        /// <summary>
        /// 化成分容柜定时向物流更新分容柜状态信息
        /// </summary>
        /// <param name="input"></param>
        /// <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))
            {
                var errResult = content.Error($"货位编号不能为空");
                log.Warning("[SendLocationStatus] 响应: {Response}", JsonSerializer.Serialize(errResult, _jsonOptions));
                return errResult;
            }
 
            try
            {
                var result = await _locationInfoService.Db.Updateable<Dt_LocationInfo>()
                    .SetColumns(s => new Dt_LocationInfo
                    {
                        EnableStatus = input.LocationStatus == 1 ? 0 : 3,
                    }).Where(s => s.LocationCode == input.LocationCode && s.RoadwayNo == TaskAddressConstants.GRADING_RoadWayNo).ExecuteCommandAsync() > 0;
 
                if (result)
                {
                    content.OK("更新成功");
                }
                else
                {
                    content.Error("更新失败");
                }
                log.Information("[SendLocationStatus] 响应: {Response}", JsonSerializer.Serialize(content, _jsonOptions));
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
                log.Error(ex, "[SendLocationStatus] 异常");
            }
            return content;
        }
 
        /// <summary>
        /// 分容柜工作完成后调用此接口通知物流出库
        /// </summary>
        /// <param name="input"></param>
        /// <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))
            {
                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)
                {
                    var errResult = content.Error("未找到对应的托盘");
                    log.Warning("[RequestOutbound] 响应: {Response}", JsonSerializer.Serialize(errResult, _jsonOptions));
                    return errResult;
                }
 
                var taskList = new Dt_Task
                {
                    WarehouseId = stock.WarehouseId,
                    PalletCode = stock.PalletCode,
                    PalletType = stock.PalletType,
                    SourceAddress = stock.LocationCode,
                    CurrentAddress = stock.LocationCode,
                    NextAddress = TaskAddressConstants.GRADING_OUTBOUND_ADDRESS,
                    TargetAddress = TaskAddressConstants.GRADING_OUTBOUND_ADDRESS,
                    Roadway = stock.LocationDetails.RoadwayNo,
                    TaskType = TaskOutboundTypeEnum.Outbound.GetHashCode(),
                    TaskStatus = TaskOutStatusEnum.OutNew.GetHashCode(),
                    Grade = 1,
                    TaskNum = await BaseDal.GetTaskNo(),
                    Creater = "system",
                };
 
                return await _unitOfWorkManage.BeginTranAsync(async () =>
                {
                    var result = await BaseDal.AddDataAsync(taskList) > 0;
                    var wmstaskDto = result ? _mapper.Map<WMSTaskDTO>(taskList) : null;
                    var wmsTaskDtos = new List<WMSTaskDTO> { wmstaskDto };
                    var httpResponse = _httpClientHelper.Post<WebResponseContent>("http://localhost:9292/api/Task/ReceiveTask", JsonSerializer.Serialize(wmsTaskDtos)).Data;
                    if (result && httpResponse != null)
                    {
                        var okResult = content.OK("出库请求成功");
                        log.Information("[RequestOutbound] 响应: {Response}", JsonSerializer.Serialize(okResult, _jsonOptions));
                        return okResult;
                    }
                    else
                    {
                        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;
        }
 
        /// <summary>
        /// 入库完成分容调用获取托盘上每个通道电芯
        /// </summary>
        /// <param name="input"></param>
        /// <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))
            {
                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)
                {
                    var errResult = content.Error("未找到对应的托盘");
                    log.Warning("[GetPalletCodeCell] 响应: {Response}", JsonSerializer.Serialize(errResult, _jsonOptions));
                    return errResult;
                }
 
                var outPutDtos = new
                {
                    input.LocationCode,
                    input.PalletCode,
                    IsNormalProcedure = 1,
                    stockInfo.LocationDetails.LocationStatus,
                    Data = stockInfo.Details.Select(x => new CellCodeData
                    {
                        CellCode = x.SerialNumber,
                        Channel = x.InboundOrderRowNo.ToString()
                    }).ToList()
                };
                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);
            }
        }
 
        #endregion 分容柜接口
    }
}