林豪 左 3 år sedan
förälder
incheckning
9b786ae6c2

+ 16 - 14
DBHelper-SqlSugar/DB.cs

@@ -80,19 +80,14 @@ namespace DBHelper_SqlSugar
         /// <returns></returns>
         public SqlSugarClient CreateContext(ConnectionConfig config, string key)
         {
-            var ctx = _contexts.FirstOrDefault(v => v.key == key);
+            var ctx = _contexts.FirstOrDefault(v => v.Key == key);
             if (ctx != null) return ctx.Client;
-            ctx = new ContextList()
+            ctx = new ContextList(key, new SqlSugarClient(new ConnectionConfig()
             {
-                key = key,
-                Client = new SqlSugarClient(new ConnectionConfig()
-                {
-                    ConnectionString = "连接符字串",
-                    DbType = DbType.SqlServer,
-                    IsAutoCloseConnection = true
-                }),
-                ConnectionConfig = config
-            };
+                ConnectionString = "连接符字串",
+                DbType = DbType.SqlServer,
+                IsAutoCloseConnection = true
+            }), config);
 
             _contexts.Add(ctx);
             return ctx.Client;
@@ -100,19 +95,26 @@ namespace DBHelper_SqlSugar
 
         public SqlSugarClient Context(string key)
         {
-            var ctx = _contexts.FirstOrDefault(v => v.key == key);
+            var ctx = _contexts.FirstOrDefault(v => v.Key == key);
             if (ctx == null) throw new Exception("没有对应的链接,请先调用创建");
             return ctx.Client;
         }
     }
 
     /// <summary>
