充电模式字段增加

zw
tq 6 months ago
parent 7da39b7de7
commit e71014e383

@ -87,5 +87,12 @@ namespace Entity.DbModel.Station
[SugarColumn(ColumnName="updated_time")]
public DateTime? UpdatedTime {get;set;}
/// <summary>
/// Desc:0-手动;1-自动充电
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="auto_charge")]
public int? AutoCharge {get;set;}
}
}

@ -0,0 +1,37 @@
using Entity.DbModel.Station;
namespace Entity.Dto.Req;
public class EquipInfoReq : BaseIdReq
{
}
public class PageEquipInfoReq : BasePageReq
{
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; } = "";
/// <summary>
/// 设备编码;0-充电机1-电表
/// </summary>
public string Code { get; set; } = "";
/// <summary>
/// 设备状态
/// </summary>
public int? Status { get; set; }
}
public class AddEquipInfoReq : EquipInfo
{
}
public class UpdateEquipInfoReq : AddEquipInfoReq
{
}
public class DeleteEquipInfoReq : BaseIdReq
{
}

@ -160,31 +160,103 @@ public partial class BinInfoResp
/// </summary>
public DateTime? UpdatedTime { get; set; }
/// <summary>
/// 功率
/// Desc:功率
/// Default:
/// Nullable:9.9
/// </summary>
public float power { get; set; }
/// <summary>
/// 缓存仓标记 0:不是 1:是
/// Desc:缓存仓标记 0:不是 1:是
/// Default:
/// Nullable:0
/// </summary>
public int CacheBinFlag { get; set; }
/// <summary>
/// 换电禁用标志 0:不可换电 1:可以换电
/// Desc:换电禁用标志 0:不可换电 1:可以换电
/// Default:
/// Nullable:0
/// </summary>
public int CanSwapFlag { get; set; }
/// <summary>
/// 充电禁用标志 0:不可充电 1:可以充电
/// Desc:充电禁用标志 0:不可充电 1:可以充电
/// Default:
/// Nullable:0
/// </summary>
public int CanChargeFlag { get; set; }
/// <summary>
/// 充电机是否连接
/// Desc:充电机是否连接
/// Default:
/// Nullable:0
/// </summary>
public bool ChargeConnectFlag { get; set; }
/// <summary>
/// Desc:本次充电时间
/// Default:
/// Nullable:0
/// </summary>
public ushort ChargingTime { get; set; }
/// <summary>
/// Desc:估算剩余充电时间
/// Default:
/// Nullable:0
/// </summary>
public ushort EstimatedRemainingTime { get; set; }
/// <summary>
/// Desc:单次充电电量
/// Default:
/// Nullable:0
/// </summary>
public float OnceElectricCharge { get; set; }
/// <summary>
/// BMS 需求电压
/// Default:
/// Nullable:0
/// </summary>
public float BmsNeedVoltage { get; set; }
/// <summary>
/// BMS 需求电流
/// Default:
/// Nullable:0
/// </summary>
public float BmsNeedCurrent { get; set; }
/// <summary>
/// 电池包总电流,充电为负值,放电为正
/// Default:
/// Nullable:0
/// </summary>
public float TotalCurrent { get; set; }
/// <summary>
/// 电芯温度最大值
/// Default:
/// Nullable:0
/// </summary>
public Int16 CellTemperatureMax { get; set; }
/// <summary>
/// 电芯温度最小值
/// Default:
/// Nullable:0
/// </summary>
public Int16 CellTemperatureMin { get; set; }
/// <summary>
/// 充电开始时间
/// Default:
/// Nullable:
/// </summary>
public DateTime? ChargingStartTime { get; set; }
/// <summary>
/// 充电结束时间
/// Default:
/// Nullable:
/// </summary>
public DateTime? ChargingStopTime { get; set; }
}

@ -1,4 +1,6 @@
using System.Linq.Expressions;
using Entity.DbModel.Station;
using Entity.Dto.Req;
using HybirdFrameworkCore.Autofac.Attribute;
using SqlSugar;
@ -6,7 +8,28 @@ namespace Repository.Station;
[Scope("SingleInstance")]
public class EquipInfoRepository: BaseRepository<EquipInfo>
{
private ISqlSugarClient DbBaseClient;
public EquipInfoRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
DbBaseClient = sqlSugar;
}
public async Task<List<EquipInfo>> EquipInfoQueryPageAsync(
bool isWhere1, Expression<Func<EquipInfo, bool>> expression1,
bool isWhere2, Expression<Func<EquipInfo, bool>> expression2,
bool isWhere3, Expression<Func<EquipInfo, bool>> expression3,
int pageNumber, int pageSize, RefAsync<int> totalNumber,
PageEquipInfoReq input, bool blUseNoLock = false)
{
var page = await DbBaseClient
.Queryable<EquipInfo>()
.WhereIF(isWhere1, expression1)
.WhereIF(isWhere2, expression2)
.WhereIF(isWhere3, expression3)
.OrderBuilder(input)
.WithNoLockOrNot(blUseNoLock)
.ToPageListAsync(pageNumber, pageSize, totalNumber);
return page;
}
}

