update 算法应用平台Service

This commit is contained in:
Lemon
2024-12-11 11:23:40 +08:00
parent 05cf609297
commit c321ca9ffc
6 changed files with 225 additions and 24 deletions

View File

@@ -185,6 +185,11 @@ public class CacheConstants {
*/ */
public static final String BMS_CHARGE_INFO_BY_TRANSACTION_CODE = "bms_charge_info_by_transaction_code:"; public static final String BMS_CHARGE_INFO_BY_TRANSACTION_CODE = "bms_charge_info_by_transaction_code:";
/**
* 0x15缓存key
*/
public static final String CHARGING_HANDSHAKE_DATA_BY_TRANSACTION_CODE = "charging_handshake_data_by_transaction_code:";
/** /**
* 充电桩状态前缀 * 充电桩状态前缀
*/ */

View File

@@ -0,0 +1,123 @@
package com.jsowell.common.core.domain.ykc;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 0x15充电握手Data
*
* @author Lemon
* @Date 2024/12/11 10:34:53
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ChargingHandshakeData {
/**
* 交易流水号
*/
private String transactionCode;
/**
* 桩编码
*/
private String pileSn;
/**
* 枪号
*/
private String connectorCode;
/**
* BMS 通信协议版本号 当前版本为 V1.1 表示为: byte3 byte2—0001Hbyte1—01H
*/
private String bmsCommunicationVersion;
/**
* BMS 电池类型
*
* 01H:铅酸电池;
* 02H:氢电池;
* 03H:磷酸铁锂电池;
* 04H:锰酸锂电池;
* 05H:钴酸锂电池;
* 06H:三元材料电池;
* 07H:聚合物锂离子电池;
* 08H:钛酸锂电池;
* FFH:其他
*/
private String bmsBatteryType;
/**
* BMS 整车动力蓄电池系统额定容量
* 0.1 Ah /位, 0 Ah 偏移量
*/
private String bmsBatteryCapacity;
/**
* BMS 整车动力蓄电池系统额定总电压
* 0.1V/位, 0V 偏移量
*/
private String bmsBatteryVoltage;
/**
* BMS 电池生产厂商名称
*/
private String bmsBatteryFactory;
/**
* BMS 电池组序号
*/
private String bmsBatteryNum;
/**
* BMS 电池组生产日期年
* 1985 年偏移量,
* 数据范围: 1985 2235 年
*/
private String bmsProductionDateYear;
/**
* BMS 电池组生产日期月
* 0 月偏移量,
* 数据范围: 112 月
*/
private String bmsProductionDateMonth;
/**
* BMS 电池组生产日期日
* 0 日偏移量,
* 数据范围: 131 日
*/
private String bmsProductionDateDay;
/**
* BMS 电池组充电次数
* 1 次/位, 0 次偏移量,
* 以 BMS 统 计为准
*/
private String bmsChargingTimes;
/**
* BMS 电池组产权标识 <0> =租赁; <1> =车自有)
*/
private String BMSPropertyIdentificationByteArr;
/**
* BMS 预留位
*/
private String BMSReservePosition;
/**
* BMS 车辆识别码
*/
private String vinCode;
/**
* BMS 软件版本号
*/
private String BMSSoftwareVersionByteArr;
}

View File

@@ -1,5 +1,7 @@
package com.jsowell.netty.handler.yunkuaichong; package com.jsowell.netty.handler.yunkuaichong;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.core.domain.ykc.ChargingHandshakeData;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol; import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.core.redis.RedisCache; import com.jsowell.common.core.redis.RedisCache;
@@ -11,6 +13,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
/** /**
* 充电握手 * 充电握手
* *
@@ -135,8 +139,30 @@ public class ChargingHandshakeHandler extends AbstractYkcHandler {
length = 8; length = 8;
byte[] BMSSoftwareVersionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); byte[] BMSSoftwareVersionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// 保存数据到redis // 保存数据到redis(缓存3天)
// redisCache.setCacheObject(); ChargingHandshakeData data = ChargingHandshakeData.builder()
.transactionCode(transactionCode)
.pileSn(pileSn)
.connectorCode(connectorCode)
.bmsCommunicationVersion(bmsCommunicationVersion)
.bmsBatteryType(bmsBatteryType)
.bmsBatteryCapacity(bmsBatteryCapacity)
.bmsBatteryVoltage(bmsBatteryVoltage)
.bmsBatteryFactory(bmsBatteryFactory)
.bmsBatteryNum(bmsBatteryNum)
.bmsProductionDateYear(bmsProductionDateYear)
.bmsProductionDateMonth(bmsProductionDateMonth)
.bmsProductionDateDay(bmsProductionDateDay)
.bmsChargingTimes(bmsChargingTimes)
// .BMSPropertyIdentificationByteArr(BMSPropertyIdentificationByteArr)
// .BMSReservePosition(BMSReservePosition)
.vinCode(vinCode)
// .BMSSoftwareVersionByteArr(BMSSoftwareVersionByteArr)
.build();
String redisKey = CacheConstants.CHARGING_HANDSHAKE_DATA_BY_TRANSACTION_CODE + transactionCode;
redisCache.setCacheObject(redisKey, data, 3, TimeUnit.DAYS);
return null; return null;
} }

View File

@@ -165,6 +165,12 @@ public interface PileBasicInfoService {
*/ */
void saveBMSChargeInfo2Redis(BMSChargeInfoData bmsChargeInfoData); void saveBMSChargeInfo2Redis(BMSChargeInfoData bmsChargeInfoData);
/**
* 根据交易流水号获取0x25数据时间倒序
* @return
*/
List<BMSChargeInfoData> getBMSChargeInfoList(String transactionCode);
/** /**
* 根据交易流水号查询0x23数据时间倒序 * 根据交易流水号查询0x23数据时间倒序
* @param transactionCode * @param transactionCode

View File

@@ -721,6 +721,34 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
} }
} }
/**
* 根据交易流水号获取0x25数据
* @param transactionCode
* @return
*/
@Override
public List<BMSChargeInfoData> getBMSChargeInfoList(String transactionCode) {
List<BMSChargeInfoData> resultList = Lists.newArrayList();
if (StringUtils.isBlank(transactionCode)) {
return resultList;
}
String redisKey = CacheConstants.BMS_CHARGE_INFO_BY_TRANSACTION_CODE + transactionCode;
// 拿到所有数据
Map<Object, Object> map = redisCache.hmget(redisKey);
if (map != null && !map.isEmpty()) {
List<String> keyList = map.keySet().stream()
.map(x -> (String) x)
.sorted(Comparator.reverseOrder()) // 对keyList排序 时间倒序
.collect(Collectors.toList());
for (String s : keyList) {
Object o = map.get(s);
BMSChargeInfoData data = JSONObject.parseObject((String) o, BMSChargeInfoData.class);
resultList.add(data);
}
}
return resultList;
}
/** /**
* 根据交易流水号查询0x23数据时间倒序 * 根据交易流水号查询0x23数据时间倒序
* @param transactionCode * @param transactionCode

View File

@@ -4,9 +4,7 @@ import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.jsowell.common.constant.CacheConstants; import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants; import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.BMSDemandAndChargerOutputData; import com.jsowell.common.core.domain.ykc.*;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
import com.jsowell.common.core.redis.RedisCache; import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.util.StringUtils; import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.service.OrderBasicInfoService; import com.jsowell.pile.service.OrderBasicInfoService;
@@ -14,6 +12,8 @@ import com.jsowell.pile.service.PileBasicInfoService;
import com.jsowell.pile.thirdparty.ParameterConfigData; import com.jsowell.pile.thirdparty.ParameterConfigData;
import com.jsowell.pile.vo.uniapp.customer.OrderVO; import com.jsowell.pile.vo.uniapp.customer.OrderVO;
import com.jsowell.thirdparty.platform.domain.ChargeAlgorithmData; import com.jsowell.thirdparty.platform.domain.ChargeAlgorithmData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@@ -38,6 +38,8 @@ public class ChargeAlgorithmService {
@Autowired @Autowired
private RedisCache redisCache; private RedisCache redisCache;
private final Logger log = LoggerFactory.getLogger(this.getClass());
/** /**
* 推送充电订单数据 * 推送充电订单数据
* @param orderCode * @param orderCode
@@ -49,7 +51,12 @@ public class ChargeAlgorithmService {
return; return;
} }
String transactionCode = orderVO.getTransactionCode(); String transactionCode = orderVO.getTransactionCode();
// 获取0x17缓存中的信息
// 获取0x15
String chargingHandshakeKey = CacheConstants.CHARGING_HANDSHAKE_DATA_BY_TRANSACTION_CODE + transactionCode;
ChargingHandshakeData chargingHandshakeData = redisCache.getCacheObject(chargingHandshakeKey);
// 获取0x17
String redisKey = CacheConstants.PARAMETER_CONFIGURATION_BY_TRANSACTION_CODE + transactionCode; String redisKey = CacheConstants.PARAMETER_CONFIGURATION_BY_TRANSACTION_CODE + transactionCode;
ParameterConfigData parameterConfigData = redisCache.getCacheObject(redisKey); ParameterConfigData parameterConfigData = redisCache.getCacheObject(redisKey);
if (parameterConfigData == null) { if (parameterConfigData == null) {
@@ -59,12 +66,12 @@ public class ChargeAlgorithmService {
String transactionDataKey = CacheConstants.TRANSACTION_RECORD_BY_TRANSACTION_CODE + transactionCode; String transactionDataKey = CacheConstants.TRANSACTION_RECORD_BY_TRANSACTION_CODE + transactionCode;
TransactionRecordsData transactionRecordsData = redisCache.getCacheObject(transactionDataKey); TransactionRecordsData transactionRecordsData = redisCache.getCacheObject(transactionDataKey);
// 获取最一条0x23数据 // 获取最一条0x23
List<BMSDemandAndChargerOutputData> bmsChargeInfoList = pileBasicInfoService.getBMSDemandAndChargerOutputInfoList(transactionCode); List<BMSDemandAndChargerOutputData> chargerOutputInfoList = pileBasicInfoService.getBMSDemandAndChargerOutputInfoList(transactionCode);
if (CollectionUtils.isEmpty(bmsChargeInfoList)) { if (CollectionUtils.isEmpty(chargerOutputInfoList)) {
return; return;
} }
BMSDemandAndChargerOutputData bmsDemandAndChargerOutputData = bmsChargeInfoList.get(0); BMSDemandAndChargerOutputData bmsDemandAndChargerOutputData = chargerOutputInfoList.get(0);
// 获取最后一条0x13 // 获取最后一条0x13
List<RealTimeMonitorData> chargingRealTimeDataList = orderBasicInfoService.getChargingRealTimeData(transactionCode); List<RealTimeMonitorData> chargingRealTimeDataList = orderBasicInfoService.getChargingRealTimeData(transactionCode);
@@ -74,12 +81,16 @@ public class ChargeAlgorithmService {
RealTimeMonitorData realTimeMonitorData = chargingRealTimeDataList.get(0); RealTimeMonitorData realTimeMonitorData = chargingRealTimeDataList.get(0);
// 获取最后一条0x25 // 获取最后一条0x25
List<BMSChargeInfoData> bmsChargeInfoList = pileBasicInfoService.getBMSChargeInfoList(transactionCode);
if (CollectionUtils.isEmpty(bmsChargeInfoList)) {
return;
}
BMSChargeInfoData bmsChargeInfoData = bmsChargeInfoList.get(0);
ChargeAlgorithmData data = ChargeAlgorithmData.builder() ChargeAlgorithmData data = ChargeAlgorithmData.builder()
.orderCode(orderCode) .orderCode(orderCode)
.initSoc(Constants.zero) .initSoc(Integer.parseInt(orderVO.getStartSoc()))
.currentSoc(Constants.zero) .currentSoc(Integer.parseInt(orderVO.getEndSoc()))
.alarmCode(Constants.ZERO) .alarmCode(Constants.ZERO)
.currentServiceFee(String.valueOf(orderVO.getTotalServiceAmount())) .currentServiceFee(String.valueOf(orderVO.getTotalServiceAmount()))
.currentTotalFee(String.valueOf(orderVO.getOrderAmount())) .currentTotalFee(String.valueOf(orderVO.getOrderAmount()))
@@ -100,11 +111,11 @@ public class ChargeAlgorithmService {
.chargePower(bmsDemandAndChargerOutputData.getOutputPower()) // 充电功率 .chargePower(bmsDemandAndChargerOutputData.getOutputPower()) // 充电功率
.ratedCapacity(parameterConfigData.getBmsSumEnergy()) // 电池额定容量 .ratedCapacity(parameterConfigData.getBmsSumEnergy()) // 电池额定容量
.nominalEnergy(parameterConfigData.getBmsSumEnergy()) .nominalEnergy(parameterConfigData.getBmsSumEnergy())
// .ratedVoltage() // 电池额定总电压 .ratedVoltage(chargingHandshakeData.getBmsBatteryVoltage()) // 电池额定总电压
.singleMaxVoltage(parameterConfigData.getPileMaxOutputVoltage()) .singleMaxVoltage(parameterConfigData.getPileMaxOutputVoltage())
.singleMinVoltage(parameterConfigData.getPileMinOutputVoltage()) .singleMinVoltage(parameterConfigData.getPileMinOutputVoltage())
// .singleMaxTemp(realTimeMonitorData.getBatteryMaxTemperature()) // 单体最高温度 .singleMaxTemp(bmsChargeInfoData.getBmsMaxBatteryTemperature()) // 单体最高温度
// .singleMinTemp() // 单体最低温度 .singleMinTemp(bmsChargeInfoData.getMinBatteryTemperature()) // 单体最低温度
// .ventTemp() // 出风口温度 // .ventTemp() // 出风口温度
// .environmentTemp() // 环境温度 // .environmentTemp() // 环境温度
.gunTemp(realTimeMonitorData.getGunLineCode()) // 充电枪温度 .gunTemp(realTimeMonitorData.getGunLineCode()) // 充电枪温度
@@ -112,14 +123,14 @@ public class ChargeAlgorithmService {
.bmsVersion("V1.1") // BMS版本 .bmsVersion("V1.1") // BMS版本
.measuringChargeVoltage(bmsDemandAndChargerOutputData.getBmsChargingVoltage()) // 车辆测量充电电压 .measuringChargeVoltage(bmsDemandAndChargerOutputData.getBmsChargingVoltage()) // 车辆测量充电电压
.measuringChargeElectricity(bmsDemandAndChargerOutputData.getBmsChargingCurrent()) // 车辆测量充电电流 .measuringChargeElectricity(bmsDemandAndChargerOutputData.getBmsChargingCurrent()) // 车辆测量充电电流
// .maxSingleVoltageGroupNum() // 最高单体电压组号 .maxSingleVoltageGroupNum(Integer.parseInt(bmsDemandAndChargerOutputData.getBmsMaxVoltageAndGroup())) // 最高单体电压组号
// .maxSingleVoltageNum() // 最高单体电压编号 .maxSingleVoltageNum(Integer.parseInt(bmsChargeInfoData.getBmsMaxVoltageNum())) // 最高单体电压编号
// .maxTempPointNum() // 最高温度点编号 .maxTempPointNum(Integer.parseInt(bmsChargeInfoData.getMaxTemperatureDetectionNum())) // 最高温度点编号
// .minTempPointNum() // 最低温度点编号 .minTempPointNum(Integer.parseInt(bmsChargeInfoData.getMinTemperatureDetectionNum())) // 最低温度点编号
// .batteryType() // 电池类型 .batteryType(chargingHandshakeData.getBmsBatteryType()) // 电池类型
// .batteryInsulation() // 电池绝缘状态 .batteryInsulation(Integer.parseInt(bmsChargeInfoData.getBmsBatteryInsulationStatus())) // 电池绝缘状态
.maxAllowTotalVoltage(parameterConfigData.getBmsMaxChargingVoltage()) .maxAllowTotalVoltage(parameterConfigData.getBmsMaxChargingVoltage())
// .beforeChargeTotalVoltage() // 充电前总电压 .beforeChargeTotalVoltage(parameterConfigData.getBmsRealTimeVoltage()) // 充电前总电压
.build(); .build();
@@ -130,11 +141,13 @@ public class ChargeAlgorithmService {
data.setCurrentSoc(Integer.parseInt(orderVO.getEndSoc())); data.setCurrentSoc(Integer.parseInt(orderVO.getEndSoc()));
} }
log.info("发送请求前封装数据 data:{}", JSON.toJSONString(data));
String url = "http://150.158.199.92:58910/gateway/api/user/battery/algorithm/json"; String url = "http://150.158.199.92:58910/gateway/api/user/battery/algorithm/json";
String clientId = ""; String clientId = "";
// 发送请求 // 发送请求
String response = HttpRequest.post(url).header("clientId", clientId).body(JSON.toJSONString(data)).execute().body(); String response = HttpRequest.post(url).header("clientId", clientId).body(JSON.toJSONString(data)).execute().body();
log.info("发送请求收到回复 response:{}", response);
} }
} }