林豪 左 пре 3 година
родитељ
комит
655814f7c0

+ 73 - 0
WCS.Core/BaseExtensions/ExceptionExtension.cs

@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WCS.BaseExtensions
+{
+    /// <summary>
+    /// 警告异常
+    /// </summary>
+    public class WarnException : Exception
+    {
+        /// <summary>
+        /// 报告WCS
+        /// </summary>
+        public bool REPORTWCS { get; set; }
+
+        /// <summary>
+        /// 报告WMS
+        /// </summary>
+        public bool REPORTWMS { get; set; }
+
+        /// <summary>
+        /// 记录文本日志
+        /// </summary>
+        public bool RECORDTXT { get; set; }
+
+        /// <summary>
+        /// 记录数据库
+        /// </summary>
+        public bool RECORDDB { get; set; }
+
+        /// <summary>
+        /// 警告异常 默认都记录
+        /// </summary>
+        /// <param name="message"></param>
+        public WarnException(string message) : base(message)
+        {
+            REPORTWCS = true;
+            REPORTWMS = true;
+            RECORDTXT = true;
+            RECORDDB = true;
+        }
+
+        /// <summary>
+        /// 警告异常,自定义上报
+        /// </summary>
+        /// <param name="message"></param>
+        /// <param name="rEPORTWCS"></param>
+        /// <param name="rEPORTWMS"></param>
+        /// <param name="rECORDTXT"></param>
+        public WarnException(string message, bool rEPORTWCS, bool rEPORTWMS, bool rECORDTXT, bool rECORDDB) : base(message)
+        {
+            REPORTWCS = rEPORTWCS;
+            REPORTWMS = rEPORTWMS;
+            RECORDTXT = rECORDTXT;
+            RECORDDB = rECORDDB;
+        }
+    }
+
+    /// <summary>
+    /// 执行记录
+    /// </summary>
+    public class DoException : Exception
+    {
+        /// <summary>
+        /// 警告异常
+        /// </summary>
+        /// <param name="message"></param>
+        public DoException(string message) : base(message)
+        {
+        }
+    }
+}

+ 237 - 0
WCS.Core/BaseExtensions/TypeExtension.cs