-    /// 找到
+    /// 链接
     /// </summary>
     public class ContextList
 
     {
-        public string key { get; set; }
+        public ContextList(string key, SqlSugarClient client, ConnectionConfig connectionConfig)
+        {
+            this.Key = key;
+            Client = client;
+            ConnectionConfig = connectionConfig;
+        }
+
+        public string Key { get; set; }
 
         public SqlSugarClient Client { get; set; }
 

+ 1 - 0
DBHelper-SqlSugar/DBHelper-SqlSugar.csproj

@@ -7,6 +7,7 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="Logs" Version="1.0.0" />
     <PackageReference Include="SqlSugarCore" Version="5.0.9.1" />
   </ItemGroup>
 

BIN
DLL/PLC.Siemens.dll


+ 179 - 0
Logs/InfoLog.cs

@@ -0,0 +1,179 @@
+using System.Collections.Generic;
+
+namespace Logs
+{
+    /// <summary>
+    /// 信息日志
+    /// </summary>
+    public class InfoLog : ILogType
+    {
+        /// <summary>
+        /// 日志名称
+        /// </summary>
+        public string LogName => "Info";
+
+        /// <summary>
+        /// 信息日志
+        /// </summary>
+        public static ILogType Log { get; set; }
+
+        /// <summary>
+        /// 日志子项集合
+        /// </summary>
+        public Dictionary<string, string> SubLogNames { get; set; }
+
+        static InfoLog()
+        {
+            Log ??= new InfoLog();
+        }
+
+        public InfoLog()
+        {
+            SubLogNames = new Dictionary<string, string>
+            {
+                ["INFO"] = "Info"
+            };
+            LogHelper.Init(this);
+        }
+
+        /// <summary>
+        /// 系统执行信息 
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_INIT(string msg)
+        {
+            Log.Info(msg, "INFO_INIT");
+        }
+
+        /// <summary>
+        /// 系统执行信息
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_SRMALARM(string msg)
+        {
+            Log.Info(msg, "INFO_SRMALARM");
+        }
+
+        /// <summary>
+        /// 系统执行信息  基本检查条件不满足时记录
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_INFO(string msg)
+        {
+            Log.Info(msg, "INFO_INFO");
+        }
+
+        /// <summary>
+        /// 系统执行错误
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_ERROR(string msg)
+        {
+            Log.Error(msg, "INFO_ERROR");
+            //Console.WriteLine(msg);
+        }
+
+        /// <summary>
+        /// 系统执行警告 所有一直错误都归类为警告
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_WARN(string msg)
+        {
+            Log.Warn(msg, "INFO_WARN");
+            //Console.WriteLine(msg);
+        }
+
+        /// <summary>
+        /// 系统执行警告 所有一直错误都归类为警告,存入数据库
+        /// </summary>
+        /// <param name="msg">错误内容</param>
+        /// <param name="code">设备</param>
+        public static void INFO_WarnDb(string msg, string code)
+        {
+            Log.Warn(msg, "INFO_WARN");
+            //WCS.Service.Helpers.LogHelper.AddWCS_EXCEPTION(msg, code, type.ToString());
+            //WMS.TaskException(code, msg);
+        }
+
+        /// <summary>
+        /// 堆垛机写入记录
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_SRMINFO(string msg)
+        {
+            Log.Info(msg, "INFO_SRMINFO");
+        }
+
+        /// <summary>
+        /// 任务状态更新记录
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_SYTASKSTATUS(string msg)
+        {
+            Log.Info(msg, "INFO_SYTASKSTATUS");
+        }
+
+        /// <summary>
+        /// WMS请求记录
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_WMSREQUEST(string msg)
+        {
+            Log.Info(msg, "INFO_WMSREQUEST");
+        }
+
+        /// <summary>
+        /// PLC读取记录
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_PLCREADLOG(string msg)
+        {
+            Log.Info(msg, "INFO_PLCREADLOG");
+        }
+
+        /// <summary>
+        /// 计时器
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_TIMING(string msg)
+        {
+            Log.Info(msg, "INFO_TIMING");
+        }
+
+        /// <summary>
+        /// WCS异常上抛记录
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_I_WCS_GetExcTask(string msg)
+        {
+            Log.Info(msg, "INFO_UPEX");
+        }
+
+        /// <summary>
+        /// 任务创建记录
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_CREATETASKIN(string msg)
+        {
+            Log.Info(msg, "INFO_CREATETASKIN");
+        }
+
+        /// <summary>
+        /// RGV的写入记录
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_RGVINFO(string msg)
+        {
+            Log.Info(msg, "INFO_RGVINFO");
+        }
+
+        /// <summary>
+        /// AGV相关日志
+        /// </summary>
+        /// <param name="msg"></param>
+        public static void INFO_AGV(string msg)
+        {
+            Log.Info(msg, "INFO_AGV");
+        }
+    }
+}

+ 2 - 2
Logs/LogConfigModel.cs

@@ -10,7 +10,7 @@ namespace Logs
         /// <summary>
         /// 路径
         /// </summary>
-        public string LogPath { get; set; }
+        public string LogPath { get; set; } = null!;
 
         /// <summary>
         /// 保留天数
@@ -48,4 +48,4 @@ namespace Logs
         /// </summary>
         public Dictionary<string, string>? SubLogNames { get; set; }
     }
-}
+}

+ 15 - 1
Logs/Logs.csproj

@@ -1,8 +1,22 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     <TargetFramework>netstandard2.1</TargetFramework>
     <Nullable>enable</Nullable>
+    <AssemblyVersion>1.0.0.1</AssemblyVersion>
+    <FileVersion>1.0.0.1</FileVersion>
+    <UserSecretsId>0d0d7a9a-e261-49ea-a9ce-953f029a7a13</UserSecretsId>
+    <IsPublishable>True</IsPublishable>
+    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
+    <Version>1.0.0.1</Version>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+    <TreatWarningsAsErrors>True</TreatWarningsAsErrors>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
+    <TreatWarningsAsErrors>True</TreatWarningsAsErrors>
   </PropertyGroup>
 
   <ItemGroup>

