bug
liuying
2024-04-25 ae4e29f352975c2197521cf3c0b7179868d8cb84
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
using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Admin.NET.Core;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Linq.Dynamic.Core;
using Microsoft.AspNetCore.Http;
using System.Text;
using System.Web;
using System.ComponentModel;
using System.Data;
namespace Admin.NET.Application
{
    /// <summary>
    /// 容器信息服务
    /// </summary>
    [ApiDescriptionSettings("WmsBase", Name = "WmsContainer", Order = 100)]
    [Route("api")]
    public class WmsContainerService : IWmsContainerService, IDynamicApiController, ITransient
    {
        private readonly IRepository<WmsContainer,MasterDbContextLocator> _wmsContainerRep;
        private readonly IRepository<SysDictType, MasterDbContextLocator> _sysDictTypeRep;
        private readonly IRepository<SysDictData, MasterDbContextLocator> _sysDictDataRep;
        private readonly ISysExcelTemplateService _sysExcelTemplateService;
        private readonly IRepository<WmsContainerType, MasterDbContextLocator> _wmsContainerTypeRep;
        private readonly static object _lock = new();
 
        public WmsContainerService(
            IRepository<WmsContainer,MasterDbContextLocator> wmsContainerRep
            ,IRepository<SysDictType, MasterDbContextLocator> sysDictTypeRep
            ,IRepository<SysDictData, MasterDbContextLocator> sysDictDataRep
            ,ISysExcelTemplateService sysExcelTemplateService
            , IRepository<WmsContainerType, MasterDbContextLocator> wmsContainerTypeRep
 
        )
        {
            _wmsContainerRep = wmsContainerRep;
         _sysDictTypeRep = sysDictTypeRep;
         _sysDictDataRep = sysDictDataRep;
         _sysExcelTemplateService = sysExcelTemplateService;
            _wmsContainerTypeRep = wmsContainerTypeRep;
        }
 
        /// <summary>
        /// 分页查询容器信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("WmsContainer/page")]
        public async Task<PageResult<WmsContainerOutput>> Page([FromQuery] WmsContainerSearch input)
        {
            var wmsContainers = await _wmsContainerRep.DetachedEntities
                                     .Where(!string.IsNullOrEmpty(input.ContainerCode), u => u.ContainerCode == input.ContainerCode)
                                     .Where(!string.IsNullOrEmpty(input.ContainerName), u => u.ContainerName == input.ContainerName)
                                     .Where(input.ContainerTypeId != null, u => u.ContainerTypeId == input.ContainerTypeId)
                                     .Where(!string.IsNullOrEmpty(input.ContainerTypeName), u => u.ContainerTypeName == input.ContainerTypeName)
                                     .Where(input.PackagingId != null, u => u.PackagingId == input.PackagingId)
                                     .Where(input.SpecLength != null, u => u.SpecLength == input.SpecLength)
                                     .Where(input.SpecWidth != null, u => u.SpecWidth == input.SpecWidth)
                                     .Where(input.SpecHeight != null, u => u.SpecHeight == input.SpecHeight)
                                     .Where(input.LimitLength != null, u => u.LimitLength == input.LimitLength)
                                     .Where(input.LimitWidth != null, u => u.LimitWidth == input.LimitWidth)
                                     .Where(input.LimitHeight != null, u => u.LimitHeight == input.LimitHeight)
                                     .Where(input.MaxWeight != null, u => u.MaxWeight == input.MaxWeight)
                                     .Where(!string.IsNullOrEmpty(input.ParentContainerName), u => u.ParentContainerName == input.ParentContainerName)
                                     .Where(input.ParentContainerId != null, u => u.ParentContainerId == input.ParentContainerId)
                                     .Where(input.IsVirtually != null, u => u.IsVirtually == input.IsVirtually)
                                     .Where(input.IsDisabled != null, u => u.IsDisabled == input.IsDisabled)
                                     .Where(input.CreatedTime!=null, u => u.CreatedTime>=  Convert.ToDateTime(input.CreatedTime[0]) && u.CreatedTime<= Convert.ToDateTime(input.CreatedTime[1]))
                                     .Where(input.UpdatedTime!=null, u => u.UpdatedTime>=  Convert.ToDateTime(input.UpdatedTime[0]) && u.UpdatedTime<= Convert.ToDateTime(input.UpdatedTime[1]))
                                     .Where(!string.IsNullOrEmpty(input.CreatedUserName), u => u.CreatedUserName == input.CreatedUserName)
                                     .Where(!string.IsNullOrEmpty(input.UpdatedUserName), u => u.UpdatedUserName == input.UpdatedUserName)
                                     .OrderBy(PageInputOrder.OrderBuilder<WmsContainerSearch>(input))
                                     .ProjectToType<WmsContainerOutput>()
                                     .ToADPagedListAsync(input.PageNo, input.PageSize);
            return wmsContainers;
        }
 
