111
lss
5 天以前 79db8fda0f71b65dfe1e1c72f307b29efc565126
HH.WCS.Mobox3 - ´ó³µ¼ä/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs
@@ -296,6 +296,128 @@
        }
        /// <summary>
        /// ç‚¹å¯¹ç‚¹ä»»åŠ¡åˆ›å»º
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        internal static Result CreatTask(CreatTask model)
        {
            Result result = new Result() { code = "200", msg = "点对点任务创建成功" };
            string Source = "MES";
            if (model == null)
            {
                result.code = "1";
                result.msg = "参数为null";
                AddErrorInfo("参数为空", result.msg, Source);
                return result;
            }
            string Start = ""; //取货点
            var db = new SqlHelper<object>().GetInstance();
            //   string CntrCode = model.partData.rfid;//托盘编码
            // string ItemCode = model.partData.partNumber;//物料编码
            string End = "";
            string CntrCode = "";
            Location endloc = new Location();
            Location startloc = new Location();
            try
            {
                startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == model.InitialLocation).First();
                if (startloc != null)
                {
                    Start = model.InitialLocation;
                }
                else
                {
                    result.code = "1";
                    result.msg = $"根据起点{model.InitialLocation},找不到对应货位,请检查货位表";
                    AddErrorInfo("货位查找失败", result.msg, Source);
                    return result;
                }
                endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == model.TargetLocation).First();
                if (endloc != null)
                {
                    End = model.TargetLocation;
                }
                else
                {
                    result.code = "1";
                    result.msg = $"根据终点{model.TargetLocation},找不到对应货位,请检查货位表";
                    AddErrorInfo("货位查找失败", result.msg, Source);
                    return result;
                }
                #region åˆ›å»ºä»»åŠ¡
                if (!string.IsNullOrEmpty(Start) && !string.IsNullOrEmpty(End))
                {
                    if (startloc.N_LOCK_STATE != 0)
                    {
                        result.code = "1";
                        result.msg = $"创建任务失败,起点{Start}有锁";
                        AddErrorInfo("货位有锁", result.msg);
                        return result;
                    }
                    //创建wcs任务
                    var wcsTask = new WCSTask
                    {
                        S_CODE = WCSHelper.GenerateTaskNo(),
                        // S_TYPE = model.taskData.taskType.ToString(),
                        //  S_EQ_NO = model.taskData.taskNum,
                        S_START_LOC = Start,
                        S_END_LOC = End,
                        N_CNTR_COUNT = 1,
                        S_START_WH = startloc.S_WH_CODE,
                        S_START_AREA = startloc.S_AREA_CODE,
                        S_END_WH = endloc.S_WH_CODE,
                        S_END_AREA = endloc.S_AREA_CODE,
                        N_SCHEDULE_TYPE = 1,
                        S_CNTR_CODE = CntrCode,
                        N_START_LAYER = 1,
                        N_END_LAYER = 1,
                        N_PRIORITY = 1,
                        //  N_TYPE = n_type
                    };
                    LogHelper.Info("创建任务:" + JsonConvert.SerializeObject(wcsTask), "CreateTask");
                    if (WCSHelper.CreateTask(wcsTask))
                    {
                        //LocationHelper.LockLoc(Start, 2);
                        //LocationHelper.LockLoc(End, 1);
                        LogHelper.Info("创建任务成功");
                    }
                    else
                    {
                        result.code = "1";
                        result.msg = $"任务创建失败";
                        AddErrorInfo("任务创建失败", result.msg, Source);
                        return result;
                    }
                }
                else
                {
                    result.code = "1";
                    result.msg = "创建任务失败,未找到对应的取货点或卸货点";
                    return result;
                }
                #endregion
                return result;
            }
            catch (Exception ex)
            {
                result.code = "1";
                result.msg = $"物料主数据创建失败 é”™è¯¯ä¿¡æ¯ï¼š{ex}";
                LogHelper.Error("点对点任务 Error:" + ex.ToString(), ex);
                return result;
            }
        }
        public static object _Point = new object();
        /// <summary>