林豪 左 1 жил өмнө
parent
commit
151f885d11

+ 1 - 1
WCS.Service/Program.cs

@@ -3,6 +3,7 @@ using System.Runtime.InteropServices;
 using ServiceCenter.Extensions;
 using ServiceCenter.Redis;
 using ServiceCenter.WebApi;
+using MessagePack;
 
 namespace WCS.Service
 {
@@ -13,7 +14,6 @@ namespace WCS.Service
             #region ½ÓÈëRedis
 
             RedisHub.CreateContext(AppSettings.Config.GetConnectionString("Redis"), "default", true);
-
             #endregion ½ÓÈëRedis
 
             //»¥³âËø¼ì²â

+ 0 - 3
WCS.Service/WCS.Service.csproj

@@ -23,15 +23,12 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="MessagePack" Version="2.5.108" />
     <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
-    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.5" />
     <PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="7.0.0" />
     <PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.0" />
   </ItemGroup>
 
   <ItemGroup>
     <ProjectReference Include="..\WCS.WorkEngineering\WCS.WorkEngineering.csproj" />
-    <ProjectReference Include="..\业务工程\分拣库\WCS.WorkEngineering\WCS.WorkEngineering.csproj" />
   </ItemGroup>
 </Project>

+ 7 - 5
WCS.Service/Worker.cs

@@ -9,6 +9,8 @@ using ServiceCenter.SqlSugars;
 using SqlSugar;
 using WCS.Core;
 using WCS.WorkEngineering;
+using MessagePack.ImmutableCollection;
+using MessagePack.Resolvers;
 
 namespace WCS.Service
 {
@@ -103,16 +105,16 @@ namespace WCS.Service
 
             #region 初始化数据库连接
 
-            InstanceFactory.CustomDbName = "TDengine";
-            InstanceFactory.CustomDllName = "SqlSugar.BzTDengineCore";
-            InstanceFactory.CustomNamespace = "SqlSugar.BzTDengineCore";
+            //InstanceFactory.CustomDbName = "TDengine";
+            //InstanceFactory.CustomDllName = "SqlSugar.BzTDengineCore";
+            //InstanceFactory.CustomNamespace = "SqlSugar.BzTDengineCore";
 
             var dbConnectionStrings = RedisHub.Default.Check("DbConnectionStrings") ?? throw new Exception("请在Redis中配置数据库连接相关内容");
             ServiceHub.DbConnectionStrings = JsonConvert.DeserializeObject<List<DataBaseConnectionString>>(dbConnectionStrings);
             if (ServiceHub.DbConnectionStrings != null)
             {
-                if (ServiceHub.DbConnectionStrings.All(v => v.Key != Wcsdb)) throw new Exception("请在DbConnectionStrings中配置WCS基础数据库连接字符串");
-                if (ServiceHub.DbConnectionStrings.All(v => v.Key == Wcsdb && !v.IsDefault)) throw new Exception("请在DbConnectionStrings中配置WCS基础数据库为默认数据库");
+                //if (ServiceHub.DbConnectionStrings.All(v => v.Key != Wcsdb)) throw new Exception("请在DbConnectionStrings中配置WCS基础数据库连接字符串");
+                //if (ServiceHub.DbConnectionStrings.All(v => v.Key == Wcsdb && !v.IsDefault)) throw new Exception("请在DbConnectionStrings中配置WCS基础数据库为默认数据库");
                 // if (ServiceHub.DbConnectionStrings.All(v => v.Key != WcsDlog)) throw new Exception("请在DbConnectionStrings中配置WCS日志数据库连接字符串");
             }
 

+ 90 - 0
WCS.WorkEngineering/Extensions/TaskExtension.cs

@@ -3,6 +3,8 @@ using ServiceCenter.Logs;
 using ServiceCenter.Redis;
 using ServiceCenter.SqlSugars;
 using SqlSugar;
+using SqlSugar.Extensions;
+using System.Text;
 using WCS.Core;
 using WCS.Entity;
 using TaskStatus = WCS.Entity.TaskStatus;
@@ -321,6 +323,94 @@ namespace WCS.WorkEngineering.Extensions
         }
 
         #endregion 工字轮支线分流
+
+
+        public static string ToSqlString(this QuestDBInsertBuilder questDb)
+        {
+            if (questDb.IsNoInsertNull)
+            {
+                questDb.DbColumnInfoList = questDb.DbColumnInfoList.Where(it => it.Value != null).ToList();
+            }
+            var groupList = questDb.DbColumnInfoList.GroupBy(it => it.TableId).ToList();
+            var isSingle = groupList.Count() == 1;
+            string columnsString = string.Join(",", groupList.First().Select(it => questDb.Builder.GetTranslationColumnName(it.DbColumnName)));
+            if (isSingle)
+            {
+                string columnParametersString = string.Join(",", questDb.DbColumnInfoList.Select(it =>
+                {
+                    var spk = questDb.Builder.SqlParameterKeyWord + it.DbColumnName;
+                    //if (it.Value is DateTime)
+                    //{
+                    //    return $"to_timestamp('{it.Value.ObjToString("yyyy-MM-ddTHH:mm:ss")}', 'yyyy-MM-ddTHH:mm:ss')";
+                    //}
+                    return questDb.GetDbColumn(it, spk);
+                }
+
+                ));
+                questDb.ActionMinDate();
+                return string.Format(questDb.SqlTemplate, questDb.GetTableNameString, columnsString, columnParametersString);
+            }
+            else
+            {
+                StringBuilder batchInsetrSql = new StringBuilder();
+                int pageSize = 200;
+                int pageIndex = 1;
+                int totalRecord = groupList.Count;
+                int pageCount = (totalRecord + pageSize - 1) / pageSize;
+                while (pageCount >= pageIndex)
+                {
+                    batchInsetrSql.AppendFormat(questDb.SqlTemplateBatch, questDb.GetTableNameString, columnsString);
+                    int i = 0;
+                    foreach (var columns in groupList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList())
+                    {
+                        var isFirst = i == 0;
+                        if (isFirst)
+                        {
+                            batchInsetrSql.Append(questDb.SqlTemplateBatchUnion);
+                        }
+                        batchInsetrSql.Append("\r\n ( " + string.Join(",", columns.Select(it =>
+                        {
+                            if (it.InsertServerTime || it.InsertSql.HasValue())
+                            {
+                                return questDb.GetDbColumn(it, null);
+                            }
+                            object value = null;
+                            if (it.Value is DateTime)
+                            {
+                                return $" cast('{it.Value.ObjToDate().ToString("yyyy-MM-dd HH:mm:ss.ffffff")}' as timestamp)";
+                            }
+                            else if (it.Value is int || it.Value is long || it.Value is short || it.Value is short || it.Value is byte || it.Value is double)
+                            {
+                                return it.Value;
+                            }
+                            else if (it.Value is bool)
+                            {
+                                return it.Value.ObjToString().ToLower();
+                            }
+                            else
+                            {
+                                value = it.Value;
+                            }
+                            if (value == null || value == DBNull.Value)
+                            {
+                                return string.Format(questDb.SqlTemplateBatchSelect, "NULL");
+                            }
+                            return string.Format(questDb.SqlTemplateBatchSelect, "'" + value.ObjToString().ToSqlFilter() + "'");
+                        })) + "),");
+                        ++i;
+                    }
+                    pageIndex++;
+                    batchInsetrSql.Remove(batchInsetrSql.Length - 1, 1).Append("\r\n;\r\n");
+                }
+                return batchInsetrSql.ToString();
+            }
+        }
+
+        public static bool HasValue(this object thisValue)
+        {
+            if (thisValue == null || thisValue == DBNull.Value) return false;
+            return thisValue.ToString() != "";
+        }
     }
 
     /// <summary>

