| | |
| | | { |
| | | site = Location.S_AGV_SITE; |
| | | } |
| | | //if (Location.N_CURRENT_NUM == 1) |
| | | //{ |
| | | // site = Location.S_AGV_SITE2; |
| | | //} |
| | | //if (Location.N_CURRENT_NUM == 2) |
| | | //{ |
| | | // site = Location.S_AGV_SITE3; |
| | | //} |
| | | //if (Location.N_CURRENT_NUM == 3) |
| | | //{ |
| | | // site = Location.S_AGV_SITE4; |
| | | //} |
| | | //if (Location.N_CURRENT_NUM == 4) |
| | | //{ |
| | | // site = Location.S_AGV_SITE5; |
| | | //} |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | return db.Queryable<TN_Location>().Where(a => a.S_CODE.Trim() == code).First(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 起点出库锁(只能对无锁货位上锁) |
| | | /// </summary> |
| | | /// <param name="loc"></param> |
| | | /// <param name="lockSource"></param> |
| | | /// <returns></returns> |
| | | public static bool LockStartLoc(ref TN_Location loc, string lockSource = "") { |
| | | if (loc == null) { |
| | | LogHelper.Info($"起点出库锁:传入的货位参数为null"); |
| | | return false; |
| | | } |
| | | |
| | | if (loc.N_LOCK_STATE != 0 || loc.S_LOCK_STATE != "无") { |
| | | LogHelper.Info($"起点出库锁:货位当前已有锁({loc.N_LOCK_STATE},{loc.S_LOCK_STATE})"); |
| | | return false; |
| | | } |
| | | |
| | | if (loc != null && loc.N_LOCK_STATE == 0) { |
| | | loc.N_LOCK_STATE = 2; // 起点出库锁 |
| | | loc.S_LOCK_STATE = GetLockStateStr(2); // 起点出库锁 |
| | | loc.S_LOCK_OP = lockSource; |
| | | loc.T_MODIFY = System.DateTime.Now; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 终点入库锁(只能对无锁货位上锁) |
| | | /// </summary> |
| | | /// <param name="loc"></param> |
| | | /// <param name="lockSource"></param> |
| | | /// <returns></returns> |
| | | public static bool LockEndLoc(ref TN_Location loc, string lockSource = "") { |
| | | if (loc == null) { |
| | | LogHelper.Info($"终点入库锁:传入的货位参数为null"); |
| | | return false; |
| | | } |
| | | |
| | | if (loc.N_LOCK_STATE != 0 || loc.S_LOCK_STATE != "无") { |
| | | LogHelper.Info($"终点入库锁:货位当前已有锁({loc.N_LOCK_STATE},{loc.S_LOCK_STATE})"); |
| | | return false; |
| | | } |
| | | |
| | | if (loc != null && loc.N_LOCK_STATE == 0) { |
| | | loc.N_LOCK_STATE = 1; // 终点出库锁 |
| | | loc.S_LOCK_STATE = GetLockStateStr(1); // 终点出库锁 |
| | | loc.S_LOCK_OP = lockSource; |
| | | loc.T_MODIFY = System.DateTime.Now; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private static string GetLockStateStr(int lockState) { |
| | | var str = ""; |
| | | switch (lockState) { |
| | | case 0: str = "无"; break; |
| | | case 1: str = "入库锁"; break; |
| | | case 2: str = "出库锁"; break; |
| | | case 3: str = "其它锁"; break; |
| | | } |
| | | return str; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 构建货位查询表达式:当前锁状态、数量、货区、名称(默认筛选已启用货位) |
| | | /// </summary> |
| | | /// <param name="db">调用区域的数据库Client</param> |
| | | /// <param name="lockState">锁状态,默认为0,小于0时不筛选</param> |
| | | /// <param name="curNum">当前数量,默认为-1,小于0时不筛选</param> |
| | | /// <param name="areas">所在库区列表,默认为null,为null或为空时不筛选</param> |
| | | /// <param name="name">货位名称,默认为null,为null或为空时不筛选</param> |
| | | /// <returns></returns> |
| | | public static ISugarQueryable<TN_Location> Query(SqlSugarClient db, int lockState = 0, int curNum = -1, List<string> areas = null, string name = null) { |
| | | var query = db.Queryable<TN_Location>().Where(l => l.C_ENABLE == "Y"); // 已启用 |
| | | |
| | | if (lockState >= 0) { |
| | | query = query.Where(l => l.N_LOCK_STATE == lockState && l.S_LOCK_STATE == GetLockStateStr(lockState)); |
| | | } |
| | | if (curNum >= 0) { |
| | | query = query.Where(l => l.N_CURRENT_NUM == curNum); |
| | | } |
| | | if (areas != null && areas.Count == 0) { |
| | | query = query.Where(l => areas.Contains(l.S_AREA_CODE)); |
| | | } |
| | | if (!string.IsNullOrEmpty(name)) { |
| | | query = query.Where(l => l.S_CODE == name); |
| | | } |
| | | |
| | | return query; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 构建货位查询的要求信息 |
| | | /// </summary> |
| | | /// <param name="lockState"></param> |
| | | /// <param name="curNum"></param> |
| | | /// <param name="areas"></param> |
| | | /// <returns></returns> |
| | | public static string Require(int lockState = 0, int curNum = -1, List<string> areas = null) { |
| | | var res = "货位要求:"; |
| | | var index = 1; |
| | | if (lockState >= 0) { |
| | | res += $"({index})锁状态='{GetLockStateStr(lockState)}';"; |
| | | index++; |
| | | } |
| | | if (curNum >= 0) { |
| | | res += $"({index})当前容器数量={curNum};"; |
| | | index++; |
| | | } |
| | | if (areas != null && areas.Count != 0) { |
| | | res += $"({index})所在库区=['{string.Join("','", areas)}'];"; |
| | | index++; |
| | | } |
| | | |
| | | return res; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <param name="loc"></param> |
| | | /// <param name="cntrs"></param> |
| | | /// <returns></returns> |
| | | public static string UnBindingLoc(string loc, List<string> cntrs) |
| | | public static string UnbindLocCntr(string loc, List<string> cntrs) |
| | | { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var logs = $"货位:{loc},容器:{JsonConvert.SerializeObject(cntrs)}"; |
| | | try |
| | | { |
| | | var lcrList = db.Queryable<TN_Loc_Container>().Where(a => cntrs.Contains(a.S_CNTR_CODE) && a.S_LOC_CODE == loc).ToList(); |
| | | if (lcrList.Count == 0) |
| | | { |
| | | if (lcrList.Count == 0) { |
| | | LogHelper.Info($"货位无需解绑容器,在数据库中未找到{JsonConvert.SerializeObject(cntrs)}相关的货位容器关系表信息"); |
| | | } |
| | | cntrs = lcrList.Select(a => a.S_CNTR_CODE).ToList(); |
| | |
| | | location.S_LOCK_STATE = "无"; |
| | | location.N_LOCK_STATE = 0; |
| | | |
| | | //var containerList = new List<TN_Container>(); |
| | | //foreach (var item in lcrList) { |
| | | // // 针对容器类型添加的新逻辑 |
| | | // var cntr = db.Queryable<TN_Container>() |
| | | // .Where(c => c.S_CODE == item.S_CNTR_CODE).First(); |
| | | // if (cntr == null) { |
| | | // LogHelper.Info($"货位解绑时,容器{item.S_CNTR_CODE}没有在容器信息表中查到,这里根据货位容器关系添加"); |
| | | // containerList.Add(new TN_Container { |
| | | // S_CODE = item.S_CNTR_CODE, |
| | | // S_TYPE = item.S_CNTR_TYPE, |
| | | // }); |
| | | // } |
| | | //} |
| | | |
| | | using (var tran = db.Ado.UseTran()) |
| | | { |
| | | //if (containerList.Count > 0) { |
| | | // if (db.Insertable<TN_Container>(containerList).ExecuteCommand() <= 0) { |
| | | // LogHelper.Info($"插入容器信息表失败" + JsonConvert.SerializeObject(containerList)); |
| | | // tran.RollbackTran(); |
| | | // return "货位解绑容器失败," + logs; |
| | | // } |
| | | //} |
| | | |
| | | if (db.Deleteable<TN_Loc_Container>().Where(it => cntrs.Contains(it.S_CNTR_CODE) && it.S_LOC_CODE == loc).ExecuteCommand() > 0) |
| | | { |
| | | LogHelper.Info($"删除货位容器关系表成功,{log}"); |
| | |
| | | } |
| | | |
| | | log = JsonConvert.SerializeObject(location); |
| | | if (db.Updateable(location).UpdateColumns(it => new { it.N_CURRENT_NUM, it.S_LOCK_STATE, it.N_LOCK_STATE }).ExecuteCommand() > 0) |
| | | { |
| | | if (db.Updateable(location).UpdateColumns(it => new { it.N_CURRENT_NUM, it.S_LOCK_STATE, it.N_LOCK_STATE }).ExecuteCommand() > 0) { |
| | | tran.CommitTran(); |
| | | |
| | | LogHelper.Info($"更新货位表成功,{log}"); |
| | | } |
| | | else |
| | | { |
| | | else { |
| | | tran.RollbackTran(); |
| | | |
| | | LogHelper.Info($"更新货位表失败,{log}"); |
| | |
| | | var logs = $"货位:{loc},容器:{JsonConvert.SerializeObject(cntrs)}"; |
| | | try |
| | | { |
| | | // 删除已经绑定过的容器记录 |
| | | var lcrList = db.Queryable<TN_Loc_Container>().Where(a => cntrs.Contains(a.S_CNTR_CODE) && a.S_LOC_CODE == loc).ToList(); |
| | | |
| | | if (lcrList.Count > 0) |
| | | { |
| | | if (lcrList.Count > 0) { |
| | | cntrs = cntrs.Except(lcrList.Select(a => a.S_CNTR_CODE).ToList()).ToList(); |
| | | } |
| | | |
| | | var bindLocCntList = new List<TN_Loc_Container>(); |
| | | foreach (var item in cntrs) |
| | | { |
| | | foreach (var item in cntrs) { |
| | | // 针对容器类型添加的新逻辑 |
| | | var cntr = db.Queryable<TN_Container>() |
| | | .Where(c => c.S_CODE == item) |
| | | .First(); |
| | | var cntr = db.Queryable<TN_Container>().Where(c => c.S_CODE == item).First(); |
| | | |
| | | if (cntr == null) { |
| | | LogHelper.Info($"货位解绑时,容器{item}没有在容器信息表中查到,不记录容器类型"); |
| | |
| | | |
| | | using (var tran = db.Ado.UseTran()) |
| | | { |
| | | if (db.Insertable<TN_Loc_Container>(bindLocCntList).ExecuteCommand() > 0) |
| | | { |
| | | LogHelper.Info($"插入货位容器关系表成功,{log}"); |
| | | } |
| | | else |
| | | { |
| | | if (db.Insertable(bindLocCntList).ExecuteCommand() <= 0) { |
| | | db.RollbackTran(); |
| | | LogHelper.Info($"插入货位容器关系表失败,{log}"); |
| | | return "货位绑定容器失败," + logs; |
| | | } |
| | | LogHelper.Info($"插入货位容器关系表成功,{log}"); |
| | | |
| | | var location = db.Queryable<TN_Location>().First(a => a.S_CODE == loc); |
| | | if (location != null) |