服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-12-19 eb0ad83719de660e5c4f7676aea4710625b6bd51
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
using Rhea.Common;
using Microsoft.AspNetCore.Http;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tiger.Model;
using Tiger.Model.Sharetronic.Shelf;
using Tiger.Business.WMS.Sharetronic.Shelf;
using Tiger.IBusiness;
 
namespace Tiger.Business.WMS.Transaction
{
    /// <summary>
    /// 盘点调度事务
    /// </summary>
    public class WmsCount : WMSTransactionBase, IWmsCount
    {
        public IWmsCount Init(string id, string userCode, string apiHost, string orgCode)
        {
            TransID = id;
            UserCode = userCode;
            ApiHost = apiHost;
            OrgCode = orgCode;
            Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]");
            return this;
        }
 
        #region Propertys & Variables
        public string UserCode { get; set; }
        public long UserId { get; set; }
        public string OrgCode { get; set; }
        public Inventory CurInv { get; set; }
        public WMS_COUNT count { get; set; }
        public List<WMS_SHELF> Shelfs { get; set; }
        public List<WMS_LOCATION> locations { get; set; }
        public List<WMS_COUNT_MDTL> mdtls { get; set; }
        public List<WMS_COUNT_LDTL> ldtls { get; set; }
        public List<WMS_COUNT_SUM> sumlist { get; set; }
        #endregion
 