        /// <summary>
        /// 不分页查询容器信息列表
        /// </summary>
        /// <param name="input">容器信息查询参数</param>
        /// <returns>(容器信息)实例列表</returns>
        [HttpGet("WmsContainer/listNonPage")]
        public async Task<List<WmsContainerOutput>> ListNonPageAsync([FromQuery] WmsContainerSearchNonPage input)
        {
            var pContainerCode = input.ContainerCode?.Trim() ?? "";
            var pContainerName = input.ContainerName?.Trim() ?? "";
            var pContainerTypeId = input.ContainerTypeId;
            var pContainerTypeName = input.ContainerTypeName?.Trim() ?? "";
            var pPackagingId = input.PackagingId;
            var pSpecLength = input.SpecLength;
            var pSpecWidth = input.SpecWidth;
            var pSpecHeight = input.SpecHeight;
            var pLimitLength = input.LimitLength;
            var pLimitWidth = input.LimitWidth;
            var pLimitHeight = input.LimitHeight;
            var pMaxWeight = input.MaxWeight;
            var pParentContainerName = input.ParentContainerName?.Trim() ?? "";
            var pParentContainerId = input.ParentContainerId;
            var pIsVirtually = input.IsVirtually;
            var pIsDisabled = input.IsDisabled;
            var pCreatedTime = input.CreatedTime;
            var pUpdatedTime = input.UpdatedTime;
            var pCreatedUserName = input.CreatedUserName?.Trim() ?? "";
            var pUpdatedUserName = input.UpdatedUserName?.Trim() ?? "";
            var wmsContainers = await _wmsContainerRep.DetachedEntities
                .Where(!string.IsNullOrEmpty(pContainerCode), u => u.ContainerCode == pContainerCode)
                .Where(!string.IsNullOrEmpty(pContainerName), u => u.ContainerName == pContainerName)
                .Where(pContainerTypeId != null, u => u.ContainerTypeId == pContainerTypeId)
                .Where(!string.IsNullOrEmpty(pContainerTypeName), u => u.ContainerTypeName == pContainerTypeName)
                .Where(pPackagingId != null, u => u.PackagingId == pPackagingId)
                .Where(pSpecLength != null, u => u.SpecLength == pSpecLength)
                .Where(pSpecWidth != null, u => u.SpecWidth == pSpecWidth)
                .Where(pSpecHeight != null, u => u.SpecHeight == pSpecHeight)
                .Where(pLimitLength != null, u => u.LimitLength == pLimitLength)
                .Where(pLimitWidth != null, u => u.LimitWidth == pLimitWidth)
                .Where(pLimitHeight != null, u => u.LimitHeight == pLimitHeight)
                .Where(pMaxWeight != null, u => u.MaxWeight == pMaxWeight)
                .Where(!string.IsNullOrEmpty(pParentContainerName), u => u.ParentContainerName == pParentContainerName)
                .Where(pParentContainerId != null, u => u.ParentContainerId == pParentContainerId)
                .Where(pIsVirtually != null, u => u.IsVirtually == pIsVirtually)
                .Where(pIsDisabled != null, u => u.IsDisabled == pIsDisabled)
           .Where(input.CreatedTime!=null, u => u.CreatedTime>=  Convert.ToDateTime(input.CreatedTime[0]) && u.CreatedTime<= Convert.ToDateTime(input.CreatedTime[1]))
           .Where(input.UpdatedTime!=null, u => u.UpdatedTime>=  Convert.ToDateTime(input.UpdatedTime[0]) && u.UpdatedTime<= Convert.ToDateTime(input.UpdatedTime[1]))
                .Where(!string.IsNullOrEmpty(pCreatedUserName), u => u.CreatedUserName == pCreatedUserName)
                .Where(!string.IsNullOrEmpty(pUpdatedUserName), u => u.UpdatedUserName == pUpdatedUserName)
            .OrderBy(PageInputOrder.OrderNonPageBuilder(input))
            .ProjectToType<WmsContainerOutput>()
            .ToListAsync();
            return wmsContainers;
        }
 