+ 34 - 154
WCS.WorkEngineering/Systems/DataCollectionSysyem.cs

@@ -1,11 +1,12 @@
 using Newtonsoft.Json;
 using PlcSiemens.Core.Extension;
 using ServiceCenter.Extensions;
+using ServiceCenter.Logs;
 using ServiceCenter.Redis;
 using ServiceCenter.SqlSugars;
-using SqlSugar;
 using System.Collections.Concurrent;
 using System.ComponentModel;
+using System.Data.SqlTypes;
 using System.Diagnostics;
 using System.Text;
 using WCS.Core;
@@ -22,9 +23,9 @@ using WCS.WorkEngineering.Worlds;
 namespace WCS.WorkEngineering.Systems
 {
     /// <summary>
-    ///  数据采集系统
+    ///  数据采集
     /// </summary>
-    [BelongTo(typeof(MainWorld))]
+    [BelongTo(typeof(DataWorld))]
     [Description("数据采集系统")]
     public class DataCollectionSysyem : DeviceSystem<Device<IStation520>>
     {
@@ -64,17 +65,19 @@ namespace WCS.WorkEngineering.Systems
 
         public override void Do(Device<IStation520> objDev)
         {
-            var sql = new StringBuilder();
             try
             {
                 var sw = new Stopwatch();
                 sw.Start();
+
+                #region 处理数据
+
+                var sw1 = new Stopwatch();
+                sw1.Start();
                 var pack = new DeviceDataPack();
                 var frame = DateTime.Now;
                 pack.Frame = World.Frame;
-                sql.Append("INSERT INTO ");
                 var ps = pack.GetType().GetProperties().OrderBy(x => x.Name);
-                var db = new SqlSugarHelper().PLC;
                 Parallel.ForEach(ps, p =>
                 {
                     if (!p.PropertyType.IsArray) return;
@@ -104,7 +107,7 @@ namespace WCS.WorkEngineering.Systems
 
                                 var obj = Activator.CreateInstance(t);
                                 t.GetProperty("Code").SetValue(obj, x.Code);
-                                var value = WCS.Core.Extentions.Copy(protObj, entType, frame);
+                                var value = WCS.Core.Extentions.Copy(protObj, entType, TimeZoneInfo.ConvertTimeToUtc(frame));
                                 t.GetProperty("Data").SetValue(obj, value);
                                 t.GetProperty("Frame").SetValue(obj, protObj.Frame);
                                 entType.GetProperty("Code").SetValue(value, x.Code);
@@ -127,8 +130,14 @@ namespace WCS.WorkEngineering.Systems
                         p.SetValue(pack, arr3);
                     }
                 });
-                var sw3 = new Stopwatch();
-                sw3.Start();
+                sw1.Stop();
+
+                #endregion 处理数据
+
+                #region 存储监控数据
+
+                var sw2 = new Stopwatch();
+                sw2.Start();
 
                 //开始存储设备信息
                 RedisHub.Monitor.RPush("Packs", pack);
@@ -136,9 +145,14 @@ namespace WCS.WorkEngineering.Systems
                 {
                     RedisHub.Monitor.LTrim("Packs", 5000, -1);
                 }
+                sw2.Stop();
+
+                #endregion 存储监控数据
 
                 #region 存储设备报警信息
 
+                var sw3 = new Stopwatch();
+                sw3.Start();
                 List<EquipmentAlarm> equipmentAlarms = new List<EquipmentAlarm>();
                 equipmentAlarms.AddRange(pack.Robot522.Where(x => x.Data.Alarm != 0).Select(x => new EquipmentAlarm()
                 {
@@ -169,11 +183,14 @@ namespace WCS.WorkEngineering.Systems
                 }));
 
                 RedisHub.Default.Set(nameof(EquipmentAlarm), JsonConvert.SerializeObject(equipmentAlarms));
+                sw3.Stop();
 
                 #endregion 存储设备报警信息
 
                 #region 存储设备状态信息
 
+                var sw4 = new Stopwatch();
+                sw4.Start();
                 List<EquipmentStatus> equipmentStatus = new List<EquipmentStatus>();
 
                 equipmentStatus.AddRange(pack.RGV521.Where(x => x.Data.WorkMode != 0).Select(x => new EquipmentStatus()
@@ -217,159 +234,22 @@ namespace WCS.WorkEngineering.Systems
                 }));
 
                 RedisHub.Default.Set(nameof(EquipmentStatus), JsonConvert.SerializeObject(equipmentStatus));
+                sw4.Stop();
 
                 #endregion 存储设备状态信息
 
-                sw3.Stop();
-                World.Log($"redis存储耗时:{sw3.ElapsedMilliseconds}");
-
-                var sw4 = new Stopwatch();
-                sw4.Start();
+                #region 存储数采数据
 
-                Parallel.ForEach(pack.GetType().GetProperties().OrderBy(x => x.Name), ps =>
-                {
-                    try
-                    {
-                        if (ps.PropertyType == typeof(ProtocolData<WCS_BCR80>[]))
-                        {
-                            if (pack.BCR80.Any())
-                                db.Insertable(pack.BCR80.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR81>[]))
-                        {
-                            if (pack.BCR81.Any())
-                                db.Insertable(pack.BCR81.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR83>[]))
-                        {
-                            if (pack.BCR83.Any())
-                                db.Insertable(pack.BCR83.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV520>[]))
-                        {
-                            if (pack.RGV520.Any())
-                                db.Insertable(pack.RGV520.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV521>[]))
-                        {
-                            if (pack.RGV521.Any())
-                                db.Insertable(pack.RGV521.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot520>[]))
-                        {
-                            if (pack.Robot520.Any())
-                                db.Insertable(pack.Robot520.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot521>[]))
-                        {
-                            if (pack.Robot521.Any())
-                                db.Insertable(pack.Robot521.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot522>[]))
-                        {
-                            if (pack.Robot522.Any())
-                                db.Insertable(pack.Robot522.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot530>[]))
-                        {
-                            if (pack.Robot530.Any())
-                                db.Insertable(pack.Robot530.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot531>[]))
-                        {
-                            if (pack.Robot531.Any())
-                                db.Insertable(pack.Robot531.Select(x => x.Data).ToList()).ToSqlString();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM520>[]))
-                        {
-                            if (pack.SRM520.Any())
-                                db.Insertable(pack.SRM520.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM521>[]))
-                        {
-                            if (pack.SRM521.Any())
-                                db.Insertable(pack.SRM521.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM537>[]))
-                        {
-                            if (pack.SRM537.Any())
-                                db.Insertable(pack.SRM537.Select(x => x.Data).Where(x => x.Alarm == 0).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station520>[]))
-                        {
-                            if (pack.Station520.Any())
-                                db.Insertable(pack.Station520.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station521>[]))
-                        {
-                            if (pack.Station521.Any())
-                                db.Insertable(pack.Station521.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station523>[]))
-                        {
-                            if (pack.Station523.Any())
-                                db.Insertable(pack.Station523.Select(x => x.Data).ToList()).UseParameter()
-                                    .ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station524>[]))
-                        {
-                            if (pack.Station524.Any())
-                                db.Insertable(pack.Station524.Select(x => x.Data).ToList()).UseParameter()
-                                    .ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station525>[]))
-                        {
-                            if (pack.Station525.Any())
-                                db.Insertable(pack.Station525.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station90>[]))
-                        {
-                            if (pack.Station90.Any())
-                                db.Insertable(pack.Station90.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station91>[]))
-                        {
-                            if (pack.Station91.Any())
-                                db.Insertable(pack.Station91.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss520>[]))
-                        {
-                            if (pack.Truss520.Any())
-                                db.Insertable(pack.Truss520.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss521>[]))
-                        {
-                            if (pack.Truss521.Any())
-                                db.Insertable(pack.Truss521.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss523>[]))
-                        {
-                            if (pack.Truss523.Any())
-                                db.Insertable(pack.Truss523.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss530>[]))
-                        {
-                            if (pack.Truss530.Any())
-                                db.Insertable(pack.Truss530.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss531>[]))
-                        {
-                            if (pack.Truss531.Any())
-                                db.Insertable(pack.Truss531.Select(x => x.Data).ToList()).ExecuteCommand();
-                        }
-                    }
-                    catch (Exception e)
-                    {
-                        World.Log($"{e.Message}:{e.StackTrace}");
-                    }
-                });
+                var sw5 = new Stopwatch();
+                sw5.Start();
+                RedisHub.Monitor.RPush("DataCollectionpacks", pack);
+                sw5.Stop();
 
