Merge branch 'dev-zza' into dev

This commit is contained in:
Lemon
2025-04-02 13:40:41 +08:00
5 changed files with 329 additions and 159 deletions

View File

@@ -85,16 +85,19 @@ public class PersonPileController extends BaseController {
int i = pileService.pileMemberBinding(dto);
response = new RestApiResponse<>(i);
}
} catch (BusinessException e) {
logger.error("绑定个人桩信息 error,", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception exception) {
logger.error("绑定个人桩信息 error,", exception);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_BINDING_PERSONAL_PILE_ERROR);
}finally {
String cacheUid = redisCache.getCacheObject(lockKey);
if (StringUtils.equals(cacheUid, uuid)) {
// 解锁
redisCache.unLock(lockKey);
}
}
// 解锁
redisCache.unLock(lockKey);
logger.info("绑定个人桩信息 result:{}", response);
return response;
}

View File

@@ -633,8 +633,9 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
BigDecimal outputVoltage = new BigDecimal(realTimeMonitorData.getOutputVoltage());
BigDecimal outputCurrent = new BigDecimal(realTimeMonitorData.getOutputCurrent());
if (outputCurrent.compareTo(BigDecimal.ZERO) == 0) {
// 电流等于0不保存到redis
String chargingDegree = realTimeMonitorData.getChargingDegree(); // 充电度数
if (outputCurrent.compareTo(BigDecimal.ZERO) == 0 && StringUtils.equals(Constants.ZERO, chargingDegree)) {
// 电流等于0, 并且充电度数也为0时不保存到redis
return;
}

View File

@@ -5,6 +5,8 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* 充电订单算法Data
*
@@ -26,10 +28,6 @@ public class ChargeAlgorithmData {
*/
private Integer initSoc;
/**
* 当前soc
*/
private Integer currentSoc;
/**
* 告警编码
@@ -61,36 +59,6 @@ public class ChargeAlgorithmData {
*/
private Integer remainChargeTime;
/**
* 最高允许电流
*/
private String maxAllowElectricity;
/**
* 单体最高允许电压
*/
private String singleMaxAllowVoltage;
/**
* 直流充电电压
*/
private String dcv;
/**
* 直流充电电流
*/
private String dca;
/**
* BMS需求电压
*/
private String bmsDemandVoltage;
/**
* BMS需求电流
*/
private String bmsDemandElectricity;
/**
* BMS充电模式
*/
@@ -101,11 +69,6 @@ public class ChargeAlgorithmData {
*/
private String readBeforeCharge;
/**
* 当前电表读数
*/
private String readCurrentCharge;
/**
* 开始充电时间
*/
@@ -116,11 +79,6 @@ public class ChargeAlgorithmData {
*/
private String maxAllowTemp;
/**
* 充电功率
*/
private String chargePower;
/**
* 电池额定容量
*/
@@ -136,41 +94,6 @@ public class ChargeAlgorithmData {
*/
private String ratedVoltage;
/**
* 单体最高电压
*/
private String singleMaxVoltage;
/**
* 单体最低电压
*/
private String singleMinVoltage;
/**
* 单体最高温度
*/
private String singleMaxTemp;
/**
* 单体最低温度
*/
private String singleMinTemp;
/**
* 出风口温度
*/
private String ventTemp;
/**
* 环境温度
*/
private String environmentTemp;
/**
* 充电枪温度
*/
private String gunTemp;
/**
* 舱门状态
*/
@@ -181,54 +104,152 @@ public class ChargeAlgorithmData {
*/
private String bmsVersion;
/**
* 车辆测量充电电压
*/
private String measuringChargeVoltage;
/**
* 车辆测量充电电流
*/
private String measuringChargeElectricity;
/**
* 最高单体电压组号
*/
private Integer maxSingleVoltageGroupNum;
/**
* 最高单体电压编号
*/
private Integer maxSingleVoltageNum;
/**
* 最高温度点编号
*/
private Integer maxTempPointNum;
/**
* 最低温度点编号
*/
private Integer minTempPointNum;
/**
* 电池类型
*/
private String batteryType;
/**
* 电池绝缘状态
* 车辆vin码
*/
private Integer batteryInsulation;
private String vin;
/**
* 最高允许充电总电压
*/
private String maxAllowTotalVoltage;
private List<ChargingDetailInfo> chargingDetailInfo;
/**
* 充电前总电压
*/
private String beforeChargeTotalVoltage;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public static class ChargingDetailInfo {
/**
* 当前电表读数
*/
private String readCurrentCharge;
/**
* 当前soc
*/
private Integer currentSoc;
/**
* 上报时间
*/
private String reportTime;
/**
* 最高允许电流
*/
private String maxAllowElectricity;
/**
* 单体最高允许电压
*/
private String singleMaxAllowVoltage;
/**
* 直流充电电压
*/
private String dcv;
/**
* 直流充电电流
*/
private String dca;
/**
* BMS需求电压
*/
private String bmsDemandVoltage;
/**
* BMS需求电流
*/
private String bmsDemandElectricity;
/**
* 充电功率
*/
private String chargePower;
/**
* 单体最高电压
*/
private String singleMaxVoltage;
/**
* 单体最低电压
*/
private String singleMinVoltage;
/**
* 单体最高温度
*/
private String singleMaxTemp;
/**
* 单体最低温度
*/
private String singleMinTemp;
/**
* 出风口温度
*/
private String ventTemp;
/**
* 环境温度
*/
private String environmentTemp;
/**
* 充电枪温度
*/
private String gunTemp;
/**
* 车辆测量充电电压
*/
private String measuringChargeVoltage;
/**
* 车辆测量充电电流
*/
private String measuringChargeElectricity;
/**
* 最高单体电压组号
*/
private Integer maxSingleVoltageGroupNum;
/**
* 最高单体电压编号
*/
private Integer maxSingleVoltageNum;
/**
* 最高温度点编号
*/
private Integer maxTempPointNum;
/**
* 最低温度点编号
*/
private Integer minTempPointNum;
/**
* 电池绝缘状态
*/
private Integer batteryInsulation;
/**
* 最高允许充电总电压
*/
private String maxAllowTotalVoltage;
/**
* 充电前总电压
*/
private String beforeChargeTotalVoltage;
}
}

View File

@@ -8,6 +8,7 @@ import com.jsowell.common.core.domain.ykc.*;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.OrderSplitRecord;
import com.jsowell.pile.service.OrderBasicInfoService;
import com.jsowell.pile.service.PileBasicInfoService;
import com.jsowell.pile.thirdparty.ParameterConfigData;
@@ -20,7 +21,11 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 订单算法平台Service
@@ -89,60 +94,45 @@ public class ChargeAlgorithmService {
// RealTimeMonitorData realTimeMonitorData = chargingRealTimeDataList.get(0);
// 获取最后一条0x25
List<BMSChargeInfoData> bmsChargeInfoList = pileBasicInfoService.getBMSChargeInfoList(transactionCode);
if (CollectionUtils.isEmpty(bmsChargeInfoList)) {
return "0x25信息为空";
}
BMSChargeInfoData bmsChargeInfoData = bmsChargeInfoList.get(0);
// List<BMSChargeInfoData> bmsChargeInfoList = pileBasicInfoService.getBMSChargeInfoList(transactionCode);
// if (CollectionUtils.isEmpty(bmsChargeInfoList)) {
// return "0x25信息为空";
// }
// BMSChargeInfoData bmsChargeInfoData = bmsChargeInfoList.get(0);
ChargeAlgorithmData data = ChargeAlgorithmData.builder()
.vin(chargingHandshakeData.getVinCode())
.orderCode(orderCode)
.beginTime(orderVO.getStartTime())
.initSoc(new BigDecimal(orderVO.getStartSoc()).intValue())
.currentSoc(new BigDecimal(orderVO.getEndSoc()).intValue())
.alarmCode(Constants.ZERO)
.currentServiceFee(String.valueOf(orderVO.getTotalServiceAmount()))
.currentTotalFee(String.valueOf(orderVO.getOrderAmount()))
.totalCharge(orderVO.getTotalPower())
.totalChargeTime(Math.toIntExact(chargingTime))
.remainChargeTime(Constants.zero)
.maxAllowElectricity(parameterConfigData.getBmsMaxCurrent())
.singleMaxAllowVoltage(parameterConfigData.getBmsMaxVoltage())
.dcv(bmsDemandAndChargerOutputData.getPileVoltageOutput()) // 直流充电电压
.dca(bmsDemandAndChargerOutputData.getPileCurrentOutput()) // 直流充电电流
.bmsDemandVoltage(bmsDemandAndChargerOutputData.getBmsVoltageDemand()) // BMS需求电压
.bmsDemandElectricity(bmsDemandAndChargerOutputData.getBmsCurrentDemand()) // BMS需求电流
.bmsChargeMode(Integer.parseInt(bmsDemandAndChargerOutputData.getBmsChargingModel())) // BMS充电模式
.readBeforeCharge(transactionRecordsData.getAmmeterTotalStart())
.readCurrentCharge(transactionRecordsData.getAmmeterTotalEnd())
.beginTime(orderVO.getStartTime())
.bmsVersion("V1.1") // BMS版本
.batteryType(chargingHandshakeData.getBmsBatteryType()) // 电池类型
.maxAllowTemp(parameterConfigData.getBmsMaxTemperature())
.chargePower(bmsDemandAndChargerOutputData.getOutputPower()) // 充电功率
.ratedCapacity(parameterConfigData.getBmsSumEnergy()) // 电池额定容量
.nominalEnergy(parameterConfigData.getBmsSumEnergy())
.ratedVoltage(chargingHandshakeData.getBmsBatteryVoltage()) // 电池额定总电压
.singleMaxVoltage(parameterConfigData.getPileMaxOutputVoltage())
.singleMinVoltage(parameterConfigData.getPileMinOutputVoltage())
.singleMaxTemp(bmsChargeInfoData.getBmsMaxBatteryTemperature()) // 单体最高温度
.singleMinTemp(bmsChargeInfoData.getMinBatteryTemperature()) // 单体最低温度
// .ventTemp() // 出风口温度
// .environmentTemp() // 环境温度
// .gunTemp(realTimeMonitorData.getGunLineTemperature()) // 充电枪温度
.gunTemp("0") // 充电枪温度
.bmsChargeMode(Integer.parseInt(bmsDemandAndChargerOutputData.getBmsChargingModel())) // BMS充电模式
// .gunTemp("0") // 充电枪温度
.doorStatus(Constants.zero) // 舱门状态
.bmsVersion("V1.1") // BMS版本
.measuringChargeVoltage(bmsDemandAndChargerOutputData.getBmsChargingVoltage()) // 车辆测量充电电压
.measuringChargeElectricity(bmsDemandAndChargerOutputData.getBmsChargingCurrent()) // 车辆测量充电电流
.maxSingleVoltageGroupNum(new BigDecimal(bmsDemandAndChargerOutputData.getBmsMaxVoltageAndGroup()).intValue()) // 最高单体电压组号
.maxSingleVoltageNum(Integer.parseInt(bmsChargeInfoData.getBmsMaxVoltageNum())) // 最高单体电压编号
.maxTempPointNum(Integer.parseInt(bmsChargeInfoData.getMaxTemperatureDetectionNum())) // 最高温度点编号
.minTempPointNum(Integer.parseInt(bmsChargeInfoData.getMinTemperatureDetectionNum())) // 最低温度点编号
.batteryType(chargingHandshakeData.getBmsBatteryType()) // 电池类型
.batteryInsulation(Integer.parseInt(bmsChargeInfoData.getBmsBatteryInsulationStatus())) // 电池绝缘状态
.maxAllowTotalVoltage(parameterConfigData.getBmsMaxChargingVoltage())
.beforeChargeTotalVoltage(parameterConfigData.getBmsRealTimeVoltage()) // 充电前总电压
.build();
List<ChargeAlgorithmData
.ChargingDetailInfo> chargingDetailInfos = transformData(transactionCode, chargerOutputInfoList, parameterConfigData, transactionRecordsData);
data.setChargingDetailInfo(chargingDetailInfos);
log.info("发送请求前封装数据 data:{}", JSON.toJSONString(data));
String url = "http://150.158.199.92:58910/gateway/api/user/battery/algorithm/json";
@@ -153,4 +143,89 @@ public class ChargeAlgorithmService {
log.info("发送请求收到回复 response:{}", response);
return response;
}
private List<ChargeAlgorithmData.ChargingDetailInfo> transformData(String transactionCode, List<BMSDemandAndChargerOutputData> chargerOutputInfoList,
ParameterConfigData parameterConfigData, TransactionRecordsData transactionRecordsData) {
List<ChargeAlgorithmData.ChargingDetailInfo> resultList = new ArrayList<>();
ChargeAlgorithmData.ChargingDetailInfo detailInfo;
// 获取0x25
List<BMSChargeInfoData> bmsChargeInfoList = pileBasicInfoService.getBMSChargeInfoList(transactionCode);
// 0x13
List<RealTimeMonitorData> chargingRealTimeDataList = orderBasicInfoService.getChargingRealTimeData(transactionCode);
Map<String, List<BMSChargeInfoData>> collect_0x25 = new LinkedHashMap<>();
Map<String, List<RealTimeMonitorData>> collect_0x13 = new LinkedHashMap<>();
if (bmsChargeInfoList != null && chargingRealTimeDataList != null) {
// 按照dateTime分组将key设置为 yyyy-MM-dd HH:mm:00 格式)
collect_0x25 = bmsChargeInfoList.stream()
.map(x -> {
x.setDateTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00", DateUtils.parseDate(x.getDateTime())));
return x;
})
.collect(Collectors.groupingBy(BMSChargeInfoData::getDateTime));
collect_0x13 = chargingRealTimeDataList.stream()
.map(x -> {
x.setDateTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00", DateUtils.parseDate(x.getDateTime())));
return x;
})
.collect(Collectors.groupingBy(RealTimeMonitorData::getDateTime));
}
if (CollectionUtils.isEmpty(chargerOutputInfoList)) {
return new ArrayList<>();
}
for (BMSDemandAndChargerOutputData realTimeData_0x23 : chargerOutputInfoList) {
detailInfo = new ChargeAlgorithmData.ChargingDetailInfo();
String dateStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00", DateUtils.parseDate(realTimeData_0x23.getDateTime()));
// 获取0x13数据
detailInfo.setReadCurrentCharge(transactionRecordsData.getAmmeterTotalEnd());
detailInfo.setCurrentSoc(new BigDecimal(realTimeData_0x23.getSoc()).intValue());
detailInfo.setReportTime(realTimeData_0x23.getDateTime());
detailInfo.setMaxAllowElectricity(parameterConfigData.getBmsMaxCurrent());
detailInfo.setSingleMaxAllowVoltage(parameterConfigData.getBmsMaxVoltage());
detailInfo.setDcv(realTimeData_0x23.getPileVoltageOutput());
detailInfo.setDca(realTimeData_0x23.getPileCurrentOutput());
detailInfo.setBmsDemandVoltage(realTimeData_0x23.getBmsVoltageDemand());
detailInfo.setBmsDemandElectricity(realTimeData_0x23.getBmsCurrentDemand());
detailInfo.setChargePower(realTimeData_0x23.getOutputPower());
detailInfo.setSingleMaxVoltage(parameterConfigData.getPileMaxOutputVoltage());
detailInfo.setSingleMinVoltage(parameterConfigData.getPileMinOutputVoltage());
detailInfo.setMeasuringChargeVoltage(realTimeData_0x23.getBmsChargingVoltage());
detailInfo.setMeasuringChargeElectricity(realTimeData_0x23.getBmsChargingCurrent());
detailInfo.setMaxSingleVoltageGroupNum(new BigDecimal(realTimeData_0x23.getBmsMaxVoltageAndGroup()).intValue());
detailInfo.setMaxAllowTotalVoltage(parameterConfigData.getBmsMaxChargingVoltage());
detailInfo.setBeforeChargeTotalVoltage(parameterConfigData.getBmsRealTimeVoltage());
// 获取该时间的0x25数据
List<BMSChargeInfoData> bmsChargeInfoDataList = collect_0x25.get(dateStr);
if (bmsChargeInfoDataList != null) {
BMSChargeInfoData realTimeData_0x25 = bmsChargeInfoDataList.get(0);
detailInfo.setSingleMaxTemp(realTimeData_0x25.getBmsMaxBatteryTemperature());
detailInfo.setSingleMinTemp(realTimeData_0x25.getMinBatteryTemperature());
detailInfo.setMaxSingleVoltageNum(Integer.parseInt(realTimeData_0x25.getBmsMaxVoltageNum()));
detailInfo.setMaxTempPointNum(Integer.parseInt(realTimeData_0x25.getMaxTemperatureDetectionNum()));
detailInfo.setMinTempPointNum(Integer.parseInt(realTimeData_0x25.getMinTemperatureDetectionNum()));
detailInfo.setBatteryInsulation(Integer.parseInt(realTimeData_0x25.getBmsBatteryInsulationStatus()));
// detailInfo.setVentTemp();
// detailInfo.setEnvironmentTemp();
}
// 获取该时间的0x13数据
List<RealTimeMonitorData> RealTimeDataList = collect_0x13.get(dateStr);
if (RealTimeDataList != null) {
RealTimeMonitorData realTimeData_0x13 = RealTimeDataList.get(0);
detailInfo.setGunTemp(realTimeData_0x13.getGunLineTemperature());
}
resultList.add(detailInfo);
}
return resultList;
}
}

View File

@@ -1,11 +1,14 @@
package com.jsowell.thirdparty.platform.service.impl;
import cn.hutool.core.util.PageUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.redis.RedisCache;
@@ -20,6 +23,7 @@ import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.*;
import com.jsowell.common.util.bean.BeanUtils;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.domain.ykcCommond.StartChargingCommand;
import com.jsowell.pile.dto.*;
@@ -52,6 +56,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -182,6 +187,71 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
}
@Override
public String getToken(String urlAddress, String operatorId, String operatorSecret, String dataSecretIv, String signSecret, String dataSecret) {
String token = "";
// // 先查询缓存有没有token
// String tokenKey = CacheConstants.THIRD_PARTY_TOKEN_BY_OPERATOR_SECRET + operatorSecret;
// RedisCache redisCache = BeanUtils.getBean(RedisCache.class);
// String cacheToken = redisCache.getCacheObject(tokenKey);
// if (StringUtils.isNotBlank(cacheToken)) {
// token = cacheToken;
// return token;
// }
try {
// 请求地址
String requestUrl = urlAddress + "query_token";
// 请求data
Map<String, String> data = new HashMap<>();
data.put("OperatorID", operatorId);
data.put("OperatorSecret", operatorSecret);
data.put("DataSecretIV", dataSecretIv);
String dataJson = JSONUtil.toJsonStr(data);
// 加密
byte[] encryptText = Cryptos.aesEncrypt(dataJson.getBytes(StandardCharsets.UTF_8),
dataSecret.getBytes(), dataSecretIv.getBytes());
String strData = Encodes.encodeBase64(encryptText);
Map<String, String> request = new LinkedHashMap<>();
request.put("OperatorID", operatorId);
request.put("Data", strData);
request.put("TimeStamp", DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date()));
request.put("Seq", "0001");
// 生成签名
String sig = GBSignUtils.sign(request, signSecret);
request.put("Sig", sig);
String tokenRequest = JSONUtil.toJsonStr(request);
String response = HttpUtil.post(requestUrl, tokenRequest);
LianLianResultVO result = JSON.parseObject(response, LianLianResultVO.class);
// logger.info("获取令牌 result:{}", result);
if (result.getRet() == 0) {
// 解密data
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64((String) result.getData()),
dataSecret.getBytes(), dataSecretIv.getBytes());
String dataStr = new String(plainText, StandardCharsets.UTF_8);
Map<String, Object> resultMap = (Map<String, Object>) JSON.parse(dataStr);
token = String.valueOf(resultMap.get("AccessToken"));
if (resultMap.get("TokenAvailableTime") != null) {
// int tokenAvailableTime = Integer.parseInt(String.valueOf(resultMap.get("TokenAvailableTime")));
// 将token存入缓存
// redisCache.setCacheObject(tokenKey, token, tokenAvailableTime, TimeUnit.SECONDS);
}
// logger.info("token: {}", token);
}
// logger.info("获取令牌 result:{}, token: {}", result, token);
} catch (Exception e) {
return token;
}
return token;
}
/**
* 查询充电站信息 query_stations_info
* 此接口用于查询对接平台的充电站的信息