From 5278c8928f132ec90491e5fd9d49bd4a7c3df071 Mon Sep 17 00:00:00 2001
From: tq <1916474859@qq,com>
Date: Thu, 13 Jun 2024 15:59:16 +0800
Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Entity/Api/Resp/EmeterResp.cs | 45 +++++++++--
Entity/DbModel/Station/BinInfo.cs | 2 +-
Entity/DbModel/Station/EquipInfo.cs | 8 +-
Service/Ammeter/EmeterEnergyChangeService.cs | 10 ++-
Service/Ammeter/EmeterEnergyService.cs | 8 +-
Service/Station/EquipInfoService.cs | 49 ++++++++----
Service/Station/EquipNetInfoService.cs | 49 ++++++++----
.../Controllers/Ammeter/AmmeterController.cs | 76 ++++++++++++-------
WebStarter/Controllers/EquipInfoController.cs | 12 +--
.../Controllers/EquipNetInfoController.cs | 12 +--
10 files changed, 187 insertions(+), 84 deletions(-)
diff --git a/Entity/Api/Resp/EmeterResp.cs b/Entity/Api/Resp/EmeterResp.cs
index ac78f80..5c21f82 100644
--- a/Entity/Api/Resp/EmeterResp.cs
+++ b/Entity/Api/Resp/EmeterResp.cs
@@ -5,22 +5,57 @@ public class EmeterResp
///
/// 充电机电表编码 (充电机Sn)
///
- public string Code { get; set; }
+ public string? Code { get; set; }
///
/// 电表当前读数
///
- public float Value { get; set; }
+ public float? Value { get; set; }
- public DateTime UploadTime { get; set; }
+ public DateTime? UploadTime { get; set; }
+ private string? _hour;
///
/// 小时时间
///
- 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;
+ }
+ }
+ }
///
///分钟时间
///
- 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;
+ }
+ }
+ }
+
+ ///
+ /// 0直流 1交流
+ ///
+ public int? Type { get; set; }
}
\ No newline at end of file
diff --git a/Entity/DbModel/Station/BinInfo.cs b/Entity/DbModel/Station/BinInfo.cs
index 24dfc74..e78c5fb 100644
--- a/Entity/DbModel/Station/BinInfo.cs
+++ b/Entity/DbModel/Station/BinInfo.cs
@@ -150,7 +150,7 @@ namespace Entity.DbModel.Station
public int? BatteryEnterSeq { get; set; }
///
- /// Desc:充电状态;0-未知;1-正在充电;2-无电池;3-禁用
+ /// Desc:充电状态;0-未知;1-正在充电;2-无电池;3-禁用 4-停止充电
/// Default:0
/// Nullable:True
///
diff --git a/Entity/DbModel/Station/EquipInfo.cs b/Entity/DbModel/Station/EquipInfo.cs
index c2261c5..265e51a 100644
--- a/Entity/DbModel/Station/EquipInfo.cs
+++ b/Entity/DbModel/Station/EquipInfo.cs
@@ -55,7 +55,13 @@ namespace Entity.DbModel.Station
[SugarColumn(ColumnName="status")]
public int? Status {get;set;}
-
+ ///
+ /// Desc:0-手动;1-自动充电
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="auto_charge")]
+ public int? AutoCharge {get;set;}
}
}
diff --git a/Service/Ammeter/EmeterEnergyChangeService.cs b/Service/Ammeter/EmeterEnergyChangeService.cs
index 02c2733..5df5a23 100644
--- a/Service/Ammeter/EmeterEnergyChangeService.cs
+++ b/Service/Ammeter/EmeterEnergyChangeService.cs
@@ -76,13 +76,16 @@ ORDER BY
string sql = @"
SELECT
code,
- MAX(value) - MIN(value) AS Value
+ 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 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 emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql);
return emeterEnergies;
diff --git a/Service/Ammeter/EmeterEnergyService.cs b/Service/Ammeter/EmeterEnergyService.cs
index 52e7cb1..31b043b 100644
--- a/Service/Ammeter/EmeterEnergyService.cs
+++ b/Service/Ammeter/EmeterEnergyService.cs
@@ -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 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 emeterEnergies = await this.BaseDal.SqlQueryable(sql);
return emeterEnergies;
diff --git a/Service/Station/EquipInfoService.cs b/Service/Station/EquipInfoService.cs
index 22a40f9..c6ab83f 100644
--- a/Service/Station/EquipInfoService.cs
+++ b/Service/Station/EquipInfoService.cs
@@ -54,17 +54,22 @@ namespace Service.Station
///
///
///
- public async Task AddEquipInfo(AddEquipInfoReq input)
+ public async Task> 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.Fail("已存在同名或同编码设备信息");
+ }
+
EquipInfo insertAsync = await _equipInfoRepository.InsertAsync(input.Adapt());
if (insertAsync.Id > 0)
- result = "增加设备信息";
- return result;
+ {
+ return Result.Success("新增id:" + insertAsync.Id);
+ }
+
+ return Result.Fail("新增失败");
}
///
@@ -72,18 +77,23 @@ namespace Service.Station
///
///
///
- public async Task UpdateEquipInfo(UpdateEquipInfoReq input)
+ public async Task> 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.Fail("已存在同名或同编码设备信息");
+ }
+
var config = input.Adapt();
int updateResult = await _equipInfoRepository.UpdateAsync(config, true);
if (updateResult > 0)
- result = "更新设备信息成功";
- return result;
+ {
+ return Result.Success("修改成功");
+ }
+
+ return Result.Fail("修改失败");
}
///
@@ -91,14 +101,21 @@ namespace Service.Station
///
///
///
- public async Task DeleteEquipInfo(DeleteEquipInfoReq input)
+ public async Task> 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.Fail("id不存在");
+
+ }
+ bool deleteResult = await _equipInfoRepository.DeleteAsync(equipInfo);
if (deleteResult)
- result = "删除设备信息成功";
- return result;
+ {
+ return Result.Success("删除设备信息成功");
+ }
+
+ return Result.Fail("删除失败");
}
}
}
\ No newline at end of file
diff --git a/Service/Station/EquipNetInfoService.cs b/Service/Station/EquipNetInfoService.cs
index 843c0e3..8b471bc 100644
--- a/Service/Station/EquipNetInfoService.cs
+++ b/Service/Station/EquipNetInfoService.cs
@@ -45,17 +45,22 @@ public class EquipNetInfoService : BaseServices
///
///
///
- public async Task AddEquipNetInfo(AddEquipNetInfoReq input)
+ public async Task> AddEquipNetInfo(AddEquipNetInfoReq input)
{
- string result = "";
var isExist =
await _equipNetInfoRepository.QueryByClauseAsync(u => u.Code == input.Code);
if (isExist != null)
- result = "已存在同编码设备信息";
+ {
+ return Result.Fail("编码已存在");
+ }
+
EquipNetInfo insertAsync = await _equipNetInfoRepository.InsertAsync(input.Adapt());
if (insertAsync.Id > 0)
- result = "增加设备信息成功";
- return result;
+ {
+ return Result.Success("新增id:" + insertAsync.Id);
+ }
+
+ return Result.Fail("新增失败");
}
///
@@ -63,18 +68,23 @@ public class EquipNetInfoService : BaseServices
///
///
///
- public async Task UpdateEquipNetInfo(UpdateEquipNetInfoReq input)
+ public async Task> 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.Fail("已存在同名或同编码设备信息");
+ }
+
var config = input.Adapt();
int updateResult = await _equipNetInfoRepository.UpdateAsync(config, true);
if (updateResult > 0)
- result = "更新设备通信信息成功";
- return result;
+ {
+ return Result.Success("修改成功");
+ }
+
+ return Result.Fail("修改失败");
}
///
@@ -82,13 +92,20 @@ public class EquipNetInfoService : BaseServices
///
///
///
- public async Task DeleteEquipNetInfo(DeleteEquipNetInfoReq input)
+ public async Task> 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.Fail("id不存在");
+
+ }
+ bool deleteResult = await _equipNetInfoRepository.DeleteAsync(equipNetInfo);
if (deleteResult)
- result = "成功删除设备通信";
- return result;
+ {
+ return Result.Success("删除设备信息成功");
+ }
+
+ return Result.Fail("删除失败");
}
}
\ No newline at end of file
diff --git a/WebStarter/Controllers/Ammeter/AmmeterController.cs b/WebStarter/Controllers/Ammeter/AmmeterController.cs
index c9cc1ac..9b7ca6a 100644
--- a/WebStarter/Controllers/Ammeter/AmmeterController.cs
+++ b/WebStarter/Controllers/Ammeter/AmmeterController.cs
@@ -63,44 +63,52 @@ namespace WebStarter.Controllers.Ammeter
List emeterEnergyChanges = await _emeterEnergyChangeService.SevenDaysElectrical();
EmeterEnergyResp resp = new EmeterEnergyResp();
+
+
+ ChargeAssignment(sevenDaysElectrical, emeterEnergyChanges, resp);
- var config = new MapperConfiguration(cfg =>
- {
- cfg.CreateMap().ReverseMap();
- cfg.CreateMap().ReverseMap();
- });
- IMapper mapper = config.CreateMapper();
-
- List emeterEnergyList = mapper.Map>(sevenDaysElectrical);
- List sevenEmeterResps = mapper.Map>(emeterEnergyChanges);
-
- resp.emeterEnergy = emeterEnergyList;
- resp.emeterEnergyChange = sevenEmeterResps;
return Result.Success(resp,"成功");
}
#region 统计分析/电能表累计值信息
+
///
- /// 直流电能表累计值
+ /// 30天累计能耗
///
///
[HttpGet("GetAllElectricalData")]
- public async Task>> GetAllElectricalData()
+ public async Task> GetAllElectricalData()
{
- // 直流表数据
- return Result>.Success(await _emeterEnergyService.GetAllElectricalData(),"成功");
+ List emeterEnergy = await _emeterEnergyService.GetAllElectricalData();
+ List emeterEnergyChanges = await _emeterEnergyChangeService.GetAllElectricalData();
+
+ EmeterEnergyResp resp = new EmeterEnergyResp();
+
+ ChargeAssignment(emeterEnergy, emeterEnergyChanges, resp);
+
+ return Result.Success(resp,"成功");
}
+
+
///
- /// 交流电能表累计值
+ /// 最近一天电表数据
///
///
- [HttpGet("GetAllEmeterEnergyChange")]
- public async Task>> GetAllEmeterEnergyChange()
+ [HttpGet("GetLastDayMeterData")]
+ public async Task> GetLastDayMeterData()
{
- // 交流表数据
- return Result>.Success(await _emeterEnergyChangeService.GetAllElectricalData(),"成功");
+ // 获取最近一天直流和交流表数据
+ List daysElectrical = await _emeterEnergyService.GetTodayHourlyElectricalData();
+ List daysElectricalChange = await _emeterEnergyChangeService.GetTodayHourlyElectricalData();
+
+ EmeterEnergyResp resp = new EmeterEnergyResp();
+
+ ChargeAssignment(daysElectrical, daysElectricalChange, resp);
+
+
+ return Result.Success(resp,"成功");
}
///
@@ -134,11 +142,20 @@ namespace WebStarter.Controllers.Ammeter
public async Task> GetTodayMinutelyElectricalData()
{
// 获取最近一个小时直流和交流表数据
- List sevenDaysElectrical = await _emeterEnergyService.GetTodayMinutelyElectricalData();
- List emeterEnergyChanges = await _emeterEnergyChangeService.GetTodayMinutelyElectricalData();
+ List minutesElectrical = await _emeterEnergyService.GetTodayMinutelyElectricalData();
+ List minutesElectricalChange = await _emeterEnergyChangeService.GetTodayMinutelyElectricalData();
EmeterEnergyResp resp = new EmeterEnergyResp();
+ ChargeAssignment(minutesElectrical, minutesElectricalChange, resp);
+
+
+ return Result.Success(resp,"成功");
+ }
+
+
+ private static void ChargeAssignment(List emeterEnergy, List emeterEnergyChanges, EmeterEnergyResp resp)
+ {
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap().ReverseMap();
@@ -146,13 +163,16 @@ namespace WebStarter.Controllers.Ammeter
});
IMapper mapper = config.CreateMapper();
- List emeterEnergyList = mapper.Map>(sevenDaysElectrical);
- List sevenEmeterResps = mapper.Map>(emeterEnergyChanges);
+ List EnergyList = mapper.Map>(emeterEnergy);
+ // 类型赋值直流
+ EnergyList?.ForEach(emeterResp => emeterResp.Type = 0);
- resp.emeterEnergy = emeterEnergyList;
- resp.emeterEnergyChange = sevenEmeterResps;
+ List EnergyChangeList = mapper.Map>(emeterEnergyChanges);
+ // 类型赋值交流
+ EnergyChangeList?.ForEach(emeterResp => emeterResp.Type = 1);
- return Result.Success(resp,"成功");
+ resp.emeterEnergy = EnergyList;
+ resp.emeterEnergyChange = EnergyChangeList;
}
///
diff --git a/WebStarter/Controllers/EquipInfoController.cs b/WebStarter/Controllers/EquipInfoController.cs
index f51df52..0e52921 100644
--- a/WebStarter/Controllers/EquipInfoController.cs
+++ b/WebStarter/Controllers/EquipInfoController.cs
@@ -42,9 +42,9 @@ public class EquipInfoController
///
[HttpPost]
[Route("add")]
- public async Task Add(AddEquipInfoReq input)
+ public async Task> Add(AddEquipInfoReq input)
{
- await _equipInfoService.AddEquipInfo(input);
+ return await _equipInfoService.AddEquipInfo(input);
}
///
@@ -53,9 +53,9 @@ public class EquipInfoController
///
[HttpPost]
[Route("update")]
- public async Task Update(UpdateEquipInfoReq input)
+ public async Task> Update(UpdateEquipInfoReq input)
{
- await _equipInfoService.UpdateEquipInfo(input);
+ return await _equipInfoService.UpdateEquipInfo(input);
}
///
@@ -64,8 +64,8 @@ public class EquipInfoController
///
[HttpPost]
[Route("delete")]
- public async Task Delete(DeleteEquipInfoReq input)
+ public async Task> Delete(DeleteEquipInfoReq input)
{
- await _equipInfoService.DeleteEquipInfo(input);
+ return await _equipInfoService.DeleteEquipInfo(input);
}
}
\ No newline at end of file
diff --git a/WebStarter/Controllers/EquipNetInfoController.cs b/WebStarter/Controllers/EquipNetInfoController.cs
index a73e4fe..60a7226 100644
--- a/WebStarter/Controllers/EquipNetInfoController.cs
+++ b/WebStarter/Controllers/EquipNetInfoController.cs
@@ -42,9 +42,9 @@ public class EquipNetInfoController
///
[HttpPost]
[Route("add")]
- public async Task Add(AddEquipNetInfoReq input)
+ public async Task> Add(AddEquipNetInfoReq input)
{
- await _equipNetInfoService.AddEquipNetInfo(input);
+ return await _equipNetInfoService.AddEquipNetInfo(input);
}
///
@@ -53,9 +53,9 @@ public class EquipNetInfoController
///
[HttpPost]
[Route("update")]
- public async Task Update(UpdateEquipNetInfoReq input)
+ public async Task> Update(UpdateEquipNetInfoReq input)
{
- await _equipNetInfoService.UpdateEquipNetInfo(input);
+ return await _equipNetInfoService.UpdateEquipNetInfo(input);
}
///
@@ -64,8 +64,8 @@ public class EquipNetInfoController
///
[HttpPost]
[Route("delete")]
- public async Task Delete(DeleteEquipNetInfoReq input)
+ public async Task> Delete(DeleteEquipNetInfoReq input)
{
- await _equipNetInfoService.DeleteEquipNetInfo(input);
+ return await _equipNetInfoService.DeleteEquipNetInfo(input);
}
}
\ No newline at end of file