change - 添加数据过滤方法

master
Wen JY 9 months ago
parent 825e005c77
commit 290b85cc0e

@ -565,18 +565,75 @@ namespace Ems.CollectService.Analysis
recordDnbInstant.zxyg = recordDnbInstant.zxyg == appConfig.virtualValue ? 0 : recordDnbInstant.zxyg; recordDnbInstant.zxyg = recordDnbInstant.zxyg == appConfig.virtualValue ? 0 : recordDnbInstant.zxyg;
if (FIlterDnbInstant(recordDnbInstant))
{
var info = SqlSugarHelper.Db.Insertable<RecordDnbInstant>(recordDnbInstant).ExecuteCommand(); var info = SqlSugarHelper.Db.Insertable<RecordDnbInstant>(recordDnbInstant).ExecuteCommand();
if (info > 0) if (info > 0)
{ {
logger.Info($"仪表:{recordDnbInstant.monitorId}数据保存成功"); logger.Info($"仪表:{recordDnbInstant.monitorId}数据保存成功");
} }
} }
}
}catch(Exception ex) }catch(Exception ex)
{ {
logger.Error($"仪表:{recordDnbInstant.monitorId}数据保存异常:{ex.Message}"); logger.Error($"仪表:{recordDnbInstant.monitorId}数据保存异常:{ex.Message}");
} }
} }
/// <summary>
/// 过滤数据与前一条相差超过4000不进行保存
/// </summary>
/// <param name="dnbInstant"></param>
/// <returns></returns>
private bool FIlterDnbInstant(RecordDnbInstant dnbInstant)
{
bool result = true;
do
{
RecordDnbInstant lastDnbInstant = SqlSugarHelper.Db.Queryable<RecordDnbInstant>()
.First(x => x.monitorId == dnbInstant.monitorId);
if (lastDnbInstant == null)
{
break;
}
BaseMonitorInfo monitorInfo = SqlSugarHelper.Db.Queryable<BaseMonitorInfo>()
.First(x => x.MonitorId == dnbInstant.monitorId);
if (monitorInfo == null)
{
result = false;
break;
}
if (monitorInfo.Pt == 0 || monitorInfo.Pt == null)
{
monitorInfo.Pt = 1;
}
if (monitorInfo.Ct == 0 || monitorInfo.Ct == null)
{
monitorInfo.Ct = 1;
}
decimal? lastZxyg = lastDnbInstant.zxyg * monitorInfo.Pt * monitorInfo.Ct;
decimal? dnbInstantZxyg = dnbInstant.zxyg * monitorInfo.Pt * monitorInfo.Ct;
decimal? zxygRes = dnbInstantZxyg - lastZxyg;
var appConfigDifferenceValue = appConfig.differenceValue == 0 ? 4000 : appConfig.differenceValue;
if ( zxygRes >= appConfigDifferenceValue)
{
logger.Info($"仪表:{dnbInstant.monitorId}与上一条数据相差超过4000不进行保存");
result = false;
}
} while (false);
return result;
}
/// <summary> /// <summary>
/// 水表数据 /// 水表数据
/// </summary> /// </summary>

@ -58,6 +58,14 @@ namespace Ems.CollectService.Entity.config
get { return _configuration.GetValue<string>("SystemConfig:virtualFlag") == "是" ? true : false;} get { return _configuration.GetValue<string>("SystemConfig:virtualFlag") == "是" ? true : false;}
} }
/// <summary>
/// 是否启用点抄功能
/// </summary>
public bool readMeterFlag
{
get { return _configuration.GetValue<string>("SystemConfig:readMeterFlag") == "是" ? true : false;}
}
/// <summary> /// <summary>
/// 日志文件路径 /// 日志文件路径
/// </summary> /// </summary>
@ -73,5 +81,10 @@ namespace Ems.CollectService.Entity.config
{ {
get { return _configuration.GetValue<long>("SystemConfig:deleteLogTimer"); } get { return _configuration.GetValue<long>("SystemConfig:deleteLogTimer"); }
} }
public int differenceValue
{
get { return _configuration.GetValue<int>("SystemConfig:differenceValue"); }
}
} }
} }

@ -86,7 +86,6 @@ namespace Ems.CollectService.TouchSocket
})) }))
.Start();//启动 .Start();//启动
ReadMeterTask(); //点抄指令下发
logger.Info($"采集服务启动成功,监听端口:{serverPort}"); logger.Info($"采集服务启动成功,监听端口:{serverPort}");
} }
catch(Exception ex) catch(Exception ex)
@ -172,8 +171,13 @@ namespace Ems.CollectService.TouchSocket
/// <summary> /// <summary>
/// 点抄指令下发 /// 点抄指令下发
/// </summary> /// </summary>
private void ReadMeterTask() public void ReadMeterTask(bool isFlag = false)
{ {
if (isFlag == false)
{
logger.Info($"未启用点抄仪表功能");
return;
}
try try
{ {
var t = Task.Run(async delegate var t = Task.Run(async delegate

@ -23,6 +23,7 @@ namespace Ems.CollectService
try try
{ {
service.Init(appConfig.listenerPort); service.Init(appConfig.listenerPort);
service.ReadMeterTask(appConfig.readMeterFlag);
//定时删除日志文件夹 //定时删除日志文件夹
deleteLogFile.DeleteLogFileTimer(); deleteLogFile.DeleteLogFileTimer();
} }

Loading…
Cancel
Save