lss
3 天以前 9cba325e0d7c30644606e63e5df01faba0c42038
HH.WCS.Mobox3 - ´ó³µ¼ä/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs
@@ -104,7 +104,10 @@
                    case "YBK":
                        n_type = 2;
                        Source = "预备库";
                        state = "等待推送";
                        if (taskData.taskType == 1)
                        {
                            state = "等待推送";
                        }
                        break;
                }
@@ -242,7 +245,7 @@
        /// <returns></returns>
        internal static Result MstStateInquire(MstStateInquire model)
        {
            Result result = new Result() { code = "200", msg = "状态下发成功" };
            Result result = new Result() { code = "0", msg = "状态下发成功" };
            var db = new SqlHelper<object>().GetInstance();
            if (model == null)
            {
@@ -258,8 +261,21 @@
                var task = db.Queryable<WCSTask>().Where(a => a.S_EQ_NO.Trim() == model.taskNum).First();
                if (task != null)
                {
                    task.S_B_STATE ="等待";
                    db.Updateable(task).UpdateColumns(a => new { a.S_B_STATE}).ExecuteCommand();
                    if (task.S_B_STATE != "等待推送")
                    {
                        result.code = "1";
                        result.msg = $"推送失败,任务已经处理";
                        AddErrorInfo("推送失败", result.msg);
                        return result;
                    }
                    task.S_B_STATE = "等待";
                    if (db.Updateable(task).UpdateColumns(a => new { a.S_B_STATE }).ExecuteCommand() < 0)
                    {
                        result.code = "1";
                        result.msg = $"推送失败,修改任务状态失败,请重新下发";
                        AddErrorInfo("推送失败", result.msg);
                        return result;
                    }
                }
                else
                {
@@ -280,6 +296,125 @@
        }
        /// <summary>
        /// ç‚¹å¯¹ç‚¹ä»»åŠ¡åˆ›å»º
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        internal static Result CreatTask(CreatTask model)
        {
            Result result = new Result() { code = "0", 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("创建任务成功");
                        return result;
                    }
                    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>
@@ -465,21 +600,22 @@
            RequestList<UploadLoc> result1 = new RequestList<UploadLoc>();
            List<UploadLoc> listuploadloc = new List<UploadLoc>();
            var db = new SqlHelper<object>().GetInstance();
            //获取时间戳
            var time = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
            result1.RequestId = "杭叉AGV" + time;
            result1.UseToken = "iFQ5fExGrLYLXliHYWzs";
            foreach (var item in model)
            {
                var loc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == item.Location).First();
                if (loc != null)
                {
                    UploadLoc upload = new UploadLoc();
                    //获取时间戳
                    var time = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
                    result1.RequestId = "杭叉AGV" + time;
                    result1.UseToken = "iFQ5fExGrLYLXliHYWzs";
                    upload.LocationNum = loc.S_CODE;
                    upload.Type = loc.S_TYPE;
                    upload.LockState = loc.S_LOCK_STATE;
                    upload.WorkCenter = loc.S_AREA_CODE;
                    upload.Warehouse = loc.S_AREA_CODE;
                    upload.locationNum = loc.S_CODE;
                    upload.type = loc.S_TYPE;
                    upload.lockState = loc.S_LOCK_STATE;
                    upload.workCenter = loc.S_AREA_CODE;
                    upload.warehouse = loc.S_AREA_CODE;
                    listuploadloc.Add(upload);
                }
                else