林豪 左 3 年之前
父节点
当前提交
cfa60540af

+ 12 - 15
WCS.Core/DbHelper/DB.cs

@@ -22,24 +22,21 @@ namespace WCS.Core.DbHelper
         /// </summary>
         public static string DefaultDbContextType { get; private set; } = null!;
 
+        /// <summary>
+        ///
+        /// </summary>
+        /// <typeparam name="T">业务代码</typeparam>
+        /// <param name="func">业务逻辑</param>
+        /// <returns></returns>
+        /// <exception cref="Exception"></exception>
         public static T Do<T>(Func<Db, T> func)
         {
             var db = new Db();
-            try
-            {
-                db.Default.BeginTran();
-                var res = func(db);
-                db.Default.CommitTran();
-                return res;
-            }
-            catch (Exception ex)
-            {
-                //var qty = ex.EntityValidationErrors.Count();
-                //var info = ex.EntityValidationErrors.First();
-                //var msg = "有" + qty + "条数据验证失败,首条错误信息:\n" + string.Join("\n", info.MemberNames) + "\n" + (info.ErrorMessage ?? "");
-                Console.WriteLine(ex.Message);
-                throw new Exception(ex.Message);
-            }
+
+            db.Default.BeginTran();
+            var res = func(db);
+            db.Default.CommitTran();
+            return res;
         }
 
         public static void Do(Action<Db> act)

+ 1 - 1
WCS.Core/DebugPublisher.cs

@@ -13,7 +13,7 @@ namespace WCS.Core
             try
 
             {
-                RedisHelper.Default().Publish(channel, msg);
+                RedisHelper.Default.Publish(channel, msg);
             }
             catch
             {

+ 3 - 1
WCS.Core/EntityEx.cs

@@ -34,7 +34,9 @@ namespace WCS.Core
 
         public Device(WCS_DEVICE entity) : base(entity)
         {
-            Data = entity.DEVICEPROTOCOLS.Single(v => v.DB.PROTOCOL == typeof(T).AssemblyQualifiedName).Data<T>();
+            //新增一个报错
+            var data = entity.DEVICEPROTOCOLS.FirstOrDefault(v => v.DB.PROTOCOL == typeof(T).AssemblyQualifiedName) ?? throw new Exception($"设备{entity.CODE}对应PROTOCOL有误,请检查相关配置");
+            Data = data.Data<T>();
         }
     }
 

+ 1 - 1
WCS.Core/Properties/PublishProfiles/FolderProfile.pubxml

@@ -8,6 +8,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
     <Platform>Any CPU</Platform>
     <PublishDir>D:\XM\Release\DLL</PublishDir>
     <PublishProtocol>FileSystem</PublishProtocol>
-    <VersionPrefix>1.0.8</VersionPrefix>
+    <VersionPrefix>1.1.0</VersionPrefix>
   </PropertyGroup>
 </Project>

+ 9 - 4
WCS.Core/Redis/RedisHelper.cs

@@ -32,11 +32,16 @@ namespace WCS.Core.Redis
         /// <summary>
         /// 默认链接
         /// </summary>
-        public static RedisClient Default()
+        public static RedisClient Default
         {
-            if (DefaultDbContextType == null)
-                throw new Exception("请先设置默认RedisDB库,调用静态方法SetDefaultDbContextType()");
-            return Context(DefaultDbContextType);
+            get
+            {
+                {
+                    if (DefaultDbContextType == null)
+                        throw new Exception("请先设置默认RedisDB库,调用静态方法SetDefaultDbContextType()");
+                    return Context(DefaultDbContextType);
+                }
+            }
         }
 
         /// <summary>

+ 1 - 2
WCS.Entity.Protocol/Properties/PublishProfiles/FolderProfile.pubxml

@@ -8,6 +8,5 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
     <Platform>Any CPU</Platform>
     <PublishDir>D:\XM\Release\DLL</PublishDir>
     <PublishProtocol>FileSystem</PublishProtocol>
-    <VersionPrefix>1.0.2</VersionPrefix>
   </PropertyGroup>
-</Project>
+</Project>

