服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2025-04-09 f8b74ce69663bed763f9fbc5b251a5d2da9bb4c7
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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
using Rhea.Common;
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.IBusiness;
using Tiger.Model.MES.Yada;
using Tiger.Model.Entitys.MES.U9C;
 
namespace Tiger.Business.WMS.Transaction
{
    /// <summary>
    /// 送货单(U9)清点事务
    /// </summary>
    public class Count_BIZ_U9_ASN : WmsTask, ICount_BIZ_U9_ASN
    {
        public ICount_BIZ_U9_ASN Init(string id, string userCode, string apiHost, string orgCode)
        {
            base.Init(id, userCode, apiHost, orgCode);
            //加载已经清点数据
            LoadData();
            Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]");
            return this;
        }
 
        #region Propertys & Variables
        //private List<WmsOrder<BIZ_U9_ASN>> _OrderList { get; set; } = new();
        private List<string> OrderList = new();
        private List<BIZ_U9_ASN_SN> CurSn = new();
        private List<BIZ_U9_ASN_SN> ScanList = new();
        #endregion
 
        #region Functions
        /// <summary>
        /// 初始化清点数据
        /// </summary>
        private void LoadData()
        {
            OrderList = MainDB.Queryable<BIZ_U9_ASN_SN>().Where(q => q.RECEIVER == UserCode && SqlFunc.Subqueryable<BIZ_U9_ASN>().Where(s => s.ORDER_NO == q.ORDER_NO && s.STATUS == BIZ_U9_ASN.STATUSs.Counting.GetValue()).Any()).Select(q => q.ORDER_NO).ToList();
        }
        /// <summary>
        /// 扫描入口
        /// </summary>
        public async Task<ApiAction<ScanOutput>> Scan(BaseInput input)
        {
            var action = new ApiAction<ScanOutput>(new ScanOutput());
            try
            {
                if (input.SN.IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L("条码不能为空");
                    action.LocaleMsg = Biz.L("WMS.Default.ScanItem.SnEmptyFailure");
                    return SetOutPutMqttMsg(action, input.Locale);
                }
                //扫描物料并复核
                else //if (Command == "Normal")
                {
                    action = await ScanItem(input);
                }
            }
            catch (Exception ex)
            {
                //取消当前操作
                ResetTrans();
                //action.CatchExceptionWithLog(ex, $"扫描[{input.SN}]异常");
                action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
            }
            return SetOutPutMqttMsg(action, input.Locale);
        }
 
