using System; using WIDESEA_Common.DBHelper; using WIDESEA_Common.EquipmentEnum; using WIDESEA_Entity.DomainModels; namespace WIDESEA_WCS.JobsPart.Public { public partial class WCSCommon { public static FreeDB freeDB = new FreeDB(); /// /// 获取起点或终点位置 /// /// 目的或来源地址 /// 放入缓存架或从缓存架取走 /// 提升机叫料物料类型 /// /// public static string GetAddress(string address, bool isIn = true, string type = "") { dt_stationinfo res = null; if (isIn) { //路由表配置了路由且当前没有任务 res = freeDB.Select() .Where(t => t.enable && t.getStatus == (int)StationEnum.Empty && t.getLastTime != null && (DateTime.Now - t.getLastTime).TotalSeconds <= 5) .Where(@"exists (select route_id from base_routing_table where route_began=@address and route_end=a.stationCode)", new { address }) .Where(@"not EXISTS ( SELECT address from ( (select agv_fromaddress address from dt_agvtask) UNION all (select agv_toaddress address from dt_agvtask) ) t where address=a.stationCode)") .OrderBy(t => t.sort) .ToOne(); } else { res = freeDB.Select() .Where(t => t.enable && t.getStatus == (int)StationEnum.Stroge && t.getLastTime != null && (DateTime.Now - t.getLastTime).TotalSeconds <= 5) .WhereIf(!string.IsNullOrEmpty(type), t => t.stationType == type) .Where(@"exists (select route_id from base_routing_table where route_end=@address and route_began=a.stationCode)", new { address }) .Where(@"not EXISTS ( SELECT address from ( (select agv_fromaddress address from dt_agvtask) UNION all (select agv_toaddress address from dt_agvtask) ) t where address=a.stationCode)") .OrderBy(t => t.lastUpdateTime) .ToOne(); } if (res == null) { throw new Exception("无可用缓存架"); } return res.stationCode; } } }