+ 1 - 0
WCS.Entity.Protocol/WCS.Entity.Protocol.csproj

@@ -5,6 +5,7 @@
     <Nullable>enable</Nullable>
     <GenerateDocumentationFile>True</GenerateDocumentationFile>
     <Description>与PLC交互协议、及与具体项目强关联的实体模型</Description>
+    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
   </PropertyGroup>
 
   <ItemGroup>

+ 19 - 22
WCS.Service/ProtocolProxy.cs

@@ -1,15 +1,13 @@
-using FreeRedis;
-using MessagePack;
+using MessagePack;
 using MessagePack.Resolvers;
-using SqlSugar;
 using System.Collections.Concurrent;
 using System.Diagnostics;
 using System.Linq.Dynamic.Core;
-using System.Reflection;
 using WCS.Core;
 using WCS.Core.BaseExtensions;
 using WCS.Core.DataTrans;
 using WCS.Core.DbHelper;
+using WCS.Core.Redis;
 using WCS.Entity;
 using WCS.Entity.Protocol;
 
@@ -17,11 +15,8 @@ namespace WCS.Service
 {
     public class ProtocolProxy : ProtocolProxyBase
     {
-        private readonly MethodInfo _setMethod;
-
         public ProtocolProxy(string id, WCS_DATABLOCK db, ushort start, WCS_DEVICEPROTOCOL protocol) : base(id, db, start, protocol)
         {
-            _setMethod = typeof(SqlSugarScope).GetMethod("Queryable", new Type[] { })?.MakeGenericMethod(this.ProtocolDataType);
         }
 
         private static readonly ConcurrentDictionary<Type, object[]> LastDatas = new();
@@ -36,8 +31,14 @@ namespace WCS.Service
             var list = new List<WCS_PROTOCOLDATA>();
             foreach (var data in datas)
             {
-                if (data.DEVICECOD == Protocol.DEVICE.CODE)
-                    list.Add(data);
+                try
+                {
+                    if (data.DEVICECOD == Protocol.DEVICE.CODE)
+                        list.Add(data);
+                }
+                catch
+                {
+                }
             }
 
             if (list.Count > 1)
@@ -78,26 +79,22 @@ namespace WCS.Service
             return newobj;
         }
 
-        private static readonly RedisClient Redis;
-        public static RedisClient ConcurrencyControlRedis;
-        public static RedisClient Ygwms150Redis;
-        public static RedisClient Ygwcs150Redis;
-
         static ProtocolProxy()
         {
             MessagePackSerializer.DefaultOptions = StandardResolver.Options.WithCompression(MessagePackCompression.Lz4Block);
-            Redis = new RedisClient("127.0.0.1,database=10");
-            Redis.Serialize = obj =>
+            RedisHelper.CreateContext("127.0.0.1,database=0", "default", true);
+            RedisHelper.CreateContext("127.0.0.1,database=10", "3D");
+            RedisHelper.CreateContext("127.0.0.1,database=1", "ConcurrencyControlRedis");
+            RedisHelper.Default.Serialize = obj =>
             {
                 var bytes = MessagePackSerializer.Serialize(obj);
                 return bytes;
             };
-            Redis.DeserializeRaw = (bytes, type) =>
+            RedisHelper.Default.DeserializeRaw = (bytes, type) =>
             {
                 var obj = MessagePackSerializer.Deserialize(type, bytes);
                 return obj;
             };
-            ConcurrencyControlRedis = new RedisClient("127.0.0.1,database=1");
         }
 
         public override void Publish(string code, WCS_PROTOCOLDATA obj)
@@ -173,18 +170,18 @@ namespace WCS.Service
 
                 var sw = new Stopwatch();
                 sw.Start();
-                Redis.Set(nameof(DeviceDataPack), pack);
+                RedisHelper.Default.Set(nameof(DeviceDataPack), pack);
                 sw.Stop();
                 Console.ForegroundColor = ConsoleColor.Blue;
                 Console.WriteLine($"Redis耗时{sw.ElapsedMilliseconds}");
                 Console.ResetColor();
 
-                Redis.RPush("Packs", pack);
+                RedisHelper.Default.RPush("Packs", pack);
 
-                var len = Redis.LLen("Packs");
+                var len = RedisHelper.Default.LLen("Packs");
                 if (len > 150000)
                 {
-                    Redis.LTrim("Packs", 20000, len);
+                    RedisHelper.Default.LTrim("Packs", 20000, len);
                 }
 
                 foreach (var data in AllDatas)

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

@@ -25,8 +25,11 @@
     <PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
     <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.8" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
-    <PackageReference Include="WCS.Core" Version="1.0.8" />
-    <PackageReference Include="WCS.Entity.Protocol" Version="1.0.2" />
-    <PackageReference Include="WCS.WebApi" Version="1.0.2" />
+    <PackageReference Include="WCS.Core" Version="1.1.0" />
+    <PackageReference Include="WCS.WebApi" Version="1.0.4" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\WCS.WorkEngineering\WCS.WorkEngineering.csproj" />
   </ItemGroup>
 </Project>

+ 2 - 2
WCS.WebApi/APICaller.cs

@@ -1,11 +1,11 @@
-using Log;
-using Newtonsoft.Json;
+using Newtonsoft.Json;
 using System;
 using System.Collections.Concurrent;
 using System.Diagnostics;
 using System.IO;
 using System.Net;
 using System.Text;
+using WCS.Core.Log;
 using static System.Net.WebRequest;
 
 namespace WCS.WebApi

+ 1 - 1
WCS.WebApi/Properties/PublishProfiles/FolderProfile.pubxml

@@ -8,6 +8,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
     <Platform>Any CPU</Platform>
     <PublishDir>D:\XM\Release\DLL</PublishDir>
     <PublishProtocol>FileSystem</PublishProtocol>
-    <VersionPrefix>1.0.2</VersionPrefix>
+    <VersionPrefix>1.0.4</VersionPrefix>
   </PropertyGroup>
 </Project>

+ 2 - 2
WCS.WebApi/WCS.WebApi.csproj

@@ -10,8 +10,8 @@
     <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
     <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.8" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
-    <PackageReference Include="WCS.Core" Version="1.0.6" />
-    <PackageReference Include="WCS.Entity.Protocol" Version="1.0.2" />
+    <PackageReference Include="WCS.Core" Version="1.0.8" />
+    <PackageReference Include="WCS.Entity.Protocol" Version="1.0.0" />
   </ItemGroup>
 
 </Project>

+ 2 - 2
WCS.WebApi/WCSApi.cs

@@ -1,8 +1,8 @@
-using DbHelper;
-using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using WCS.Core.DbHelper;
 using WCS.Entity;
 using WCS.Entity.Protocol;
 using WCS.WebApi.WMS;

+ 3 - 3
WCS.WebApi/WMS/WMS.cs

@@ -1,10 +1,10 @@
-using Log;
-using Newtonsoft.Json;
+using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using WCS.BaseExtensions;
 using WCS.Core;
+using WCS.Core.BaseExtensions;
+using WCS.Core.Log;
 using WCS.WebApi.WMS.Request;
 using WCS.WebApi.WMS.Response;
 

+ 22 - 22
WCS.WorkEngineering/Extensions/DeviceExtension.cs

@@ -292,8 +292,8 @@ namespace WCS.Service.Extensions
             var key = $"WCS:Lock:{Entity.CODE}";
             try
             {
-                if (RedisHelper.Default().Get(key) != null) throw new WarnException($"[{Entity.CODE}]--触发并发管控");
-                RedisHelper.Default().Set(key, Entity.CODE);
+                if (RedisHelper.Default.Get(key) != null) throw new WarnException($"[{Entity.CODE}]--触发并发管控");
+                RedisHelper.Default.Set(key, Entity.CODE);
                 act(this);
             }
             catch (DoException ex)
@@ -310,7 +310,7 @@ namespace WCS.Service.Extensions
             }
             finally
             {
-                RedisHelper.Default().Del(key);
+                RedisHelper.Default.Del(key);
             }
         }
 