@@ -0,0 +1,237 @@
+using Log;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Linq;
+using System.Reflection;
+using System.Security.Cryptography;
+
+namespace WCS.BaseExtensions
+{
+    /// <summary>
+    ///
+    /// </summary>
+    public static class TypeExtension
+    {
+        /// <summary>
+        /// 将字符串转换为short
+        /// </summary>
+        /// <param name="value">需要转换的字符串</param>
+        /// <returns></returns>
+        public static short ToShort(this string value)
+        {
+            return Convert.ToInt16(value);
+        }
+
+        /// <summary>
+        /// 将int转换为short
+        /// </summary>
+        /// <param name="value">需要转换的字符串</param>
+        /// <returns></returns>
+        public static short ToShort(this int value)
+        {
+            return Convert.ToInt16(value);
+        }
+
+        /// <summary>
+        /// 将decimal转换为short
+        /// </summary>
+        /// <param name="value">需要转换的字符串</param>
+        /// <returns></returns>
+        public static short ToShort(this decimal value)
+        {
+            return Convert.ToInt16(value);
+        }
+
+        /// <summary>
+        /// 将字符串转换为int
+        /// </summary>
+        /// <param name="value">需要转换的字符串</param>
+        /// <returns></returns>
+        public static int ToInt(this string value)
+        {
+            return Convert.ToInt32(value);
+        }
+
+        /// <summary>
+        /// 判断值为奇数/偶数
+        /// </summary>
+        /// <param name="value">需要判断的值</param>
+        /// <returns> true:是奇数   false:是偶数</returns>
+        public static bool OddNumberOrEven(this short value)
+        {
+            return value % 2 != 0;
+        }
+
+        /// <summary>
+        /// 获取short类型Code,只限设备组
+        /// </summary>
+        /// <param name="value"></param>
+        /// <returns></returns>
+        public static short GetShortCode(this string value)
+        {
+            return value.Replace("G", "").ToShort();
+        }
+
+        /// <summary>
+        /// 数据映射
+        /// </summary>
+        /// <typeparam name="D"></typeparam>
+        /// <typeparam name="S"></typeparam>
+        /// <param name="s"></param>
+        /// <returns></returns>
+        public static D Mapper<D, S>(S s)
+        {
+            D d = Activator.CreateInstance<D>();
+
+            var sType = s.GetType();
+            var dType = typeof(D);
+            foreach (PropertyInfo sP in sType.GetProperties())
+            {
+                foreach (PropertyInfo dP in dType.GetProperties())
+                {
+                    if (dP.Name == sP.Name)
+                    {
+                        dP.SetValue(d, sP.GetValue(s));
+                        break;
+                    }
+                }
+            }
+            return d;
+        }
+
+        /// <summary>
+        /// 获取字典
+        /// </summary>
+        /// <typeparam name="T1"></typeparam>
+        /// <typeparam name="T2"></typeparam>
+        /// <typeparam name="T3"></typeparam>
+        /// <param name="t3"></param>
+        /// <returns></returns>
+        public static Dictionary<string, object> EntityClassToDictionary<T>(T t)
+        {
+            Type type = typeof(SugarColumn);
+            Dictionary<string, object> d = new Dictionary<string, object>();
+
+            var sType = t.GetType();
+            foreach (PropertyInfo sP in sType.GetProperties())
+            {
+                if (sP.CustomAttributes.Any(v => v.AttributeType == type) && sP.Name != "VER" && sP.Name != "ID")
+                {
+                    d.Add(sP.Name, sP.GetValue(t));
+                }
+            }
+
+            return d;
+        }
+
+        /// <summary>
+        /// 获取MD5字符串
+        /// </summary>
+        /// <param name="myString"></param>
+        /// <returns></returns>
+        public static string GetMD5(this string myString)
+        {
+            MD5 md5 = MD5.Create();
+            byte[] fromData = System.Text.Encoding.Unicode.GetBytes(myString);
+            byte[] targetData = md5.ComputeHash(fromData);
+            string byte2String = null;
+
+            for (int i = 0; i < targetData.Length; i++)
+            {
+                byte2String += targetData[i].ToString("x");
+            }
+
+            return byte2String;
+        }
+
+        /// <summary>
+        /// DataTable转换成实体类
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="dt"></param>
+        /// <returns></returns>
+        public static List<object> TableToEntity(this DataTable dt, string typeName)
+        {
+            List<object> list = new List<object>();
+            try
+            {
+                foreach (DataRow row in dt.Rows)
+                {
+                    Type entity = Type.GetType(typeName);
+                    PropertyInfo[] pArray = entity.GetType().GetProperties();
+
+                    foreach (PropertyInfo p in pArray)
+                    {
+                        if (dt.Columns.Contains(p.Name))
+                        {
+                            if (!p.CanWrite) continue;
+                            var value = row[p.Name];
+                            if (value != DBNull.Value)
+                            {
+                                Type targetType = p.PropertyType;
+                                Type convertType = targetType;
+                                if (targetType.IsGenericType && targetType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
+                                {
+                                    //可空类型
+                                    NullableConverter nullableConverter = new NullableConverter(targetType);
+                                    convertType = nullableConverter.UnderlyingType;
+                                }
+                                if (!string.IsNullOrEmpty(convertType.FullName) && !string.IsNullOrEmpty(value.ToString()))
+                                {
+                                    value = Convert.ChangeType(value, convertType);
+                                }
+                                switch (convertType.FullName)
+                                {
+                                    case "System.Decimal":
+                                        p.SetValue(entity, Convert.ToDecimal(value), null);
+                                        break;
+
+                                    case "System.String":
+                                        p.SetValue(entity, Convert.ToString(value), null);
+                                        break;
+
+                                    case "System.Int32":
+                                        p.SetValue(entity, Convert.ToInt32(value), null);
+                                        break;
+
+                                    case "System.Int64":
+                                        p.SetValue(entity, Convert.ToInt64(value), null);
+                                        break;
+
+                                    case "System.Int16":
+                                        p.SetValue(entity, Convert.ToInt16(value), null);
+                                        break;
+
+                                    case "System.Double":
+                                        p.SetValue(entity, Convert.ToDouble(value), null);
+                                        break;
+
+                                    case "System.Single":
+                                        p.SetValue(entity, Convert.ToSingle(value), null);
+                                        break;
+
+                                    case "System.DateTime":
+                                        p.SetValue(entity, Convert.ToDateTime(value), null);
+                                        break;
+
+                                    default:
+                                        p.SetValue(entity, value, null);
+                                        break;
+                                }
+                            }
+                        }
+                    }
+                    list.Add(entity);
+                }
+            }
+            catch (Exception ex)
+            {
+                InfoLog.INFO_ERROR("Table转换实体类失败:" + ex.Message);
+            }
+            return list;
+        }
+    }
+}

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

@@ -8,7 +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.1</VersionPrefix>
-    <describe>第一版</describe>
+    <VersionPrefix>1.0.2</VersionPrefix>
   </PropertyGroup>
 </Project>

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

@@ -4,11 +4,11 @@
     <TargetFramework>netstandard2.1</TargetFramework>
     <Nullable>enable</Nullable>
     <GenerateDocumentationFile>True</GenerateDocumentationFile>
-    <Description>$(describe)</Description>
+    <Description>与PLC交互协议、及与具体项目强关联的实体模型</Description>
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="WCS.Entity" Version="1.0.3" />
+    <PackageReference Include="WCS.Entity" Version="1.0.4" />
   </ItemGroup>
 
 </Project>

+ 14 - 14
WCS.Entity.Protocol/WCS_TASK.cs

@@ -49,7 +49,7 @@ namespace WCS.Entity
         /// <summary>
         /// 巷道
         /// </summary>
-        [SugarColumn(ColumnDescription = "巷道", Length = 10)]
+        [SugarColumn(ColumnDescription = "巷道", Length = 10, IsNullable = true)]
         public string TUNNEL { get; set; }
 
         /// <summary>
@@ -61,13 +61,13 @@ namespace WCS.Entity
         /// <summary>
         /// 设备
         /// </summary>
-        [SugarColumn(ColumnDescription = "设备", Length = 20)]
+        [SugarColumn(ColumnDescription = "设备", Length = 20, IsNullable = true)]
         public string DEVICE { get; set; }
 
         /// <summary>
         /// 堆垛机放货站台
         /// </summary>
-        [SugarColumn(ColumnDescription = "堆垛机放货站台", Length = 20)]
+        [SugarColumn(ColumnDescription = "堆垛机放货站台", Length = 20, IsNullable = true)]
         public string SRMSTATION { get; set; }
 
         /// <summary>
@@ -85,37 +85,37 @@ namespace WCS.Entity
         /// <summary>
         /// 结束时间
         /// </summary>
-        [SugarColumn(ColumnDescription = "结束时间")]
+        [SugarColumn(ColumnDescription = "结束时间", IsNullable = true)]
         public DateTime? ENDTIME { get; set; }
 
         /// <summary>
         /// 单号
         /// </summary>
-        [SugarColumn(ColumnDescription = "单号")]
+        [SugarColumn(ColumnDescription = "单号", IsNullable = true)]
         public int DOCID { get; set; }
 
         /// <summary>
         /// 托盘类型
         /// </summary>
-        [SugarColumn(ColumnDescription = "托盘类型")]
+        [SugarColumn(ColumnDescription = "托盘类型", IsNullable = true)]
         public short PALLETTYPE { get; set; }
 
         /// <summary>
         /// 产线
         /// </summary>
-        [SugarColumn(ColumnDescription = "产线")]
+        [SugarColumn(ColumnDescription = "产线", IsNullable = true)]
         public short PRODLINE { get; set; }
 
         /// <summary>
         /// 满盘数量
         /// </summary>
-        [SugarColumn(ColumnDescription = "满盘数量")]
+        [SugarColumn(ColumnDescription = "满盘数量", IsNullable = true)]
         public short FULLQTY { get; set; }
 
         /// <summary>
         /// 高度
         /// </summary>
-        [SugarColumn(ColumnDescription = "高度")]
+        [SugarColumn(ColumnDescription = "高度", IsNullable = true)]
         public short HEIGHT { get; set; }
 
         /// <summary>
@@ -127,7 +127,7 @@ namespace WCS.Entity
         /// <summary>
         /// 任务组ID
         /// </summary>
-        [SugarColumn(ColumnDescription = "任务组ID")]
+        [SugarColumn(ColumnDescription = "任务组ID", IsNullable = true)]
         public string TaskGroupKey { get; set; }
 
         /// <summary>
@@ -139,7 +139,7 @@ namespace WCS.Entity
         /// <summary>
         /// AGV任务号
         /// </summary>
-        [SugarColumn(ColumnDescription = "AGV任务号")]
+        [SugarColumn(ColumnDescription = "AGV任务号", IsNullable = true)]
         public int AGVTASKID { get; set; }
 
         /// <summary>
@@ -157,19 +157,19 @@ namespace WCS.Entity
         /// <summary>
         /// 手动处理备注
         /// </summary>
-        [SugarColumn(ColumnDescription = "手动处理备注")]
+        [SugarColumn(ColumnDescription = "手动处理备注", IsNullable = true)]
         public string ManualRemarks { get; set; }
 
         /// <summary>
         /// 产品长度
         /// </summary>
-        [SugarColumn(ColumnDescription = "产品长度")]
+        [SugarColumn(ColumnDescription = "产品长度", IsNullable = true)]
         public decimal Length { get; set; }
 
         /// <summary>
         /// 产品编码
         /// </summary>
-        [SugarColumn(ColumnDescription = "产品编码")]
+        [SugarColumn(ColumnDescription = "产品编码", IsNullable = true)]
         public string MaterialCode { get; set; }
     }
 

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

