lss
2025-06-18 83109bffe17f4cf877bb9546065723835a3c6b7d
HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs
@@ -38,12 +38,12 @@
        public static object _lockCreateTask = new object();
        public static object _lockCreateItem = new object();
        /// <summary>
        /// 立库任务下发=》创建任务
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        internal static Result Createtask(CreateTask model)
        {
            Result result = new Result() { code = "0", msg = "创建成功" };
@@ -170,7 +170,7 @@
                        if (startloc != null)
                        {
                            Start = startloc.S_CODE;
                            var CntrRel = LocationHelper.GetLocCntrRel(startloc.S_CODE).FirstOrDefault();
                            var CntrRel = LocationHelper.GetLocCntrRel(startloc.S_CODE).OrderBy(a => a.T_CREATE).FirstOrDefault();
                            if (CntrRel != null)
                            {
                                if (CntrRel.S_CNTR_CODE!= partData.rfid)
@@ -693,23 +693,63 @@
            try
            {
                string[] state = new string[] { "取消", "失败", "错误", "完成" };
                if (model.type == "1")
                {
                //找到任务
                var task = db.Queryable<WCSTask>().Where(a => a.S_EQ_NO.Trim() == model.task_no && !state.Contains(a.S_B_STATE)).First();
                if (task != null)
                    var task = db.Queryable<WCSTask>().Where(a => a.S_START_LOC.Trim() == model.loc && !state.Contains(a.S_B_STATE)).ToList();
                    if (task.Count > 0)
                {
                    if (model.type == "1" || model.type == "2")
                        foreach (var item in task)
                    {
                        NDCApi.ChangeOrderParam(task.S_CODE.Trim(), 6, "1");
                            var taskAction = db.Queryable<TaskAction>().Where(a => a.S_TASK_CODE == item.S_CODE).OrderByDescending(a => a.T_CREATE).First();
                            if (taskAction.N_ACTION_CODE == 1101)
                            {
                                NDCApi.ChangeOrderParam(item.S_CODE.Trim(), 6, "1");
                                return result;
                    }
                            result.code = "1";
                            result.msg = $"根据下发货位{model.loc}未找到对应申请取货状态任务";
                            AddErrorInfo("未找到任务", result.msg, "", model.task_no);
                            return result;
                        }
                }
                else
                {
                    result.code = "1";
                    result.msg = $"根据下发任务号{model.task_no}未找到对应任务";
                        result.msg = $"根据下发货位{model.loc}未找到对应任务";
                    AddErrorInfo("未找到任务", result.msg, "", model.task_no);
                    return result;
                }
                }
                else if (model.type == "2")
                {
                    //找到任务
                    var task = db.Queryable<WCSTask>().Where(a => a.S_END_LOC.Trim() == model.loc && !state.Contains(a.S_B_STATE)).ToList();
                    if (task.Count > 0)
                    {
                        foreach (var item in task)
                        {
                            var taskAction = db.Queryable<TaskAction>().Where(a => a.S_TASK_CODE == item.S_CODE).OrderByDescending(a => a.T_CREATE).First();
                            if (taskAction.N_ACTION_CODE == 1103)
                            {
                                NDCApi.ChangeOrderParam(item.S_CODE.Trim(), 6, "1");
                                return result;
                            }
                        }
                        result.code = "1";
                        result.msg = $"根据下发货位{model.loc}未找到对应申请卸货状态任务";
                        AddErrorInfo("未找到任务", result.msg, "", model.task_no);
                        return result;
                    }
                    else
                    {
                        result.code = "1";
                        result.msg = $"根据下发货位{model.loc}未找到对应任务";
                        AddErrorInfo("未找到任务", result.msg, "", model.task_no);
                        return result;
                    }
                }
                return result;
            }
            catch (Exception ex)
@@ -729,6 +769,7 @@
        /// <returns></returns>
        internal static Result TrayItembind(TrayItembind model)
        {
            Result result = new Result() { code = "200", msg = "产出信息下发成功" };
            if (model == null)
            {
@@ -737,8 +778,11 @@
                AddErrorInfo("参数为空", result.msg);
                return result;
            }
            lock (_lockCreateItem)
            {
            try
            {
                //创建托盘数据绑定关系
                if (ContainerHelper.CreateCntrItem(model.Rfid, model.PartNumber, model.PartDesc, model.LotNumber, model.Weight, model.Qty, model.ProductionTime, model.MaturityTime))
                {
@@ -760,6 +804,8 @@
                LogHelper.Error("TrayItembind Error:" + ex.ToString(), ex);
                return result;
            }
            }
        }
@@ -874,13 +920,8 @@
                        return result;
                    }
                    //判断有无相同物料排
                    loc = StorageCompute(itemcode, areacode);
                    //if (loc == null)
                    //{
                    //    //无相同物料排找空排
                    //    loc = emptyRow(areacode);
                    //}
                    if (loc != null)
                    {
                        End = loc.S_CODE;
@@ -1219,7 +1260,7 @@
                        if (startloc.N_LAYER == 3)
                        {
                            //叠盘货位计算叠盘货位
                            var dploc = db.Queryable<Location>().Where(a => a.S_NOTE.Trim() == "叠盘" && a.N_LAYER == startloc.N_LAYER && a.S_WH_CODE.Trim() == startloc.S_WH_CODE).ToList();
                            var dploc = db.Queryable<Location>().Where(a => a.S_NOTE.Trim() == "叠盘" && a.N_LAYER == startloc.N_LAYER && a.S_WH_CODE.Trim() == startloc.S_WH_CODE && a.C_ENABLE == "Y").ToList();
                            if (dploc.Count > 0)
                            {
                                // LogHelper.Info($"获取叠盘货位:{JsonConvert.SerializeObject(dploc)}");
@@ -1250,7 +1291,7 @@
                        else if (startloc.S_NOTE == "PB")
                        {
                            //找块胶堆叠区
                            var KjDploc = db.Queryable<Location>().Where(a => a.S_NOTE.Trim() == "片胶堆叠位" && a.S_WH_CODE.Trim() == startloc.S_WH_CODE).ToList();
                            var KjDploc = db.Queryable<Location>().Where(a => a.S_NOTE.Trim() == "片胶堆叠位" && a.S_WH_CODE.Trim() == startloc.S_WH_CODE && a.C_ENABLE == "Y").ToList();
                            if (KjDploc.Count > 0)
                            {
                                loc = KjDploc.FindAll(a => a.N_LOCK_STATE == 0 && a.N_CURRENT_NUM < 6).OrderByDescending(a => a.N_CURRENT_NUM).FirstOrDefault();
@@ -1644,7 +1685,7 @@
                    }
                    else
                    {
                        if (db.Updateable(new LocCntrRel() { S_CNTR_CODE = model.Rfid, S_LOC_CODE = Start }).UpdateColumns().ExecuteCommand() <= 0)
                        if (db.Insertable(new LocCntrRel() { S_CNTR_CODE = model.Rfid, S_LOC_CODE = Start }).ExecuteCommand() <= 0)
                        {
                            result.code = "1";
                            result.msg = $"创建任务失败,托盘:{model.Rfid}绑定货位{Start}失败";
@@ -1703,7 +1744,6 @@
                            {
                                //loc =  EndLocs.Find(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0);
                                loc = FindEndcolByLocList(EndLocs);
                            }
                            else
@@ -2094,7 +2134,7 @@
                var startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == model.Data.start_loc_code).First();
                var endloc = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == model.Data.end_loc_code && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0).First();
                var endloc = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == model.Data.end_loc_code && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.C_ENABLE == "Y").First();
                //判断楼层是否相等,如果不相同需要生成分段任务进行电梯调用
@@ -2298,6 +2338,8 @@
            }
            string loc = model.LocationNum;
            var db = new SqlHelper<object>().GetInstance();
            lock (_lockCreateItem)
            {
            try
            {
                var location = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == loc).First();
@@ -2346,6 +2388,9 @@
                return result;
            }
            }
            return result;
        }
@@ -2542,7 +2587,7 @@
        internal static Location StorageCompute(string itemcode, string areacode)
        {
            var db = new SqlHelper<object>().GetInstance();
            Location result = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.S_AREA_CODE.Trim() == areacode && a.N_LOCK_STATE == 0).First();
            Location result = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.S_AREA_CODE.Trim() == areacode && a.N_LOCK_STATE == 0 && a.C_ENABLE == "Y").First();
            //查询所有有托盘的排没锁的排
            // var list = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM > 0 && a.S_AREA_CODE.Trim() == areacode && a.N_LOCK_STATE == 0).OrderByDescending(a => a.N_COL).Take(1).PartitionBy(a => a.N_ROW).ToList();
            // if (list.Count > 0)
@@ -2739,7 +2784,7 @@
            lock (_lockLocation)
            {
                var loc = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.S_NOTE == cntrType && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "无").First();
                var loc = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.S_NOTE == cntrType && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "无" && a.C_ENABLE == "Y").First();
                if (loc != null)
                {
                    End = loc;
@@ -2812,7 +2857,7 @@
                        Location other = null;
                        //当前排没有锁并且有空位置
                        //先找满位,然后后面一层要么是空,要么不存在
                        other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0).FirstOrDefault();
                        other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.C_ENABLE == "Y").FirstOrDefault();
                        //if (full == null)
                        //{
                        //    //没有满位,那就找最小的空位