diff --git a/Sln.Imm.Daemon.Cache/BaseDeviceInfoCacheService.cs b/Sln.Imm.Daemon.Cache/BaseDeviceInfoCacheService.cs new file mode 100644 index 0000000..d23ad15 --- /dev/null +++ b/Sln.Imm.Daemon.Cache/BaseDeviceInfoCacheService.cs @@ -0,0 +1,83 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- + * 版权所有 (c) 2025 WenJY 保留所有权利。 + * CLR版本:4.0.30319.42000 + * 机器名称:Mr.Wen's MacBook Pro + * 命名空间:Sln.Imm.Daemon.Cache + * 唯一标识:C61D97E2-2108-46A3-974C-AFE6C83258BA + * + * 创建者:WenJY + * 电子邮箱: + * 创建时间:2025-09-05 11:29:42 + * 版本:V1.0.0 + * 描述: + * + *-------------------------------------------------------------------- + * 修改人: + * 时间: + * 修改说明: + * + * 版本:V1.0.0 + *--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using Sln.Imm.Daemon.Model.dao; +using Sln.Imm.Daemon.Repository.service; +using Sln.Imm.Daemon.Serilog; +using ZiggyCreatures.Caching.Fusion; + +namespace Sln.Imm.Daemon.Cache; + +public class BaseDeviceInfoCacheService +{ + private readonly SerilogHelper _logger; + + private readonly IFusionCache _fusionCache; + + private readonly IBaseDeviceInfoService _service; + + public BaseDeviceInfoCacheService(SerilogHelper logger, IFusionCache fusionCache, IBaseDeviceInfoService service) + { + _logger = logger; + _fusionCache = fusionCache; + _service = service; + } + + /// + /// 通过缓存获取值 + /// + /// + /// + public async Task> GetValueAsync(string key) + { + var cachedValue = await _fusionCache.GetOrDefaultAsync>(key).ConfigureAwait(false); + if (cachedValue != null) + { + _logger.Info($"通过Cache获取数据:{cachedValue.Count};条"); + return cachedValue; + } + else + { + var value = _service.Query(); + //将值存入缓存,设置过期时间等 + await _fusionCache.SetAsync(key, value, TimeSpan.FromSeconds(5)).ConfigureAwait(false); + _logger.Info($"通过ORM获取数据:{value.Count};条"); + return value; + } + } + + public async Task SetValueAsync(string key, BaseDeviceInfo deviceInfo) + { + var isRes = _service.Update(deviceInfo); + + if (isRes) + { + var value = _service.Query(); + await _fusionCache.SetAsync(key, value, TimeSpan.FromSeconds(5)).ConfigureAwait(false); + } + + return isRes; + } +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Common/StringChange.cs b/Sln.Imm.Daemon.Common/StringChange.cs new file mode 100644 index 0000000..6423659 --- /dev/null +++ b/Sln.Imm.Daemon.Common/StringChange.cs @@ -0,0 +1,280 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- +* 版权所有 (c) 2025 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:Mr.Wen's MacBook Pro +* 命名空间:Sln.Imm.Daemon.Common +* 唯一标识:CE4BD2CC-E101-4CF0-BB9C-C3325F54C8FE +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2025-09-05 11:10:34 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using System.Text; + +namespace Sln.Imm.Daemon.Common; + +public class StringChange + { + /// + /// 将字符串强制转换成int,转换失败则返回0 + /// + /// + /// + public int ParseToInt(string str) + { + int returnInt = 0; + if (str == null || str.Trim().Length < 1) + { + return returnInt; + } + if (int.TryParse(str, out returnInt)) + { + return returnInt; + } + else + { + return 0; + } + } + + /// + /// char数组转Array + /// + /// + /// + /// + public string CharArrayToString(char[] cha, int len) + { + string str = ""; + for (int i = 0; i < len; i++) + { + str += string.Format("{0}", cha[i]); + } + + return str; + } + + + + public byte[] HexStrTorbytes(string strHex)//e.g. " 01 01" ---> { 0x01, 0x01} + { + strHex = strHex.Replace(" ", ""); + if ((strHex.Length % 2) != 0) + strHex += " "; + byte[] returnBytes = new byte[strHex.Length / 2]; + for (int i = 0; i < returnBytes.Length; i++) + returnBytes[i] = Convert.ToByte(strHex.Substring(i * 2, 2), 16); + return returnBytes; + } + + public string StringToHexString(string s, Encoding encode) + { + byte[] b = encode.GetBytes(s); //按照指定编码将string编程字节数组 + string result = string.Empty; + for (int i = 0; i < b.Length; i++) //逐字节变为16进制字符,以%隔开 + { + result += "%" + Convert.ToString(b[i], 16); + } + return result; + } + + public string HexStringToString(string hs, Encoding encode) + { + //以%分割字符串,并去掉空字符 + string[] chars = hs.Split(new char[] { '%' }, StringSplitOptions.RemoveEmptyEntries); + byte[] b = new byte[chars.Length]; + //逐个字符变为16进制字节数据 + for (int i = 0; i < chars.Length; i++) + { + b[i] = Convert.ToByte(chars[i], 16); + } + //按照指定编码将字节数组变为字符串 + return encode.GetString(b); + } + + public byte[] Swap16Bytes(byte[] OldU16) + { + byte[] ReturnBytes = new byte[2]; + ReturnBytes[1] = OldU16[0]; + ReturnBytes[0] = OldU16[1]; + return ReturnBytes; + } + + /// + /// 获取时间戳 + /// + /// + public long GetTimeStamp() + { + TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); + return Convert.ToInt64(ts.TotalSeconds); + } + + public byte[] ConvertFloatToINt(byte[] floatBytes) + { + byte[] intBytes = new byte[floatBytes.Length / 2]; + for (int i = 0; i < intBytes.Length; i++) + { + intBytes[i] = floatBytes[i * 2]; + } + return intBytes; + } + + //CRC异或校验 + public byte CalculateVerify(byte[] pMessage, int iLength) + { + UInt16 i; + byte iVerify = 0; + + iVerify = pMessage[0]; + for (i = 1; i < iLength; i++) + { + iVerify = (byte)(iVerify ^ pMessage[i]); + } + return iVerify; + } + + public int HexStringToNegative(string strNumber) + { + + int iNegate = 0; + int iNumber = Convert.ToInt32(strNumber, 16); + if (iNumber > 127) + { + int iComplement = iNumber - 1; + string strNegate = string.Empty; + char[] binchar = Convert.ToString(iComplement, 2).PadLeft(8, '0').ToArray(); + foreach (char ch in binchar) + { + if (Convert.ToInt32(ch) == 48) + { + strNegate += "1"; + } + else + { + strNegate += "0"; + } + } + iNegate = -Convert.ToInt32(strNegate, 2); + } + return iNegate; + } + + + /// + /// Byte[] 转 uint16 + /// + /// + /// + /// + public void ConvertBytesToUInt16(byte[] buffer,out uint falg) + { + if (buffer == null || buffer.Length < 2) + { + throw new ArgumentException("Input array length must be at least 2."); + } + + var input = buffer.Reverse().ToArray(); + + falg = (uint) ((input[1] << 8) | input[0]); + } + + /// + /// Byte[] 移位转换 + /// + /// + /// + public void SwapBytes(ref byte[] input) + { + if (input == null || input.Length % 2 != 0) + { + throw new ArgumentException("Input array length must be a multiple of 2."); + } + + byte[] result = new byte[input.Length]; + + for (int j = 0; j < input.Length; j += 2) + { + ushort swapped = (ushort)((input[j + 1] << 8) | input[j]); + result[j] = (byte)(swapped >> 8); + result[j + 1] = (byte)swapped; + } + input = result; + } + + /// + /// Byte[] 转string + /// + /// + /// + public string ConverToString(byte[] data) + { + string str; + StringBuilder stb = new StringBuilder(); + for (int i = 0; i < data.Length; i++) + { + if ((int)data[i] > 15) + { + stb.Append(Convert.ToString(data[i], 16).ToUpper()); //添加字符串 + } + else //如果是小于0F需要加个零 + { + stb.Append("0" + Convert.ToString(data[i], 16).ToUpper()); + } + } + str = stb.ToString(); + return str; + } + + /// + /// Byte[] 转 Hex + /// + /// + /// + /// + public string bytesToHexStr(byte[] bytes, int iLen) + { + StringBuilder sb = new StringBuilder(); + if (bytes != null) + { + for (int i = 0; i < iLen; i++) + { + sb.Append(bytes[i].ToString("X2")); + } + } + return sb.ToString(); + } + + /// + /// 校验计算 + /// + /// + /// + /// + public byte[] CalculateVerifyToArray(byte[] pMessage, int iLength) + { + UInt16 i; + int iVerify = 0; + + iVerify = pMessage[0]; + for (i = 0; i < iLength - 1; i++) + { + iVerify = iVerify + pMessage[i + 1]; + } + return BitConverter.GetBytes(Convert.ToUInt16(iVerify)); + } + } \ No newline at end of file diff --git a/Sln.Imm.Daemon.Config/AppConfig.cs b/Sln.Imm.Daemon.Config/AppConfig.cs new file mode 100644 index 0000000..d6e7ca8 --- /dev/null +++ b/Sln.Imm.Daemon.Config/AppConfig.cs @@ -0,0 +1,43 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- +* 版权所有 (c) 2025 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:Mr.Wen's MacBook Pro +* 命名空间:Sln.Imm.Daemon.Config +* 唯一标识:8304972C-4A1D-402B-8997-1E95920777C0 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2025-09-05 10:50:20 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using Microsoft.Extensions.Options; + +namespace Sln.Imm.Daemon.Config; + +public class AppConfig: IOptions +{ + /// + /// 日志文件路径 + /// + public string logPath { get; set; } + + /// + /// Sql连接配置 + /// + public List sqlConfig { get; set; } + + public AppConfig Value => this; +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Config/SqlConfig.cs b/Sln.Imm.Daemon.Config/SqlConfig.cs new file mode 100644 index 0000000..599e1c6 --- /dev/null +++ b/Sln.Imm.Daemon.Config/SqlConfig.cs @@ -0,0 +1,49 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- +* 版权所有 (c) 2025 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:Mr.Wen's MacBook Pro +* 命名空间:Sln.Imm.Daemon.Config +* 唯一标识:D4F08CCE-FDDD-4416-B5C8-235A765236A2 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2025-09-05 10:51:36 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +namespace Sln.Imm.Daemon.Config; + +public class SqlConfig +{ + /// + /// Sql 配置ID,实体通过该ID关联数据源 + /// + public string configId { get; set; } + + /// + /// 数据库类型,MySql-0;SqlServer-1;Sqlite-2;Oracle-3 + /// + public int dbType { get; set; } + + /// + /// 是否启用:true-是;false-否 + /// + public bool isFlag{get;set;} + + /// + /// 连接字符串 + /// + public string connStr { get; set; } +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Model/dao/BaseDeviceInfo.cs b/Sln.Imm.Daemon.Model/dao/BaseDeviceInfo.cs new file mode 100644 index 0000000..a5edf64 --- /dev/null +++ b/Sln.Imm.Daemon.Model/dao/BaseDeviceInfo.cs @@ -0,0 +1,203 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- + * 版权所有 (c) 2025 WenJY 保留所有权利。 + * CLR版本:4.0.30319.42000 + * 机器名称:Mr.Wen's MacBook Pro + * 命名空间:Sln.Imm.Daemon.Model.dao + * 唯一标识:B0FF7F3C-05DE-44D0-9909-3301EA07E749 + * + * 创建者:WenJY + * 电子邮箱: + * 创建时间:2025-09-05 11:14:23 + * 版本:V1.0.0 + * 描述: + * + *-------------------------------------------------------------------- + * 修改人: + * 时间: + * 修改说明: + * + * 版本:V1.0.0 + *--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using SqlSugar; + +namespace Sln.Imm.Daemon.Model.dao; + +/// +/// 设备信息 +/// +[SugarTable("ems_base_monitor_info"), TenantAttribute("mes")] +public class BaseDeviceInfo +{ + /// + /// Desc:自增标识 + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "obj_id")] + public int objid { get; set; } + + /// + /// Desc:父级编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "parent_id")] + public int? parentId { get; set; } + + /// + /// Desc:计量设备编号 + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, ColumnName = "monitor_code")] + public string monitorId { get; set; } + + /// + /// Desc:计量设备名称 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "monitor_name")] + public string monitorName { get; set; } + + /// + /// Desc:计量设备位置 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "monitor_addr")] + public string monitorAddr { get; set; } + + /// + /// Desc:计量设备类型 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "monitor_type")] + public int? monitorType { get; set; } + + /// + /// Desc:计量设备状态 + /// Default:0 + /// Nullable:True + /// + [SugarColumn(ColumnName = "monitor_status")] + public int? monitorStatus { get; set; } + + /// + /// Desc:采集设备编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "collect_device_id")] + public string collectDeviceId { get; set; } + + /// + /// Desc:祖级列表 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "ancestors")] + public string ancestors { get; set; } + + /// + /// Desc:等级 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "grade")] + public int? grade { get; set; } + + /// + /// Desc:传感器仪表 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "meter_type_id")] + public string meterTypeId { get; set; } + + /// + /// Desc:修正值 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "correct_value")] + public decimal? correctValue { get; set; } + + /// + /// Desc:PT值 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "pt")] + public int? pt { get; set; } + + /// + /// Desc:CT值 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "ct")] + public int? ct { get; set; } + + /// + /// Desc:是否虚拟 + /// Default:false + /// Nullable:True + /// + [SugarColumn(ColumnName = "is_ammeter")] + public string isAmmeter { get; set; } + + /// + /// Desc:通断复位 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "is_key_monitor")] + public int? isKeyMonitor { get; set; } + + /// + /// Desc:是否断路 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "is_circuit")] + public int? isCircuit { get; set; } + + /// + /// Desc:创建人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "create_by")] + public string createBy { get; set; } + + /// + /// Desc:创建时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "create_time")] + public DateTime? createTime { get; set; } + + /// + /// Desc:更新人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "update_by")] + public string updateBy { get; set; } + + /// + /// Desc:更新时间 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "update_time")] + public DateTime? updateTime { get; set; } +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Model/dao/BaseDeviceParam.cs b/Sln.Imm.Daemon.Model/dao/BaseDeviceParam.cs new file mode 100644 index 0000000..a0fa4b5 --- /dev/null +++ b/Sln.Imm.Daemon.Model/dao/BaseDeviceParam.cs @@ -0,0 +1,37 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- +* 版权所有 (c) 2025 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:Mr.Wen's MacBook Pro +* 命名空间:Sln.Imm.Daemon.Model.dao +* 唯一标识:471106BA-23AA-4923-99A0-EBF103DAD909 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2025-09-05 11:15:14 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using SqlSugar; + +namespace Sln.Imm.Daemon.Model.dao; + +/// +/// 设备采集参数 +/// +[SugarTable("ems_base_monitor_info"), TenantAttribute("mes")] +public class BaseDeviceParam +{ + +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Repository/Repository.cs b/Sln.Imm.Daemon.Repository/Repository.cs new file mode 100644 index 0000000..2b80063 --- /dev/null +++ b/Sln.Imm.Daemon.Repository/Repository.cs @@ -0,0 +1,42 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- + * 版权所有 (c) 2025 WenJY 保留所有权利。 + * CLR版本:4.0.30319.42000 + * 机器名称:Mr.Wen's MacBook Pro + * 命名空间:Sln.Imm.Daemon.Repository + * 唯一标识:8E7E6A6F-CF05-49EA-A400-30147E92C840 + * + * 创建者:WenJY + * 电子邮箱: + * 创建时间:2025-09-05 11:21:51 + * 版本:V1.0.0 + * 描述: + * + *-------------------------------------------------------------------- + * 修改人: + * 时间: + * 修改说明: + * + * 版本:V1.0.0 + *--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using SqlSugar; + +namespace Sln.Imm.Daemon.Repository; + +public class Repository : SimpleClient where T : class, new() +{ + public ITenant itenant = null; //多租户事务、GetConnection、IsAnyConnection等功能 + + public Repository(ISqlSugarClient db) + { + itenant = db.AsTenant(); //用来处理事务 + base.Context = db.AsTenant().GetConnectionScopeWithAttr(); //获取子Db + + //如果不想通过注入多个仓储 + //用到ChangeRepository或者Db.GetMyRepository需要看标题4写法 + } +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Repository/SqlsugarSetup.cs b/Sln.Imm.Daemon.Repository/SqlsugarSetup.cs new file mode 100644 index 0000000..30d7f2c --- /dev/null +++ b/Sln.Imm.Daemon.Repository/SqlsugarSetup.cs @@ -0,0 +1,70 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- + * 版权所有 (c) 2025 WenJY 保留所有权利。 + * CLR版本:4.0.30319.42000 + * 机器名称:Mr.Wen's MacBook Pro + * 命名空间:Sln.Imm.Daemon.Repository + * 唯一标识:E2ACD454-D380-4130-8B28-FB2A2BF58530 + * + * 创建者:WenJY + * 电子邮箱: + * 创建时间:2025-09-05 11:22:32 + * 版本:V1.0.0 + * 描述: + * + *-------------------------------------------------------------------- + * 修改人: + * 时间: + * 修改说明: + * + * 版本:V1.0.0 + *--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using Microsoft.Extensions.DependencyInjection; +using Sln.Imm.Daemon.Config; +using SqlSugar; + +namespace Sln.Imm.Daemon.Repository; + +public static class SqlsugarSetup +{ + /// + /// 注册SqlSugar + /// + /// + public static void AddSqlSugarSetup(this IServiceCollection services) + { + services.AddSingleton(x => + { + var appConfig = x.GetService(); + + var connectConfigList = new List(); + if (appConfig.sqlConfig != null) + { + foreach (var item in appConfig.sqlConfig) + { + if (item.isFlag) + { + var config = new ConnectionConfig() + { + ConfigId = item.configId, + DbType = (DbType)item.dbType, + ConnectionString = item.connStr, + InitKeyType = InitKeyType.Attribute, + IsAutoCloseConnection = true, + }; + connectConfigList.Add(config); + } + } + } + + SqlSugarScope Db = + new SqlSugarScope(connectConfigList, db => { db.Aop.OnLogExecuting = (sql, pars) => { }; }); + + return Db; + }); + } +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Repository/service/IBaseDeviceInfoService.cs b/Sln.Imm.Daemon.Repository/service/IBaseDeviceInfoService.cs new file mode 100644 index 0000000..d6ade53 --- /dev/null +++ b/Sln.Imm.Daemon.Repository/service/IBaseDeviceInfoService.cs @@ -0,0 +1,33 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- + * 版权所有 (c) 2025 WenJY 保留所有权利。 + * CLR版本:4.0.30319.42000 + * 机器名称:Mr.Wen's MacBook Pro + * 命名空间:Sln.Imm.Daemon.Repository.service + * 唯一标识:77A94DE4-5143-4392-9125-9E505AFC5D2D + * + * 创建者:WenJY + * 电子邮箱: + * 创建时间:2025-09-05 11:25:32 + * 版本:V1.0.0 + * 描述: + * + *-------------------------------------------------------------------- + * 修改人: + * 时间: + * 修改说明: + * + * 版本:V1.0.0 + *--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using Sln.Imm.Daemon.Model.dao; +using Sln.Imm.Daemon.Repository.service.@base; + +namespace Sln.Imm.Daemon.Repository.service; + +public interface IBaseDeviceInfoService : IBaseService +{ +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Repository/service/IBaseDeviceParamService.cs b/Sln.Imm.Daemon.Repository/service/IBaseDeviceParamService.cs new file mode 100644 index 0000000..70444ab --- /dev/null +++ b/Sln.Imm.Daemon.Repository/service/IBaseDeviceParamService.cs @@ -0,0 +1,33 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- + * 版权所有 (c) 2025 WenJY 保留所有权利。 + * CLR版本:4.0.30319.42000 + * 机器名称:Mr.Wen's MacBook Pro + * 命名空间:Sln.Imm.Daemon.Repository.service + * 唯一标识:99E3BC15-AFBC-4B79-B2FF-38374E3BB6BD + * + * 创建者:WenJY + * 电子邮箱: + * 创建时间:2025-09-05 11:26:53 + * 版本:V1.0.0 + * 描述: + * + *-------------------------------------------------------------------- + * 修改人: + * 时间: + * 修改说明: + * + * 版本:V1.0.0 + *--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using Sln.Imm.Daemon.Model.dao; +using Sln.Imm.Daemon.Repository.service.@base; + +namespace Sln.Imm.Daemon.Repository.service; + +public interface IBaseDeviceParamService : IBaseService +{ +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Repository/service/Impl/BaseDeviceInfoServiceImpl.cs b/Sln.Imm.Daemon.Repository/service/Impl/BaseDeviceInfoServiceImpl.cs new file mode 100644 index 0000000..7854e08 --- /dev/null +++ b/Sln.Imm.Daemon.Repository/service/Impl/BaseDeviceInfoServiceImpl.cs @@ -0,0 +1,36 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- + * 版权所有 (c) 2025 WenJY 保留所有权利。 + * CLR版本:4.0.30319.42000 + * 机器名称:Mr.Wen's MacBook Pro + * 命名空间:Sln.Imm.Daemon.Repository.service.Impl + * 唯一标识:4B5A8864-4B34-489E-986B-B4C698CED289 + * + * 创建者:WenJY + * 电子邮箱: + * 创建时间:2025-09-05 11:26:11 + * 版本:V1.0.0 + * 描述: + * + *-------------------------------------------------------------------- + * 修改人: + * 时间: + * 修改说明: + * + * 版本:V1.0.0 + *--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using Sln.Imm.Daemon.Model.dao; +using Sln.Imm.Daemon.Repository.service.@base; + +namespace Sln.Imm.Daemon.Repository.service.Impl; + +public class BaseDeviceInfoServiceImpl : BaseServiceImpl, IBaseDeviceInfoService +{ + public BaseDeviceInfoServiceImpl(Repository rep) : base(rep) + { + } +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Repository/service/Impl/BaseDeviceParamServiceImpl.cs b/Sln.Imm.Daemon.Repository/service/Impl/BaseDeviceParamServiceImpl.cs new file mode 100644 index 0000000..9f48637 --- /dev/null +++ b/Sln.Imm.Daemon.Repository/service/Impl/BaseDeviceParamServiceImpl.cs @@ -0,0 +1,36 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- + * 版权所有 (c) 2025 WenJY 保留所有权利。 + * CLR版本:4.0.30319.42000 + * 机器名称:Mr.Wen's MacBook Pro + * 命名空间:Sln.Imm.Daemon.Repository.service.Impl + * 唯一标识:4D067141-7FEC-4ED6-A69C-F285D68FFDEF + * + * 创建者:WenJY + * 电子邮箱: + * 创建时间:2025-09-05 11:27:26 + * 版本:V1.0.0 + * 描述: + * + *-------------------------------------------------------------------- + * 修改人: + * 时间: + * 修改说明: + * + * 版本:V1.0.0 + *--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using Sln.Imm.Daemon.Model.dao; +using Sln.Imm.Daemon.Repository.service.@base; + +namespace Sln.Imm.Daemon.Repository.service.Impl; + +public class BaseDeviceParamServiceImpl : BaseServiceImpl, IBaseDeviceParamService +{ + public BaseDeviceParamServiceImpl(Repository rep) : base(rep) + { + } +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Repository/service/base/BaseServiceImpl.cs b/Sln.Imm.Daemon.Repository/service/base/BaseServiceImpl.cs new file mode 100644 index 0000000..11d5d8e --- /dev/null +++ b/Sln.Imm.Daemon.Repository/service/base/BaseServiceImpl.cs @@ -0,0 +1,368 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- + * 版权所有 (c) 2025 WenJY 保留所有权利。 + * CLR版本:4.0.30319.42000 + * 机器名称:Mr.Wen's MacBook Pro + * 命名空间:Sln.Imm.Daemon.Repository.service.base + * 唯一标识:B602D392-6450-4597-A0A9-F0696683B8AB + * + * 创建者:WenJY + * 电子邮箱: + * 创建时间:2025-09-05 11:24:10 + * 版本:V1.0.0 + * 描述: + * + *-------------------------------------------------------------------- + * 修改人: + * 时间: + * 修改说明: + * + * 版本:V1.0.0 + *--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using System.Linq.Expressions; +using SqlSugar; + +namespace Sln.Imm.Daemon.Repository.service.@base; + +public class BaseServiceImpl : IBaseService where T : class, new() +{ + public readonly Repository _rep; + + public BaseServiceImpl(Repository rep) + { + _rep = rep; + } + + /// + /// 添加实体信息 + /// + /// + /// + /// + /// + public bool Insert(T model) + { + if (model == null) + { + throw new ArgumentNullException($"添加实体信息异常:实体参数为空"); + } + + try + { + return _rep.CopyNew().Insert(model); + } + catch (Exception ex) + { + throw new InvalidOperationException($"添加实体信息异常:{ex.Message}"); + } + } + + /// + /// 批量添加实体集合 + /// + /// + /// + /// + /// + public bool Insert(List lisT) + { + if (lisT == null) + { + throw new ArgumentNullException($"批量添加实体集合异常:实体集合参数为空"); + } + + try + { + // _rep.AsTenant().BeginTran(); + var info = _rep.CopyNew().InsertRange(lisT); + // _rep.AsTenant().CommitTran(); + return true; + } + catch (Exception ex) + { + // _rep.AsTenant().RollbackTran(); + throw new InvalidOperationException($"批量添加实体集合异常:{ex.Message}"); + } + } + + /// + /// 根据id 删除信息 + /// + /// + /// + /// + public bool DeleteById(object id) + { + if (id == null) + { + throw new ArgumentNullException($"根据id删除信息异常:Id参数为空"); + } + + try + { + return _rep.DeleteById(id); + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据id删除信息异常:{ex.Message}"); + } + } + + /// + /// 根据实体删除信息 + /// + /// + /// + /// + /// + public bool Delete(T model) + { + if (model == null) + { + throw new ArgumentNullException($"根据实体删除信息异常:实体参数为空"); + } + + try + { + return _rep.DeleteById(model); + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据实体删除信息异常:{ex.Message}"); + } + } + + /// + /// 根据实体集合批量删除信息 + /// + /// + /// + /// + public bool Deletes(List entitys) + { + if (entitys == null) + { + throw new ArgumentNullException($"根据实体集合批量删除信息异常:实体集合参数为空"); + } + + try + { + return _rep.Delete(entitys); + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据实体集合批量删除信息异常:{ex.Message}"); + } + } + + /// + /// 根据实体更新信息 + /// + /// + /// + /// + public bool Update(T model) + { + if (model == null) + { + throw new ArgumentNullException($"根据实体更新信息异常:实体参数为空"); + } + + try + { + return _rep.Update(model); + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据实体更新信息异常:{ex.Message}"); + } + } + + /// + /// 批量更新实体集合信息 + /// + /// + /// + /// + public bool Update(List entitys) + { + if (entitys == null) + { + throw new ArgumentNullException($"批量更新实体集合信息异常:实体集合参数为空"); + } + + try + { + return _rep.UpdateRange(entitys); + } + catch (Exception ex) + { + throw new InvalidOperationException($"批量更新实体集合信息异常:{ex.Message}"); + } + } + + /// + /// 根据Where条件更新实体信息 + /// + /// + /// + /// + public bool Update(T entity, string strWhere) + { + if (entity == null) + { + throw new ArgumentNullException($"根据Where条件更新实体信息异常:实体参数为空"); + } + + if (string.IsNullOrEmpty(strWhere)) + { + throw new ArgumentNullException($"根据Where条件更新实体信息异常:Where参数为空"); + } + + try + { + return _rep.AsUpdateable(entity).Where(strWhere).ExecuteCommandHasChange(); + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据Where条件更新实体信息异常:{ex.Message}"); + } + } + + /// + /// 根据实体更新指定列 + /// + /// + /// + /// + /// + /// + public bool Update(T entity, List lstColumns = null, List lstIgnoreColumns = null, + string strWhere = "") + { + try + { + IUpdateable up = _rep.AsUpdateable(entity); + if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0) + { + up = up.IgnoreColumns(lstIgnoreColumns.ToArray()); + } + + if (lstColumns != null && lstColumns.Count > 0) + { + up = up.UpdateColumns(lstColumns.ToArray()); + } + + if (!string.IsNullOrEmpty(strWhere)) + { + up = up.Where(strWhere); + } + + return up.ExecuteCommandHasChange(); + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据实体更新指定列异常:{ex.Message}"); + } + } + + /// + /// 查询所有信息 + /// + /// + /// + public List Query() + { + try + { + return _rep.GetList(); + } + catch (Exception ex) + { + throw new InvalidOperationException($"查询所有信息异常:{ex.Message}"); + } + } + + /// + /// 根据Id查询实体 + /// + /// + /// + /// + public T Query(object objId) + { + if (objId == null) + { + throw new ArgumentNullException($"根据Id查询实体信息异常:Id参数为空"); + } + + try + { + return _rep.GetById(objId); + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据Id查询实体信息异常:{ex.Message}"); + } + } + + /// + /// 根据表达式查询 + /// + /// + /// + /// + public List Query(Expression> whereExpression) + { + if (whereExpression == null) + { + throw new ArgumentNullException($"根据表达式查询实体信息异常:表达式参数为空"); + } + + try + { + return _rep.GetList(whereExpression); + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据表达式查询实体信息异常:{ex.Message}"); + } + } + + /// + /// 根据表达式排序查询 + /// + /// + /// + /// + /// + /// + public List Query(Expression> whereExpression, Expression> orderByExpression, + bool isAsc = true) + { + if (whereExpression == null) + { + throw new ArgumentNullException($"根据表达式排序查询信息异常:条件表达式参数为空"); + } + + if (orderByExpression == null) + { + throw new ArgumentNullException($"根据表达式排序查询信息异常:排序表达式参数为空"); + } + + try + { + return _rep.AsQueryable() + .OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc) + .WhereIF(whereExpression != null, whereExpression).ToList(); + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据表达式排序查询信息异常:{ex.Message}"); + } + } +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Repository/service/base/IBaseService.cs b/Sln.Imm.Daemon.Repository/service/base/IBaseService.cs new file mode 100644 index 0000000..4a5070e --- /dev/null +++ b/Sln.Imm.Daemon.Repository/service/base/IBaseService.cs @@ -0,0 +1,128 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- + * 版权所有 (c) 2025 WenJY 保留所有权利。 + * CLR版本:4.0.30319.42000 + * 机器名称:Mr.Wen's MacBook Pro + * 命名空间:Sln.Imm.Daemon.Repository.service.base + * 唯一标识:0AE676A9-45F0-4A21-B1E2-BFCBF3BBAF2B + * + * 创建者:WenJY + * 电子邮箱: + * 创建时间:2025-09-05 11:23:41 + * 版本:V1.0.0 + * 描述: + * + *-------------------------------------------------------------------- + * 修改人: + * 时间: + * 修改说明: + * + * 版本:V1.0.0 + *--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using System.Linq.Expressions; + +namespace Sln.Imm.Daemon.Repository.service.@base; + +public interface IBaseService where T : class +{ + /// + /// 添加实体信息 + /// + /// + /// + bool Insert(T model); + + /// + /// 批量添加实体集合 + /// + /// + /// + bool Insert(List lisT); + + /// + /// 根据id 删除信息 + /// + /// + /// + bool DeleteById(object id); + + /// + /// 根据实体删除信息 + /// + /// + /// + bool Delete(T model); + + /// + /// 根据实体集合批量删除信息 + /// + /// + /// + bool Deletes(List entitys); + + /// + /// 根据实体更新信息 + /// + /// + /// + bool Update(T model); + + /// + /// 批量更新实体集合信息 + /// + /// + /// + bool Update(List entitys); + + /// + /// 根据Where条件更新实体信息 + /// + /// + /// + /// + bool Update(T entity, string strWhere); + + /// + /// 根据实体更新指定列 + /// + /// + /// + /// + /// + /// + bool Update(T entity, List lstColumns = null, List lstIgnoreColumns = null, string strWhere = ""); + + /// + /// 查询所有信息 + /// + /// + List Query(); + + /// + /// 根据Id查询实体 + /// + /// + /// + T Query(object objId); + + /// + /// 根据表达式查询 + /// + /// + /// + List Query(Expression> whereExpression); + + /// + /// 根据表达式排序查询 + /// + /// 查询条件 + /// 排序条件 + /// 是否正序 + /// + List Query(Expression> whereExpression, Expression> orderByExpression, + bool isAsc = true); +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Serilog/SerilogExtensions.cs b/Sln.Imm.Daemon.Serilog/SerilogExtensions.cs new file mode 100644 index 0000000..3897330 --- /dev/null +++ b/Sln.Imm.Daemon.Serilog/SerilogExtensions.cs @@ -0,0 +1,62 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- +* 版权所有 (c) 2025 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:Mr.Wen's MacBook Pro +* 命名空间:Sln.Imm.Daemon.Serilog +* 唯一标识:21109DAB-7351-4989-B90E-BCCBE927EE8A +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2025-09-05 11:00:23 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using Microsoft.Extensions.DependencyInjection; +using Serilog; +using Sln.Imm.Daemon.Config; + +namespace Sln.Imm.Daemon.Serilog; + +public static class SerilogExtensions +{ + public static void UseSerilogExtensions(this IServiceProvider service) + { + //启用Serilog中间件 + + + #region 通过配置文件读取日志存放位置 + var appConfig = service.GetService(); + var logPath = Path.Combine(appConfig.logPath, "Logs"); + #endregion + + Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console() + .WriteTo.Logger(lc => lc + .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Info")) + .WriteTo.File(Path.Combine($"{logPath}/Info/", "Info.log"), rollingInterval: RollingInterval.Day)) + .WriteTo.Logger(lc => lc + .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Iot")) + .WriteTo.File(Path.Combine($"{logPath}/Iot/", "Iot.log"), rollingInterval: RollingInterval.Day)) + .WriteTo.Logger(lc => lc + .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Alarm")) + .WriteTo.File(Path.Combine($"{logPath}/Alarm/", "Alarm.log"), rollingInterval: RollingInterval.Day)) + .WriteTo.Logger(lc => lc + .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Error")) + .WriteTo.File(Path.Combine($"{logPath}/Error/", "Error.log"), rollingInterval: RollingInterval.Day)) + .CreateLogger(); + + + + } +} \ No newline at end of file diff --git a/Sln.Imm.Daemon.Serilog/SerilogHelper.cs b/Sln.Imm.Daemon.Serilog/SerilogHelper.cs new file mode 100644 index 0000000..1ef5891 --- /dev/null +++ b/Sln.Imm.Daemon.Serilog/SerilogHelper.cs @@ -0,0 +1,103 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- +* 版权所有 (c) 2025 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:Mr.Wen's MacBook Pro +* 命名空间:Sln.Imm.Daemon.Serilog +* 唯一标识:08A4FDC7-3133-4325-BF81-CCAD5E6B7336 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2025-09-05 11:02:13 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using Serilog; + +namespace Sln.Imm.Daemon.Serilog; + +public class SerilogHelper + { + private readonly ILogger? Info_logger = Log.ForContext("Module", "Info"); + private readonly ILogger? Iot_logger = Log.ForContext("Module", "Iot"); + private readonly ILogger? Error_logger = Log.ForContext("Module", "Error"); + private readonly ILogger? Alarm_logger = Log.ForContext("Module", "Alarm"); + + /// + /// Info日志 + /// + /// + public void Info(string msg) + { + if (Info_logger != null) + { + this.Info_logger.Information(msg); + } + } + + /// + /// Iot日志 + /// + /// + public void Iot(string msg) + { + if (Iot_logger != null) + { + this.Iot_logger.Information(msg); + } + } + + /// + /// 设备告警日志 + /// + /// + public void Alarm(string msg) + { + if (Alarm_logger != null) + { + this.Alarm_logger.Information(msg); + } + } + + /// + /// Error日志 + /// + /// + /// + public void Error(string msg, Exception ex = null) + { + if (!string.IsNullOrEmpty(msg) && ex == null) + { + this.Error_logger.Information("【附加信息】 : {0}
", new object[] { msg }); + } + else if (!string.IsNullOrEmpty(msg) && ex != null) + { + string errorMsg = BeautyErrorMsg(ex); + this.Error_logger.Information("【附加信息】 : {0}
{1}", new object[] { msg, errorMsg }); + } + else if (string.IsNullOrEmpty(msg) && ex != null) + { + string errorMsg = BeautyErrorMsg(ex); + this.Error_logger.Information(errorMsg); + } + } + + private string BeautyErrorMsg(Exception ex) + { + string errorMsg = string.Format("【异常类型】:{0}
【异常信息】:{1}
【堆栈调用】:{2}", new object[] { ex.GetType().Name, ex.Message, ex.StackTrace }); + errorMsg = errorMsg.Replace("\r\n", "
"); + errorMsg = errorMsg.Replace("位置", "位置"); + return errorMsg; + } + } \ No newline at end of file diff --git a/Sln.Imm.Daemon.sln b/Sln.Imm.Daemon.sln index 182dde2..84ce5f8 100644 --- a/Sln.Imm.Daemon.sln +++ b/Sln.Imm.Daemon.sln @@ -5,6 +5,18 @@ VisualStudioVersion = 17.10.35122.118 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sln.Imm.Daemon", "Sln.Imm.Daemon\Sln.Imm.Daemon.csproj", "{682DDE67-2CBF-4B54-831F-987EC6667FD1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sln.Imm.Daemon.Config", "Sln.Imm.Daemon.Config\Sln.Imm.Daemon.Config.csproj", "{A08A7879-F8B6-4A34-8ABE-2DEE3309F225}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sln.Imm.Daemon.Serilog", "Sln.Imm.Daemon.Serilog\Sln.Imm.Daemon.Serilog.csproj", "{3D173F48-72EC-46F5-AB2E-2B0A1A1729B9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sln.Imm.Daemon.Common", "Sln.Imm.Daemon.Common\Sln.Imm.Daemon.Common.csproj", "{728A030C-33EC-494C-AF86-ABC24B84AFD0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sln.Imm.Daemon.Model", "Sln.Imm.Daemon.Model\Sln.Imm.Daemon.Model.csproj", "{D0A7BFAC-A920-48E1-9F54-CA70DE7D01CF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sln.Imm.Daemon.Repository", "Sln.Imm.Daemon.Repository\Sln.Imm.Daemon.Repository.csproj", "{BE51B37D-92B4-4561-92B6-D236300E33FA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sln.Imm.Daemon.Cache", "Sln.Imm.Daemon.Cache\Sln.Imm.Daemon.Cache.csproj", "{143CC5C4-661C-42A9-BEA0-3C6653347DE5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +27,30 @@ Global {682DDE67-2CBF-4B54-831F-987EC6667FD1}.Debug|Any CPU.Build.0 = Debug|Any CPU {682DDE67-2CBF-4B54-831F-987EC6667FD1}.Release|Any CPU.ActiveCfg = Release|Any CPU {682DDE67-2CBF-4B54-831F-987EC6667FD1}.Release|Any CPU.Build.0 = Release|Any CPU + {A08A7879-F8B6-4A34-8ABE-2DEE3309F225}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A08A7879-F8B6-4A34-8ABE-2DEE3309F225}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A08A7879-F8B6-4A34-8ABE-2DEE3309F225}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A08A7879-F8B6-4A34-8ABE-2DEE3309F225}.Release|Any CPU.Build.0 = Release|Any CPU + {3D173F48-72EC-46F5-AB2E-2B0A1A1729B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3D173F48-72EC-46F5-AB2E-2B0A1A1729B9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3D173F48-72EC-46F5-AB2E-2B0A1A1729B9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3D173F48-72EC-46F5-AB2E-2B0A1A1729B9}.Release|Any CPU.Build.0 = Release|Any CPU + {728A030C-33EC-494C-AF86-ABC24B84AFD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {728A030C-33EC-494C-AF86-ABC24B84AFD0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {728A030C-33EC-494C-AF86-ABC24B84AFD0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {728A030C-33EC-494C-AF86-ABC24B84AFD0}.Release|Any CPU.Build.0 = Release|Any CPU + {D0A7BFAC-A920-48E1-9F54-CA70DE7D01CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D0A7BFAC-A920-48E1-9F54-CA70DE7D01CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D0A7BFAC-A920-48E1-9F54-CA70DE7D01CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D0A7BFAC-A920-48E1-9F54-CA70DE7D01CF}.Release|Any CPU.Build.0 = Release|Any CPU + {BE51B37D-92B4-4561-92B6-D236300E33FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE51B37D-92B4-4561-92B6-D236300E33FA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE51B37D-92B4-4561-92B6-D236300E33FA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE51B37D-92B4-4561-92B6-D236300E33FA}.Release|Any CPU.Build.0 = Release|Any CPU + {143CC5C4-661C-42A9-BEA0-3C6653347DE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {143CC5C4-661C-42A9-BEA0-3C6653347DE5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {143CC5C4-661C-42A9-BEA0-3C6653347DE5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {143CC5C4-661C-42A9-BEA0-3C6653347DE5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sln.Imm.Daemon/Program.cs b/Sln.Imm.Daemon/Program.cs index 3bd8fdb..7233b58 100644 --- a/Sln.Imm.Daemon/Program.cs +++ b/Sln.Imm.Daemon/Program.cs @@ -1,10 +1,71 @@ -namespace Sln.Imm.Daemon +using System.Reflection; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using NeoSmart.Caching.Sqlite; +using Sln.Imm.Daemon.Config; +using Sln.Imm.Daemon.Repository; +using Sln.Imm.Daemon.Serilog; +using ZiggyCreatures.Caching.Fusion; +using ZiggyCreatures.Caching.Fusion.Serialization.NewtonsoftJson; + +namespace Sln.Imm.Daemon { internal class Program { + public static IServiceProvider? ServiceProvider = null; + static void Main(string[] args) { - Console.WriteLine("Hello, World!"); + var services = new ServiceCollection(); + ConfigureServices(services); + ServiceProvider = services.BuildServiceProvider(); + ServiceProvider.UseSerilogExtensions(); + + var appConfig = ServiceProvider.GetService(); + var log = ServiceProvider.GetService(); + log.Info($"系统启动成功,日志存放位置:{appConfig.logPath}"); + } + + private static void ConfigureServices(IServiceCollection services) + { + services.AddSingleton(provider => + { + var configurationBuilder = new ConfigurationBuilder() + .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); + IConfiguration configuration = configurationBuilder.Build(); + var ap = configuration.GetSection("AppConfig").Get(); + return ap; + }); + + Assembly[] assemblies = + { + Assembly.LoadFrom("Sln.Iot.Common.dll"), + Assembly.LoadFrom("Sln.Iot.Repository.dll"), + // Assembly.LoadFrom("Sln.Iot.Socket.dll"), + // Assembly.LoadFrom("Sln.Iot.Business.dll"), + // Assembly.LoadFrom("Sln.Iot.Cache.dll"), + }; + + services.Scan(scan => scan.FromAssemblies(assemblies) + .AddClasses() + .AsImplementedInterfaces() + .AsSelf() + .WithSingletonLifetime()); + + services.AddSingleton(typeof(SerilogHelper)); + + services.AddSqlSugarSetup(); + + services.AddFusionCache() + .WithSerializer( + new FusionCacheNewtonsoftJsonSerializer() + ) + .WithDistributedCache( + new SqliteCache(new SqliteCacheOptions + { + CachePath = "/Users/wenxiansheng/Public/WorkSpace/Mesnac/项目资料/澳柯玛注塑车间MES项目/数据缓存/FusionCache.db" + })); } } -} +} \ No newline at end of file diff --git a/Sln.Imm.Daemon/Sln.Imm.Daemon.csproj b/Sln.Imm.Daemon/Sln.Imm.Daemon.csproj index 74abf5c..e934311 100644 --- a/Sln.Imm.Daemon/Sln.Imm.Daemon.csproj +++ b/Sln.Imm.Daemon/Sln.Imm.Daemon.csproj @@ -1,10 +1,28 @@ - - Exe - net6.0 - enable - enable - + + Exe + net8.0 + enable + enable + + + + + + + + + + + + + + + + + PreserveNewest + + diff --git a/Sln.Imm.Daemon/appsettings.json b/Sln.Imm.Daemon/appsettings.json new file mode 100644 index 0000000..f04ed9c --- /dev/null +++ b/Sln.Imm.Daemon/appsettings.json @@ -0,0 +1,14 @@ +{ + "AppConfig": { + "logPath": "/Users/wenxiansheng/Public/WorkSpace/Mesnac/项目资料/澳柯玛注塑车间MES项目/日志信息", + "SqlConfig": [ + { + "configId": "mes", //imm:注塑设备简称 + "dbType": 0, //tidb按照 mysql 去连接 + "isFlag": false, + "connStr": "server=127.0.0.1;Port=4000;Database=tao_iot;Uid=root;" //Pwd=haiwei@123; + //"connStr": "server=1.13.177.47;Port=3306;Database=tao_iot;Uid=root;Pwd=Haiwei123456;" + } + ] + } +} \ No newline at end of file