林豪 左 2 years ago
parent
commit
4cfb80850b

+ 51 - 0
WCS.WorkEngineering/Extensions/BCRExtension.cs

@@ -0,0 +1,51 @@
+using PlcSiemens.Core.Extension;
+using WCS.Core;
+using WCS.Entity.Protocol.BCR;
+using WCS.WorkEngineering.Worlds.Logs;
+
+namespace WCS.WorkEngineering.Extensions
+{
+    /// <summary>
+    ///  BCR扩展
+    /// </summary>
+    public class BCR : Device<IBCR80, IBCR81>
+    {
+        /// <summary>
+        ///  BCR扩展
+        /// </summary>
+        /// <param name="device"></param>
+        public BCR(Device device) : base(device)
+        {
+        }
+
+        /// <summary>
+        ///  获取BCR码
+        /// </summary>
+        /// <returns></returns>
+        public string GetBCRCode()
+        {
+            var barcode = Data.Content.Trim('\r');
+            if (barcode.IsNullOrWhiteSpace()) throw new KnownException($"{Entity.Code}--扫码失败,内容为空", LogLevelEnum.High);
+
+            return barcode;
+        }
+    }
+
+    /// <summary>
+    ///  BCR扩展
+    /// </summary>
+    public class BCRList : List<BCR>
+    {
+        /// <summary>
+        ///  获取BCR码
+        /// </summary>
+        /// <param name="Code">BCR对应站点设备号</param>
+        /// <returns></returns>
+        public string GetBCRCode(string code)
+        {
+            code = "BCR" + code;
+            var bcr = this.FirstOrDefault(p => p.Entity.Code == code) ?? throw new KnownException($"未找到扫码器{code}", LogLevelEnum.High);
+            return bcr.GetBCRCode();
+        }
+    }
+}

+ 14 - 0
WCS.WorkEngineering/Extensions/DeviceExtension.cs

@@ -10,6 +10,8 @@ namespace WCS.WorkEngineering.Extensions
     /// </summary>
     public static class DeviceExtension
     {
+        #region 设备类型
+
         /// <summary>
         ///  是否是输送线
         /// </summary>
@@ -30,6 +32,18 @@ namespace WCS.WorkEngineering.Extensions
             return source.Code.Contains("TY");
         }
 
+        /// <summary>
+        ///  是否是BCR
+        /// </summary>
+        /// <param name="source">设备信息</param>
+        /// <returns></returns>
+        public static bool IsBCR(this Device source)
+        {
+            return source.Code.Contains("BCR");
+        }
+
+        #endregion 设备类型
+
         /// <summary>
         ///  获取下一个地址
         /// </summary>

+ 13 - 1
WCS.WorkEngineering/Extensions/StationExtension.cs

@@ -1,5 +1,7 @@
-using WCS.Core;
+using ServiceCenter.Redis;
+using WCS.Core;
 using WCS.Entity.Protocol.Station;
+using WCS.WorkEngineering.Worlds.Logs;
 
 namespace WCS.WorkEngineering.Extensions
 {
@@ -8,5 +10,15 @@ namespace WCS.WorkEngineering.Extensions
         public Station(Device device) : base(device)
         {
         }
+
+        /// <summary>
+        ///  入库站点是否被禁止
+        /// </summary>
+        /// <returns></returns>
+        public void StorageStationIsForbid()
+        {
+            var config = RedisHub.Default.Get("ForbidTubuEnter").Split(",");
+            if (config.Contains(Entity.Code)) throw new KnownException("当前入库口已被禁用,请联系运维人员了解具体情况", LogLevelEnum.High);
+        }
     }
 }

+ 7 - 3
WCS.WorkEngineering/Systems/DataCollectionSysyem.cs

@@ -5,7 +5,7 @@ using ServiceCenter.SqlSugars;
 using System.ComponentModel;
 using WCS.Core;
 using WCS.Entity;
-using WCS.Entity.Protocol.Station;
+using WCS.Entity.Protocol.DataStructure;
 using WCS.Service.Worlds;
 using WCS.WorkEngineering.Extensions;
 
