bklLiudl
2025-04-07 4e8f58cb41c7b6d570fd1979d80f74ab8a4d00c2
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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.Intrinsics.X86;
using System.Text;
using System.Threading.Tasks;
using Model.ModelDto.SysDto;
using Model.ModelVm.SysVm;
using SqlSugar;
using WMS.BLL.LogServer;
using WMS.DAL;
using WMS.Entity.BllAsnEntity;
using WMS.Entity.Context;
using WMS.Entity.DataEntity;
using WMS.Entity.SysEntity;
using WMS.IBLL.ILogServer;
using WMS.IBLL.ISysServer;
using WMS.IDAL.ISysInterface;
 
namespace WMS.BLL.SysServer
{
    public class StorageLocatServer : DbHelper<SysStorageLocat>, IStorageLocatServer
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
        public IStorageLocatRepository LocatRst { get; set; }
        public StorageLocatServer(IStorageLocatRepository locatRst) : base(Db)
        {
            LocatRst = locatRst;
        }
 
        /// <summary>
        /// 查询储位信息
        /// </summary>
        /// <param name="houseNo">仓库号</param>
        /// <param name="roadwayNo">巷道号</param>
        /// <param name="areaNo">区域号</param>
        /// <param name="status">状态</param>
        /// <param name="flag">标志0:正常 1:屏蔽 2:损坏 屏蔽:储位不可存放货物,不影响内侧储位使用  损坏:内侧储位也不允许使用 </param>
        /// <param name="locat">储位号</param>
        /// <param name="row">排</param>
        /// <param name="col">列</param>
        /// <param name="layer">层</param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public List<LocatDto> GetStorageLocatList(string houseNo, string roadwayNo, string areaNo, string status, string flag, string locat, int? row, int? col, int? layer, int page, int limit, out int count)
        {
            try
            {
                Expression<Func<SysStorageLocat, bool>> item = Expressionable.Create<SysStorageLocat>() //创建表达式
                    .AndIF(!string.IsNullOrWhiteSpace(houseNo), it => it.WareHouseNo == houseNo)
                    .AndIF(!string.IsNullOrWhiteSpace(roadwayNo), it => it.RoadwayNo == roadwayNo)
                    .AndIF(!string.IsNullOrWhiteSpace(areaNo), it => it.AreaNo == areaNo)
                    .AndIF(!string.IsNullOrWhiteSpace(status), it => it.Status == status)
                    .AndIF(!string.IsNullOrWhiteSpace(flag), it => it.Flag == flag)
                    .AndIF(!string.IsNullOrWhiteSpace(locat), it => it.LocatNo.Contains(locat.Trim()))
                    .AndIF(row != null, it => it.Row == row)
                    .AndIF(col != null, it => it.Column == col)
                    .AndIF(layer != null, it => it.Layer == layer)
                    .ToExpression();//注意 这一句 不能少
 
 
                var data = LocatRst.GetAllByOrderPageAsync(item, limit, page, out int counts)
                    .Includes(x => x.WareHouseInfo)
                    .Includes(x => x.AreaInfo)
                    .Includes(x => x.RoadwayInfo)
                    .Includes(x => x.TemperatureInfo)
                    .Includes(x => x.CreateUserInfo)
                    .Includes(x => x.UpdateUserInfo).ToList();
                count = counts;
                return data.Select(m => new LocatDto()
                {
                    Id = m.Id,
                    LocatNo = m.LocatNo,
                    WareHouseNo = m.WareHouseNo,
                    WareHouseName = m.WareHouseInfo == null ? "" : m.WareHouseInfo.WareHouseName,
                    RoadwayNo = m.RoadwayNo,
                    RoadwayName = m.RoadwayInfo == null ? "" : m.RoadwayInfo.RoadwayName,
                    AreaNo = m.AreaNo,
                    AreaName = m.AreaInfo == null ? "" : m.AreaInfo.AreaName,
                    Status = m.Status,
                    StatusName = GetStatus(m.Status),
                    Flag = m.Flag,
                    FlagName = GetFlag(m.Flag),
                    Depth = m.Depth,
                    Row = m.Row,
                    Column = m.Column,
                    Layer = m.Layer,
                    Height = m.Height,
                    Weight = m.Weight,
                    TempName = m.TemperatureInfo == null ? "" : m.TemperatureInfo.DictName,
                    CreateTime = m.CreateTime,
                    CreateUserName = m.CreateUserInfo == null ? "" : m.CreateUserInfo.UserName,
                    UpdateTime = m.UpdateTime,
                    UpdateUserName = m.UpdateUserInfo == null ? "" : m.UpdateUserInfo.UserName
                }).ToList();
 
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 查询单条储位信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SysStorageLocat GetStorageLocat(int id)
        {
            try
            {
                var data = LocatRst.GetOneById(id);
                //var data = Db.Queryable<SysStorageLocat>().First(m=>m.Id == id);
                return data;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public List<SysStorageLocat> GetStorageLocat(List<int> id)
        {
            try
            {
                var SysStorageLocats = new List<SysStorageLocat>();
                foreach (var item in id)
                {
                    var storage = LocatRst.GetOneById(item);
                    SysStorageLocats.Add(storage);
                }
                return SysStorageLocats;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
 
        public bool EditStorageLocat(EditLocateVm model, int userId)
        {
            try
            {
                var bl = LocatRst.EditStorageLocat(model.Id, model.Status, model.Flag, model.Temperature,model.Area, userId);
 
                return bl;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 添加储位信息(立体库)用于开发人员添加基础信息
        /// </summary>
        /// <param name="houseNo">仓库号</param>
        /// <param name="roadwayNo">巷道号</param>
        /// <param name="areaNo">区域号</param>
        /// <param name="row">排</param>
        /// <param name="col">列</param>
        /// <param name="layer">层</param>
        /// <param name="dept">深度</param>
        /// <param name="userId">操作人</param>
        /// <returns></returns>
        public async Task<int> AddStorageLocat(string houseNo, string roadwayNo, string areaNo, int row, int col, int layer, string dept, int userId)
        {
            try
            {
                var q = 0;
                //R01 -01 -01 -02
                //巷道–排-列-层 
                for (int r = 5; r <= row; r++)//排
                {
                    var r1 = "1";
                    if (r < 10)
                    {
                        r1 = "0" + r;
                    }
                    else
                    {
                        r1 = r.ToString();
                    }
                    for (int l = 1; l <= layer; l++)//层
                    {
                        var l1 = "1";
                        if (l < 10)
                        {
                            l1 = "0" + l;
                        }
                        else
                        {
                            l1 = l.ToString();
                        }
                        for (int c = 1; c <= col; c++)//列
                        {
                            var c1 = "1";
                            if (c < 10)
                            {
                                c1 = "0" + c;
                            }
                            else
                            {
                                c1 = c.ToString();
                            }
                            var area = l <= 7 ? "A12" : "A11";//区域
                            for (int d = 1; d <= int.Parse(dept); d++) //深度
                            {
                                var s = "0" + d;//深度
                                q += await LocatRst.AddAsync(new SysStorageLocat()
                                {
                                    LocatNo = r1 + c1 + l1 + s,
                                    WareHouseNo = houseNo,
                                    RoadwayNo = roadwayNo,
                                    AreaNo = area,
                                    Status = "0",
                                    Flag = "0",
                                    Depth = s,
                                    Row = r,
                                    Column = c,
                                    Layer = l,
                                    CreateUser = userId
                                });
                            }
 
 
 
 
 
                        }
                    }
                }
 
                return q;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 添加储位信息(平库)用于开发人员添加基础信息
        /// </summary>
        /// <param name="model"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task<int> AddPkStorageLocat(AddLocateVm model, int userId)
        {
            try
            {
                var q = 0;
                // 排(组)循环
                for (int i = 1; i <= model.Row; i++)
                {
                    // 列循环
                    for (int z = 1; z <= model.Col; z++)
                    {
                        q += await LocatRst.AddAsync(new SysStorageLocat()
                        {
                            // 区域+排+列+层
                            LocatNo = model.AreaNo + i.ToString().PadLeft(2, '0') + z.ToString().PadLeft(2, '0') + "01",
                            WareHouseNo = model.HouseNo,
                            RoadwayNo = "",
                            AreaNo = model.AreaNo,
                            Status = "0",
                            AisleOne = "1",
                            AisleTwo = "",
                            Flag = "0",
                            Depth = z.ToString(),
                            Row = i,
                            Column = z,
                            Layer = 1,
                            CreateUser = userId
                        }); ;
                    }
                }
 
                return q;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        public bool EditStorageLocatList(EditLocateListVm model, int userId)
        {
            try
            {
                var bl = LocatRst.EditStorageLocatList(model.Id, model.Status, model.Flag, model.Temperature, userId);
 
                return bl;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public bool EditStorageLocatListNew(EditLocateListNewVm model, int userId)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(model.RoadWayNo))
                {
                    throw new Exception("巷道不能为空");
                }
                bool isRow = false;
                if (model.Row != null)
                {
                    if (model.Row <= 0)
                    {
                        throw new Exception("排需要大于0");
                    }
                    isRow = true;
                }
                bool isColumn = false;
                if (model.Column != null)
                {
                    if (model.Column <= 0)
                    {
                        throw new Exception("列需要大于0");
                    }
                    isColumn = true;
                }
                bool isLayer = false;
                if (model.Layer != null )
                {
                    if (model.Column <= 0)
                    {
                        throw new Exception("层需要大于0");
                    }
                    isLayer = true;
                }
                bool isDepth = false;
                if (model.Dept != null)
                {
                    if (model.Dept != 1 && model.Dept != 2)
                    {
                        throw new Exception("深度只能为1或2");
                    }
                    isDepth = true;
                }
                Expression<Func<SysStorageLocat, bool>> item = Expressionable.Create<SysStorageLocat>() //创建表达式
                    .AndIF(isRow, it => it.Row == model.Row)
                    .AndIF(isColumn, it => it.Column == model.Column)
                    .AndIF(isLayer, it => it.Layer == model.Layer)
                    .AndIF(isDepth, it => it.Depth == "0"+model.Dept)
                    .AndIF(!string.IsNullOrWhiteSpace(model.RoadWayNo), it => it.RoadwayNo == model.RoadWayNo)
                    .ToExpression();//注意 这一句 不能少
                var locateList = Db.Queryable<SysStorageLocat>().Where(item).ToList();
                if (locateList.Count == 0)
                {
                    throw new Exception($"未查询到相对应的储位信息");
                }
 
                var com = new Common();
                var i = 0;
                Db.BeginTran();
                foreach (var locate in locateList)
                {
                    if (model.Flag == "2" && locate.Depth == "01")//标识是损坏且深度是01时 需把深度为2的储位给屏蔽
                    {
                        var locate2 = com.GetLocateNoDepth2(locate.WareHouseNo, locate.LocatNo);
                        if (locate2.Flag == "0" && !locateList.Contains(locate2))
                        {
                            locate2.Flag = "1";
                            locate2.UpdateUser = userId;
                            locate2.UpdateTime = DateTime.Now;
                            var m = Db.Updateable(locate2).ExecuteCommand();
                        }
 
                    }
                    if (model.Flag == "0" && locate.Depth == "02")//标识是正常且深度是02时 需判断深度为1的储位状态是否正常
                    {
                        var locate1 = com.GetLocateNoDepth1(locate.WareHouseNo, locate.LocatNo);
 
                        if (locate1.Flag == "2")
                        {
                            throw new Exception($"需先修改{locate1.LocatNo}的储位标识为不是损坏");
                        }
                    }
 
                    if (!string.IsNullOrEmpty(model.Status))
                    {
                        locate.Status = model.Status;
                    }
                    if (!string.IsNullOrEmpty(model.Flag))
                    {
                        locate.Flag = model.Flag;
                    }
                    if (!string.IsNullOrEmpty(model.AreaNo))
                    {
                        locate.AreaNo = model.AreaNo;
                    }
                    locate.UpdateUser = userId;
                    locate.UpdateTime = DateTime.Now;
                    i = Db.Updateable(locate).ExecuteCommand();
                }
                Db.CommitTran();
                return i > 0;
 
            }
            catch (Exception e)
            {
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 查询储位状态
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public string GetStatus(string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return "";
            }
            else
            {
                var str = "";
                switch (code)
                {
                    case "0":
                        str = "空储位";
                        break;
                    case "1":
                        str = "有物品";
                        break;
                    case "2":
                        str = "入库中";
                        break;
                    case "3":
                        str = "出库中";
                        break;
                    case "4":
                        str = "移入中";
                        break;
                    case "5":
                        str = "移出中";
                        break;
                }
 
                return str;
            }
        }
        /// <summary>
        /// 查询储位标志
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public string GetFlag(string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return "";
            }
            else
            {
                var str = "";
                switch (code)
                {
                    case "0":
                        str = "正常";
                        break;
                    case "1":
                        str = "屏蔽";
                        break;
                    case "2":
                        str = "损坏";
                        break;
                }
                return str;
            }
        }
 
        /// <summary>
        /// 获取储位信息
        /// </summary>
        /// <param name="wareHouseNo">仓库</param>
        /// <param name="roadway">巷道号</param>
        /// <param name="row">排 1 or 2</param>
        /// <param name="depth">深度</param>
        /// <returns></returns>
        public List<SysStorageLocat> GetStorageLocatLists(string wareHouseNo, string roadway, string row, string depth)
        {
            try
            {
                var list = Db.Queryable<SysStorageLocat>().Where(m =>
                    m.IsDel == "0" && m.WareHouseNo == wareHouseNo && m.RoadwayNo == roadway && m.Row == int.Parse(row) && m.Depth == depth).ToList();
 
                return list;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
 
        }
 
        /// <summary>
        /// 获取最大层级
        /// </summary>
        /// <param name="wareHouseNo">仓库号</param>
        /// <param name="roadway">仓库号</param>
        /// <param name="row">仓库号</param>
        /// <returns></returns>
        public int GetMaxLayer(string wareHouseNo, string roadway, string row)
        {
            try
            {
                var road = roadway.Substring(1, roadway.Length - 1);
                var num = int.Parse(road);
                var rows = (num - 1) * 2 + int.Parse(row);//排
 
                var maxLayer = Db.Queryable<SysStorageLocat>().Where(m =>
                    m.IsDel == "0" && m.WareHouseNo == wareHouseNo && m.RoadwayNo == roadway && m.Row == int.Parse(row)).Max(m => m.Layer);
 
                return maxLayer;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 获取最大列数
        /// </summary>
        /// <param name="wareHouseNo">仓库号</param>
        /// <param name="roadway">仓库号</param>
        /// <param name="row">仓库号</param>
        /// <returns></returns>
        public int GetColumn(string wareHouseNo, string roadway, string row)
        {
            try
            {
                var road = roadway.Substring(1, roadway.Length - 1);
                var num = int.Parse(road);
                var rows = (num - 1) * 2 + int.Parse(row);//排
 
                var maxColumn = Db.Queryable<SysStorageLocat>().Where(m =>
                    m.IsDel == "0" && m.WareHouseNo == wareHouseNo && m.RoadwayNo == roadway && m.Row == int.Parse(row)).Max(m => m.Column);
 
                return maxColumn;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 获取该仓库排数
        /// </summary>
        /// <param name="wareHouseNo">仓库号</param>
        /// <returns></returns>
        public List<int> GetStorageLocatRow(string wareHouseNo)
        {
            List<int> maxrow = LocatRst.GetStorageLocatRow(wareHouseNo);
            return maxrow;
        }
 
        /// <summary>
        /// 获取该仓库深度
        /// </summary>
        /// <param name="wareHouseNo">仓库号</param>
        /// <returns></returns>
        public List<string> GetDepth(string wareHouseNo)
        {
            List<string> depthlist = LocatRst.GetDepth(wareHouseNo);
            return depthlist;
        }
 
 
 
        /// <summary>
        /// 获取库位占比(圆)
        /// </summary>
        /// <param name="wareHouseNo">仓库号</param>
        /// <returns></returns>
        public List<GetLocateVm> GetStorageProportion(string wareHouseNo)
        {
            try
            {
                string str = $"select status,count(Status) statusnum,'{wareHouseNo}' as WareHouseNo from SysStorageLocat where IsDel = '0' and WareHouseNo = @warehouseno and Flag = '0' group by Status order by Status";
                List<GetLocateVm> getLocateVms = Db.Ado.SqlQuery<GetLocateVm>(str, new
                {
                    warehouseno = wareHouseNo //仓库号
                });
                str = $"select 6 as Status,COUNT(*) statusnum,'{wareHouseNo}' as WareHouseNo from SysStorageLocat where IsDel = '0' and WareHouseNo = '{wareHouseNo}' and Flag != '0'";
                GetLocateVm getLocateVm = Db.Ado.SqlQuerySingle<GetLocateVm>(str);
 
                getLocateVms.Add(getLocateVm);
 
                int a = 0; //0:空储位 
                int b = 0; //1:有物品 
                int c = 0; //2:入库中 
                int d = 0; //3:出库中 
                int e = 0; //4:移入中 
                int f = 0; //5:移出中 
                int g = 0; //6:损坏\屏蔽 
 
                foreach (var item in getLocateVms)
                {
                    //0:空储位 
                    if (item.Status == "0")
                    {
                        a = 1; //0:空储位 
                        continue;
                    }
                    //1:有物品 
                    if (item.Status == "1")
                    {
                        b = 1; //1:有物品 
                        continue;
                    }
                    //2:入库中 
                    if (item.Status == "2")
                    {
                        c = 1; //2:入库中 
                        continue;
                    }
                    //3:出库中 
                    if (item.Status == "3")
                    {
                        d = 1; //3:出库中 
                        continue;
                    }
                    //4:移入中 
                    if (item.Status == "4")
                    {
                        e = 1; //4:移入中 
                        continue;
                    }
                    //5:移出中 
                    if (item.Status == "5")
                    {
                        f = 1; //5:移出中 
                        continue;
                    }
                    //6:损坏\屏蔽 
                    if (item.Status == "6")
                    {
                        g = 1; //6:损坏\屏蔽 
                        continue;
                    }
                }
 
                //0:空储位 
                if (a == 0)
                {
                    getLocateVm = new GetLocateVm();
                    getLocateVm.WareHouseNo = wareHouseNo; //仓库号
                    getLocateVm.StatusNum = "0";
                    getLocateVm.Status = "0";
                    getLocateVms.Add(getLocateVm);
                }
                //1:有物品 
                if (b == 0)
                {
                    getLocateVm = new GetLocateVm();
                    getLocateVm.WareHouseNo = wareHouseNo; //仓库号
                    getLocateVm.StatusNum = "0";
                    getLocateVm.Status = "1";
                    getLocateVms.Add(getLocateVm);
                }
                //2:入库中 
                if (c == 0)
                {
                    getLocateVm = new GetLocateVm();
                    getLocateVm.WareHouseNo = wareHouseNo; //仓库号
                    getLocateVm.StatusNum = "0";
                    getLocateVm.Status = "2";
                    getLocateVms.Add(getLocateVm);
                }
                //3:出库中 
                if (d == 0)
                {
                    getLocateVm = new GetLocateVm();
                    getLocateVm.WareHouseNo = wareHouseNo; //仓库号
                    getLocateVm.StatusNum = "0";
                    getLocateVm.Status = "3";
                    getLocateVms.Add(getLocateVm);
                }
                //4:移入中 
                if (e == 0)
                {
                    getLocateVm = new GetLocateVm();
                    getLocateVm.WareHouseNo = wareHouseNo; //仓库号
                    getLocateVm.StatusNum = "0";
                    getLocateVm.Status = "4";
                    getLocateVms.Add(getLocateVm);
                }
                //5:移出中 
                if (f == 0)
                {
                    getLocateVm = new GetLocateVm();
                    getLocateVm.WareHouseNo = wareHouseNo; //仓库号
                    getLocateVm.StatusNum = "0";
                    getLocateVm.Status = "5";
                    getLocateVms.Add(getLocateVm);
                }
                //6:损坏\屏蔽 
                if (g == 0)
                {
                    getLocateVm = new GetLocateVm();
                    getLocateVm.WareHouseNo = wareHouseNo; //仓库号
                    getLocateVm.StatusNum = "0";
                    getLocateVm.Status = "6";
                    getLocateVms.Add(getLocateVm);
                }
 
                return getLocateVms;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 获取库位占比(柱)
        /// </summary>
        /// <param name="wareHouseNo">仓库号</param>
        /// <param name="roadwayNo">巷道号</param>
        /// <returns></returns>
        public List<GetLocateVm> GetStorageProportion1(string wareHouseNo, string roadwayNo)
        {
            try
            {
                //根据仓库号以及巷道号获取储位各状态数据
                string str = "select Row,Status,COUNT(Status) StatusNum from SysStorageLocat where WareHouseNo = @warehouseno and RoadwayNo = @roadwayno group by Row,Status order by Row,Status";
 
                List<GetLocateVm> getLocateVms = Db.Ado.SqlQuery<GetLocateVm>(str, new
                {
                    warehouseno = wareHouseNo, //仓库号
                    roadwayno = roadwayNo //巷道号
                });
 
 
 
                getLocateVms[0].WareHouseNo = wareHouseNo;
                getLocateVms[0].RoadwayNo = roadwayNo;
                return getLocateVms;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 获取仓库巷道
        /// </summary>
        /// <param name="wareHouseNo">仓库号</param>
        /// <returns></returns>
        public List<RoadwayDto> GetRoadwayList(string wareHouseNo)
        {
            try
            {
                string str = "select RoadwayNo,RoadwayName,WareHouseNo from SysStorageRoadway where IsDel = @isdel";
 
                if (!string.IsNullOrWhiteSpace(wareHouseNo))
                {
                    str += " and WareHouseNo = @warehouseno";
                }
 
                List<RoadwayDto> roadway = Db.Ado.SqlQuery<RoadwayDto>(str, new
                {
                    isdel = "0", //是否删除
                    warehouseno = wareHouseNo //仓库号
                });
                return roadway;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 根据储位地址获取储位上的托盘和物品信息
        /// </summary>
        /// <param name="locatNo"></param>
        /// <returns></returns>
        public LocateInfoVm GetLocateInfo(string locatNo)
        {
            try
            {
                LocateInfoVm model = new LocateInfoVm();
                string status = "";
                //储位信息
                SysStorageLocat storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == locatNo && w.IsDel == "0");
                if (storageLocat == null)
                {
                    throw new Exception("未找到对应储位");
                }
                //有物品、出库中数据源(库存明细表)
                if (storageLocat.Status == "1" || storageLocat.Status == "3" || storageLocat.Status == "5")
                {
                    //库存明细
                    List<DataStockDetail> stockDetailList = Db.Queryable<DataStockDetail>().Where(w => w.LocatNo == locatNo && w.IsDel == "0").ToList();
                    if (stockDetailList == null || stockDetailList.Count <= 0)
                    {
                        throw new Exception("未找到对应的库存明细信息");
                    }
                    model.LocatNo = locatNo;
                    model.Status = storageLocat.Status;
                    model.PalletNo = stockDetailList[0].PalletNo;
 
                    List<LocateGoodsInfoVm> goodsList = new List<LocateGoodsInfoVm>();
                    foreach (var item in stockDetailList)
                    {
                        LocateGoodsInfoVm goodsModel = new LocateGoodsInfoVm();
                        goodsModel.SkuNo = item.SkuNo;
                        goodsModel.SkuName = item.SkuName;
                        goodsModel.LotNo = item.LotNo;
                        goodsModel.Qty = item.Qty;
                        switch (item.InspectStatus)
                        {
                            case "0":
                                status = "待检验";
                                break;
                            case "1":
                                status = "合格";
                                break;
                            case "2":
                                status = "不合格";
                                break;
                        }
                        goodsModel.InspectStatus = status;
 
                        goodsList.Add(goodsModel);
                    }
                    model.GoodsInfoList = goodsList;
                }
                //入库中数据源(托盘绑定表)
                else if (storageLocat.Status == "2")
                {
                    //托盘绑定信息
                    List<BllPalletBind> palletBindList = Db.Queryable<BllPalletBind>()
                        .Where(w => w.LocatNo == locatNo && w.IsDel == "0" && w.Status == "1").ToList();
                    if (palletBindList == null || palletBindList.Count <= 0)
                    {
                        throw new Exception("未找到对应的托盘绑定信息");
                    }
                    model.LocatNo = locatNo;
                    model.Status = storageLocat.Status;
                    model.PalletNo = palletBindList[0].PalletNo;
 
                    List<LocateGoodsInfoVm> goodsList = new List<LocateGoodsInfoVm>();
                    foreach (var item in palletBindList)
                    {
                        //入库单明细
                        BllArrivalNoticeDetail noticeDetail = Db.Queryable<BllArrivalNoticeDetail>().First(w => w.Id == item.ASNDetailNo);
                        if (noticeDetail == null)
                        {
                            throw new Exception("未找到对应的入库单明细信息");
                        }
                        LocateGoodsInfoVm goodsModel = new LocateGoodsInfoVm();
                        goodsModel.SkuNo = noticeDetail.SkuNo;
                        goodsModel.SkuName = noticeDetail.SkuName;
                        goodsModel.LotNo = noticeDetail.LotNo;
                        goodsModel.Qty = noticeDetail.Qty;
                        goodsModel.InspectStatus = "待检验";
 
                        goodsList.Add(goodsModel);
                    }
                    model.GoodsInfoList = goodsList;
                }
                else
                {
                    model.LocatNo = locatNo;
                    model.Status = storageLocat.Status;
                }
                //储位状态
                switch (model.Status)
                {
                    case "0":
                        model.Status = "空储位";
                        break;
                    case "1":
                        model.Status = "有物品";
                        break;
                    case "2":
                        model.Status = "入库中";
                        break;
                    case "3":
                        model.Status = "出库中";
                        break;
                    case "4":
                        model.Status = "移入中";
                        break;
                    case "5":
                        model.Status = "移出中";
                        break;
                    default:
                        model.Status = "";
                        break;
                }
                return model;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        #region 平库图例
 
        /// <summary>
        /// 获取储位信息(平库图例)
        /// </summary>
        /// <param name="wareHouseNo">仓库</param>
        /// <param name="row">排</param>
        /// <returns></returns>
        public List<SysStorageLocat> GetFlatLibraryLegend(string wareHouseNo, string row)
        {
            try
            {
                //一楼区域
                //List<string> row1 = new List<string>()
                //{
                //    "B01",
                //    "B02",
                //    "B03",
                //    "B04",
                //    "B05",
                //    "B06",
                //    "B07",
                //};
                ////二楼区域
                //List<string> row3 = new List<string>()
                //{
                //    "B11",
                //    "B12",
                //    "B13",
                //    "B14",
                //    "B15",
                //};
                string row1 = "'B01','B02','B03','B04','B05','B06','B07'";
                string row3 = "'B11','B12','B13','B14','B15'";
                string str = $"select * from SysStorageLocat where IsDel = '0' and WareHouseNo = '{wareHouseNo}' and ";
                if (row == "1")
                {
                    str += $" AreaNo in ({row1})";
                }
                else if (row == "3")
                {
                    str += $" AreaNo in ({row3})";
                }
 
                var list = Db.Ado.SqlQuery<SysStorageLocat>(str);
 
                //var list = Db.Queryable<SysStorageLocat>().Where(m => m.IsDel == "0" && m.WareHouseNo == wareHouseNo && row == "1" ? row1.Contains(m.AreaNo) : row3.Contains(m.AreaNo)).ToList();
 
                return list;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
 
        }
 
        #endregion
    }
}