+ 1 - 1
Projects/永冠OPP/WCS.Entity.Protocol/WCS.Entity.Protocol.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFramework>netstandard2.0</TargetFramework>
+    <TargetFramework>netstandard2.1</TargetFramework>
   </PropertyGroup>
 
   <ItemGroup>

+ 3 - 4
Projects/永冠OPP/WCS.Service/Program.cs

@@ -5,7 +5,6 @@ using System;
 using System.Runtime.InteropServices;
 using System.Threading;
 using System.Threading.Tasks;
-using WCS.Core;
 
 namespace WCS.Service
 {
@@ -25,7 +24,7 @@ namespace WCS.Service
             else
             {
                 Console.WriteLine("请勿重复运行");
-                InfoLog.INFO_INIT("请勿重复运行");
+                //InfoLog.INFO_INIT("请勿重复运行");
                 Task.Delay(2000).Wait();
             }
         }
@@ -51,7 +50,7 @@ namespace WCS.Service
                     })
                     .ConfigureServices((hostContext, services) =>
                     {
-                        services.AddDbContext<WCSDB>();
+                        //services.AddDbContext<WCSDB>();
                         services.AddHostedService<Worker>();
                     });
             }
@@ -63,4 +62,4 @@ namespace WCS.Service
                 });
         }
     }
-}
+}

+ 2 - 2
Projects/永冠OPP/WCS.Service/WCS.Service.csproj

@@ -13,6 +13,8 @@
   </ItemGroup>
 
   <ItemGroup>
+    <PackageReference Include="DBHelper-SqlSugar" Version="1.0.0" />
+    <PackageReference Include="Logs" Version="1.0.0.1" />
     <PackageReference Include="MessagePack" Version="2.3.85" />
     <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.3">
@@ -33,8 +35,6 @@
   </ItemGroup>
 
   <ItemGroup>
-    <ProjectReference Include="..\..\..\DBHelper-SqlSugar\DBHelper-SqlSugar.csproj" />
-    <ProjectReference Include="..\..\..\Logs\Logs.csproj" />
     <ProjectReference Include="..\..\..\WCS.Core\WCS.Core.csproj" />
     <ProjectReference Include="..\..\..\WCS.Entity\WCS.Entity.csproj" />
     <ProjectReference Include="..\WCS.Entity.Protocol\WCS.Entity.Protocol.csproj" />

+ 0 - 101
Projects/永冠OPP/WCS.Service/WCSDB.cs