-                sw4.Stop();
-                World.Log($"执行SQL耗时:{sw4.ElapsedMilliseconds}");
+                #endregion 存储数采数据
 
                 sw.Stop();
 
-                World.Log($"数据采集耗时:{sw.ElapsedMilliseconds}");
+                World.Log($"业务耗时:[{sw.ElapsedMilliseconds}]--处理数据:[{sw1.ElapsedMilliseconds}]--存储监控数据:[{sw2.ElapsedMilliseconds}]--存储设备报警信息:[{sw3.ElapsedMilliseconds}]--存储设备状态数据:[{sw4.ElapsedMilliseconds}]--存储数采数据:[{sw5.ElapsedMilliseconds}]");
             }
             catch (Exception e)
             {

+ 361 - 0
WCS.WorkEngineering/Systems/MainSysyem.cs

@@ -0,0 +1,361 @@
+using Newtonsoft.Json;
+using PlcSiemens.Core.Extension;
+using ServiceCenter.Extensions;
+using ServiceCenter.Logs;
+using ServiceCenter.Redis;
+using ServiceCenter.SqlSugars;
+using SqlSugar;
+using System.Collections.Concurrent;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Text;
+using WCS.Core;
+using WCS.Entity.Protocol.BCR;
+using WCS.Entity.Protocol.DataStructure;
+using WCS.Entity.Protocol.RGV;
+using WCS.Entity.Protocol.Robot;
+using WCS.Entity.Protocol.SRM;
+using WCS.Entity.Protocol.Station;
+using WCS.Entity.Protocol.Truss;
+using WCS.WorkEngineering.Extensions;
+using WCS.WorkEngineering.Worlds;
+
+namespace WCS.WorkEngineering.Systems
+{
+    /// <summary>
+    ///  数据处理
+    /// </summary>
+    [BelongTo(typeof(MainWorld))]
+    [Description("数据处理")]
+    public class MainSysyem : DeviceSystem<Device<IStation520>>
+    {
+        public MainSysyem()
+        {
+        }
+
+        protected override bool ParallelDo => true;
+
+        protected override bool SaveLogsToFile => true;
+
+        public override bool Select(Device dev)
+        {
+            return dev.Code == "1";
+        }
+
+        public override void Do(Device<IStation520> objDev)
+        {
+            var sql = new StringBuilder();
+            try
+            {
+                var sw = new Stopwatch();
+                sw.Start();
+
+                var db = new SqlSugarHelper().PLC;
+                var pack = RedisHub.Monitor.LPop<DeviceDataPack>("DataCollectionpacks"); ;
+                if (pack == null) return;
+
+                Parallel.ForEach(pack.GetType().GetProperties().OrderBy(x => x.Name), ps =>
+                {
+                    var sw10 = new Stopwatch();
+                    sw10.Start();
+                    var typeName = "";
+                    try
+                    {
+                        if (ps.PropertyType == typeof(ProtocolData<WCS_BCR80>[]))
+                        {
+                            if (pack.BCR80.Any())
+                            {
+                                var value = pack.BCR80.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_BCR80).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR81>[]))
+                        {
+                            if (pack.BCR81.Any())
+                            {
+                                var value = pack.BCR81.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_BCR81).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_BCR83>[]))
+                        {
+                            if (pack.BCR83.Any())
+                            {
+                                var value = pack.BCR83.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_BCR83).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV520>[]))
+                        {
+                            if (pack.RGV520.Any())
+                            {
+                                var value = pack.RGV520.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_RGV520).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_RGV521>[]))
+                        {
+                            if (pack.RGV521.Any())
+                            {
+                                var value = pack.RGV521.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_RGV521).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot520>[]))
+                        {
+                            if (pack.Robot520.Any())
+                            {
+                                var value = pack.Robot520.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Robot520).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot521>[]))
+                        {
+                            if (pack.Robot521.Any())
+                            {
+                                var value = pack.Robot521.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Robot521).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot522>[]))
+                        {
+                            if (pack.Robot522.Any())
+                            {
+                                var value = pack.Robot522.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Robot522).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot530>[]))
+                        {
+                            if (pack.Robot530.Any())
+                            {
+                                var value = pack.Robot530.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Robot530).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Robot531>[]))
+                        {
+                            if (pack.Robot531.Any())
+                            {
+                                var value = pack.Robot531.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Robot531).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM520>[]))
+                        {
+                            if (pack.SRM520.Any())
+                            {
+                                var value = pack.SRM520.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_SRM520).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM521>[]))
+                        {
+                            if (pack.SRM521.Any())
+                            {
+                                var value = pack.SRM521.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_SRM521).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_SRM537>[]))
+                        {
+                            if (pack.SRM537.Any())
+                            {
+                                var value = pack.SRM537.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_SRM537).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station520>[]))
+                        {
+                            if (pack.Station520.Any())
+                            {
+                                var value = pack.Station520.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Station520).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station521>[]))
+                        {
+                            if (pack.Station521.Any())
+                            {
+                                var value = pack.Station521.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Station521).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station523>[]))
+                        {
+                            if (pack.Station523.Any())
+                            {
+                                var value = pack.Station523.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Station523).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station524>[]))
+                        {
+                            if (pack.Station524.Any())
+                            {
+                                var value = pack.Station524.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Station524).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station525>[]))
+                        {
+                            if (pack.Station525.Any())
+                            {
+                                var value = pack.Station525.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Station525).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station90>[]))
+                        {
+                            if (pack.Station90.Any())
+                            {
+                                var value = pack.Station90.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Station90).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Station91>[]))
+                        {
+                            if (pack.Station91.Any())
+                            {
+                                var value = pack.Station91.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Station91).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss520>[]))
+                        {
+                            if (pack.Truss520.Any())
+                            {
+                                var value = pack.Truss520.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Truss520).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss521>[]))
+                        {
+                            if (pack.Truss521.Any())
+                            {
+                                var value = pack.Truss521.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Truss521).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss523>[]))
+                        {
+                            if (pack.Truss523.Any())
+                            {
+                                var value = pack.Truss523.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Truss523).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss530>[]))
+                        {
+                            if (pack.Truss530.Any())
+                            {
+                                var value = pack.Truss530.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Truss530).Name;
+                            }
+                        }
+                        else if (ps.PropertyType == typeof(ProtocolData<WCS_Truss531>[]))
+                        {
+                            if (pack.Truss531.Any())
+                            {
+                                var value = pack.Truss531.Select(x => x.Data).ToList();
+                                var sql = db.Insertable(value).ToSqlString();
+                                db.Ado.ExecuteCommand(sql);
+                                typeName = typeof(WCS_Truss531).Name;
+                            }
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        World.Log($"错误内容:{e.Message}");
+                    }
+                    finally
+                    {
+                        sw10.Stop();
+                        World.Log($"执行耗时:{typeName}:{sw10.ElapsedMilliseconds}");
+                    }
+                });
+
+                sw.Stop();
+                World.Log($"数据处理耗时:{sw.ElapsedMilliseconds}");
+            }
+            catch (Exception e)
+            {
+                World.Log($"错误内容:{e.Message}");
+            }
+        }
+
+        private Type GetProtocolType(Type source)
+        {
+            var t = source.GetInterfaces().FirstOrDefault(v => v.GetInterfaces().Any(d => d.Name == "IProtocol"));
+            var t1 = source.GetInterfaces().FirstOrDefault(v => v.GetInterfaces().Any(d => d.Name == "IProtocol"));
+            return t;
+        }
+
+        private object AppendLock = new object();
+
+        public StringBuilder Append(StringBuilder sql, string value)
+        {
+            lock (AppendLock)
+            {
+                return sql.Append(value);
+            }
+        }
+
+        public string GetString(string value)
+        {
+            return value.Replace("INSERT INTO ", "")
+                .Replace(",N'", ",'")
+                .Replace("\0", "")
+                .Replace("wcs_", "")
+                .Replace("(N'", "('") + "\r";
+        }
+    }
+}