@ -0,0 +1,68 @@
using AutoMapper;
using Entity.DbModel.Station;
using Entity.Dto.Resp;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using Repository.Station;
using Service.Charger.Client;
namespace Service.Station;
[Scope("SingleInstance")]
public class BinInfoService : BaseServices<BinInfo>
{
private readonly BinInfoRepository _binInfoRepository;
public BinInfoService(BinInfoRepository binInfoRepository)
{
_binInfoRepository = binInfoRepository;
}
/// <summary>
/// 获取仓位数据
/// </summary>
/// <returns>仓位数据列表</returns>
public List<BinInfoResp> GetChargMonitorChargBinData()
{
List<BinInfo> binInfos = _binInfoRepository.Query();
var configuration = new MapperConfiguration(cfg => cfg.CreateMap<BinInfo, BinInfoResp>());
var mapper = configuration.CreateMapper();
// 转换为 BinInfoResp 列表
List<BinInfoResp> binInfoList = mapper.Map<List<BinInfoResp>>(binInfos);
// 功率赋值
foreach (var binInfoResp in binInfoList)
{
ChargerClient? chargerClient = ClientMgr.GetBySn(binInfoResp.ChargerNo);
if (chargerClient != null)
{
binInfoResp.power = chargerClient.RealTimeChargePower;
binInfoResp.ChargeConnectFlag = chargerClient.Connected;
binInfoResp.ChargingTime = chargerClient.UploadTelemetryData.ChargingTime;
binInfoResp.EstimatedRemainingTime = chargerClient.UploadTelemetryData.EstimatedRemainingTime;
if (chargerClient.BatteryPackTotalElectricity != null)
binInfoResp.OnceElectricCharge = chargerClient.BatteryPackTotalElectricity.OnceElectricCharge;
binInfoResp.BmsNeedVoltage = chargerClient.UploadTelemetryData.BmsNeedVoltage;
binInfoResp.BmsNeedCurrent = chargerClient.UploadTelemetryData.BmsNeedCurrent;
if (chargerClient.BatteryPackData != null)
binInfoResp.TotalCurrent = chargerClient.BatteryPackData.TotalCurrent;
if (chargerClient.BatteryPackDataVoltage != null)
binInfoResp.CellTemperatureMax = chargerClient.BatteryPackDataVoltage.CellTemperatureMax;
if (chargerClient.BatteryPackDataVoltage != null)
binInfoResp.CellTemperatureMin = chargerClient.BatteryPackDataVoltage.CellTemperatureMin;
binInfoResp.ChargingStartTime = chargerClient.ChargingStartTime;
binInfoResp.ChargingStopTime = chargerClient.ChargingStopTime;
}
}
return binInfoList;
}
/// <summary>
/// 禁用仓位
/// </summary>
/// <param name="id"></param>
/// <returns>修改结果</returns>
public bool UpdateStatus(int id)
{
return _binInfoRepository.UpdateStatus(id);
}
}

