统计优化

master
tq 5 months ago
parent 8a9e76825a
commit 5278c8928f

@ -5,22 +5,57 @@ public class EmeterResp
/// <summary>
/// 充电机电表编码 (充电机Sn)
/// </summary>
public string Code { get; set; }
public string? Code { get; set; }
/// <summary>
/// 电表当前读数
/// </summary>
public float Value { get; set; }
public float? Value { get; set; }
public DateTime UploadTime { get; set; }
public DateTime? UploadTime { get; set; }
private string? _hour;
/// <summary>
/// 小时时间
/// </summary>
public string Hour { get; set; }
public string? Hour
{
get { return _hour; }
set
{
if (!string.IsNullOrEmpty(value))
{
_hour = DateTime.Parse(value).ToString("HH:mm:ss");
}
else
{
_hour = value;
}
}
}
/// <summary>
///分钟时间
/// </summary>
public string Minute { get; set; }
private string? _minute;
public string? Minute
{
get { return _minute; }
set
{
if (!string.IsNullOrEmpty(value))
{
_minute = DateTime.Parse(value).ToString("HH:mm:ss");
}
else
{
_minute = value;
}
}
}
/// <summary>
/// 0直流 1交流
/// </summary>
public int? Type { get; set; }
}

@ -150,7 +150,7 @@ namespace Entity.DbModel.Station
public int? BatteryEnterSeq { get; set; }
/// <summary>
/// Desc:充电状态;0-未知1-正在充电2-无电池3-禁用
/// Desc:充电状态;0-未知1-正在充电2-无电池3-禁用 4-停止充电
/// Default:0
/// Nullable:True
/// </summary>

@ -55,7 +55,13 @@ namespace Entity.DbModel.Station
[SugarColumn(ColumnName="status")]
public int? Status {get;set;}
/// <summary>
/// Desc:0-手动;1-自动充电
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="auto_charge")]
public int? AutoCharge {get;set;}
}
}

@ -79,10 +79,13 @@ ORDER BY
MAX(value) - MIN(value) AS Value
FROM
emeter_energy_change
WHERE
upload_time >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
GROUP BY
code
ORDER BY
code;
";
List<EmeterEnergyChange> emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql);
return emeterEnergies;
@ -162,8 +165,8 @@ ORDER BY
m.`code`,
m.`Minute`,
CASE
WHEN p.`PreviousMaxValue` IS NULL THEN 0
WHEN m.`record_count` > 1 THEN m.`MaxValue` - m.`MinValue`
WHEN p.`PreviousMaxValue` IS NULL THEN 0
ELSE m.`MaxValue` - p.`PreviousMaxValue`
END AS `Value`
FROM
@ -171,7 +174,8 @@ ORDER BY
LEFT JOIN
`previous_minute_max` p ON m.`code` = p.`code` AND m.`Minute` = p.`Minute`
ORDER BY
m.`code`, m.`Minute`;";
m.`code`, m.`Minute`;
";
List<EmeterEnergyChange> emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql);
return emeterEnergies;

@ -86,10 +86,13 @@ ORDER BY
MAX(value) - MIN(value) AS Value
FROM
emeter_energy
WHERE
upload_time >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
GROUP BY
code
ORDER BY
code;
";
List<EmeterEnergy> emeterEnergies = await this.BaseDal.SqlQueryable(sql);
@ -175,8 +178,8 @@ ORDER BY
m.`code`,
m.`Minute`,
CASE
WHEN p.`PreviousMaxValue` IS NULL THEN 0
WHEN m.`record_count` > 1 THEN m.`MaxValue` - m.`MinValue`
WHEN p.`PreviousMaxValue` IS NULL THEN 0
ELSE m.`MaxValue` - p.`PreviousMaxValue`
END AS `Value`
FROM
@ -184,7 +187,8 @@ ORDER BY
LEFT JOIN
`previous_minute_max` p ON m.`code` = p.`code` AND m.`Minute` = p.`Minute`
ORDER BY
m.`code`, m.`Minute`;";
m.`code`, m.`Minute`;
";
List<EmeterEnergy> emeterEnergies = await this.BaseDal.SqlQueryable(sql);
return emeterEnergies;