@@ -18,17 +18,21 @@ namespace WCS.Service.Systems
     [Description("数据采集系统")]
     public class DataCollectionSysyem : ServiceSystem<bool, bool>
     {
-        public List<Device<IStation520, IStation521>> ConvList;
+        public List<Station> ConvList;
 
         public DataCollectionSysyem()
         {
-            ConvList = World.Devices.Where(v => v.IsConv()).Select(v => new Device<IStation520, IStation521>(v)).ToList();
+            ConvList = World.Devices.Where(v => v.IsConv()).Select(v => new Station(v)).ToList();
         }
 
         protected override bool Do(bool obj)
         {
             SqlSugarHelper.Do(db =>
             {
+                DeviceDataPack pack = new DeviceDataPack();
+                pack.Frame = DateTime.Now;
+                //pack.
+
                 //byte[] bytes = System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(ConvList, null, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
 
                 var plcData = new WCS_PlcData()

+ 0 - 29
WCS.WorkEngineering/Systems/MainLineScanCode.cs

@@ -1,29 +0,0 @@
-using System.ComponentModel;
-using WCS.Core;
-using WCS.Entity.Protocol.Station;
-using WCS.WorkEngineering.Worlds;
-
-namespace WCS.WorkEngineering.Systems
-{
-    /// <summary>
-    ///  主线扫码
-    /// </summary>
-    [BelongTo(typeof(SortingMainLineWorld))]
-    [Description("主线扫码")]
-    public class MainLineScanCode : DeviceSystem<Device<IStation520, IStation521, IStation523>>
-    {
-        protected override bool ParallelDo => throw new NotImplementedException();
-
-        protected override bool SaveLogsToFile => throw new NotImplementedException();
-
-        public override void Do(Device<IStation520, IStation521, IStation523> obj)
-        {
-            throw new NotImplementedException();
-        }
-
-        public override bool Select(Device dev)
-        {
-            return new int[] { 1701, 2101, 1717, 2117 }.Contains(int.Parse(dev.Code));
-        }
-    }
-}

+ 41 - 0
WCS.WorkEngineering/Systems/OutboundSiteInteractionSystems.cs

@@ -0,0 +1,41 @@
+using System.Threading.Tasks;
+using WCS.Core;
+using WCS.WorkEngineering.Extensions;
+
+namespace WCS.WorkEngineering.Systems
+{
+    /// <summary>
+    /// 出库站点交互
+    /// </summary>
+    public class OutboundSiteInteractionSystems : DeviceSystem<Station>
+    {
+        protected override bool ParallelDo => true;
+
+        protected override bool SaveLogsToFile => true;
+
+        public override void Do(Station obj)
+        {
+            var IsThereATask = false;
+
+            #region 判断站点是否有任务
+
+            #endregion
+
+            if (IsThereATask)
+            {
+                //TODO判断当前站台是否是一楼
+                if (true) //一楼无任务站台开始呼叫空轮出库任务
+                {
+
+                }
+            }
+            else { 
+            }
+        }
+
+        public override bool Select(Device dev)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

+ 47 - 0
WCS.WorkEngineering/Systems/StorageSysyem.cs

@@ -0,0 +1,47 @@
+using System.ComponentModel;
+using WCS.Core;
+using WCS.WorkEngineering.Extensions;
+using WCS.WorkEngineering.WebApi.Controllers;
+using WCS.WorkEngineering.Worlds;
+using WCS.WorkEngineering.Worlds.Logs;
+
+namespace WCS.WorkEngineering.Systems
+{
+    /// <summary>
+    /// </summary>
+    [BelongTo(typeof(SortingMainLineWorld))]
+    [Description("主线扫码")]
+    public class StorageSysyem : DeviceSystem<Station>
+    {
+        protected override bool ParallelDo => true;
+
+        protected override bool SaveLogsToFile => true;
+
+        private BCRList BCRS = new BCRList();
+
+        public StorageSysyem()
+        {
+            BCRS = World.Devices.Where(v => v.IsBCR()).Select(v => new BCR(v)).ToList() as BCRList;
+        }
+
+        public override void Do(Station obj)
+        {
+            obj.StorageStationIsForbid();
+            //判断凭证号是否一致
+            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(Entity.Protocol.Station.StatusEunm.Run)) throw new KnownException("设备运行中", LogLevelEnum.Low);
+
+            //获取条码
+            var barcode = BCRS.GetBCRCode(obj.Entity.Code);
+
+            //获取入库任务
+            var info = WmsApi.I_WCS_GetInTask(barcode, obj.Entity.Code, true);
+        }
+
+        public override bool Select(Device dev)
+        {
+            return new int[] { 1701, 2101, 1717, 2117 }.Contains(int.Parse(dev.Code));
+        }
+    }
+}

+ 24 - 0
WCS.WorkEngineering/WebApi/Controllers/WmsApi.cs

@@ -37,5 +37,29 @@ namespace WCS.WorkEngineering.WebApi.Controllers
             }
             return res;
         }
+
+        /// <summary>
+        /// 向WMS获取入库任务 一次单卷
+        /// </summary>
+        /// <param name="barcode">产品条码</param>
+        /// <param name="devCode">设备条码</param>
+        /// <param name="getTunnel"></param>
+        /// <returns></returns>
+        /// <exception cref="Exception"></exception>
+        public static I_WCS_GetInTaskResponse I_WCS_GetInTask(string barcode, string devCode, bool getTunnel = false)
+        {
+            var res = APICaller.CallApi<I_WCS_GetInTaskResponse>(WMSUrl + "/api/Task/I_WCS_GetInTask", new List<I_WCS_GetInTaskRequest>()
+            {
+                new I_WCS_GetInTaskRequest(){
+                     ContainerBarCode = barcode,
+                     WareHouseId = wareHouseId,
+                     EquipmentNo = devCode,
+                     Memo1 = getTunnel ? "1" : "" //1:分巷道  2:分货位
+                }
+            });
+            if (!res.ResType) throw new KnownException(res.ResMessage, LogLevelEnum.High);
+
+            return res;
+        }
     }
 }

+ 54 - 0
WCS.WorkEngineering/WebApi/Models/WMS/Request/I_WCS_GetInTaskRequest.cs

@@ -0,0 +1,54 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace WCS.WorkEngineering.WebApi.Models.WMS.Request
+{
+    /// <summary>
+    /// 获取入库任务请求实体
+    /// </summary>
+    public class I_WCS_GetInTaskRequest
+    {
+        /// <summary>
+        /// 容器编号
+        /// </summary>
+        [Required(ErrorMessage = "{0} 不可为空")]
+        public string ContainerBarCode { get; set; }
+
+        /// <summary>
+        /// 容器类型
+        /// </summary>
+        [Required(ErrorMessage = "{0} 不可为空")]
+        public int ContainerType { get; set; }
+
+        /// <summary>
+        /// 物料条码
+        /// </summary>
+        public string MatBarCode { get; set; }
+
+        /// <summary>
+        /// 仓库编码
+        /// </summary>
+        [Required(ErrorMessage = "{0} 不可为空")]
+        public string WareHouseId { get; set; }
+
+        /// <summary>
+        /// 设备编号
+        /// </summary>
+        [Required(ErrorMessage = "{0} 不可为空")]
+        public string EquipmentNo { get; set; }
+
+        /// <summary>
+        /// 目标位置
+        /// </summary>
+        public string EndPostion { get; set; }
+
+        /// <summary>
+        /// 货叉(直接申请货位使用)
+        /// </summary>
+        public int ForkNum { get; set; }
+
+        public string Memo1 { get; set; }
+        public string Memo2 { get; set; }
+        public string Memo3 { get; set; }
+        public string Memo4 { get; set; }
+    }
+}

+ 46 - 0
WCS.WorkEngineering/WebApi/Models/WMS/Response/I_WCS_GetInTaskResponse.cs

@@ -0,0 +1,46 @@
+namespace WCS.WorkEngineering.WebApi.Models.WMS.Response
+{
+    public class I_WCS_GetInTaskResponse : WcsContractApiResponse
+    {
+        /// <summary>
+        /// WMS任务号
+        /// </summary>
+        public string WMSTaskNum { get; set; } = "0";
+
+        /// <summary>
+        /// 任务类型(1:入库2:出库3:移库4:移动(搬运) 5:异常 )
+        /// </summary>
+        public int TaskType { get; set; }
+
+        /// <summary>
+        /// 仓库名称
+        /// </summary>
+        public string WareHouseName { get; set; } = "";
+
+        /// <summary>
+        /// 入库巷道(集合巷道,由WCS自行判断入到哪一个巷道,最前面的最优先。)
+        /// </summary>
+        public string TunnelNum { get; set; } = "";
+
+        /// <summary>
+        /// 目标位置(入库该地址为srm.如果是移动任务,该地址为WCS传递的目标位置。)
+        /// </summary>
+        public string EndPostion { get; set; } = "";
+
+        public int Priority { get; set; } = 0;
+
+        /// <summary>
+        /// 产品编码(半成品入库使用)
+        /// </summary>
+        public string ContainerCode { get; set; } = "";
+
+        /// <summary>
+        /// 0默认值  1载货  2空盘(包含一个托盘或一摞两种情况)
+        /// </summary>
+        public int ContainerType { get; set; } = 0;
+
+        public string Memo1 { get; set; } = "";
+        public string Memo2 { get; set; } = "";
+        public string Memo3 { get; set; } = "";
+    }
+}