wankeda
昨天 734f49c3f74e4a46cfb5892ce60dbf1bb86e74ab
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
using AutoMapper;
using MailKit.Search;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_BasicRepository;
using WIDESEA_Common;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.CodeConfigEnum;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_Core.Utilities;
using WIDESEA_DTO;
using WIDESEA_DTO.Basic;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Outbound;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_IInboundRepository;
using WIDESEA_IInboundService;
using WIDESEA_InboundRepository;
using WIDESEA_IStockRepository;
using WIDESEA_IStockService;
using WIDESEA_ITaskInfoRepository;
using WIDESEA_Model.Models;
using static WIDESEA_Common.HouseInventoryIn;
 
namespace WIDESEA_InboundService
{
    public partial class InboundOrderService : ServiceBase<Dt_InboundOrder, IInboundOrderRepository>, IInboundOrderService
    {
        private readonly IMapper _mapper;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly ITaskRepository _taskRepository;
        private readonly IInboundRepository _inboundRepository;
        private readonly IBasicRepository _basicRepository;
        private IBasicService _basicService;
        private IStockService _stockService;
        private IInboundOrderDetailService _inboundOrderDetailService;
        private IInboundOrder_HtyService _inboundOrderHtyService;
        private IInboundOrderDetail_HtyService _inboundOrderDetail_HtyService;
        private IWarehouseService _warehouseService;
        private readonly IStockRepository _stockRepository;
        private IPalletTypeInfoRepository _palletTypeInfoRepository;
 
        public IInboundOrderRepository Repository => BaseDal;
 
        public InboundOrderService(IInboundOrderRepository BaseDal, IMapper mapper, IBasicService basicService, IBasicRepository basicRepository, IInboundRepository inboundRepository, IUnitOfWorkManage unitOfWorkManage, ITaskRepository taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IInboundOrder_HtyService inboundOrderHtyService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IWarehouseService warehouseService, IStockRepository stockRepository,IPalletTypeInfoRepository palletTypeInfoRepository) : base(BaseDal)
        {
            _mapper = mapper;
            _unitOfWorkManage = unitOfWorkManage;
            _taskRepository = taskRepository;
            _stockService = stockService;
            _inboundRepository = inboundRepository;
            _basicRepository = basicRepository;
            _inboundOrderDetailService = inboundOrderDetailService;
            _inboundOrderHtyService = inboundOrderHtyService;
            _inboundOrderDetail_HtyService = inboundOrderDetail_HtyService;
            _basicService = basicService;
            _warehouseService = warehouseService;
            _stockRepository = stockRepository;
            _palletTypeInfoRepository = palletTypeInfoRepository;
        }
 
        /// <summary>
        /// 组盘
        /// </summary>
        /// <param name="materielGroupDTO"></param>
        /// <returns></returns>
        public WebResponseContent MaterielGroup(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
 
                var orderNo = saveModel.MainData["orderNo"].ToString();
                var palletCode = saveModel.MainData["palletCode"].ToString();
                var warehouseId = saveModel.MainData["warehouseId"].ObjToInt();
                var Initiallife = saveModel.MainData["initiallife"].ObjToInt();
                var serNums = saveModel.DelKeys.Select(x => x.ToString()).ToList();
                Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId);
                if (warehouse == null)
                {
                    return WebResponseContent.Instance.Error($"未找到该仓库信息");
                }
 
                Dt_InboundOrder inboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderNo == orderNo && x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).First();
                if (inboundOrder == null)
                {
                    return WebResponseContent.Instance.Error($"未找到入库单信息");
                }
                if (inboundOrder.Details == null || inboundOrder.Details.Count <= 0)
                {
                    return WebResponseContent.Instance.Error($"未找到入库单明细信息");
                }
                List<MatSerNumAnalysisModel> models = CodeAnalysisHelper.CodeAnalysis<MatSerNumAnalysisModel>(AnalysisCodeEnum.MatSerNumAnalysis, serNums);
                //验证判断时间格式
                WebResponseContent IsValidContent = IsValidMCDates(models);
                if (!IsValidContent.Status)
                {
                    return content.Error(IsValidContent.Message);
                }
 
