251030
This commit is contained in:
@@ -14,7 +14,7 @@ namespace MoviconHub.App
|
|||||||
{
|
{
|
||||||
public static IFreeSql FDb = new FreeSql.FreeSqlBuilder()
|
public static IFreeSql FDb = new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.SqlServer, ConfigHelper.GetValue("RemoteConnecting"))
|
.UseConnectionString(FreeSql.DataType.SqlServer, ConfigHelper.GetValue("RemoteConnecting"))
|
||||||
.UseAutoSyncStructure(true) //自动同步实体结构到数据库
|
.UseAutoSyncStructure(false) //自动同步实体结构到数据库
|
||||||
.Build(); //请务必定义成 Singleton 单例模式
|
.Build(); //请务必定义成 Singleton 单例模式
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ namespace MoviconHub.App.Models
|
|||||||
[Column(Name = "DeviceState", IsNullable = true)]
|
[Column(Name = "DeviceState", IsNullable = true)]
|
||||||
public int? DeviceState { get; set; }
|
public int? DeviceState { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 报警信息
|
||||||
|
/// </summary>
|
||||||
|
[Column(Name = "AlarmMessage", StringLength = 180, IsNullable = true)]
|
||||||
|
public string AlarmMessage { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建时间
|
/// 创建时间
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ namespace MoviconHub.App.Services
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.Error(ex, "轮询RTVar数据时发生错误");
|
Logger.Error($"实时数据轮询时发生错误: {ex.Message}");
|
||||||
// 发生错误时,等待一段时间后重试
|
// 发生错误时,等待一段时间后重试
|
||||||
await Task.Delay(5000, cancellationToken);
|
await Task.Delay(5000, cancellationToken);
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,7 @@ namespace MoviconHub.App.Services
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.Error(ex, "读取RTVar数据时发生错误");
|
Logger.Error($"读取RTVar数据时发生错误: {ex.StackTrace}");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,6 +153,9 @@ namespace MoviconHub.App.Services
|
|||||||
/// <param name="rtVars">RTVar数据列表</param>
|
/// <param name="rtVars">RTVar数据列表</param>
|
||||||
private void UpdateWebSocketData(List<RTVar> rtVars)
|
private void UpdateWebSocketData(List<RTVar> rtVars)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
if (rtVars == null || rtVars.Count == 0)
|
if (rtVars == null || rtVars.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -196,8 +199,15 @@ namespace MoviconHub.App.Services
|
|||||||
//更新数据到远程数据库
|
//更新数据到远程数据库
|
||||||
|
|
||||||
// 记录日志
|
// 记录日志
|
||||||
Logger.Debug("实时数据已更新");
|
//Logger.Debug("实时数据已更新");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Error($"UpdateWebSocketData: {ex.StackTrace}");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -205,6 +215,8 @@ namespace MoviconHub.App.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="webSocketData"></param>
|
/// <param name="webSocketData"></param>
|
||||||
private void UpdateRemoteDb(WebSocketData webSocketData)
|
private void UpdateRemoteDb(WebSocketData webSocketData)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
// 获取组件信息
|
// 获取组件信息
|
||||||
var component = webSocketData.ListComponentsInfo?.FirstOrDefault();
|
var component = webSocketData.ListComponentsInfo?.FirstOrDefault();
|
||||||
@@ -273,6 +285,12 @@ namespace MoviconHub.App.Services
|
|||||||
Logger.Debug("实时数据已更新到远程数据库");
|
Logger.Debug("实时数据已更新到远程数据库");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Error($"UpdateRemoteDb: {ex.StackTrace}");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -449,6 +449,16 @@ namespace MoviconHub.App
|
|||||||
EndTime = Value.EndTime,
|
EndTime = Value.EndTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (Data.DeviceState == 4)
|
||||||
|
{
|
||||||
|
var ActiveAlarmModels = ListAlarmModels.Where(a => a.IsActive == true).ToList();
|
||||||
|
if (ActiveAlarmModels != null && ActiveAlarmModels.Count > 0)
|
||||||
|
{
|
||||||
|
Data.AlarmMessage = ActiveAlarmModels.FirstOrDefault().AlarmMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var Result = FRemoteSqlContext.FDb.Insert<DeviceStatusChange>(Data).ExecuteInserted();
|
var Result = FRemoteSqlContext.FDb.Insert<DeviceStatusChange>(Data).ExecuteInserted();
|
||||||
if (Result != null && Result.Count > 0)
|
if (Result != null && Result.Count > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,8 +48,7 @@ namespace MoviconWebApi.API.DeviceStateApi
|
|||||||
a.StandbyTime,
|
a.StandbyTime,
|
||||||
a.FaultTime,
|
a.FaultTime,
|
||||||
a.ShutdownTime,
|
a.ShutdownTime,
|
||||||
a.FaultNum,
|
a.FaultNum
|
||||||
a.JobNum
|
|
||||||
});
|
});
|
||||||
|
|
||||||
long totalPowerOn = lightList.Sum(x => (long)(x.PowerOnTime ?? 0));
|
long totalPowerOn = lightList.Sum(x => (long)(x.PowerOnTime ?? 0));
|
||||||
@@ -58,7 +57,11 @@ namespace MoviconWebApi.API.DeviceStateApi
|
|||||||
long totalFault = lightList.Sum(x => (long)(x.FaultTime ?? 0));
|
long totalFault = lightList.Sum(x => (long)(x.FaultTime ?? 0));
|
||||||
long totalShutdown = lightList.Sum(x => (long)(x.ShutdownTime ?? 0));
|
long totalShutdown = lightList.Sum(x => (long)(x.ShutdownTime ?? 0));
|
||||||
long totalFaultCount = lightList.Sum(x => (long)(x.FaultNum ?? 0));
|
long totalFaultCount = lightList.Sum(x => (long)(x.FaultNum ?? 0));
|
||||||
long totalJobCount = lightList.Sum(x => (long)(x.JobNum ?? 0));
|
// 作业次数:来自当前搜索时间内 ClearData 的记录数
|
||||||
|
long totalJobCount = await db.Select<ClearData>()
|
||||||
|
.WhereIf(!string.IsNullOrWhiteSpace(request.DeviceCode), x => x.DeviceCode == request.DeviceCode)
|
||||||
|
.Where(x => x.CreateTime >= startTime && x.CreateTime <= endTime)
|
||||||
|
.CountAsync();
|
||||||
|
|
||||||
// 若该时间段内没有任何记录,返回空集合
|
// 若该时间段内没有任何记录,返回空集合
|
||||||
var hasAnyData = (totalPowerOn + totalRun + totalStandby + totalFault + totalShutdown + totalFaultCount + totalJobCount) > 0;
|
var hasAnyData = (totalPowerOn + totalRun + totalStandby + totalFault + totalShutdown + totalFaultCount + totalJobCount) > 0;
|
||||||
@@ -99,7 +102,7 @@ namespace MoviconWebApi.API.DeviceStateApi
|
|||||||
ShutdownTime = (int)totalShutdown,
|
ShutdownTime = (int)totalShutdown,
|
||||||
UseRatio = useRatioText,
|
UseRatio = useRatioText,
|
||||||
FaultNum = (int)totalFaultCount,
|
FaultNum = (int)totalFaultCount,
|
||||||
JobNum = (int)totalJobCount,
|
JobNum = totalJobCount > int.MaxValue ? int.MaxValue : (int)totalJobCount,
|
||||||
CreateTime = endTime.ToString("yyyy-MM-dd HH:mm:ss")
|
CreateTime = endTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user