林豪 左 преди 2 години
родител
ревизия
5c627eba85

+ 0 - 0
WCS.WorkEngineering/Systems/湿拉满轮帘线芯股第一次扫码.cs → WCS.WorkEngineering/Systems/分拣主线/湿拉满轮帘线芯股第一次扫码.cs


+ 0 - 0
WCS.WorkEngineering/Systems/满轮主线预写入目标地址.cs → WCS.WorkEngineering/Systems/分拣主线/满轮主线预写入目标地址.cs


+ 1 - 1
WCS.WorkEngineering/Systems/桁架分流点.cs → WCS.WorkEngineering/Systems/分拣支线/桁架分流点.cs

@@ -14,7 +14,7 @@ namespace WCS.WorkEngineering.Systems
     /// <summary>
     ///  桁架分流点
     /// </summary>
-    [BelongTo(typeof(MainWorld))]
+    [BelongTo(typeof(SortingBranchWorld))]
     [Description("桁架分流点")]
     public class 桁架分流点 : DeviceSystem<Device<IStation520, IStation521, IStation523>>
     {

+ 201 - 0
WCS.WorkEngineering/Systems/分拣支线/环形库分流点.cs

@@ -0,0 +1,201 @@
+using ServiceCenter.Extensions;
+using ServiceCenter.Logs;
+using ServiceCenter.SqlSugars;
+using System.ComponentModel;
+using WCS.Core;
+using WCS.Entity;
+using WCS.WorkEngineering.Extensions;
+using WCS.WorkEngineering.Protocol.Station;
+using WCS.WorkEngineering.Worlds;
+using DeviceFlags = WCS.WorkEngineering.Extensions.DeviceFlags;
+using TaskStatus = WCS.Entity.TaskStatus;
+
+namespace WCS.WorkEngineering.Systems
+{
+    /// <summary>
+    ///  分流点
+    /// </summary>
+    [BelongTo(typeof(SortingBranchWorld))]
+    [Description("环形库分流点")]
+    public class 环形库分流点 : DeviceSystem<Device<IStation520, IStation521, IStation523, IStation91>>
+    {
+        protected override bool ParallelDo => true;
+
+        protected override bool SaveLogsToFile => true;
+
+        public override void Do(Device<IStation520, IStation521, IStation523, IStation91> obj)
+        {
+            if (obj.Data.VoucherNo != obj.Data2.VoucherNo) throw new KnownException($"凭证号不一致,DB520:{obj.Data.VoucherNo}-DB521:{obj.Data2.VoucherNo}", LogLevelEnum.High);
+            if (obj.Data3.Status.HasFlag(StationStatus.Run)) throw new KnownException("设备运行中", LogLevelEnum.Low);
+            if (!obj.Data3.Status.HasFlag(StationStatus.OT_Status)) throw new KnownException("站台货物信息与实际占用不一致", LogLevelEnum.Low);
+            if (obj.Data2.Request != 1) throw new KnownException("无请求", LogLevelEnum.Mid);
+
+            //处理异常任务
+            if (obj.Data2.TaskNumber == 1)
+            {
+                obj.Data.TaskNumber = 591;
+                obj.Data.GoodsStart = obj.Entity.Code.ToShort();
+                obj.Data.GoodsEnd = 591;
+                obj.Data.VoucherNo++;
+                World.Log($"执行记录:任务号[{591}]");
+            }
+
+            var isPut = false;
+            SqlSugarHelper.Do(_db =>
+            {
+                var db = _db.Default;
+                var taskInfo = db.Queryable<WCS_TaskInfo>().First(v => v.ID == obj.Data2.TaskNumber && v.Status == TaskStatus.WaitingToExecute) ?? throw new KnownException($"未找到对应的WCS任务{obj.Data2.TaskNumber}", LogLevelEnum.Mid);
+
+                //TODO:暂时不来考虑动态计算可前往的目标
+                var nextAdd = taskInfo.WarehouseCode switch
+                {
+                    "1N" => "455",
+                    "1S" => "455",
+                    "2N" => "455",
+                    "2S" => "455",
+                    "3N" => "455",
+                    "3S" => "455",
+                    _ => "0"
+                };
+                //获取这个地址的下一个地址集合
+                var cacheLineDevList = Device.All.First(x => x.Code == nextAdd).Targets.Where(x => x.HasFlag(DeviceFlags.桁架缓存放行点));
+                var cacheLineCodes = cacheLineDevList.Select(x => x.Code.ToShort());
+                var cacheLineList = db.Queryable<WCS_CacheLine>().Includes(x => x.Locations).ToList();
+
+                #region 跟据缓存信息寻找可以到达的缓存点
+
+                //找到当前任务可用的缓存线信息
+                var cacheLine = cacheLineList.Where(x => x.Locations.Any(l => l is { InStock: false, IsEmpty: false })).FirstOrDefault(x => cacheLineCodes.Contains(x.LocationNo) && x.MatCodeList.Contains(taskInfo.MatCode) && !x.InStock);
+
+                if (cacheLine != null)//这个任务可以直接去一条线体,不需要新建缓存信息
+                {
+                    //找到这条线体中序号最小的一条位信息 非空置且无货
+                    var cacheLoc = cacheLine.Locations.Where(x => x is { InStock: false, IsEmpty: false }).MinBy(x => x.XYNo);
+                    if (cacheLoc != null)
+                    {
+                        cacheLoc = db.Queryable<WCS_CacheLineLoc>().Single(x => x.Id == cacheLoc.Id);
+                        cacheLoc.InStock = true;
+                        cacheLoc.TaskId = taskInfo.ID;
+                        cacheLoc.EditTime = DateTime.Now;
+                        db.Updateable(cacheLoc).ExecuteCommand();
+
+                        //WCS任务相关信息
+                        taskInfo.Status = TaskStatus.FinishOfShunt;
+                        taskInfo.AddrNext = cacheLine.LocationNo.ToString();
+                        taskInfo.EditWho = "WCS";
+                        taskInfo.EditTime = DateTime.Now;
+                        taskInfo.AddWCS_TASK_DTL(_db, obj.Entity.Code, taskInfo.AddrNext, $"完成分库计算,目标地址:{cacheLine.LocationNo}");
+                        db.Updateable(taskInfo).ExecuteCommand();
+                        taskInfo.UpdateRedisHash();
+                        isPut = true;
+                        return;
+                    }
+                }
+
+                #endregion 跟据缓存信息寻找可以到达的缓存点
+
+                #region 初始化一个信息的缓存信息
+
+                //找到所有当前轮子可以去的垛形
+                var palletizingList = db.Queryable<WCS_Palletizing>()
+                    .Includes(x => x.Layers, r => r.Rows, l => l.Locs)
+                    .Where(x => x.MatCodeList.Contains(taskInfo.MatCode) && !x.Finish).ToList().Where(x => x.Layers.SelectMany(x => x.Rows).Any(r => r.LineCode == null)).OrderBy(x => x.AddTime).ToList();
+                //如果没有对应的垛形信息就初始化一个垛形信息
+                if (palletizingList.Count <= 0)
+                {
+                    taskInfo.InitStackStructure();
+                    return;
+                }
+                foreach (var palletizingLayer in palletizingList.Select(palletizing => palletizing.Layers
+                             .Where(x => !x.IsEmpty)
+                             .Where(x => !x.Finish)
+                             .Where(x => x.MatCodeList.Contains(taskInfo.MatCode))
+                             .Where(x => x.Rows.Any(r => r.CacheLineId == 0))
+                             .MinBy(x => x.LayerNo)))
+                {
+                    //如果没有哪一层需要这个物料号,就初始化一个新的垛形信息
+                    if (palletizingLayer == null)
+                    {
+                        taskInfo.InitStackStructure();
+                        return;
+                    }
+
+                    //再找行:未空置、未结束
+                    var palletizingRow = palletizingLayer.Rows.Where(x => x is { IsEmpty: false, Finish: false } && x.MatCodeList.Contains(taskInfo.MatCode) && x.CacheLineId == 0)
+                        .MinBy(x => x.RowNo);
+                    //如果没有哪一行需要这个物料号,就初始化一个新的垛形信息
+                    if (palletizingRow == null)
+                    {
+                        taskInfo.InitStackStructure();
+                        return;
+                    }
+                    //走到这一步就表示没有哪一段线体缓存了当前物料,需要选一段新的线体进行缓存
+
+                    //TODO:暂时不处理就近分线的逻辑
+                    //获取一个当前可以使用的分配锁
+                    var devCode = cacheLineDevList.Select(x => x.Code.ToShort()).FirstOrDefault(x => !cacheLineList.Select(s => s.LocationNo).Contains(x));
+                    if (devCode == 0)
+                    {
+                        World.Log($"无可用线体:{taskInfo.ID}");
+                        return;
+                    }
+
+                    //开始初始化缓存位信息
+                    cacheLine = new WCS_CacheLine()
+                    {
+                        LocationNo = devCode,
+                        AddTime = DateTime.Now,
+                        PalletizingRowId = palletizingRow.Id,
+                        InStock = false,
+                        Put = false,
+                        MatCodeList = palletizingRow.MatCodeList
+                    };
+
+                    var res = db.Insertable(cacheLine).ExecuteReturnEntity();
+                    palletizingRow = db.Queryable<WCS_PalletizingRow>().Includes(x => x.Locs).Single(x => x.Id == palletizingRow.Id);
+                    palletizingRow.Locs = palletizingRow.Locs.OrderBy(x => x.XYNo).ToList();
+                    palletizingRow.CacheLineId = res.Id;
+                    palletizingRow.EditTime = DateTime.Now;
+                    db.Updateable(palletizingRow).ExecuteCommand();
+
+                    for (var i = 0; i < palletizingRow.Locs.Count; i++)
+                    {
+                        var loc = new WCS_CacheLineLoc()
+                        {
+                            XYNo = palletizingRow.Locs[i].XYNo,
+                            InStock = i == 0,
+                            IsEmpty = palletizingRow.Locs[i].IsEmpty,
+                            MatCode = palletizingRow.Locs[i].MatCode,
+                            TaskId = i == 0 ? taskInfo.ID : 0,
+                            CacheLineId = res.Id
+                        };
+                        db.Insertable(loc).ExecuteCommand();
+                    }
+
+                    taskInfo.Status = TaskStatus.FinishOfShunt;
+                    taskInfo.AddrNext = devCode.ToString();
+                    taskInfo.EditWho = "WCS";
+                    taskInfo.EditTime = DateTime.Now;
+                    taskInfo.AddWCS_TASK_DTL(_db, obj.Entity.Code, taskInfo.AddrNext, $"完成分库计算,目标地址:{cacheLine.LocationNo}");
+                    db.Updateable(taskInfo).ExecuteCommand();
+                    taskInfo.UpdateRedisHash();
+                    isPut = true;
+                    return;
+                }
+
+                #endregion 初始化一个信息的缓存信息
+            });
+            if (!isPut) return;
+            obj.Data.TaskNumber = obj.Data2.TaskNumber;
+            obj.Data.GoodsStart = obj.Entity.Code.ToShort();
+            obj.Data.GoodsEnd = 455;
+            obj.Data.VoucherNo++;
+            World.Log($"执行记录:任务号[{obj.Data2.TaskNumber}]");
+        }
+
+        public override bool Select(Device dev)
+        {
+            return dev.HasFlag(DeviceFlags.环形库分流点);
+        }
+    }
+}

+ 2 - 2
WCS.WorkEngineering/Systems/分线计算09.cs

@@ -5,7 +5,6 @@ using WCS.Core;
 using WCS.Entity;
 using WCS.WorkEngineering.Extensions;
 using WCS.WorkEngineering.Protocol.Station;
-using WCS.WorkEngineering.Worlds;
 using DeviceFlags = WCS.WorkEngineering.Extensions.DeviceFlags;
 using TaskStatus = WCS.Entity.TaskStatus;
 
@@ -14,7 +13,7 @@ namespace WCS.WorkEngineering.Systems
     /// <summary>
     ///  分线计算09
     /// </summary>
-    [BelongTo(typeof(NoInteractionWorld))]
+    //[BelongTo(typeof(NoInteractionWorld))]
     [Description("分线计算09")]
     public class 分线计算09 : DeviceSystem<Device<IStation520>>
     {
@@ -170,6 +169,7 @@ namespace WCS.WorkEngineering.Systems
                         taskInfo.UpdateRedisHash();
                         return;
                     }
+
                     #endregion 初始化一个信息的缓存信息
                 }
             });

