| | |
| | | using NLog.Fluent; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading; |
| | | using System.Threading.Tasks; |
| | | using static HH.WCS.JiaTong.dispatch.NDC; |
| | | |
| | |
| | | "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", |
| | | "U", "V", "W", "X", "Y", "Z" |
| | | }; |
| | | |
| | | /// <summary> |
| | | /// 根据物料找托盘 |
| | | /// </summary> |
| | |
| | | /// <param name="lev">物料等级</param> |
| | | /// <param name="ItemCode">物料编码</param> |
| | | /// <returns></returns> |
| | | internal static List<Location> GetLocByItemCode(string areaCode, string ItemCode, string lev) |
| | | internal static List<Location> GetLocByItemCode(string areaCode, string ItemCode, string lev, string powderType) |
| | | { |
| | | |
| | | List<Location> locs; |
| | | |
| | | |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var queryable = db.Queryable<Location>() |
| | | .LeftJoin<LocCntrRel>((a, b) => a.S_CODE == b.S_LOC_CODE) |
| | |
| | | //.Skip(targetIndex) // 跳过高于目标等级的等级 |
| | | //.ToList(); |
| | | |
| | | LogHelper.Info($"GetLocByItemCode=>根据库区编码:{areaCode},物料编码:{ItemCode},物料优先级:{lev},物料等级计算出有托盘货位{JsonConvert.SerializeObject(queryable.ToList())}"); |
| | | LogHelper.Info($"GetLocByItemCode=>根据库区编码:{areaCode},物料编码:{ItemCode},物料优先级:{lev},机台型号:{powderType},物料等级计算出有托盘货位{JsonConvert.SerializeObject(queryable.ToList())}"); |
| | | //判断需不需要物料等级查找,并优先出库余料 |
| | | if (string.IsNullOrEmpty(lev)) |
| | | { |
| | |
| | | { |
| | | locs = queryable.Where((a, b, c) => c.LEV == lev && c.S_BS_TYPE == "余料").ToList(); |
| | | } |
| | | LogHelper.Info($"GetLocByItemCode=>查找余料,{JsonConvert.SerializeObject(locs)}"); |
| | | if (string.IsNullOrEmpty(powderType)) |
| | | { |
| | | locs = queryable.Where((a, b, c) => c.S_BS_TYPE == "余料").ToList(); |
| | | } |
| | | else |
| | | { |
| | | locs = queryable.Where((a, b, c) => (c.S_FLTYPE == powderType||string.IsNullOrEmpty(c.S_FLTYPE)) && c.S_BS_TYPE == "余料").ToList(); |
| | | } |
| | | |
| | | //没有余料则寻找全部物料 |
| | | if (locs.Count == 0) |
| | |
| | | queryable = db.Queryable<Location>() |
| | | .LeftJoin<LocCntrRel>((a, b) => a.S_CODE == b.S_LOC_CODE) |
| | | .LeftJoin<CntrItemDetail>((a, b, c) => b.S_CNTR_CODE == c.S_CNTR_CODE) |
| | | .Where((a, b, c) => a.N_CURRENT_NUM > 0 && a.N_LOCK_STATE == 0 && a.S_AREA_CODE == areaCode); |
| | | .Where((a, b, c) => a.N_CURRENT_NUM > 0 && a.N_LOCK_STATE == 0 && a.S_AREA_CODE == areaCode ); |
| | | //六位码匹配前六位,其他的全部配置 |
| | | if (ItemCode.Trim().Length == 6) |
| | | { |
| | |
| | | } |
| | | LogHelper.Info($"GetLocByItemCode=>无余料,查找全部{JsonConvert.SerializeObject(queryable.ToList())}"); |
| | | |
| | | |
| | | |
| | | if (string.IsNullOrEmpty(lev)) |
| | | { |
| | | locs = queryable.ToList(); |
| | |
| | | else |
| | | { |
| | | locs = queryable.Where((a, b, c) => c.LEV == lev).ToList(); |
| | | } |
| | | if (string.IsNullOrEmpty(powderType)) |
| | | { |
| | | locs = queryable.ToList(); |
| | | } |
| | | else |
| | | { |
| | | locs = queryable.Where((a, b, c) => c.S_FLTYPE == powderType || string.IsNullOrEmpty(c.S_FLTYPE)).ToList(); |
| | | } |
| | | LogHelper.Info($"GetLocByItemCode=>无余料,查找全部{JsonConvert.SerializeObject(locs)}"); |
| | | } |
| | |
| | | /// 根据库区获取空托 |
| | | /// </summary> |
| | | /// <param name="areaCode">库区编码</param> |
| | | /// <param name="lev">物料等级</param> |
| | | /// <param name="ItemCode">物料编码</param> |
| | | /// <returns></returns> |
| | | internal static Location GetLocByAreacode(string areaCode) |
| | | internal static Location GetLocByAreacode(string areaCode, string type) |
| | | { |
| | | Location loc = new Location(); |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | string CntrCodeWith = ""; |
| | | if (type.Trim().Contains("MA")) |
| | | { |
| | | CntrCodeWith = "MA"; |
| | | } |
| | | else if (type.Trim().Contains("NA")) |
| | | { |
| | | CntrCodeWith = "NA"; |
| | | } |
| | | if (CntrCodeWith == "") |
| | | { |
| | | LogHelper.Info($"托盘类型{type}不在规定范围"); |
| | | } |
| | | var query = db.Queryable<Location>() |
| | | .LeftJoin<LocCntrRel>((a, b) => a.S_CODE == b.S_LOC_CODE) |
| | | .LeftJoin<CntrItemDetail>((a, b, c) => b.S_CNTR_CODE == c.S_CNTR_CODE) |
| | | .Where((a, b, c) => a.S_AREA_CODE == areaCode && a.N_CURRENT_NUM == 1 |
| | | && a.N_LOCK_STATE == 0 |
| | | && b.S_CNTR_CODE != null |
| | | ); |
| | | .LeftJoin<LocCntrRel>((a, b) => a.S_CODE == b.S_LOC_CODE) |
| | | .LeftJoin<CntrItemDetail>((a, b, c) => b.S_CNTR_CODE == c.S_CNTR_CODE) |
| | | .Where((a, b, c) => a.S_AREA_CODE == areaCode && a.N_CURRENT_NUM == 1 |
| | | && a.N_LOCK_STATE == 0 |
| | | && b.S_CNTR_CODE != null && b.S_CNTR_CODE.Contains(CntrCodeWith) && c.S_ITEM_CODE == null |
| | | ); |
| | | loc = query.First(); |
| | | |
| | | |
| | | return loc; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 分配电梯货位 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | internal static Location GetElevatorLoc() |
| | | { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | Location location = new Location(); |
| | | //查找全部电梯,分配任务最少的电梯 |
| | | var devices = Settings.deviceInfos.Where(a => a.deviceType == 2 && a.enable == 1).ToList(); |
| | | string[] state = new string[] { "执行中", "开始取货", "取货完成" }; |
| | | Dictionary<int, string> dics = new Dictionary<int, string>(); |
| | | foreach (var deviceInfo in devices) |
| | | { |
| | | int mst = db.Queryable<WCSTask>().Where(a => a.S_TYPE.Contains("电梯") && state.Contains(a.S_B_STATE) && a.S_END_LOC == deviceInfo.TN_Location).Count(); |
| | | dics.Add(mst, deviceInfo.TN_Location); |
| | | } |
| | | if (dics.Count > 0) |
| | | { |
| | | var dic = dics.OrderBy(a => a.Key).First(); |
| | | location = db.Queryable<Location>().Where(a => a.S_CODE == dic.Value).First(); |
| | | if (location == null) |
| | | { |
| | | LogHelper.Info($"根据货位编码:{dic.Value},未找到对应货位"); |
| | | } |
| | | } |
| | | return location; |
| | | } |
| | | /// <summary> |
| | | /// 根据物料编码,仓库编码获取托盘数量 |
| | | /// </summary> |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据货位集合获取 没有容器 没有锁的货位 |
| | | /// 根据货位获取货位信息 |
| | | /// </summary> |
| | | /// <param name="loc"></param> |
| | | /// <returns></returns> |
| | | internal static List<Location> GetLocListEmptyFree(List<string> loc) |
| | | internal static Location GetLocByLoc(string loc) |
| | | { |
| | | //1.0 查货位容器表 |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var list = db.Queryable<Location>().Where(a => loc.Contains(a.S_CODE) && a.N_CURRENT_NUM == 0 && a.S_LOCK_STATE.Trim() == "无").ToList(); |
| | | var list = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == loc).First(); |
| | | return list; |
| | | |
| | | } |
| | |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info($"锁定货位{loc}成功"); |
| | | LogHelper.Info($"锁定货位{loc}失败,重新锁"); |
| | | Task.Run(() => |
| | | { |
| | | LockLoc(loc, lockState); |
| | | }); |
| | | } |
| | | return res; |
| | | } |
| | |
| | | var location = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == loc).First(); |
| | | try |
| | | { |
| | | LogHelper.Info($"BindingLoc:开始解绑容器:{JsonConvert.SerializeObject(cntrs)}"); |
| | | db.BeginTran(); |
| | | var lcrList = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == loc).ToList(); |
| | | //if (!string.IsNullOrEmpty(location.S_NOTE) && lcrList.Count > 0) |
| | | //{ |
| | | // if (location.S_NOTE == "叠盘" || location.S_NOTE.Trim() == "片胶堆叠位") |
| | | // { |
| | | // LogHelper.Info("叠盘货位删除托盘"); |
| | | // cntrs = lcrList.Select(a => a.S_CNTR_CODE).ToList(); |
| | | |
| | | // } |
| | | //} |
| | | if (lcrList.Count > 0) |
| | | { |
| | | cntrs = lcrList.Select(a => a.S_CNTR_CODE).ToList(); |
| | | } |
| | | var count = db.Deleteable<LocCntrRel>().Where(it => cntrs.Contains(it.S_CNTR_CODE.Trim()) && it.S_LOC_CODE.Trim() == loc).ExecuteCommand(); |
| | | location.N_CURRENT_NUM = lcrList.Count - count; |
| | | location.S_LOCK_STATE = "无"; |
| | | location.N_LOCK_STATE = 0; |
| | | db.Updateable(location).UpdateColumns(it => new { it.N_CURRENT_NUM, it.S_LOCK_STATE, it.N_LOCK_STATE }).ExecuteCommand(); |
| | | LogHelper.Info($"BindingLoc:解绑容器:{JsonConvert.SerializeObject(cntrs)}成功"); |
| | | db.CommitTran(); |
| | | res = true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogHelper.Info($"BindingLoc Error:{ex}"); |
| | | db.RollbackTran(); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 库位清空 |
| | | /// </summary> |
| | | /// <param name="loc"></param> |
| | | /// <param name="cntrs"></param> |
| | | /// <returns></returns> |
| | | public static bool Clear(string loc, List<string> cntrs) |
| | | { |
| | | var res = false; |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | |
| | | try |
| | | { |
| | | var location = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == loc).First(); |
| | | if (location == null) |
| | | { |
| | | LogHelper.Info($"Clear:货位:{loc}货位表查询错误,请假查货位表"); |
| | | return res; |
| | | } |
| | | LogHelper.Info($"Clear:开始解绑容器:{JsonConvert.SerializeObject(cntrs)}"); |
| | | db.BeginTran(); |
| | | var lcrList = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == loc).ToList(); |
| | | if (lcrList.Count > 0) |
| | | { |
| | | cntrs = lcrList.Select(a => a.S_CNTR_CODE).ToList(); |
| | | } |
| | | var count = db.Deleteable<LocCntrRel>().Where(it => cntrs.Contains(it.S_CNTR_CODE.Trim()) && it.S_LOC_CODE.Trim() == loc).ExecuteCommand(); |
| | | LogHelper.Info($"Clear:开始删除容器:{JsonConvert.SerializeObject(cntrs)}"); |
| | | db.Deleteable<Container>().Where(it => cntrs.Contains(it.S_CODE)).ExecuteCommand(); |
| | | |
| | | location.N_CURRENT_NUM = lcrList.Count - count; |
| | | location.S_LOCK_STATE = "无"; |
| | | location.N_LOCK_STATE = 0; |
| | | db.Updateable(location).UpdateColumns(it => new { it.N_CURRENT_NUM, it.S_LOCK_STATE, it.N_LOCK_STATE }).ExecuteCommand(); |
| | | LogHelper.Info($"Clear:开始删除容器物料:{JsonConvert.SerializeObject(cntrs)}"); |
| | | var CntrItem = db.Queryable<CntrItemDetail>().Where(a => cntrs.Contains(a.S_CNTR_CODE.Trim())).First(); |
| | | if (CntrItem != null) |
| | | { |
| | | db.Deleteable<CntrItemDetail>().Where(it => cntrs.Contains(it.S_CNTR_CODE)).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info($"Clear=》托盘:{JsonConvert.SerializeObject(cntrs)}无物料数据"); |
| | | |
| | | } |
| | | LogHelper.Info($"BindingLoc:解绑容器:{JsonConvert.SerializeObject(cntrs)}成功"); |
| | | db.CommitTran(); |
| | | res = true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogHelper.Info($"BindingLoc Error:{ex}"); |
| | | db.RollbackTran(); |
| | | } |
| | | return res; |
| | | } |
| | | /// <summary> |
| | | /// 解锁货位,删除货位托盘 |
| | | /// </summary> |
| | | /// <param name="loc"></param> |
| | | /// <returns></returns> |
| | | public static bool UnlockLocDeleteCntrs(string loc) |
| | | { |
| | | var res = false; |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | List<string> cntrs = null; int count = 0; |
| | | var location = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == loc).First(); |
| | | try |
| | | { |
| | | db.BeginTran(); |
| | | var lcrList = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == loc).ToList(); |
| | | if (lcrList.Count > 0) |
| | | { |
| | | cntrs = lcrList.Select(a => a.S_CNTR_CODE).ToList(); |
| | | LogHelper.Info($"UnlockLocDeleteCntrs:货位{loc}:查询绑定托盘{cntrs}"); |
| | | LogHelper.Info($"UnlockLocDeleteCntrs:开始删除容器:{JsonConvert.SerializeObject(cntrs)}"); |
| | | count = db.Deleteable<LocCntrRel>().Where(it => cntrs.Contains(it.S_CNTR_CODE.Trim()) && it.S_LOC_CODE.Trim() == loc).ExecuteCommand(); |
| | | |
| | | } |
| | | |
| | | location.N_CURRENT_NUM = lcrList.Count - count; |
| | | location.S_LOCK_STATE = "无"; |
| | | location.N_LOCK_STATE = 0; |
| | | db.Updateable(location).UpdateColumns(it => new { it.S_LOCK_STATE, it.N_LOCK_STATE, it.N_CURRENT_NUM }).ExecuteCommand(); |
| | | db.CommitTran(); |
| | | res = true; |
| | | } |
| | |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 解锁货位 |
| | | /// </summary> |