        /// <summary>
        /// 扫描物料并复核
        /// </summary>
        public async Task<ApiAction<ScanOutput>> ScanItem(BaseInput input)
        {
            var action = new ApiAction<ScanOutput>(new ScanOutput() { Command = Command });
            try
            {
                //解析条码
                Barcode barcode = new Barcode(input.SN);
                if (barcode.IsException)
                {
                    throw barcode.AnalyseException;
                }
                //非法条码
                else if (!barcode.IsRegular)
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L("条码为非法条码");
                    action.LocaleMsg = Biz.L("WMS.WmsItem.Barcode.IllegalFailure", input.SN);
                    return SetOutPutMqttMsg(action, input.Locale); ;
                }
 
                if (barcode.Type == Barcode.Types.OuterPackage)
                {
                    CurSn = MainDB.Queryable<BIZ_U9_ASN_SN>().Where(q => q.CARTON_NO == barcode.SN).ToList();
                }
                else
                {
                    CurSn = MainDB.Queryable<BIZ_U9_ASN_SN>().Where(q => q.SN == barcode.SN).ToList();
                    foreach (var sn in CurSn)
                    {
                        sn.META_SN = input.SN;
                    }
                }
 
                if (CurSn.IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L("ASN单中不存在条码[{0}]");
                    action.LocaleMsg = Biz.L("WMS.Count_BIZ_U9_ASN.SnNotExists", input.SN);
                    return SetOutPutMqttMsg(action, input.Locale); ;
                }
                if (CurSn.First().AUTH_ORG != input.AuthOption.CurOrg)
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L($"条码所属组织[{0}]与当前登录组织[{1}]不一致,请重新选择组织");
                    action.LocaleMsg = Biz.L("WMS.Count_BIZ_U9_ASN.OrgNotCorrect", CurSn.First().AUTH_ORG, input.AuthOption.CurOrg);
                    return SetOutPutMqttMsg(action, input.Locale); ;
                }
                //验证条码是否正确
                if (CurSn.First().STATUS > WMS_ITEM.STATUSs.Incoming.GetValue())
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L("状态[{0}]异常,请重新扫描");
                    action.LocaleMsg = Biz.L("WMS.Default.ScanItem.StatusException", CurSn.First().STATUS.GetEnumDesc<WMS_ITEM.STATUSs>());
                    return SetOutPutMqttMsg(action, input.Locale); ;
                }
 
                //执行清点数据处理
                foreach (var sn in CurSn)
                {
                    sn.STATUS = WMS_ITEM.STATUSs.Counted.GetValue();
                    sn.RECEIVER = UserCode;
                    sn.RECEIVE_DATE = DateTime.Now;
                }
 
                //创建变量克隆对象用于传入DBSubmitAction中保存当前需要暂存的数据值
                var _CurSn = CurSn.Clone();
                AddCommitAction("Counted", () =>
                {
                    //使用统一的事务DB对象
                    var db = GetCommitDB();
                    //数据保存逻辑
                    db.Updateable<BIZ_U9_ASN>(UserCode).SetColumns(q => q.STATUS == BIZ_U9_ASN.STATUSs.Counting.GetValue()).Where(q => q.ORDER_NO == _CurSn.First().ORDER_NO).ExecuteCommand();
                    db.Storageable(_CurSn, UserCode).ExecuteCommand();
                });
 
                //完成所有处理后使用事务保存数据
                action = DoIfFinish(action, input.Locale, () =>
                {
                    if (!OrderList.Contains(CurSn.First().ORDER_NO))
                    {
                        OrderList.Add(CurSn.First().ORDER_NO);
                    }
                    ScanList.AddRange(CurSn);
                });
            }
            catch (Exception ex)
            {
                //取消当前操作
                ResetTrans();
                //action.CatchExceptionWithLog(ex, $"扫描条码[{0}]复核异常");
                action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", input.SN));
            }
            return SetOutPutMqttMsg(action, input.Locale);
        }
 
        /// <summary>
        /// 完成所有处理后使用事务保存数据
        /// </summary>
        /// <param name="action"></param>
        /// <param name="locale"></param>
        /// <param name="doAfterSave"></param>
        /// <returns></returns>
        public ApiAction<ScanOutput> DoIfFinish(ApiAction<ScanOutput> action, string locale, Action doAfterSave = null)
        {
            //保存数据库
            SaveCommitListToDB();
 
            //保存数据成功后执行
            doAfterSave?.Invoke();
 
            // 返回数据
            action.Data.Data = ScanList;
 
            //action.LocaleMsg = Biz.L($"条码[{0}]清点成功!");
            action.LocaleMsg = Biz.L("WMS.Count_BIZ_U9_ASN.CountSuccess", CurSn.First().SN);
 
            //重置工序
            ResetTrans();
            return SetOutPutMqttMsg(action, locale); ;
        }
 
        /// <summary>
        /// 删除当前所有已清点记录
        /// </summary>
        /// <returns></returns>
        public async Task<ApiAction> DeleteScannedList()
        {
            var action = new ApiAction();
            try
            {
                foreach (var sn in ScanList)
                {
                    sn.STATUS = WMS_ITEM.STATUSs.Incoming.GetValue();
                    sn.RECEIVER = null;
                    sn.RECEIVE_DATE = DateTime.MinValue;
                }
 
                //var historys = new List<WMS_ITEM_HIS>();
                //var items = await Biz.Db.Queryable<WMS_ITEM>().Where(q => ScanList.Select(s => s.SN).Contains(q.SN)).ToListAsync();
                //foreach (var item in items)
                //{
                //    var order = item.TRANS_CODE;
                //    item.STATUS = WMS_ITEM.STATUSs.Incoming.GetValue();
                //    item.SOURCE_CODE = "";
                //    item.SOURCE_ORDER = "";
                //    item.SOURCE_LINE = "";
                //    item.TRANS_CODE = item.SOURCE_CODE;
                //    item.TRANS_NO = item.SOURCE_ORDER;
                //    item.TRANS_LINE = item.SOURCE_LINE;
                //    historys.Add(new WMS_ITEM_HIS(item, $"条码[{item.SN}]取消清点,操作单据[{order}]"));
                //}
 
                //使用统一的事务DB对象
                var db = GetCommitDB();
                var dbTran = db.UseTran(() =>
                {
                    db.Updateable(ScanList, UserCode).UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.STATUS }).ExecuteCommandAsync();
                    //db.Updateable(items, UserCode).ExecuteCommand();
                    //db.Insertable(historys, UserCode).ExecuteCommand();
                });
                if (dbTran.IsSuccess)
                {
                    ScanList.Clear();
                }
                else
                {
                    Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception");
                    //抛出异常
                    throw dbTran.ErrorException;
                }
            }
            catch (System.Exception ex)
            {
                //return action.CatchExceptionWithLog(ex, Biz.L("删除当前所有已清点记录异常"));
                return action.CatchExceptionWithLog(ex, Biz.L("WMS.Count_BIZ_U9_ASN.DeleteScanListException"));
            }
            return action;
        }
 
        /// <summary>
        /// 删除当前用户的已扫单个记录
        /// </summary>
        /// <returns></returns>
        public async Task<ApiAction> DeleteScannedSn(BaseInput input)
        {
            var action = new ApiAction();
            try
            {
                //var item = await Biz.Db.Queryable<WMS_ITEM>().Where(q => q.SN == input.SN).FirstAsync();
                //var order = item.TRANS_CODE;
                //item.STATUS = WMS_ITEM.STATUSs.Incoming.GetValue();
                //item.SOURCE_CODE = "";
                //item.SOURCE_ORDER = "";
                //item.SOURCE_LINE = "";
                //item.TRANS_CODE = item.SOURCE_CODE;
                //item.TRANS_NO = item.SOURCE_ORDER;
                //item.TRANS_LINE = item.SOURCE_LINE;
 
                //使用统一的事务DB对象
                var db = GetCommitDB();
                var dbTran = db.UseTran(() =>
                {
                    db.Updateable<BIZ_U9_ASN_SN>(UserCode).SetColumns(q => q.STATUS == WMS_ITEM.STATUSs.Incoming.GetValue())
                        .SetColumns(q => q.RECEIVER == null)
                        .SetColumns(q => q.RECEIVE_DATE == DateTime.MinValue)
                        .Where(q => q.SN == input.SN).ExecuteCommand();
                    //db.Updateable(item, UserCode).ExecuteCommand();
                    //db.Insertable(new WMS_ITEM_HIS(item, $"条码[{item.SN}]取消清点,操作单据[{order}]"), UserCode).ExecuteCommand();
                });
                if (dbTran.IsSuccess)
                {
                    ScanList.RemoveAll(q => q.SN == input.SN);
                }
                else
                {
                    Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception");
                    //抛出异常
                    throw dbTran.ErrorException;
                }
            }
            catch (System.Exception ex)
            {
                //return action.CatchExceptionWithLog(ex, Biz.L("删除已清点条码[{0}]异常"));
                return action.CatchExceptionWithLog(ex, Biz.L("WMS.Count_BIZ_U9_ASN.DeleteScannedSnException", input.SN));
            }
            return action;
        }
 
        /// <summary>
        ///  获取本次已清点的物料列表(带分页)
        /// </summary>
        /// <returns></returns>
        public async Task<ApiAction<PageAble<BIZ_U9_ASN_SN>>> GetScannedList(BaseInputWithPage input)
        {
            var action = new ApiAction<PageAble<BIZ_U9_ASN_SN>>();
            action.Data = new PageAble<BIZ_U9_ASN_SN>();
            action.Data.pageSize = input.pageSize;
            action.Data.pageIndex = input.pageIndex;
            action.Data.totals = ScanList.Count;
            action.Data.data = ScanList.Skip((input.pageIndex - 1) * input.pageSize).Take(input.pageSize).ToList();
            //action.Data = query;
            return action;
        }
 
        /// <summary>
        ///  获取当前所有单据信息
        /// </summary>
        /// <returns></returns>
        public async Task<ApiAction<List<BIZ_U9_ASN>>> GetOrderList()
        {
            var action = new ApiAction<List<BIZ_U9_ASN>>();
            action.Data = await Biz.Db.Queryable<BIZ_U9_ASN>().Where(q => OrderList.Contains(q.ORDER_NO)).IncludesAllFirstLayer().ToListAsync();
            if (!action.Data.IsNullOrEmpty())
            {
                foreach (var order in action.Data)
                {
                    foreach (var dtl in order.Details)
                    {
                        dtl.SnList = order.SnList.Where(q => q.LINE_NO == dtl.LINE_NO).OrderByDescending(q => q.STATUS).ToList();
                        dtl.QTY_COUNTED = dtl.SnList.Where(q => q.STATUS == WMS_ITEM.STATUSs.Counted.GetValue() || q.STATUS == WMS_ITEM.STATUSs.Rejected.GetValue()).Sum(q => q.QTY);
                    }
                    order.IsFinished = !order.Details.Where(q => q.QTY != q.QTY_COUNTED).Any();
                }
            }
            return action;
        }
 
        /// <summary>
        ///  生成收货单:调用U9新增收货单接口
        /// </summary>
        /// <returns></returns>
        public async Task<ApiAction> SetGiftQty(BaseInput input)
        {
            var action = new ApiAction();
            try
            {
                var dtl = input?.Data?.JsonToObject<BIZ_U9_ASN_DTL>();
                if ((dtl?.ID ?? "").IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L($"提交的收货单明细ID不能为空");
                    action.LocaleMsg = Biz.L("WMS.Count_BIZ_U9_ASN.SetGiftQty.DetailIDIsNull");
                    return action;
                }
 
                //使用统一的事务DB对象
                var db = GetCommitDB();
                await db.Updateable(dtl, UserCode).UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.QTY_GIFT }).ExecuteCommandAsync();
            }
            catch (System.Exception ex)
            {
                //return action.CatchExceptionWithLog(ex, Biz.L("设置收货单明细赠品数量为异常"));
                return action.CatchExceptionWithLog(ex, Biz.L("WMS.Count_BIZ_U9_ASN.SetGiftQtyException"));
            }
            return action;
        }
 
        /// <summary>
        /// 生成收货单:调用U9新增收货单接口
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction> GenerateReceipt(BaseInput input)
        {
            var action = new ApiAction();
            var orderNo = input.Data;
            try
            {
                var order = await MainDB.Queryable<BIZ_U9_ASN>().Where(q => q.ORDER_NO == orderNo).Includes(q => q.Details, d => d._ItemInfos).IncludesAllFirstLayer().FirstAsync();
                if (order.IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L($"找不到送货单[{0}]的单据信息,请提交正确的单号");
                    action.LocaleMsg = Biz.L("WMS.Count_BIZ_U9_ASN.GenerateReceipt.ASNNotExists", orderNo);
                    return action;
                }
                //验证条码是否正确
                if (order.STATUS != BIZ_U9_ASN.STATUSs.Counting.GetValue())
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L("生成收货单:送货单状态[{0}]异常");
                    action.LocaleMsg = Biz.L("WMS.Count_BIZ_U9_ASN.GenerateReceipt.StatusException", order.STATUS.GetEnumDesc<BIZ_U9_ASN.STATUSs>());
                    return action;
                }
 
                //查询是否存在清点完成的行明细,如果有则先提交完成的行,如果没有则报错
                var finishNotSubmit = order.Details.Where(q => SqlFunc.IsNullOrEmpty(q.RECEIVER_NO) && q.QTY == order.SnList.Where(s => s.LINE_NO == q.LINE_NO && (s.STATUS == WMS_ITEM.STATUSs.Counted.GetValue() || q.STATUS == WMS_ITEM.STATUSs.Rejected.GetValue())).Sum(s => s.QTY)).ToList();
                var noFinish = order.Details.Where(q => q.QTY != order.SnList.Where(s => s.LINE_NO == q.LINE_NO && (s.STATUS == WMS_ITEM.STATUSs.Counted.GetValue() || q.STATUS == WMS_ITEM.STATUSs.Rejected.GetValue())).Sum(s => s.QTY));
                if (!finishNotSubmit.Any())
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L("送货单[{0}]没有清点完成可以提交的行,未完成清点的行号如下:{1}");
                    action.LocaleMsg = Biz.L("WMS.Count_BIZ_U9_ASN.GenerateReceipt.NoFinishCounting", orderNo, string.Join(",", noFinish.Select(q => q.LINE_NO)));
                    return action;
                }
 
                var iInput = new CreateRcvBySrcASNInput
                {
                    userId = UserCode,
                    IsLogin = true,
                    CreateRcvBySrcASNParam = new()
                    {
                        aSNToRcvTransDTOs = finishNotSubmit.Select(q => new ASNToRcvTransDTO
                        {
                            ASNLineKey = q.ID,
                            TransQty = new() { m_amount1 = q.QTY },
                            BinInfoList = new() { new() { Bin = new() { m_code = q.ItemInfo.DEFAULT_LOCATION }, LocationQtySU = q.QTY, LocationQtyTU = q.QTY } },
                        }).ToList(),
                    }
                };
                var result = await DI.Resolve<IWMS_U9C>().CreateRcvBySrcASN(iInput);
                if (!result.IsSuccessed)
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = result.LocaleMsg;
                    return action;
                }
 
                //根据接口返回收货单单号查询单据明细,并创建条码明细
                var receipt = new BIZ_U9_RECEIPT();
                receipt.Details = new();
                receipt.SnList = new();
                DbClient U9Cdb = Biz.DataSource["YadaU9C"].Client;
                var list = U9Cdb.Queryable<mes_ReturnedDocInfo>().Where(x => x.RcvId == result.Data[0].ID.ToDouble() && x.DocNo == result.Data[0].Code && x.SplitFlag != 1).ToList();
 
                if (list != null && list.Count > 0)
                {
                    receipt.ID = list.First().RcvId.ToString();
                    receipt.AUTH_ORG = order.AUTH_ORG;
                    receipt.STATUS = BIZ_U9_RECEIPT.STATUSs.InQC.GetValue();
                    receipt.ORDER_NO = list.First().DocNo;
                    receipt.SUPP_CODE = list.First().SupplierCode;
                    receipt.SUPP_NAME = list.First().SupplierName;
                    receipt.RECEIVER = UserCode;
                    receipt.RECEIVE_DATE = DateTime.Now;
                    receipt.ASN_ID = order.ID;
                    receipt.ASN_NO = order.ORDER_NO;
                    receipt.ORDER_DATE = list.First().ModifiedOn;
                    receipt.HANDLED = 0;
                    receipt.HANDLED_DATE = DateTime.Now;
 
                    foreach (var item in list)
                    {
                        var asnDtl = finishNotSubmit.First(q => q.ID == item.SrcASNDocLineId.ToString());
                        BIZ_U9_RECEIPT_DTL receiptDt = new()
                        {
                            ID = item.RcvLineId.ToString(),
                            AUTH_ORG = receipt.AUTH_ORG,
                            STATUS = BIZ_U9_RECEIPT.STATUSs.InQC.GetValue(),
                            ORDER_NO = item.DocNo,
                            LINE_NO = item.DocLineNo.ToString(),
                            ITEM_CODE = item.ItemCode,
                            QTY = item.EyeballingQtyTU.ToDouble(), // mes单据数量 --U9退补数量
                            QTY_GIFT = asnDtl.QTY_GIFT,
                            ASN_ID = item.SrcASNDocId.ToString(),
                            ASN_NO = asnDtl.ORDER_NO,
                            ASN_LINE_ID = item.SrcASNDocLineId.ToString(),
                            ASN_LINE = asnDtl.LINE_NO,
                            ERP_CODE = item.ItemCode1,
                            ERP_STATUS_CODE = item.Status.ToString(),
                            ERP_STATUS_NAME = item.StatusName,
                        };
                        receipt.Details.Add(receiptDt);
                        asnDtl.STATUS = BIZ_U9_ASN.STATUSs.Finished.GetValue();
                        asnDtl.RECEIVER_ID = item.RcvId.ToString();
                        asnDtl.RECEIVER_NO = item.DocNo;
                        asnDtl.RECEIVER_LINE = item.DocLineNo.ToString();
                        asnDtl.RECEIVER = UserCode;
                        asnDtl.RECEIVE_DATE = DateTime.Now;
                    }
 
                    foreach (var sn in order.SnList.Where(q=> finishNotSubmit.Any(s => s.LINE_NO == q.LINE_NO)))
                    {
                        var dtl = receipt.Details.First(q => q.ASN_LINE == sn.LINE_NO);
                        BIZ_U9_RECEIPT_SN receiptSn = new()
                        {
                            AUTH_ORG = dtl.AUTH_ORG,
                            ORDER_NO = dtl.ORDER_NO,
                            LINE_NO = dtl.LINE_NO,
                            SN = sn.SN,
                            META_SN = sn.META_SN,
                            ITEM_CODE = sn.ITEM_CODE,
                            STATUS = WMS_ITEM.STATUSs.WaitIn.GetValue(),
                            QTY = sn.QTY,
                            UNIT = sn.UNIT,
                            IS_OK = sn.IS_OK,
                            IS_IN = sn.IS_IN,
                            LOTNO = sn.LOTNO,
                            CARTON_NO = sn.CARTON_NO,
                            PALLET_NO = sn.PALLET_NO,
                        };
                        receipt.SnList.Add(receiptSn);
                    }
                }
 
                //更新库存表信息
                var items = MainDB.Queryable<WMS_ITEM>().Where(q => SqlFunc.Subqueryable<BIZ_U9_ASN_SN>().Where(s => s.SN == q.SN && s.ORDER_NO == order.ORDER_NO).Any()).ToList();
                var historys = new List<WMS_ITEM_HIS>();
                foreach (var item in items)
                {
                    item.AUTH_ORG = receipt.AUTH_ORG;
                    item.STATUS = WMS_ITEM.STATUSs.WaitIn.GetValue();
                    item.SOURCE_CODE = item.TRANS_CODE;
                    item.SOURCE_ORDER = item.TRANS_NO;
                    item.SOURCE_LINE = item.TRANS_LINE;
                    item.TRANS_CODE = nameof(BIZ_U9_RECEIPT);
                    item.TRANS_NO = receipt.ORDER_NO;
                    item.TRANS_LINE = receipt.SnList.First(q => q.SN == item.SN).LINE_NO;
                    historys.Add(new WMS_ITEM_HIS(item, $"送货单[{order.ORDER_NO}]的条码[{item.SN}]生成收货单[{receipt.ORDER_NO}],待检验完成后可入库"));
                }
                var pkgs = MainDB.Queryable<WMS_ITEM_PKG>().Where(q => SqlFunc.Subqueryable<BIZ_U9_ASN_SN>().Where(s => s.SN == q.SN && s.ORDER_NO == order.ORDER_NO).Any()).ToList();
                foreach (var item in pkgs)
                {
                    item.AUTH_ORG = receipt.AUTH_ORG;
                    item.SOURCE_CODE = item.TRANS_CODE;
                    item.SOURCE_ORDER = item.TRANS_NO;
                    item.SOURCE_LINE = item.TRANS_LINE;
                    item.TRANS_CODE = nameof(BIZ_U9_RECEIPT);
                    item.TRANS_NO = receipt.ORDER_NO;
                    item.TRANS_LINE = receipt.SnList.First(q => q.SN == item.SN).LINE_NO;
                }
                if (!noFinish.Any())
                {
                    order.STATUS = BIZ_U9_ASN.STATUSs.Finished.GetValue();
                    order.RECEIVER = UserCode;
                    order.RECEIVE_DATE = DateTime.Now;
                }
 
                //使用统一的事务DB对象
                var db = GetCommitDB();
                var dbTran = db.UseTran(() =>
                {
                    db.Updateable(items, UserCode).UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.AUTH_ORG, q.STATUS, q.TRANS_CODE, q.TRANS_NO, q.TRANS_LINE, q.SOURCE_CODE, q.SOURCE_ORDER, q.SOURCE_LINE }).ExecuteCommand();
                    db.Updateable(pkgs, UserCode).UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.AUTH_ORG, q.TRANS_CODE, q.TRANS_NO, q.TRANS_LINE, q.SOURCE_CODE, q.SOURCE_ORDER, q.SOURCE_LINE }).ExecuteCommand();
                    db.Insertable(historys, UserCode).ExecuteCommand();
                    db.Updateable(order, UserCode).UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.STATUS, q.RECEIVER, q.RECEIVE_DATE, q.RECEIVER_ID, q.RECEIVER_NO }).ExecuteCommand();
                    db.Updateable(finishNotSubmit, UserCode).UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.STATUS, q.RECEIVER, q.RECEIVE_DATE, q.RECEIVER_ID, q.RECEIVER_NO }).ExecuteCommand();
                    db.Insertable(receipt, UserCode).ExecuteCommand();
                    db.Insertable(receipt.Details, UserCode).ExecuteCommand();
                    db.Insertable(receipt.SnList, UserCode).ExecuteCommand();
                });
                if (dbTran.IsSuccess)
                {
                    //action.LocaleMsg = Biz.L($"送货单[{0}]生成收货单[{1}]成功");
                    action.LocaleMsg = Biz.L("WMS.Count_BIZ_U9_ASN.GenerateReceipt.Success", order.ORDER_NO, receipt.ORDER_NO);
                }
                else
                {
                    Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception");
                    //抛出异常
                    throw dbTran.ErrorException;
                }
            }
            catch (System.Exception ex)
            {
                //return action.CatchExceptionWithLog(ex, Biz.L("送货单[{0}]生成收货单异常"));
                return action.CatchExceptionWithLog(ex, Biz.L("WMS.Count_BIZ_U9_ASN.GenerateReceiptException", orderNo));
            }
            return action;
        }
 
        #endregion
 
        /// <summary>
        /// 重置事务数据,有需要则重写此方法
        /// </summary>
        public override void ResetTrans()
        {
            ResetScan();
            CurScanShelf = null;
            base.ResetTrans();
        }
 
        /// <summary>
        /// 重置本次扫码信息
        /// </summary>
        public override void ResetScan()
        {
            Command = "Normal";
            CurInvItem = null;
            CurSn = null;
            base.ResetScan();
        }
 
        public override bool Close(bool needSaveHistoryLog = false)
        {
            this.IsFinished = true;
            return IsFinished ? base.Close(needSaveHistoryLog) : IsFinished;
        }
 
    }//endClass
}