+ 5 - 8
WCS.WorkEngineering/Systems/机台叫料生成AGV任务.cs

@@ -1,13 +1,9 @@
-using ServiceCenter.SqlSugars;
-using System.ComponentModel;
-using System.Threading.Tasks;
+using System.ComponentModel;
 using WCS.Core;
-using WCS.Entity;
 using WCS.WorkEngineering.Protocol.Station;
 using WCS.WorkEngineering.WebApi.Controllers;
 using WCS.WorkEngineering.Worlds;
 using DeviceFlags = WCS.WorkEngineering.Extensions.DeviceFlags;
-using TaskStatus = WCS.Entity.TaskStatus;
 
 namespace WCS.WorkEngineering.Systems
 {
@@ -21,8 +17,9 @@ namespace WCS.WorkEngineering.Systems
 
         public override void Do(Device<IStation520, IStation521, IStation523> obj)
         {
-
-            //var res = AgvApi.测试路径("LXLK2", "2225552");
+            //var res = AgvApi.测试路径("2534", "2225552");
+            //var res = AgvApi.机台叫料("2534", "", "2225552");
+            var res = AgvApi.托盘回库("2534", "2225552");
 
             //if (!obj.Data3.Status.HasFlag(StationStatus.PH_Status)) return;
             //if (!obj.Data3.Status.HasFlag(StationStatus.Auto)) return;
@@ -42,4 +39,4 @@ namespace WCS.WorkEngineering.Systems
             return dev.HasFlag(DeviceFlags.AGV取货站台口);
         }
     }
