林豪 左 1 year ago
parent
commit
2816a1bd6e

+ 27 - 19
ServiceCenter/Logs/LogHub.cs

@@ -153,6 +153,7 @@ namespace ServiceCenter.Logs
             {
                 var sw = new Stopwatch();
                 sw.Start();
+                int index = 0;
                 List<LogModel> logs = new List<LogModel>();
                 try
                 {
@@ -165,35 +166,43 @@ namespace ServiceCenter.Logs
                         logs = ret.Select(JsonConvert.DeserializeObject<LogModel>).ToList();
                     }
 
-                    Parallel.ForEach(logs.Where(log => log != null).GroupBy(x => x.path), paths =>
+                    foreach (var paths in logs.Where(log => log != null).GroupBy(x => x.path))
                     {
-                        Parallel.ForEach(paths.GroupBy(x => x.Title), title =>
+                        foreach (var title in paths.GroupBy(x => x.Title))
                         {
                             var log = title.First();
                             var cons = title.OrderBy(x => x.Time).Select(x => x.Con);
                             if (!Directory.Exists(log.path)) Directory.CreateDirectory(log.path);/*.txt*/
-
                             var path = Path.Combine(log.path, log.Title);
-                            var fileInfo = new FileInfo(path);
-                            var fileMb = fileInfo.Length / 1024 / 1024;
-                            if (fileMb > 20) //如果当前文件大小超过20MB 开始封存此文件,
+                            if (!File.Exists(path))
+                            {
+                                File.AppendAllLines(path, cons);
+                            }
+                            else
                             {
-                                var fileIndex = 1; //文件索引
-                                var isSave = false;
-                                while (!isSave) //未保存成功
+                                var fileInfo = new FileInfo(path);
+                                var fileMb = fileInfo.Length / 1024 / 1024;
+                                if (fileMb > 20) //如果当前文件大小超过20MB 开始封存此文件,
                                 {
-                                    var newPath = Path.Combine(log.path, log.Title.Replace(".txt", $"{fileIndex}.txt"));//使用文件索引头来判断当前索引对应的标题文件是否存在
-                                    if (!File.Exists(newPath))//不存在,将现有文件更名成新的文件名
+                                    var fileIndex = 1; //文件索引
+                                    var isSave = false;
+                                    while (!isSave) //未保存成功
                                     {
-                                        File.Move(path, newPath);
-                                        isSave = true;
+                                        var newPath = Path.Combine(log.path, log.Title.Replace(".txt", $"{fileIndex}.txt"));//使用文件索引头来判断当前索引对应的标题文件是否存在
+                                        if (!File.Exists(newPath))//不存在,将现有文件更名成新的文件名
+                                        {
+                                            File.Move(path, newPath);
+                                            isSave = true;
+                                        }
+                                        fileIndex++;
                                     }
-                                    fileIndex++;
                                 }
+                                File.AppendAllLines(path, cons);
                             }
-                            File.AppendAllLines(path, cons);
-                        });
-                    });
+
+                            index++;
+                        }
+                    }
                 }
                 catch (Exception ex)
                 {
@@ -203,8 +212,7 @@ namespace ServiceCenter.Logs
                 sw.Stop();
                 var path1 = $"D:\\WCSLogs\\{DateTime.Now.yyyyMMdd()}\\日志处理进程";
                 if (!Directory.Exists(path1)) Directory.CreateDirectory(path1);
-                var count = logs.Where(log => log != null).GroupBy(x => x.path).SelectMany(x => x.GroupBy(t => t.Title)).Count();
-                File.AppendAllText(Path.Combine(path1, "耗时.txt"), $"{DateTime.Now.yyyyMMddhhmmssf()}耗时:{sw.ElapsedMilliseconds}--{logs.Count}--{count}\n");
+                File.AppendAllText(Path.Combine(path1, "耗时.txt"), $"{DateTime.Now.yyyyMMddhhmmssf()}耗时:{sw.ElapsedMilliseconds}--{logs.Count}--{index}\n");
                 if (sw.ElapsedMilliseconds >= toao) continue;
                 var time = toao - sw.ElapsedMilliseconds.ToInt();
                 Thread.Sleep(time);

+ 2 - 2
WCS.Service/appsettings.json

@@ -7,7 +7,7 @@
     }
   },
   "ConnectionStrings": {
-    //"Redis": "10.30.37.2:6379,database=0,prefix=Sorting:"
-    "Redis": "127.0.0.1,database=0,prefix=Sorting:"
+    "Redis": "10.30.37.2:6379,database=0,prefix=Sorting:"
+    //"Redis": "127.0.0.1,database=0,prefix=Sorting:"
   }
 }

+ 1 - 1
业务工程/分拣库/WCS.WorkEngineering/Extensions/DeviceExtension.cs

@@ -56,7 +56,7 @@ namespace WCS.WorkEngineering.Extensions
                         Port = 102,
                         Rack = 0,
                         Slot = 1,
-                        //Type = PLCType.Siemens
+                        Type = PLCType.Siemens
                     }
                 }
             };

+ 111 - 27
业务工程/分拣库/WCS.WorkEngineering/Systems/DataCollectionSysyem.cs

@@ -9,8 +9,13 @@ 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;
 
@@ -65,11 +70,11 @@ namespace WCS.WorkEngineering.Systems
                 var sw = new Stopwatch();
                 sw.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;
