using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using HH.WCS.Mobox3.DSZSH.models; using HH.WCS.Mobox3.DSZSH.util; using Newtonsoft.Json; using static HH.WCS.Mobox3.DSZSH.api.ApiModel; using static HH.WCS.Mobox3.DSZSH.util.Config; namespace HH.WCS.Mobox3.DSZSH.wms { /// /// [ 具体业务 ] 帮助类 /// public class WMSHelper { /// /// 检查容器类型 ( 容器表 不存在 / 类型不匹配 时 , 返回 false ) /// /// /// /// /// public static (bool, string) CheckCntrType(string cntrCode, string cntrType, out TN_Container cntr) { var db = new SqlHelper().GetInstance(); cntr = db.Queryable().Where(c => c.S_CODE == cntrCode).First(); if (cntr == null) { return (false, $"容器'{cntrCode}'在[容器表]中不存在,请在前台页面中维护!!"); } if (cntr.S_TYPE != cntrType) { return (false, $"容器'{cntrCode}'在[容器表]中的类型为'{cntr.S_TYPE}',与当前流程所需容器类型'{cntrType}'不同!!"); } return (true, "检查容器类型成功!!"); } /// /// 根据容器号 , 查找旧的货位 / 货位绑定 / 物料信息 ( 将待删除 / 更新数据写入 obj ) /// /// /// /// /// /// public static LocCntrCg FindOldCntrInfo(CreateTaskObj obj, string cntrCode, bool skipCgDetail = true) { var oldLocCntrCg = WCSHelper.GetLocCntrCg(cntrCode, skipCgDetail); obj.Old = oldLocCntrCg; return oldLocCntrCg; } /// /// 绑定货位容器 ( 修改 [ 货位容器表 ] [ 货位类型 ] = cntrType ; 将 [ 待插入 ] 货位容器关系 加入到 obj 中 )
/// 调用 设置 loc.N_CURRENT_NUM = 1 ///
/// /// /// /// /// /// public static TN_Loc_Container BindLocCntr(CreateTaskObj obj, TN_Location loc, string cntrCode, string cntrType = "") { var locCntrRel = WCSHelper.BindLocCntr(loc, cntrCode); if (!string.IsNullOrEmpty(cntrType)) { locCntrRel.S_CNTR_TYPE = cntrType; } obj.New = new LocCntrCg { LocCntrRel = locCntrRel }; return locCntrRel; } /// /// 创建任务 ( 构造任务项 / 起点终点上锁 ; 将 插入任务 / 更新货位 的对象写入 obj ) /// /// /// /// /// /// /// /// /// public static TN_Task CreateTask(CreateTaskObj obj, TN_Location startLoc, TN_Location endLoc, string cntId, string type, int pri = 3, int agv = 1) { var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, type, pri); WCSHelper.LockStartLoc(startLoc, task.S_CODE); WCSHelper.LockEndLoc(endLoc, task.S_CODE); obj.TaskToInsert = task; obj.StartLocToUpdate = startLoc; obj.EndLocToUpdate = endLoc; return task; } private const bool __查询语句封装__ = false; // 仅用于分段,没有实质意义(VS2022 v17.4.3 文档大纲) #region 查询语句(搁置,设为私有,查询需求变更多,封装不够灵活) /// /// 查询 [ 绑定前 ] 的起点货位 /// /// /// /// /// /// private static (bool, string) FindStartLocUnbind(string locCode, List areas, out TN_Location startLoc) { var db = new SqlHelper().GetInstance(); startLoc = db.Queryable().Where(DbExpr.StartLocUnbind(locCode, areas)).First(); if (startLoc == null) { return (false, LogMsg.StartLocUnbindNotFound(locCode, areas)); } return (true, ""); } /// /// 查询 [ 绑定后 ] 的起点货位 /// /// /// /// /// /// private static (bool, string) FindStartLoc(string locCode, List areas, out TN_Location startLoc) { var db = new SqlHelper().GetInstance(); startLoc = db.Queryable().Where(DbExpr.StartLoc(locCode, areas)).First(); if (startLoc == null) { return (false, LogMsg.StartLocNotFound(locCode, areas)); } return (true, ""); } /// /// 查询终点货位 /// /// /// /// /// /// private static (bool, string) FindEndLoc(string locCode, List areas, out TN_Location endLoc) { var db = new SqlHelper().GetInstance(); endLoc = db.Queryable().Where(DbExpr.EndLoc(locCode, areas)).First(); if (endLoc == null) { return (false, LogMsg.EndLocNotFound(locCode, areas)); } return (true, ""); } #endregion } }