@@ -1,101 +0,0 @@
-using DBHelper;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.Extensions.Configuration;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.Linq;
-using WCS.Entity;
-using WCS.Entity.Protocol;
-using WCS.Entity.Protocol.BCR;
-using WCS.Entity.Protocol.Station;
-
-namespace WCS.Service
-{
-    public class WCSDB : DbContext
-    {
-        protected override void OnModelCreating(ModelBuilder modelBuilder)
-        {
-            var fks = modelBuilder.Model.GetEntityTypes().SelectMany(v => v.GetForeignKeys()).Where(v => v.DeleteBehavior == DeleteBehavior.Cascade).ToArray();
-            foreach (var fk in fks)
-            {
-                fk.DeleteBehavior = DeleteBehavior.Restrict;
-            }
-            base.OnModelCreating(modelBuilder);
-        }
-
-        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
-        {
-            //var loggerFactory = new LoggerFactory();
-            //loggerFactory.AddProvider(new EFLoggerProvider());
-            optionsBuilder.UseSqlServer(AppSettings.Config.GetConnectionString("WCSDB"))/*.UseLoggerFactory(loggerFactory)*/.EnableSensitiveDataLogging();
-            //optionsBuilder.UseLoggerFactory(LoggerFactory.Create(builder =>
-            //{
-            //    builder.AddFilter((category, level) => category == DbLoggerCategory.Database.Command.Name && level == LogLevel.Information).AddConsole();
-            //}));
-        }
-
-        public override int SaveChanges()
-        {
-            var entities = from e in ChangeTracker.Entries()
-                           where e.State is EntityState.Added or EntityState.Modified
-                           select e.Entity;
-            var list = new List<ValidationResult>();
-            foreach (var entity in entities)
-            {
-                var validationContext = new ValidationContext(entity);
-                try
-                {
-                    Validator.ValidateObject(entity, validationContext);
-                }
-                catch (ValidationException ex)
-                {
-                    list.Add(ex.ValidationResult);
-                }
-            }
-            if (list.Count > 0)
-                throw new EntityValidationException { EntityValidationErrors = list };
-
-            return base.SaveChanges();
-        }
-
-        public DbSet<WCS_PLC> WCS_PLC { get; set; }
-        public DbSet<WCS_DATABLOCK> WCS_DATABLOCK { get; set; }
-        public DbSet<WCS_DEVICE> WCS_DEVICE { get; set; }
-        public DbSet<WCS_DEVICEPROTOCOL> WCS_DEVICEPROTOCOL { get; set; }
-        public DbSet<WCS_EXCEPTION> WCS_EXCEPTION { get; set; }
-        public DbSet<WCS_Station520> WCS_STATION520 { get; set; }
-        public DbSet<WCS_Station521> WCS_STATION521 { get; set; }
-
-        public DbSet<WCS_Station523> WCS_STATION523 { get; set; }
-
-        public DbSet<WCS_SystemConfig> WCS_SystemConfig { get; set; }
-
-        public DbSet<WCS_StatusLog> WCS_StatusLog { get; set; }
-
-        public DbSet<WCS_RGV520> WCS_RGV520 { get; set; }
-        public DbSet<WCS_RGV521> WCS_RGV521 { get; set; }
-        public DbSet<WCS_RGV523> WCS_RGV523 { get; set; }
-
-        public DbSet<WCS_GROUPMEMBER> WCS_GROUPMEMBER { get; set; }
-
-        public DbSet<WCS_SRM520> WCS_SRM520 { get; set; }
-        public DbSet<WCS_SRM521> WCS_SRM521 { get; set; }
-        public DbSet<WCS_SRM537> WCS_SRM537 { get; set; }
-        public DbSet<WCS_BCR80> WCS_BCR80 { get; set; }
-        public DbSet<WCS_CMD> WCS_CMD { get; set; }
-        public DbSet<WCS_TASK> WCS_TASK { get; set; }
-        public DbSet<WCS_ROUTE> WCS_ROUTE { get; set; }
-
-        public DbSet<WCS_PATH> WCS_PATH { get; set; }
-
-        public DbSet<WCS_AGVTask> WCS_AGVTask { get; set; }
-
-        public DbSet<WCS_PATHPOINT> WCS_PATHPOINT { get; set; }
-
-        public DbSet<WCS_Users> WCS_Users { get; set; }
-
-        public DbSet<WCS_MAPPINGENTRY> WCS_MAPPINGENTRY { get; set; }
-
-        public DbSet<WCS_TASK_OLD> WCS_TASK_OLD { get; set; }
-    }
-}

+ 4 - 4
Projects/永冠OPP/WCS.Service/Worker.cs

@@ -37,7 +37,7 @@ namespace WCS.Service
             #endregion 启用日志
 
             _logger.LogInformation("WCS开始启动");
-            InfoLog.INFO_INIT("WCS开始启动");
+            //InfoLog.INFO_INIT("WCS开始启动");
             Configs.DebugRedisUrl = "127.0.0.1";
             Configs.ProtocolProxyBaseType = typeof(ProtocolProxy);
             Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
@@ -126,19 +126,19 @@ namespace WCS.Service
                 #endregion 启用所有的逻辑处理器
 
                 _logger.LogInformation("WCS启动成功");