@@ -542,7 +542,7 @@ namespace WCS.Service.Extensions
         /// <returns></returns>
         public void BcrStationIsForbid()
         {
-            var config = RedisHelper.Default().Get("ForbidTubuEnter").Split(",");
+            var config = RedisHelper.Default.Get("ForbidTubuEnter").Split(",");
             if (config.Contains(Entity.CODE)) throw new WarnException("当前入库口已被禁用,请联系机修人员了解具体情况");
         }
     }
@@ -609,8 +609,8 @@ namespace WCS.Service.Extensions
 
             try
             {
-                if (RedisHelper.Default().Get(key) != null) throw new WarnException($"[{Entity.CODE}]--触发并发管控");
-                RedisHelper.Default().Set(key, Entity.CODE);
+                if (RedisHelper.Default.Get(key) != null) throw new WarnException($"[{Entity.CODE}]--触发并发管控");
+                RedisHelper.Default.Set(key, Entity.CODE);
                 act(this);
             }
             catch (DoException ex)
@@ -627,7 +627,7 @@ namespace WCS.Service.Extensions
             }
             finally
             {
-                RedisHelper.Default().Del(key);
+                RedisHelper.Default.Del(key);
             }
         }
     }
@@ -709,8 +709,8 @@ namespace WCS.Service.Extensions
 
             try
             {
-                if (RedisHelper.Default().Get(key) != null) throw new WarnException($"[{Entity.CODE}]--触发并发管控");
-                RedisHelper.Default().Set(key, Entity.CODE);
+                if (RedisHelper.Default.Get(key) != null) throw new WarnException($"[{Entity.CODE}]--触发并发管控");
+                RedisHelper.Default.Set(key, Entity.CODE);
                 act(this);
             }
             catch (DoException ex)