-}
+}

+ 2 - 2
WCS.WorkEngineering/Systems/桁架.cs → WCS.WorkEngineering/Systems/桁架码垛/桁架.cs

@@ -15,7 +15,7 @@ namespace WCS.WorkEngineering.Systems
     /// <summary>
     ///  桁架
     /// </summary>
-    [BelongTo(typeof(MainWorld))]
+    [BelongTo(typeof(SortingPalletizingWorld))]
     [Description("桁架")]
     public class 桁架 : DeviceSystem<Truss>
     {
@@ -185,7 +185,7 @@ namespace WCS.WorkEngineering.Systems
 
         public override bool Select(Device dev)
         {
-            return dev.HasFlag(Extensions.DeviceFlags.桁架);
+            return dev.HasFlag(DeviceFlags.桁架);
         }
 
         public 桁架()

+ 4 - 1
WCS.WorkEngineering/Systems/桁架缓存放行点.cs → WCS.WorkEngineering/Systems/桁架码垛/桁架缓存放行点.cs

@@ -10,7 +10,10 @@ using WCS.WorkEngineering.Worlds;
 
 namespace WCS.WorkEngineering.Systems
 {
-    [BelongTo(typeof(MainWorld))]
+    /// <summary>
+    ///  桁架缓存放行点
+    /// </summary>
+    [BelongTo(typeof(SortingPalletizingWorld))]
     [Description("桁架缓存放行点")]
     public class 桁架缓存放行点 : DeviceSystem<Device<IStation520, IStation521, IStation523>>
     {

+ 0 - 74
WCS.WorkEngineering/Systems/环形库分流点.cs

@@ -1,74 +0,0 @@
-using ServiceCenter.Extensions;
-using ServiceCenter.Logs;
-using ServiceCenter.SqlSugars;
-using System.ComponentModel;
-using WCS.Core;
-using WCS.Entity;
-using WCS.WorkEngineering.Extensions;
-using WCS.WorkEngineering.Protocol.Station;
-using WCS.WorkEngineering.Worlds;
-using TaskStatus = WCS.Entity.TaskStatus;
-
-namespace WCS.WorkEngineering.Systems
-{
-    /// <summary>
-    ///  分流点
-    /// </summary>
-    [BelongTo(typeof(MainWorld))]
-    [Description("环形库分流点")]
-    public class 环形库分流点 : DeviceSystem<Device<IStation520, IStation521, IStation523, IStation91>>
-    {
-        protected override bool ParallelDo => true;
-
-        protected override bool SaveLogsToFile => true;
-
-        public override void Do(Device<IStation520, IStation521, IStation523, IStation91> obj)
-        {
-            if (obj.Data.VoucherNo != obj.Data2.VoucherNo) throw new KnownException($"凭证号不一致,DB520:{obj.Data.VoucherNo}-DB521:{obj.Data2.VoucherNo}", LogLevelEnum.High);
-            if (obj.Data3.Status.HasFlag(StationStatus.Run)) throw new KnownException("设备运行中", LogLevelEnum.Low);
-            if (!obj.Data3.Status.HasFlag(StationStatus.OT_Status)) throw new KnownException("站台货物信息与实际占用不一致", LogLevelEnum.Low);
-            if (obj.Data2.Request != 1) throw new KnownException("无请求", LogLevelEnum.Mid);
-
-            //处理异常任务
-            if (obj.Data2.TaskNumber == 1)
-            {
-                obj.Data.TaskNumber = 591;
-                obj.Data.GoodsStart = obj.Entity.Code.ToShort();
-                obj.Data.GoodsEnd = 591;
-                obj.Data.VoucherNo++;
-                World.Log($"执行记录:任务号[{591}]");
-            }
-
-            var db = new SqlSugarHelper();
-            var taskInfo = db.Default.Queryable<WCS_TaskInfo>().First(v => v.ID == obj.Data2.TaskNumber && v.Status == TaskStatus.FinishOfShunt) ?? throw new KnownException("未找到对应的WCS任务", LogLevelEnum.Mid);
-            try
-            {
-                db.Connect.BeginTran();
-                //taskInfo.Status = TaskStatus.ConveyorExecution;
-                //taskInfo.AddrNext = "455";//TODO:暂时先用固定值
-                taskInfo.EditWho = "WCS";
-                taskInfo.EditTime = DateTime.Now;
-                taskInfo.AddWCS_TASK_DTL(db, obj.Entity.Code, taskInfo.AddrNext, "环形库分流");
-                db.Default.Updateable(taskInfo).ExecuteCommand();
-                db.Connect.CommitTran();
-                taskInfo.UpdateRedisHash();
-            }
-            catch (Exception e)
-            {
-                db.Connect.RollbackTran();
-                throw new KnownException($"{obj.Data2.TaskNumber}:----{e.Message}", LogLevelEnum.High);
-            }
-
-            obj.Data.TaskNumber = obj.Data2.TaskNumber;
-            obj.Data.GoodsStart = obj.Entity.Code.ToShort();
-            obj.Data.GoodsEnd = 455;
-            obj.Data.VoucherNo++;
-            World.Log($"执行记录:任务号[{obj.Data2.TaskNumber}]");
-        }
-
-        public override bool Select(Device dev)
-        {
-            return dev.HasFlag(Extensions.DeviceFlags.环形库分流点);
-        }
-    }
-}

+ 35 - 42
WCS.WorkEngineering/WebApi/Controllers/AgvApi.cs

@@ -49,71 +49,64 @@ namespace WCS.WorkEngineering.WebApi.Controllers
                     type="00"
                 },
                 new positionCodeClass(){ //巷道分配点
-                    positionCode="LX001",
+                    positionCode="LX002",
                     type="00"
-                },
-                new positionCodeClass(){ //预分配放货点
-                    positionCode="LXSS1",
-                    type="00"
-                }
+                }/*,*/
+                //new positionCodeClass(){ //预分配放货点
+                //    positionCode="LXSS1",
+                //    type="00"
+                //}
             }, "1", taskCode, "LX03", "1");
         }
 
         /// <summary>
