统计优化

master
tq 5 months ago
parent 8a9e76825a
commit 5278c8928f

@ -5,22 +5,57 @@ public class EmeterResp
/// <summary> /// <summary>
/// 充电机电表编码 (充电机Sn) /// 充电机电表编码 (充电机Sn)
/// </summary> /// </summary>
public string Code { get; set; } public string? Code { get; set; }
/// <summary> /// <summary>
/// 电表当前读数 /// 电表当前读数
/// </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>
/// 小时时间 /// 小时时间
/// </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>
///分钟时间 ///分钟时间
/// </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; } public int? BatteryEnterSeq { get; set; }
/// <summary> /// <summary>
/// Desc:充电状态;0-未知1-正在充电2-无电池3-禁用 /// Desc:充电状态;0-未知1-正在充电2-无电池3-禁用 4-停止充电
/// Default:0 /// Default:0
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>

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

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

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

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

@ -45,17 +45,22 @@ public class EquipNetInfoService : BaseServices<EquipNetInfo>
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
public async Task<string> AddEquipNetInfo(AddEquipNetInfoReq input) public async Task<Result<string>> AddEquipNetInfo(AddEquipNetInfoReq input)
{ {
string result = "";
var isExist = var isExist =
await _equipNetInfoRepository.QueryByClauseAsync(u => u.Code == input.Code); await _equipNetInfoRepository.QueryByClauseAsync(u => u.Code == input.Code);
if (isExist != null) if (isExist != null)
result = "已存在同编码设备信息"; {
return Result<string>.Fail("编码已存在");
}
EquipNetInfo insertAsync = await _equipNetInfoRepository.InsertAsync(input.Adapt<EquipNetInfo>()); EquipNetInfo insertAsync = await _equipNetInfoRepository.InsertAsync(input.Adapt<EquipNetInfo>());
if (insertAsync.Id > 0) if (insertAsync.Id > 0)
result = "增加设备信息成功"; {
return result; return Result<string>.Success("新增id" + insertAsync.Id);
}
return Result<string>.Fail("新增失败");
} }
/// <summary> /// <summary>
@ -63,18 +68,23 @@ public class EquipNetInfoService : BaseServices<EquipNetInfo>
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <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 => var isExist = await _equipNetInfoRepository.QueryByClauseAsync(u =>
(u.Code == input.Code) && u.Id != input.Id); (u.Code == input.Code) && u.Id != input.Id);
if (isExist != null) if (isExist != null)
result = "已存在同编码设备通信信息"; {
return Result<string>.Fail("已存在同名或同编码设备信息");
}
var config = input.Adapt<EquipNetInfo>(); var config = input.Adapt<EquipNetInfo>();
int updateResult = await _equipNetInfoRepository.UpdateAsync(config, true); int updateResult = await _equipNetInfoRepository.UpdateAsync(config, true);
if (updateResult > 0) if (updateResult > 0)
result = "更新设备通信信息成功"; {
return result; return Result<string>.Success("修改成功");
}
return Result<string>.Fail("修改失败");
} }
/// <summary> /// <summary>
@ -82,13 +92,20 @@ public class EquipNetInfoService : BaseServices<EquipNetInfo>
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
public async Task<string> DeleteEquipNetInfo(DeleteEquipNetInfoReq input) public async Task<Result<string>> DeleteEquipNetInfo(DeleteEquipNetInfoReq input)
{ {
string result = ""; var equipNetInfo = await _equipNetInfoRepository.QueryByClauseAsync(u => u.Id == input.Id);
var config = await _equipNetInfoRepository.QueryByClauseAsync(u => u.Id == input.Id); if (equipNetInfo==null)
bool deleteResult = await _equipNetInfoRepository.DeleteAsync(config); {
return Result<string>.Fail("id不存在");
}
bool deleteResult = await _equipNetInfoRepository.DeleteAsync(equipNetInfo);
if (deleteResult) 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(); 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); ChargeAssignment(sevenDaysElectrical, emeterEnergyChanges, resp);
List<EmeterResp> sevenEmeterResps = mapper.Map<List<EmeterResp>>(emeterEnergyChanges);
resp.emeterEnergy = emeterEnergyList;
resp.emeterEnergyChange = sevenEmeterResps;
return Result<EmeterEnergyResp>.Success(resp,"成功"); return Result<EmeterEnergyResp>.Success(resp,"成功");
} }
#region 统计分析/电能表累计值信息 #region 统计分析/电能表累计值信息
/// <summary> /// <summary>
/// 直流电能表累计值 /// 30天累计能耗
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpGet("GetAllElectricalData")] [HttpGet("GetAllElectricalData")]
public async Task<Result<List<EmeterEnergy>>> GetAllElectricalData() public async Task<Result<EmeterEnergyResp>> GetAllElectricalData()
{ {
// 直流表数据 List<EmeterEnergy> emeterEnergy = await _emeterEnergyService.GetAllElectricalData();
return Result<List<EmeterEnergy>>.Success(await _emeterEnergyService.GetAllElectricalData(),"成功"); List<EmeterEnergyChange> emeterEnergyChanges = await _emeterEnergyChangeService.GetAllElectricalData();
EmeterEnergyResp resp = new EmeterEnergyResp();
ChargeAssignment(emeterEnergy, emeterEnergyChanges, resp);
return Result<EmeterEnergyResp>.Success(resp,"成功");
} }
/// <summary> /// <summary>
/// 交流电能表累计值 /// 最近一天电表数据
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpGet("GetAllEmeterEnergyChange")] [HttpGet("GetLastDayMeterData")]
public async Task<Result<List<EmeterEnergyChange>>> GetAllEmeterEnergyChange() 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> /// <summary>
@ -134,11 +142,20 @@ namespace WebStarter.Controllers.Ammeter
public async Task<Result<EmeterEnergyResp>> GetTodayMinutelyElectricalData() public async Task<Result<EmeterEnergyResp>> GetTodayMinutelyElectricalData()
{ {
// 获取最近一个小时直流和交流表数据 // 获取最近一个小时直流和交流表数据
List<EmeterEnergy> sevenDaysElectrical = await _emeterEnergyService.GetTodayMinutelyElectricalData(); List<EmeterEnergy> minutesElectrical = await _emeterEnergyService.GetTodayMinutelyElectricalData();
List<EmeterEnergyChange> emeterEnergyChanges = await _emeterEnergyChangeService.GetTodayMinutelyElectricalData(); List<EmeterEnergyChange> minutesElectricalChange = await _emeterEnergyChangeService.GetTodayMinutelyElectricalData();
EmeterEnergyResp resp = new EmeterEnergyResp(); 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 => var config = new MapperConfiguration(cfg =>
{ {
cfg.CreateMap<EmeterResp, EmeterEnergy>().ReverseMap(); cfg.CreateMap<EmeterResp, EmeterEnergy>().ReverseMap();
@ -146,13 +163,16 @@ namespace WebStarter.Controllers.Ammeter
}); });
IMapper mapper = config.CreateMapper(); IMapper mapper = config.CreateMapper();
List<EmeterResp> emeterEnergyList = mapper.Map<List<EmeterResp>>(sevenDaysElectrical); List<EmeterResp> EnergyList = mapper.Map<List<EmeterResp>>(emeterEnergy);
List<EmeterResp> sevenEmeterResps = mapper.Map<List<EmeterResp>>(emeterEnergyChanges); // 类型赋值直流
EnergyList?.ForEach(emeterResp => emeterResp.Type = 0);
resp.emeterEnergy = emeterEnergyList; List<EmeterResp> EnergyChangeList = mapper.Map<List<EmeterResp>>(emeterEnergyChanges);
resp.emeterEnergyChange = sevenEmeterResps; // 类型赋值交流
EnergyChangeList?.ForEach(emeterResp => emeterResp.Type = 1);
return Result<EmeterEnergyResp>.Success(resp,"成功"); resp.emeterEnergy = EnergyList;
resp.emeterEnergyChange = EnergyChangeList;
} }
/// <summary> /// <summary>

@ -42,9 +42,9 @@ public class EquipInfoController
/// <param name="input"></param> /// <param name="input"></param>
[HttpPost] [HttpPost]
[Route("add")] [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> /// <summary>
@ -53,9 +53,9 @@ public class EquipInfoController
/// <param name="input"></param> /// <param name="input"></param>
[HttpPost] [HttpPost]
[Route("update")] [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> /// <summary>
@ -64,8 +64,8 @@ public class EquipInfoController
/// <param name="input"></param> /// <param name="input"></param>
[HttpPost] [HttpPost]
[Route("delete")] [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> /// <param name="input"></param>
[HttpPost] [HttpPost]
[Route("add")] [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> /// <summary>
@ -53,9 +53,9 @@ public class EquipNetInfoController
/// <param name="input"></param> /// <param name="input"></param>
[HttpPost] [HttpPost]
[Route("update")] [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> /// <summary>
@ -64,8 +64,8 @@ public class EquipNetInfoController
/// <param name="input"></param> /// <param name="input"></param>
[HttpPost] [HttpPost]
[Route("delete")] [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