| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 起点出库锁(强制赋值,不会检查loc!=null,锁状态=无,需要传参前确认) |
| | | /// ![[弃用|理由:不灵活,涉及业务过于具体]]检查容器类型是否正确 |
| | | /// </summary> |
| | | /// <param name="cntrCode"></param> |
| | | /// <param name="cntrType"></param> |
| | | /// <param name="errMsg"></param> |
| | | /// <returns></returns> |
| | | private static bool CheckCntrType(string cntrCode, string cntrType, out string errMsg) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | errMsg = string.Empty; |
| | | |
| | | var cntr = db.Queryable<TN_Container>().Where(c => c.S_CODE == cntrType).First(); |
| | | if (cntr == null) { |
| | | errMsg = $"容器'{cntrCode}'在[容器表]中不存在,请在前台页面中维护!"; |
| | | return false; |
| | | } |
| | | if (cntr.S_TYPE != cntrType) { |
| | | errMsg = $"容器'{cntrCode}'在[容器表]中的类型是'{cntr.S_TYPE},不是'{cntrType}'!"; |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据容器号,查询当前容器关联的[货位/容器/物料]信息(只查询1条) |
| | | /// </summary> |
| | | /// <param name="cntrCode">容器号</param> |
| | | /// <param name="skipCgDetail">是否跳过[物料表]的查询(当容器号来自[物料表]时)</param> |
| | | /// <returns></returns> |
| | | public static LocCntrCg GetLocCntrCg(string cntrCode, bool skipCgDetail = false) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | |
| | | TN_CG_Detail cgDetail = null; |
| | | if (!skipCgDetail) { |
| | | cgDetail = db.Queryable<TN_CG_Detail>().Where(d => d.S_CNTR_CODE == cntrCode).First(); |
| | | } |
| | | |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>().Where(c => c.S_CNTR_CODE == cntrCode).First(); |
| | | |
| | | TN_Location location = null; |
| | | if (locCntrRel != null) { |
| | | location = db.Queryable<TN_Location>().Where(l => l.S_CODE == locCntrRel.S_LOC_CODE).First(); |
| | | if (location == null) { |
| | | LogHelper.Warn($""); |
| | | } |
| | | } |
| | | if (location != null) { |
| | | location.N_CURRENT_NUM = 0; |
| | | location.T_MODIFY = DateTime.Now; |
| | | } |
| | | |
| | | return new LocCntrCg { |
| | | CgDetail = cgDetail, |
| | | LocCntrRel = locCntrRel, |
| | | Location = location |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 绑定[货位-容器]信息 |
| | | /// </summary> |
| | | /// <param name="startLoc"></param> |
| | | /// <param name="cntrCode"></param> |
| | | /// <returns></returns> |
| | | public static TN_Loc_Container BindLocCntr(ref TN_Location startLoc, string cntrCode) { |
| | | var locCntrRel = new TN_Loc_Container { |
| | | S_LOC_CODE = startLoc.S_CODE, |
| | | S_CNTR_CODE = cntrCode, |
| | | }; |
| | | |
| | | startLoc.N_CURRENT_NUM = 1; |
| | | startLoc.T_MODIFY = DateTime.Now; |
| | | |
| | | return locCntrRel; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 起点出库锁 |
| | | /// </summary> |
| | | /// <param name="loc"></param> |
| | | /// <param name="lockSource"></param> |
| | | public static void LockStartLoc(ref TN_Location loc, string lockSource = "") { |
| | | if (loc == null) { |
| | | throw new ArgumentNullException(); // 接受货位loc为空时直接抛异常(通常不会发生) |
| | | } |
| | | |
| | | if (loc.N_LOCK_STATE != 0 || loc.S_LOCK_STATE != "无") { |
| | | LogHelper.Warn($"起点出库锁:程序正在尝试给当前[锁状态]不是'无'的货位上锁!货位='{loc.S_CODE}',锁状态=({loc.N_LOCK_STATE},{loc.S_LOCK_STATE})"); |
| | | } |
| | | |
| | | loc.N_LOCK_STATE = 2; // 起点出库锁 |
| | | loc.S_LOCK_STATE = TN_Location.GetLockStateStr(2); // 起点出库锁 |
| | | loc.S_LOCK_OP = lockSource; |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 终点入库锁(强制赋值,不会检查loc!=null,锁状态=无,需要传参前确认) |
| | | /// 终点入库锁 |
| | | /// </summary> |
| | | /// <param name="loc"></param> |
| | | /// <param name="lockSource"></param> |
| | | public static void LockEndLoc(ref TN_Location loc, string lockSource = "") { |
| | | if (loc == null) { |
| | | throw new ArgumentNullException(); // 接受货位loc为空时直接抛异常(通常不会发生) |
| | | } |
| | | |
| | | if (loc.N_LOCK_STATE != 0 || loc.S_LOCK_STATE != "无") { |
| | | LogHelper.Warn($"起点出库锁:程序正在尝试给当前[锁状态]不是'无'的货位上锁!货位='{loc.S_CODE}',锁状态=({loc.N_LOCK_STATE},{loc.S_LOCK_STATE})"); |
| | | } |
| | | |
| | | loc.N_LOCK_STATE = 1; // 终点出库锁 |
| | | loc.S_LOCK_STATE = TN_Location.GetLockStateStr(1); // 终点出库锁 |
| | | loc.S_LOCK_OP = lockSource; |
| | | loc.T_MODIFY = System.DateTime.Now; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 创建任务 |
| | | /// </summary> |
| | | /// <param name="startLoc">起点货位:至少提供:S_CODE,S_AREA_CODE</param> |
| | | /// <param name="endLoc">终点货位:至少提供:S_CODE,S_AREA_CODE</param> |
| | | /// <param name="cntId">容器号</param> |
| | | /// <param name="type">任务类型(名称)</param> |
| | | /// <param name="pri">优先级</param> |
| | | /// <param name="agvType">AGV类型</param> |
| | | /// <returns></returns> |
| | | public static TN_Task BuildTask(TN_Location startLoc, TN_Location endLoc, string cntId, string type, int pri = 3, int agvType = 1) { |
| | | TN_Task TN_Task = new TN_Task() { |
| | | S_CODE = GenerateTaskNo(), |
| | |
| | | S_TYPE = type, |
| | | N_PRIORITY = pri, |
| | | N_SCHEDULE_TYPE = agvType, |
| | | N_B_STATE = 0, // 任务创建时,默认等待 |
| | | N_B_STATE = 0, // 任务创建时,默认等待 |
| | | S_CNTR_CODE = cntId, |
| | | }; |
| | | |
| | | return TN_Task; |
| | | } |
| | | |
| | | |
| | | internal static bool CheckActionRecordExist(string no, int code) { |
| | | var db = new SqlHelper<TN_Task_Action>().GetInstance(); |
| | |
| | | internal static void Fail(TN_Task task) { |
| | | var db = new SqlHelper<TN_Task>().GetInstance(); |
| | | if (task != null) { |
| | | //判断有没有取货完成,没有就变成失败。有取货完成默认完成了(跟据项目而定,有些项目人工拉走了也没有放到终点)。 |
| | | //判断有没有取货完成,没有就变成失败。有取货完成默认完成了 (跟据项目而定,有些项目人工拉走了也没有放到终点) 。 |
| | | task.N_B_STATE = 4; |
| | | task.S_B_STATE = TN_Task.GetStateStr(task.N_B_STATE); |
| | | db.Updateable(task).UpdateColumns(it => new { it.N_B_STATE, it.S_B_STATE }).ExecuteCommand(); |
| | |
| | | return db.Queryable<TN_Task>().Where(a => a.N_B_STATE == 0 && (a.S_B_STATE == "等待" || a.S_B_STATE == "待推送")).ToList(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// [货位/容器/物料]信息 |
| | | /// </summary> |
| | | public class LocCntrCg { |
| | | public TN_CG_Detail CgDetail { get; set; } = null; |
| | | public TN_Loc_Container LocCntrRel { get; set; } = null; |
| | | public TN_Location Location { get; set; } = null; |
| | | } |
| | | } |