林豪 左 2 жил өмнө
parent
commit
97b597663c

+ 1 - 28
WCS.Service/Worker.cs

@@ -94,15 +94,7 @@ namespace WCS.Service
                     {
                         case "WCSDB"://WCS基本数据库
                             SqlSugarHelper.SetDefault(connectionString.Key);
-                            //_db.CodeFirst.InitTables(typeof(WCS_PlcSet));
-                            //_db.CodeFirst.InitTables(typeof(WCS_PlcDataBlock));
                             _db.CodeFirst.InitTables(typeof(WCS_PlcData));
-                            //_db.CodeFirst.InitTables(typeof(WCS_DeviceInfo));
-                            //_db.CodeFirst.InitTables(typeof(WCS_DeviceGrp));
-                            //_db.CodeFirst.InitTables(typeof(WCS_DeviceProt));
-                            //_db.CodeFirst.InitTables(typeof(WCS_PathInfo));
-                            //_db.CodeFirst.InitTables(typeof(WCS_PathGrp));
-                            //_db.CodeFirst.InitTables(typeof(WCS_Route));
                             _db.CodeFirst.InitTables(typeof(WCS_TaskInfo));
                             _db.CodeFirst.InitTables(typeof(WCS_TaskDtl));
                             _db.CodeFirst.InitTables(typeof(WCS_TaskOld));
@@ -111,19 +103,6 @@ namespace WCS.Service
                             break;
 
                         case "WCSDlog"://WCS日志数据库
-                            //SqlSugarHelper.SetDlog(connectionString.Key);
-                            //_db.DbMaintenance.CreateDatabase();
-                            //_db.CodeFirst.InitTables(typeof(WCS_BCR80));
-                            ////db.Context(WcsDlog).CodeFirst.InitTables(typeof(WCS_RGV520));
-                            ////db.Context(WcsDlog).CodeFirst.InitTables(typeof(WCS_RGV521));
-                            ////db.Context(WcsDlog).CodeFirst.InitTables(typeof(WCS_RGV523));
-                            ////_db.CodeFirst.InitTables(typeof(WCS_SRM520));
-                            ////_db.CodeFirst.InitTables(typeof(WCS_SRM521));
-                            ////db.Context(WcsDlog).CodeFirst.InitTables(typeof(WCS_SRM537));
-                            //_db.CodeFirst.InitTables(typeof(WCS_Station520));
-                            //_db.CodeFirst.InitTables(typeof(WCS_Station521));
-                            //_db.CodeFirst.InitTables(typeof(WCS_Station523));
-                            //_db.CodeFirst.InitTables(typeof(WCS_Station91));
 
                             break;
 
@@ -135,13 +114,7 @@ namespace WCS.Service
 
             #endregion 初始化数据库连接
 
-            #region 配置DebugRedisUrl
-
-            var debugRedisUrl = RedisHub.Default.Check("DebugRedisUrl") ?? throw new Exception("请在Redis中配置DebugRedisUrl地址");
-            if (debugRedisUrl.IsNullOrEmpty()) throw new Exception("请在Redis中配置DebugRedisUrl地址");
-            Configs.DebugRedisUrl = debugRedisUrl;
-
-            #endregion 配置DebugRedisUrl
+         
 
             #region 初始化设备信息
 

+ 40 - 4
WCS.WorkEngineering/ProtocolProxy.cs

@@ -1,8 +1,9 @@
-using WCS.Core;
-using WCS.Entity.Protocol.BCR;
+using MessagePack;
+using Newtonsoft.Json;
+using ServiceCenter;
+using ServiceCenter.Redis;
+using WCS.Core;
 using WCS.Entity.Protocol.DataStructure;
-using WCS.Entity.Protocol.SRM;
-using WCS.Entity.Protocol.Station;
 
 namespace WCS.Service
 {
@@ -12,6 +13,41 @@ namespace WCS.Service
 
         public ProtocolProxy(Device dev, ProtocolInfo info, Type protocolType, World world) : base(dev, info, protocolType, world)
         {
+            #region 初始化Redis连接
+
+            var redisConnectionStrings = RedisHub.Default.Check("RedisConnectionStrings") ?? throw new Exception("请在Redis中配置RedisConnectionStrings");
+            var configs = JsonConvert.DeserializeObject<List<DataBaseConnectionString>>(redisConnectionStrings);
+            if (configs != null)
+            {
+                if (configs.All(v => v.Key != "Monitor")) throw new Exception("请在RedisConnectionStrings中配置监控RedisDB库连接字符串");
+            }
+
+            foreach (var redisConnection in configs!)
+            {
+                RedisHub.CreateContext(redisConnection.ConnectionString, redisConnection.Key);
+                switch (redisConnection.Key)
+                {
+                    case "Monitor":
+                        RedisHub.SetMonitorContextType(redisConnection.Key);
+                        RedisHub.Monitor.Serialize = obj =>
+                        {
+                            var bytes = MessagePackSerializer.Serialize(obj);
+                            return bytes;
+                        };
+                        RedisHub.Monitor.DeserializeRaw = (bytes, type) =>
+                        {
+                            var obj = MessagePackSerializer.Deserialize(type, bytes);
+                            return obj;
+                        };
+                        break;
+
+                    case "DebugRedisUrl":
+                        Configs.DebugRedisUrl = redisConnection.Key;
+                        break;
+                }
+            }
+
+            #endregion 初始化Redis连接
         }
 
         protected override void DataChanged()

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

@@ -1,6 +1,7 @@
 using Newtonsoft.Json;
 using ServiceCenter;
 using ServiceCenter.Extensions;
+using ServiceCenter.Redis;
 using ServiceCenter.SqlSugars;
 using System.ComponentModel;
 using WCS.Core;
@@ -101,7 +102,13 @@ namespace WCS.Service.Systems
                     WAREHOUSE = ServiceHub.WarehouseName,
                     CONTENT = JsonConvert.SerializeObject(pack, null, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }),
                 };
+                RedisHub.Monitor.RPush("Packs", pack);
+                RedisHub.Monitor.Set(nameof(DeviceDataPack), pack);
 
+                if (RedisHub.Monitor.LLen("Packs") > 500000)
+                {
+                    RedisHub.Monitor.LTrim("Packs", 5000, -1);
+                }
                 db.Default.Insertable(plcData).ExecuteCommand();
             });
         }

+ 1 - 0
WCS.WorkEngineering/WCS.WorkEngineering.csproj

@@ -20,6 +20,7 @@
   </ItemGroup>
 
   <ItemGroup>
+    <PackageReference Include="MessagePack" Version="2.5.108" />
     <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.5" />
   </ItemGroup>