@ -54,17 +54,22 @@ namespace Service.Station
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> AddEquipInfo(AddEquipInfoReq input)
public async Task<Result<string>> AddEquipInfo(AddEquipInfoReq input)
{
string result = "";
var isExist =
await _equipInfoRepository.QueryByClauseAsync(u => u.Name == input.Name || u.Code == input.Code);
if (isExist != null)
result = "已存在同名或同编码设备信息";
{
return Result<string>.Fail("已存在同名或同编码设备信息");
}
EquipInfo insertAsync = await _equipInfoRepository.InsertAsync(input.Adapt<EquipInfo>());
if (insertAsync.Id > 0)
result = "增加设备信息";
return result;
{
return Result<string>.Success("新增id" + insertAsync.Id);
}
return Result<string>.Fail("新增失败");
}
/// <summary>
@ -72,18 +77,23 @@ namespace Service.Station
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> UpdateEquipInfo(UpdateEquipInfoReq input)
public async Task<Result<string>> UpdateEquipInfo(UpdateEquipInfoReq input)
{
string result = "";
var isExist = await _equipInfoRepository.QueryByClauseAsync(u =>
(u.Name == input.Name || u.Code == input.Code) && u.Id != input.Id);
if (isExist != null)
result = "已存在同名或同编码设备信息";
{
return Result<string>.Fail("已存在同名或同编码设备信息");
}
var config = input.Adapt<EquipInfo>();
int updateResult = await _equipInfoRepository.UpdateAsync(config, true);
if (updateResult > 0)
result = "更新设备信息成功";
return result;
{
return Result<string>.Success("修改成功");
}
return Result<string>.Fail("修改失败");
}
/// <summary>
@ -91,14 +101,21 @@ namespace Service.Station
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> DeleteEquipInfo(DeleteEquipInfoReq input)
public async Task<Result<string>> DeleteEquipInfo(DeleteEquipInfoReq input)
{
string result = "";
var config = await _equipInfoRepository.QueryByClauseAsync(u => u.Id == input.Id);
bool deleteResult = await _equipInfoRepository.DeleteAsync(config);
var equipInfo = await _equipInfoRepository.QueryByClauseAsync(u => u.Id == input.Id);
if (equipInfo==null)
{
return Result<string>.Fail("id不存在");
}
bool deleteResult = await _equipInfoRepository.DeleteAsync(equipInfo);
if (deleteResult)
result = "删除设备信息成功";
return result;
{
return Result<string>.Success("删除设备信息成功");
}
return Result<string>.Fail("删除失败");
}
}
}

@ -45,17 +45,22 @@ public class EquipNetInfoService : BaseServices<EquipNetInfo>
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> AddEquipNetInfo(AddEquipNetInfoReq input)
public async Task<Result<string>> AddEquipNetInfo(AddEquipNetInfoReq input)
{
string result = "";
var isExist =
await _equipNetInfoRepository.QueryByClauseAsync(u => u.Code == input.Code);
if (isExist != null)
result = "已存在同编码设备信息";
{
return Result<string>.Fail("编码已存在");
}
EquipNetInfo insertAsync = await _equipNetInfoRepository.InsertAsync(input.Adapt<EquipNetInfo>());
if (insertAsync.Id > 0)
result = "增加设备信息成功";
return result;
{
return Result<string>.Success("新增id" + insertAsync.Id);
}
return Result<string>.Fail("新增失败");
}
/// <summary>
@ -63,18 +68,23 @@ public class EquipNetInfoService : BaseServices<EquipNetInfo>
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> UpdateEquipNetInfo(UpdateEquipNetInfoReq input)
public async Task<Result<string>> UpdateEquipNetInfo(UpdateEquipNetInfoReq input)
{
string result = "";
var isExist = await _equipNetInfoRepository.QueryByClauseAsync(u =>
(u.Code == input.Code) && u.Id != input.Id);
if (isExist != null)
result = "已存在同编码设备通信信息";
{
return Result<string>.Fail("已存在同名或同编码设备信息");
}
var config = input.Adapt<EquipNetInfo>();
int updateResult = await _equipNetInfoRepository.UpdateAsync(config, true);
if (updateResult > 0)
result = "更新设备通信信息成功";
return result;
{
return Result<string>.Success("修改成功");
}
return Result<string>.Fail("修改失败");
}
/// <summary>
@ -82,13 +92,20 @@ public class EquipNetInfoService : BaseServices<EquipNetInfo>
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> DeleteEquipNetInfo(DeleteEquipNetInfoReq input)
public async Task<Result<string>> DeleteEquipNetInfo(DeleteEquipNetInfoReq input)
{
string result = "";
var config = await _equipNetInfoRepository.QueryByClauseAsync(u => u.Id == input.Id);
bool deleteResult = await _equipNetInfoRepository.DeleteAsync(config);
var equipNetInfo = await _equipNetInfoRepository.QueryByClauseAsync(u => u.Id == input.Id);
if (equipNetInfo==null)
{
return Result<string>.Fail("id不存在");
}
bool deleteResult = await _equipNetInfoRepository.DeleteAsync(equipNetInfo);
if (deleteResult)
result = "成功删除设备通信";
return result;
{
return Result<string>.Success("删除设备信息成功");
}
return Result<string>.Fail("删除失败");
}
}

