dengjunjie
2026-03-11 b2cc7bb7740e42e57cf50af02a8ca4b535cad484
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
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common.LocationEnum;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_BasicInfoService
{
    public class RGVLocationInfoService : ServiceBase<Dt_RGVLocationInfo, IRepository<Dt_RGVLocationInfo>>, IRGVLocationInfoService
    {
        public RGVLocationInfoService(IRepository<Dt_RGVLocationInfo> BaseDal) : base(BaseDal)
        {
        }
        private Dictionary<string, OrderByType> _emptyAssignOrderBy = new Dictionary<string, OrderByType>()
        {
            { nameof(Dt_RGVLocationInfo.Row), OrderByType.Asc },
            { nameof(Dt_RGVLocationInfo.Depth), OrderByType.Desc },
            { nameof(Dt_RGVLocationInfo.Layer), OrderByType.Asc },
            //{ nameof(Dt_RGVLocationInfo.Column), OrderByType.Asc },
        };
        private Dictionary<string, OrderByType> _DepthAscOrderBy = new Dictionary<string, OrderByType>()
        {
            { nameof(Dt_RGVLocationInfo.Depth), OrderByType.Asc },
        };
        public IRepository<Dt_RGVLocationInfo> Repository => BaseDal;
 
        public List<Dt_RGVLocationInfo> GetFreeLocationInfos()
        {
            return BaseDal.QueryData(x => x.EnableStatus == EnableStatusEnum.Normal.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt(), _emptyAssignOrderBy);
        }
        /// <summary>
        /// 查找入库可用货位
        /// </summary>
        /// <param name="AreaCode"></param>
        /// <returns></returns>
        public Dt_RGVLocationInfo? GetInFreeLocationInfo(string AreaCode)
        {
            Dt_RGVLocationInfo? rGVLocationInfo = null;
            Dt_RGVLocationInfo? FreerGVLocationInfo = null;
            List<Dt_RGVLocationInfo> rGVLocationInfos = BaseDal.QueryData(x => x.WarehouseId.ToString() == AreaCode && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt(), _emptyAssignOrderBy);//查找所有空货位
            if (rGVLocationInfos == null || rGVLocationInfos.Count < 1) return rGVLocationInfo;
            #region 判断巷道是否有货
            List<string> LocationCodes = new List<string>();
            foreach (var items in rGVLocationInfos.GroupBy(x => x.RoadwayNo))//根据巷道号分组
            {
                foreach (var item in items)
                {
                    List<Dt_RGVLocationInfo> dt_RGVLocationInfos = BaseDal.QueryData(x => x.RoadwayNo == items.Key);//查找当前巷道号货位
                    if (item.LocationType == 1)
                    {
                        rGVLocationInfo = dt_RGVLocationInfos.Where(x => x.Depth < item.Depth && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt()).FirstOrDefault();//判断浅深度货位是否有货
                        if (rGVLocationInfo != null) break;
                        return item;
                    }
                    else
                    {
                        rGVLocationInfo = dt_RGVLocationInfos.Where(x => x.Depth < item.Depth && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt()).OrderByDescending(x => x.Depth).FirstOrDefault();//判断浅深度货位是否有货
                        if (rGVLocationInfo != null)
                        {
                            rGVLocationInfo = dt_RGVLocationInfos.Where(x => x.Depth > rGVLocationInfo.Depth && x.LocationStatus == LocationStatusEnum.Free.ObjToInt()).OrderBy(x => x.Depth).FirstOrDefault();
                            if (rGVLocationInfo != null)
                            {
                                if (dt_RGVLocationInfos.Where(x => x.Depth > rGVLocationInfo.Depth && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt()).Any()) rGVLocationInfo = null;
                                else return rGVLocationInfo;
                            }
                            //var Depth = 0;
                            //while (item.Depth - rGVLocationInfo.Depth != 0)
                            //{
                            //    if (rGVLocationInfo.Depth < item.Depth) Depth = rGVLocationInfo.Depth - 1;
                            //    else Depth = rGVLocationInfo.Depth + 1;
                            //    rGVLocationInfo = dt_RGVLocationInfos.Where(x => x.Depth == Depth).FirstOrDefault();
                            //    if (rGVLocationInfo != null && rGVLocationInfo.LocationStatus == (int)LocationStatusEnum.Free) return rGVLocationInfo;
                            //}
                        }//判断浅深度货位是否有货
                        else return item;
                    }
 
                    //if (rGVLocationInfo != null)//浅深度货位有货,找深深度货位是否有货
                    //{
                    //    if (item.LocationType == 1) break;//巷道类型为单向,直接跳过
                    //    foreach (var locationInfo in rGVLocationInfos.Where(x => x.RoadwayNo == items.Key).OrderByDescending(x => x.Depth))
                    //    {
                    //        if (!dt_RGVLocationInfos.Where(x => x.LocationStatus == LocationStatusEnum.InStock.ObjToInt() && x.Depth < locationInfo.Depth).Any()) return locationInfo;
                    //    }
                    //    //rGVLocationInfo = dt_RGVLocationInfos.Where(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt()).OrderBy(x => x.Depth).FirstOrDefault();//找浅深度空货位
                    //    //if (rGVLocationInfo != null)
                    //    //{
                    //    //    if (dt_RGVLocationInfos.Where(x => x.Depth > rGVLocationInfo.Depth && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt()).FirstOrDefault() == null)//判断深深度货位是否有货
                    //    //        return rGVLocationInfo;
                    //    //}
                    //}
                    //if (rGVLocationInfo == null)
                    //{
                    //    rGVLocationInfo = dt_RGVLocationInfos.Where(x => x.Depth > item.Depth && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt()).FirstOrDefault();//判断浅深度货位是否有货
                    //    if (item.LocationType == 1) break;//巷道类型为单向,直接跳过
                    //    foreach (var locationInfo in rGVLocationInfos.Where(x => x.RoadwayNo == items.Key).OrderByDescending(x => x.Depth))
                    //    {
                    //        if (!dt_RGVLocationInfos.Where(x => x.LocationStatus == LocationStatusEnum.InStock.ObjToInt() && x.Depth < locationInfo.Depth).Any()) return locationInfo;
                    //    }
                    //}
                    //else return item;
                }
            }
            #endregion
            return FreerGVLocationInfo;
        }
    }
}