-                var frame = DateTime.Now;
                 Parallel.ForEach(ps, p =>
                 {
                     if (!p.PropertyType.IsArray) return;
@@ -99,7 +104,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, protObj.Frame);
+                                var value = WCS.Core.Extentions.Copy(protObj, entType, frame);
                                 t.GetProperty("Data").SetValue(obj, value);
                                 t.GetProperty("Frame").SetValue(obj, protObj.Frame);
                                 entType.GetProperty("Code").SetValue(value, x.Code);
@@ -221,31 +226,110 @@ namespace WCS.WorkEngineering.Systems
                 var sw4 = new Stopwatch();
                 sw4.Start();
 
-                if (pack.BCR80.Any()) db.Insertable(pack.BCR80.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.BCR81.Any()) db.Insertable(pack.BCR81.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.BCR83.Any()) db.Insertable(pack.BCR83.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.RGV520.Any()) db.Insertable(pack.RGV520.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.RGV521.Any()) db.Insertable(pack.RGV521.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Robot520.Any()) db.Insertable(pack.Robot520.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Robot521.Any()) db.Insertable(pack.Robot521.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Robot522.Any()) db.Insertable(pack.Robot522.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Robot530.Any()) db.Insertable(pack.Robot530.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Robot531.Any()) db.Insertable(pack.Robot531.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.SRM520.Any()) db.Insertable(pack.SRM520.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.SRM521.Any()) db.Insertable(pack.SRM521.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.SRM537.Any()) db.Insertable(pack.SRM537.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Station520.Any()) db.Insertable(pack.Station520.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Station521.Any()) db.Insertable(pack.Station521.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Station523.Any()) db.Insertable(pack.Station523.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Station524.Any()) db.Insertable(pack.Station524.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Station525.Any()) db.Insertable(pack.Station525.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Station90.Any()) db.Insertable(pack.Station90.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Station91.Any()) db.Insertable(pack.Station91.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Truss520.Any()) db.Insertable(pack.Truss520.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Truss521.Any()) db.Insertable(pack.Truss521.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Truss523.Any()) db.Insertable(pack.Truss523.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Truss530.Any()) db.Insertable(pack.Truss530.Select(x => x.Data).ToList()).ExecuteCommand();
-                if (pack.Truss531.Any()) db.Insertable(pack.Truss531.Select(x => x.Data).ToList()).ExecuteCommand();
+                Parallel.ForEach(pack.GetType().GetProperties().OrderBy(x => x.Name), ps =>
+                {
+                    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()).ExecuteCommand();
+                    }
+                    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).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();
+                    }
+                });
+
                 sw4.Stop();
                 World.Log($"执行SQL耗时:{sw4.ElapsedMilliseconds}");
 

+ 7 - 7
业务工程/分拣库/WCS.WorkEngineering/WorkStart.cs

@@ -316,7 +316,7 @@ namespace WCS.WorkEngineering
             {
                 new TrussSegmentInfo( 1, "10.30.37.211"),
                 new TrussSegmentInfo( 2, "10.30.37.217"),
-                //new TrussSegmentInfo( 3, "10.30.37.223")
+                new TrussSegmentInfo( 3, "10.30.37.223")
             };
 
             foreach (var item in TrussInfo)
@@ -333,7 +333,7 @@ namespace WCS.WorkEngineering
                 //桁架
                 new("10.30.37.211",new  List<int>(){1685,1686,1687,1688,1689,1690,1675,1674,1673,1672,1671,1670,1677,1678,1679,1680,1665,1664,1663,1662}), //分拣库一
                 new("10.30.37.217",new  List<int>(){1715,1716,1717,1718,1719,1720,1705,1704,1703,1702,1701,1700,1707,1708,1709,1710,1695,1694,1693,1692}), //分拣库二
-                //new("10.30.37.223",new  List<int>(){1745,1746,1747,1748,1749,1750,1735,1734,1733,1732,1731,1730,1737,1738,1739,1740,1725,1724,1723,1722}), //分拣库三
+                new("10.30.37.223",new  List<int>(){1745,1746,1747,1748,1749,1750,1735,1734,1733,1732,1731,1730,1737,1738,1739,1740,1725,1724,1723,1722}), //分拣库三
             };
 
             foreach (var item in tuples1)
@@ -361,8 +361,8 @@ namespace WCS.WorkEngineering
                 new("10.30.37.232",new  List<int>(){ 1681, 1676}), //库一南
                 new("10.30.37.234",new  List<int>(){ 1696, 1691}), //库二北
                 new("10.30.37.236",new  List<int>(){ 1711, 1706}), //库二南
-                //new("10.30.37.238",new  List<int>(){ 1726, 1721}), //库三北
-                //new("10.30.37.240",new  List<int>(){ 1736, 1741}), //库三南
+                new("10.30.37.238",new  List<int>(){ 1726, 1721}), //库三北
+                new("10.30.37.240",new  List<int>(){ 1736, 1741}), //库三南
             };
 
             foreach (var item in tuples21)
@@ -388,8 +388,8 @@ namespace WCS.WorkEngineering
                 new( 2, "10.30.37.232"),
                 new( 3, "10.30.37.234"),
                 new( 4, "10.30.37.236"),
-                //new( 5, "10.30.37.238"),
-                //new( 6, "10.30.37.240"),
+                new( 5, "10.30.37.238"),
+                new( 6, "10.30.37.240"),
             };
 
             foreach (var item in TrussInfo1)
@@ -407,7 +407,7 @@ namespace WCS.WorkEngineering
 
             int ip = 41;
 
-            for (int i = 0; i <= 3; i++)
+            for (int i = 0; i <= 5; i++)
             {
                 var srm = new Device($"SRM{i + 1}");
                 srm.AddFlag(DeviceFlags.堆垛机);