+ 3 - 4
WCS.WorkEngineering/WCS.WorkEngineering.csproj

@@ -20,13 +20,12 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="MessagePack" Version="2.5.108" />
-    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.5" />
-    <PackageReference Include="WCS.Entity.Protocol" Version="1.0.6.8" />
+    <PackageReference Include="MessagePack" Version="2.5.140" />
   </ItemGroup>
 
   <ItemGroup>
-    <ProjectReference Include="..\..\..\ServiceCenter\ServiceCenter.csproj" />
+    <ProjectReference Include="..\..\WcsFramework\ServiceCenter\ServiceCenter.csproj" />
+    <ProjectReference Include="..\..\WcsFramework\业务工程\分拣库\WCS.Entity.Protocol\WCS.Entity.Protocol.csproj" />
   </ItemGroup>
 
   <ItemGroup>

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 748 - 685
WCS.WorkEngineering/WorkStart.cs


+ 19 - 0
WCS.WorkEngineering/Worlds/DataWorld.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WCS.WorkEngineering.Worlds
+{
+    [Description("数据采集世界")]
+    public class DataWorld : MainWorld
+    {
+        /// <summary>
+        ///  世界执行周期间隔
+        ///  单位:毫秒
+        /// </summary>
+        protected override int Interval => 500;
+    }
+}

