handle json parse exception, just catch it n return null

This commit is contained in:
ZZ 2021-12-10 11:12:46 +08:00
parent bd81a0b595
commit 2a24e1a8a1
16 changed files with 614 additions and 747 deletions

View File

@ -5,6 +5,6 @@ public class EvcsConst {
//请求成功
public static final String RET_SUCC = "0";
//请求失败
public static final String RET_FAIL = "1";
public static final String RET_FAIL = "500";
}

View File

@ -6,6 +6,8 @@ import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Iterator;
@ -13,7 +15,8 @@ import java.util.List;
public class JSONUtil {
private static ObjectMapper mapper = new ObjectMapper();
private static final ObjectMapper mapper = new ObjectMapper();
private static final Logger logger = LoggerFactory.getLogger(JSONUtil.class);
/**
* 将一个对象转换成目标对象
@ -33,9 +36,14 @@ public class JSONUtil {
}
// 适用于简单对象,复杂对象参考下面的main方法
public static <T> T readParams(String params, Class<T> clz) throws IOException {
public static <T> T readParams(String params, Class<T> clz) {
return mapper.readValue(params, clz);
try {
return mapper.readValue(params, clz);
} catch (JsonProcessingException e) {
logger.debug("invalid json:{}", params);
return null;
}
}
public static <T> List<T> readParamsList(String data, Class<T> clzo) throws IOException {

View File

@ -22,7 +22,7 @@ public class NotificationChargeOrderInfoController {
stationInfo.setOperatorId(operatorID);
String data = commonRequest.getData();
ChargeOrderInfo chargeOrderInfo = JSONUtil.readParams(data, ChargeOrderInfo.class);
chargeOrderInfo.setInfraOperatorId("759588065"); //todo use common request operator id?
chargeOrderInfo.setInfraOperatorId("759588065"); //todo use common request operator id && check NPE
chargeOrderInfo.setBillerOperatorId("MA6DFCTD5");
log.info(">>notify charge order OID: " + operatorID);
// chargeOrderInfoRepository.save(chargeOrderInfo);

View File

@ -27,7 +27,7 @@ public class NotificationStartChargeResultController {
String data = commonRequest.getData();
NotificationStartChargeResultRequestData startChargeResultRequest = JSONUtil.readParams(data,
NotificationStartChargeResultRequestData.class);
NotificationStartChargeResultRequestData.class); // todo check NPE
String startChargeSeq = startChargeResultRequest.getStartChargeSeq();
// ChargeOrderInfo chargeOrderInfo = chargeOrderInfoRepository.findById(startChargeSeq).orElse(new ChargeOrderInfo()
// .setStartChargeSeqAndReturn(startChargeSeq));

View File

@ -25,7 +25,7 @@ public class NotifyNoBillOrderController {
public CommonResponse notifyNoBillOrder(@RequestBody CommonRequest<NotifyNoBillOrderRequest> commonRequest) throws IOException {
NotifyNoBillOrderRequest notifyNoBillOrderRequest = JSONUtil.readParams(commonRequest.getData(),
NotifyNoBillOrderRequest.class);
NotifyNoBillOrderRequest.class);// todo check NPE
CommonResponse commonResponse = new CommonResponse();
commonResponse.setMsg("Query equipment business policy success");

View File

@ -6,6 +6,7 @@ import com.xhpc.evcs.dto.CommonRequest;
import com.xhpc.evcs.dto.CommonResponse;
import com.xhpc.evcs.dto.EquipAuthRequest;
import com.xhpc.evcs.dto.EquipAuthResponse;
import com.xhpc.evcs.encryption.EvcsConst;
import com.xhpc.evcs.jpa.XhpcInternetUserRepository;
import com.xhpc.evcs.jpa.XhpcStationInternetBlacklistRepository;
import com.xhpc.evcs.utils.JSONUtil;
@ -38,56 +39,58 @@ public class QueryEquipAuthController {
public CommonResponse queryEquipAuth(@RequestBody CommonRequest<EquipAuthRequest> commonRequest) throws Exception {
CommonResponse resp = new CommonResponse();
EquipAuthResponse equipAuthResponse = new EquipAuthResponse();
resp.setRet(EvcsConst.RET_FAIL);
EquipAuthRequest equipAuthRequest = JSONUtil.readParams(commonRequest.getData(), EquipAuthRequest.class);
String equipAuthSeq = equipAuthRequest.getEquipAuthSeq();
String connectorId = equipAuthRequest.getConnectorId();
equipAuthResponse.setEquipAuthSeq(equipAuthSeq);
equipAuthResponse.setConnectorId(connectorId);
String pileId = connectorId.substring(0, connectorId.length() - 2);
Map<String, Object> pileDataModel = REDIS.getCacheMap("pile:" + pileId);
Long stationId = Long.parseLong(pileDataModel.get("stationId").toString());
Instant now = Instant.now();
XhpcInternetUser xhpcInternetUser = xhpcInternetUserRepository
.findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(commonRequest.getOperatorId(), now, now);
if (xhpcInternetUser == null) {
equipAuthResponse.setSuccStat(1);
equipAuthResponse.setFailReason(2);
resp.setRet("500");
resp.setMsg("auth denied");
if (equipAuthRequest == null) {
resp.setMsg("Request or token params validation failed");
} else {
Long internetUserId = xhpcInternetUser.getInternetUserId();
XhpcStationInternetBlacklist xhpcStationInternetBlacklist =
xhpcStationInternetBlacklistRepo.findByChargingStationIdAndInternetUserId(stationId, internetUserId).orElse(null);
if (null != xhpcStationInternetBlacklist) {
EquipAuthResponse equipAuthResponse = new EquipAuthResponse();
String equipAuthSeq = equipAuthRequest.getEquipAuthSeq();
String connectorId = equipAuthRequest.getConnectorId();
equipAuthResponse.setEquipAuthSeq(equipAuthSeq);
equipAuthResponse.setConnectorId(connectorId);
String pileId = connectorId.substring(0, connectorId.length() - 2);
Map<String, Object> pileDataModel = REDIS.getCacheMap("pile:" + pileId);
Long stationId = Long.parseLong(pileDataModel.get("stationId").toString());
Instant now = Instant.now();
XhpcInternetUser xhpcInternetUser = xhpcInternetUserRepository
.findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(commonRequest.getOperatorId(), now, now);
if (xhpcInternetUser == null) {
equipAuthResponse.setSuccStat(1);
equipAuthResponse.setFailReason(2);
resp.setRet("500");
resp.setMsg("auth denied");
} else {
Map<String, Object> cacheGun = REDIS.getCacheMap("gun:".concat(connectorId));
String terminalStatus = (String) cacheGun.get("vehicleGunStatus");
String status = (String) cacheGun.get("status");
if (!"空闲".equals(status)) {
resp.setMsg("终端不在空闲状态:[".concat(status == null ? "未注册" : isInteger(status) ? "充电中" : status).concat("]"));
resp.setRet("500");
Long internetUserId = xhpcInternetUser.getInternetUserId();
XhpcStationInternetBlacklist xhpcStationInternetBlacklist =
xhpcStationInternetBlacklistRepo.findByChargingStationIdAndInternetUserId(stationId, internetUserId).orElse(null);
if (null != xhpcStationInternetBlacklist) {
equipAuthResponse.setSuccStat(1);
equipAuthResponse.setFailReason(1);
} else if ("".equals(terminalStatus)) {
resp.setMsg("未插枪");
resp.setRet("500");
equipAuthResponse.setSuccStat(1);
equipAuthResponse.setFailReason(1);
equipAuthResponse.setFailReason(2);
resp.setMsg("auth denied");
} else {
resp.setRet("0");
resp.setMsg("success");
equipAuthResponse.setSuccStat(0);
equipAuthResponse.setFailReason(0);
}
Map<String, Object> cacheGun = REDIS.getCacheMap("gun:".concat(connectorId));
String terminalStatus = (String) cacheGun.get("vehicleGunStatus");
String status = (String) cacheGun.get("status");
if (!"空闲".equals(status)) {
resp.setMsg("终端不在空闲状态:[".concat(status == null ? "未注册" : isInteger(status) ? "充电中" : status).concat(
"]"));
equipAuthResponse.setSuccStat(1);
equipAuthResponse.setFailReason(1);
} else if ("".equals(terminalStatus)) {
resp.setMsg("未插枪");
equipAuthResponse.setSuccStat(1);
equipAuthResponse.setFailReason(1);
} else {
resp.setRet("0");
resp.setMsg("success");
equipAuthResponse.setSuccStat(0);
equipAuthResponse.setFailReason(0);
}
}
}
resp.setData(JSONUtil.toJSONString(equipAuthResponse));
}
resp.setData(JSONUtil.toJSONString(equipAuthResponse));
return resp;
}
}

View File

@ -29,130 +29,133 @@ public class QueryEquipBusinessPolicyController {
public CommonResponse queryEquipBusinessPolicy(@RequestBody CommonRequest<EquipBizRequest> commonRequest) throws IOException {
//获取充电设备接口编码枪编码
EquipBizRequest equipBizRequest = JSONUtil.readParams(commonRequest.getData(), EquipBizRequest.class);
String connectorId = equipBizRequest.getConnectorId();
//获取枪所对应的桩编码
String pileSerialNumber = xhpcTerminalRepository.selectBySql(connectorId);
Map<String, Object> cachePile = REDIS.getCacheMap("pile:" + pileSerialNumber);
if (pileSerialNumber == null || cachePile == null) {
CommonResponse commonResponse = new CommonResponse();
commonResponse.setMsg("ConnectorID not found");
commonResponse.setRet("1");
return commonResponse;
}
ArrayList<String> modelTypes = new ArrayList<>();
//存储时段个数
ArrayList<Integer> modelCount = new ArrayList<>();
Long rateModelId = (Long) cachePile.get("rateModelId");
CacheRateModel rateModel = REDIS.getCacheObject("rateModel:" + rateModelId);
PolicyInfos[] policyInfosArr = new PolicyInfos[0];
if (rateModel != null) {
String[] tfPricesSeq = rateModel.getTfPricesSeq();
//存储时段
//建立对应时段的映射Map集合存放其对应的价格和服务费
Map<String, Object> timeMap = new HashMap<>();
//个数计数器
int count = 0;
//最后一个时段的前一个时段的下标索引
int index = 0;
//遍历获取每一个时段
for (int i = 0; i < tfPricesSeq.length - 1; i++) {
count++;
//如果当前时段与后面的时段不相同则表示当前时段已经结束添加当前时段到list中,并将其坐标存放到另一个集合中
if (!tfPricesSeq[i].equals(tfPricesSeq[i + 1])) {
//将每段时间的索引赋值
index = i;
modelTypes.add(tfPricesSeq[i]);
modelCount.add(count);
//如果这段时段结束则重置计数器
count = 0;
}
}
//获取最后一个时段的费率值
String lastModelType = tfPricesSeq[tfPricesSeq.length - 1];
//放入到类型list中
modelTypes.add(lastModelType);
//获取最后一个时段的费率的个数
int lastCount = (tfPricesSeq.length - 1) - index;
//放入到个数List中
modelCount.add(lastCount);
//获取各个类型的时段的时间区间并将其存放至timeList集合中
//定义一个初始时间段
String initTime = "000000";
//添加临时存储变量
int temp = -1;
ArrayList<String> timeList = new ArrayList<>();
//放入必有初始时间
timeList.add(initTime);
//根据出现的时段个数确定他们的时间区间,然后存放至List集合中
for (int i = 0; i < modelCount.size() - 1; i++) {
if (temp != -1) {
Integer integer = modelCount.get(i);
int hours = integer / 2;
temp = temp + hours;
String hoursStr = String.format("%02d", temp);
String finalTime = hoursStr + "0000";
timeList.add(finalTime);
} else {
Integer integer = modelCount.get(i);
int hours = integer / 2;
//记录中间时间
temp = hours;
String hoursStr = String.format("%02d", temp);
String finalTime = hoursStr + "0000";
timeList.add(finalTime);
}
}
policyInfosArr = new PolicyInfos[timeList.size()];
for (int i = 0; i <= timeList.size() - 1; i++) {
PolicyInfos policyInfos = new PolicyInfos();
policyInfos.setStartTime(timeList.get(i));
String modelType = modelTypes.get(i);
switch (modelType) {
case "00":
policyInfos.setServicePrice(BigDecimal.valueOf((long) rateModel.getT1SvcPrice()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
policyInfos.setElecPrice(BigDecimal.valueOf((long) rateModel.getT1Price()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
break;
case "01":
policyInfos.setServicePrice(BigDecimal.valueOf((long) rateModel.getT2SvcPrice()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
policyInfos.setElecPrice(BigDecimal.valueOf((long) rateModel.getT2Price()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
break;
case "02":
policyInfos.setServicePrice(BigDecimal.valueOf((long) rateModel.getT3SvcPrice()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
policyInfos.setElecPrice(BigDecimal.valueOf((long) rateModel.getT3Price()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
break;
case "03":
policyInfos.setServicePrice(BigDecimal.valueOf((long) rateModel.getT4SvcPrice()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
policyInfos.setElecPrice(BigDecimal.valueOf((long) rateModel.getT4Price()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
break;
default:
break;
}
policyInfosArr[i] = policyInfos;
}
}
//封装数据
EquipBizResponse equipBizResponse = new EquipBizResponse();
//业务查询流水号
equipBizResponse.setEquipBizSeq(equipBizRequest.getEquipBizSeq());
//充电设备接口编码
equipBizResponse.setConnectorId(connectorId);
//操作结果
equipBizResponse.setSuccStat(0);
//失败原因
equipBizResponse.setFailReason(0);
//总时段数
equipBizResponse.setSumPeriod(modelTypes.size());
//计费信息
equipBizResponse.setPolicyInfos(policyInfosArr);
//塞入包装类
CommonResponse commonResponse = new CommonResponse();
commonResponse.setMsg("Query equipment business policy success");
commonResponse.setRet("0");
commonResponse.setData(JSONUtil.toJSONString(equipBizResponse));
if (equipBizRequest == null) {
commonResponse.setRet("500");
commonResponse.setMsg("Request or token params validation failed");
} else {
String connectorId = equipBizRequest.getConnectorId();
//获取枪所对应的桩编码
String pileSerialNumber = xhpcTerminalRepository.selectBySql(connectorId);
Map<String, Object> cachePile = REDIS.getCacheMap("pile:" + pileSerialNumber);
if (pileSerialNumber == null || cachePile == null) {
commonResponse.setMsg("ConnectorID not found");
commonResponse.setRet("500");
return commonResponse;
}
ArrayList<String> modelTypes = new ArrayList<>();
//存储时段个数
ArrayList<Integer> modelCount = new ArrayList<>();
Long rateModelId = (Long) cachePile.get("rateModelId");
CacheRateModel rateModel = REDIS.getCacheObject("rateModel:" + rateModelId);
PolicyInfos[] policyInfosArr = new PolicyInfos[0];
if (rateModel != null) {
String[] tfPricesSeq = rateModel.getTfPricesSeq();
//存储时段
//建立对应时段的映射Map集合存放其对应的价格和服务费
Map<String, Object> timeMap = new HashMap<>();
//个数计数器
int count = 0;
//最后一个时段的前一个时段的下标索引
int index = 0;
//遍历获取每一个时段
for (int i = 0; i < tfPricesSeq.length - 1; i++) {
count++;
//如果当前时段与后面的时段不相同则表示当前时段已经结束添加当前时段到list中,并将其坐标存放到另一个集合中
if (!tfPricesSeq[i].equals(tfPricesSeq[i + 1])) {
//将每段时间的索引赋值
index = i;
modelTypes.add(tfPricesSeq[i]);
modelCount.add(count);
//如果这段时段结束则重置计数器
count = 0;
}
}
//获取最后一个时段的费率值
String lastModelType = tfPricesSeq[tfPricesSeq.length - 1];
//放入到类型list中
modelTypes.add(lastModelType);
//获取最后一个时段的费率的个数
int lastCount = (tfPricesSeq.length - 1) - index;
//放入到个数List中
modelCount.add(lastCount);
//获取各个类型的时段的时间区间并将其存放至timeList集合中
//定义一个初始时间段
String initTime = "000000";
//添加临时存储变量
int temp = -1;
ArrayList<String> timeList = new ArrayList<>();
//放入必有初始时间
timeList.add(initTime);
//根据出现的时段个数确定他们的时间区间,然后存放至List集合中
for (int i = 0; i < modelCount.size() - 1; i++) {
if (temp != -1) {
Integer integer = modelCount.get(i);
int hours = integer / 2;
temp = temp + hours;
String hoursStr = String.format("%02d", temp);
String finalTime = hoursStr + "0000";
timeList.add(finalTime);
} else {
Integer integer = modelCount.get(i);
int hours = integer / 2;
//记录中间时间
temp = hours;
String hoursStr = String.format("%02d", temp);
String finalTime = hoursStr + "0000";
timeList.add(finalTime);
}
}
policyInfosArr = new PolicyInfos[timeList.size()];
for (int i = 0; i <= timeList.size() - 1; i++) {
PolicyInfos policyInfos = new PolicyInfos();
policyInfos.setStartTime(timeList.get(i));
String modelType = modelTypes.get(i);
switch (modelType) {
case "00":
policyInfos.setServicePrice(BigDecimal.valueOf((long) rateModel.getT1SvcPrice()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
policyInfos.setElecPrice(BigDecimal.valueOf((long) rateModel.getT1Price()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
break;
case "01":
policyInfos.setServicePrice(BigDecimal.valueOf((long) rateModel.getT2SvcPrice()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
policyInfos.setElecPrice(BigDecimal.valueOf((long) rateModel.getT2Price()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
break;
case "02":
policyInfos.setServicePrice(BigDecimal.valueOf((long) rateModel.getT3SvcPrice()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
policyInfos.setElecPrice(BigDecimal.valueOf((long) rateModel.getT3Price()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
break;
case "03":
policyInfos.setServicePrice(BigDecimal.valueOf((long) rateModel.getT4SvcPrice()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
policyInfos.setElecPrice(BigDecimal.valueOf((long) rateModel.getT4Price()).divide(BigDecimal.valueOf(100000L)).setScale(4).doubleValue());
break;
default:
break;
}
policyInfosArr[i] = policyInfos;
}
}
//封装数据
EquipBizResponse equipBizResponse = new EquipBizResponse();
//业务查询流水号
equipBizResponse.setEquipBizSeq(equipBizRequest.getEquipBizSeq());
//充电设备接口编码
equipBizResponse.setConnectorId(connectorId);
//操作结果
equipBizResponse.setSuccStat(0);
//失败原因
equipBizResponse.setFailReason(0);
//总时段数
equipBizResponse.setSumPeriod(modelTypes.size());
//计费信息
equipBizResponse.setPolicyInfos(policyInfosArr);
//塞入包装类
commonResponse.setMsg("Query equipment business policy success");
commonResponse.setRet("0");
commonResponse.setData(JSONUtil.toJSONString(equipBizResponse));
}
return commonResponse;
}
}

View File

@ -40,100 +40,105 @@ public class QueryEquipChargeStatusController {
//充电订单号 三方传进来都是27位
String data = commonRequest.getData();
ChargeInfoRequest chargeInfoRequest = JSONUtil.readParams(data, ChargeInfoRequest.class);
String startChargeSeq = chargeInfoRequest.getStartChargeSeq();
equipChargeStatus.setStartChargeSeq(startChargeSeq);
CommonResponse response = new CommonResponse();
//充电订单状态
EtOrderMapping etOrderMapping = orderMappingRepository.findByEvcsOrderNo(startChargeSeq).orElse(null);
if (etOrderMapping == null) {
if (chargeInfoRequest == null) {
response.setRet(EvcsConst.RET_FAIL);
response.setMsg("Order not found/started");
log.error("3rdpty order[{}] not found", startChargeSeq);
return response;
}
String internalOrderNum = etOrderMapping.getXhOrderNo();
Map<String, Object> cacheOrder = REDIS.getCacheMap("order:" + internalOrderNum);
if (cacheOrder == null) {
response.setRet(EvcsConst.RET_FAIL);
response.setMsg("Order cache data not found");
response.setMsg("Request or token params validation failed");
} else {
String orderStatus = (String) cacheOrder.get("status");
int startChargeSeqStat;
if (orderStatus == null) {
startChargeSeqStat = 5;
} else switch (orderStatus) {
case "启动中":
startChargeSeqStat = 1;
break;
case "充电中":
startChargeSeqStat = 2;
break;
case "停止中":
startChargeSeqStat = 3;
break;
case "已结束":
startChargeSeqStat = 4;
break;
default:
startChargeSeqStat = 5;
break;
String startChargeSeq = chargeInfoRequest.getStartChargeSeq();
equipChargeStatus.setStartChargeSeq(startChargeSeq);
//充电订单状态
EtOrderMapping etOrderMapping = orderMappingRepository.findByEvcsOrderNo(startChargeSeq).orElse(null);
if (etOrderMapping == null) {
response.setRet(EvcsConst.RET_FAIL);
response.setMsg("Order not found/started");
log.error("3rdpty order[{}] not found", startChargeSeq);
return response;
}
equipChargeStatus.setStartChargeSeqStat(startChargeSeqStat);
//充电设备接口编码
String connectorId = internalOrderNum.substring(0, 16);
equipChargeStatus.setConnectorID(connectorId);
//充电设备接口状态
Map<String, Object> cacheGunData = REDIS.getCacheMap("gun:" + connectorId);
String gunStatus = (String) cacheGunData.get("status");
int connectorStatus = 0;
switch (gunStatus) {
case "空闲":
connectorStatus = 1;
break;
case "离线":
connectorStatus = 2;
break;
case "故障":
connectorStatus = 255;
break;
default:
connectorStatus = 3;
break;
}
equipChargeStatus.setConnectorStatus(connectorStatus);
//A相电流
Double current = (Double) cacheGunData.get("current");
equipChargeStatus.setCurrentA(current);
//A相电压
Double voltage = (Double) cacheGunData.get("voltage");
equipChargeStatus.setVoltageA(voltage);
//电池剩余电量
Integer endSoc = (Integer) cacheOrder.get("endSoc");
Double soc = Double.valueOf(endSoc == null ? 0 : endSoc);
equipChargeStatus.setSoc(soc);
//开始充电时间
String startTime = (String) cacheOrder.get("startTime");
if (startTime == null) startTime = orderNo2DateStr(internalOrderNum);
equipChargeStatus.setStartTime(startTime);
//本次采样时间 直接new一个当前时间的Date就可以了
CacheRealtimeData lord = REDIS.getCacheObject("order:" + internalOrderNum + ".lord");
if (lord != null) {
equipChargeStatus.setEndTime(lord.getCreateTime());
equipChargeStatus.setTotalMoney(lord.getAmountCharged() / 10000.0);
equipChargeStatus.setTotalPower(lord.getChargingDegree() / 10000.0);
String internalOrderNum = etOrderMapping.getXhOrderNo();
Map<String, Object> cacheOrder = REDIS.getCacheMap("order:" + internalOrderNum);
if (cacheOrder == null) {
response.setRet(EvcsConst.RET_FAIL);
response.setMsg("Order cache data not found");
} else {
equipChargeStatus.setEndTime(equipChargeStatus.getStartTime());
equipChargeStatus.setTotalMoney(0.0);
equipChargeStatus.setTotalPower(0.0);
String orderStatus = (String) cacheOrder.get("status");
int startChargeSeqStat;
if (orderStatus == null) {
startChargeSeqStat = 5;
} else switch (orderStatus) {
case "启动中":
startChargeSeqStat = 1;
break;
case "充电中":
startChargeSeqStat = 2;
break;
case "停止中":
startChargeSeqStat = 3;
break;
case "已结束":
startChargeSeqStat = 4;
break;
default:
startChargeSeqStat = 5;
break;
}
equipChargeStatus.setStartChargeSeqStat(startChargeSeqStat);
//充电设备接口编码
String connectorId = internalOrderNum.substring(0, 16);
equipChargeStatus.setConnectorID(connectorId);
//充电设备接口状态
Map<String, Object> cacheGunData = REDIS.getCacheMap("gun:" + connectorId);
String gunStatus = (String) cacheGunData.get("status");
int connectorStatus = 0;
switch (gunStatus) {
case "空闲":
connectorStatus = 1;
break;
case "离线":
connectorStatus = 2;
break;
case "故障":
connectorStatus = 255;
break;
default:
connectorStatus = 3;
break;
}
equipChargeStatus.setConnectorStatus(connectorStatus);
//A相电流
Double current = (Double) cacheGunData.get("current");
equipChargeStatus.setCurrentA(current);
//A相电压
Double voltage = (Double) cacheGunData.get("voltage");
equipChargeStatus.setVoltageA(voltage);
//电池剩余电量
Integer endSoc = (Integer) cacheOrder.get("endSoc");
Double soc = Double.valueOf(endSoc == null ? 0 : endSoc);
equipChargeStatus.setSoc(soc);
//开始充电时间
String startTime = (String) cacheOrder.get("startTime");
if (startTime == null) startTime = orderNo2DateStr(internalOrderNum);
equipChargeStatus.setStartTime(startTime);
//本次采样时间 直接new一个当前时间的Date就可以了
CacheRealtimeData lord = REDIS.getCacheObject("order:" + internalOrderNum + ".lord");
if (lord != null) {
equipChargeStatus.setEndTime(lord.getCreateTime());
equipChargeStatus.setTotalMoney(lord.getAmountCharged() / 10000.0);
equipChargeStatus.setTotalPower(lord.getChargingDegree() / 10000.0);
} else {
equipChargeStatus.setEndTime(equipChargeStatus.getStartTime());
equipChargeStatus.setTotalMoney(0.0);
equipChargeStatus.setTotalPower(0.0);
}
Integer chargeModel = (Integer) cacheOrder.get("chargeModel");
equipChargeStatus.setChargeModel(chargeModel == null ? 0 : chargeModel);
final Long rateModelId = REDIS.getCacheMapValue("pile:".concat(connectorId.substring(0, 14)), "rateModelId");
final CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:" + rateModelId);
calculateEm(equipChargeStatus, cacheRateModel);
response.setRet(EvcsConst.RET_SUCC);
response.setData(JSONUtil.toJSONString(equipChargeStatus));
response.setMsg("success");
}
Integer chargeModel = (Integer) cacheOrder.get("chargeModel");
equipChargeStatus.setChargeModel(chargeModel == null ? 0 : chargeModel);
final Long rateModelId = REDIS.getCacheMapValue("pile:".concat(connectorId.substring(0, 14)), "rateModelId");
final CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:" + rateModelId);
calculateEm(equipChargeStatus, cacheRateModel);
response.setRet(EvcsConst.RET_SUCC);
response.setData(JSONUtil.toJSONString(equipChargeStatus));
response.setMsg("success");
}
return response;
}

View File

@ -45,70 +45,72 @@ public class QueryStartChargeController {
CommonResponse resp = new CommonResponse();
resp.setRet(EvcsConst.RET_FAIL);
StartChargeResponse startChargeResponse = new StartChargeResponse();
startChargeResponse.setFailReason(0);
startChargeResponse.setSuccStat(1);
startChargeResponse.setStartChargeSeqStat(4);
StartChargeRequest startChargeRequest = JSONUtil.readParams(commonRequest.getData(), StartChargeRequest.class);
String startChargeSeq = startChargeRequest.getStartChargeSeq();
String connectorId = startChargeRequest.getConnectorId();
Map<String, Object> cacheGun = REDIS.getCacheMap("gun:".concat(connectorId));
String terminalStatus = (String) cacheGun.get("vehicleGunStatus");
String status = (String) cacheGun.get("status");
EtOrderMapping etOrderMapping = new EtOrderMapping();
Date now = DateUtils.getNowDate();
etOrderMapping.setCreateTime(now);
etOrderMapping.setEvcsOrderNo(startChargeSeq);
if (!"空闲".equals(status)) {
resp.setMsg("终端状态异常:[".concat(status == null ? "未注册" : status).concat("]"));
resp.setRet("500");
emptyHorder(startChargeSeq, connectorId, etOrderMapping);
} else if ("".equals(terminalStatus)) {
resp.setMsg("未插枪");
resp.setRet("500");
emptyHorder(startChargeSeq, connectorId, etOrderMapping);
if (startChargeRequest == null) {
resp.setMsg("Request or token params validation failed");
} else {
String plateNum = startChargeRequest.getPlateNum();
plateNum = plateNum == null ? startChargeRequest.getPlateNum2() : plateNum;
R res = pileOrderService.pileStartUpBy3rd(startChargeSeq, startChargeRequest.getDriverId(),
startChargeRequest.getChargingAmt(), plateNum, -1, connectorId);
startChargeResponse.setStartChargeSeq(startChargeSeq);
startChargeResponse.setConnectorID(connectorId);
resp.setMsg(res.getMsg());
if (res.getCode() != 200) {
if (res.getCode() != 500) {
startChargeResponse.setFailReason(res.getCode());
} else {
startChargeResponse.setFailReason(3);
}
startChargeResponse.setSuccStat(1);
startChargeResponse.setStartChargeSeqStat(4);
StartChargeResponse startChargeResponse = new StartChargeResponse();
startChargeResponse.setFailReason(0);
startChargeResponse.setSuccStat(1);
startChargeResponse.setStartChargeSeqStat(4);
String startChargeSeq = startChargeRequest.getStartChargeSeq();
String connectorId = startChargeRequest.getConnectorId();
Map<String, Object> cacheGun = REDIS.getCacheMap("gun:".concat(connectorId));
String terminalStatus = (String) cacheGun.get("vehicleGunStatus");
String status = (String) cacheGun.get("status");
EtOrderMapping etOrderMapping = new EtOrderMapping();
Date now = DateUtils.getNowDate();
etOrderMapping.setCreateTime(now);
etOrderMapping.setEvcsOrderNo(startChargeSeq);
if (!"空闲".equals(status)) {
resp.setMsg("终端状态异常:[".concat(status == null ? "未注册" : status).concat("]"));
emptyHorder(startChargeSeq, connectorId, etOrderMapping);
} else if ("".equals(terminalStatus)) {
resp.setMsg("未插枪");
emptyHorder(startChargeSeq, connectorId, etOrderMapping);
} else {
Map<String, Object> etOrderData = (Map<String, Object>) res.getData();
if (etOrderData != null) {
resp.setRet(EvcsConst.RET_SUCC);
startChargeResponse.setStartChargeSeqStat(1);
startChargeResponse.setSuccStat(0);
startChargeResponse.setFailReason(0);
Map<String, Object> pushOrder = new HashMap<>();
pushOrder.put("startChargeSeqStat", 1);
pushOrder.put("internetSerialNumber", startChargeRequest.getStartChargeSeq());
pushOrder.put("connectorID", connectorId);
pushOrder.put("startChargeNotificationStat", 0);
pushOrder.put("chargeOrderInfoNotificationStat", 0);
pushOrder.put("operatorId3rdpty", startChargeSeq.substring(0, 9));
pushOrder.put("startTime", etOrderData.get("startTime"));
String orderNo = (String) etOrderData.get("orderNo");
etOrderMapping.setXhOrderNo(orderNo);
REDIS.setCacheMap("pushOrder:".concat(orderNo), pushOrder);
} else {
String plateNum = startChargeRequest.getPlateNum();
plateNum = plateNum == null ? startChargeRequest.getPlateNum2() : plateNum;
R res = pileOrderService.pileStartUpBy3rd(startChargeSeq, startChargeRequest.getDriverId(),
startChargeRequest.getChargingAmt(), plateNum, -1, connectorId);
startChargeResponse.setStartChargeSeq(startChargeSeq);
startChargeResponse.setConnectorID(connectorId);
resp.setMsg(res.getMsg());
if (res.getCode() != 200) {
if (res.getCode() != 500) {
startChargeResponse.setFailReason(res.getCode());
} else {
startChargeResponse.setFailReason(3);
}
startChargeResponse.setSuccStat(1);
startChargeResponse.setStartChargeSeqStat(4);
emptyHorder(startChargeSeq, connectorId, etOrderMapping);
} else {
Map<String, Object> etOrderData = (Map<String, Object>) res.getData();
if (etOrderData != null) {
resp.setRet(EvcsConst.RET_SUCC);
startChargeResponse.setStartChargeSeqStat(1);
startChargeResponse.setSuccStat(0);
startChargeResponse.setFailReason(0);
Map<String, Object> pushOrder = new HashMap<>();
pushOrder.put("startChargeSeqStat", 1);
pushOrder.put("internetSerialNumber", startChargeRequest.getStartChargeSeq());
pushOrder.put("connectorID", connectorId);
pushOrder.put("startChargeNotificationStat", 0);
pushOrder.put("chargeOrderInfoNotificationStat", 0);
pushOrder.put("operatorId3rdpty", startChargeSeq.substring(0, 9));
pushOrder.put("startTime", etOrderData.get("startTime"));
String orderNo = (String) etOrderData.get("orderNo");
etOrderMapping.setXhOrderNo(orderNo);
REDIS.setCacheMap("pushOrder:".concat(orderNo), pushOrder);
} else {
emptyHorder(startChargeSeq, connectorId, etOrderMapping);
}
}
}
etOrderMappingRepo.save(etOrderMapping);
resp.setData(JSONUtil.toJSONString(startChargeResponse));
}
etOrderMappingRepo.save(etOrderMapping);
resp.setData(JSONUtil.toJSONString(startChargeResponse));
return resp;
}

View File

@ -2,6 +2,7 @@ package com.xhpc.evcs.api;
import com.xhpc.common.api.dto.ChargingStationDto;
import com.xhpc.evcs.dto.*;
import com.xhpc.evcs.encryption.EvcsConst;
import com.xhpc.evcs.utils.JSONUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -19,68 +20,73 @@ public class QueryStationStatusController {
@PostMapping("/v1/query_station_status")
public CommonResponse queryStationsInfo(@RequestBody CommonRequest<StationStatusRequest> commonRequest) throws Exception {
CommonResponse resp = new CommonResponse();
resp.setRet(EvcsConst.RET_FAIL);
StationStatusRequest stationStatusRequest = JSONUtil.readParams(commonRequest.getData(), StationStatusRequest.class);
String[] stationIDs = stationStatusRequest.getStationIds();
List<StationStatusInfo> stationStatusInfos = new ArrayList<>();
//Loading data through redis at first.
Collection<String> guns = REDIS.keys("gun:*");
List<String> gunsNewList = new ArrayList<>();
for (String value : guns) {
gunsNewList.add(value.substring(4));
}
List<String> gunsIds = new ArrayList<>();
for (String value : gunsNewList) {
if (value.length() == 16) {
gunsIds.add(value);
if (stationStatusRequest == null) {
resp.setMsg("Request or token params validation failed");
} else {
String[] stationIDs = stationStatusRequest.getStationIds();
List<StationStatusInfo> stationStatusInfos = new ArrayList<>();
//Loading data through redis at first.
Collection<String> guns = REDIS.keys("gun:*");
List<String> gunsNewList = new ArrayList<>();
for (String value : guns) {
gunsNewList.add(value.substring(4));
}
}
Map<String, Integer> statusMap = new HashMap<>();
String[] keys = {"离线", "空闲", "故障"};
Integer[] values = {0, 1, 255};
for (int i = 0; i < keys.length; i++) {
statusMap.put(keys[i], values[i]);
}
for (String stationID : stationIDs) {
ChargingStationDto chargingStationDto = REDIS.getCacheObject("station:" + stationID);
Set<String> pileIds = new HashSet<>();
if (null != chargingStationDto) {
pileIds = chargingStationDto.getPiles();
}
boolean existsGun = false;
List<ConnectorStatusInfo> connectorStatusInfos = new ArrayList<>();
for (String pileId : pileIds) {
for (String value : gunsIds) {
if (pileId.equals(value.substring(0, 14))) {
existsGun = true;
ConnectorStatusInfo connectorStatusInfo = new ConnectorStatusInfo();
Object status = REDIS.getCacheMapValue("gun:" + value, "status");
if (isInteger(status.toString())) {
connectorStatusInfo.setStatus(3);
} else {
connectorStatusInfo.setStatus(statusMap.get(status));
}
connectorStatusInfo.setConnectorID(value);
connectorStatusInfos.add(connectorStatusInfo);
}
List<String> gunsIds = new ArrayList<>();
for (String value : gunsNewList) {
if (value.length() == 16) {
gunsIds.add(value);
}
}
if (existsGun) {
StationStatusInfo stationStatusInfo = new StationStatusInfo();
stationStatusInfo.setStationID(stationID);
stationStatusInfo.setConnectorStatusInfos(connectorStatusInfos);
stationStatusInfos.add(stationStatusInfo);
Map<String, Integer> statusMap = new HashMap<>();
String[] keys = {"离线", "空闲", "故障"};
Integer[] values = {0, 1, 255};
for (int i = 0; i < keys.length; i++) {
statusMap.put(keys[i], values[i]);
}
for (String stationID : stationIDs) {
ChargingStationDto chargingStationDto = REDIS.getCacheObject("station:" + stationID);
Set<String> pileIds = new HashSet<>();
if (null != chargingStationDto) {
pileIds = chargingStationDto.getPiles();
}
boolean existsGun = false;
List<ConnectorStatusInfo> connectorStatusInfos = new ArrayList<>();
for (String pileId : pileIds) {
for (String value : gunsIds) {
if (pileId.equals(value.substring(0, 14))) {
existsGun = true;
ConnectorStatusInfo connectorStatusInfo = new ConnectorStatusInfo();
Object status = REDIS.getCacheMapValue("gun:" + value, "status");
if (isInteger(status.toString())) {
connectorStatusInfo.setStatus(3);
} else {
connectorStatusInfo.setStatus(statusMap.get(status));
}
connectorStatusInfo.setConnectorID(value);
connectorStatusInfos.add(connectorStatusInfo);
}
}
}
if (existsGun) {
StationStatusInfo stationStatusInfo = new StationStatusInfo();
stationStatusInfo.setStationID(stationID);
stationStatusInfo.setConnectorStatusInfos(connectorStatusInfos);
stationStatusInfos.add(stationStatusInfo);
}
}
}
StationStatusInfoWrapper stationStatusInfoWrappers = new StationStatusInfoWrapper();
stationStatusInfoWrappers.setTotal(stationStatusInfos.size());
if (stationStatusInfos.size() != 0) {
stationStatusInfoWrappers.setStationStatusInfos(stationStatusInfos);
StationStatusInfoWrapper stationStatusInfoWrappers = new StationStatusInfoWrapper();
stationStatusInfoWrappers.setTotal(stationStatusInfos.size());
if (stationStatusInfos.size() != 0) {
stationStatusInfoWrappers.setStationStatusInfos(stationStatusInfos);
}
resp.setRet("0");
resp.setMsg("Query station status success");
resp.setData(JSONUtil.toJSONString(stationStatusInfoWrappers));
}
CommonResponse resp = new CommonResponse();
resp.setRet("0");
resp.setMsg("Query station status success");
resp.setData(JSONUtil.toJSONString(stationStatusInfoWrappers));
return resp;
}

View File

@ -9,6 +9,7 @@ import com.xhpc.evcs.dto.CommonRequest;
import com.xhpc.evcs.dto.CommonResponse;
import com.xhpc.evcs.dto.QueryStopChargeRequest;
import com.xhpc.evcs.dto.QueryStopChargeResponse;
import com.xhpc.evcs.encryption.EvcsConst;
import com.xhpc.evcs.jpa.OrderMappingRepository;
import com.xhpc.evcs.jpa.XhpcChargingPileRepository;
import com.xhpc.evcs.utils.JSONUtil;
@ -40,77 +41,82 @@ public class QueryStopChargeController {
@PostMapping("/v1/query_stop_charge")
public CommonResponse queryStopCharge(@RequestBody CommonRequest<QueryStopChargeRequest> commonRequest) throws IOException {
QueryStopChargeRequest queryStopChargeRequest = JSONUtil.readParams(commonRequest.getData(), QueryStopChargeRequest.class);
// evcs电订单号(27位)
String startChargeSeq = queryStopChargeRequest.getStartChargeSeq();
QueryStopChargeResponse queryStopChargeResponse = new QueryStopChargeResponse();
queryStopChargeResponse.setStartChargeSeq(startChargeSeq);
//判断三方的订单号是否存在
EtOrderMapping etOrderMapping = etOrderMappingRepo.findByEvcsOrderNo(startChargeSeq).orElse(null);
if (etOrderMapping == null) {
return failCommonResponse(queryStopChargeResponse, "错误的充电订单号");
}
String xhOrderNo = etOrderMapping.getXhOrderNo();
String pushOrderkey = "pushOrder:".concat(xhOrderNo);
Map<String, Object> pushOrder = REDIS.getCacheMap(pushOrderkey);
if (pushOrder == null || (pushOrder.get("isStopNotified") != null && (Boolean) pushOrder.get("isStopNotified"))) {
return failCommonResponse(queryStopChargeResponse, "已下发停止充电指令");
}
//充电设备接口编码枪编码
String connectorId = queryStopChargeRequest.getConnectorId();
String pileNum = connectorId.substring(0, connectorId.length() - 2);
//从数据库中查询对应的桩的版本信息
XhpcChargingPile pileInfo = XhpcChargingPileRepository.findBySerialNumber(pileNum).orElse(null);
String versionNum = pileInfo.getCommunicationProtocolVersion() != null ? pileInfo.getCommunicationProtocolVersion() :
"0A";
//给对应的枪发送停止充电指令
R r = powerPileService.stopCharging(xhOrderNo, pileNum, connectorId, versionNum);
// 判断停止指令发送是否成功
if (r.getCode() != 200) {
//向redis中放入停止充电指令没有下发成功的标识
REDIS.setCacheMap(pushOrderkey, pushOrder);
//充电订单状态
queryStopChargeResponse.setStartChargeSeqStat(5);
//操作结果
queryStopChargeResponse.setSuccStat(1);
//失败原因
String errorMsg = r.getMsg();
if (errorMsg.contains("未注册")) {
queryStopChargeResponse.setFailReason(1);
}
if (errorMsg.contains("离线")) {
queryStopChargeResponse.setFailReason(2);
}
if (errorMsg.contains("订单号")) {
//4 means error orderNumber
queryStopChargeResponse.setFailReason(4);
}
if (errorMsg.contains("端口")) {
//5 means port is not charging
queryStopChargeResponse.setFailReason(5);
}
queryStopChargeResponse.setStartChargeSeqStat(4);
queryStopChargeResponse.setSuccStat(1);
String data = JSONUtil.toJSONString(queryStopChargeResponse);
CommonResponse commonResponse = new CommonResponse();
commonResponse.setRet("1");
commonResponse.setMsg("请求停止充电失败");
commonResponse.setData(data);
return commonResponse;
}
//设置该订单已经被停止的标识
Map<String, Object> order = REDIS.getCacheMap("order:" + xhOrderNo);
order.replace("status", "已结束");
REDIS.setCacheMap("order:".concat(xhOrderNo), order);
REDIS.setCacheMap(pushOrderkey, pushOrder);
queryStopChargeResponse.setStartChargeSeqStat(3);
queryStopChargeResponse.setSuccStat(0);
queryStopChargeResponse.setFailReason(0);
String data = JSONUtil.toJSONString(queryStopChargeResponse);
CommonResponse commonResponse = new CommonResponse();
commonResponse.setRet("0");
commonResponse.setMsg("请求停止充电成功");
commonResponse.setData(data);
commonResponse.setRet(EvcsConst.RET_FAIL);
QueryStopChargeRequest queryStopChargeRequest = JSONUtil.readParams(commonRequest.getData(),
QueryStopChargeRequest.class);
if (queryStopChargeRequest == null) {
commonResponse.setMsg("Request or token params validation failed");
} else {
// evcs电订单号(27位)
String startChargeSeq = queryStopChargeRequest.getStartChargeSeq();
QueryStopChargeResponse queryStopChargeResponse = new QueryStopChargeResponse();
queryStopChargeResponse.setStartChargeSeq(startChargeSeq);
//判断三方的订单号是否存在
EtOrderMapping etOrderMapping = etOrderMappingRepo.findByEvcsOrderNo(startChargeSeq).orElse(null);
if (etOrderMapping == null) {
return failCommonResponse(queryStopChargeResponse, "错误的充电订单号");
}
String xhOrderNo = etOrderMapping.getXhOrderNo();
String pushOrderkey = "pushOrder:".concat(xhOrderNo);
Map<String, Object> pushOrder = REDIS.getCacheMap(pushOrderkey);
if (pushOrder == null || (pushOrder.get("isStopNotified") != null && (Boolean) pushOrder.get("isStopNotified"))) {
return failCommonResponse(queryStopChargeResponse, "已下发停止充电指令");
}
//充电设备接口编码枪编码
String connectorId = queryStopChargeRequest.getConnectorId();
String pileNum = connectorId.substring(0, connectorId.length() - 2);
//从数据库中查询对应的桩的版本信息
XhpcChargingPile pileInfo = XhpcChargingPileRepository.findBySerialNumber(pileNum).orElse(null);
String versionNum = pileInfo.getCommunicationProtocolVersion() != null ?
pileInfo.getCommunicationProtocolVersion() :
"0A";
//给对应的枪发送停止充电指令
R r = powerPileService.stopCharging(xhOrderNo, pileNum, connectorId, versionNum);
// 判断停止指令发送是否成功
if (r.getCode() != 200) {
//向redis中放入停止充电指令没有下发成功的标识
REDIS.setCacheMap(pushOrderkey, pushOrder);
//充电订单状态
queryStopChargeResponse.setStartChargeSeqStat(5);
//操作结果
queryStopChargeResponse.setSuccStat(1);
//失败原因
String errorMsg = r.getMsg();
if (errorMsg.contains("未注册")) {
queryStopChargeResponse.setFailReason(1);
}
if (errorMsg.contains("离线")) {
queryStopChargeResponse.setFailReason(2);
}
if (errorMsg.contains("订单号")) {
//4 means error orderNumber
queryStopChargeResponse.setFailReason(4);
}
if (errorMsg.contains("端口")) {
//5 means port is not charging
queryStopChargeResponse.setFailReason(5);
}
queryStopChargeResponse.setStartChargeSeqStat(4);
queryStopChargeResponse.setSuccStat(1);
String data = JSONUtil.toJSONString(queryStopChargeResponse);
commonResponse.setMsg("请求停止充电失败");
commonResponse.setData(data);
return commonResponse;
}
//设置该订单已经被停止的标识
Map<String, Object> order = REDIS.getCacheMap("order:" + xhOrderNo);
order.replace("status", "已结束");
REDIS.setCacheMap("order:".concat(xhOrderNo), order);
REDIS.setCacheMap(pushOrderkey, pushOrder);
queryStopChargeResponse.setStartChargeSeqStat(3);
queryStopChargeResponse.setSuccStat(0);
queryStopChargeResponse.setFailReason(0);
String data = JSONUtil.toJSONString(queryStopChargeResponse);
commonResponse.setRet("0");
commonResponse.setMsg("请求停止充电成功");
commonResponse.setData(data);
}
return commonResponse;
}
@ -121,7 +127,7 @@ public class QueryStopChargeController {
queryStopChargeResponse.setFailReason(0);
String data = JSONUtil.toJSONString(queryStopChargeResponse);
CommonResponse commonResponse = new CommonResponse();
commonResponse.setRet("0");
commonResponse.setRet("500");
commonResponse.setMsg(msg);
commonResponse.setData(data);
return commonResponse;

View File

@ -22,18 +22,23 @@ public class QueryTerminalCodeController {
public CommonResponse queryTerminalCode(@RequestBody CommonRequest<QueryTerminalCodeRequest> commonRequest) throws IOException {
CommonResponse resp = new CommonResponse();
QueryTerminalCodeResponse queryTerminalCodeResponse = new QueryTerminalCodeResponse();
QueryTerminalCodeRequest queryTerminalCodeRequest = JSONUtil.readParams(commonRequest.getData(), QueryTerminalCodeRequest.class);
resp.setRet(EvcsConst.RET_FAIL);
resp.setMsg("fail");
if (null != queryTerminalCodeRequest) {
QueryTerminalCodeRequest queryTerminalCodeRequest = JSONUtil.readParams(commonRequest.getData(),
QueryTerminalCodeRequest.class);
if (queryTerminalCodeRequest == null) {
resp.setMsg("Request or token params validation failed");
} else {
resp.setMsg("Please check the qrcode format");
QueryTerminalCodeResponse queryTerminalCodeResponse = new QueryTerminalCodeResponse();
String qRCode = queryTerminalCodeRequest.getQRCode();
if (null != qRCode) {
resp.setRet(EvcsConst.RET_SUCC);
resp.setMsg("success");
String terminalCode = qRCode.split("=")[1];
queryTerminalCodeResponse.setTerminalCode(terminalCode);
resp.setData(JSONUtil.toJSONString(queryTerminalCodeResponse));
String[] terminalId = qRCode.split("=");
if (terminalId.length == 2) {
resp.setRet(EvcsConst.RET_SUCC);
resp.setMsg("success");
queryTerminalCodeResponse.setTerminalCode(terminalId[1]);
resp.setData(JSONUtil.toJSONString(queryTerminalCodeResponse));
}
}
}
return resp;

View File

@ -5,6 +5,7 @@ import com.xhpc.evcs.domain.XhpcInternetUser;
import com.xhpc.evcs.dto.CommonResponse;
import com.xhpc.evcs.dto.TokenRequest;
import com.xhpc.evcs.dto.TokenResponse;
import com.xhpc.evcs.encryption.EvcsConst;
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
import com.xhpc.evcs.jpa.XhpcInternetUserRepository;
import com.xhpc.evcs.utils.JSONUtil;
@ -24,6 +25,8 @@ import java.util.Calendar;
import java.util.Date;
import java.util.UUID;
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
@Slf4j
@RestController()
public class QueryTokenController {
@ -39,59 +42,54 @@ public class QueryTokenController {
log.debug("<<query token request body: " + tokenRequest);
CommonResponse resp = new CommonResponse();
resp.setRet("0");
resp.setMsg("");
resp.setRet(EvcsConst.RET_FAIL);
String operatorID = tokenRequest.getOperatorId();
if (operatorID == null) {
String decodedData = (String) tokenRequest.getAdditionalProperties().get("Data");
try {
tokenRequest = JSONUtil.readParams(decodedData, TokenRequest.class);
} catch (Exception e) {
log.error("invalid Data string: {}", decodedData);
}
tokenRequest = JSONUtil.readParams(decodedData, TokenRequest.class);
}
operatorID = tokenRequest.getOperatorId();
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setOperatorId("MA6DFCTD5");
tokenResponse.setSuccStat(0);
tokenResponse.setFailReason(0);
String data = null; //todo 优化OperatorIdEvcs like
XhpcInternetUser xhpcInternetUser =
xhpcInternetUserRepository.findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(tokenRequest.getOperatorId(), Instant.now(), Instant.now());
if (xhpcInternetUser != null) {
String operatorSecret = tokenRequest.getOperatorSecret();
if (operatorSecret == null) {
operatorSecret = tokenRequest.getOperatorSecret();
}
AuthSecretToken authSecretTokenIn =
authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenTypeAndOperatorSecret(
operatorID, AuthSecretToken.SECRET_TOKEN_TYPE_IN, operatorSecret).orElse(null);
if (authSecretTokenIn == null) {
resp.setRet("4003");
resp.setMsg("Invalid OperatorID/Secret");
tokenResponse.setSuccStat(1);
tokenResponse.setFailReason(2);
resp.setData(data);
} else {
String token;
if (authSecretTokenIn.getTokenExpiry() != null && !authSecretTokenIn.getTokenExpiry().before(Calendar.getInstance().getTime())) {
token = authSecretTokenIn.getToken();
} else {
token = UUID.randomUUID().toString().replaceAll("-", "");
authSecretTokenIn.setToken(token);
authSecretTokenIn.setTokenExpiry(getTokenExpiry(xhpcInternetUser));
authSecretTokenRepository.save(authSecretTokenIn);
}
tokenResponse.setAccessToken(token);
Instant te = authSecretTokenIn.getTokenExpiry().toInstant();
tokenResponse.setTokenAvailableTime(Long.valueOf(ChronoUnit.SECONDS.between(Instant.now(), te)).intValue());
tokenResponse.setSuccStat(0);
tokenResponse.setFailReason(0);
resp.setMsg("Query token success");
resp.setData(JSONUtil.toJSONString(tokenResponse));
}
if (tokenRequest == null) {
resp.setMsg("Request params validation failed");
} else {
resp.setMsg("Cooperation settings or start time not valid");
operatorID = tokenRequest.getOperatorId();
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setOperatorId(REDIS.getCacheObject("global:EVCS_OPID"));
tokenResponse.setSuccStat(0);
tokenResponse.setFailReason(0);
XhpcInternetUser xhpcInternetUser =
xhpcInternetUserRepository.findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(tokenRequest.getOperatorId(), Instant.now(), Instant.now());
if (xhpcInternetUser != null) {
String operatorSecret = tokenRequest.getOperatorSecret();
AuthSecretToken authSecretTokenIn =
authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenTypeAndOperatorSecret(
operatorID, AuthSecretToken.SECRET_TOKEN_TYPE_IN, operatorSecret).orElse(null);
if (authSecretTokenIn == null) {
resp.setRet("4003");
resp.setMsg("Invalid OperatorID/Secret");
tokenResponse.setSuccStat(1);
tokenResponse.setFailReason(2);
} else {
String token;
if (authSecretTokenIn.getTokenExpiry() != null && !authSecretTokenIn.getTokenExpiry().before(Calendar.getInstance().getTime())) {
token = authSecretTokenIn.getToken();
} else {
token = UUID.randomUUID().toString().replaceAll("-", "");
authSecretTokenIn.setToken(token);
authSecretTokenIn.setTokenExpiry(getTokenExpiry(xhpcInternetUser));
authSecretTokenRepository.save(authSecretTokenIn);
}
tokenResponse.setAccessToken(token);
Instant te = authSecretTokenIn.getTokenExpiry().toInstant();
tokenResponse.setTokenAvailableTime(Long.valueOf(ChronoUnit.SECONDS.between(Instant.now(), te)).intValue());
tokenResponse.setSuccStat(0);
tokenResponse.setFailReason(0);
resp.setRet(EvcsConst.RET_SUCC);
resp.setMsg("Query token success");
resp.setData(JSONUtil.toJSONString(tokenResponse));
}
} else {
resp.setMsg("Cooperation settings or start time are not valid");
}
}
return resp;
}

View File

@ -12,6 +12,7 @@ import com.xhpc.evcs.domain.AuthSecretToken;
import com.xhpc.evcs.dto.CommonRequest;
import com.xhpc.evcs.dto.CommonResponse;
import com.xhpc.evcs.encryption.Aes128Cbc;
import com.xhpc.evcs.encryption.EvcsConst;
import com.xhpc.evcs.encryption.HMAC;
import com.xhpc.evcs.http.HttpServletRequestRepeatReadWrapper;
import com.xhpc.evcs.http.HttpServletRequestWritableWrapper;
@ -75,109 +76,119 @@ public class EvcsFilter extends OncePerRequestFilter {
String servletPath = request.getServletPath();
log.debug("servletPath: " + servletPath);
CommonRequest commonRequest = JSONUtil.readParams(bodyString, CommonRequest.class);
String operatorId = commonRequest.getOperatorId();
String authorization = request.getHeader("Authorization");
log.debug("Authorization: {}", authorization);
AuthSecretToken authSecretTokenIn = null;
Date now = Calendar.getInstance().getTime();
resp.setRet(EvcsConst.RET_FAIL);
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
if (servletPath.endsWith("query_token")) {
authSecretTokenIn = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId,
AuthSecretToken.SECRET_TOKEN_TYPE_IN).orElse(null);
handleQueryToken(request, response, chain, requestWrapper, bodyString, commonRequest, operatorId,
responseWrapper, authSecretTokenIn);
if (commonRequest == null) {
resp.setMsg("Request params validation failed");
resp.setRet("4004");
String data = JSONUtil.toJSONString(resp);
response.getOutputStream().write(data.getBytes(StandardCharsets.UTF_8));
chain.doFilter(requestWrapper, responseWrapper);
return;
} else {
if (authorization != null && authorization.startsWith("Bearer ")) {
String token = authorization.replace("Bearer ", "");
authSecretTokenIn =
authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenTypeAndTokenExpiryGreaterThan(
operatorId, AuthSecretToken.SECRET_TOKEN_TYPE_IN, now).orElse(null);
if (authSecretTokenIn == null) {
String operatorId = commonRequest.getOperatorId();
String authorization = request.getHeader("Authorization");
log.debug("Authorization: {}", authorization);
AuthSecretToken authSecretTokenIn = null;
Date now = Calendar.getInstance().getTime();
if (servletPath.endsWith("query_token")) {
authSecretTokenIn = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId,
AuthSecretToken.SECRET_TOKEN_TYPE_IN).orElse(null);
handleQueryToken(request, response, chain, requestWrapper, bodyString, commonRequest, operatorId,
responseWrapper, authSecretTokenIn);
} else {
if (authorization != null && authorization.startsWith("Bearer ")) {
String token = authorization.replace("Bearer ", "");
authSecretTokenIn =
authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenTypeAndTokenExpiryGreaterThan(
operatorId, AuthSecretToken.SECRET_TOKEN_TYPE_IN, now).orElse(null);
if (authSecretTokenIn == null) {
resp.setRet("4002");
resp.setMsg("Invalid token(db)");
String data = JSONUtil.toJSONString(resp);
response.getOutputStream().write(data.getBytes(StandardCharsets.UTF_8));
responseWrapper = new ContentCachingResponseWrapper(response);
chain.doFilter(requestWrapper, responseWrapper);
return;
} else if (!token.equals(authSecretTokenIn.getToken())) {
log.error("op[{}] Invalid auth: {}", operatorId, authorization);
resp.setRet("4002"); // todo YBD...
resp.setMsg("Invalid token(inequal)");
String data = JSONUtil.toJSONString(resp);
response.getOutputStream().write(data.getBytes(StandardCharsets.UTF_8));
// responseWrapper = new ContentCachingResponseWrapper(response);
// chain.doFilter(requestWrapper, responseWrapper);
return;
}
} else {
log.error("op[{}] Invalid auth: {}", operatorId, authorization);
resp.setRet("4002");
resp.setMsg("Invalid token(db)");
resp.setMsg("Authorization header is not present or invalid");
String data = JSONUtil.toJSONString(resp);
response.getOutputStream().write(data.getBytes(StandardCharsets.UTF_8));
responseWrapper = new ContentCachingResponseWrapper(response);
chain.doFilter(requestWrapper, responseWrapper);
return;
} else if (!token.equals(authSecretTokenIn.getToken())) {
log.error("op[{}] Invalid auth: {}", operatorId, authorization);
resp.setRet("4002"); // todo YBD...
resp.setMsg("Invalid token(inequal)");
String data = JSONUtil.toJSONString(resp);
response.getOutputStream().write(data.getBytes(StandardCharsets.UTF_8));
// responseWrapper = new ContentCachingResponseWrapper(response);
// chain.doFilter(requestWrapper, responseWrapper);
return;
}
} else {
log.error("op[{}] Invalid auth: {}", operatorId, authorization);
resp.setRet("4002");
resp.setMsg("Authorization header is not present or invalid");
String data = JSONUtil.toJSONString(resp);
response.getOutputStream().write(data.getBytes(StandardCharsets.UTF_8));
responseWrapper = new ContentCachingResponseWrapper(response);
chain.doFilter(requestWrapper, responseWrapper);
return;
}
//decrypt request
byte[] decryptedReq = null;
String erroMsg = "Decryption error";
try {
//decrypt request
byte[] decryptedReq = null;
String erroMsg = "Decryption error";
try {
// if (authSecretTokenIn.isEncrypt() && !"false".equals(encin)) { // test code
decryptedReq = decrypt(request, authSecretTokenIn, commonRequest, bodyString);
decryptedReq = decrypt(request, authSecretTokenIn, commonRequest, bodyString);
// } else {
// String data = commonRequest.getData();
// if (data == null) data = bodyString;
// decryptedReq = data.getBytes(StandardCharsets.UTF_8);
// }
commonRequest.setData(new String(decryptedReq));
log.debug("in.dec: {}", commonRequest);
} catch (BadPaddingException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | IllegalBlockSizeException | NoSuchPaddingException | InvalidKeyException e) {
erroMsg = e.getMessage();
commonRequest.setData(new String(decryptedReq));
log.debug("in.dec: {}", commonRequest);
} catch (BadPaddingException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | IllegalBlockSizeException | NoSuchPaddingException | InvalidKeyException e) {
erroMsg = e.getMessage();
}
if (decryptedReq != null && decryptedReq.length > 0) {
requestWrapper = new HttpServletRequestWritableWrapper(request,
JSONUtil.toJSONString(commonRequest).getBytes(StandardCharsets.UTF_8));
} else {
resp.setRet("4004");
resp.setMsg(erroMsg);
String data = JSONUtil.toJSONString(resp);
response.getOutputStream().write(data.getBytes(StandardCharsets.UTF_8));
chain.doFilter(requestWrapper, responseWrapper);
return;
}
}
if (decryptedReq != null && decryptedReq.length > 0) {
requestWrapper = new HttpServletRequestWritableWrapper(request,
JSONUtil.toJSONString(commonRequest).getBytes(StandardCharsets.UTF_8));
} else {
resp.setRet("4004");
resp.setMsg(erroMsg);
String data = JSONUtil.toJSONString(resp);
response.getOutputStream().write(data.getBytes(StandardCharsets.UTF_8));
chain.doFilter(requestWrapper, responseWrapper);
return;
}
}
//encrypt response
final String encout = request.getHeader("enc.out");
//encrypt response
final String encout = request.getHeader("enc.out");
// if (requestWrapper == null) {
// chain.doFilter(request, responseWrapper);
// } else {
chain.doFilter(requestWrapper, responseWrapper);
chain.doFilter(requestWrapper, responseWrapper);
// }
// responseWrapper.copyBodyToResponse();
// responseWrapper = new ContentCachingResponseWrapper(responseWrapper);
byte[] buf = responseWrapper.getContentAsByteArray();
log.debug("out.plain: {}", new String(buf, StandardCharsets.UTF_8));
String encryptedData;
byte[] buf = responseWrapper.getContentAsByteArray();
log.debug("out.plain: {}", new String(buf, StandardCharsets.UTF_8));
String encryptedData;
// AuthSecretToken authSecretTokenOut = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType
// (operatorId,
// AuthSecretToken.SECRET_TOKEN_TYPE_OUT).orElse(null);
if (encout == null) {
encryptedData = encryptRespOut(authSecretTokenIn.getDataSecret(), authSecretTokenIn.getDataSecretIV(),
authSecretTokenIn.getSigSecret(), buf).toString();
log.debug("out.enc: {}", encryptedData);
response.getOutputStream().write(encryptedData == null ? internalError() :
encryptedData.getBytes(StandardCharsets.UTF_8));
} else if ("false".equals(encout)) {
response.getOutputStream().write(buf);
if (encout == null) {
encryptedData = encryptRespOut(authSecretTokenIn.getDataSecret(), authSecretTokenIn.getDataSecretIV(),
authSecretTokenIn.getSigSecret(), buf).toString();
log.debug("out.enc: {}", encryptedData);
response.getOutputStream().write(encryptedData == null ? internalError() :
encryptedData.getBytes(StandardCharsets.UTF_8));
} else if ("false".equals(encout)) {
response.getOutputStream().write(buf);
// } else {
// resp.setRet("4004");
// resp.setMsg("Encryption error");
// String data = JSONUtil.toJSONString(resp);
// response.getOutputStream().write(data.getBytes(StandardCharsets.UTF_8));
//// chain.doFilter(requestWrapper, responseWrapper);
}
}
}
}

View File

@ -105,7 +105,7 @@ public class CheckChargeOrders extends CoreDispatcher {
//推送并处理推送结果
String result = ok(commonRequest, "/check_charge_orders", authSecretTokenOut);
CheckChargeOrderResponseData checkChargeOrderResponseData = JSONUtil.readParams(result,
CheckChargeOrderResponseData.class);
CheckChargeOrderResponseData.class); //todo check NPE
if (checkChargeOrderResponseData.getDisputeOrders() == null) {
//没有争议订单
REDIS.deleteObject(pushOrderKey);

View File

@ -1,180 +0,0 @@
package com.xhpc.evcs.notification;
import com.xhpc.common.data.redis.CacheOrderData;
import com.xhpc.common.redis.service.RedisService;
import com.xhpc.evcs.domain.AuthSecretToken;
import com.xhpc.evcs.domain.XhpcRate;
import com.xhpc.evcs.dto.ChargeOrderInfo;
import com.xhpc.evcs.dto.ChargeOrderInfoResponse;
import com.xhpc.evcs.dto.CommonRequest;
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
import com.xhpc.evcs.jpa.XhpcRateRepository;
import com.xhpc.evcs.utils.JSONUtil;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
import static com.xhpc.evcs.domain.AuthSecretToken.SECRET_TOKEN_TYPE_OUT;
/**
* 用于进行充电历史订单的推送
*
* @author WH
* @date 2021/11/7 14:39
* @since version-1.0
*/
public class NotificationChargeOrderInfo extends CoreDispatcher {
@Autowired
private RedisService redisService;
@Autowired
private AuthSecretTokenRepository authSecretTokenRepository;
@Autowired
private XhpcRateRepository xhpcRateRepository;
public static void main(String[] args) {
}
public void pushChargeOrderInfo() throws IOException {
//获取Redis中的所有订单的状态数据
Collection<String> pushOrders = REDIS.keys("pushOrder:*");
for (String pushOrderKey : pushOrders) {
Map<String, Object> pushOrder = REDIS.getCacheMap(pushOrderKey);
Boolean isStopNotified = (Boolean) pushOrder.get("isStopNotified");
if (isStopNotified) {
continue;
}
String orderNo = pushOrderKey.substring(10);
Map<String, Object> order = REDIS.getCacheMap("order:" + orderNo);
String operatorId3rdpty = (String) pushOrder.get("operatorId3rdpty");
if (operatorId3rdpty == null) {
continue;
}
AuthSecretToken authSecretTokenOut =
authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId3rdpty,
SECRET_TOKEN_TYPE_OUT).orElse(null);
if (authSecretTokenOut == null) {
continue;
}
CommonRequest<ChargeOrderInfo> commonRequest = new CommonRequest<>();
//封装数据的实体类
ChargeOrderInfo chargeOrderInfo = new ChargeOrderInfo();
//判断是否是结束了的充电订单
if (isStopNotified) {
//充电订单号内部对应的第三方充电订单号
CacheOrderData orderData = (CacheOrderData) order.get("orderData");
String internetSerialNumber = (String) pushOrder.get("internetSerialNumber");
chargeOrderInfo.setStartChargeSeq(internetSerialNumber);
if (orderData != null) {
//使用指定包装类封装数据
//充电设备接口编码
chargeOrderInfo.setConnectorID(orderData.getPileNo() + orderData.getGunId());
//开始充电时间
chargeOrderInfo.setStartTime(orderData.getStartTime());
//结束充电时间
chargeOrderInfo.setEndTime(orderData.getEndTime());
//累计充电量
chargeOrderInfo.setTotalPower(Double.parseDouble(orderData.getTotalPowerQuantity().toString()) / 10000);
//总电费
Map<String, Double> map = getTotalElecMoneyAndTotalServiceMoney(orderNo);
Double totalPowerPrice = map.get("totalPowerPrice");
chargeOrderInfo.setTotalPower(totalPowerPrice);
//总服务费
Double totalServicePrice = map.get("totalServicePrice");
chargeOrderInfo.setTotalSeviceMoney(totalServicePrice);
//累计总金额
Double sumMoney = totalPowerPrice + totalServicePrice;
chargeOrderInfo.setTotalMoney(sumMoney);
//充电结束原因
chargeOrderInfo.setStopReason(0);
//将其转换为json
String jsonData = JSONUtil.toJSONString(chargeOrderInfo);
commonRequest.setData(jsonData);
String result = ok(commonRequest, "/notification_charge_order_info", authSecretTokenOut);
ChargeOrderInfoResponse chargeOrderInfoResponse = JSONUtil.readParams(result, ChargeOrderInfoResponse.class);
Integer confirmResult = chargeOrderInfoResponse.getConfirmResult();
//无视争议订单对结果不进行处理在下面的推送中在进行处理
}
}
}
}
private Map<String, Double> getTotalElecMoneyAndTotalServiceMoney(String orderNo) {
//获取结算后的订单
Map<String, Object> cacheMap = redisService.getCacheMap("order:" + orderNo);
CacheOrderData cacheOrderData = (CacheOrderData) cacheMap.get("orderData");
//总金额
BigDecimal bigDecimal = new BigDecimal(10000);
BigDecimal money = new BigDecimal(cacheOrderData.getCost()).divide(bigDecimal);
//00: 尖费率 01: 峰费率 02: 平费率 03: 谷费率
BigDecimal t1powerFee = new BigDecimal(0);
BigDecimal t2powerFee = new BigDecimal(0);
BigDecimal t3powerFee = new BigDecimal(0);
BigDecimal t4powerFee = new BigDecimal(0);
//费率计费模型
Long rateModelId = (Long) cacheMap.get("rateModelId");
List<XhpcRate> rateModelList = xhpcRateRepository.findByRateModelId(rateModelId);
for (XhpcRate xhpcRate : rateModelList) {
if ("00".equals(xhpcRate.getRateValue())) {
t1powerFee = xhpcRate.getPowerFee();
}
if ("01".equals(xhpcRate.getRateValue())) {
t2powerFee = xhpcRate.getPowerFee();
}
if ("02".equals(xhpcRate.getRateValue())) {
t3powerFee = xhpcRate.getPowerFee();
}
if ("03".equals(xhpcRate.getRateValue())) {
t4powerFee = xhpcRate.getPowerFee();
}
}
//总电费
BigDecimal powerPrice = new BigDecimal(0);
Integer totalPower = 0;
if (!"0".equals(cacheOrderData.getT1PowerQuantity().toString())) {
BigDecimal multiply = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(t1powerFee);
totalPower = totalPower + cacheOrderData.getT1PowerQuantity();
powerPrice = powerPrice.add(multiply);
}
if (!"0".equals(cacheOrderData.getT2PowerQuantity().toString())) {
BigDecimal multiply = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(t2powerFee);
totalPower = totalPower + cacheOrderData.getT2PowerQuantity();
powerPrice = powerPrice.add(multiply);
}
if (!"0".equals(cacheOrderData.getT3PowerQuantity().toString())) {
BigDecimal multiply = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(t3powerFee);
totalPower = totalPower + cacheOrderData.getT3PowerQuantity();
powerPrice = powerPrice.add(multiply);
}
if (!"0".equals(cacheOrderData.getT4PowerQuantity().toString())) {
BigDecimal multiply = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(t4powerFee);
totalPower = totalPower + cacheOrderData.getT4PowerQuantity();
powerPrice = powerPrice.add(multiply);
}
powerPrice = powerPrice.setScale(2, BigDecimal.ROUND_DOWN);
//总服务费
BigDecimal servicePrice = money.subtract(powerPrice);
HashMap<String, Double> data = new HashMap<>(7);
data.put("totalPowerPrice", servicePrice.doubleValue());
data.put("totalServicePrice", servicePrice.doubleValue());
return data;
}
}