        #region Functions
        /// <summary>
        /// 盘点单列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="orgcode"></param>
        /// <param name="billcode"></param>
        /// <returns></returns>
        public ApiAction<PageAble<WMS_COUNT>> GetCountHeaders(int pageIndex, int pageSize, string orgcode, string billcode)
        {
            var action = new ApiAction<PageAble<WMS_COUNT>>();
            try
            {
                var query = Biz.Db.Queryable<WMS_COUNT>().Where(x =>
                (x.STATUS < WMS_COUNT.STATUSs.Paused.GetValue())
                && x.AUTH_ORG == orgcode)
                    .WhereIF(!billcode.IsNullOrEmpty(), x => x.COUNT_NO.Contains(billcode))
                    .OrderByDescending(x => x.UPDATE_TIME)
                    .OrderBy(x => x.CREATE_TIME)
                    .ToPage(pageIndex, pageSize);
                action.Data = query;
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"盘点单获取列表异常");
            }
            return action;
        }
        /// <summary>
        /// 盘点单选择事件
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction<CountEntityReturn>> SelectOrder(CountEntity input)
        {
            var action = new ApiAction<CountEntityReturn>();
            try
            {
                count = await Biz.Db.Queryable<WMS_COUNT>().ByAuth(input.AuthOption).Where(x => x.COUNT_NO == input.CountNo)
                    .Includes(q => q.MDtlsWithGhost, d => d.Warehouse)
                    .Includes(q => q.MDtlsWithGhost, d => d.Region)
                    .Includes(q => q.MDtlsWithGhost, d => d.Shelf)
                    .Includes(q => q.MDtlsWithGhost, d => d.Location)
                    .IncludesAllFirstLayer().FirstAsync();
                mdtls = count.MDtls;
                ldtls = count.LDtls;
                sumlist = count.SumList;
                locations = count.MDtls.Where(x => x.STATUS == WMS_COUNT_MDTL.STATUSs.WaitCount.GetValue()).Select(x => x.Location).Distinct().ToList();
                Shelfs = count.MDtls.Where(q => q.SHELF_ID != null && q.STATUS==0).Select(x => x.Shelf).Distinct().ToList();
                action.Data = new CountEntityReturn()
                {
                    CountNo = input.CountNo,
                    Shelfs = Shelfs.Select(q => new ShelfDropDown { SHELF_CODE = q.SHELF_CODE, SHELF_NAME = q.SHELF_NAME }).ToList(),
                    Warehouse = count.MDtls.Select(x => x.Warehouse).First(),
                    COUNT_TYPE = count.COUNT_TYPE
                };
                action.LocaleMsg = Biz.L($"选择盘点单[{input.CountNo}]成功");
                //action = await LightAll(new() { AuthOption = input.AuthOption, ReqType = CurReqType, Color = LedColor.Blue });
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"盘点单选择异常");
            }
            return action;
        }
 
        /// <summary>
        /// 盘点单推荐所有物料亮灯
        /// </summary>
        /// <param name="light"></param>
        /// <returns></returns>
        public async Task<ApiAction<CountOutput>> LightAll(CountLightEntity light)
        {
            var action = new ApiAction<CountOutput>();
            try
            {
                var _shelf = Shelfs.Where(q => q.SHELF_CODE == light.ShelfCode).FirstOrDefault();
                var list = locations.Where(q => q.SHELF_ID == _shelf.ID).ToList();
                if (list.Any())
                {
                    await Share.Shelf.LightMulti(TransID, light.Color, list);
                    action.Data = new CountOutput()
                    {
                        CountNo = count.COUNT_NO,
                    };
                    Logger.Interface.Info($"亮灯成功,亮灯颜色[{light.Color.GetDesc()}],亮灯位置[{string.Join(",", list.Select(t => t.LOCATION_CODE))}]");
                    action.LocaleMsg = Biz.L("亮灯成功,亮灯颜色[{0}]", light.Color.GetDesc());
                }
                else
                {
                    action.LocaleMsg = Biz.L($"无需亮灯,盘点的物料不在智能货架上");
                }
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"亮灯异常");
            }
            return action;
        }
 
        /// <summary>
        /// 盘点单明细
        /// </summary>
        /// <returns></returns>
        public async Task<ApiAction<PageAble<V_WMS_COUNT_SUM>>> CountSumDtl(BasePageInput input)
        {
            var action = new ApiAction<PageAble<V_WMS_COUNT_SUM>>();
            try
            {
                var query = Biz.Db.Queryable<V_WMS_COUNT_SUM>().ByAuth(input.AuthOption)
                .WhereIF(!input.Code.IsNullOrEmpty(), x => x.ITEM_CODE.Contains(input.Code))
                .Where(t => t.COUNT_NO == count.COUNT_NO)
                .OrderByDescending(x => x.UPDATE_TIME.ToString("yyyy-MM-dd"))
                .OrderBy(x => x.CREATE_TIME)
                .ToPage(input.pageIndex, input.pageSize);
 
                action.Data = await Task.FromResult(query);
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"获取盘点单明细异常");
            }
            return action;
        }
 
        ///// <summary>
        ///// 发料明细提示信息
        ///// </summary>
        ///// <returns></returns>
        //public async Task<ApiAction> GetItemTips(string itemcode)
        //{
        //    var action = new ApiAction();
        //    try
        //    {
        //        action.Data = $"物料{itemcode}:已下架[{(double)req.Dtls.Where(x => x.ITEM_CODE == itemcode).Sum(x => x.OUTQTY)}],共{(double)req.Dtls.Where(x => x.ITEM_CODE == itemcode).Sum(x => x.PRQTY)} {Suggests.FirstOrDefault()?.Item?.UNIT}";
        //    }
        //    catch (Exception ex)
        //    {
        //        action.CatchExceptionWithLog(ex, $"获取发料明细提示信息异常");
        //    }
        //    return action;
        //}
 
        /// <summary>
        /// 扫描物料调度下架
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction<CountOutput>> ScanItem(BaseInput input)
        {
            var action = new ApiAction<CountOutput>();
            try
            {
                if (input.SN.IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L("条码不能为空");
                    return action;
                }
 
                //解析条码
                Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true);
                if (!result.IsSuccessed)
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = result.LocaleMsg;
                    return action;
                }
                CurInv = result.Data as Inventory;
 
                //验证条码是否正确
                if (!CurInv.isNormalStatus || CurInv.Status != WMS_ITEM.STATUSs.InStore)
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L("WMS.WmsCount.ScanItem.StatusException", string.Join(',', CurInv.StatusList.Select(x => x.GetDesc())));
                    return action;
                }
                //储位验证
                if (CurInv.Location.IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L("WMS.WmsCount.ScanItem.LocationIsNull", CurInv.CurPkg.SN, CurInv.CurPkg.LOCATION_ID);
                    return action;
                }
 
                //物料验证
                if (CurInv.ItemInfo.IsNullOrEmpty() || !mdtls.Where(t => t.ITEM_CODE == CurInv.ItemInfo?.ITEM_CODE).Any())
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L("WMS.WmsCount.ScanItem.NotFound", CurInv.ItemInfo.ITEM_CODE.IsNullOrEmpty(CurInv.Barcode.ItemCode));
                    return action;
                }
                //var aa = mdtls.Where(t => t.SN == CurInv.CurPkg.SN).First();
                //V076420231110000003
                //更新条码盘点明细状态
                var mItem = mdtls.Where(q=> CurInv.Items.Any(a=>q.SN==a.SN)).ToList() ?? new List<WMS_COUNT_MDTL>()
                {
                    new()
                    {
                        COUNT_NO = count.COUNT_NO,
                        SN = CurInv.SN,
                        QTY = CurInv.CurPkg.QTY,
                        ITEM_CODE = CurInv.ItemInfo.ITEM_CODE,
                        UNIT = CurInv.ItemInfo.UNIT,
                        PROD_DATE = CurInv.Items[0].PROD_DATE,
                        FIRST_IN_DATE = CurInv.Items[0].FIRST_IN_DATE,
                        SUPP_CODE = CurInv.CurPkg.SUPP_CODE,
                        SUPP_LOTNO = CurInv.CurPkg.SUPP_LOTNO,
                        WH_ID = CurInv.CurPkg.WH_ID,
                        REGION_ID = CurInv.CurPkg.REGION_ID,
                        SHELF_ID = CurInv.CurPkg.SHELF_ID,
                        LOCATION_ID = CurInv.CurPkg.LOCATION_ID,
                        ERP_WH = CurInv.CurPkg.ERP_WH,
                        RESULT = WMS_COUNT_MDTL.RESULTs.NewFound.GetValue(),
                    }
                };
                //如果是新发现的条码就添加到列表中
                foreach (var item in mItem)
                {
                    if (item.RESULT == WMS_COUNT_MDTL.RESULTs.NewFound.GetValue()) { mdtls.Add(item); }
 
                    if (item.STATUS == WMS_COUNT_MDTL.STATUSs.Counted.GetValue())
                    {
                        //灭灯
                        var _action = await DownLight(input);
                        if (!_action.IsSuccessed)
                        {
                            return _action;
                        }
                        action.IsSuccessed = false;
                        action.LocaleMsg = Biz.L($"该条码已经盘点过,请扫描其他未盘点的条码!");
 
                        return action;
                    }
                    item.ACTION = WMS_COUNT_MDTL.ACTIONs.NoAdjust.GetValue();
                    item.STATUS = WMS_COUNT_MDTL.STATUSs.Counted.GetValue();
                    item.REVIEWER = UserCode;
                    item.REVIEW_DATE = DateTime.Now;
                    item.ACT_QTY = CurInv.CurPkg.QTY;
                    item.RESULT = item.RESULT == WMS_COUNT_MDTL.RESULTs.NewFound.GetValue() ? WMS_COUNT_MDTL.RESULTs.NewFound.GetValue() : WMS_COUNT_MDTL.RESULTs.Founded.GetValue();
 
                    //var lItem = ldtls.Where(t => t.LOCATION_ID == CurInv.CurPkg.LOCATION_ID).FirstOrDefault();
                    ////如果是新发现的条码,其原储位又没有在盘点储位列表中
                    //bool isNewFound = false;
                    //if (lItem == null && item.RESULT == WMS_COUNT_MDTL.RESULTs.NewFound.GetValue())
                    //{
                    //    lItem = new()
                    //    {
                    //        COUNT_NO = count.COUNT_NO,
                    //        ITEM_CODE = CurInv.ItemInfo.ITEM_CODE,
                    //        UNIT = CurInv.ItemInfo.UNIT,
                    //        WH_ID = CurInv.CurPkg.WH_ID,
                    //        REGION_ID = CurInv.CurPkg.REGION_ID,
                    //        SHELF_ID = CurInv.CurPkg.SHELF_ID,
                    //        LOCATION_ID = CurInv.CurPkg.LOCATION_ID,
                    //        ERP_WH = CurInv.CurPkg.ERP_WH,
                    //        QTY = CurInv.CurPkg.QTY,
                    //        SN_QTY = 1,
                    //        ACT_SN_QTY = 1,
                    //        ACT_QTY = CurInv.CurPkg.QTY,
                    //        STATUS = WMS_COUNT_LDTL.STATUSs.Counted.GetValue(),
                    //        RESULT = lItem.QTY == lItem.ACT_QTY ? WMS_COUNT_LDTL.RESULTs.Balance.GetValue() : (lItem.QTY > lItem.ACT_QTY ? WMS_COUNT_LDTL.RESULTs.Losses.GetValue() : WMS_COUNT_LDTL.RESULTs.Profit.GetValue())
                    //    };
                    //    isNewFound = true;
                    //}
 
                    var sumItem = sumlist.Where(t => t.ITEM_CODE == CurInv.ItemInfo.ITEM_CODE).FirstOrDefault();
                   
                    count.STATUS = count.STATUS == WMS_COUNT.STATUSs.New.GetValue() ? WMS_COUNT.STATUSs.Counting.GetValue() : count.STATUS;
                    //如果扫描列表状态都是已盘点,则结束并更新盘点单状态
                    if (mdtls.Count == mdtls.Where(t => t.STATUS == WMS_COUNT_MDTL.STATUSs.Counted.GetValue()).Count())
                    {
                        count.STATUS = WMS_COUNT.STATUSs.Closed.GetValue();
                    }
 
                    locations = mdtls.Where(x => x.STATUS == WMS_COUNT_MDTL.STATUSs.WaitCount.GetValue()).Select(x => x.Location).Distinct().ToList();
 
                    //灭灯
                    var Action = await DownLight(input);
                    if (!Action.IsSuccessed)
                    {
                        item.STATUS = WMS_COUNT_MDTL.STATUSs.WaitCount.GetValue();
                        return Action;
                    }
                    //保存数据库
                    var db = Business.Biz.Db;
                    var dbTran = db.UseTran(() =>
                    {
                        db.Storageable(mItem, UserCode).ExecuteCommand();
                        //if (isNewFound)
                        //{
                        //    ldtls.Add(lItem);
                        //    db.Insertable(lItem, UserCode).ExecuteCommand();
                        //}
                        //else
                        //{
                        //    db.Updateable<WMS_COUNT_LDTL>().SetColumns(t => new WMS_COUNT_LDTL
                        //    {
                        //        STATUS = WMS_COUNT_LDTL.STATUSs.Counted.GetValue(),
                        //        ACT_QTY = t.ACT_QTY + CurInv.CurPkg.QTY,
                        //        ACT_SN_QTY = t.ACT_SN_QTY + 1,
                        //        UPDATE_USER = UserCode,
                        //        UPDATE_TIME = DateTime.Now,
                        //        RESULT = Convert.ToInt32(SqlFunc.IF(t.QTY == t.ACT_QTY + CurInv.CurPkg.QTY).Return(WMS_COUNT_LDTL.RESULTs.Balance.GetValue()).ElseIF(t.QTY > t.ACT_QTY + CurInv.CurPkg.QTY).Return(WMS_COUNT_LDTL.RESULTs.Losses.GetValue()).End(WMS_COUNT_LDTL.RESULTs.Profit.GetValue()))
                        //    }).Where(q => q.ID == lItem.ID).ExecuteCommand();
                        //}
                        if (sumItem != null)
                        {
                            db.Updateable<WMS_COUNT_SUM>().SetColumns(t => new WMS_COUNT_SUM
                            {
                                ACT_QTY = t.ACT_QTY + CurInv.CurPkg.QTY,
                                ACT_SN_QTY = t.ACT_SN_QTY + 1,
                                UPDATE_USER = UserCode,
                                UPDATE_TIME = DateTime.Now,
                                RESULT = Convert.ToInt32(SqlFunc.IF(t.QTY == t.ACT_QTY + CurInv.CurPkg.QTY).Return(WMS_COUNT_SUM.RESULTs.Balance.GetValue()).ElseIF(t.QTY > t.ACT_QTY + CurInv.CurPkg.QTY).Return(WMS_COUNT_SUM.RESULTs.Losses.GetValue()).End(WMS_COUNT_SUM.RESULTs.Profit.GetValue()))
                            }).Where(q => q.ID == sumItem.ID).ExecuteCommand();
                        }
                        db.Updateable(count, UserCode).UpdateColumns(t => new { t.UPDATE_TIME, t.UPDATE_USER, t.STATUS }).ExecuteCommand();
                    });
                    if (!dbTran.IsSuccess)
                    {
                        Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception");
                        this.Close(!dbTran.IsSuccess);
                        throw dbTran.ErrorException;
                    }
                }
                if (count.STATUS == WMS_COUNT.STATUSs.Closed.GetValue())
                {
                    CloseLight(new CountLightEntity() { ShelfCode = "" });
                }
                action.LocaleMsg = Biz.L($"条码[{CurInv.CurPkg.SN}]核实成功,单号:[{count.COUNT_NO}],状态:{count.STATUS.GetEnumDesc<WMS_COUNT.STATUSs>()}");
                //var shelfs = Biz.Db.Queryable<WMS_COUNT_MDTL>().Where(q =>q.COUNT_NO==count.COUNT_NO && q.SHELF_ID != null && q.STATUS == 0).Select(x => x.Shelf).Distinct().ToList();
                var shelfs = mdtls.Where(q => q.SHELF_ID != null && q.STATUS == 0).Select(x => x.Shelf).Distinct().ToList();
                action.Data = new CountOutput()
                {
                    SN = CurInv.CurPkg.SN,
                    ItemCode = CurInv.ItemInfo.ITEM_CODE,
                    ItemName = CurInv.ItemInfo.ITEM_VER,
                    ItemDesc = CurInv.ItemInfo.ITEM_NAME,
                    Qty = CurInv.CurPkg.QTY,
                    regionCode = CurInv.Region.REGION_CODE,
                    locationCode = CurInv.Location?.LOCATION_CODE,
                    Unit = CurInv.CurPkg.UNIT,
                    Shelfs= shelfs.Select(q => new ShelfDropDown { SHELF_CODE = q.SHELF_CODE, SHELF_NAME = q.SHELF_NAME }).ToList(),
                    Status = $"已盘点数:[{mdtls.Where(t => t.STATUS == WMS_COUNT_MDTL.STATUSs.Counted.GetValue()).Count()}]/总数:[{mdtls.Count}]"
                };
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"扫描物料[{input.SN}]复核异常");
            }
            return action;
        }
 
        /// <summary>
        /// 选普通货架带出储位
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction<CountOutput>> ChangeShelf(BaseInput input)
        {
            var action = new ApiAction<CountOutput>();
            try
            {
                //检查是否是智能货架
                var whUnit = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => t.SHELF_CODE.ToUpper() == input.SN.ToUpper() && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync();
                if (whUnit != null && whUnit.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.Smart.GetValue())
                {
                    var shelfs = mdtls.Where(q => q.SHELF_ID != null && q.STATUS == 0).Select(x => x.Shelf).Distinct().ToList();
                    action.Data = new CountOutput()
                    {
                        locationCode = "",
                        Shelfs = shelfs.Select(q => new ShelfDropDown { SHELF_CODE = q.SHELF_CODE, SHELF_NAME = q.SHELF_NAME }).ToList(),
                    };
                }
                else
                {
                    //查询出所有储位
                    var locations = mdtls.Where(q=>q.Shelf.SHELF_CODE==input.SN && q.STATUS==0).Select(q=>q.Location.LOCATION_CODE).Distinct().ToList();
                    string joined = String.Join(",", locations);
                    var shelfs = mdtls.Where(q => q.SHELF_ID != null && q.STATUS == 0).Select(x => x.Shelf).Distinct().ToList();
                    action.Data = new CountOutput()
                    {
                        locationCode = joined,
                        Shelfs = shelfs.Select(q => new ShelfDropDown { SHELF_CODE = q.SHELF_CODE, SHELF_NAME = q.SHELF_NAME }).ToList(),
                    };
                }
               
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"选择货架[{input.SN}]复核异常");
            }
            return action;
        }
        /// <summary>
        /// 灭灯
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private async Task<ApiAction<CountOutput>> DownLight(BaseInput input)
        {
            var action = new ApiAction<CountOutput>();
            try
            {
                if (CurInv.Shelf.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.Smart.GetValue())
                {
                    ShelfApiResult shelfApiResult = await Share.Shelf.PutOn(TransID, CurInv.Shelf, CurInv.Items[0]);
                    if (!shelfApiResult.IsSuccess)
                    {
                        action.IsSuccessed = false;
                        action.LocaleMsg = Biz.L(shelfApiResult.GetData<string>());
                        return action;
                    }
                    var reaultShelf = shelfApiResult.GetData<ShelfChangeModel>();
 
                    var nLocation = reaultShelf.GetLocation();
                    if (nLocation == null)
                    {
                        action.IsSuccessed = false;
                        action.LocaleMsg = Biz.L($"系统不存在储位,请先维护货架信息");
                        return action;
                    }
                    if (nLocation.LOCATION_CODE != CurInv.Location.LOCATION_CODE)
                    {
                        action.IsSuccessed = false;
                        action.LocaleMsg = Biz.L($"货架返回的储位跟条码所在的储位不一样");
                        return action;
                    }
 
                }
                //灭灯
                if (CurInv.Shelf.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.Smart.GetValue() || CurInv.Shelf.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.QRCode.GetValue())
                {
                    await Share.Shelf.DownSingle(TransID, CurInv.Location);
                }
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"扫描物料[{input.SN}]复核异常");
            }
            return action;
        }
 
 
        /// <summary>
        /// 灭灯
        /// </summary>
        /// <returns></returns>
        public async Task<ApiAction> CloseLight(CountLightEntity light)
        {
            var action = new ApiAction();
            try
            {
                var _shelf = Shelfs.Where(q => q.SHELF_CODE == light.ShelfCode).FirstOrDefault();
                var list = light.ShelfCode.IsNullOrEmpty() ? mdtls.Select(x => x.Location).Distinct().ToList() : locations.Where(q => q.SHELF_ID == _shelf.ID).ToList();
                if (list.Any())
                {
                    //灭灯
                    await Share.Shelf.DownMulti(TransID, list);
                    action.Data = new CountOutput()
                    {
                        CountNo = count.COUNT_NO,
                    };
                    action.LocaleMsg = Biz.L("灭灯成功");
                }
                else
                {
                    action.LocaleMsg = Biz.L($"无需灭灯");
                }
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"灭灯异常");
            }
            return action;
        }
 
        /// <summary>
        /// 添加一个ApiAction的历史记录
        /// </summary>
        /// <param name="action"></param>
        public override void AddHistory<T>(Microsoft.AspNetCore.Http.HttpRequest request, ApiAction<T> action)
        {
            var his = action.History();
            his.TraceDic.Add("mdtls", mdtls);
            his.TraceDic.Add("ldtls", ldtls);
            his.TraceDic.Add("count", count);
            his.TraceDic.Add("sumlist", sumlist);
            ActionHistoryList.Add($"{request.HttpContext.TraceIdentifier} at {action.Timestamp:yyyy/MM/dd HH:mm:ss.fff}: {request.Path}", his);
            LastActionTime = DateTime.Now;
        }
 
        #endregion
        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="needSaveHistoryLog"></param>
        /// <returns></returns>
        public override bool Close(bool needSaveHistoryLog = false)
        {
            //检查盘点单是否关闭
            Biz.Db.Ado.UseStoredProcedure().ExecuteCommand("pkg_count_status", new SugarParameter("CountNo", count.COUNT_NO));
            //needSaveHistoryLog = true;
            CloseLight(new CountLightEntity() { ShelfCode = "" }).Wait();
            //保存操作日志
 
            this.IsFinished = true;
            return IsFinished ? base.Close(needSaveHistoryLog) : IsFinished;
        }
 
    }//endClass
}