update 算法应用Service

This commit is contained in:
Lemon
2024-12-18 11:28:25 +08:00
parent ac62831a53
commit a681a5fe9c
2 changed files with 65 additions and 23 deletions

View File

@@ -0,0 +1,39 @@
package com.jsowell.api.thirdparty;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.thirdparty.platform.service.impl.ChargeAlgorithmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 算法应用Controller
*
* @author Lemon
* @Date 2024/12/17 15:20:36
*/
@Anonymous
@RestController
@RequestMapping("/chargealgorithm")
public class ChargeAlgorithmController extends BaseController {
@Autowired
private ChargeAlgorithmService chargeAlgorithmService;
@GetMapping("/pushOrderInfo/{orderCode}")
public RestApiResponse<?> pushOrderInfo(@PathVariable("orderCode") String orderCode) {
RestApiResponse<?> response = null;
try {
String result = chargeAlgorithmService.pushOrderInfo(orderCode);
response = new RestApiResponse<>(result);
}catch (Exception e) {
logger.error("算法应用推送订单信息 error, ", e);
response = new RestApiResponse<>(e);
}
return response;
}
}

View File

@@ -6,6 +6,7 @@ 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.*; import com.jsowell.common.core.domain.ykc.*;
import com.jsowell.common.core.redis.RedisCache; import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.StringUtils; import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.service.OrderBasicInfoService; import com.jsowell.pile.service.OrderBasicInfoService;
import com.jsowell.pile.service.PileBasicInfoService; import com.jsowell.pile.service.PileBasicInfoService;
@@ -18,6 +19,7 @@ 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;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
/** /**
@@ -44,24 +46,30 @@ public class ChargeAlgorithmService {
* 推送充电订单数据 * 推送充电订单数据
* @param orderCode * @param orderCode
*/ */
public void pushOrderInfo(String orderCode) { public String pushOrderInfo(String orderCode) {
// 根据订单号查询订单信息 // 根据订单号查询订单信息
OrderVO orderVO = orderBasicInfoService.getChargeOrderInfoByOrderCode(orderCode); OrderVO orderVO = orderBasicInfoService.getChargeOrderInfoByOrderCode(orderCode);
if (orderVO == null) { if (orderVO == null) {
return; return "订单信息为空";
} }
// 计算充电时长
long chargingTime = DateUtils.intervalTime(orderVO.getStartTime(), orderVO.getEndTime());
String transactionCode = orderVO.getTransactionCode(); String transactionCode = orderVO.getTransactionCode();
// 获取0x15 // 获取0x15
String chargingHandshakeKey = CacheConstants.CHARGING_HANDSHAKE_DATA_BY_TRANSACTION_CODE + transactionCode; String chargingHandshakeKey = CacheConstants.CHARGING_HANDSHAKE_DATA_BY_TRANSACTION_CODE + transactionCode;
ChargingHandshakeData chargingHandshakeData = redisCache.getCacheObject(chargingHandshakeKey); ChargingHandshakeData chargingHandshakeData = redisCache.getCacheObject(chargingHandshakeKey);
if (chargingHandshakeData == null) {
return "0x15信息为空";
}
// 获取0x17 // 获取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) {
return; return "0x17信息为空";
} }
// 获取0x3b缓存信息 // 获取0x3b缓存信息
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);
@@ -69,33 +77,33 @@ public class ChargeAlgorithmService {
// 获取最后一条0x23 // 获取最后一条0x23
List<BMSDemandAndChargerOutputData> chargerOutputInfoList = pileBasicInfoService.getBMSDemandAndChargerOutputInfoList(transactionCode); List<BMSDemandAndChargerOutputData> chargerOutputInfoList = pileBasicInfoService.getBMSDemandAndChargerOutputInfoList(transactionCode);
if (CollectionUtils.isEmpty(chargerOutputInfoList)) { if (CollectionUtils.isEmpty(chargerOutputInfoList)) {
return; return "0x23信息为空";
} }
BMSDemandAndChargerOutputData bmsDemandAndChargerOutputData = chargerOutputInfoList.get(0); BMSDemandAndChargerOutputData bmsDemandAndChargerOutputData = chargerOutputInfoList.get(0);
// 获取最后一条0x13 // 获取最后一条0x13
List<RealTimeMonitorData> chargingRealTimeDataList = orderBasicInfoService.getChargingRealTimeData(transactionCode); // List<RealTimeMonitorData> chargingRealTimeDataList = orderBasicInfoService.getChargingRealTimeData(transactionCode);
if (CollectionUtils.isEmpty(chargingRealTimeDataList)) { // if (CollectionUtils.isEmpty(chargingRealTimeDataList)) {
return; // return "0x13信息为空";
} // }
RealTimeMonitorData realTimeMonitorData = chargingRealTimeDataList.get(0); // RealTimeMonitorData realTimeMonitorData = chargingRealTimeDataList.get(0);
// 获取最后一条0x25 // 获取最后一条0x25
List<BMSChargeInfoData> bmsChargeInfoList = pileBasicInfoService.getBMSChargeInfoList(transactionCode); List<BMSChargeInfoData> bmsChargeInfoList = pileBasicInfoService.getBMSChargeInfoList(transactionCode);
if (CollectionUtils.isEmpty(bmsChargeInfoList)) { if (CollectionUtils.isEmpty(bmsChargeInfoList)) {
return; return "0x25信息为空";
} }
BMSChargeInfoData bmsChargeInfoData = bmsChargeInfoList.get(0); BMSChargeInfoData bmsChargeInfoData = bmsChargeInfoList.get(0);
ChargeAlgorithmData data = ChargeAlgorithmData.builder() ChargeAlgorithmData data = ChargeAlgorithmData.builder()
.orderCode(orderCode) .orderCode(orderCode)
.initSoc(Integer.parseInt(orderVO.getStartSoc())) .initSoc(new BigDecimal(orderVO.getStartSoc()).intValue())
.currentSoc(Integer.parseInt(orderVO.getEndSoc())) .currentSoc(new BigDecimal(orderVO.getEndSoc()).intValue())
.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()))
.totalCharge(orderVO.getTotalPower()) .totalCharge(orderVO.getTotalPower())
.totalChargeTime(Integer.parseInt(orderVO.getChargingTime())) .totalChargeTime(Math.toIntExact(chargingTime))
.remainChargeTime(Constants.zero) .remainChargeTime(Constants.zero)
.maxAllowElectricity(parameterConfigData.getBmsMaxCurrent()) .maxAllowElectricity(parameterConfigData.getBmsMaxCurrent())
.singleMaxAllowVoltage(parameterConfigData.getBmsMaxVoltage()) .singleMaxAllowVoltage(parameterConfigData.getBmsMaxVoltage())
@@ -118,12 +126,13 @@ public class ChargeAlgorithmService {
.singleMinTemp(bmsChargeInfoData.getMinBatteryTemperature()) // 单体最低温度 .singleMinTemp(bmsChargeInfoData.getMinBatteryTemperature()) // 单体最低温度
// .ventTemp() // 出风口温度 // .ventTemp() // 出风口温度
// .environmentTemp() // 环境温度 // .environmentTemp() // 环境温度
.gunTemp(realTimeMonitorData.getGunLineCode()) // 充电枪温度 // .gunTemp(realTimeMonitorData.getGunLineTemperature()) // 充电枪温度
.gunTemp("0") // 充电枪温度
.doorStatus(Constants.zero) // 舱门状态 .doorStatus(Constants.zero) // 舱门状态
.bmsVersion("V1.1") // BMS版本 .bmsVersion("V1.1") // BMS版本
.measuringChargeVoltage(bmsDemandAndChargerOutputData.getBmsChargingVoltage()) // 车辆测量充电电压 .measuringChargeVoltage(bmsDemandAndChargerOutputData.getBmsChargingVoltage()) // 车辆测量充电电压
.measuringChargeElectricity(bmsDemandAndChargerOutputData.getBmsChargingCurrent()) // 车辆测量充电电流 .measuringChargeElectricity(bmsDemandAndChargerOutputData.getBmsChargingCurrent()) // 车辆测量充电电流
.maxSingleVoltageGroupNum(Integer.parseInt(bmsDemandAndChargerOutputData.getBmsMaxVoltageAndGroup())) // 最高单体电压组号 .maxSingleVoltageGroupNum(new BigDecimal(bmsDemandAndChargerOutputData.getBmsMaxVoltageAndGroup()).intValue()) // 最高单体电压组号
.maxSingleVoltageNum(Integer.parseInt(bmsChargeInfoData.getBmsMaxVoltageNum())) // 最高单体电压编号 .maxSingleVoltageNum(Integer.parseInt(bmsChargeInfoData.getBmsMaxVoltageNum())) // 最高单体电压编号
.maxTempPointNum(Integer.parseInt(bmsChargeInfoData.getMaxTemperatureDetectionNum())) // 最高温度点编号 .maxTempPointNum(Integer.parseInt(bmsChargeInfoData.getMaxTemperatureDetectionNum())) // 最高温度点编号
.minTempPointNum(Integer.parseInt(bmsChargeInfoData.getMinTemperatureDetectionNum())) // 最低温度点编号 .minTempPointNum(Integer.parseInt(bmsChargeInfoData.getMinTemperatureDetectionNum())) // 最低温度点编号
@@ -134,20 +143,14 @@ public class ChargeAlgorithmService {
.build(); .build();
if (StringUtils.isNotBlank(orderVO.getStartSoc())) {
data.setInitSoc(Integer.parseInt(orderVO.getStartSoc()));
}
if (StringUtils.isNotBlank(orderVO.getEndSoc())) {
data.setCurrentSoc(Integer.parseInt(orderVO.getEndSoc()));
}
log.info("发送请求前封装数据 data:{}", JSON.toJSONString(data)); 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 = "e488bac5f70b496fa2d82065089e5f81";
// 发送请求 // 发送请求
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); log.info("发送请求收到回复 response:{}", response);
return response;
} }
} }