         /// <summary>
        /// 获取容器信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("WmsContainer/detail")]
        public async Task<WmsContainerOutput> Get([FromQuery] QueryeWmsContainerInput input)
        {
            return (await _wmsContainerRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id)).Adapt<WmsContainerOutput>();
        }
 
        /// <summary>
        /// 获取容器信息列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("WmsContainer/list")]
        public async Task<List<WmsContainerOutput>> List([FromQuery] WmsContainerInput input)
        {
            return await _wmsContainerRep.DetachedEntities.ProjectToType<WmsContainerOutput>().ToListAsync();
        }    
 
        #region 增、删、改
 
        /// <summary>
        /// 增加容器信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("WmsContainer/add")]
        public async Task Add(AddWmsContainerInput input)
        {
            var wmsContainer = input.Adapt<WmsContainer>();
 
                        //验证
            await CheckExisit(wmsContainer);
 
            //容器类型id
            var ContainerTypeInfo = _wmsContainerTypeRep.Where(x => x.Id == input.ContainerTypeId).FirstOrDefault();
            if (ContainerTypeInfo == null)
            {
                throw Oops.Oh(errorMessage: @$"类型不存在!");
            }
            wmsContainer.ContainerTypeName = ContainerTypeInfo.TypeName;
 
            wmsContainer.CreatedUserId = wmsContainer.UpdatedUserId = SysHelper.GetUserId();
            wmsContainer.CreatedUserName = wmsContainer.UpdatedUserName = SysHelper.GetUserName();
            wmsContainer.CreatedTime = wmsContainer.UpdatedTime = SysHelper.GetNowTime();
            await _wmsContainerRep.InsertAsync(wmsContainer);
        }
 
        /// <summary>
        /// 删除容器信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("WmsContainer/delete")]
        public async Task Delete(DeleteWmsContainerInput input)
        {
            var wmsContainer = await _wmsContainerRep.FirstOrDefaultAsync(u => u.Id == input.Id);
            await _wmsContainerRep.DeleteAsync(wmsContainer);
            
        }
 
        /// <summary>
        /// 更新容器信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("WmsContainer/edit")]
        public async Task Update(UpdateWmsContainerInput input)
        {
            var isExist = await _wmsContainerRep.AnyAsync(u => u.Id == input.Id, false);
            if (!isExist) throw Oops.Oh(ErrorCode.D1002);
 
            var wmsContainer = input.Adapt<WmsContainer>();
            //验证
            await CheckExisit(wmsContainer,true);
 
            wmsContainer.UpdatedUserId = SysHelper.GetUserId();
            wmsContainer.UpdatedUserName = SysHelper.GetUserName();
            wmsContainer.UpdatedTime = SysHelper.GetNowTime();
            await _wmsContainerRep.UpdateAsync(wmsContainer,ignoreNullValues:true);
        }
 
        #endregion
 
        #region 导入
 
        /// <summary>
        /// Excel模板导入容器信息功能
        /// </summary>
        /// <param name="file">Excel模板文件</param>
        /// <returns>导入的记录数</returns>
        [HttpPost("WmsContainer/importExcel")]
        public async Task<int> ImportExcelAsync(IFormFile file)
        { 
            int _HeadStartLine = 2;//第1行是说明,第2行是列名
            int _DataStartLine = 3;//第3行开始是数据
 
            DataTable importDataTable = ExcelUtil.ImportExcelToDataTable(file, _HeadStartLine, _DataStartLine);
            var addList =await CommonImport(importDataTable, _DataStartLine);
 
            lock (_lock)
            {
                _wmsContainerRep.InsertAsync(addList);
               
            }
            await Task.CompletedTask;
            return addList.Count;
        }
 
