/// <summary> /// 分配车位: /// 1、优先分配中间区域的车位 /// 2、判断ETV可达,车厅可达 /// </summary> /// <param name="checkcode"></param> /// <returns></returns> public Location AllocateLoc(string checkcode) { //优先分配中间区域的车位 int middlecolmn = 9; CWLocation cwlctn = new CWLocation(); CWDevice cwdevice = new CWDevice(); CWTask cwtask = new CWTask(); CWICCard cwiccd = new CWICCard(); #region 依距车厅的远近找出所有车位的集合 List <Location> allLocLst = cwlctn.FindLocList(); List <Customer> fixCustLst = cwiccd.FindCustList(cu => cu.Type == EnmICCardType.FixedLocation || cu.Type == EnmICCardType.VIP); //排除固定车位 List <Location> suitLocsLst = allLocLst.FindAll(lc => fixCustLst.Exists(cc => cc.LocAddress == lc.Address && cc.Warehouse == lc.Warehouse) == false); List <Location> sameLctnLst = new List <Location>(); var locList_small = from loc in suitLocsLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && string.Compare(loc.LocSize, checkcode) == 0 orderby loc.LocSide ascending, Math.Abs(loc.LocColumn - middlecolmn) ascending select loc; var locList_big = from loc in suitLocsLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && string.Compare(loc.LocSize, checkcode) > 0 orderby loc.LocSide ascending, Math.Abs(loc.LocColumn - middlecolmn) ascending select loc; sameLctnLst.AddRange(locList_small); sameLctnLst.AddRange(locList_big); List <Location> lctnLst = new List <Location>(); #region 如果是重列车位,优先分配前面车位是空闲的,其次是占用的,最后才是执行中的 List <Location> spaceLctnLst = new List <Location>(); List <Location> occupyLctnLst = new List <Location>(); List <Location> otherLctnLst = new List <Location>(); foreach (Location loc in sameLctnLst) { if (loc.LocSide == 4) { #region 判断前面车位状态 string fwdAddrs = "2" + loc.Address.Substring(1); Location forward = cwlctn.FindLocation(l => l.Address == fwdAddrs); if (forward != null) { if (forward.Type == EnmLocationType.Normal) { if (forward.Status == EnmLocationStatus.Space) { spaceLctnLst.Add(loc); } else if (forward.Status == EnmLocationStatus.Occupy) { occupyLctnLst.Add(loc); } else { otherLctnLst.Add(loc); } } } #endregion } else if (loc.LocSide == 2) { #region 判断后面车位状态 string bckAddrs = "4" + loc.Address.Substring(1); Location back = cwlctn.FindLocation(l => l.Address == bckAddrs); if (back != null) { if (back.Type == EnmLocationType.Normal) { if (back.Status == EnmLocationStatus.Space) { spaceLctnLst.Add(loc); } else if (back.Status == EnmLocationStatus.Occupy) { occupyLctnLst.Add(loc); } else { otherLctnLst.Add(loc); } } else //禁用的 { spaceLctnLst.Add(loc); } } #endregion } else { spaceLctnLst.Add(loc); } } lctnLst.AddRange(spaceLctnLst); lctnLst.AddRange(occupyLctnLst); lctnLst.AddRange(otherLctnLst); #endregion if (lctnLst.Count == 0) { return(null); } List <Device> nEtvList = cwdevice.FindList(d => d.Type == EnmSMGType.ETV); WorkScope workscope = new WorkScope(nEtvList); List <Device> availHallLst = cwdevice.FindList(d => d.Type == EnmSMGType.Hall && d.Mode == EnmModel.Automatic); List <Device> availEtvLst = nEtvList.FindAll(d => d.Mode == EnmModel.Automatic); if (availEtvLst.Count == 0 || availHallLst.Count == 0) { return(null); } if (availEtvLst.Count == 2 && availHallLst.Count == 2) { return(lctnLst.FirstOrDefault()); } if (availEtvLst.Count == 1) { CScope scope = workscope.GetEtvScope(availEtvLst[0]); if (availHallLst.Count == 2) { foreach (Location loc in lctnLst) { if (loc.LocColumn >= scope.LeftCol && loc.LocColumn <= scope.RightCol) { return(loc); } } } else { Device hall = availHallLst[0]; int hallcolmn = Convert.ToInt32(hall.Address.Substring(1, 2)); if (hallcolmn >= scope.LeftCol && hallcolmn <= scope.RightCol) { foreach (Location loc in lctnLst) { if (loc.LocColumn >= scope.LeftCol && loc.LocColumn <= scope.RightCol) { return(loc); } } } } } #endregion return(null); }
/// <summary> /// 巷道堆垛临时卡车位分配 /// </summary> /// <returns></returns> private Location PXDAllocate(Device hall, string checkCode, out int smg) { smg = 0; #region CWLocation cwlctn = new CWLocation(); CWDevice cwdevice = new CWDevice(); CWTask cwtask = new CWTask(); CWICCard cwiccd = new CWICCard(); List <Device> nEtvList = cwdevice.FindList(d => d.Type == EnmSMGType.ETV); WorkScope workscope = new WorkScope(nEtvList); int hallColmn = Convert.ToInt32(hall.Address.Substring(1, 2)); List <Device> reachHall = new List <Device>(); #region 找出可达车厅、可用的ETV集合 foreach (Device dev in nEtvList) { CScope scope = workscope.GetEtvScope(dev); if (scope.LeftCol <= hallColmn && hallColmn <= scope.RightCol) { if (dev.IsAble == 1) { reachHall.Add(dev); } } } #endregion List <Location> lctnLst = new List <Location>(); #region 依距车厅的远近找出所有车位的集合 List <Location> allLocLst = cwlctn.FindLocList(); List <Customer> fixCustLst = cwiccd.FindCustList(cu => cu.Type == EnmICCardType.FixedLocation || cu.Type == EnmICCardType.VIP); //排除固定车位 allLocLst = allLocLst.FindAll(lc => fixCustLst.Exists(cc => cc.LocAddress == lc.Address && cc.Warehouse == lc.Warehouse) == false); #region 车位尺寸一致 List <Location> sameLctnLst = new List <Location>(); #region #region 首先 分配与车厅同一个区域的,车位尺寸一致的, 4-2-1依次排列, var L42_locList_small = from loc in allLocLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkCode) == 1 && loc.LocSide != 1 && loc.Region == hall.Region orderby Math.Abs(loc.LocColumn - hallColmn) ascending, loc.LocSide descending select loc; //1边 var L1_locList_small = from loc in allLocLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkCode) == 1 && loc.LocSide == 1 && loc.Region == hall.Region orderby Math.Abs(loc.LocColumn - hallColmn) ascending select loc; #endregion sameLctnLst.AddRange(L42_locList_small); sameLctnLst.AddRange(L1_locList_small); #region 再次分配与车厅同一个区域,车位尺寸(仅宽度)偏大点的 var L42_locList_width = from loc in allLocLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkCode) == 2 && loc.LocSide != 1 && loc.Region == hall.Region orderby Math.Abs(loc.LocColumn - hallColmn) ascending, loc.LocSide descending select loc; //1边 var L1_locList_width = from loc in allLocLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkCode) == 2 && loc.LocSide == 1 && loc.Region == hall.Region orderby Math.Abs(loc.LocColumn - hallColmn) ascending select loc; #endregion sameLctnLst.AddRange(L42_locList_width); sameLctnLst.AddRange(L1_locList_width); #region 再分配与车厅不是同一个区域的 //4边2边 var L42_locList_small_dif = from loc in allLocLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkCode) == 1 && loc.LocSide != 1 && loc.Region != hall.Region orderby Math.Abs(loc.LocColumn - hallColmn) ascending, loc.LocSide descending select loc; //1边 var L1_locList_small_dif = from loc in allLocLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkCode) == 1 && loc.LocSide == 1 && loc.Region != hall.Region orderby Math.Abs(loc.LocColumn - hallColmn) ascending select loc; #endregion sameLctnLst.AddRange(L42_locList_small_dif); sameLctnLst.AddRange(L1_locList_small_dif); #region 再次分配与车厅不同区域,车位尺寸(仅宽度)偏大点的 var L42_locList_width_dif = from loc in allLocLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkCode) == 2 && loc.LocSide != 1 && loc.Region != hall.Region orderby Math.Abs(loc.LocColumn - hallColmn) ascending, loc.LocSide descending select loc; //1边 var L1_locList_width_dif = from loc in allLocLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkCode) == 2 && loc.LocSide == 1 && loc.Region != hall.Region orderby Math.Abs(loc.LocColumn - hallColmn) ascending select loc; #endregion sameLctnLst.AddRange(L42_locList_width_dif); sameLctnLst.AddRange(L1_locList_width_dif); #endregion #region 如果是重列车位,优先分配前面车位是空闲的,其次是占用的,最后才是执行中的 List <Location> spaceLctnLst = new List <Location>(); List <Location> occupyLctnLst = new List <Location>(); List <Location> otherLctnLst = new List <Location>(); foreach (Location loc in sameLctnLst) { if (loc.LocSide == 4) { #region 判断前面车位状态 string fwdAddrs = "2" + loc.Address.Substring(1); Location forward = cwlctn.FindLocation(l => l.Address == fwdAddrs); if (forward != null) { if (forward.Type == EnmLocationType.Normal) { if (forward.Status == EnmLocationStatus.Space) { spaceLctnLst.Add(loc); } else if (forward.Status == EnmLocationStatus.Occupy) { occupyLctnLst.Add(loc); } else { otherLctnLst.Add(loc); } } } #endregion } else if (loc.LocSide == 2) { #region 判断后面车位状态 string bckAddrs = "4" + loc.Address.Substring(1); Location back = cwlctn.FindLocation(l => l.Address == bckAddrs); if (back != null) { if (back.Type == EnmLocationType.Normal) { if (back.Status == EnmLocationStatus.Space) { spaceLctnLst.Add(loc); } else if (back.Status == EnmLocationStatus.Occupy) { occupyLctnLst.Add(loc); } else { otherLctnLst.Add(loc); } } else //禁用的 { spaceLctnLst.Add(loc); } } #endregion } else { spaceLctnLst.Add(loc); } } lctnLst.AddRange(spaceLctnLst); lctnLst.AddRange(occupyLctnLst); lctnLst.AddRange(otherLctnLst); #endregion #endregion #region 车位尺寸是大的 List <Location> bigLctnLst = new List <Location>(); #region #region 首先 分配与车厅同一个区域的,车位尺寸一致的, 4-2-1依次排列, var L42_locList_big = from loc in allLocLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkCode) == 3 && loc.LocSide != 1 && loc.Region == hall.Region orderby Math.Abs(loc.LocColumn - hallColmn) ascending, loc.LocSide descending select loc; //1边 var L1_locList_big = from loc in allLocLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkCode) == 3 && loc.LocSide == 1 && loc.Region == hall.Region orderby Math.Abs(loc.LocColumn - hallColmn) ascending select loc; #endregion bigLctnLst.AddRange(L42_locList_big); bigLctnLst.AddRange(L1_locList_big); #region 再分配与车厅不是同一个区域的 var L42_locList_big_dif = from loc in allLocLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkCode) == 3 && loc.LocSide != 1 && loc.Region != hall.Region orderby Math.Abs(loc.LocColumn - hallColmn) ascending, loc.LocSide descending select loc; //1边 var L1_locList_big_dif = from loc in allLocLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkCode) == 3 && loc.LocSide == 1 && loc.Region != hall.Region orderby Math.Abs(loc.LocColumn - hallColmn) ascending select loc; #endregion bigLctnLst.AddRange(L42_locList_big_dif); bigLctnLst.AddRange(L1_locList_big_dif); #endregion #region 如果是重列车位,优先分配前面车位是空闲的,其次是占用的,最后才是执行中的 List <Location> spaceLctnLst_big = new List <Location>(); List <Location> occupyLctnLst_big = new List <Location>(); List <Location> otherLctnLst_big = new List <Location>(); foreach (Location loc in bigLctnLst) { if (loc.LocSide == 4) { #region 判断前面车位状态 string fwdAddrs = "2" + loc.Address.Substring(1); Location forward = cwlctn.FindLocation(l => l.Address == fwdAddrs); if (forward != null) { if (forward.Type == EnmLocationType.Normal) { if (forward.Status == EnmLocationStatus.Space) { spaceLctnLst_big.Add(loc); } else if (forward.Status == EnmLocationStatus.Occupy) { occupyLctnLst_big.Add(loc); } else { otherLctnLst_big.Add(loc); } } } #endregion } else if (loc.LocSide == 2) { #region 判断后面车位状态 string bckAddrs = "4" + loc.Address.Substring(1); Location back = cwlctn.FindLocation(l => l.Address == bckAddrs); if (back != null) { if (back.Type == EnmLocationType.Normal) { if (back.Status == EnmLocationStatus.Space) { spaceLctnLst_big.Add(loc); } else if (back.Status == EnmLocationStatus.Occupy) { occupyLctnLst_big.Add(loc); } else { otherLctnLst_big.Add(loc); } } else //禁用的 { spaceLctnLst_big.Add(loc); } } #endregion } else { spaceLctnLst_big.Add(loc); } } lctnLst.AddRange(spaceLctnLst_big); lctnLst.AddRange(occupyLctnLst_big); lctnLst.AddRange(otherLctnLst_big); #endregion #endregion #endregion if (reachHall.Count == 1) { CScope scope = workscope.GetEtvScope(reachHall[0]); //只要一个ETV可达车厅, //依作业范围,找出在TV范围内的车位 foreach (Location loc in lctnLst) { if (scope.LeftCol <= loc.LocColumn && loc.LocColumn <= scope.RightCol) { smg = reachHall[0].DeviceCode; return(loc); } } } else if (reachHall.Count == 2) { //如果有两个空闲的 List <Device> freeEtvs = reachHall.FindAll(ch => ch.TaskID == 0); if (freeEtvs.Count == 2) { #region freeEtvs = reachHall.OrderBy(h => Math.Abs(h.Region - hall.Region)).ToList(); foreach (Device dev in freeEtvs) { CScope scope = workscope.GetEtvScope(dev); foreach (Location loc in lctnLst) { if (scope.LeftCol <= loc.LocColumn && loc.LocColumn <= scope.RightCol) { smg = dev.DeviceCode; return(loc); } } } #endregion } else if (freeEtvs.Count == 1) { #region Device dev = freeEtvs[0]; if (dev.Region == hall.Region) { #region smg = dev.DeviceCode; CScope scope = workscope.GetEtvScope(dev); foreach (Location loc in lctnLst) { if (scope.LeftCol <= loc.LocColumn && loc.LocColumn <= scope.RightCol) { return(loc); } } #endregion } else { #region //如果不是同一区域的 //判断另一个ETV在执行什么样的动作, //另一台ETV要不要跨区作业 Device other = reachHall.Find(h => h.DeviceCode != dev.DeviceCode); if (other.TaskID != 0) { ImplementTask task = cwtask.Find(other.TaskID); if (task != null) { string toAddrs = ""; if (task.Status == EnmTaskStatus.TWaitforLoad || task.Status == EnmTaskStatus.TWaitforMove) { toAddrs = task.FromLctAddress; } else { toAddrs = task.ToLctAddress; } int toCol = Convert.ToInt32(toAddrs.Substring(1, 2)); //正在作业TV int currCol = Convert.ToInt32(other.Address.Substring(1, 2)); //空闲TV int freeCol = Convert.ToInt32(dev.Address.Substring(1, 2)); //空闲TV在右侧,即2号ETV空闲 if (currCol < freeCol) { #region TV2空闲 if (hallColmn >= toCol + 3) { //1#车厅不在范围内,则允许2#ETV动作 smg = dev.DeviceCode; CScope scope = workscope.GetEtvScope(dev); foreach (Location loc in lctnLst) { if (scope.LeftCol <= loc.LocColumn && loc.LocColumn <= scope.RightCol) { return(loc); } } } #endregion } else { #region 1#TV空闲 if (hallColmn <= toCol - 3) { //2#车厅不在范围内,则允许1#ETV动作 smg = dev.DeviceCode; CScope scope = workscope.GetEtvScope(dev); foreach (Location loc in lctnLst) { if (scope.LeftCol <= loc.LocColumn && loc.LocColumn <= scope.RightCol) { return(loc); } } } #endregion } } } #endregion } #endregion } List <Device> orderbyEtvs = reachHall.OrderBy(dr => Math.Abs(dr.Region - hall.Region)).ToList(); #region 两个都在忙或上述找不到时,则依车厅区域内的ETV优先,分配ETV foreach (Device devc in orderbyEtvs) { CScope scope = workscope.GetEtvScope(devc); foreach (Location loc in lctnLst) { if (scope.LeftCol <= loc.LocColumn && loc.LocColumn <= scope.RightCol) { smg = devc.DeviceCode; return(loc); } } } #endregion } #endregion return(null); }
/// <summary> /// 依ETV作业范围,找出符合尺寸的车位 /// 如果是重列车位,则前面的车位,一定是空闲的 /// </summary> /// <param name="etv"></param> /// <returns></returns> public Location AllocateLocOfEtvScope(Device etv, string checkcode) { CWLocation cwlctn = new CWLocation(); CWDevice cwdevice = new CWDevice(); CWTask cwtask = new CWTask(); CWICCard cwiccd = new CWICCard(); List<Device> nEtvList = cwdevice.FindList(d => d.Type == EnmSMGType.ETV); WorkScope workscope = new WorkScope(nEtvList); CScope scope = workscope.GetEtvScope(etv); int etvColmn = Convert.ToInt32(etv.Address.Substring(1, 2)); List<Location> allLocsLst = cwlctn.FindLocList(); List<Customer> fixCustLst = cwiccd.FindCustList(cu => cu.Type == EnmICCardType.FixedLocation || cu.Type == EnmICCardType.VIP); //排除固定车位 List<Location> suitLocsLst = allLocsLst.FindAll(lc => fixCustLst.Exists(cc => cc.LocAddress == lc.Address && cc.Warehouse == lc.Warehouse) == false); var queryLstsmall = from loc in suitLocsLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkcode) == 1 && cwiccd.FindFixLocationByAddress(loc.Warehouse, loc.Address) == null orderby Math.Abs(loc.LocColumn - etvColmn) ascending, loc.LocSide ascending select loc; List<Location> priorLocsLst = new List<Location>(); List<Location> nextLocsLst = new List<Location>(); foreach (Location loc in queryLstsmall) { if (loc.LocColumn >= scope.LeftCol && loc.LocColumn <= scope.RightCol) { #region if (loc.LocSide == 2) { #region 如果后边的车位在作业,则最后分配 string bckAddrs = "4" + loc.Address.Substring(1); Location back = cwlctn.FindLocation(l => l.Address == bckAddrs); if (back != null) { if (back.Type == EnmLocationType.Normal) { if (back.Status == EnmLocationStatus.Space) { priorLocsLst.Add(loc); } else { nextLocsLst.Add(loc); } } else if (back.Type == EnmLocationType.Disable) { priorLocsLst.Add(loc); } } #endregion } else if (loc.LocSide == 4) { #region 如果是重列,则前面的车位一定是空闲的 string fwdAddrs = "2" + loc.Address.Substring(1); Location forward = cwlctn.FindLocation(l => l.Address == fwdAddrs); if (forward != null) { if (forward.Type == EnmLocationType.Normal && forward.Status == EnmLocationStatus.Space) { priorLocsLst.Add(loc); } } #endregion } else if (loc.LocSide == 1) { priorLocsLst.Add(loc); } #endregion } } if (priorLocsLst.Count > 0) { return priorLocsLst[0]; } if (nextLocsLst.Count > 0) { return nextLocsLst[0]; } var queryLstbig = from loc in suitLocsLst where loc.Type == EnmLocationType.Normal && loc.Status == EnmLocationStatus.Space && compareSize(loc.LocSize, checkcode) > 1 && cwiccd.FindFixLocationByAddress(loc.Warehouse, loc.Address) == null orderby Math.Abs(loc.LocColumn - etvColmn) ascending, loc.LocSide ascending select loc; List<Location> priorLocsLstbig = new List<Location>(); List<Location> nextLocsLstbig = new List<Location>(); foreach (Location loc in queryLstbig) { if (loc.LocColumn >= scope.LeftCol && loc.LocColumn <= scope.RightCol) { #region if (loc.LocSide == 2) { #region 如果后边的车位在作业,则最后分配 string bckAddrs = "4" + loc.Address.Substring(1); Location back = cwlctn.FindLocation(l => l.Address == bckAddrs); if (back != null) { if (back.Type == EnmLocationType.Normal) { if (back.Status == EnmLocationStatus.Space) { priorLocsLstbig.Add(loc); } else { nextLocsLstbig.Add(loc); } } else if (back.Type == EnmLocationType.Disable) { priorLocsLstbig.Add(loc); } } #endregion } else if (loc.LocSide == 4) { #region 如果是重列,则前面的车位一定是空闲的 string fwdAddrs = "2" + loc.Address.Substring(1); Location forward = cwlctn.FindLocation(l => l.Address == fwdAddrs); if (forward != null) { if (forward.Type == EnmLocationType.Normal && forward.Status == EnmLocationStatus.Space) { priorLocsLstbig.Add(loc); } } #endregion } else if (loc.LocSide == 1) { priorLocsLstbig.Add(loc); } #endregion } } if (priorLocsLstbig.Count > 0) { return priorLocsLstbig[0]; } if (nextLocsLstbig.Count > 0) { return nextLocsLstbig[0]; } return null; }
public LocStatInfo GetLocStatisInfo() { int total = 0; int occupy = 0; int space = 0; int fix = 0; int bspace = 0; int sspace = 0; try { CWICCard cwiccd = new CWICCard(); List <Location> locLst = new CWLocation().FindLocList(); List <Customer> custsLst = cwiccd.FindCustList(cu => cu.Type == EnmICCardType.FixedLocation || cu.Type == EnmICCardType.VIP); for (int i = 0; i < locLst.Count; i++) { Location loc = locLst[i]; #region if (loc.Type != EnmLocationType.Hall && loc.Type != EnmLocationType.Invalid) { total++; } bool isFixLoc = false; if (custsLst.Exists(cc => cc.LocAddress == loc.Address && cc.Warehouse == loc.Warehouse)) { fix++; isFixLoc = true; } if (loc.Type == EnmLocationType.Normal) { if (loc.Status == EnmLocationStatus.Space) { if (!isFixLoc) { space++; if (loc.LocSize.Length == 3) { string last = loc.LocSize.Substring(2); if (last == "1") { sspace++; } else if (last == "2") { bspace++; } } } } else if (loc.Status == EnmLocationStatus.Occupy) { occupy++; } } #endregion } } catch (Exception ex) { Log log = LogFactory.GetLogger("GetLocStatisInfoAsync"); log.Error(ex.ToString()); } LocStatInfo info = new LocStatInfo(); info.Total = total; info.Occupy = occupy; info.Space = space; info.SmallSpace = sspace; info.BigSpace = bspace; info.FixLoc = fix; return(info); }