|
|
@ -95,33 +95,66 @@ namespace WebStarter.Controllers.Ammeter
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("GetLastDayMeterData")]
|
|
|
|
[HttpGet("GetLastDayMeterData")]
|
|
|
|
public async Task<Result<EmeterEnergyResp>> GetLastDayMeterData()
|
|
|
|
public async Task<Result<List<EmeterEnergyTimeResp>>> GetLastDayMeterData()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 获取最近一天直流和交流表数据
|
|
|
|
// 获取最近一天直流和交流表数据
|
|
|
|
List<EmeterHourEnergy> daysElectrical = await _emeterHourEnergyService.GetTodayHourlyElectricalData(1);
|
|
|
|
var daysElectricalTask = _emeterHourEnergyService.GetTodayHourlyElectricalData(1);
|
|
|
|
List<EmeterHourEnergy> daysElectricalChange =
|
|
|
|
var daysElectricalChangeTask = _emeterHourEnergyService.GetTodayHourlyElectricalData(2);
|
|
|
|
await _emeterHourEnergyService.GetTodayHourlyElectricalData(2);
|
|
|
|
|
|
|
|
|
|
|
|
await Task.WhenAll(daysElectricalTask, daysElectricalChangeTask);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var daysElectrical = daysElectricalTask.Result;
|
|
|
|
|
|
|
|
var daysElectricalChange = daysElectricalChangeTask.Result;
|
|
|
|
|
|
|
|
|
|
|
|
EmeterEnergyResp resp = new EmeterEnergyResp();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var config = new MapperConfiguration(cfg =>
|
|
|
|
var config = new MapperConfiguration(cfg =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cfg.CreateMap<EmeterResp, EmeterHourEnergy>().ReverseMap();
|
|
|
|
cfg.CreateMap<EmeterResp, EmeterHourEnergy>().ReverseMap();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
var mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
|
|
|
|
List<EmeterResp> EnergyList = mapper.Map<List<EmeterResp>>(daysElectrical);
|
|
|
|
var energyList = mapper.Map<List<EmeterResp>>(daysElectrical);
|
|
|
|
// 类型赋值直流
|
|
|
|
energyList?.ForEach(emeterResp => emeterResp.Type = 0);
|
|
|
|
EnergyList?.ForEach(emeterResp => emeterResp.Type = 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<EmeterResp> EnergyChangeList = mapper.Map<List<EmeterResp>>(daysElectricalChange);
|
|
|
|
var energyChangeList = mapper.Map<List<EmeterResp>>(daysElectricalChange);
|
|
|
|
// 类型赋值交流
|
|
|
|
energyChangeList?.ForEach(emeterResp => emeterResp.Type = 1);
|
|
|
|
EnergyChangeList?.ForEach(emeterResp => emeterResp.Type = 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp.emeterEnergy = EnergyList.OrderBy(i => i.Code).ToList();
|
|
|
|
var respList = new List<EmeterEnergyTimeResp>();
|
|
|
|
resp.emeterEnergyChange = EnergyChangeList.OrderBy(i => i.Code).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var groupedEnergyList = energyList
|
|
|
|
return Result<EmeterEnergyResp>.Success(resp, "成功");
|
|
|
|
.Where(e => !string.IsNullOrEmpty(e.Hour))
|
|
|
|
|
|
|
|
.GroupBy(e => e.Hour)
|
|
|
|
|
|
|
|
.Select(g => new EmeterEnergyTimeResp
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
time = g.Key,
|
|
|
|
|
|
|
|
emeterEnergy = g.ToList()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
respList.AddRange(groupedEnergyList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var groupedEnergyChangeList = energyChangeList
|
|
|
|
|
|
|
|
.Where(e => !string.IsNullOrEmpty(e.Hour))
|
|
|
|
|
|
|
|
.GroupBy(e => e.Hour)
|
|
|
|
|
|
|
|
.Select(g => new EmeterEnergyTimeResp
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
time = g.Key,
|
|
|
|
|
|
|
|
emeterEnergyChange = g.ToList()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var changeItem in groupedEnergyChangeList)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var existingItem = respList.FirstOrDefault(r => r.time == changeItem.time);
|
|
|
|
|
|
|
|
if (existingItem != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
existingItem.emeterEnergyChange = changeItem.emeterEnergyChange;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
respList.Add(changeItem);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result<List<EmeterEnergyTimeResp>>.Success(respList, "成功");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -153,34 +186,68 @@ namespace WebStarter.Controllers.Ammeter
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("GetTodayMinutelyElectricalData")]
|
|
|
|
[HttpGet("GetTodayMinutelyElectricalData")]
|
|
|
|
public async Task<Result<EmeterEnergyResp>> GetTodayMinutelyElectricalData()
|
|
|
|
public async Task<Result<List<EmeterEnergyTimeResp>>> GetTodayMinutelyElectricalData()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 获取最近一个小时直流和交流表数据
|
|
|
|
// 获取最近一个小时直流和交流表数据
|
|
|
|
List<EmeterMinutesEnergy> minutesElectrical = await _emeterMinutesEnergyService.GetTodayMinutelyElectricalData(1);
|
|
|
|
var minutesElectricalTask = _emeterMinutesEnergyService.GetTodayMinutelyElectricalData(1);
|
|
|
|
List<EmeterMinutesEnergy> minutesElectricalChange =
|
|
|
|
var minutesElectricalChangeTask = _emeterMinutesEnergyService.GetTodayMinutelyElectricalData(2);
|
|
|
|
await _emeterMinutesEnergyService.GetTodayMinutelyElectricalData(2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EmeterEnergyResp resp = new EmeterEnergyResp();
|
|
|
|
await Task.WhenAll(minutesElectricalTask, minutesElectricalChangeTask);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var minutesElectrical = minutesElectricalTask.Result;
|
|
|
|
|
|
|
|
var minutesElectricalChange = minutesElectricalChangeTask.Result;
|
|
|
|
|
|
|
|
|
|
|
|
var config = new MapperConfiguration(cfg =>
|
|
|
|
var config = new MapperConfiguration(cfg =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cfg.CreateMap<EmeterResp, EmeterMinutesEnergy>().ReverseMap();
|
|
|
|
cfg.CreateMap<EmeterResp, EmeterMinutesEnergy>().ReverseMap();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
var mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
|
|
|
|
List<EmeterResp> EnergyList = mapper.Map<List<EmeterResp>>(minutesElectrical);
|
|
|
|
var energyList = mapper.Map<List<EmeterResp>>(minutesElectrical);
|
|
|
|
// 类型赋值直流
|
|
|
|
// 类型赋值直流
|
|
|
|
EnergyList?.ForEach(emeterResp => emeterResp.Type = 0);
|
|
|
|
energyList?.ForEach(emeterResp => emeterResp.Type = 0);
|
|
|
|
|
|
|
|
|
|
|
|
List<EmeterResp> EnergyChangeList = mapper.Map<List<EmeterResp>>(minutesElectricalChange);
|
|
|
|
var energyChangeList = mapper.Map<List<EmeterResp>>(minutesElectricalChange);
|
|
|
|
// 类型赋值交流
|
|
|
|
// 类型赋值交流
|
|
|
|
EnergyChangeList?.ForEach(emeterResp => emeterResp.Type = 1);
|
|
|
|
energyChangeList?.ForEach(emeterResp => emeterResp.Type = 1);
|
|
|
|
|
|
|
|
|
|
|
|
resp.emeterEnergy = EnergyList.OrderBy(i => i.Code).ToList();
|
|
|
|
var respList = new List<EmeterEnergyTimeResp>();
|
|
|
|
resp.emeterEnergyChange = EnergyChangeList.OrderBy(i => i.Code).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var groupedEnergyList = energyList
|
|
|
|
|
|
|
|
.Where(e => !string.IsNullOrEmpty(e.Minute))
|
|
|
|
|
|
|
|
.GroupBy(e => e.Minute)
|
|
|
|
|
|
|
|
.Select(g => new EmeterEnergyTimeResp
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
time = g.Key,
|
|
|
|
|
|
|
|
emeterEnergy = g.ToList()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
respList.AddRange(groupedEnergyList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var groupedEnergyChangeList = energyChangeList
|
|
|
|
|
|
|
|
.Where(e => !string.IsNullOrEmpty(e.Minute))
|
|
|
|
|
|
|
|
.GroupBy(e => e.Minute)
|
|
|
|
|
|
|
|
.Select(g => new EmeterEnergyTimeResp
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
time = g.Key,
|
|
|
|
|
|
|
|
emeterEnergyChange = g.ToList()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
return Result<EmeterEnergyResp>.Success(resp, "成功");
|
|
|
|
foreach (var changeItem in groupedEnergyChangeList)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var existingItem = respList.FirstOrDefault(r => r.time == changeItem.time);
|
|
|
|
|
|
|
|
if (existingItem != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
existingItem.emeterEnergyChange = changeItem.emeterEnergyChange;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
respList.Add(changeItem);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result<List<EmeterEnergyTimeResp>>.Success(respList, "成功");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|