123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- using ProductionLineMonitor.Core.Models;
- using ProductionLineMonitor.Web.Services;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ProductionLineMonitor.Application.Services.EnergyConsumptionService.Dtos
- {
- public class MachineElectricEnergyDto : Machine
- {
- public int Floor { get; set; }
- public int Line { get; set; }
- public List<ElectricEnergyMeter> Meters { get; set; }
- = new List<ElectricEnergyMeter>();
- }
- public class MachineElectricEnergyMeterCheckDto : MachineElectricEnergyDto
- {
- public enum MachineMeterState
- {
- Normal,
- TimeOut,
- ValueDoesNotChange,
- MesApiGetNull,
- OValue
- }
- public int MachineState { get; set; }
-
- public MachineMeterState State { get; private set; } = MachineMeterState.Normal;
- public string Message { get; private set; } = string.Empty;
- public int TimeOutValue { get; private set; } = 10;
- public int Index { get; private set; } = 0;
- public int LastIndex { get; private set; } = 0;
- public List<ElectricEnergyMeterDataDto>[] ElectricEnergyMeterDtos { get; private set; }
- = new List<ElectricEnergyMeterDataDto>[10];
- public void GetElectricEnergyMeterDtos()
- {
- if (Index >= 10)
- Index = 0;
- var dtos = MesApiService.GetElectricEnergyMeters(Topic).ToList();
- ElectricEnergyMeterDtos[Index] = dtos;
- Index++;
- }
- public void Check()
- {
- DateTime time = DateTime.Now;
- if (Meters == null || Meters.Count() == 0)
- {
- State = MachineMeterState.MesApiGetNull;
- Message = $"待导入!";
- return;
- }
- if (ElectricEnergyMeterDtos[Index - 1] == null || ElectricEnergyMeterDtos[Index - 1].Count() == 0)
- {
- State = MachineMeterState.MesApiGetNull;
- Message = $"MesApi 未获取到数据!";
- return;
- }
- foreach (var electricEnergyMeterDto in ElectricEnergyMeterDtos[Index - 1])
- {
- var meter = Meters.FirstOrDefault(x => x.SerialNumber == electricEnergyMeterDto.SerialNumber);
- if (meter == null)
- continue;
- if (!meter.Enable)
- continue;
- double min = (time - electricEnergyMeterDto.DataTime).TotalMinutes;
- if (min > TimeOutValue)
- {
- State = MachineMeterState.TimeOut;
- Message = $"编号 {electricEnergyMeterDto.SerialNumber} 超过 {(int)min} 分钟未推送!";
- return;
- }
- if (electricEnergyMeterDto.ElectricEnergy == 0)
- {
- State = MachineMeterState.OValue;
- Message = $"编号 {electricEnergyMeterDto.SerialNumber} 能耗为 0!";
- return;
- }
- if (Index - 2 < 0)
- LastIndex = 9;
- else
- LastIndex = Index - 2;
- var last = ElectricEnergyMeterDtos[LastIndex];
- if (last == null)
- continue;
- var lastMeter = last.FirstOrDefault(x => x.SerialNumber == meter.SerialNumber);
- if (lastMeter == null)
- continue;
- if (electricEnergyMeterDto.ElectricEnergy < lastMeter.ElectricEnergy)
- {
- State = MachineMeterState.ValueDoesNotChange;
- Message = $"编号 {electricEnergyMeterDto.SerialNumber} 能耗在负增长!";
- return;
- }
- if (Index == 10)
- LastIndex = 0;
- else
- LastIndex = Index;
- last = ElectricEnergyMeterDtos[LastIndex];
- if (last == null)
- continue;
- lastMeter = last.FirstOrDefault(x => x.SerialNumber == meter.SerialNumber);
- if (lastMeter == null)
- continue;
- if (electricEnergyMeterDto.ElectricEnergy == lastMeter.ElectricEnergy
- && electricEnergyMeterDto.Uab == lastMeter.Uab
- && electricEnergyMeterDto.Ubc == lastMeter.Ubc
- && electricEnergyMeterDto.Uca == lastMeter.Uca
- && electricEnergyMeterDto.Ua == lastMeter.Ua
- && electricEnergyMeterDto.Ub == lastMeter.Ub
- && electricEnergyMeterDto.Uc == lastMeter.Uc
- && electricEnergyMeterDto.Ia == lastMeter.Ia
- && electricEnergyMeterDto.Ib == lastMeter.Ib
- && electricEnergyMeterDto.Ic == lastMeter.Ic)
- {
- double min1 = (electricEnergyMeterDto.DataTime - lastMeter.DataTime).TotalMinutes;
- State = MachineMeterState.ValueDoesNotChange;
- Message = $"编号 {electricEnergyMeterDto.SerialNumber} {(int)min1}分钟 值无变化!";
- return;
- }
- }
- State = MachineMeterState.Normal;
- Message = "正常";
- }
- }
- }
|