You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.6 KiB

using AutoMapper;
5 months ago
using DotNetty.Transport.Channels;
using Entity.Api.Resp;
5 months ago
using Entity.DbModel.Station;
5 months ago
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
5 months ago
using Repository.Station;
5 months ago
namespace Service.Charger.Handler;
/// <summary>
/// 电池状态上报 处理器
/// </summary>
[Order(8)]
[Scope("InstancePerDependency")]
public class BatteryStatusReportedReqHandler : SimpleChannelInboundHandler<BatteryStatusReportedReq>, IBaseHandler
{
private readonly BinInfoRepository _binInfoRepository;
5 months ago
private static readonly ILog Log =LogManager.GetLogger(typeof(BatteryStatusReportedReqHandler));
public BinInfoRepository BinInfoRepository { get; set; }
5 months ago
/// <summary>
///
/// </summary>
protected override void ChannelRead0(IChannelHandlerContext ctx, BatteryStatusReportedReq msg)
{
List<BinInfo> binInfos = _binInfoRepository.Query();
var configuration = new MapperConfiguration(cfg => cfg.CreateMap<BinInfo, BinInfoResp>());
var mapper = configuration.CreateMapper();
List<BinInfoResp> binInfoList = mapper.Map<List<BinInfoResp>>(binInfos);
byte[] granaries = new byte[8];
for (int i = 0; i < binInfoList.Count && i < granaries.Length; i++)
{
granaries[i] = (binInfoList[i].ChargeStatus == 0 || binInfoList[i].ChargeStatus.Value == 2 || binInfoList[i].ChargeStatus.Value == 4) ? (byte)0 : (byte)1;
}
ctx.Channel.WriteAndFlushAsync(message: new Msg.Host.Resp.WhetherChargedResq(granaries[0], granaries[1], granaries[2], granaries[3], granaries[4], granaries[5], granaries[6], granaries[7]));
UpdateBinInfo(msg.granary01, "1");
5 months ago
UpdateBinInfo(msg.granary02, "2");
UpdateBinInfo(msg.granary03, "3");
UpdateBinInfo(msg.granary04, "4");
UpdateBinInfo(msg.granary05, "5");
UpdateBinInfo(msg.granary06, "6");
UpdateBinInfo(msg.granary07, "7");
UpdateBinInfo(msg.granary08, "8");
// UpdateBinInfo(msg.granary09, "9");
}
5 months ago
private void UpdateBinInfo(int exists, string binNo)
{
if (exists == 0)
BinInfoRepository.Update(
it =>
new BinInfo(){
Exists = 0,
3 months ago
ChargeStatus=2,
2 months ago
5 months ago
BatteryNo = "-1",
Soc = (decimal)-1,
5 months ago
Soe = (decimal)-1,
Soh = (decimal)-1,
},
it => it.No == binNo);
else
3 months ago
BinInfoRepository.Update(it => new BinInfo { Exists = 1 },
5 months ago
it => it.No == binNo);
5 months ago
}
}