@ -0,0 +1,79 @@
using System.ComponentModel;
using Entity.Base;
using Entity.DbModel.Station;
using Entity.Dto.Req;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using Mapster;
using Repository.Station;
using SqlSugar;
namespace Service.Station;
[Scope("SingleInstance")]
public class EquipInfoService : BaseServices<EquipInfo>
{
private readonly EquipInfoRepository _equipInfoRepository;
public EquipInfoService(EquipInfoRepository equipInfoRepository)
{
_equipInfoRepository = equipInfoRepository;
}
/// <summary>
/// 获取分页列表 🔖
/// </summary>
/// <param name="input">查询参数</param>
/// <returns>分页列表</returns>
public async Task<SqlSugarPagedList<EquipInfo>> Page(PageEquipInfoReq input)
{
RefAsync<int> total = 0;
var items = await _equipInfoRepository.EquipInfoQueryPageAsync(
!string.IsNullOrEmpty(input.Name), u => u.Name.Contains(input.Name),
!string.IsNullOrEmpty(input.Code), u => u.Code.Contains(input.Code),
input.Status != null, (u => input.Status != null && u.Status.Equals(input.Status.Value)),
input.Page, input.PageSize, total, input);
return SqlSugarPagedExtensions.CreateSqlSugarPagedList(items, total, input.Page, input.PageSize);
}
/// <summary>
/// 修改充电模式配置 🔖
/// </summary>
/// <param name="input">修改参数</param>
/// <returns>修改结果</returns>
[DisplayName("更新充电模式配置")]
public async Task<Result<object>> UpdateEquipInfoReq(UpdateEquipInfoReq input)
{
var isExist = await _equipInfoRepository.QueryByClauseAsync
(u => (u.Name == input.Name || u.Code == input.Code) && u.Id != input.Id);
if (isExist != null)
{
return Result<object>.Fail(false, "已存在同名或同编码参数配置");
}
var config = input.Adapt<EquipInfo>();
int affectedRows = await _equipInfoRepository.UpdateAsync(config, true);
// 判断是否更新成功
if (affectedRows > 0)
{
return Result<object>.Success(true, "修改成功");
}
return Result<object>.Fail(false, "修改失败");
}
/// <summary>
/// 删除充电模式配置 🔖
/// </summary>
/// <param name="input">删除参数</param>
/// <returns>删除结果</returns>
[DisplayName("删除充电模式配置")]
public async Task<Result<object>> DeleteEquipInfoReq(DeleteEquipInfoReq input)
{
var config = await _equipInfoRepository.QueryByClauseAsync(u => u.Id == input.Id);
bool deleteResult = await _equipInfoRepository.DeleteAsync(config);
if (deleteResult)
return Result<object>.Success(true, "修改成功");
return Result<object>.Fail(true, "删除成功");
}
}

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc;
using Repository.Station;
using Service.Charger;
using Service.Charger.Client;
using Service.Station;
namespace WebStarter.Controllers;
@ -19,12 +20,12 @@ namespace WebStarter.Controllers;
public class ChargeController : ControllerBase
{
private ChargerService _chargerService;
private BinInfoRepository _binInfoRepository;
private BinInfoService _binInfoService;
public ChargeController(ChargerService chargerService, BinInfoRepository binInfoRepository)
public ChargeController(ChargerService chargerService, BinInfoService binInfoService)
{
_chargerService = chargerService;
_binInfoRepository = binInfoRepository;
_binInfoService = binInfoService;
}
@ -36,25 +37,7 @@ public class ChargeController : ControllerBase
[Route("GetChargMonitorChargBinData")]
public Result<List<BinInfoResp>> GetChargMonitorChargBinData()
{
List<BinInfo> binInfos = _binInfoRepository.Query();
var configuration = new MapperConfiguration(cfg => cfg.CreateMap<BinInfo, BinInfoResp>());
var mapper = configuration.CreateMapper();
// 转换为 BinInfoResp 列表
List<BinInfoResp> binInfoList = mapper.Map<List<BinInfoResp>>(binInfos);
// 功率赋值
foreach (var binInfoResp in binInfoList)
{
ChargerClient? chargerClient = ClientMgr.GetBySn(binInfoResp.ChargerNo);
if (chargerClient != null)
{
binInfoResp.power = chargerClient.RealTimeChargePower;
binInfoResp.ChargeConnectFlag = chargerClient.Connected;
}
}
return Result<List<BinInfoResp>>.Success(binInfoList);
return Result<List<BinInfoResp>>.Success(_binInfoService.GetChargMonitorChargBinData());
}
/// <summary>
@ -66,7 +49,7 @@ public class ChargeController : ControllerBase
[Route("ChargingBinDisable/{data}")]
public Result<bool> ChargingBinDisable(int data)
{
return Result<bool>.Success(_binInfoRepository.UpdateStatus(data));
return Result<bool>.Success(_binInfoService.UpdateStatus(data));
}
/// <summary>

@ -0,0 +1,56 @@
using Entity.Base;
using Entity.DbModel.Station;
using Entity.Dto.Req;
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
using Service.Station;
namespace WebStarter.Controllers.Station;
/// <summary>
/// 充电模式配置
/// </summary>
[Produces("application/json")]
[ApiController]
public class EquipInfoController
{
private EquipInfoService _equipInfoService;
public EquipInfoController(EquipInfoService equipInfoService)
{
_equipInfoService = equipInfoService;
}
/// <summary>
/// 充电模式配置分页
/// </summary>
/// <returns>充电模式分页列表</returns>
[HttpPost]
[Route("/api/equipInfo/page")]
public async Task<SqlSugarPagedList<EquipInfo>> Page(PageEquipInfoReq input)
{
return await _equipInfoService.Page(input);
}
/// <summary>
/// 充电模式配置修改
/// </summary>
/// <returns>修改结果</returns>
[HttpPost]
[Route("/api/equipInfo/update")]
public async Task<Result<object>> Update(UpdateEquipInfoReq input)
{
return await _equipInfoService.UpdateEquipInfoReq(input);
}
/// <summary>
/// 充电模式配置删除
/// </summary>
/// <returns>删除结果</returns>
[HttpPost]
[Route("/api/equipInfo/delete")]
public async Task<Result<object>> Delete(DeleteEquipInfoReq input)
{
return await _equipInfoService.DeleteEquipInfoReq(input);
}
}
Loading…
Cancel
Save