@@ -727,7 +727,7 @@ namespace WCS.Service.Extensions
             }
             finally
             {
-                RedisHelper.Default().Del(key);
+                RedisHelper.Default.Del(key);
             }
         }
 
@@ -1046,8 +1046,8 @@ namespace WCS.Service.Extensions
 
             try
             {
-                if (RedisHelper.Default().Get(key) != null) throw new WarnException($"[{Entity.CODE}]--触发并发管控");
-                RedisHelper.Default().Set(key, Entity.CODE);
+                if (RedisHelper.Default.Get(key) != null) throw new WarnException($"[{Entity.CODE}]--触发并发管控");
+                RedisHelper.Default.Set(key, Entity.CODE);
                 act(this);
             }
             catch (DoException ex)
@@ -1064,7 +1064,7 @@ namespace WCS.Service.Extensions
             }
             finally
             {
-                RedisHelper.Default().Del(key);
+                RedisHelper.Default.Del(key);
             }
         }
 
@@ -1080,30 +1080,30 @@ namespace WCS.Service.Extensions
                 if (Entity.CODE == "SRM3" || Entity.CODE == "SRM4")
                 {
                     key += "SRM3-SRM4-Out";
-                    if (RedisHelper.Default().Get(key) != null) throw new WarnException($"触发出库并发管控--[{Entity.CODE}]");
-                    RedisHelper.Default().Set(key, Entity.CODE);
+                    if (RedisHelper.Default.Get(key) != null) throw new WarnException($"触发出库并发管控--[{Entity.CODE}]");
+                    RedisHelper.Default.Set(key, Entity.CODE);
                 }
                 if (Entity.CODE == "SRM5" || Entity.CODE == "SRM6")
                 {
                     key += "SRM5-SRM6-Out";
-                    if (RedisHelper.Default().Get(key) != null) throw new WarnException($"触发出库并发管控--[{Entity.CODE}]");
-                    RedisHelper.Default().Set(key, Entity.CODE);
+                    if (RedisHelper.Default.Get(key) != null) throw new WarnException($"触发出库并发管控--[{Entity.CODE}]");
+                    RedisHelper.Default.Set(key, Entity.CODE);
                 }
 
                 if (Entity.CODE == "SRM7" || Entity.CODE == "SRM8")
                 {
                     key += "SRM7-SRM8-Out";
-                    if (RedisHelper.Default().Get(key) != null) throw new WarnException($"触发出库并发管控--[{Entity.CODE}]");
-                    RedisHelper.Default().Set(key, Entity.CODE);
+                    if (RedisHelper.Default.Get(key) != null) throw new WarnException($"触发出库并发管控--[{Entity.CODE}]");
+                    RedisHelper.Default.Set(key, Entity.CODE);
                 }
 
                 act(this);
             }
             finally
             {
-                if (Entity.CODE == "SRM3" || Entity.CODE == "SRM4") RedisHelper.Default().Del($"{key}SRM3-SRM4-Out");
-                if (Entity.CODE == "SRM5" || Entity.CODE == "SRM6") RedisHelper.Default().Del($"{key}SRM5-SRM6-Out");
-                if (Entity.CODE == "SRM7" || Entity.CODE == "SRM8") RedisHelper.Default().Del($"{key}SRM7-SRM8-Out");
+                if (Entity.CODE == "SRM3" || Entity.CODE == "SRM4") RedisHelper.Default.Del($"{key}SRM3-SRM4-Out");
+                if (Entity.CODE == "SRM5" || Entity.CODE == "SRM6") RedisHelper.Default.Del($"{key}SRM5-SRM6-Out");
+                if (Entity.CODE == "SRM7" || Entity.CODE == "SRM8") RedisHelper.Default.Del($"{key}SRM7-SRM8-Out");
             }
         }
 