@@ -8,7 +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>
-    <describe>优化引用</describe>
+    <VersionPrefix>1.0.4</VersionPrefix>
   </PropertyGroup>
 </Project>

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

@@ -4,7 +4,7 @@
     <TargetFramework>netstandard2.1</TargetFramework>
     <Nullable>enable</Nullable>
     <GenerateDocumentationFile>True</GenerateDocumentationFile>
-    <Description>$(describe)</Description>
+    <Description>通用模型</Description>
   </PropertyGroup>
 
   <ItemGroup>

+ 2 - 2
WCS.Entity/WCS_PATHPOINT.cs

@@ -35,7 +35,7 @@ namespace WCS.Entity
         /// <summary>
         /// 路径点设备号
         /// </summary>
-        [SugarColumn(ColumnDescription = "路径点设备号")]
+        [SugarColumn(ColumnDescription = "路径点设备号", IsNullable = true)]
         public string DEVICECODE { get; set; }
 
         /// <summary>
@@ -59,7 +59,7 @@ namespace WCS.Entity
         /// <summary>
         /// 后路径点设备号
         /// </summary>
-        [SugarColumn(ColumnDescription = "后路径点设备号")]
+        [SugarColumn(ColumnDescription = "后路径点设备号", IsNullable = true)]
         public string NEXTCODE { get; set; }
 
         /// <summary>

