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>, IRGVLocationInfoService { public RGVLocationInfoService(IRepository BaseDal) : base(BaseDal) { } private Dictionary _emptyAssignOrderBy = new Dictionary() { { 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 _DepthAscOrderBy = new Dictionary() { { nameof(Dt_RGVLocationInfo.Depth), OrderByType.Asc }, }; public IRepository Repository => BaseDal; public List GetFreeLocationInfos() { return BaseDal.QueryData(x => x.EnableStatus == EnableStatusEnum.Normal.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt(), _emptyAssignOrderBy); } /// /// 查找入库可用货位 /// /// /// public Dt_RGVLocationInfo? GetInFreeLocationInfo(string AreaCode) { Dt_RGVLocationInfo? rGVLocationInfo = null; Dt_RGVLocationInfo? FreerGVLocationInfo = null; List 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 LocationCodes = new List(); foreach (var items in rGVLocationInfos.GroupBy(x => x.RoadwayNo))//根据巷道号分组 { foreach (var item in items) { List 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; } } }