wxw
2025-05-12 c7c2f7aa20427204944ba80a2704232b2f281582
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
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
using Model.ModelDto;
using Model.ModelVm;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using WMS.Entity.Context;
using WMS.IBLL.IPdaServer;
using WMS.DAL;
using WMS.Entity.BllAsnEntity;
using WMS.Entity.DataEntity;
using WMS.Entity.SysEntity;
 
namespace WMS.BLL.BllPdaServer
{
    public class PdaAsnServer : IPdaAsnServer
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
 
        // 获取单据列表
        public List<ArrivalNoticeDto> GetArrivalNotices(ArrivalNoticeVm model)
        {
            string sqlString = string.Empty;
            try
            {
                // 未关单的单据
                sqlString = $"select * from BllArrivalNotice where Status != '3' and IsDel='0' order by CreateTime;";
                var modelList = Db.Ado.SqlQuery<ArrivalNoticeDto>(sqlString);
 
                return modelList;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 
        // 根据单据号获取单据明细列表
        public List<ArrivalNoticeDetailDto> GetArrivalNoticeDetails(ArrivalNoticeVm model)
        {
            string sqlString = string.Empty;
            try
            {
                sqlString = $"select * from BllArrivalNoticeDetail where ASNNo = '{model.ASNNo}' and isdel='0' order by CreateTime;";
                var modelList = Db.Ado.SqlQuery<ArrivalNoticeDetailDto>(sqlString);
 
                return modelList;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 
        // 根据单据明细ID获取明细详情
        public ArrivalNoticeDetailDto GetArrivalNoticeDetail(ArrivalNoticeDetailVm model)
        {
            string sqlString = string.Empty;
            try
            {
                if (model.Id == null || model.Id == 0)
                {
                    throw new Exception("明细ID不可为空!");
                }
 
                sqlString = $"select * from BllArrivalNoticeDetail where Id = '{model.Id}' and isdel='0' order by CreateTime;";
                var modelList = Db.Ado.SqlQuery<ArrivalNoticeDetailDto>(sqlString);
 
                if (modelList.Count > 0)
                {
                    return modelList[0];
                }
 
                return new ArrivalNoticeDetailDto();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 
        /// <summary>
        /// 验证托盘是否存在
        /// </summary>
        /// <param name="palletNo">托盘号</param>
        /// <returns>"":可使用 -1:不可使用(原因)</returns>
        public string IsEnablePalletNo(string palletNo)
        {
            string sqlMsg = "";
            string sqlString = string.Empty;
            try
            {
                sqlString = $"select * from SysPallets where PalletNo = '{palletNo}' and isdel = '0';";
                var models = Db.Ado.SqlQuery<PalletBindVm>(sqlString);
 
                if (models.Count > 1)
                {
                    sqlMsg = "-1:存在重复托盘号,请检查!";
                    return sqlMsg;
                }
                if (models.Count > 0)
                {
                    if (models[0].Status == "1")
                    {
                        sqlString = $"select count(id) from DataStockDetail where PalletNo = '{palletNo}' and isnull(LocatNo,'') != '' and isdel = '0';";
                        int rowNum = Db.Ado.GetInt(sqlString);
                        if (rowNum > 0)
                        {
                            sqlMsg = "-1:托盘使用中,此托盘应在库内请核实!";
                        }
                    }
                }
                else
                {
                    sqlMsg = "-1:托盘号不存在!";
                }
 
                return sqlMsg;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 
        // 根据箱码或托盘号获取箱支信息   liudl 
        public List<BoxInfoDto> GetBoxInfos(BoxInfoVm model)
        {
            try
            {
                var sqlString = "select BoxNo, SkuNo,SkuName, LotNo, SUM(Qty) as Qty from BllBoxInfo where IsDel = '0' ";
                if (!string.IsNullOrEmpty(model.PalletNo))
                {
                    sqlString += $"and PalletNo = '{model.PalletNo}' and Status = '1' ";
                }
                if (!string.IsNullOrEmpty(model.BoxNo))
                {
                    sqlString += $"and BoxNo = '{model.BoxNo}' and Status in ('0','1') ";
                }
                sqlString += $"group by BoxNo,SkuNo,SkuName,LotNo; ";
                var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
 
                return models;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 
        // 绑定物料托盘
        public void BindPallet(PdaPalletBindVm model, int userId)
        {
            try
            {
                #region 判断
 
                if (string.IsNullOrEmpty(model.AsnNo))
                {
                    throw new Exception("-1:单据号不可为空!");
                }
                if (model.AsnDetailId == null || model.AsnDetailId == 0)
                {
                    throw new Exception("-1:物料不可为空!");
                }
                if (string.IsNullOrEmpty(model.PalletNo))
                {
                    throw new Exception("-1:托盘号不可为空!");
                }
                if (string.IsNullOrEmpty(model.BoxNo))
                {
                    throw new Exception("-1:物料数量不可为空!");
                }
 
                if (model.IsContinue == "1")
                {
                    if (string.IsNullOrWhiteSpace(model.TailBoxNo))
                    {
                        throw new Exception("-1:开启连续组托时,尾箱码信息不可为空!");
                    }
 
                }
                #endregion
 
                Db.BeginTran();
 
                //托盘是否存在
                var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
                if (pallet == null)
                {
                    throw new Exception("未查询到托盘信息,请核实!");
                }
                // 验证入库单明细是否存在
                var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo);
                if (detail == null)
                {
                    throw new Exception("-1:当前物料及批次与单据无关联,请核实!");
                }
                #region 包装
                var package = Db.Queryable<SysPackag>().Where(m => m.IsDel == "0");
                var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo);
                var pack = package.First(m => m.IsDel == "0" && m.PackagNo == sku.PackagNo);
                var pNum = 0;//托盘物品数量 
                var bNum = 0;//箱码物品数量 
                if (pack.L5Num.HasValue)
                {
                    pNum = (int)pack.L5Num;
                    bNum = (int)pack.L4Num;
                }
                else if (pack.L4Num.HasValue)
                {
                    pNum = (int)pack.L4Num;
                    bNum = (int)pack.L3Num;
                }
                else if (pack.L3Num.HasValue)
                {
                    pNum = (int)pack.L3Num;
                    bNum = (int)pack.L2Num;
                }
                else if (pack.L2Num.HasValue)
                {
                    pNum = (int)pack.L2Num;
                    bNum = (int)pack.L1Num;
                }
                else if (pack.L1Num.HasValue)
                {
                    pNum = (int)pack.L1Num;
                    bNum = (int)pack.L1Num;
                }
                if (pNum == 0 || bNum == 0)
                {
                    throw new Exception($"绑定失败,{detail.SkuNo}物品包装未找到!");
                }
 
                var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo);
 
                var bindId = 0;
                if (bind == null)
                {
                    bind = new BllPalletBind
                    {
                        ASNNo = model.AsnNo,
                        ASNDetailNo = (int)model.AsnDetailId,
                        PalletNo = model.PalletNo,
                        PalletNo2 = "",
                        PalletNo3 = "",
                        Qty = int.Parse(model.BoxNo),
                        FullQty = pNum,
                        Status = "0",
                        Type = "0",
                        LotNo = detail.LotNo,
                        LotText = detail.LotText,
                        SupplierLot = detail.SupplierLot,
                        InspectMark = "1",
                        BitPalletMark = pNum == int.Parse(model.BoxNo) ? "0" : "1",
                        IsBale = "0",
                        IsBelt = "0",
                        CreateUser = userId
                    };
                    // 插入托盘绑定表
                    bindId = Db.Insertable(bind).ExecuteReturnIdentity();
                }
                else
                {
                    if (bind.Status != "0")
                    {
                        throw new Exception("-1:当前托盘正在执行中,绑定失败,请核实!");
                    }
                    bindId = bind.Id;
                }
 
                #region 箱码信息
                var boxInfoList = new List<BllBoxInfo>();
                //首箱
                var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo && m.Status == "0").ToList();
                if (boxInfo.Count == 0)
                {
                    throw new Exception("-1:箱码信息不存在!");
                }
                boxInfoList.AddRange(boxInfo);
                //是否连续组托
                if (model.IsContinue == "1")
                {
                    //尾箱
                    var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo).ToList();
                    if (boxInfo2.Count == 0)
                    {
                        throw new Exception("-1:尾箱码信息不存在!");
                    }
                    boxInfoList.AddRange(boxInfo2);
                    var sql = $"select * from BllBoxInfo where IsDel = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; ";
                    var list = Db.Ado.SqlQuery<BllBoxInfo>(sql);
                    boxInfoList.AddRange(list);
                }
                #endregion
 
 
 
 
                #endregion
                // 更改箱支关系表
                var factQty = 0;//托盘总数量
                var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList();
                foreach (var g in boxGroup)
                {
                    var boxFullQty = 0;//箱内总数量
                    foreach (var box in g)
                    {
                        if (box.BindNo != null && box.BindNo != 0)
                        {
                            continue;
                        }
                        //箱内物料批次与单据明细不符合
                        if (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo)
                        {
                            throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!");
                        }
 
                        box.ASNNo = model.AsnNo;
                        box.ASNDetailNo = model.AsnDetailId;
                        box.BindNo = bindId;
                        box.PalletNo = model.PalletNo;
                        box.Status = "1";
                        box.CompleteTime = DateTime.Now;
                        box.UpdateTime = DateTime.Now;
                        box.UpdateUser = userId;
 
                        factQty += box.Qty;
                        boxFullQty += box.Qty;
                    }
                    if (boxFullQty > bNum)
                    {
                        throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!");
                    }
                }
                Db.Updateable(boxInfoList).ExecuteCommand();
 
                // 更新托盘绑定表
                bind.Qty += factQty;
                if (bind.FullQty < bind.Qty)
                {
                    throw new Exception("托盘绑定数量已超出该物料包装数量");
                }
 
                if (bind.FullQty == bind.Qty)
                {
                    bind.BitPalletMark = "1";
                }
                Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
 
                // 更改入库单明细已组数量
                var sqlString = string.Empty;
                sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{factQty}' where id = '{model.AsnDetailId}';";
                Db.Ado.ExecuteCommand(sqlString);
 
                // 更改入库单及入库明细状态
                if (detail.Status == "0")
                {
                    var sqlString2 = string.Empty;
                    sqlString2 += $"update BllArrivalNotice set Status = '1',CompleteTime= getDate() where ASNNo = '{model.AsnNo}' and Status ='0';";
                    sqlString2 += $"update BllArrivalNoticeDetail set Status = '1',CompleteTime= getDate() where id = '{model.AsnDetailId}' and Status ='0';";
                    Db.Ado.ExecuteCommand(sqlString2);
                }
 
                // 更改托盘使用状态
                var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
                //添加托盘记录表数据
                sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','组盘','0',getDate(),{userId},NULL,NULL);";
                Db.Ado.ExecuteCommand(sqlStr);
                Db.CommitTran();
 
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                throw ex;
            }
        }
 
        // 绑定空托盘
        public string BindNullPallet(PalletBindVm model)
        {
            string strMsg = "";
            try
            {
                if (string.IsNullOrEmpty(model.PalletNo))
                {
                    strMsg = "-1:托盘号不可为空!";
                    return strMsg;
                }
                if (model.Qty == null || model.Qty == 0)
                {
                    strMsg = "-1:空托盘数量不可为空!";
                    return strMsg;
                }
 
                Db.BeginTran();
                // 插入托盘绑定表
                var modelpb = new BllPalletBind
                {
                    PalletNo = model.PalletNo,
                    PalletNo2 = model.PalletNo2,
                    PalletNo3 = model.PalletNo3,
                    Qty = (int)model.Qty,
                    FullQty = model.FullQty,
                    Status = "0",
                    Type = "1",
                    LotNo = model.LotNo,
                    LotText = model.LotText,
                    SupplierLot = model.SupplierLot,
                    InspectMark = model.InspectMark,
                    BitPalletMark = model.BitPalletMark,
                    IsBale = model.IsBale,
                    IsBelt = model.IsBelt,
                    CreateUser = (int)model.CreateUser,
                    CreateTime = Db.GetDate()
                };
                Db.Insertable(modelpb).ExecuteCommand();
 
                // 更改托盘使用状态
                string sqlStr = string.Empty;
                sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
                Db.Ado.ExecuteCommand(sqlStr);
                Db.CommitTran();
 
                return strMsg;
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                throw ex;
            }
        }
 
        // 删除已组信息
        public string DelBoxInfo(BoxInfoVm model)
        {
            string strMsg = "";
            string sqlString = string.Empty;
            try
            {
                if (model.Id == null || model.Id == 0)
                {
                    strMsg = "-1:箱支ID不可为空!";
                    return strMsg;
                }
 
                // 获取箱支信息和托盘状态(已组未入库的可删除;入库成功又出库的不可删除)
                sqlString = $"select * from BllBoxInfo where id = '{model.Id}' and Status='1' and isdel = '0';";
                var boxModel = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
                if (boxModel.Count <= 0)
                {
                    strMsg = "-1:箱支信息状态已变更或已存在库存信息,请检查!";
                }
 
                // 查询托盘上其他物料数量
                sqlString = string.Empty;
                sqlString += $"select count(id) from BllBoxInfo where PalletNo = '{boxModel[0].PalletNo}' and isdel = '0' and id != '{model.Id}';";
                int rowNum = Db.Ado.GetInt(sqlString);
 
                // 查询入库单明细是否有其他托盘绑定信息
                sqlString = string.Empty;
                sqlString += $"select count(id) from BllBoxInfo where ASNDetailNo = '{boxModel[0].ASNDetailNo}' and isdel = '0' and id != '{model.Id}';";
                int asnDetailNum = Db.Ado.GetInt(sqlString);
 
                // 查询入库单明细是否有其他托盘绑定信息
                sqlString = string.Empty;
                sqlString += $"select count(id) from BllBoxInfo where ASNNo = '{boxModel[0].ASNNo}' and isdel = '0' and id != '{model.Id}';";
                int asnNum = Db.Ado.GetInt(sqlString);
 
                Db.BeginTran();
                // 解除箱支和托盘的关联
                sqlString = string.Empty;
                sqlString = $"Update BllBoxInfo set ASNNo = '',ASNDetailNo='',BindNo = '',PalletNo='' ";
                sqlString += $",UpdateTime=GETDATE(),UpdateUser='{model.CreateUser} where id = '{model.Id}';";
 
                // 判断托盘上是否还有物料 无:删除绑定的托盘信息并更改托盘状态
                if (rowNum <= 0)
                {
                    // 删除托盘绑定信息
                    sqlString = string.Empty;
                    sqlString = $"Update BllPalletBind set IsDel = '1' where id = '{model.Id}';";
 
 
                    // 判断入库单明细是否存在其他已组托盘的
                    if (asnDetailNum <= 0)
                    {
                        // 更改入库单明细状态
                        sqlString = string.Empty;
                        sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty - '{boxModel[0].Qty}',Status = '0', ";
                        sqlString += $"CompleteTime=GETDATE() where id = '{boxModel[0].ASNDetailNo}';";
                        Db.Ado.ExecuteCommand(sqlString);
 
                        // 判断入库单是否有其他组托信息
                        if (asnNum <= 0)
                        {
                            // 更改入库单状态
                            sqlString = string.Empty;
                            sqlString += $"update BllArrivalNotice set Status = '0',CompleteTime=GETDATE() where ASNNo = '{boxModel[0].ASNNo}';";
                            Db.Ado.ExecuteCommand(sqlString);
                        }
                    }
 
                    // 更改托盘状态
                    sqlString = string.Empty;
                    sqlString = $"update SysPallets set Status = '0' where PalletNo = '{boxModel[0].PalletNo}';";
                    Db.Ado.ExecuteCommand(sqlString);
                }
 
                Db.CommitTran();
                return strMsg;
            }
            catch (Exception ex)
            {
                Db.RollbackTran();
                throw ex;
            }
        }
 
        // 平库完成入库操作
        public string CompleteInStock(PalletBindVm model)
        {
            string strMsg = "";
            string sqlString = string.Empty;
            try
            {
                DateTime serverTime = Db.Ado.GetDateTime("select GETDATE();");
                // 验证托盘信息
                sqlString += $"select tb1.*,tb2.Standard,tb2.SkuNo,tb2.SkuName,tb2.PackagNo from BllPalletBind as tb1 ";
                sqlString += "left join  SysMaterials as tb2 on tb1.SkuNo = tb2.SkuNo ";
                sqlString += $"where PalletNo = '{model.PalletNo}' and tb1.isdel = '0' and tb1.Status='0';";
                var bindModels = Db.Ado.SqlQuery<PalletBindVm>(sqlString);
                if (bindModels.Count <= 0)
                {
                    strMsg = "-1:托盘状态变更,请检查!";
                    return strMsg;
                }
                // 验证储位状态
                var locatModel = Db.Queryable<SysStorageLocat>()
                    .First(it => it.LocatNo == model.LocatNo && it.Status == "0" && it.Flag == "0" && it.IsDel == "0");
                if (locatModel == null)
                {
                    strMsg = "-1:储位不可用,请检查储位状态!";
                    return strMsg;
                }
 
                Db.BeginTran();
                // 改变储位状态; 有货物
                sqlString = $"Update SysStorageLocat set Status = '1' where LocatNo = '{model.LocatNo}';";
                Db.Ado.ExecuteCommand(sqlString);
 
                // 改变箱支关系表状态:已入库
                sqlString = "Update BllBoxInfo set Status = '2' where PalletNo = '{model.PalletNo}';";
                Db.Ado.ExecuteCommand(sqlString);
 
                // 改变托盘绑定表状态:已入库 完成时间:当前时间 
                sqlString = "Update BllPalletBind set Status = '2',CompleteTime=GETDATE() where PalletNo = '{model.PalletNo}';";
                Db.Ado.ExecuteCommand(sqlString);
 
                // 改变入库明细表状态:若完成数量和数量相等:执行完成 不相等:正在执行;
                foreach (PalletBindVm bindModel in bindModels)
                {
                    // 判断入库明细是否完成
                    sqlString = $"select count(id) from BllArrivalNoticeDetail where isdel = '0' ";
                    sqlString += $"and Qty = CompleteQty + {bindModel.Qty} and id = '{bindModel.ASNDetailNo}';";
                    int detailNum = Db.Ado.GetInt(sqlString);
                    if (detailNum > 0)
                    {
                        // 改变入库单明细状态和完成时间
                        sqlString = $"Update BllArrivalNoticeDetail set Status = '2',CompleteTime=GETDATE() ";
                        sqlString += $"where id = '{bindModel.ASNDetailNo}';";
                        Db.Ado.ExecuteCommand(sqlString);
 
                        // 判断入库单总表是否完成
                        sqlString = $"select count(id) from BllArrivalNoticeDetail where isdel = '0' and Status != '2' ";
                        sqlString += $"and ASNNo = '{bindModel.ASNNo}' and id !='{bindModel.ASNDetailNo}';";
                        int asnNum = Db.Ado.GetInt(sqlString);
                        if (detailNum <= 0)
                        {
                            // 改变入库单状态和完成时间   若入库明细表所有状态为执行完毕:执行完毕 否:正在执行;
                            sqlString = $"Update BllArrivalNotice set Status = '2',CompleteTime=GETDATE() ";
                            sqlString += $"where ASNNo = '{bindModel.ASNNo}';";
                            Db.Ado.ExecuteCommand(sqlString);
                        }
                    }
 
                    #region 库存总表
                    // 判断当前物料库存表是否已存在
                    var stockModel = Db.Queryable<DataStock>()
                        .First(it => it.SkuNo == bindModel.SkuNo && it.LotNo == bindModel.LotNo
                         && it.Standard == bindModel.Standard && it.SupplierLot == bindModel.SupplierLot && it.IsDel == "0");
 
                    if (stockModel == null || stockModel.Id == 0)
                    {
                        stockModel = new DataStock
                        {
                            LotNo = bindModel.LotNo,
                            LotText = bindModel.LotText,
                            SupplierLot = bindModel.SupplierLot,
                            SkuNo = bindModel.SkuNo,
                            SkuName = bindModel.SkuName,
                            Qty = (int)bindModel.Qty,
                            Standard = bindModel.Standard,
                            CreateUser = (int)model.CreateUser
                        };
                        Db.Insertable<DataStock>(stockModel).ExecuteCommand();
                    }
                    else
                    {
                        sqlString = $"update DataStock set Qty = Qty + {bindModel.Qty}," +
                            $"UpdateTime = GETDATE(),UpdateUser='{model.CreateUser}' where id = '{stockModel.Id}';";
                        Db.Ado.ExecuteCommand(sqlString);
                    }
                    #endregion
 
                    #region 库存明细表
                    // 判断当前托盘是否已存在(拣货回库托盘)
                    var detailModel = Db.Queryable<DataStockDetail>()
                        .First(it => it.PalletNo == bindModel.PalletNo && it.LotNo == bindModel.LotNo && it.SkuNo == bindModel.SkuNo
                         && it.Standard == bindModel.Standard && it.SupplierLot == bindModel.SupplierLot && it.IsDel == "0");
                    if (detailModel == null || detailModel.Id == 0)
                    {
                        // 获取可抽检数量
                        sqlString = "select sum(qty) from BllBoxInfo where isdel = 0 and ";
                        sqlString += $"BindNo = '{bindModel.Id}' and BitBoxMark = '1';";
                        int inspectQty = Db.Ado.GetInt(sqlString);
 
                        // 添加库存明细表
                        detailModel = new DataStockDetail()
                        {
                            LotNo = bindModel.LotNo,
                            LotText = bindModel.LotText,
                            SupplierLot = bindModel.SupplierLot,
                            SkuNo = bindModel.SkuNo,
                            SkuName = bindModel.SkuName,
                            Standard = bindModel.Standard,
                            Qty = bindModel.Qty,
                            InspectQty = inspectQty,
                            ASNNo = bindModel.ASNNo,
                            ASNDetailNo = (int)bindModel.ASNDetailNo,
                            WareHouseNo = locatModel.WareHouseNo,
                            RoadwayNo = locatModel.RoadwayNo,
                            AreaNo = locatModel.AreaNo,
                            LocatNo = model.LocatNo,
                            PalletNo = model.PalletNo,
                            PalletNo2 = bindModel.PalletNo2,
                            PalletNo3 = bindModel.PalletNo3,
                            CompleteTime = serverTime,
                            ProductionTime = bindModel.ProductionTime,
                            ExpirationTime = bindModel.ExpirationTime,
                            Status = "0",
                            InspectMark = bindModel.InspectMark,
                            BitPalletMark = bindModel.BitPalletMark,
                            InspectStatus = bindModel.InspectMark,       // 组盘的时候就要默认设定好是否合格
                            PackagNo = bindModel.PackagNo,
                            IsBale = bindModel.IsBale,
                            IsBelt = bindModel.IsBelt,
                            CreateUser = (int)model.CreateUser
                        };
 
                        Db.Insertable<DataStockDetail>(detailModel).ExecuteCommand();
                    }
                    else
                    {
                        detailModel.LocatNo = model.LocatNo;
                        detailModel.UpdateTime = serverTime;
                        detailModel.UpdateUser = (int)model.CreateUser;
                        // 变更储位地址
                        Db.Updateable<DataStockDetail>(detailModel).UpdateColumns(it => new { it.LocatNo, it.UpdateTime, it.UpdateUser }).ExecuteCommand();
                    }
                    #endregion
 
                    #region 库存箱支明细表
                    // 插入新组的箱支信息
                    sqlString = $"insert into DataBoxInfo ";
                    sqlString += "select BindNo,BoxNo,BoxNo2,BoxNo3,PalletNo,PalletNo2,PalletNo3, ";
                    sqlString += "Qty,FullQty,'0' as Status,LotNo,LotText,ProductionTime,SupplierLot,";
                    sqlString += "InspectMark,BitBoxMark,InspectStatus ";
                    sqlString += $"from BllBoxInfo where isdel = 0 and Status='1' and BindNo = '{bindModel.Id}';";
                    Db.Ado.ExecuteCommand(sqlString);
                    #endregion
                }
 
                Db.CommitTran();
 
                return strMsg;
            }
            catch (Exception ex)
            {
                Db.RollbackTran();
                throw ex;
            }
        }
 
    }
}