+ 1 - 2
WCS.WorkEngineering/Extensions/TaskExtension.cs

@@ -2,8 +2,8 @@
 using System.Collections.Generic;
 using System.Linq;
 using WCS.Core;
-using WCS.Core.DataTrans;
 using WCS.Core.BaseExtensions;
+using WCS.Core.DataTrans;
 using WCS.Core.DbHelper;
 using WCS.Core.Log;
 using WCS.Entity;
@@ -50,7 +50,6 @@ namespace WCS.Service.Extensions
                            .ThenBy(v => v.Layer)
                            .ThenBy(v => v.Col)
                            .Take(2)
-                           .DistinctBy(v => v.Col)
                            .OrderBy(v => v.Col)
                            .ToArray();
         }

+ 3 - 2
WCS.WorkEngineering/Handlers/WorkHandler.cs

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
 using WCS.Core;
 using WCS.Core.BaseExtensions;
 using WCS.Core.DataTrans;
+using WCS.Core.Helpers;
 using WCS.Core.Log;
 using WCS.Entity;
 
@@ -23,9 +24,9 @@ namespace WCS.Service.Handlers
 
         protected WorkHandler()
         {
+            var a = ReflectionHelper.GetTypesByImplementInterface<Work>();
             //所有被声明的处理器
-            var arr = Assembly.GetEntryAssembly()
-                ?.GetTypes().Where(v => v.IsSubclassOf(typeof(Work))).Where(v =>
+            var arr = ReflectionHelper.GetTypesByImplementInterface<Work>().Where(v =>
                 {
                     var attr = v.GetCustomAttribute<WorkTitleAttribute>();
                     if (attr == null)

+ 1 - 1
WCS.WorkEngineering/Properties/PublishProfiles/FolderProfile.pubxml

@@ -8,6 +8,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
     <Platform>Any CPU</Platform>
     <PublishDir>D:\XM\Release\DLL</PublishDir>
     <PublishProtocol>FileSystem</PublishProtocol>
-    <VersionPrefix>1.0.3</VersionPrefix>
+    <VersionPrefix>1.0.4</VersionPrefix>
   </PropertyGroup>
 </Project>

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

@@ -8,10 +8,10 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="WCS.Core" Version="1.0.7" />
+    <PackageReference Include="WCS.Core" Version="1.1.0" />
     <PackageReference Include="WCS.Entity" Version="1.0.4" />
-    <PackageReference Include="WCS.Entity.Protocol" Version="1.0.2" />
-    <PackageReference Include="WCS.WebApi" Version="1.0.2" />
+    <PackageReference Include="WCS.Entity.Protocol" Version="1.0.0" />
+    <PackageReference Include="WCS.WebApi" Version="1.0.4" />
   </ItemGroup>
 
 </Project>