diff --git a/PVDEMCS/.vs/PVDEMCS/DesignTimeBuild/.dtbcache.v2 b/PVDEMCS/.vs/PVDEMCS/DesignTimeBuild/.dtbcache.v2
index 8d504d8..85620a4 100644
Binary files a/PVDEMCS/.vs/PVDEMCS/DesignTimeBuild/.dtbcache.v2 and b/PVDEMCS/.vs/PVDEMCS/DesignTimeBuild/.dtbcache.v2 differ
diff --git a/PVDEMCS/.vs/PVDEMCS/v17/.suo b/PVDEMCS/.vs/PVDEMCS/v17/.suo
index 1263ec6..71be1b8 100644
Binary files a/PVDEMCS/.vs/PVDEMCS/v17/.suo and b/PVDEMCS/.vs/PVDEMCS/v17/.suo differ
diff --git a/PVDEMCS/PVDEMCS/Devices/Impl/DeviceRun.cs b/PVDEMCS/PVDEMCS/Devices/Impl/DeviceRun.cs
index 72024c1..0acb78c 100644
--- a/PVDEMCS/PVDEMCS/Devices/Impl/DeviceRun.cs
+++ b/PVDEMCS/PVDEMCS/Devices/Impl/DeviceRun.cs
@@ -88,20 +88,23 @@ namespace PVDEMCS.Devices.Impl
}
}
+ //
private void TaskRun()
{
+ //监控设备连接
Task.Run(() =>
{
while (true)
{
foreach (var item in monitors)
{
- var task = item.StopAsync();
+ var task = item.StartAsync();
}
Thread.Sleep(5000);
}
});
+ //添加设备记录
Task.Run(() =>
{
while (true)
@@ -112,16 +115,22 @@ namespace PVDEMCS.Devices.Impl
}
});
-
+ //设备记录日统计
Task.Run(() =>
{
while (true)
{
- RunEquipmentRecordTotal();
+ equipmentRecordService.RunEquipmentRecordDayTotal(DateTime.Now);
Thread.Sleep(1000 * 60);
}
});
+
+ //设备记录统计
+ Task.Run(() =>
+ {
+ equipmentRecordService.RunEquipmentRecordTotal();
+ });
}
//记录设备数据
@@ -169,12 +178,6 @@ namespace PVDEMCS.Devices.Impl
}
}
- //记录设备数据统计
- private void RunEquipmentRecordTotal()
- {
- equipmentRecordService.RunEquipmentRecordTotal(DateTime.Now);
- }
-
private void DeviceMonitor_PointChnage(object sender, DevicePoint e)
{
}
diff --git a/PVDEMCS/PVDEMCS/Services/IEquipmentRecordService.cs b/PVDEMCS/PVDEMCS/Services/IEquipmentRecordService.cs
index 4f05728..4c92be6 100644
--- a/PVDEMCS/PVDEMCS/Services/IEquipmentRecordService.cs
+++ b/PVDEMCS/PVDEMCS/Services/IEquipmentRecordService.cs
@@ -43,7 +43,6 @@ namespace PVDEMCS.Services
///
/// 设备Id
/// 设备状态,运行:Run,待机:Stop,报警:Alarm
- /// 设备Id
///
Result AddUpdateEquipmentRecord(string equipmentId, string state, DateTime dateTime);
@@ -52,7 +51,13 @@ namespace PVDEMCS.Services
///
///
///
- Result RunEquipmentRecordTotal(DateTime date);
+ Result RunEquipmentRecordDayTotal(DateTime date);
+
+ ///
+ /// 进行设备状态记录统计
+ ///
+ ///
+ Result RunEquipmentRecordTotal();
#endregion
diff --git a/PVDEMCS/PVDEMCS/Services/Impl/EquipmentRecordService.cs b/PVDEMCS/PVDEMCS/Services/Impl/EquipmentRecordService.cs
index fca796d..db58e0f 100644
--- a/PVDEMCS/PVDEMCS/Services/Impl/EquipmentRecordService.cs
+++ b/PVDEMCS/PVDEMCS/Services/Impl/EquipmentRecordService.cs
@@ -73,9 +73,19 @@ namespace PVDEMCS.Services.Impl
///
///
///
- public Result RunEquipmentRecordTotal(DateTime date)
+ public Result RunEquipmentRecordDayTotal(DateTime date)
{
- var result = this._equipmentRecordRepository.RunEquipmentRecordTotal(date);
+ var result = this._equipmentRecordRepository.RunEquipmentRecordDayTotal(date);
+ return result;
+ }
+
+ ///
+ /// 进行设备状态记录统计
+ ///
+ ///
+ public Result RunEquipmentRecordTotal()
+ {
+ var result = this._equipmentRecordRepository.RunEquipmentRecordTotal();
return result;
}
diff --git a/PVDEMCS/PVDEMCS/Services/Repositories/IEquipmentRecordRepository.cs b/PVDEMCS/PVDEMCS/Services/Repositories/IEquipmentRecordRepository.cs
index b89e8f7..902cef6 100644
--- a/PVDEMCS/PVDEMCS/Services/Repositories/IEquipmentRecordRepository.cs
+++ b/PVDEMCS/PVDEMCS/Services/Repositories/IEquipmentRecordRepository.cs
@@ -47,7 +47,6 @@ namespace PVDEMCS.Services.Repositories
///
/// 设备Id
/// 设备状态,运行:Run,待机:Stop,报警:Alarm
- /// 设备Id
///
Result AddUpdateEquipmentRecord(string equipmentId, string state, DateTime dateTime);
@@ -56,7 +55,13 @@ namespace PVDEMCS.Services.Repositories
///
///
///
- Result RunEquipmentRecordTotal(DateTime date);
+ Result RunEquipmentRecordDayTotal(DateTime date);
+
+ ///
+ /// 进行设备状态记录统计
+ ///
+ ///
+ Result RunEquipmentRecordTotal();
#endregion
diff --git a/PVDEMCS/PVDEMCS/Services/Repositories/Impl/EquipmentRecordRepository.cs b/PVDEMCS/PVDEMCS/Services/Repositories/Impl/EquipmentRecordRepository.cs
index 73ad16f..385dcbd 100644
--- a/PVDEMCS/PVDEMCS/Services/Repositories/Impl/EquipmentRecordRepository.cs
+++ b/PVDEMCS/PVDEMCS/Services/Repositories/Impl/EquipmentRecordRepository.cs
@@ -151,7 +151,7 @@ namespace PVDEMCS.Services.Repositories.Impl
///
///
///
- public Result RunEquipmentRecordTotal(DateTime date)
+ public Result RunEquipmentRecordDayTotal(DateTime date)
{
var begDate = DateTime.Parse(date.ToString("yyyy-MM-dd"));
var endDate = begDate.AddDays(1).AddSeconds(-1);
@@ -308,6 +308,69 @@ namespace PVDEMCS.Services.Repositories.Impl
}
}
+ ///
+ /// 进行设备状态记录统计
+ ///
+ ///
+ public Result RunEquipmentRecordTotal()
+ {
+ using (var context = new EFContext())
+ {
+ var query = context.EquipmentRecordDayTotals.AsQueryable();
+ //获取最后更新时间
+ var list = context.EquipmentRecordTotals.ToList();
+ var maxDate = list.Max(f => f.UpdateAt);
+ //如果有记录
+ if (!maxDate.HasValue)
+ {
+ query = query.Where(f => f.UpdateAt > maxDate);
+ }
+ var values = query.GroupBy(f => f.EquipmentId).Select(f => new EquipmentRecordTotalEntity
+ {
+ EquipmentId = f.Key,
+ FurnaceNum = f.Sum(f=>f.FurnaceNum),
+ TotalRunningTime = f.Sum(f => f.TotalRunningTime),
+ TotalAlarmTime = f.Sum(f => f.TotalAlarmTime),
+ TotalStopTime = f.Sum(f => f.TotalStopTime),
+ }).ToList();
+ if (values.Count > 0)
+ {
+ if (list.IsNullOrEmpty())
+ {
+ foreach (var item in values)
+ {
+ item.Create();
+ }
+ context.EquipmentRecordTotals.AddRange(values);
+ }
+ else
+ {
+ foreach (var item in list)
+ {
+ var value = values.Where(f => f.EquipmentId == item.EquipmentId).FirstOrDefault();
+ if (value.IsNullOrEmpty())
+ {
+ value.Create();
+ context.EquipmentRecordTotals.Add(value);
+ }
+ else
+ {
+ item.FurnaceNum += value.FurnaceNum;
+ item.TotalAlarmTime += value.TotalAlarmTime;
+ item.TotalRunningTime += value.TotalRunningTime;
+ item.TotalStopTime += value.TotalStopTime;
+ item.Update();
+ }
+ }
+ }
+ context.SaveChanges();
+ }
+
+ return new Result();
+
+ }
+ }
+
class TotalRecord
{
public string EquipmentId { get; set; }
@@ -403,7 +466,7 @@ namespace PVDEMCS.Services.Repositories.Impl
/// 设备类型
/// 当前页
/// 页大小
- public Result> GetEquipmentRecordTotalPageList(string equipmentName, string equipmentCode, string equipmentType, int page, int size)
+ public Result> GetEquipmentRecordTotalPageList(string equipmentName, string equipmentCode, string equipmentType, int page, int size)
{
using (var context = new EFContext())
{
@@ -526,9 +589,9 @@ namespace PVDEMCS.Services.Repositories.Impl
}
}
-
-
+
+
#endregion
}
}