+ 1 - 1
WCS.WorkEngineering/Worlds/MainWorld.cs

@@ -30,7 +30,7 @@ namespace WCS.WorkEngineering.Worlds
         ///  世界执行周期间隔
         ///  单位:毫秒
         /// </summary>
-        protected override int Interval => 500;
+        protected override int Interval => 300;
 
         /// <summary>
         ///  更新前执行,重写改方法后请自行添加执行内容

+ 30 - 0
分拣中心数据采集.sln

@@ -7,6 +7,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WCS.Service", "WCS.Service\
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WCS.WorkEngineering", "WCS.WorkEngineering\WCS.WorkEngineering.csproj", "{8649A293-18DF-47CB-BB15-B16B0A8FB74F}"
 EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlSugar", "..\..\..\..\Code\SqlSugar\Src\Asp.NetCore2\SqlSugar\SqlSugar.csproj", "{D81E04A6-920F-4F37-9455-8C2CE26BEFF6}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WCS.Entity.Protocol", "..\WcsFramework\业务工程\分拣库\WCS.Entity.Protocol\WCS.Entity.Protocol.csproj", "{D0BA866F-F6D3-4BE8-AB0A-9F9893DABCDA}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WCS.Entity", "..\WcsFramework\WCS.Entity\WCS.Entity.csproj", "{F961CCFA-82D8-411D-94D4-12BAAAEE3468}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceCenter", "..\WcsFramework\ServiceCenter\ServiceCenter.csproj", "{0120E012-9793-4E30-BEF0-C0A19742604C}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WCS.Core", "..\WcsFramework\WCS.Core\WCS.Core.csproj", "{6FBE4D58-C5E0-4804-9D24-13D69938602B}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -21,6 +31,26 @@ Global
 		{8649A293-18DF-47CB-BB15-B16B0A8FB74F}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{8649A293-18DF-47CB-BB15-B16B0A8FB74F}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{8649A293-18DF-47CB-BB15-B16B0A8FB74F}.Release|Any CPU.Build.0 = Release|Any CPU
