|
|
|
@ -1,6 +1,11 @@
|
|
|
|
|
using Masuit.Tools;
|
|
|
|
|
using Masuit.Tools.Models;
|
|
|
|
|
using PVDEMCS.Common.Constant;
|
|
|
|
|
using PVDEMCS.Services;
|
|
|
|
|
using PVDEMCS.Services.Models;
|
|
|
|
|
using PVDEMCS.Services.Repositories.Entities;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Security.Principal;
|
|
|
|
|
|
|
|
|
|
namespace PVDEMCS
|
|
|
|
|
{
|
|
|
|
@ -33,19 +38,134 @@ namespace PVDEMCS
|
|
|
|
|
|
|
|
|
|
public static void UpdateEquipmentRecordDayTotal(IEquipmentRecordService equipmentRecordService)
|
|
|
|
|
{
|
|
|
|
|
var begDate = DateTime.Parse("2023-12-1");
|
|
|
|
|
var endDate = DateTime.Parse("2024-5-7");
|
|
|
|
|
var begDate = DateTime.Parse("2024-4-1");
|
|
|
|
|
var endDate = DateTime.Parse("2024-6-19");
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
equipmentRecordService.RunEquipmentRecordDayTotal(begDate);
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(begDate.ToString() + "统计完成!!");
|
|
|
|
|
|
|
|
|
|
begDate = begDate.AddDays(1);
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(begDate.ToString() + "统计完成!!");
|
|
|
|
|
} while (begDate <= endDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 明细与日汇总数据比较
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void EqualsRecordAndDayTotal()
|
|
|
|
|
{
|
|
|
|
|
var dayList = new List<EquipmentRecordDayTotal>();
|
|
|
|
|
|
|
|
|
|
using (var context = new EFContext())
|
|
|
|
|
{
|
|
|
|
|
var start = DateTime.Parse("2024-05-01");
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
var query = context.EquipmentRecords.Where(f => f.EquipmentId == "1139430645193863168" && f.StartTime >= start && f.StartTime <= start.AddDays(1).AddMinutes(-1)).ToList();
|
|
|
|
|
|
|
|
|
|
//获取状态统计时间
|
|
|
|
|
var total = query.GroupBy(f => new { f.EquipmentId, f.State })
|
|
|
|
|
.Select(f => new
|
|
|
|
|
{
|
|
|
|
|
EquipmentId = f.Key.EquipmentId,
|
|
|
|
|
State = f.Key.State,
|
|
|
|
|
Value = Convert.ToDecimal(f.Sum(ff => (ff.EndTime - ff.StartTime).TotalMinutes)),
|
|
|
|
|
Date = DateTime.Parse(f.Min(ff => ff.StartTime).ToString("yyyy-MM-dd")),
|
|
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
} while (begDate<=endDate);
|
|
|
|
|
if (total.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var day = new EquipmentRecordDayTotal();
|
|
|
|
|
day.TotalDay = start;
|
|
|
|
|
var value = total.Where(f => f.State == EquipmentState.Stop).FirstOrDefault();
|
|
|
|
|
if (value != null)
|
|
|
|
|
{
|
|
|
|
|
day.TotalStopTime = Math.Round(value.Value, 2);
|
|
|
|
|
}
|
|
|
|
|
value = total.Where(f => f.State == EquipmentState.Alarm).FirstOrDefault();
|
|
|
|
|
if (value != null)
|
|
|
|
|
{
|
|
|
|
|
day.TotalAlarmTime = Math.Round(value.Value, 2);
|
|
|
|
|
}
|
|
|
|
|
value = total.Where(f => f.State == EquipmentState.Run).FirstOrDefault();
|
|
|
|
|
if (value != null)
|
|
|
|
|
{
|
|
|
|
|
day.TotalRunningTime = Math.Round(value.Value, 2);
|
|
|
|
|
}
|
|
|
|
|
dayList.Add(day);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
start = start.AddDays(1);
|
|
|
|
|
|
|
|
|
|
} while (start <= DateTime.Parse("2024-05-31"));
|
|
|
|
|
|
|
|
|
|
var days = context.EquipmentRecordDayTotals.Where(f => f.EquipmentId == "1139430645193863168" && f.TotalDay >= DateTime.Parse("2024-05-01") && f.TotalDay <= DateTime.Parse("2024-05-31")).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var item in dayList)
|
|
|
|
|
{
|
|
|
|
|
var val = days.Where(f => f.TotalDay == item.TotalDay).FirstOrDefault();
|
|
|
|
|
if (val != null)
|
|
|
|
|
{
|
|
|
|
|
if (val.TotalAlarmTime != item.TotalAlarmTime ||
|
|
|
|
|
val.TotalStopTime != item.TotalStopTime ||
|
|
|
|
|
val.TotalRunningTime != item.TotalRunningTime)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(item.TotalDay);
|
|
|
|
|
Console.WriteLine($"record:Alarm:{item.TotalAlarmTime},Stop:{item.TotalStopTime},Running:{item.TotalRunningTime}");
|
|
|
|
|
Console.WriteLine($"total: Alarm:{val.TotalAlarmTime},Stop:{val.TotalStopTime},Running:{val.TotalRunningTime}");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(item.TotalDay + " OK!!!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void QueryRecordFaultInfo()
|
|
|
|
|
{
|
|
|
|
|
var beg = DateTime.Parse("2024-6-1");
|
|
|
|
|
var end = beg.AddMonths(1);
|
|
|
|
|
using (var context = new EFContext())
|
|
|
|
|
{
|
|
|
|
|
var equiments = context.EquipmentInfos.Where(f => !f.IsDelete).ToList();
|
|
|
|
|
|
|
|
|
|
var records = context.EquipmentRecords.Where(f => f.StartTime >= beg && f.StartTime <= end).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var equipment in equiments)
|
|
|
|
|
{
|
|
|
|
|
EquipmentRecordEntity er = null;
|
|
|
|
|
var list = records.Where(f => f.EquipmentId == equipment.Id).OrderBy(f => f.CreateAt).ToList();
|
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i == 0)
|
|
|
|
|
{
|
|
|
|
|
er= list[i];
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (er.EndTime != list[i].StartTime)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(er.ToJsonString());
|
|
|
|
|
Console.WriteLine(list[i].StartTime.ToJsonString());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Console.WriteLine(er.EquipmentId + "OK!!!");
|
|
|
|
|
}
|
|
|
|
|
er = list[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|