@ -64,43 +64,51 @@ namespace WebStarter.Controllers.Ammeter
EmeterEnergyResp resp = new EmeterEnergyResp();
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<EmeterResp, EmeterEnergy>().ReverseMap();
cfg.CreateMap<EmeterResp, EmeterEnergyChange>().ReverseMap();
});
IMapper mapper = config.CreateMapper();
List<EmeterResp> emeterEnergyList = mapper.Map<List<EmeterResp>>(sevenDaysElectrical);
List<EmeterResp> sevenEmeterResps = mapper.Map<List<EmeterResp>>(emeterEnergyChanges);
ChargeAssignment(sevenDaysElectrical, emeterEnergyChanges, resp);
resp.emeterEnergy = emeterEnergyList;
resp.emeterEnergyChange = sevenEmeterResps;
return Result<EmeterEnergyResp>.Success(resp,"成功");
}
#region 统计分析/电能表累计值信息
/// <summary>
/// 直流电能表累计值
/// 30天累计能耗
/// </summary>
/// <returns></returns>
[HttpGet("GetAllElectricalData")]
public async Task<Result<List<EmeterEnergy>>> GetAllElectricalData()
public async Task<Result<EmeterEnergyResp>> GetAllElectricalData()
{
// 直流表数据
return Result<List<EmeterEnergy>>.Success(await _emeterEnergyService.GetAllElectricalData(),"成功");
List<EmeterEnergy> emeterEnergy = await _emeterEnergyService.GetAllElectricalData();
List<EmeterEnergyChange> emeterEnergyChanges = await _emeterEnergyChangeService.GetAllElectricalData();
EmeterEnergyResp resp = new EmeterEnergyResp();
ChargeAssignment(emeterEnergy, emeterEnergyChanges, resp);
return Result<EmeterEnergyResp>.Success(resp,"成功");
}
/// <summary>
/// 交流电能表累计值
/// 最近一天电表数据
/// </summary>
/// <returns></returns>
[HttpGet("GetAllEmeterEnergyChange")]
public async Task<Result<List<EmeterEnergyChange>>> GetAllEmeterEnergyChange()
[HttpGet("GetLastDayMeterData")]
public async Task<Result<EmeterEnergyResp>> GetLastDayMeterData()
{
// 交流表数据
return Result<List<EmeterEnergyChange>>.Success(await _emeterEnergyChangeService.GetAllElectricalData(),"成功");
// 获取最近一天直流和交流表数据
List<EmeterEnergy> daysElectrical = await _emeterEnergyService.GetTodayHourlyElectricalData();
List<EmeterEnergyChange> daysElectricalChange = await _emeterEnergyChangeService.GetTodayHourlyElectricalData();
EmeterEnergyResp resp = new EmeterEnergyResp();
ChargeAssignment(daysElectrical, daysElectricalChange, resp);
return Result<EmeterEnergyResp>.Success(resp,"成功");
}
/// <summary>
@ -134,11 +142,20 @@ namespace WebStarter.Controllers.Ammeter
public async Task<Result<EmeterEnergyResp>> GetTodayMinutelyElectricalData()
{
// 获取最近一个小时直流和交流表数据
List<EmeterEnergy> sevenDaysElectrical = await _emeterEnergyService.GetTodayMinutelyElectricalData();
List<EmeterEnergyChange> emeterEnergyChanges = await _emeterEnergyChangeService.GetTodayMinutelyElectricalData();
List<EmeterEnergy> minutesElectrical = await _emeterEnergyService.GetTodayMinutelyElectricalData();
List<EmeterEnergyChange> minutesElectricalChange = await _emeterEnergyChangeService.GetTodayMinutelyElectricalData();
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)
{
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<EmeterResp, EmeterEnergy>().ReverseMap();
@ -146,13 +163,16 @@ namespace WebStarter.Controllers.Ammeter
});
IMapper mapper = config.CreateMapper();
List<EmeterResp> emeterEnergyList = mapper.Map<List<EmeterResp>>(sevenDaysElectrical);
List<EmeterResp> sevenEmeterResps = mapper.Map<List<EmeterResp>>(emeterEnergyChanges);
List<EmeterResp> EnergyList = mapper.Map<List<EmeterResp>>(emeterEnergy);
// 类型赋值直流
EnergyList?.ForEach(emeterResp => emeterResp.Type = 0);
resp.emeterEnergy = emeterEnergyList;
resp.emeterEnergyChange = sevenEmeterResps;
List<EmeterResp> EnergyChangeList = mapper.Map<List<EmeterResp>>(emeterEnergyChanges);
// 类型赋值交流
EnergyChangeList?.ForEach(emeterResp => emeterResp.Type = 1);
return Result<EmeterEnergyResp>.Success(resp,"成功");
resp.emeterEnergy = EnergyList;
resp.emeterEnergyChange = EnergyChangeList;
}
/// <summary>

