diff --git a/Sln.Iot.Common/Class1.cs b/Sln.Iot.Common/Class1.cs
deleted file mode 100644
index 6644cec..0000000
--- a/Sln.Iot.Common/Class1.cs
+++ /dev/null
@@ -1,5 +0,0 @@
-namespace Sln.Iot.Common;
-
-public class Class1
-{
-}
\ No newline at end of file
diff --git a/Sln.Iot.Model/Class1.cs b/Sln.Iot.Model/Class1.cs
deleted file mode 100644
index 636c8d9..0000000
--- a/Sln.Iot.Model/Class1.cs
+++ /dev/null
@@ -1,5 +0,0 @@
-namespace Sln.Iot.Model;
-
-public class Class1
-{
-}
\ No newline at end of file
diff --git a/Sln.Iot.Model/dao/BaseAlarmRule.cs b/Sln.Iot.Model/dao/BaseAlarmRule.cs
index 0117c5c..25506ee 100644
--- a/Sln.Iot.Model/dao/BaseAlarmRule.cs
+++ b/Sln.Iot.Model/dao/BaseAlarmRule.cs
@@ -57,5 +57,11 @@ namespace Sln.Iot.Model.dao
///
[SugarColumn(ColumnName = "cause")]
public string cause { get; set; }
+
+ ///
+ /// 告警记录ID,推送数据使用,ORM不用
+ ///
+ [SugarColumn(IsIgnore = true)]
+ public long alarmId { get; set; }
}
}
diff --git a/Sln.Iot.Model/dao/RecordAlarmData.cs b/Sln.Iot.Model/dao/RecordAlarmData.cs
new file mode 100644
index 0000000..8ecdd69
--- /dev/null
+++ b/Sln.Iot.Model/dao/RecordAlarmData.cs
@@ -0,0 +1,83 @@
+#region << 版 本 注 释 >>
+
+/*--------------------------------------------------------------------
+* 版权所有 (c) 2025 Wen JY 保留所有权利。
+* CLR版本:4.0.30319.42000
+* 机器名称:ThinkPad T14
+* 命名空间:Sln.Iot.Model.dao
+* 唯一标识:50695B31-9DE2-4EE5-A13D-D58B53CDEBBA
+*
+* 创建者:WenJY
+* 电子邮箱:
+* 创建时间:2025-06-05 10:38:09
+* 版本:V1.0.0
+* 描述:
+*
+*--------------------------------------------------------------------
+* 修改人:
+* 时间:
+* 修改说明:
+*
+* 版本:V1.0.0
+*--------------------------------------------------------------------*/
+
+#endregion << 版 本 注 释 >>
+
+using SqlSugar;
+
+namespace Sln.Iot.Model.dao;
+
+///
+///告警数据记录
+///
+[SugarTable("ems_record_alarm_data"), Tenant("tao_iot")]
+public class RecordAlarmData
+{
+
+ ///
+ /// 编号
+ ///
+ [SugarColumn(ColumnName = "obj_id", IsPrimaryKey = true)]
+ public long objid { get; set; }
+
+ ///
+ /// Desc:计量设备编号
+ /// Default:
+ /// Nullable:False
+ ///
+ [SugarColumn(IsPrimaryKey=true,ColumnName="monitor_id")]
+ public string monitorId {get;set;}
+
+ ///
+ /// Desc:采集设备编号
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="collect_device_id")]
+ public string collectDeviceId {get;set;}
+
+ ///
+ /// 触发规则(0大于 1小于)
+ ///
+ [SugarColumn(ColumnName = "alarm_type")]
+ public int triggerRule { get; set; }
+
+ ///
+ /// 监测字段(0温度,1湿度,2振动-速度(mm/s),3振动-位移(um),4振动-加速度(g),5振动-温度(℃),6-噪音,7-照度)
+ ///
+ [SugarColumn(ColumnName = "cause")]
+ public int monitorField { get;set; }
+
+ ///
+ /// 告警值
+ ///
+ [SugarColumn(ColumnName = "alarm_data")]
+ public decimal alarmValue { get;set; }
+
+ ///
+ /// 采集时间
+ ///
+ [SugarColumn(ColumnName="collect_time" )]
+ public DateTime? collectTime { get; set; }
+
+}
\ No newline at end of file
diff --git a/Sln.Iot.Model/dto/MonitorAlarmDto.cs b/Sln.Iot.Model/dto/MonitorAlarmDto.cs
index fa1dd05..26c62c8 100644
--- a/Sln.Iot.Model/dto/MonitorAlarmDto.cs
+++ b/Sln.Iot.Model/dto/MonitorAlarmDto.cs
@@ -19,7 +19,7 @@ namespace Sln.Iot.Model.dto
/// 是否报警:1-是;0-否
///
public int isFlag { get;set; }
-
+
///
/// 设备参数
///
diff --git a/Sln.Iot.Repository/Class1.cs b/Sln.Iot.Repository/Class1.cs
deleted file mode 100644
index e063971..0000000
--- a/Sln.Iot.Repository/Class1.cs
+++ /dev/null
@@ -1,5 +0,0 @@
-namespace Sln.Iot.Repository;
-
-public class Class1
-{
-}
\ No newline at end of file
diff --git a/Sln.Iot.Repository/service/IRecordAlarmDataService.cs b/Sln.Iot.Repository/service/IRecordAlarmDataService.cs
new file mode 100644
index 0000000..c51c11d
--- /dev/null
+++ b/Sln.Iot.Repository/service/IRecordAlarmDataService.cs
@@ -0,0 +1,9 @@
+using Sln.Iot.Model.dao;
+using Sln.Iot.Repository.service.@base;
+
+namespace Sln.Iot.Repository.service;
+
+public interface IRecordAlarmDataService:IBaseService
+{
+
+}
\ No newline at end of file
diff --git a/Sln.Iot.Repository/service/Impl/RecordAlarmDataServiceImpl.cs b/Sln.Iot.Repository/service/Impl/RecordAlarmDataServiceImpl.cs
new file mode 100644
index 0000000..ed77e54
--- /dev/null
+++ b/Sln.Iot.Repository/service/Impl/RecordAlarmDataServiceImpl.cs
@@ -0,0 +1,36 @@
+#region << 版 本 注 释 >>
+
+/*--------------------------------------------------------------------
+* 版权所有 (c) 2025 Wen JY 保留所有权利。
+* CLR版本:4.0.30319.42000
+* 机器名称:ThinkPad T14
+* 命名空间:Sln.Iot.Repository.service.Impl
+* 唯一标识:0838E02D-6FDB-4D1D-8A1F-B78B582EE185
+*
+* 创建者:WenJY
+* 电子邮箱:
+* 创建时间:2025-06-05 10:46:10
+* 版本:V1.0.0
+* 描述:
+*
+*--------------------------------------------------------------------
+* 修改人:
+* 时间:
+* 修改说明:
+*
+* 版本:V1.0.0
+*--------------------------------------------------------------------*/
+
+#endregion << 版 本 注 释 >>
+
+using Sln.Iot.Model.dao;
+using Sln.Iot.Repository.service.@base;
+
+namespace Sln.Iot.Repository.service.Impl;
+
+public class RecordAlarmDataServiceImpl: BaseServiceImpl, IRecordAlarmDataService
+{
+ public RecordAlarmDataServiceImpl(Repository rep) : base(rep)
+ {
+ }
+}
\ No newline at end of file
diff --git a/Sln.Iot.Serial/SerialExtensions.cs b/Sln.Iot.Serial/SerialExtensions.cs
deleted file mode 100644
index 1fca02f..0000000
--- a/Sln.Iot.Serial/SerialExtensions.cs
+++ /dev/null
@@ -1,198 +0,0 @@
-using Dm.util;
-using Microsoft.Extensions.DependencyInjection;
-using Newtonsoft.Json;
-using RJCP.IO.Ports;
-using Sln.Iot.Business;
-using Sln.Iot.Common;
-using Sln.Iot.Config;
-using Sln.Iot.Model.dao;
-using Sln.Iot.Model.dto;
-using Sln.Iot.Repository.service;
-using Sln.Iot.Serilog;
-using SqlSugar;
-using System;
-using System.Linq.Expressions;
-using System.Net.WebSockets;
-using System.Text;
-using TouchSocket.Core;
-using TouchSocket.Sockets;
-
-namespace Sln.Iot.Serial
-{
- public static class SerialExtensions
- {
-
- public static void UseSerialPortExtensions(this IServiceProvider service)
- {
- IRecordIotEnvInstantService instantService = service.GetService();
-
- IBaseAlarmRuleService _alarmRuleService = service.GetService();
-
- WebSocketBusiness webSocket = service.GetService();
-
- var logger = service.GetService();
- try
- {
- var appConfig = service.GetService();
- var tcpClient = service.GetService();
- var stringChange = service.GetService();
-
- SerialPortStream serialPort = new SerialPortStream(appConfig.serialPortConfig.PortName);
- serialPort.BaudRate = appConfig.serialPortConfig.BaudRate;
- serialPort.Parity = Parity.None;
- serialPort.StopBits = StopBits.One;
- serialPort.DataBits = appConfig.serialPortConfig.DataBits;
- serialPort.Handshake = Handshake.None;
-
- serialPort.DataReceived += (sender, e) =>
- {
- lock (string.Empty)
- {
- try
- {
- byte[] receivedData = new byte[serialPort.BytesToRead];
- serialPort.Read(receivedData, 0, receivedData.Length);
-
- string str = Encoding.ASCII.GetString(receivedData);
- logger.Info($"串口服务接收到数据:{str}");
-
- List< RecordIotEnvInstant > iotEnvInstants = new List< RecordIotEnvInstant >();
- string[] monitorInfos = str.Split(';');
-
- foreach ( string monitorInfo in monitorInfos )
- {
-
- if (monitorInfo.Length < 12)
- {
- continue;
- }
- logger.Info($"解析串口数据:{monitorInfo}");
- RecordIotEnvInstant iotEnvInstant = new RecordIotEnvInstant();
- string[] strs = monitorInfo.Replace(";","").Split('-');
-
- iotEnvInstant.monitorId = strs[0];
-
- if (strs[1] == "5" || strs[1] == "6")
- {
- iotEnvInstant.temperature = decimal.Parse(strs[2].Trim());
- }
- if (strs[1] == "6")
- {
- iotEnvInstant.humidity = decimal.Parse(strs[3].Trim());
- }
- if (strs[1] == "7")
- {
- iotEnvInstant.noise = decimal.Parse(strs[2].Trim());
- }
- if (strs[1] == "8")
- {
- iotEnvInstant.illuminance = decimal.Parse(strs[2].Trim());
- }
-
- if (strs[1] == "10")
- {
- iotEnvInstant.vibrationSpeed = decimal.Parse(strs[2].Trim());
- iotEnvInstant.vibrationAcceleration = decimal.Parse(strs[3].Trim());
- iotEnvInstant.vibrationDisplacement = decimal.Parse(strs[4].Trim());
- iotEnvInstant.vibrationTemp = decimal.Parse(strs[5].Trim());
- }
- iotEnvInstant.collectTime = DateTime.Now;
- iotEnvInstant.recordTime = DateTime.Now;
- iotEnvInstants.Add(iotEnvInstant);
-
- Thread.Sleep(200);
- }
-
-
- var inRes = instantService.SplitInsert(iotEnvInstants, out List insertIds);
-
- logger.Info($"物联网数据保存{(inRes ? "成功" : "失败")}");
-
- ParamAlarmFilter(iotEnvInstants,_alarmRuleService,logger, webSocket);
- }
- catch (Exception ex)
- {
- logger.Info($"串口接收数据异常:{ex.Message}");
- }
- }
- };
-
- serialPort.Open();
-
- logger.Info($"串口服务加载启动成功");
- }
- catch (Exception ex)
- {
- logger.Error($"串口服务加载异常:{ex.Message}");
- }
- }
-
- private static void ParamAlarmFilter(List iotEnvInstants, IBaseAlarmRuleService _alarmRuleService, SerilogHelper _logger, WebSocketBusiness _webSocket)
- {
- if (iotEnvInstants == null)
- {
- throw new ArgumentNullException(nameof(iotEnvInstants), "报警参数过滤异常,传入参数为空");
- }
-
- // 预编译比较委托(避免循环内重复编译)
- static Func CreateComparer(int triggerRule)
- {
- ParameterExpression x = Expression.Parameter(typeof(decimal), "x");
- ParameterExpression y = Expression.Parameter(typeof(decimal), "y");
- BinaryExpression comparison = triggerRule == 0
- ? Expression.GreaterThan(x, y)
- : Expression.LessThan(x, y);
- return Expression.Lambda>(comparison, x, y).Compile();
- }
-
- var fieldAccessors = new Dictionary>
- {
- { 0, item => item.temperature },
- { 1, item => item.humidity },
- { 2, item => item.vibrationSpeed },
- { 3, item => item.vibrationDisplacement },
- { 4, item => item.vibrationAcceleration },
- { 5, item => item.vibrationTemp },
- { 6, item => item.noise },
- { 7, item => item.illuminance }
- };
-
- foreach (var item in iotEnvInstants)
- {
- var alarmRules = _alarmRuleService.Query(x => x.monitorId == item.monitorId);
-
- List ruleRes = new List();
- List alarmContents = new List();
- foreach (var rule in alarmRules)
- {
- decimal paramValue = fieldAccessors.TryGetValue(rule.monitorField, out var accessor)
- ? accessor(item)
- : 0;
-
- var comparer = CreateComparer(rule.triggerRule);
-
- if (comparer(paramValue, rule.triggerValue))
- {
- ruleRes.Add(rule);
- alarmContents.Add($"{item.monitorId}传感器数据在{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}触发{rule.ruleName}异常告警,告警规则:{(rule.triggerRule == 0 ? "大于" : "小于")},阈值:{rule.triggerValue},详细信息:{rule.cause}");
- }
- }
-
- MonitorAlarmDto monitorAlarmDto = new MonitorAlarmDto()
- {
- monitorId = item.monitorId,
- isFlag = ruleRes.Count() > 0 ? 1 : 0,
- deviceParam = item,
- alarmRules = ruleRes,
- alarmContents = alarmContents,
- recordTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
- };
- string str = JsonConvert.SerializeObject(monitorAlarmDto);
- _logger.Alarm($"传感器数据推送:{str}");
-
- _webSocket.PushMsg(str);
- }
- }
-
- }
-}
diff --git a/Sln.Iot.Serial/Sln.Iot.Serial.csproj b/Sln.Iot.Serial/Sln.Iot.Serial.csproj
deleted file mode 100644
index dae9b9b..0000000
--- a/Sln.Iot.Serial/Sln.Iot.Serial.csproj
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
- net6.0
- enable
- enable
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Always
-
-
-
-
diff --git a/Sln.Iot.Serial/libnserial.so.1 b/Sln.Iot.Serial/libnserial.so.1
deleted file mode 100644
index 5b93c2a..0000000
Binary files a/Sln.Iot.Serial/libnserial.so.1 and /dev/null differ
diff --git a/Sln.Iot.Serilog/Class1.cs b/Sln.Iot.Serilog/Class1.cs
deleted file mode 100644
index 4416261..0000000
--- a/Sln.Iot.Serilog/Class1.cs
+++ /dev/null
@@ -1,5 +0,0 @@
-namespace Sln.Iot.Serilog;
-
-public class Class1
-{
-}
\ No newline at end of file
diff --git a/Sln.Iot.sln b/Sln.Iot.sln
index a491fd6..1d3561e 100644
--- a/Sln.Iot.sln
+++ b/Sln.Iot.sln
@@ -19,8 +19,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sln.Iot.Serilog", "Sln.Iot.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sln.Iot.Socket", "Sln.Iot.Socket\Sln.Iot.Socket.csproj", "{5B7C6367-7B41-48A6-9A71-2F191CE14000}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sln.Iot.Serial", "Sln.Iot.Serial\Sln.Iot.Serial.csproj", "{A030CF57-DAA0-4662-B836-3CFC2CDCD9FE}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -59,10 +57,6 @@ Global
{5B7C6367-7B41-48A6-9A71-2F191CE14000}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B7C6367-7B41-48A6-9A71-2F191CE14000}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B7C6367-7B41-48A6-9A71-2F191CE14000}.Release|Any CPU.Build.0 = Release|Any CPU
- {A030CF57-DAA0-4662-B836-3CFC2CDCD9FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {A030CF57-DAA0-4662-B836-3CFC2CDCD9FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {A030CF57-DAA0-4662-B836-3CFC2CDCD9FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {A030CF57-DAA0-4662-B836-3CFC2CDCD9FE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Sln.Iot/Program.cs b/Sln.Iot/Program.cs
index cd8b3fa..6a1af7c 100644
--- a/Sln.Iot/Program.cs
+++ b/Sln.Iot/Program.cs
@@ -7,10 +7,7 @@ using Sln.Iot.Config;
using Sln.Iot.Repository;
using Sln.Iot.Serilog;
using Sln.Iot.Socket;
-using Sln.Iot.Serial;
using TouchSocket.Sockets;
-using TouchSocket.Core;
-using Fleck;
namespace Sln.Iot
{
@@ -78,9 +75,6 @@ namespace Sln.Iot
);
}
};
-
- ServiceProvider.UseSerialPortExtensions();
-
await Task.Delay(-1);
}
diff --git a/Sln.Iot/Sln.Iot.csproj b/Sln.Iot/Sln.Iot.csproj
index e953348..ee5f903 100644
--- a/Sln.Iot/Sln.Iot.csproj
+++ b/Sln.Iot/Sln.Iot.csproj
@@ -14,7 +14,6 @@
-
@@ -28,9 +27,6 @@
PreserveNewest
-
- Always
-
diff --git a/Sln.Iot/libnserial.so.1 b/Sln.Iot/libnserial.so.1
deleted file mode 100644
index 5b93c2a..0000000
Binary files a/Sln.Iot/libnserial.so.1 and /dev/null differ