zxx
2025-05-31 267ffc1263e9975adf0d3dcca9ccc5d7dbd239f6
jushi
2个文件已修改
157 ■■■■ 已修改文件
HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WMSCore.cs 111 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs 46 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WMSCore.cs
@@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using static HH.WCS.JuShi.device.S7Helper;
@@ -284,35 +285,34 @@
                var reservoirs2 = Settings.ReservoirAreas.Where(s => s.areaName == "6min空托区").FirstOrDefault();
                var linePlcInfo1 = Settings.linePlcInfos.Where(s => s.deviceNo == "1").FirstOrDefault();
                var linePlcInfo2 = Settings.linePlcInfos.Where(s => s.deviceNo == "2").FirstOrDefault();
                //找到空托缓存区的所有货位编号
                var locList = db.Queryable<Location>()
                    .Where(s => s.S_AREA_CODE == reservoirs1.areaCode || s.S_AREA_CODE == reservoirs2.areaCode)
                    .Where(s => s.N_LOCK_STATE == 0)
                    .OrderByDescending(s => s.N_ROW).OrderByDescending(s => s.N_COL).OrderBy(s => s.N_LAYER)
                    .Select(s => s.S_CODE)
                    .ToList();
                ////找到空托缓存区的所有货位编号
                //var locList = db.Queryable<Location>()
                //    .Where(s => s.S_AREA_CODE == reservoirs1.areaCode || s.S_AREA_CODE == reservoirs2.areaCode)
                //    .Where(s => s.N_LOCK_STATE == 0)
                //    .OrderByDescending(s => s.N_ROW).OrderByDescending(s => s.N_COL).OrderBy(s => s.N_LAYER)
                //    .Select(s => s.S_CODE)
                //    .ToList();
                //找到绑了托盘的货位号
                var locCntrs = db.Queryable<LocCntrRel>()
                    .Where(s => locList.Contains(s.S_LOC_CODE.Trim()))
                    .Select(s => s.S_LOC_CODE)
                    .ToList();
                if (locCntrs.Any())
                //查询每排最后一列有托盘的货位  根据行分区 再找每一行的最后一列有货的货位
                var list = db.Queryable<Location>().
                    Where(a => a.N_CURRENT_NUM > 0 ).Where(a=> a.S_AREA_CODE.Trim() == reservoirs1.areaCode|| a.S_AREA_CODE.Trim() == reservoirs2.areaCode)
                    .PartitionBy(a => a.N_ROW)
                    .OrderByDescending(a => a.N_COL).Take(1).ToList();
                if (list.Count > 0)
                {
                    //LogHelper.Info($"空托缓存区有绑定货位:{JsonConvert.SerializeObject(locCntrs)}");
                    //var loccode = locCntrs.First();
                    foreach (var loccode in locCntrs)
                    for (int i = 0; i < list.Count; i++)
                    {
                        var loc = db.Queryable<Location>().Where(s => s.S_CODE == loccode).First();
                        //var loc = list[i];
                        //判断送往3寸还是6寸拆托机
                        string endLoc = null;
                        string dev = null;
                        if (loc.S_AREA_CODE == reservoirs1.areaCode)
                        if (list[i].S_AREA_CODE == reservoirs1.areaCode)
                        {
                            endLoc = linePlcInfo1.inLoca;
                            dev = "1";
                        }
                        else if (loc.S_AREA_CODE == reservoirs2.areaCode)
                        else if (list[i].S_AREA_CODE == reservoirs2.areaCode)
                        {
                            endLoc = linePlcInfo2.inLoca;
                            dev = "2";
@@ -329,17 +329,17 @@
                        if ((plcDeviceTable.requestPut1 && dev == "1") ||
                            (plcDeviceTable.requestPut2 && dev == "2"))
                        {
                            var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == loccode).First();
                            var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == list[i].S_CODE).First();
                            LogHelper.Info($"创建任务 起点:{loccode}终点:{endLoc}");
                            var res = TaskProcess.CreateTransport(loccode, endLoc, "送托", locCntrRel.S_CNTR_CODE, 1, 1);
                            LogHelper.Info($"创建任务 起点:{list[i].S_CODE}终点:{endLoc}");
                            var res = TaskProcess.CreateTransport(list[i].S_CODE, endLoc, "送托", locCntrRel.S_CNTR_CODE, 1, 1);
                            if (res)
                            {
                                LogHelper.Info($"起点:{loccode}终点:{endLoc}任务创建成功");
                                LogHelper.Info($"起点:{list[i].S_CODE}终点:{endLoc}任务创建成功");
                            }
                            else
                            {
                                LogHelper.Info($"起点:{loccode}终点:{endLoc}任务创建失败");
                                LogHelper.Info($"起点:{list[i].S_CODE}终点:{endLoc}任务创建失败");
                            }
                        }
                        else
@@ -347,8 +347,69 @@
                            LogHelper.Info($"拆托机{endLoc}不允许放框");
                        }
                    }
                }
                ////找到绑了托盘的货位号
                //var locCntrs = db.Queryable<LocCntrRel>()
                //    .Where(s => locList.Contains(s.S_LOC_CODE.Trim()))
                //    .Select(s => s.S_LOC_CODE)
                //    .ToList();
                //if (locCntrs.Any())
                //{
                //    //LogHelper.Info($"空托缓存区有绑定货位:{JsonConvert.SerializeObject(locCntrs)}");
                //    //var loccode = locCntrs.First();
                //    foreach (var loccode in locCntrs)
                //    {
                //        var loc = db.Queryable<Location>().Where(s => s.S_CODE == loccode).First();
                //        //判断送往3寸还是6寸拆托机
                //        string endLoc = null;
                //        string dev = null;
                //        if (loc.S_AREA_CODE == reservoirs1.areaCode)
                //        {
                //            endLoc = linePlcInfo1.inLoca;
                //            dev = "1";
                //        }
                //        else if (loc.S_AREA_CODE == reservoirs2.areaCode)
                //        {
                //            endLoc = linePlcInfo2.inLoca;
                //            dev = "2";
                //        }
                //        var endLocation = db.Queryable<Location>().Where(s => s.S_CODE == endLoc).First();
                //        if (endLocation == null || endLocation.N_LOCK_STATE != 0)
                //        {
                //            //LogHelper.Info($"拆托机货位{endLoc}不存在或已被锁");
                //            return;
                //        }
                //        //校验是否允许放货
                //        var plcDeviceTable = S7Helper.plcDeviceTables;
                //        LogHelper.Info($"自动送托 拆托机{dev}:{plcDeviceTable.requestPut1}");
                //        if ((plcDeviceTable.requestPut1 && dev == "1") ||
                //            (plcDeviceTable.requestPut2 && dev == "2"))
                //        {
                //            var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == loccode).First();
                //            LogHelper.Info($"创建任务 起点:{loccode}终点:{endLoc}");
                //            var res = TaskProcess.CreateTransport(loccode, endLoc, "送托", locCntrRel.S_CNTR_CODE, 1, 1);
                //            if (res)
                //            {
                //                LogHelper.Info($"起点:{loccode}终点:{endLoc}任务创建成功");
                //            }
                //            else
                //            {
                //                LogHelper.Info($"起点:{loccode}终点:{endLoc}任务创建失败");
                //            }
                //        }
                //        else
                //        {
                //            LogHelper.Info($"拆托机{endLoc}不允许放框");
                //        }
                //    }
                //}
            }
            catch (Exception ex)
HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs
@@ -824,21 +824,51 @@
                    {
                        list.RemoveAll(s => loca.Contains(s.S_CODE));
                    }
                    //过滤一下 允许进入的才分配
                    var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "立库入库区").FirstOrDefault();
                    if (reservoirs.areaCode.Equals(area))
                    // 3. 如果是立库入库区,检查 PLC 是否允许卸载
                    var reservoirs = Settings.ReservoirAreas.FirstOrDefault(s => s.areaName == "立库入库区");
                    if (reservoirs != null && reservoirs.areaCode.Equals(area))
                    {
                        var plcDeviceTable = S7Helper.plcDeviceTables;
                        foreach (var l in list)
                        // 先收集要移除的货位,避免在遍历时修改集合
                        List<Location> locationsToRemove = new List<Location>();
                        foreach (var location in list)
                        {
                            var safeInteraction = Settings.SafeInteractions.Where(s => s.location == l.S_CODE).FirstOrDefault();
                            var res = int.Parse(plcDeviceTable.RGVAllowUnload[safeInteraction.code].ToString().Substring(1, 1));
                            if (res!=1)
                            var safeInteraction = Settings.SafeInteractions.FirstOrDefault(s => s.location == location.S_CODE);
                            if (safeInteraction != null)
                            {
                                list.Remove(l);
                                // 检查 PLC 是否允许卸载(取第二位数字,判断是否为 1)
                                string allowUnloadStr = plcDeviceTable.RGVAllowUnload[safeInteraction.code].ToString();
                                int allowUnload = int.Parse(allowUnloadStr.Substring(1, 1));
                                if (allowUnload != 1)
                                {
                                    locationsToRemove.Add(location); // 不允许卸载,加入待移除列表
                                }
                            }
                        }
                        // 遍历结束后,再统一移除不符合条件的货位
                        foreach (var locToRemove in locationsToRemove)
                        {
                            list.Remove(locToRemove);
                        }
                    }
                    ////过滤一下 允许进入的才分配
                    //var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "立库入库区").FirstOrDefault();
                    //if (reservoirs.areaCode.Equals(area))
                    //{
                    //    var plcDeviceTable = S7Helper.plcDeviceTables;
                    //    foreach (var l in list)
                    //    {
                    //        var safeInteraction = Settings.SafeInteractions.Where(s => s.location == l.S_CODE).FirstOrDefault();
                    //        var res = int.Parse(plcDeviceTable.RGVAllowUnload[safeInteraction.code].ToString().Substring(1, 1));
                    //        if (res!=1)
                    //        {
                    //            list.Remove(l);
                    //        }
                    //    }
                    //}
                    
                    //符合条件的排序选第一个  先找第一个