-        ///  机台补空
+        ///   测试路径
         /// </summary>
-        /// <param name="position">补空机台</param>
+        /// <param name="position">取货机台</param>
         /// <param name="taskCode">WMS任务号</param>
-        /// <param name="priority">优先级</param>
         /// <returns></returns>
-        public static GenAgvSchedulingTaskResponse 机台补空(string position, string taskCode, string priority)
+        public static GenAgvSchedulingTaskResponse 机台叫料(string SPosition, string EPosition, string taskCode)
         {
-            return GenAgvSchedulingTask("iWMS", "", "4", new List<positionCodeClass>()
+            return GenAgvSchedulingTask("iwms_third", "", "4", new List<positionCodeClass>()
             {
-                new positionCodeClass(){ //合金库空区域
-                    positionCode="21",
-                    type="04"
+                new positionCodeClass(){ //取货机台
+                    positionCode=SPosition,
+                    type="00"
                 },
-                new positionCodeClass(){ //目标机台
-                    positionCode=position,
+                new positionCodeClass(){ //巷道分配点
+                    positionCode=EPosition,
                     type="00"
-                }
-            }, priority, taskCode, "ZTGT03", "0");
-        }
-
-        /// <summary>
-        ///  缓存架补空
-        /// </summary>
-        /// <param name="taskCode">任务号</param>
-        /// <param name="nextPositionCode">取货地址</param>
-        /// <returns></returns>
-        public static ContinueTaskResponse 缓存架补空(string taskCode, string nextPositionCode)
-        {
-            return ContinueTask(taskCode, nextPositionCode);
+                }/*,*/
+                //new positionCodeClass(){ //预分配放货点
+                //    positionCode="LXSS1",
+                //    type="00"
+                //}
+            }, "1", taskCode, "LX01", "1");
         }
 
         /// <summary>
