lss
2025-06-20 b2c070eaf8cc59b40d27bda904312d0c394a51f4
HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/api/ApiHelper.cs
@@ -143,6 +143,7 @@
        private static object lockObj = new object();
        /// <summary>
        /// 创建任务
        /// </summary>
@@ -167,7 +168,6 @@
            {
                try
                {
                    // 1 空托回库
                    if (model.TaskType == "1")
                    {
@@ -200,7 +200,8 @@
                        #endregion
                        #region 计算立库终点
                        endloc = LocationHelper.InStorage(startloc);
                        endloc = LocationHelper.InStorage("");
                        if (endloc == null)
                        {
                            result.Code = -1;
@@ -208,6 +209,65 @@
                            LogHelper.Info($"creattask:{result.Msg}");
                            return result;
                        }
                        #endregion
                        #region 创建作业
                        if (startloc != null && endloc != null)
                        {
                            //创建作业
                            var wcsTask = new WMSTask
                            {
                                S_CODE = WMSHelper.GenerateTaskNo(),
                                S_TYPE = Type,
                                N_TYPE = int.Parse(model.TaskType),
                                S_START_LOC = start,
                                S_END_LOC = endloc.S_CODE,
                                S_CNTR_CODE = cntrcode,
                                S_END_WH = endloc.S_WH_CODE,
                                S_START_WH = startloc.S_WH_CODE,
                                S_START_AREA = startloc.S_AREA_CODE,
                                S_END_AREA = endloc.S_AREA_CODE,
                            };
                            LogHelper.Info("创建作业:" + JsonConvert.SerializeObject(wcsTask), "CreateTask");
                            if (WMSHelper.CreateTask(wcsTask))
                            {
                                LocationHelper.LockLoc(startloc.S_CODE, 2);
                                LocationHelper.LockLoc(endloc.S_CODE, 1);
                                LogHelper.Info("创建作业成功");
                                //空托回库成功,如果存在物料数据,删除
                                var itemcntr = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == cntrcode).First();
                                if (itemcntr != null) { db.Deleteable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == cntrcode).ExecuteCommand(); }
                                LogHelper.Info("创建任务成功");
                            }
                        }
                        #endregion
                    }
                    // 2 出库
                    if (model.TaskType == "2")
                    {
                        Type = "出库";
                        #region 获取终点信息
                        startloc = LocationHelper.GetLoc(model.endBit);
                        if (startloc == null)
                        {
                            result.Code = -1;
                            result.Msg = $"根据终点:{model.startBit}未找到货位信息";
                            LogHelper.Info($"creattask:{result.Msg}");
                            return result;
                        }
                        #endregion
                        #region 根据物料计算出库托盘,先进先出,优先出外侧
                        //先计算内侧货位,判断是否有单组托盘
                        var locations = LocationHelper.GetLocByItemCodeOrderyTime("", model.ItemCode);
                        if (locations.Count > 0)
                        {
                            endloc = locations.OrderBy(a => a.N_COL).First();
                        }
                        #endregion
                        #region 创建作业
@@ -247,8 +307,6 @@
                        return result;
                    }
                    return result;
                }
                catch (Exception ex)
@@ -280,6 +338,7 @@
            Location endloc = new Location();
            Location startloc = new Location();
            string cntrcode = model.CntrNo;
            // string itemCode = "";
            var db = new SqlHelper<object>().GetInstance();
            if (model.DeviceNo == "1")//叠盘机
@@ -311,7 +370,8 @@
                #endregion
                #region 计算立库终点
                endloc = LocationHelper.InStorage(startloc);
                endloc = LocationHelper.InStorage("");
                if (endloc == null)
                {
                    result.Code = -1;
@@ -376,7 +436,16 @@
                    #endregion
                    #region 计算立库终点
                    endloc = LocationHelper.InStorage(startloc);
                    //获取托盘物料绑定关系
                    var cntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE == model.CntrNo).First();
                    if (cntrItem == null)
                    {
                        result.Code = -1;
                        result.Msg = $"根据托盘:{model.CntrNo}未找到物料信息";
                        LogHelper.Info($"EquipmentInfo:{result.Msg}");
                        return result;
                    }
                    endloc = LocationHelper.InStorage(cntrItem.S_ITEM_CODE);
                    if (endloc == null)
                    {
                        result.Code = -1;
@@ -496,6 +565,53 @@
            return result;
        }
        internal static Result<ReseltApplyDestModel> ApplyDest(ApplyDestModel model)
        {
            Result<ReseltApplyDestModel> result = new Result<ReseltApplyDestModel> { Code = 0, Msg = "创建成功" };
            if (model == null)
            {
                result.Code = -1;
                result.Msg = "入参为空";
                return result;
            }
            var db = new SqlHelper<object>().GetInstance();
            string ItemCode = "";
            var task = WCSHelper.GetTask(model.TaskNo);
            if (task != null)
            {
                //根据任务托盘获取物料信息
                var cntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE == task.S_CNTR_CODE).First();
                if (cntrItem != null)
                {
                    ItemCode = cntrItem.S_ITEM_CODE;
                }
                var endloc = LocationHelper.InStorage(ItemCode);
                if (endloc != null) {
                    result.Data = new ReseltApplyDestModel() { Loc = endloc.S_CODE };
                }
                else
                {
                    result.Code = -1;
                    result.Msg = "当前没有可用终点可以分配";
                    return result;
                }
            }
            else
            {
                result.Code = 1;
                result.Msg = "任务不存在";
                return result;
            }
            return result;
        }
        /// <summary>
        /// 获取托盘物料信息
        /// </summary>