|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Entity.Ammeter;
|
|
|
|
|
using Entity.Api.Resp;
|
|
|
|
|
using HybirdFrameworkCore.Entity;
|
|
|
|
@ -97,25 +98,37 @@ namespace WebStarter.Controllers.Ammeter
|
|
|
|
|
[HttpGet("GetLastDayMeterData")]
|
|
|
|
|
public async Task<Result<List<EmeterEnergyTimeResp>>> GetLastDayMeterData()
|
|
|
|
|
{
|
|
|
|
|
// 获取最近一天直流和交流表数据
|
|
|
|
|
var daysElectricalTask = _emeterHourEnergyService.GetTodayHourlyElectricalData(1);
|
|
|
|
|
var daysElectricalChangeTask = _emeterHourEnergyService.GetTodayHourlyElectricalData(2);
|
|
|
|
|
DateTime todayZero = DateTime.Today;
|
|
|
|
|
|
|
|
|
|
await Task.WhenAll(daysElectricalTask, daysElectricalChangeTask);
|
|
|
|
|
|
|
|
|
|
var daysElectrical = daysElectricalTask.Result;
|
|
|
|
|
var daysElectricalChange = daysElectricalChangeTask.Result;
|
|
|
|
|
List<EmeterHourEnergy> list = await _emeterHourEnergyService.QueryListByClauseAsync(i => DateTime.Parse(i.Time)>=todayZero);
|
|
|
|
|
|
|
|
|
|
List<EmeterHourEnergy> daysElectrical = list.Where(i => i.Type == 1).ToList();
|
|
|
|
|
|
|
|
|
|
List<EmeterHourEnergy> daysElectricalChange = list.Where(i => i.Type == 2).ToList();
|
|
|
|
|
|
|
|
|
|
var config = new MapperConfiguration(cfg =>
|
|
|
|
|
List<EmeterResp> energyList = new List<EmeterResp>();
|
|
|
|
|
|
|
|
|
|
foreach (var energy in daysElectrical)
|
|
|
|
|
{
|
|
|
|
|
cfg.CreateMap<EmeterResp, EmeterHourEnergy>().ReverseMap();
|
|
|
|
|
});
|
|
|
|
|
var mapper = config.CreateMapper();
|
|
|
|
|
EmeterResp resp = new EmeterResp();
|
|
|
|
|
resp.Code = energy.Code;
|
|
|
|
|
resp.Value = energy.Value;
|
|
|
|
|
resp.Hour = energy.Time;
|
|
|
|
|
energyList.Add(resp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var energyList = mapper.Map<List<EmeterResp>>(daysElectrical);
|
|
|
|
|
energyList?.ForEach(emeterResp => emeterResp.Type = 0);
|
|
|
|
|
|
|
|
|
|
var energyChangeList = mapper.Map<List<EmeterResp>>(daysElectricalChange);
|
|
|
|
|
|
|
|
|
|
List<EmeterResp> energyChangeList = new List<EmeterResp>();
|
|
|
|
|
|
|
|
|
|
foreach (var energy in daysElectricalChange)
|
|
|
|
|
{
|
|
|
|
|
EmeterResp resp = new EmeterResp();
|
|
|
|
|
resp.Code = energy.Code;
|
|
|
|
|
resp.Value = energy.Value;
|
|
|
|
|
resp.Hour = energy.Time;
|
|
|
|
|
energyChangeList.Add(resp);
|
|
|
|
|
}
|
|
|
|
|
energyChangeList?.ForEach(emeterResp => emeterResp.Type = 1);
|
|
|
|
|
|
|
|
|
|
var respList = new List<EmeterEnergyTimeResp>();
|
|
|
|
@ -157,30 +170,6 @@ namespace WebStarter.Controllers.Ammeter
|
|
|
|
|
return Result<List<EmeterEnergyTimeResp>>.Success(respList, "成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 直流电能表小时统计
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("GetTodayHourlyEnergy")]
|
|
|
|
|
public async Task<Result<List<EmeterHourEnergy>>> GetTodayHourlyElectricalData()
|
|
|
|
|
{
|
|
|
|
|
// 直流表数据
|
|
|
|
|
return Result<List<EmeterHourEnergy>>.Success(await _emeterHourEnergyService.GetTodayHourlyElectricalData(1), "成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 交流电能表小时统计
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("GetTodayHourlyEnergyChange")]
|
|
|
|
|
public async Task<Result<List<EmeterHourEnergy>>> GetTodayHourlyElectricalChangeData()
|
|
|
|
|
{
|
|
|
|
|
// 交流表数据
|
|
|
|
|
return Result<List<EmeterHourEnergy>>.Success(
|
|
|
|
|
await _emeterHourEnergyService.GetTodayHourlyElectricalData(2), "成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 最近一小时电表数据
|
|
|
|
|
/// </summary>
|
|
|
|
@ -188,29 +177,42 @@ namespace WebStarter.Controllers.Ammeter
|
|
|
|
|
[HttpGet("GetTodayMinutelyElectricalData")]
|
|
|
|
|
public async Task<Result<List<EmeterEnergyTimeResp>>> GetTodayMinutelyElectricalData()
|
|
|
|
|
{
|
|
|
|
|
// 获取最近一个小时直流和交流表数据
|
|
|
|
|
var minutesElectricalTask = _emeterMinutesEnergyService.GetTodayMinutelyElectricalData(1);
|
|
|
|
|
var minutesElectricalChangeTask = _emeterMinutesEnergyService.GetTodayMinutelyElectricalData(2);
|
|
|
|
|
|
|
|
|
|
await Task.WhenAll(minutesElectricalTask, minutesElectricalChangeTask);
|
|
|
|
|
|
|
|
|
|
var minutesElectrical = minutesElectricalTask.Result;
|
|
|
|
|
var minutesElectricalChange = minutesElectricalChangeTask.Result;
|
|
|
|
|
|
|
|
|
|
DateTime now = DateTime.Now;
|
|
|
|
|
DateTime time = new DateTime(now.Year, now.Month, now.Day, now.Hour, 0, 0);
|
|
|
|
|
|
|
|
|
|
List<EmeterMinutesEnergy> list = await _emeterMinutesEnergyService.QueryListByClauseAsync(i => DateTime.Parse(i.Time)>=time);
|
|
|
|
|
|
|
|
|
|
List<EmeterMinutesEnergy> daysElectrical = list.Where(i => i.Type == 1).ToList();
|
|
|
|
|
|
|
|
|
|
List<EmeterMinutesEnergy> daysElectricalChange = list.Where(i => i.Type == 2).ToList();
|
|
|
|
|
|
|
|
|
|
var config = new MapperConfiguration(cfg =>
|
|
|
|
|
List<EmeterResp> energyList = new List<EmeterResp>();
|
|
|
|
|
|
|
|
|
|
foreach (var energy in daysElectrical)
|
|
|
|
|
{
|
|
|
|
|
cfg.CreateMap<EmeterResp, EmeterMinutesEnergy>().ReverseMap();
|
|
|
|
|
});
|
|
|
|
|
var mapper = config.CreateMapper();
|
|
|
|
|
EmeterResp resp = new EmeterResp();
|
|
|
|
|
resp.Code = energy.Code;
|
|
|
|
|
resp.Value = energy.Value;
|
|
|
|
|
resp.Minute = energy.Time;
|
|
|
|
|
energyList.Add(resp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var energyList = mapper.Map<List<EmeterResp>>(minutesElectrical);
|
|
|
|
|
// 类型赋值直流
|
|
|
|
|
energyList?.ForEach(emeterResp => emeterResp.Type = 0);
|
|
|
|
|
|
|
|
|
|
var energyChangeList = mapper.Map<List<EmeterResp>>(minutesElectricalChange);
|
|
|
|
|
// 类型赋值交流
|
|
|
|
|
|
|
|
|
|
List<EmeterResp> energyChangeList = new List<EmeterResp>();
|
|
|
|
|
|
|
|
|
|
foreach (var energy in daysElectricalChange)
|
|
|
|
|
{
|
|
|
|
|
EmeterResp resp = new EmeterResp();
|
|
|
|
|
resp.Code = energy.Code;
|
|
|
|
|
resp.Value = energy.Value;
|
|
|
|
|
resp.Minute = energy.Time;
|
|
|
|
|
energyChangeList.Add(resp);
|
|
|
|
|
}
|
|
|
|
|
energyChangeList?.ForEach(emeterResp => emeterResp.Type = 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var respList = new List<EmeterEnergyTimeResp>();
|
|
|
|
|
|
|
|
|
|
var groupedEnergyList = energyList
|
|
|
|
@ -257,31 +259,64 @@ namespace WebStarter.Controllers.Ammeter
|
|
|
|
|
[HttpGet("GetEnergyMeterRealTime")]
|
|
|
|
|
public async Task<Result<EmeterEnergyResp>> GetEnergyMeterRealTime(string endTime)
|
|
|
|
|
{
|
|
|
|
|
// 不传值时查实时
|
|
|
|
|
if (!DateTime.TryParse(endTime, out DateTime parsedEndTime))
|
|
|
|
|
EmeterEnergyResp resp = new EmeterEnergyResp();
|
|
|
|
|
DateTime parsedEndTime;
|
|
|
|
|
|
|
|
|
|
if (!DateTime.TryParse(endTime, out parsedEndTime))
|
|
|
|
|
{
|
|
|
|
|
parsedEndTime = DateTime.Now;
|
|
|
|
|
endTime = parsedEndTime.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
await QueryRealTime(resp,endTime);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
endTime = parsedEndTime.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
await QueryParameterTime(resp, endTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
endTime = parsedEndTime.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
return Result<EmeterEnergyResp>.Success(resp, "成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取实时直流和交流表数据
|
|
|
|
|
List<EmeterHourEnergy> minutesElectrical = await _emeterHourEnergyService.GetEnergyMeterRealTime(endTime, 1);
|
|
|
|
|
List<EmeterHourEnergy> minutesElectricalChange = await _emeterHourEnergyService.GetEnergyMeterRealTime(endTime, 2);
|
|
|
|
|
private async Task QueryRealTime(EmeterEnergyResp resp,string time)
|
|
|
|
|
{
|
|
|
|
|
List<EmeterEnergy> sevenDaysElectrical = await _emeterEnergyService.GetEnergyMeterRealTime(time);
|
|
|
|
|
List<EmeterEnergyChange> emeterEnergyChanges = await _emeterEnergyChangeService.GetEnergyMeterRealTime(time);
|
|
|
|
|
|
|
|
|
|
EmeterEnergyResp resp = new EmeterEnergyResp
|
|
|
|
|
var config = new MapperConfiguration(cfg =>
|
|
|
|
|
{
|
|
|
|
|
emeterEnergy = TransformEnergyData(minutesElectrical, 0),
|
|
|
|
|
emeterEnergyChange = TransformEnergyData(minutesElectricalChange, 1)
|
|
|
|
|
};
|
|
|
|
|
cfg.CreateMap<EmeterResp, EmeterEnergy>().ReverseMap();
|
|
|
|
|
cfg.CreateMap<EmeterResp, EmeterEnergyChange>().ReverseMap();
|
|
|
|
|
});
|
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
|
|
return Result<EmeterEnergyResp>.Success(resp, "成功");
|
|
|
|
|
resp.emeterEnergy = MapEnergyData(mapper.Map<List<EmeterResp>>(sevenDaysElectrical), 0);
|
|
|
|
|
resp.emeterEnergyChange = MapEnergyData(mapper.Map<List<EmeterResp>>(emeterEnergyChanges), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task QueryParameterTime(EmeterEnergyResp resp, string endTime)
|
|
|
|
|
{
|
|
|
|
|
List<EmeterHourEnergy> minutesElectrical =
|
|
|
|
|
await _emeterHourEnergyService.GetEnergyMeterRealTime(endTime, 1);
|
|
|
|
|
List<EmeterHourEnergy> minutesElectricalChange =
|
|
|
|
|
await _emeterHourEnergyService.GetEnergyMeterRealTime(endTime, 2);
|
|
|
|
|
|
|
|
|
|
resp.emeterEnergy = TransformEnergyData(minutesElectrical, 0);
|
|
|
|
|
resp.emeterEnergyChange = TransformEnergyData(minutesElectricalChange, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<EmeterResp> MapEnergyData(List<EmeterResp> energyData, int type)
|
|
|
|
|
{
|
|
|
|
|
energyData?.ForEach(emeterResp => emeterResp.Type = type);
|
|
|
|
|
return energyData?.OrderBy(e => e.Code).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<EmeterResp> TransformEnergyData(List<EmeterHourEnergy> energyData, int type)
|
|
|
|
|
{
|
|
|
|
|
return energyData.Select(hourEnergy =>
|
|
|
|
|
return energyData.Select(hourEnergy =>
|
|
|
|
|
{
|
|
|
|
|
DateTime? uploadTime = DateTime.TryParse(hourEnergy.Time, out DateTime parsedTime) ? parsedTime : (DateTime?)null;
|
|
|
|
|
DateTime? uploadTime = DateTime.TryParse(hourEnergy.Time, out DateTime parsedTime)
|
|
|
|
|
? parsedTime
|
|
|
|
|
: (DateTime?)null;
|
|
|
|
|
|
|
|
|
|
return new EmeterResp
|
|
|
|
|
{
|
|
|
|
@ -292,6 +327,7 @@ namespace WebStarter.Controllers.Ammeter
|
|
|
|
|
};
|
|
|
|
|
}).OrderBy(e => e.Code).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void ElectricEnergyDay(List<EmeterDayEnergy> daysElectrical, List<EmeterDayEnergy> emeterEnergyChanges, EmeterEnergyResp resp)
|
|
|
|
|
{
|
|
|
|
|