        /// <summary>
        ///  DataTable转换实体对象列表
        /// </summary>
        /// <param name="dataTable"></param>
        /// <param name="dataStartLine">模版列名开始行</param>
        /// <returns></returns>
        private async Task<List<WmsContainer>> CommonImport(DataTable dataTable, int dataStartLine)
        {
 
            var details = new List<WmsContainer>();
            int index = dataStartLine;//模版列名开始行
            foreach (System.Data.DataRow row in dataTable.Rows)
            {
                index++;
 
               //导入模版定制化代码(替换模版使用)
                                          
                           var addItem = new WmsContainer()
                            {
                               CreatedTime = SysHelper.GetNowTime(),
                               CreatedUserId = SysHelper.GetUserId(),
                               CreatedUserName = SysHelper.GetUserName(),
                               UpdatedTime = SysHelper.GetNowTime(),
                               UpdatedUserId = SysHelper.GetUserId(),
                               UpdatedUserName = SysHelper.GetUserName()
                             };
                          #region 定义变量
                           var _ContainerCode = "";//编号
                           var _ContainerName = "";//名称
                           var _ContainerTypeId = "";//类型ID
                           var _ContainerTypeName = "";//类型名称
                           var _PackagingId = "";//容器关系ID
                           var _SpecLength = "";//长度
                           var _SpecWidth = "";//宽度
                           var _SpecHeight = "";//高度
                           var _LimitLength = "";//限长
                           var _LimitWidth = "";//限宽
                           var _LimitHeight = "";//限高
                           var _MaxWeight = "";//载重上限
                           var _ParentContainerName = "";//父容器名称
                           var _ParentContainerId = "";//父容器Id
                           var _IsVirtually = "";//是否虚拟
                           var _IsDisabled = "";//是否禁用
                           var _Id = "";//Id主键
                          #endregion
                          
                          
                          #region 取值
                           _ContainerCode = row["编号"]?.ToString() ;
                           _ContainerName = row["名称"]?.ToString() ;
                           _ContainerTypeId = row["类型ID"]?.ToString() ;
                           _ContainerTypeName = row["类型名称"]?.ToString() ;
                           _PackagingId = row["容器关系ID"]?.ToString() ;
                           _SpecLength = row["长度"]?.ToString() ;
                           _SpecWidth = row["宽度"]?.ToString() ;
                           _SpecHeight = row["高度"]?.ToString() ;
                           _LimitLength = row["限长"]?.ToString() ;
                           _LimitWidth = row["限宽"]?.ToString() ;
                           _LimitHeight = row["限高"]?.ToString() ;
                           _MaxWeight = row["载重上限"]?.ToString() ;
                           _ParentContainerName = row["父容器名称"]?.ToString() ;
                           _ParentContainerId = row["父容器Id"]?.ToString() ;
                           _IsVirtually = row["是否虚拟"]?.ToString() ;
                           _IsDisabled = row["是否禁用"]?.ToString() ;
                           _Id = row["Id主键"]?.ToString() ;
                          #endregion
                          
                          
                          #region 验证
                          
                          if (string.IsNullOrEmpty(_ContainerCode))
                          {
                            throw Oops.Oh($"第{index}行[编号]{_ContainerCode}不能为空!");
                          }
                          
                          if(!string.IsNullOrEmpty(_ContainerCode))
                          {
                                addItem.ContainerCode = (string)_ContainerCode;
                           }
                          
                          if (string.IsNullOrEmpty(_ContainerName))
                          {
                            throw Oops.Oh($"第{index}行[名称]{_ContainerName}不能为空!");
                          }
                          
                          if(!string.IsNullOrEmpty(_ContainerName))
                          {
                                addItem.ContainerName = (string)_ContainerName;
                           }
                          
                          if (string.IsNullOrEmpty(_ContainerTypeId))
                          {
                            throw Oops.Oh($"第{index}行[类型ID]{_ContainerTypeId}不能为空!");
                          }
                          
                          if(!string.IsNullOrEmpty(_ContainerTypeId))
                          {
                              if (!long.TryParse(_ContainerTypeId, out long outContainerTypeId)&&!string.IsNullOrEmpty(_ContainerTypeId))
                              {
                                 throw Oops.Oh($"第{index}行[类型ID]{_ContainerTypeId}值不正确!");
                              }
                              if (outContainerTypeId <= 0&&!string.IsNullOrEmpty(_ContainerTypeId))
                              {
                                 throw Oops.Oh($"第{index}行[类型ID]{_ContainerTypeId}值不能小于等于0!");
                              }
                              else
                              {
                                 addItem.ContainerTypeId = outContainerTypeId;
                              }
                          
                          }
                          
                          if (string.IsNullOrEmpty(_ContainerTypeName))
                          {
                            throw Oops.Oh($"第{index}行[类型名称]{_ContainerTypeName}不能为空!");
                          }
                          
                          if(!string.IsNullOrEmpty(_ContainerTypeName))
                          {
                                addItem.ContainerTypeName = (string)_ContainerTypeName;
                           }
                          
                          if (string.IsNullOrEmpty(_PackagingId))
                          {
                            throw Oops.Oh($"第{index}行[容器关系ID]{_PackagingId}不能为空!");
                          }
                          
                          if(!string.IsNullOrEmpty(_PackagingId))
                          {
                              if (!long.TryParse(_PackagingId, out long outPackagingId)&&!string.IsNullOrEmpty(_PackagingId))
                              {
                                 throw Oops.Oh($"第{index}行[容器关系ID]{_PackagingId}值不正确!");
                              }
                              if (outPackagingId <= 0&&!string.IsNullOrEmpty(_PackagingId))
                              {
                                 throw Oops.Oh($"第{index}行[容器关系ID]{_PackagingId}值不能小于等于0!");
                              }
                              else
                              {
                                 addItem.PackagingId = outPackagingId;
                              }
                          
                          }
                          if(!string.IsNullOrEmpty(_SpecLength))
                          {
                              if (!decimal.TryParse(_SpecLength, out decimal outSpecLength)&&!string.IsNullOrEmpty(_SpecLength))
                              {
                                 throw Oops.Oh($"第{index}行[长度]{_SpecLength}值不正确!");
                              }
                              if (outSpecLength <= 0&&!string.IsNullOrEmpty(_SpecLength))
                              {
                                 throw Oops.Oh($"第{index}行[长度]{_SpecLength}值不能小于等于0!");
                              }
                              else
                              {
                                 addItem.SpecLength = outSpecLength;
                              }
                          
                          }
                          if(!string.IsNullOrEmpty(_SpecWidth))
                          {
                              if (!decimal.TryParse(_SpecWidth, out decimal outSpecWidth)&&!string.IsNullOrEmpty(_SpecWidth))
                              {
                                 throw Oops.Oh($"第{index}行[宽度]{_SpecWidth}值不正确!");
                              }
                              if (outSpecWidth <= 0&&!string.IsNullOrEmpty(_SpecWidth))
                              {
                                 throw Oops.Oh($"第{index}行[宽度]{_SpecWidth}值不能小于等于0!");
                              }
                              else
                              {
                                 addItem.SpecWidth = outSpecWidth;
                              }
                          
                          }
                          if(!string.IsNullOrEmpty(_SpecHeight))
                          {
                              if (!decimal.TryParse(_SpecHeight, out decimal outSpecHeight)&&!string.IsNullOrEmpty(_SpecHeight))
                              {
                                 throw Oops.Oh($"第{index}行[高度]{_SpecHeight}值不正确!");
                              }
                              if (outSpecHeight <= 0&&!string.IsNullOrEmpty(_SpecHeight))
                              {
                                 throw Oops.Oh($"第{index}行[高度]{_SpecHeight}值不能小于等于0!");
                              }
                              else
                              {
                                 addItem.SpecHeight = outSpecHeight;
                              }
                          
                          }
                          if(!string.IsNullOrEmpty(_LimitLength))
                          {
                              if (!decimal.TryParse(_LimitLength, out decimal outLimitLength)&&!string.IsNullOrEmpty(_LimitLength))
                              {
                                 throw Oops.Oh($"第{index}行[限长]{_LimitLength}值不正确!");
                              }
                              if (outLimitLength <= 0&&!string.IsNullOrEmpty(_LimitLength))
                              {
                                 throw Oops.Oh($"第{index}行[限长]{_LimitLength}值不能小于等于0!");
                              }
                              else
                              {
                                 addItem.LimitLength = outLimitLength;
                              }
                          
                          }
                          if(!string.IsNullOrEmpty(_LimitWidth))
                          {
                              if (!decimal.TryParse(_LimitWidth, out decimal outLimitWidth)&&!string.IsNullOrEmpty(_LimitWidth))
                              {
                                 throw Oops.Oh($"第{index}行[限宽]{_LimitWidth}值不正确!");
                              }
                              if (outLimitWidth <= 0&&!string.IsNullOrEmpty(_LimitWidth))
                              {
                                 throw Oops.Oh($"第{index}行[限宽]{_LimitWidth}值不能小于等于0!");
                              }
                              else
                              {
                                 addItem.LimitWidth = outLimitWidth;
                              }
                          
                          }
                          if(!string.IsNullOrEmpty(_LimitHeight))
                          {
                              if (!decimal.TryParse(_LimitHeight, out decimal outLimitHeight)&&!string.IsNullOrEmpty(_LimitHeight))
                              {
                                 throw Oops.Oh($"第{index}行[限高]{_LimitHeight}值不正确!");
                              }
                              if (outLimitHeight <= 0&&!string.IsNullOrEmpty(_LimitHeight))
                              {
                                 throw Oops.Oh($"第{index}行[限高]{_LimitHeight}值不能小于等于0!");
                              }
                              else
                              {
                                 addItem.LimitHeight = outLimitHeight;
                              }
                          
                          }
                          if(!string.IsNullOrEmpty(_MaxWeight))
                          {
                              if (!decimal.TryParse(_MaxWeight, out decimal outMaxWeight)&&!string.IsNullOrEmpty(_MaxWeight))
                              {
                                 throw Oops.Oh($"第{index}行[载重上限]{_MaxWeight}值不正确!");
                              }
                              if (outMaxWeight <= 0&&!string.IsNullOrEmpty(_MaxWeight))
                              {
                                 throw Oops.Oh($"第{index}行[载重上限]{_MaxWeight}值不能小于等于0!");
                              }
                              else
                              {
                                 addItem.MaxWeight = outMaxWeight;
                              }
                          
                          }
                          if(!string.IsNullOrEmpty(_ParentContainerName))
                          {
                                addItem.ParentContainerName = (string)_ParentContainerName;
                           }
                          if(!string.IsNullOrEmpty(_ParentContainerId))
                          {
                              if (!long.TryParse(_ParentContainerId, out long outParentContainerId)&&!string.IsNullOrEmpty(_ParentContainerId))
                              {
                                 throw Oops.Oh($"第{index}行[父容器Id]{_ParentContainerId}值不正确!");
                              }
                              if (outParentContainerId <= 0&&!string.IsNullOrEmpty(_ParentContainerId))
                              {
                                 throw Oops.Oh($"第{index}行[父容器Id]{_ParentContainerId}值不能小于等于0!");
                              }
                              else
                              {
                                 addItem.ParentContainerId = outParentContainerId;
                              }
                          
                          }
                          if(!string.IsNullOrEmpty(_IsVirtually))
                          {
                              if (!int.TryParse(_IsVirtually, out int outIsVirtually)&&!string.IsNullOrEmpty(_IsVirtually))
                              {
                                 throw Oops.Oh($"第{index}行[是否虚拟]{_IsVirtually}值不正确!");
                              }
                              if (outIsVirtually <= 0&&!string.IsNullOrEmpty(_IsVirtually))
                              {
                                 throw Oops.Oh($"第{index}行[是否虚拟]{_IsVirtually}值不能小于等于0!");
                              }
                              else
                              {
                                 addItem.IsVirtually = outIsVirtually;
                              }
                          
                          }
                          if(!string.IsNullOrEmpty(_IsDisabled))
                          {
                            if(!_IsDisabled.Equals("是") && !_IsDisabled.Equals("否"))
                             {
                               throw Oops.Oh($"第{index}行[是否禁用]{_IsDisabled}值不正确!");
                             }
                             else
                             {
                               bool outIsDisabled = _IsDisabled.Equals("是") ? true : false;
                               addItem.IsDisabled = outIsDisabled;
                             }
                             }
                          
                          if(!string.IsNullOrEmpty(_Id))
                          {
                              if (!long.TryParse(_Id, out long outId)&&!string.IsNullOrEmpty(_Id))
                              {
                                 throw Oops.Oh($"第{index}行[Id主键]{_Id}值不正确!");
                              }
                              if (outId <= 0&&!string.IsNullOrEmpty(_Id))
                              {
                                 throw Oops.Oh($"第{index}行[Id主键]{_Id}值不能小于等于0!");
                              }
                              else
                              {
                                 addItem.Id = outId;
                              }
                          
                          }
                          #endregion
                          
 
              
                details.Add(addItem);
            }
              //验重
              await CheckExisitForImport(details);
            
            return details;
        }
 