-                InfoLog.INFO_INIT("WCS启动成功");
+                //InfoLog.INFO_INIT("WCS启动成功");
             }
             catch (Exception ex)
             {
                 _logger.LogError("WCS启动失败{0}", ex.Message);
-                InfoLog.INFO_INIT($"WCS启动失败{ex.Message}");
+                //InfoLog.INFO_INIT($"WCS启动失败{ex.Message}");
             }
         }
 
         public override Task StopAsync(CancellationToken cancellationToken)
         {
             _logger.LogError("WCS关闭");
-            InfoLog.INFO_INIT("WCS关闭");
+            //InfoLog.INFO_INIT("WCS关闭");
             LogicHandler.StopAll();
             return base.StopAsync(cancellationToken);
         }

+ 2 - 1
WCS.Core/LogicHandler.cs

@@ -1,4 +1,5 @@
-using System;
+using Logs;
+using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Linq;

+ 2 - 1
WCS.Core/WCS.Core.csproj

@@ -9,11 +9,12 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="DBHelper-SqlSugar" Version="1.0.0" />
     <PackageReference Include="FreeRedis" Version="0.3.5" />
+    <PackageReference Include="Logs" Version="1.0.0.1" />
   </ItemGroup>
 
   <ItemGroup>
-    <ProjectReference Include="..\DBHelper-SqlSugar\DBHelper-SqlSugar.csproj" />
     <ProjectReference Include="..\WCS.Entity\WCS.Entity.csproj" />
   </ItemGroup>
 

+ 13 - 9
WCS.Entity/OBJ.cs

@@ -1,42 +1,46 @@
-using System;
+using SqlSugar;
+using System;
 using System.ComponentModel.DataAnnotations;
 using System.ComponentModel.DataAnnotations.Schema;
-using System.Reflection;
 
 namespace WCS.Entity
 {
     [Serializable]
     public abstract class OBJ
     {
+        [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "ID")]
+        [Column(Order = 0)]
         [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
         [Display(Name = "主键", Order = 0)]
         [Key]
-        [Column(Order = 0)] 
         public virtual int ID { get; set; }
 
+        [SugarColumn(ColumnDescription = "是否可用")]
         [Display(Name = "可用")]
         public bool ENABLED { get; set; } = true;
 
+        [SugarColumn(ColumnDescription = "是否可用", Length = 50, IsNullable = true)]
+        [Display(Name = "更新者")]
         [MaxLength(50)]
         [Required]
-        [Display(Name = "更新者")]
         public string UPDATEUSER { get; set; }
 
+        [SugarColumn(ColumnDescription = "更新时间")]
         [Display(Name = "更新时间")]
         public DateTime UPDATETIME { get; set; } = DateTime.Now;
 
-        //[ConcurrencyCheck]
+        [SugarColumn(ColumnDescription = "更新时间")]
         [Timestamp]
         [Display(Name = "版本")]
         public byte[] VER { get; set; }
 
         public T Copy<T>() where T : OBJ
         {
-            T instance = Activator.CreateInstance<T>();
-            foreach (PropertyInfo property in this.GetType().GetProperties())
+            var instance = Activator.CreateInstance<T>();
+            foreach (var property in GetType().GetProperties())
             {
-                object obj = property.GetValue((object)this);
-                typeof(T).GetProperty(property.Name).SetValue((object)instance, obj);
+                var obj = property.GetValue(this);
+                typeof(T).GetProperty(property.Name)!.SetValue(instance, obj);
             }
             return instance;
         }

+ 3 - 2
WCS.Entity/WCS.Entity.csproj

@@ -1,10 +1,11 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFramework>netstandard2.0</TargetFramework>
+    <TargetFramework>netstandard2.1</TargetFramework>
   </PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="DBHelper-SqlSugar" Version="1.0.0" />
     <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
   </ItemGroup>
 

+ 2 - 0
WCS.Entity/WCS_CMD.cs

@@ -2,9 +2,11 @@
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
 using System.Text;
+using SqlSugar;
 
 namespace WCS.Entity
 {
+    [SugarTable("WCS_CMD")]
     public class WCS_CMD : OBJ
     {
         [StringLength(20)]