-        ///  机台补满
+        ///   测试路径
         /// </summary>
-        /// <param name="ctnrCode">RFID</param>
-        /// <param name="position1">取货站台</param>
-        /// <param name="position2">放货机台</param>
+        /// <param name="position">取货机台</param>
         /// <param name="taskCode">WMS任务号</param>
-        /// <param name="priority">优先级</param>
         /// <returns></returns>
-        public static GenAgvSchedulingTaskResponse 机台补满(string ctnrCode, string position1, string position2, string taskCode, string priority)
+        public static GenAgvSchedulingTaskResponse 托盘回库(string position, string taskCode)
         {
-            return GenAgvSchedulingTask("iWMS", ctnrCode, "1", new List<positionCodeClass>()
+            return GenAgvSchedulingTask("iwms_third", "", "4", new List<positionCodeClass>()
             {
-                new positionCodeClass(){ //取货
-                    positionCode=position1,
+                new positionCodeClass(){ //取货
+                    positionCode=position,
                     type="00"
                 },
-                new positionCodeClass(){ //放货机台
-                    positionCode=position2,
+                new positionCodeClass(){ //巷道分配点
+                    positionCode="LX002",
                     type="00"
-                }
-            }, priority, taskCode, "ZTGT21", "-1");
+                }/*,*/
+                //new positionCodeClass(){ //预分配放货点
+                //    positionCode="LXSS1",
+                //    type="00"
+                //}
+            }, "1", taskCode, "LX02", "1");
         }
 
         /// <summary>

