| | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | loc = StorageCompute(itemcode, areacode); |
| | | |
| | | if (loc != null) |
| | |
| | | { |
| | | lock (_lockEmpty) |
| | | { |
| | | #region 判断托盘绑定货位是否和下发绑定起点相同 |
| | | //var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First(); |
| | | //if (CntrLoc != null) |
| | | //{ |
| | | // if (CntrLoc.S_LOC_CODE != Start) |
| | | // { |
| | | // LogHelper.Info($"ItemBack:创建任务失败,托盘:{model.Rfid}绑定位置不是起点:{Start}"); |
| | | // result.code = "1"; |
| | | // result.msg = $"创建任务失败,托盘:{model.Rfid}绑定位置不是起点:{Start}"; |
| | | // AddErrorInfo("托盘绑定位置不同", result.msg); |
| | | // return result; |
| | | // } |
| | | //} |
| | | //else |
| | | //{ |
| | | // LogHelper.Info($"ItemBack:创建任务失败,托盘:{model.Rfid}未找到绑定货位"); |
| | | // result.code = "1"; |
| | | // result.msg = $"创建任务失败,托盘:{model.Rfid}未找到绑定货位"; |
| | | // AddErrorInfo("查找托盘货位失败", result.msg); |
| | | // return result; |
| | | //} |
| | | #endregion |
| | | |
| | | |
| | | #region 根据货位楼层判断,3楼去往叠盘位 其他的回库 |
| | | var startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == Start).First(); |
| | | if (startloc != null) |
| | | { |
| | | if (startloc.N_LAYER == 3) |
| | | if (!string.IsNullOrEmpty(startloc.S_NOTE1)) |
| | | { |
| | | //叠盘货位计算叠盘货位 |
| | | // var dploc = db.Queryable<Location>().Where(a => a.S_NOTE.Trim() == "叠盘" && a.N_LAYER == startloc.N_LAYER && a.S_WH_CODE.Trim() == startloc.S_WH_CODE && a.C_ENABLE == "Y").ToList(); |
| | | var dploc = db.Queryable<Location>().Where(a => a.S_NOTE1.Trim() == startloc.S_NOTE1 + "叠盘" && a.S_WH_CODE.Trim() == startloc.S_WH_CODE).ToList(); |
| | | if (dploc.Count > 0) |
| | | { |
| | | // LogHelper.Info($"获取叠盘货位:{JsonConvert.SerializeObject(dploc)}"); |
| | | loc = dploc.FindAll(a => a.N_LOCK_STATE == 0 && a.N_CURRENT_NUM < 6).OrderByDescending(a => a.N_CURRENT_NUM).FirstOrDefault(); |
| | | if (loc == null) |
| | | { |
| | | LogHelper.Info($"{startloc.S_NOTE1}叠盘位,都已经有锁或者已经叠满,请检查货位状态"); |
| | | result.code = "1"; |
| | | result.msg = $"{startloc.S_NOTE1}叠盘货位不可用,终点库区没有可用货位,请检查锁状态和数量"; |
| | | AddErrorInfo("查找库区失败", result.msg, Source); |
| | | return result; |
| | | } |
| | | else |
| | | { |
| | | endlayer = loc.N_CURRENT_NUM + 1; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // LogHelper.Info($"根据货位楼层:{startloc.N_LAYER},仓库编码:{startloc.S_WH_CODE},货位备注:叠盘,未找到叠盘货位"); |
| | | result.code = "1"; |
| | | result.msg = $"{startloc.S_NOTE1}叠盘货位不可用,未找到可叠盘货位"; |
| | | LogHelper.Info($"根据货位备注:{startloc.S_NOTE1}叠盘,货位仓库:{startloc.S_WH_CODE},找不到叠盘货位"); |
| | | AddErrorInfo("查找货位失败", result.msg, Source); |
| | | return result; |
| | | } |
| | | } |
| | | else if (startloc.N_LAYER == 3) |
| | | { |
| | | //叠盘货位计算叠盘货位 |
| | | // var dploc = db.Queryable<Location>().Where(a => a.S_NOTE.Trim() == "叠盘" && a.N_LAYER == startloc.N_LAYER && a.S_WH_CODE.Trim() == startloc.S_WH_CODE && a.C_ENABLE == "Y").ToList(); |
| | |
| | | loc = StorageCompute(itemcode, areacode); |
| | | if (loc == null) |
| | | { |
| | | loc = emptyRow(areacode); |
| | | if (loc == null) |
| | | { |
| | | result.code = "1"; |
| | | result.msg = $"库区:{areacode}没有可用货位"; |
| | | LogHelper.Info($" {result.msg}"); |
| | | AddErrorInfo("查找库区失败", result.msg, Source); |
| | | // LogHelper.Info($"库区:{areacode}没有可用货位"); |
| | | } |
| | | |
| | | result.code = "1"; |
| | | result.msg = $"库区:{areacode}没有可用货位"; |
| | | LogHelper.Info($" {result.msg}"); |
| | | AddErrorInfo("查找库区失败", result.msg, Source); |
| | | return result; |
| | | // LogHelper.Info($"库区:{areacode}没有可用货位"); |
| | | |
| | | } |
| | | //else |
| | | //{ |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region 创建任务 |
| | | #region 创建任务 |
| | | if (startloc != null && loc != null) |
| | | { |
| | | if (startloc.N_LOCK_STATE != 0 && loc.N_LOCK_STATE != 0) |
| | |
| | | AddErrorInfo("货位有锁", result.msg); |
| | | return result; |
| | | } |
| | | LogHelper.Info("创建空托回库任务,终点货位为空:" + JsonConvert.SerializeObject(loc)); |
| | | //创建wcs任务 |
| | | var wcsTask = new WCSTask |
| | | { |
| | |
| | | lock (_lockItemBack) |
| | | { |
| | | |
| | | |
| | | |
| | | #region 判断托盘绑定货位是否和下发绑定起点相同 |
| | | var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First(); |
| | | if (CntrLoc != null) |
| | |
| | | } |
| | | else |
| | | { |
| | | |
| | | result.code = "1"; |
| | | result.msg = $"创建任务失败,物料号{model.PartNumber}不属于规定物料"; |
| | | LogHelper.Info($"ItemBack:{result.msg}"); |
| | |
| | | /// <returns></returns> |
| | | internal static Location StorageCompute(string itemcode, string areacode) |
| | | { |
| | | //Location result = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.S_AREA_CODE.Trim() == areacode && a.N_LOCK_STATE == 0).First(); |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | // Location result = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.S_AREA_CODE.Trim() == areacode && a.N_LOCK_STATE == 0 ).First(); |
| | | Location result = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.S_AREA_CODE.Trim() == areacode && a.N_LOCK_STATE == 0 && a.C_ENABLE == "Y").First(); |
| | | //查询所有有托盘的排没锁的排 |
| | | // var list = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM > 0 && a.S_AREA_CODE.Trim() == areacode && a.N_LOCK_STATE == 0).OrderByDescending(a => a.N_COL).Take(1).PartitionBy(a => a.N_ROW).ToList(); |
| | | // if (list.Count > 0) |
| | | //{ |
| | | // for (int i = 0; i < list.Count; i++) |
| | | // { |
| | | // LogHelper.Info($"有托盘排号{list[i].N_ROW},物料编码{itemcode},库区{areacode}"); |
| | | // //查询货位绑定托盘 |
| | | // var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == list[i].S_CODE).First(); |
| | | // if (cntr != null) |
| | | // { |
| | | // //查询托盘物料信息 |
| | | // var iteminfo = ContainerHelper.GetCntrItemRel(cntr.S_CNTR_CODE).FirstOrDefault(); |
| | | Location result = null; |
| | | // 867C567A-183C-413B-9891-15D8F6DE1620 |
| | | |
| | | // if (string.IsNullOrEmpty(itemcode))//空托入库 |
| | | // { |
| | | // if (iteminfo == null) |
| | | // { |
| | | // //物料相同入货位后一位货位 |
| | | // result = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => a.S_AREA_CODE.Trim() == areacode && a.N_ROW == list[i].N_ROW && a.N_COL > list[i].N_COL && a.N_LOCK_STATE == 0 && a.N_CURRENT_NUM == 0).First(); |
| | | // } |
| | | // } |
| | | // else//满拖入库 |
| | | // { |
| | | // if (iteminfo != null) |
| | | // { |
| | | // if (iteminfo.S_ITEM_CODE == itemcode) |
| | | // { |
| | | // //物料相同入货位后一位货位 |
| | | // result = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => a.S_AREA_CODE.Trim() == areacode && a.N_ROW == list[i].N_ROW && a.N_COL > list[i].N_COL && a.N_LOCK_STATE == 0 && a.N_CURRENT_NUM == 0).First(); |
| | | // var aaa = db.Deleteable<Location>(a => a.S_ID == "867C567A-183C-413B-9891-15D8F6DE1620").ExecuteCommand(); |
| | | // var aaa = db.Deleteable<Location>(a => a.S_ID.Trim() == "867C567A-183C-413B-9891-15D8F6DE1620").ExecuteCommand(); |
| | | LogHelper.Info($"方法:StorageCompute"); |
| | | var list = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.S_AREA_CODE == areacode && a.N_LOCK_STATE == 0 && a.N_ROW > 0 && a.N_COL > 0).ToList(); |
| | | LogHelper.Info($"创建空托回库任务,终点货位集合:根据库区编码:{areacode}" + list.Count); |
| | | //list.RemoveAll(a => string.IsNullOrEmpty(a.S_CODE.Trim()) || a.S_CODE == null || string.IsNullOrWhiteSpace(a.S_CODE.Trim())); |
| | | list = list.FindAll(a => a.N_ROW > 0 && a.N_COL > 0); |
| | | LogHelper.Info("创建空托回库任务,终点货位集合过滤:" + list.Count); |
| | | if (list.Count > 0) |
| | | { |
| | | result = FindEndcolByLocList(list); |
| | | } |
| | | |
| | | // } |
| | | // } |
| | | // } |
| | | // if (result != null) |
| | | // { |
| | | // return result; |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // LogHelper.Info($"根据货物编码{list[i].S_CODE}未找到托盘货位绑定关系"); |
| | | // } |
| | | // } |
| | | //} |
| | | return result; |
| | | } |
| | | |
| | |
| | | var rows = locations.Select(a => a.N_ROW).Distinct().ToList(); |
| | | for (int i = 0; i < rows.Count; i++) |
| | | { |
| | | |
| | | var rowList = locations.Where(r => r.N_ROW == rows[i]).ToList(); |
| | | LogHelper.Info($"当前排:{rows[i]},获得货位{JsonConvert.SerializeObject(rowList)}"); |
| | | if (rowList.Count(a => a.N_CURRENT_NUM == 0) > 0) |
| | | { |
| | | Location other = null; |
| | | //当前排没有锁并且有空位置 |
| | | //先找满位,然后后面一层要么是空,要么不存在 |
| | | /// other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.C_ENABLE == "Y").FirstOrDefault(); |
| | | other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0).FirstOrDefault(); |
| | | |
| | | // other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.C_ENABLE == "Y").FirstOrDefault(); |
| | | other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && !string.IsNullOrEmpty(a.S_CODE.Trim()) && !string.IsNullOrWhiteSpace(a.S_CODE.Trim())).FirstOrDefault(); |
| | | //if (full == null) |
| | | //{ |
| | | // //没有满位,那就找最小的空位 |
| | |
| | | // other = db.Queryable<Location>().OrderBy(a => a.N_LAYER).Where(a => (string.IsNullOrEmpty(a.C_ENABLE) || a.C_ENABLE.Trim() != "禁用") && a.S_AREA_CODE == other.S_AREA_CODE && a.N_ROW == other.N_ROW && a.N_COL > other.N_COL).First(); |
| | | // //LogHelper.Info($"禁用选择后一个货位{result}", "成品"); |
| | | //} |
| | | |
| | | if (other != null) |
| | | { |
| | | if (other.S_CODE != null && !string.IsNullOrEmpty(other.S_CODE)) |
| | | { |
| | | end = other; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return end; |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 找终点空货位计算排锁 |
| | | /// </summary> |
| | | /// <param name="locations"></param> |
| | | /// <returns></returns> |
| | | internal static Location FindEndcolByLocListLock(List<Location> locations) |
| | | { |
| | | try |
| | | { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | Location end = null; |
| | | //根据终点货位找空闲货位 |
| | | var rows = locations.Select(a => a.N_ROW).Distinct().ToList(); |
| | | for (int i = 0; i < rows.Count; i++) |
| | | { |
| | | var rowList = locations.Where(r => r.N_ROW == rows[i]).ToList(); |
| | | if (rowList.Count(a => a.S_LOCK_STATE != "无") == 0 && rowList.Count(a => a.N_CURRENT_NUM == 0) > 0) |
| | | { |
| | | Location other = null; |
| | | //当前排没有锁并且有空位置 |
| | | //先找满位,然后后面一位要么是空,要么不存在 |
| | | var full = rowList.OrderByDescending(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 1).FirstOrDefault(); |
| | | if (full == null) |
| | | { |
| | | //没有满位,那就找最小的空位 |
| | | other = rowList.OrderBy(a => a.N_COL).FirstOrDefault(); |
| | | } |
| | | else |
| | | { |
| | | other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_COL > full.N_COL).FirstOrDefault(); |
| | | } |
| | | |
| | | if (other != null) |
| | | { |
| | | end = other; |