+ 2 - 2
WCS.Service/WCS.Service.csproj

@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk.Worker">
+<Project Sdk="Microsoft.NET.Sdk.Worker">
 
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
@@ -26,6 +26,6 @@
     <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.8" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
     <PackageReference Include="WCS.Virtual_PLC" Version="1.0.0" />
-    <PackageReference Include="WCS.WorkEngineering" Version="1.0.0" />
+    <PackageReference Include="WCS.WorkEngineering" Version="1.0.2" />
   </ItemGroup>
 </Project>

+ 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.1</VersionPrefix>
+    <VersionPrefix>1.0.2</VersionPrefix>
   </PropertyGroup>
 </Project>

+ 1 - 1
WCS.WebApi/WCS.WebApi.csproj

@@ -11,7 +11,7 @@
     <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.1" />
+    <PackageReference Include="WCS.Entity.Protocol" Version="1.0.2" />
   </ItemGroup>
 
 </Project>

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

@@ -8,7 +8,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="WCS.WebApi" Version="1.0.1" />
+    <PackageReference Include="WCS.WebApi" Version="1.0.2" />
   </ItemGroup>
 
 </Project>

+ 1 - 0
WCS.WorkEngineering/Works/Station/一楼入库.cs

@@ -19,6 +19,7 @@ namespace WCS.Service.Works.Station
     {
         protected override void Do(StationDeviceGroup obj)
         {
+            InfoLog.INFO_WARN("测试");
             var timer = new Stopwatch();
             timer.Start();
             obj.EX(obj =>