                string materielCode = models.FirstOrDefault()?.MaterielCode ?? "";
                Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materielCode);
                if (materielInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到该物料的信息");
                }
 
                List<Dt_InboundOrderDetail> inboundOrderDetails = inboundOrder.Details.Where(x => x.MaterielCode == materielCode && x.BatchNo == (models.FirstOrDefault()?.LotNo ?? "")).ToList();
 
                if (inboundOrderDetails == null || inboundOrderDetails.Count <= 0)
                {
                    return WebResponseContent.Instance.Error($"未在入库单明细中找到该物料信息");
                }
                var inboundOrderDet = inboundOrderDetails.FirstOrDefault();
                //Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(palletCode);
 
                decimal beforeQuantity = 0;
 
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
                if (stockInfo == null)
                {
                    stockInfo = new Dt_StockInfo()
                    {
                        BatchNo = inboundOrderDet.BatchNo,
                        PalletCode = palletCode,
                        PalletType =1,//GetPalletType(warehouse, palletCode)
                        IsFull = true,
                        StockStatus = (int)StockStatusEmun.组盘暂存,
                        Creater = "WMS",
                        CreateDate = DateTime.Now,
                        MaterialType = (int)InventoryMaterialType.成品,
                        Materialweight = 0,
                        Wlstatus = (int)InventoryMaterialStatus.合格,
                        Mgeneratetime = DateTime.Now,
                        WarehouseId = warehouse.WarehouseId,
                        Details = new List<Dt_StockInfoDetail>()
                    };
                }
                else
                {
                    if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt())
                    {
                        return WebResponseContent.Instance.Error($"托盘号重复");
                    }
                    beforeQuantity = stockInfo.Details.Sum(x => x.StockQuantity);
                }
 
                if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ToString())
                {
                    stockInfo.Remark = Initiallife.ToString();
                    string batchNo = models.FirstOrDefault()?.LotNo ?? "";
                    //Dt_StockInfoDetail existDetail = _stockRepository.StockInfoDetailRepository.QueryFirst(x => x.BatchNo == batchNo);
                    //if (existDetail != null)
                    //{
                    //    return WebResponseContent.Instance.Error($"{batchNo}测试架已存在");
                    //}
                    if (models.Count >= 2)
                    {
                        return WebResponseContent.Instance.Error($"组盘明细不唯一");
                    }
                    if (palletCode.Substring(0, 1) == "6")
                    {
                        stockInfo.PalletType = PalletTypeEnum.MediumPallet.ObjToInt();
                    }
                    else
                    {
                        stockInfo.PalletType = PalletTypeEnum.LargestPallet.ObjToInt();
                    }
                }
                else if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ToString())
                {
                    if (models.Count >= 2)
                    {
                        return WebResponseContent.Instance.Error($"组盘明细不唯一");
                    }
                }
 
                List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>();
                foreach (var model in models)
                {
                    Dt_InboundOrderDetail? notGroupDetail = inboundOrderDetails.Where(x => x.OrderDetailStatus <= OrderDetailStatusEnum.Inbounding.ObjToInt() && x.MaterielCode == model.MaterielCode && x.BatchNo == model.LotNo && x.OrderQuantity > x.ReceiptQuantity).FirstOrDefault();
 
                    if (notGroupDetail == null)
                    {
                        return WebResponseContent.Instance.Error($"该物料在该入库单中已全部组盘完成");
                    }
                    Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
                    {
                        MaterielCode = inboundOrderDet.MaterielCode,
                        MaterielName = inboundOrderDet.MaterielName,
                        OrderNo = inboundOrder.OrderNo,
                        BatchNo = inboundOrderDet.BatchNo,
                        LinId = inboundOrderDet.LinId,
                        StockQuantity = model.Quantity,
                        Status = (int)StockStatusEmun.组盘暂存,
                        Creater = "WMS",
                        CreateDate = DateTime.Now,
                        Id = inboundOrderDet.LinId.ObjToInt(),
                    };
 
                    if (stockInfo.Id > 0)
                    {
                        stockInfoDetail.StockId = stockInfo.Id;
                    }
                    stockInfo.Details.Add(stockInfoDetail);
 
                    stockInfoDetails.Add(stockInfoDetail);
 
                    decimal decimalReceiptQuantity = Convert.ToDecimal(notGroupDetail.ReceiptQuantity);
                    decimal decimalModelQuantity = Convert.ToDecimal(model.Quantity);
                    decimal decimalOrderQuantity = Convert.ToDecimal(notGroupDetail.OrderQuantity);
                    decimalReceiptQuantity += decimalModelQuantity;
                    // 检查是否超出订单数量
                    if (decimalReceiptQuantity > decimalOrderQuantity)
                    {
                        return WebResponseContent.Instance.Error($"组盘数量溢出{decimalReceiptQuantity - decimalOrderQuantity}");
                    }
                    // 转回float类型存储,但比较和计算都使用decimal完成
                    notGroupDetail.ReceiptQuantity = Convert.ToDecimal(decimalReceiptQuantity);
                    if (notGroupDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
                    {
                        notGroupDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
                    }
                }
 
                decimal totalQuantity = stockInfo.Details.Sum(x => x.StockQuantity);
 
                inboundOrder.OrderStatus = InOrderStatusEnum.入库中.ObjToInt();
 
                _unitOfWorkManage.BeginTran();
                if (stockInfo.Id == 0)
                {
                    _stockRepository.StockInfoRepository.Db.InsertNav(stockInfo).Include(x => x.Details).ExecuteCommand();
                }
                else
                {
                    _stockRepository.StockInfoRepository.Db.UpdateNav(stockInfo).Include(x => x.Details, new UpdateNavOptions() { OneToManyInsertOrUpdate = true }).ExecuteCommand();
                }
                _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetails);
                _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder);
                _unitOfWorkManage.CommitTran();
                content.OK();
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            finally
            {
 
            }
            return content;
        }
        public int GetPalletType(Dt_Warehouse warehouse, string palletCode)
        {
 
            if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ObjToString())
            {
                Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 1));
                if (palletTypeInfo == null)
                {
                    throw new Exception($"托盘号错误");
                }
                return palletTypeInfo.PalletType;
            }
            //else if (warehouse.WarehouseCode == WarehouseEnum.HA152.ObjToString())
            //{
            //    Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
            //    if (palletTypeInfo == null)
            //    {
            //        throw new Exception($"托盘号错误");
            //    }
            //    return palletTypeInfo.PalletType;
            //}
            //else if (warehouse.WarehouseCode == WarehouseEnum.HA57.ObjToString())
            //{
            //    Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 3));
            //    if (palletTypeInfo == null)
            //    {
            //        throw new Exception($"托盘号错误");
            //    }
            //    return palletTypeInfo.PalletType;
            //}
            //else if (warehouse.WarehouseCode == WarehouseEnum.HA58.ObjToString())
            //{
            //    Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
            //    if (palletTypeInfo == null)
            //    {
            //        throw new Exception($"托盘号错误");
            //    }
            //    return palletTypeInfo.PalletType;
            //}
            return -1;
        }
        /// <summary>
        /// 判断正确时间格式
        /// </summary>
        public WebResponseContent IsValidMCDates(List<MatSerNumAnalysisModel> analysisModels)
        {
            string[] effDates = analysisModels.Select(x => x.EffectiveDate).Distinct().ToArray();
            string[] ProDates = analysisModels.Select(x => x.ProductionDate).Distinct().ToArray();
            foreach (string effDate in effDates)
            {
                string format = "yyyy-MM-dd"; // 目标格式
                DateTime parsedDate;
                // 解析并验证格式
                bool isValid = DateTime.TryParseExact(
                    effDate,
                    format,
                    CultureInfo.InvariantCulture,
                    DateTimeStyles.None,
                    out parsedDate
                );
 
                if (!isValid)
                {
                    return WebResponseContent.Instance.Error("格式无效或日期不合法");
                }
            }
            foreach (string ProDate in ProDates)
            {
                string format = "yyyy-MM-dd"; // 目标格式
                DateTime parsedDate;
                // 解析并验证格式
                bool isValid = DateTime.TryParseExact(
                    ProDate,
                    format,
                    CultureInfo.InvariantCulture,
                    DateTimeStyles.None,
                    out parsedDate
                );
 
                if (!isValid)
                {
                    return WebResponseContent.Instance.Error("格式无效或日期不合法");
                }
            }
            return WebResponseContent.Instance.OK();
        }
 
        /// <summary>
        /// 入库单据下发
        /// </summary>
        /// <param name="orderAddDTO"></param>
        /// <returns></returns>
        public WebResponseContent AddInboundOrders(HouseInbound model)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                foreach (var item in model.DetailList)
                {
                    //获取物料信息
                    Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == item.MaterielCode);
                    if (materielInfo == null)
                    {
                        return content.Error($"物料{item.MaterielCode}不存在!");
                    }
                    Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == model.InWarehouse);
                    if (warehouse == null)
                    {
                        return content.Error($"未找到仓库信息");
                    }
                    Dt_InboundOrder inboundOrderOld = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == model.AsnNo).Includes(x => x.Details).First();
                    if (inboundOrderOld != null)
                    {
                        if (inboundOrderOld.OrderStatus != OrderDetailStatusEnum.New.ObjToInt())
                        {
                            return content.Error($"{model.AsnNo}单据已开始!");
                        }
                        Dt_InboundOrderDetail? inboundOrderDetailOld = inboundOrderOld.Details?.FirstOrDefault(x => x.LinId == item.LinId && x.MaterielCode == item.MaterielCode);
                        if (inboundOrderDetailOld != null)
                        {
                            inboundOrderDetailOld.OrderQuantity += item.OrderQuantity;
                            _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetailOld);
                        }
                        else
                        {
                            Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail()
                            {
                                OrderId = inboundOrderOld.Id,
                                MaterielCode = item.MaterielCode,
                                BatchNo = "",
                                OrderQuantity = item.OrderQuantity,
                                ReceiptQuantity = 0,
                                OverInQuantity = 0,
                                OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
                                LinId = item.LinId,
                                MaterielName = materielInfo.MaterielName,
                                MaterieSpec = materielInfo.MaterieSpec
                            };
                            _inboundRepository.InboundOrderDetailRepository.AddData(orderDetail);
                        }
                    }
                    else
                    {
                        Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail()
                        {
                            MaterielCode = item.MaterielCode,
                            BatchNo = item.BatchNo,
                            OrderQuantity = item.OrderQuantity,
                            ReceiptQuantity = 0,
                            OverInQuantity = 0,
                            OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
                            LinId = item.LinId,
                            LPNNo = item.LPN_No,
                            MaterielName = item.MaterielName,
                            MaterieSpec = item.MaterieSpec,
                            Creater = "上游WMS"
                        };
 
                        Dt_InboundOrder inboundOrder = new Dt_InboundOrder()
                        {
                            OrderNo = model.AsnNo,
                            UpperOrderNo = model.AsnNo,
                            WarehouseId = warehouse.WarehouseId,
                            //SupplierId = "",
                            OrderStatus = InboundStatusEnum.未开始.ObjToInt(),
                            CreateType = CreateType.UpperSystemPush.ObjToInt(),
                            Remark = "",
                            TransactionCode = model.TransactionCode,
                            InoutType = model.OrderType,
                            OrderType = model.InoutType.ObjToInt(),
                            Creater = "上游WMS",
                            Details = new List<Dt_InboundOrderDetail> { orderDetail }
                        };
                        //switch (model.OrderType)//单据类型
                        //{
                        //    case 1:
                        //        inboundOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt();
                        //        break;
                        //    case 3:
                        //        inboundOrder.OrderType = InOrderTypeEnum.CustomerRecovery.ObjToInt();
                        //        break;
                        //    case 6:
                        //        inboundOrder.OrderType = InOrderTypeEnum.SaleReturn.ObjToInt();
                        //        break;
                        //    default:
                        //        break;
                        //};
                        Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                    }
                }
                content = WebResponseContent.Instance.OK();
 
 
 
 
                //InboundOrderAddDTO orderAddDTO1 = new InboundOrderAddDTO();
                //orderAddDTO1.OrderNo = orderAddDTO.AsnNo;
                //orderAddDTO1.UpperOrderNo = orderAddDTO.AsnNo;
                //orderAddDTO1.OutWareHouse = orderAddDTO.InWarehouse;
                //orderAddDTO1.TransactionCode = orderAddDTO.TransactionCode;
                //orderAddDTO1.InoutType = orderAddDTO.OrderType;
                //orderAddDTO1.OrderType = orderAddDTO.InoutType.ObjToInt();
                //orderAddDTO1.Details = orderAddDTO.DetailList.DicToIEnumerable<InboundOrderDetailAddDTO>();
                //#region 验证数据
                //(bool, string, object?) result = CheckInboundOrderAddData(orderAddDTO1);
                //if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
                //#endregion
 
                //Dt_InboundOrder inboundOrder = _mapper.Map<Dt_InboundOrder>(orderAddDTO1);
                //inboundOrder.OrderStatus = InboundStatusEnum.未开始.ObjToInt();
                //inboundOrder.Creater = "WMS";
                //inboundOrder.CreateDate = DateTime.Now;
                //bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
 
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            finally
            {
 
            }
            return content;
        }
        /// <summary>
        /// 盘点入库
        /// </summary>
        /// <returns></returns>
        public WebResponseContent InventoryIn(string name)
        {
            WebResponseContent content = new();
            try
            {
                //Dt_StockInfoDetail stockInfoDetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.OrderNo == name);
                ////Dt_OutboundOrderDetail outboundOrderDetail= 
                //HouseInventoryIn houseInventoryIn1 = new HouseInventoryIn();
                //houseInventoryIn1.No = name;
                //InventoryIn inventoryIn = new InventoryIn();
                //inventoryIn.LinId = stockInfoDetail.LinId;
                ////inventoryIn.LPN_No =stockInfoDetail.
                //inventoryIn.MaterielCode = stockInfoDetail.MaterielCode;
                //inventoryIn.OrderQuantity = stockInfoDetail.StockQuantity;
                //inventoryIn.BatchNo = stockInfoDetail.BatchNo;
                //inventoryIn.FinishQty = stockInfoDetail.FinishQty;
                //inventoryIn.WarehouseCode =
                //  inventoryIn.StorageAreaCode =
                //  inventoryIn.StorageLocationCode =
                //          #region 验证数据
                //(bool, string, object ?) result = CheckInboundOrderAddData(orderAddDTO1);
                //          if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
                //          #endregion
 
                //          Dt_OutboundOrder inboundOrder = _mapper.Map<Dt_OutboundOrder>(orderAddDTO1);
                //          inboundOrder.OrderStatus = InboundStatusEnum.未开始.ObjToInt();
                //          inboundOrder.OrderType = OutOrderTypeEnum.OutInventory.ObjToInt();
                //          inboundOrder.Creater = "WMS";
                //          inboundOrder.CreateDate = DateTime.Now;
                //          bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                content = WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            finally
            {
 
            }
            return content;
        }
        /// <summary>
        /// 入库单据取消
        /// </summary>
        /// <param name="houseInventoryIn"></param>
        /// <returns></returns>
        public WebResponseContent CancelIn(HouseCancelIn houseCancelIn)
        {
            WebResponseContent content = new();
            try
            {
                InboundOrderAddDTO orderAddDTO1 = new InboundOrderAddDTO();
                orderAddDTO1.OrderNo = houseCancelIn.AsnNo;
                orderAddDTO1.Details = houseCancelIn.DetailList.DicToIEnumerable<InboundOrderDetailAddDTO>();
                Dt_InboundOrder oldOutboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == orderAddDTO1.OrderNo).Includes(x => x.Details).First();
                Dt_InboundOrderDetail dt_InboundOrderDetail = BaseDal.Db.Queryable<Dt_InboundOrderDetail>().Where(x => x.OrderId == oldOutboundOrder.Id).First();
                if (oldOutboundOrder.OrderStatus != InboundStatusEnum.未开始.ObjToInt())
                {
                    return WebResponseContent.Instance.Error("该入库单任务已开始执行,不可取消");
                }
                oldOutboundOrder.OrderStatus = InboundStatusEnum.取消.ObjToInt();
                BaseDal.UpdateData(oldOutboundOrder);
 
                Dt_InboundOrder_Hty inboundOrder_Hty = new Dt_InboundOrder_Hty
                {
                    OrderStatus = oldOutboundOrder.OrderStatus,
                    CreateType = oldOutboundOrder.CreateType,
                    //SourceId = oldOutboundOrder.SourceId,
                    UpperOrderNo = oldOutboundOrder.UpperOrderNo,
                    //OrderNo = oldOutboundOrder.OrderNo,
                    //OutWareHouse = oldOutboundOrder.OutWareHouse,
                    TransactionCode = oldOutboundOrder.TransactionCode,
                    InoutType = oldOutboundOrder.InoutType,
                    OrderType = oldOutboundOrder.OrderType,
                    Creater = "WMS",
                    CreateDate = DateTime.Now,
                };
                _inboundOrderHtyService.AddData(inboundOrder_Hty);
                foreach (var item in oldOutboundOrder.Details)
                {
                    Dt_InboundOrderDetail_Hty dt_InboundOrderDetail_Hty = new Dt_InboundOrderDetail_Hty
                    {
                        OrderId = dt_InboundOrderDetail.OrderId,
                        MaterielCode = dt_InboundOrderDetail.MaterielCode,
                        MaterielName = dt_InboundOrderDetail.MaterielName,
                        BatchNo = dt_InboundOrderDetail.BatchNo,
                        OrderQuantity = dt_InboundOrderDetail.OrderQuantity,
                        ReceiptQuantity = dt_InboundOrderDetail.ReceiptQuantity,
                        OverInQuantity = dt_InboundOrderDetail.OverInQuantity,
                        OrderDetailStatus = dt_InboundOrderDetail.OrderDetailStatus,
                        Creater = "WMS",
                        CreateDate = DateTime.Now,
                    };
                    _inboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_Hty);
                    _inboundOrderDetailService.DeleteData(item);
                }
                BaseDal.DeleteData(oldOutboundOrder);
                content = WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            finally
            {
 
            }
            return content;
        }
 
        public WebResponseContent GetInboundOrders(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                int pageNo = saveModel.MainData["pageNo"].ObjToInt();
                string? orderNo = saveModel.MainData["orderNo"].ToString();
                int warehouseId = saveModel.MainData["warehouseId"].ObjToInt();
                List<Dt_InboundOrder> dt_ReceiveOrders = new List<Dt_InboundOrder>();
                if (string.IsNullOrEmpty(orderNo))
                {
                    dt_ReceiveOrders = Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderStatus < InboundStatusEnum.入库完成.ObjToInt() && x.WarehouseId == warehouseId).Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 10);
                }
                else
                {
                    dt_ReceiveOrders = Db.Queryable<Dt_InboundOrder>().Where(x => (x.OrderNo.Contains(orderNo)) && x.OrderStatus < InboundStatusEnum.入库完成.ObjToInt() && x.WarehouseId == warehouseId).Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 10);
                }
 
                content.OK(data: dt_ReceiveOrders);
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
 
        /// <summary>
        /// 验证单据添加DTO对象
        /// </summary>
        /// <param name="inboundOrderAddDTO">单据添加DTO</param>
        /// <returns></returns>
        //private (bool, string, object?) CheckInboundOrderAddData(InboundOrderAddDTO inboundOrderAddDTO)
        //{
        //    (bool, string, object?) result1 = ModelValidate.ValidateModelData(inboundOrderAddDTO);
        //    if (!result1.Item1) return result1;
 
        //    (bool, string, object?) result2 = ModelValidate.ValidateModelData(inboundOrderAddDTO.Details);
        //    if (!result2.Item1) return result2;
 
        //    IEnumerable<int> inOrderTypes = Enum.GetValues<OrderTypeEmun>().Cast<int>();
        //    if (!inOrderTypes.Contains(inboundOrderAddDTO.OrderType))
        //    {
        //        return (false, "未找到该单据类型", inboundOrderAddDTO);
        //    }
 
        //    List<string> materielCodes = inboundOrderAddDTO.Details.Select(x => x.MaterielCode).ToList();
        //    if (!_basicService.MaterielInfoService.ExsitMateriels(materielCodes))
        //    {
        //        return (false, "有物料信息未录入,请录入物料信息", inboundOrderAddDTO);
        //    }
        //    Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == inboundOrderAddDTO.OutWareHouse);
        //    if (warehouse == null)
        //    {
        //        return (false, "未找到仓库信息", inboundOrderAddDTO);
        //    }
        //    if (BaseDal.QueryFirst(x => x.OrderName == inboundOrderAddDTO.orderName && !string.IsNullOrEmpty(x.OrderName)) != null)
        //    {
        //        return (false, "单据已存在", inboundOrderAddDTO);
        //    }
        //    return (true, "成功", inboundOrderAddDTO);
        //}
 
 
    }
}