+ 1 - 1
WCS.WorkEngineering/WebApi/Controllers/AgvController.cs

@@ -33,7 +33,7 @@ namespace WCS.WorkEngineering.WebApi.Controllers
                 switch (type)
                 {
                     case 1:
-                        AgvApi.机台补空(pos, code, "1");
+                        //AgvApi.机台补空(pos, code, "1");
                         break;
 
                     case 2:

+ 15 - 0
WCS.WorkEngineering/Worlds/SortingBranchWorld.cs

@@ -0,0 +1,15 @@
+using System.ComponentModel;
+
+namespace WCS.WorkEngineering.Worlds
+{
+    /// <summary>
+    ///  分拣支线
+    /// </summary>
+    [Description("分拣支线")]
+    public class SortingBranchWorld : MainWorld
+    {
+        public SortingBranchWorld()
+        {
+        }
+    }
+}

+ 15 - 0
WCS.WorkEngineering/Worlds/SortingPalletizingWorld.cs

@@ -0,0 +1,15 @@
+using System.ComponentModel;
+
+namespace WCS.WorkEngineering.Worlds
+{
+    /// <summary>
+    ///  分拣码垛
+    /// </summary>
+    [Description("分拣码垛")]
+    public class SortingPalletizingWorld : MainWorld
+    {
+        public SortingPalletizingWorld()
+        {
+        }
+    }
+}