        /// <summary>
        /// 根据版本下载容器信息的Excel导入模板
        /// </summary>
        /// <param name="version">模板版本</param>
        /// <returns>下载的模板文件</returns>
        [HttpGet("WmsContainer/downloadExcelTemplate")]
        public IActionResult DownloadExcelTemplate([FromQuery] string version)
        {
            string _path = TemplateConst.EXCEL_TEMPLATEFILE_导入模版路径 + $"\\WmsContainer{TemplateConst.EXCEL_TEMPLATEFILE_导入模版名称后缀}.xlsx";
            var fileName = HttpUtility.UrlEncode($"导入模板(容器信息).xlsx", Encoding.GetEncoding("UTF-8"));
            return new FileStreamResult(new FileStream(_path, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName };
        }
 
        #endregion
 
        #region 私有方法
 
        /// <summary>
        /// 根据联合主键验证数据是否已存在-数据库
        /// </summary>
        /// <param name="input"></param>
        /// <param name="isEdit"></param>
        /// <returns></returns>
        private async Task CheckExisit( WmsContainer input,bool isEdit=false)
        {
           
 
           
           bool isExist = false;
           if (!isEdit)//新增
           {
                   //数据是否存在重复
                   isExist = await _wmsContainerRep.AnyAsync(u =>
                                   u.ContainerCode.Equals(input.ContainerCode)
                   ,false);
          }
           else//编辑 
          {
 
          
                
                 //当前编辑数据以外是否存在重复
                  isExist = await _wmsContainerRep.AnyAsync(u => 
                                    u.Id != input.Id
                                    &&u.ContainerCode.Equals(input.ContainerCode)
                    ,false);
               }
               
        
 
            if (isExist) throw Oops.Oh(ErrorCode.E0001);
       }
        
        /// <summary>
        /// 根据联合主键验证数据是否已存在-导入时验证
        /// </summary>
        /// <param name="inputs"></param>
        /// <returns></returns>
        private async Task CheckExisitForImport(List<WmsContainer> inputs)
        { 
            //根据联合主键验证表格中中是否已存在相同数据  
                 if (inputs?.Count <= 0)
                 {
                     throw Oops.Oh($"导入数据不能为空");
                 }
                 //数据是否重复
                 var existExcelItem = inputs.GroupBy(g => new {
                                               g.ContainerCode
                                               })
                                               .Where(g => g.Count() > 1)
                                               .Select(s => new {
                                               s.Key.ContainerCode
                                               }).FirstOrDefault();
                 if (existExcelItem != null)
                 {
                   var wmsContainer = existExcelItem.Adapt<WmsContainer>();
                   var item= existExcelItem.Adapt<WmsContainer>();
                   throw Oops.Oh($"导入的表格中,编号[{item.ContainerCode}]已存在");
                 }
                      
 
 
 
    //根据联合主键验证数据库中是否已存在相同数据
                 var existDBItem = await _wmsContainerRep.DetachedEntities.FirstOrDefaultAsync(w=> 
                                                                         inputs.Select(s=>""
                                                                           +s.ContainerCode
                                                                        )
                                                                        .Contains(""
                                                                         +w.ContainerCode
                  ));
                  if (existDBItem != null)
                 {
                   var wmsContainer = existExcelItem.Adapt<WmsContainer>();
                   var item= existExcelItem.Adapt<WmsContainer>();
                   throw Oops.Oh($"系统中,编号[{item.ContainerCode}]已存在");
                 }
        }
 
        #endregion
    }
}