+		{D81E04A6-920F-4F37-9455-8C2CE26BEFF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{D81E04A6-920F-4F37-9455-8C2CE26BEFF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{D81E04A6-920F-4F37-9455-8C2CE26BEFF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{D81E04A6-920F-4F37-9455-8C2CE26BEFF6}.Release|Any CPU.Build.0 = Release|Any CPU
+		{D0BA866F-F6D3-4BE8-AB0A-9F9893DABCDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{D0BA866F-F6D3-4BE8-AB0A-9F9893DABCDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{D0BA866F-F6D3-4BE8-AB0A-9F9893DABCDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{D0BA866F-F6D3-4BE8-AB0A-9F9893DABCDA}.Release|Any CPU.Build.0 = Release|Any CPU
+		{F961CCFA-82D8-411D-94D4-12BAAAEE3468}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{F961CCFA-82D8-411D-94D4-12BAAAEE3468}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{F961CCFA-82D8-411D-94D4-12BAAAEE3468}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{F961CCFA-82D8-411D-94D4-12BAAAEE3468}.Release|Any CPU.Build.0 = Release|Any CPU
+		{0120E012-9793-4E30-BEF0-C0A19742604C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{0120E012-9793-4E30-BEF0-C0A19742604C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{0120E012-9793-4E30-BEF0-C0A19742604C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{0120E012-9793-4E30-BEF0-C0A19742604C}.Release|Any CPU.Build.0 = Release|Any CPU
+		{6FBE4D58-C5E0-4804-9D24-13D69938602B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{6FBE4D58-C5E0-4804-9D24-13D69938602B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{6FBE4D58-C5E0-4804-9D24-13D69938602B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{6FBE4D58-C5E0-4804-9D24-13D69938602B}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно