新增解析充电BMS数据

This commit is contained in:
panshuling321 2022-08-31 15:22:23 +08:00
parent 319aee8634
commit ac432609c9
2 changed files with 200 additions and 0 deletions

View File

@ -0,0 +1,143 @@
package com.xhpc.common.data.redis;
import com.xhpc.common.data.up.BaseData;
//充电桩与 BMS 充电过程 BMS 需求充电机输出
public class CacheBmsReqChargerOutputData extends BaseData {
private String orderNo; //交易流水号
private String pileNo; //桩号
private String gunId; //枪号
private Double bmsVoltageRequest; //BMS 电压需求
private Double bmsCurrentRequest; //BMS 电流需求
private Integer bmsChargingMod; //BMS 充电模式
private Double bmsChargingVolt; //BMS 充电电压测量值
private Double bmsChargingCurrent; //BMS 充电电流测量值
private Double monoBatteryVolt; //BMS 最高单体动力蓄电池电压
private Integer soc; //BMS 当前荷电状态 SOC %
private Integer bmsEstRemainingTime; //BMS 估算剩余充电时间
private Double pileVoltageOutput; //电桩电压输出值
private Double pileCurrentOutput; //电桩电流输出值
private Integer chargingTimeSummary; //累计充电时间
private Integer monoBatteryVoltGroupId; // BMS 最高单体动力蓄电池电压所在组号ID
public String getOrderNo() {
return orderNo;
}
public Double getMonoBatteryVolt() {
return monoBatteryVolt;
}
public void setMonoBatteryVolt(Double monoBatteryVolt) {
this.monoBatteryVolt = monoBatteryVolt;
}
public void setOrderNo(String orderNo) {
this.orderNo = orderNo;
}
public String getPileNo() {
return pileNo;
}
public void setPileNo(String pileNo) {
this.pileNo = pileNo;
}
public String getGunId() {
return gunId;
}
public void setGunId(String gunId) {
this.gunId = gunId;
}
public Double getBmsVoltageRequest() {
return bmsVoltageRequest;
}
public void setBmsVoltageRequest(Double bmsVoltageRequest) {
this.bmsVoltageRequest = bmsVoltageRequest;
}
public Double getBmsCurrentRequest() {
return bmsCurrentRequest;
}
public void setBmsCurrentRequest(Double bmsCurrentRequest) {
this.bmsCurrentRequest = bmsCurrentRequest;
}
public Integer getBmsChargingMod() {
return bmsChargingMod;
}
public void setBmsChargingMod(Integer bmsChargingMod) {
this.bmsChargingMod = bmsChargingMod;
}
public Double getBmsChargingVolt() {
return bmsChargingVolt;
}
public void setBmsChargingVolt(Double bmsChargingVolt) {
this.bmsChargingVolt = bmsChargingVolt;
}
public Double getBmsChargingCurrent() {
return bmsChargingCurrent;
}
public void setBmsChargingCurrent(Double bmsChargingCurrent) {
this.bmsChargingCurrent = bmsChargingCurrent;
}
public Integer getMonoBatteryVoltGroupId() {
return monoBatteryVoltGroupId;
}
public void setMonoBatteryVoltGroupId(Integer monoBatteryVoltGroupId) {
this.monoBatteryVoltGroupId = monoBatteryVoltGroupId;
}
public Integer getSoc() {
return soc;
}
public void setSoc(Integer soc) {
this.soc = soc;
}
public Integer getBmsEstRemainingTime() {
return bmsEstRemainingTime;
}
public void setBmsEstRemainingTime(Integer bmsEstRemainingTime) {
this.bmsEstRemainingTime = bmsEstRemainingTime;
}
public Double getPileVoltageOutput() {
return pileVoltageOutput;
}
public void setPileVoltageOutput(Double pileVoltageOutput) {
this.pileVoltageOutput = pileVoltageOutput;
}
public Double getPileCurrentOutput() {
return pileCurrentOutput;
}
public void setPileCurrentOutput(Double pileCurrentOutput) {
this.pileCurrentOutput = pileCurrentOutput;
}
public Integer getChargingTimeSummary() {
return chargingTimeSummary;
}
public void setChargingTimeSummary(Integer chargingTimeSummary) {
this.chargingTimeSummary = chargingTimeSummary;
}
}

View File

@ -1,19 +1,29 @@
package com.xhpc.pp.logic;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xhpc.common.api.PileOrderService;
import com.xhpc.common.data.redis.CacheBmsReqChargerOutputData;
import com.xhpc.common.data.up.BmsReqChargerOutputData;
import com.xhpc.common.enums.StationDeviceEnum;
import com.xhpc.pp.domain.XhpcDeviceMessage;
import com.xhpc.pp.mapper.XhpcDeviceMessageMapper;
import com.xhpc.pp.tx.ServiceParameter;
import com.xhpc.pp.tx.ServiceResult;
import com.xhpc.pp.tx.logic.ServiceLogic;
import com.xhpc.pp.utils.HexUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.Map;
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
@Lazy
@Component("BmsReqChargerOutputDataLogic")
public class BmsReqChargerOutputDataLogic implements ServiceLogic {
@ -22,10 +32,24 @@ public class BmsReqChargerOutputDataLogic implements ServiceLogic {
@Resource
XhpcDeviceMessageMapper deviceMessageMapper;
@Resource
PileOrderService pileOrderService;
@Override
public ServiceResult service(ServiceParameter sp) throws Exception {
Map<String, Object> req = sp.getParameters();
ObjectMapper objectMapper = new ObjectMapper();
BmsReqChargerOutputData orderData = objectMapper.convertValue(req, BmsReqChargerOutputData.class);
String orderNo = (String) req.get("orderNo");
String orderKey = "order:".concat(orderNo);
Map<String, Object> cacheOrder = REDIS.getCacheMap(orderKey);
CacheBmsReqChargerOutputData cacheBmsReqChargerOutputData = translate(orderData);
cacheOrder.put("bmsData", cacheBmsReqChargerOutputData);
REDIS.setCacheMap(orderKey, cacheOrder);
pileOrderService.pileRimeOrderBms(orderNo);
XhpcDeviceMessage deviceMessage = new XhpcDeviceMessage();
deviceMessage.setType(StationDeviceEnum.PILE.getCode());
@ -39,4 +63,37 @@ public class BmsReqChargerOutputDataLogic implements ServiceLogic {
return new ServiceResult(false);
}
private CacheBmsReqChargerOutputData translate(BmsReqChargerOutputData orderData) {
CacheBmsReqChargerOutputData cacheBmsReqChargerOutputData = new CacheBmsReqChargerOutputData();
cacheBmsReqChargerOutputData.setOrderNo(orderData.getOrderNo());
cacheBmsReqChargerOutputData.setPileNo(orderData.getPileNo());
cacheBmsReqChargerOutputData.setGunId(orderData.getGunId());
cacheBmsReqChargerOutputData.setBmsVoltageRequest(convertDouble(HexUtils.reverseHexInt(orderData.getBmsVoltageRequest()) * 0.1));
cacheBmsReqChargerOutputData.setBmsCurrentRequest(convertDouble(HexUtils.reverseHexInt(orderData.getBmsCurrentRequest()) * 0.1));
cacheBmsReqChargerOutputData.setBmsChargingMod(HexUtils.reverseHexInt(orderData.getBmsChargingMod()));
cacheBmsReqChargerOutputData.setBmsChargingVolt(convertDouble(HexUtils.reverseHexInt(orderData.getBmsChargingVolt()) * 0.1));
cacheBmsReqChargerOutputData.setBmsChargingCurrent(convertDouble(HexUtils.reverseHexInt(orderData.getBmsChargingCurrent()) * 0.1));
cacheBmsReqChargerOutputData.setMonoBatteryVolt(convertDouble(Integer.parseInt(orderData.getMonoBatteryVoltGroupId().substring(0, 3), 16) * 0.01));
cacheBmsReqChargerOutputData.setSoc(HexUtils.reverseHexInt(orderData.getSoc()));
cacheBmsReqChargerOutputData.setBmsEstRemainingTime(HexUtils.reverseHexInt(orderData.getBmsEstRemainingTime()));
cacheBmsReqChargerOutputData.setPileVoltageOutput(convertDouble(HexUtils.reverseHexInt(orderData.getPileVoltageOutput()) * 0.1));
cacheBmsReqChargerOutputData.setPileCurrentOutput(convertDouble(HexUtils.reverseHexInt(orderData.getPileVoltageOutput()) * 0.1));
cacheBmsReqChargerOutputData.setChargingTimeSummary(HexUtils.reverseHexInt(orderData.getChargingTimeSummary()));
cacheBmsReqChargerOutputData.setMonoBatteryVoltGroupId(Integer.parseInt(orderData.getMonoBatteryVoltGroupId().substring(3), 16));
cacheBmsReqChargerOutputData.setHex(orderData.getHex());
cacheBmsReqChargerOutputData.setCreateTime(DateUtil.now());
return cacheBmsReqChargerOutputData;
}
private Double convertDouble(Double oldVar) {
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
nf.setMinimumFractionDigits(2);
nf.setRoundingMode(RoundingMode.HALF_UP);
nf.setGroupingUsed(false);
return Double.parseDouble(nf.format(oldVar));
}
}