电表实时数据

master
tq 6 months ago
parent 1dd2f20e40
commit cde5bf66a0

@ -182,4 +182,27 @@ ORDER BY
List<EmeterEnergyChange> emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql); List<EmeterEnergyChange> emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql);
return emeterEnergies; return emeterEnergies;
} }
/// <summary>
/// 获取交流电表实时数据
/// </summary>
/// <returns></returns>
public async Task<List<EmeterEnergyChange>> GetEnergyMeterRealTime()
{
// 根据code分组,取最新时间的一条数据,数据范围7天
string sql = @"
SELECT t1.*
FROM emeter_energy_change t1
JOIN (
SELECT code, MAX(upload_time) as latest_upload_time
FROM emeter_energy_change
WHERE upload_time >= NOW() - INTERVAL 7 DAY
GROUP BY code
) t2 ON t1.code = t2.code AND t1.upload_time = t2.latest_upload_time
WHERE t1.upload_time >= NOW() - INTERVAL 7 DAY;
";
List<EmeterEnergyChange> emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql);
return emeterEnergies;
}
} }

@ -192,6 +192,28 @@ ORDER BY
m.`code`, m.`Minute`; m.`code`, m.`Minute`;
"; ";
List<EmeterEnergy> emeterEnergies = await this.BaseDal.SqlQueryable(sql);
return emeterEnergies;
}
/// <summary>
/// 获取直流电表实时数据
/// </summary>
/// <returns></returns>
public async Task<List<EmeterEnergy>> GetEnergyMeterRealTime()
{
// 根据code分组,取最新时间的一条数据,数据范围7天
string sql = @"
SELECT t1.*
FROM emeter_energy t1
JOIN (
SELECT code, MAX(upload_time) as latest_upload_time
FROM emeter_energy
WHERE upload_time >= NOW() - INTERVAL 7 DAY
GROUP BY code
) t2 ON t1.code = t2.code AND t1.upload_time = t2.latest_upload_time
WHERE t1.upload_time >= NOW() - INTERVAL 7 DAY;
";
List<EmeterEnergy> emeterEnergies = await this.BaseDal.SqlQueryable(sql); List<EmeterEnergy> emeterEnergies = await this.BaseDal.SqlQueryable(sql);
return emeterEnergies; return emeterEnergies;
} }

@ -153,6 +153,25 @@ namespace WebStarter.Controllers.Ammeter
return Result<EmeterEnergyResp>.Success(resp,"成功"); return Result<EmeterEnergyResp>.Success(resp,"成功");
} }
/// <summary>
/// 获取直流交流电表实时数据
/// </summary>
/// <returns></returns>
[HttpGet("GetEnergyMeterRealTime")]
public async Task<Result<EmeterEnergyResp>> GetEnergyMeterRealTime()
{
// 获取实时直流和交流表数据
List<EmeterEnergy> minutesElectrical = await _emeterEnergyService.GetEnergyMeterRealTime();
List<EmeterEnergyChange> minutesElectricalChange = await _emeterEnergyChangeService.GetEnergyMeterRealTime();
EmeterEnergyResp resp = new EmeterEnergyResp();
ChargeAssignment(minutesElectrical, minutesElectricalChange, resp);
return Result<EmeterEnergyResp>.Success(resp,"成功");
}
private static void ChargeAssignment(List<EmeterEnergy> emeterEnergy, List<EmeterEnergyChange> emeterEnergyChanges, EmeterEnergyResp resp) private static void ChargeAssignment(List<EmeterEnergy> emeterEnergy, List<EmeterEnergyChange> emeterEnergyChanges, EmeterEnergyResp resp)
{ {

Loading…
Cancel
Save