ke_junjie
2025-06-04 84620534eb627e95811b971a4b552b6a177829bf
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
using Furion.DatabaseAccessor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Furion.FriendlyException;
using iWare.Wms.Core;
using iWare.Wms.Core.Enum;
 
namespace Admin.NET.Application.Common.FindEmptyLocationFactory.Default
{
    internal class ContainerFindEmptyLocationHandle : FindEmptyLocationServiceHandle
    {
        public ContainerFindEmptyLocationHandle(IRepository<v_empty_location, MasterDbContextLocator> v_EmptyLocationRep,
            IRepository<WmsPlace, MasterDbContextLocator> wareLocationRep,
             IRepository<WareTask, MasterDbContextLocator> wareTaskRep,
            IRepository<WareContainerVsMaterial, MasterDbContextLocator> wareContainerVsMaterial,
            IRepository<WmsContainer, MasterDbContextLocator> wareContainer,
             IRepository<WmsContainerType, MasterDbContextLocator> wareContainerType,
              IRepository<v_ware_inventory_by_container, MasterDbContextLocator> v_ware_inventory_by_container,
            string containerCode, string siteCode) : base(
                 v_EmptyLocationRep,
            wareLocationRep,
             wareTaskRep,
            wareContainerVsMaterial,
            wareContainer,
             wareContainerType,
             v_ware_inventory_by_container,
            containerCode,
            siteCode)
        {
 
        }
 
        protected override void DiyFilter()
        {
            base.DiyFilter();
        }
 
        protected override void QueryBaseEmptyLocationList()
        {
            //base.QueryBaseEmptyLocationList();
            var container = _wareContainer.DetachedEntities.Where(u => u.ContainerCode == _containerCode).FirstOrDefault();
            if (container == null)
            {
                throw Oops.Oh("小车没有配置信息");
            }
            WmsContainerType containerType = new WmsContainerType();
            if (container != null)
            {
                containerType = _wareContainerType.Where(u => u.WareContainerTypeCode == container.ContainerTypeCode).FirstOrDefault();
                if (containerType == null)
                {
                    throw Oops.Oh($"查询不到小车{_containerCode}的容器类型");
                }
            }
            else
            {
                throw Oops.Oh($"小车{_containerCode}未查询到基础信息");
            }
 
            //处理可入库位类型
            var typeList = containerType.LocationType.Split(',');
 
            //优先找远伸位有空小车的近伸位,并且托盘类型相同且为空托,空托放在同一个伸位
            var farlocationlist = _v_ware_inventory_by_container.DetachedEntities.Where(u => u.IsLocked == false && u.DeepcellNo == DeepcellNoEnum.远伸 && u.ContainerType == containerType.WareContainerTypeCode).Select(u => u.UnionCode).ToList();
            findEmptyLocationList = _v_EmptyLocationRep.DetachedEntities.Where(u => farlocationlist.Contains(u.UnionCode) && u.DeepcellNo == DeepcellNoEnum.近伸).ToList();
            if (findEmptyLocationList.Count == 0)
            {
                //优先放远伸,放满所有远伸后放近伸
                findEmptyLocationList = _v_EmptyLocationRep.DetachedEntities.Where(u => u.DeepcellNo == DeepcellNoEnum.远伸 && typeList.Contains(u.WareLocationTypeCode)).ToList();
            }
            if (findEmptyLocationList.Count == 0)
            {
                //优先放远伸,放满所有远伸后放近伸
                findEmptyLocationList = _v_EmptyLocationRep.DetachedEntities.Where(u => typeList.Contains(u.WareLocationTypeCode)).ToList();
            }
            if (findEmptyLocationList.Count == 0 && _siteCode == "HMAX")
            {
                //还是没有满足的库位,找可入库位放
                findEmptyLocationList = _v_EmptyLocationRep.DetachedEntities.Where(u => u.WareLocationTypeCode == "HMAX").ToList();
            }
        }
 
        protected override void EnableLaneFilter()
        {
            base.EnableLaneFilter();
        }
        protected override void TaskOccupyFilter()
        {
            base.TaskOccupyFilter();
        }
 
        protected override void DataOrder()
        {
            if (findEmptyLocationList != null && findEmptyLocationList.Count > 0)
            {
                findEmptyLocationList = findEmptyLocationList
                       //先按照层,升序排列
                       .OrderByDescending(x => x.LayerNo + x.ColumnNo).ToList();
            }
            base.DataOrder();
        }
    }
}