@ -42,9 +42,9 @@ public class EquipInfoController
/// <param name="input"></param>
[HttpPost]
[Route("add")]
public async Task Add(AddEquipInfoReq input)
public async Task<Result<string>> Add(AddEquipInfoReq input)
{
await _equipInfoService.AddEquipInfo(input);
return await _equipInfoService.AddEquipInfo(input);
}
/// <summary>
@ -53,9 +53,9 @@ public class EquipInfoController
/// <param name="input"></param>
[HttpPost]
[Route("update")]
public async Task Update(UpdateEquipInfoReq input)
public async Task<Result<string>> Update(UpdateEquipInfoReq input)
{
await _equipInfoService.UpdateEquipInfo(input);
return await _equipInfoService.UpdateEquipInfo(input);
}
/// <summary>
@ -64,8 +64,8 @@ public class EquipInfoController
/// <param name="input"></param>
[HttpPost]
[Route("delete")]
public async Task Delete(DeleteEquipInfoReq input)
public async Task<Result<string>> Delete(DeleteEquipInfoReq input)
{
await _equipInfoService.DeleteEquipInfo(input);
return await _equipInfoService.DeleteEquipInfo(input);
}
}

@ -42,9 +42,9 @@ public class EquipNetInfoController
/// <param name="input"></param>
[HttpPost]
[Route("add")]
public async Task Add(AddEquipNetInfoReq input)
public async Task<Result<string>> Add(AddEquipNetInfoReq input)
{
await _equipNetInfoService.AddEquipNetInfo(input);
return await _equipNetInfoService.AddEquipNetInfo(input);
}
/// <summary>
@ -53,9 +53,9 @@ public class EquipNetInfoController
/// <param name="input"></param>
[HttpPost]
[Route("update")]
public async Task Update(UpdateEquipNetInfoReq input)
public async Task<Result<string>> Update(UpdateEquipNetInfoReq input)
{
await _equipNetInfoService.UpdateEquipNetInfo(input);
return await _equipNetInfoService.UpdateEquipNetInfo(input);
}
/// <summary>
@ -64,8 +64,8 @@ public class EquipNetInfoController
/// <param name="input"></param>
[HttpPost]
[Route("delete")]
public async Task Delete(DeleteEquipNetInfoReq input)
public async Task<Result<string>> Delete(DeleteEquipNetInfoReq input)
{
await _equipNetInfoService.DeleteEquipNetInfo(input);
return await _equipNetInfoService.DeleteEquipNetInfo(input);
}
}
Loading…
Cancel
Save