handle json parse exception, just catch it n return null
This commit is contained in:
parent
bd81a0b595
commit
2a24e1a8a1
@ -5,6 +5,6 @@ public class EvcsConst {
|
|||||||
//请求成功
|
//请求成功
|
||||||
public static final String RET_SUCC = "0";
|
public static final String RET_SUCC = "0";
|
||||||
//请求失败
|
//请求失败
|
||||||
public static final String RET_FAIL = "1";
|
public static final String RET_FAIL = "500";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import com.fasterxml.jackson.databind.JavaType;
|
|||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.type.CollectionType;
|
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -13,7 +15,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public class JSONUtil {
|
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方法
|
// 适用于简单对象,复杂对象参考下面的main方法
|
||||||
public static <T> T readParams(String params, Class<T> clz) throws IOException {
|
public static <T> T readParams(String params, Class<T> clz) {
|
||||||
|
|
||||||
|
try {
|
||||||
return mapper.readValue(params, clz);
|
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 {
|
public static <T> List<T> readParamsList(String data, Class<T> clzo) throws IOException {
|
||||||
|
|||||||
@ -22,7 +22,7 @@ public class NotificationChargeOrderInfoController {
|
|||||||
stationInfo.setOperatorId(operatorID);
|
stationInfo.setOperatorId(operatorID);
|
||||||
String data = commonRequest.getData();
|
String data = commonRequest.getData();
|
||||||
ChargeOrderInfo chargeOrderInfo = JSONUtil.readParams(data, ChargeOrderInfo.class);
|
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");
|
chargeOrderInfo.setBillerOperatorId("MA6DFCTD5");
|
||||||
log.info(">>notify charge order OID: " + operatorID);
|
log.info(">>notify charge order OID: " + operatorID);
|
||||||
// chargeOrderInfoRepository.save(chargeOrderInfo);
|
// chargeOrderInfoRepository.save(chargeOrderInfo);
|
||||||
|
|||||||
@ -27,7 +27,7 @@ public class NotificationStartChargeResultController {
|
|||||||
|
|
||||||
String data = commonRequest.getData();
|
String data = commonRequest.getData();
|
||||||
NotificationStartChargeResultRequestData startChargeResultRequest = JSONUtil.readParams(data,
|
NotificationStartChargeResultRequestData startChargeResultRequest = JSONUtil.readParams(data,
|
||||||
NotificationStartChargeResultRequestData.class);
|
NotificationStartChargeResultRequestData.class); // todo check NPE
|
||||||
String startChargeSeq = startChargeResultRequest.getStartChargeSeq();
|
String startChargeSeq = startChargeResultRequest.getStartChargeSeq();
|
||||||
// ChargeOrderInfo chargeOrderInfo = chargeOrderInfoRepository.findById(startChargeSeq).orElse(new ChargeOrderInfo()
|
// ChargeOrderInfo chargeOrderInfo = chargeOrderInfoRepository.findById(startChargeSeq).orElse(new ChargeOrderInfo()
|
||||||
// .setStartChargeSeqAndReturn(startChargeSeq));
|
// .setStartChargeSeqAndReturn(startChargeSeq));
|
||||||
|
|||||||
@ -25,7 +25,7 @@ public class NotifyNoBillOrderController {
|
|||||||
public CommonResponse notifyNoBillOrder(@RequestBody CommonRequest<NotifyNoBillOrderRequest> commonRequest) throws IOException {
|
public CommonResponse notifyNoBillOrder(@RequestBody CommonRequest<NotifyNoBillOrderRequest> commonRequest) throws IOException {
|
||||||
|
|
||||||
NotifyNoBillOrderRequest notifyNoBillOrderRequest = JSONUtil.readParams(commonRequest.getData(),
|
NotifyNoBillOrderRequest notifyNoBillOrderRequest = JSONUtil.readParams(commonRequest.getData(),
|
||||||
NotifyNoBillOrderRequest.class);
|
NotifyNoBillOrderRequest.class);// todo check NPE
|
||||||
|
|
||||||
CommonResponse commonResponse = new CommonResponse();
|
CommonResponse commonResponse = new CommonResponse();
|
||||||
commonResponse.setMsg("Query equipment business policy success");
|
commonResponse.setMsg("Query equipment business policy success");
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.xhpc.evcs.dto.CommonRequest;
|
|||||||
import com.xhpc.evcs.dto.CommonResponse;
|
import com.xhpc.evcs.dto.CommonResponse;
|
||||||
import com.xhpc.evcs.dto.EquipAuthRequest;
|
import com.xhpc.evcs.dto.EquipAuthRequest;
|
||||||
import com.xhpc.evcs.dto.EquipAuthResponse;
|
import com.xhpc.evcs.dto.EquipAuthResponse;
|
||||||
|
import com.xhpc.evcs.encryption.EvcsConst;
|
||||||
import com.xhpc.evcs.jpa.XhpcInternetUserRepository;
|
import com.xhpc.evcs.jpa.XhpcInternetUserRepository;
|
||||||
import com.xhpc.evcs.jpa.XhpcStationInternetBlacklistRepository;
|
import com.xhpc.evcs.jpa.XhpcStationInternetBlacklistRepository;
|
||||||
import com.xhpc.evcs.utils.JSONUtil;
|
import com.xhpc.evcs.utils.JSONUtil;
|
||||||
@ -38,8 +39,12 @@ public class QueryEquipAuthController {
|
|||||||
public CommonResponse queryEquipAuth(@RequestBody CommonRequest<EquipAuthRequest> commonRequest) throws Exception {
|
public CommonResponse queryEquipAuth(@RequestBody CommonRequest<EquipAuthRequest> commonRequest) throws Exception {
|
||||||
|
|
||||||
CommonResponse resp = new CommonResponse();
|
CommonResponse resp = new CommonResponse();
|
||||||
EquipAuthResponse equipAuthResponse = new EquipAuthResponse();
|
resp.setRet(EvcsConst.RET_FAIL);
|
||||||
EquipAuthRequest equipAuthRequest = JSONUtil.readParams(commonRequest.getData(), EquipAuthRequest.class);
|
EquipAuthRequest equipAuthRequest = JSONUtil.readParams(commonRequest.getData(), EquipAuthRequest.class);
|
||||||
|
if (equipAuthRequest == null) {
|
||||||
|
resp.setMsg("Request or token params validation failed");
|
||||||
|
} else {
|
||||||
|
EquipAuthResponse equipAuthResponse = new EquipAuthResponse();
|
||||||
String equipAuthSeq = equipAuthRequest.getEquipAuthSeq();
|
String equipAuthSeq = equipAuthRequest.getEquipAuthSeq();
|
||||||
String connectorId = equipAuthRequest.getConnectorId();
|
String connectorId = equipAuthRequest.getConnectorId();
|
||||||
equipAuthResponse.setEquipAuthSeq(equipAuthSeq);
|
equipAuthResponse.setEquipAuthSeq(equipAuthSeq);
|
||||||
@ -53,7 +58,6 @@ public class QueryEquipAuthController {
|
|||||||
if (xhpcInternetUser == null) {
|
if (xhpcInternetUser == null) {
|
||||||
equipAuthResponse.setSuccStat(1);
|
equipAuthResponse.setSuccStat(1);
|
||||||
equipAuthResponse.setFailReason(2);
|
equipAuthResponse.setFailReason(2);
|
||||||
resp.setRet("500");
|
|
||||||
resp.setMsg("auth denied");
|
resp.setMsg("auth denied");
|
||||||
} else {
|
} else {
|
||||||
Long internetUserId = xhpcInternetUser.getInternetUserId();
|
Long internetUserId = xhpcInternetUser.getInternetUserId();
|
||||||
@ -62,20 +66,18 @@ public class QueryEquipAuthController {
|
|||||||
if (null != xhpcStationInternetBlacklist) {
|
if (null != xhpcStationInternetBlacklist) {
|
||||||
equipAuthResponse.setSuccStat(1);
|
equipAuthResponse.setSuccStat(1);
|
||||||
equipAuthResponse.setFailReason(2);
|
equipAuthResponse.setFailReason(2);
|
||||||
resp.setRet("500");
|
|
||||||
resp.setMsg("auth denied");
|
resp.setMsg("auth denied");
|
||||||
} else {
|
} else {
|
||||||
Map<String, Object> cacheGun = REDIS.getCacheMap("gun:".concat(connectorId));
|
Map<String, Object> cacheGun = REDIS.getCacheMap("gun:".concat(connectorId));
|
||||||
String terminalStatus = (String) cacheGun.get("vehicleGunStatus");
|
String terminalStatus = (String) cacheGun.get("vehicleGunStatus");
|
||||||
String status = (String) cacheGun.get("status");
|
String status = (String) cacheGun.get("status");
|
||||||
if (!"空闲".equals(status)) {
|
if (!"空闲".equals(status)) {
|
||||||
resp.setMsg("终端不在空闲状态:[".concat(status == null ? "未注册" : isInteger(status) ? "充电中" : status).concat("]"));
|
resp.setMsg("终端不在空闲状态:[".concat(status == null ? "未注册" : isInteger(status) ? "充电中" : status).concat(
|
||||||
resp.setRet("500");
|
"]"));
|
||||||
equipAuthResponse.setSuccStat(1);
|
equipAuthResponse.setSuccStat(1);
|
||||||
equipAuthResponse.setFailReason(1);
|
equipAuthResponse.setFailReason(1);
|
||||||
} else if ("否".equals(terminalStatus)) {
|
} else if ("否".equals(terminalStatus)) {
|
||||||
resp.setMsg("未插枪");
|
resp.setMsg("未插枪");
|
||||||
resp.setRet("500");
|
|
||||||
equipAuthResponse.setSuccStat(1);
|
equipAuthResponse.setSuccStat(1);
|
||||||
equipAuthResponse.setFailReason(1);
|
equipAuthResponse.setFailReason(1);
|
||||||
} else {
|
} else {
|
||||||
@ -88,6 +90,7 @@ public class QueryEquipAuthController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp.setData(JSONUtil.toJSONString(equipAuthResponse));
|
resp.setData(JSONUtil.toJSONString(equipAuthResponse));
|
||||||
|
}
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,14 +29,18 @@ public class QueryEquipBusinessPolicyController {
|
|||||||
public CommonResponse queryEquipBusinessPolicy(@RequestBody CommonRequest<EquipBizRequest> commonRequest) throws IOException {
|
public CommonResponse queryEquipBusinessPolicy(@RequestBody CommonRequest<EquipBizRequest> commonRequest) throws IOException {
|
||||||
//获取充电设备接口编码(枪编码)
|
//获取充电设备接口编码(枪编码)
|
||||||
EquipBizRequest equipBizRequest = JSONUtil.readParams(commonRequest.getData(), EquipBizRequest.class);
|
EquipBizRequest equipBizRequest = JSONUtil.readParams(commonRequest.getData(), EquipBizRequest.class);
|
||||||
|
CommonResponse commonResponse = new CommonResponse();
|
||||||
|
if (equipBizRequest == null) {
|
||||||
|
commonResponse.setRet("500");
|
||||||
|
commonResponse.setMsg("Request or token params validation failed");
|
||||||
|
} else {
|
||||||
String connectorId = equipBizRequest.getConnectorId();
|
String connectorId = equipBizRequest.getConnectorId();
|
||||||
//获取枪所对应的桩编码
|
//获取枪所对应的桩编码
|
||||||
String pileSerialNumber = xhpcTerminalRepository.selectBySql(connectorId);
|
String pileSerialNumber = xhpcTerminalRepository.selectBySql(connectorId);
|
||||||
Map<String, Object> cachePile = REDIS.getCacheMap("pile:" + pileSerialNumber);
|
Map<String, Object> cachePile = REDIS.getCacheMap("pile:" + pileSerialNumber);
|
||||||
if (pileSerialNumber == null || cachePile == null) {
|
if (pileSerialNumber == null || cachePile == null) {
|
||||||
CommonResponse commonResponse = new CommonResponse();
|
|
||||||
commonResponse.setMsg("ConnectorID not found");
|
commonResponse.setMsg("ConnectorID not found");
|
||||||
commonResponse.setRet("1");
|
commonResponse.setRet("500");
|
||||||
return commonResponse;
|
return commonResponse;
|
||||||
}
|
}
|
||||||
ArrayList<String> modelTypes = new ArrayList<>();
|
ArrayList<String> modelTypes = new ArrayList<>();
|
||||||
@ -148,11 +152,10 @@ public class QueryEquipBusinessPolicyController {
|
|||||||
equipBizResponse.setPolicyInfos(policyInfosArr);
|
equipBizResponse.setPolicyInfos(policyInfosArr);
|
||||||
|
|
||||||
//塞入包装类
|
//塞入包装类
|
||||||
CommonResponse commonResponse = new CommonResponse();
|
|
||||||
commonResponse.setMsg("Query equipment business policy success");
|
commonResponse.setMsg("Query equipment business policy success");
|
||||||
commonResponse.setRet("0");
|
commonResponse.setRet("0");
|
||||||
commonResponse.setData(JSONUtil.toJSONString(equipBizResponse));
|
commonResponse.setData(JSONUtil.toJSONString(equipBizResponse));
|
||||||
|
}
|
||||||
return commonResponse;
|
return commonResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,9 +40,13 @@ public class QueryEquipChargeStatusController {
|
|||||||
//充电订单号 三方传进来都是27位
|
//充电订单号 三方传进来都是27位
|
||||||
String data = commonRequest.getData();
|
String data = commonRequest.getData();
|
||||||
ChargeInfoRequest chargeInfoRequest = JSONUtil.readParams(data, ChargeInfoRequest.class);
|
ChargeInfoRequest chargeInfoRequest = JSONUtil.readParams(data, ChargeInfoRequest.class);
|
||||||
|
CommonResponse response = new CommonResponse();
|
||||||
|
if (chargeInfoRequest == null) {
|
||||||
|
response.setRet(EvcsConst.RET_FAIL);
|
||||||
|
response.setMsg("Request or token params validation failed");
|
||||||
|
} else {
|
||||||
String startChargeSeq = chargeInfoRequest.getStartChargeSeq();
|
String startChargeSeq = chargeInfoRequest.getStartChargeSeq();
|
||||||
equipChargeStatus.setStartChargeSeq(startChargeSeq);
|
equipChargeStatus.setStartChargeSeq(startChargeSeq);
|
||||||
CommonResponse response = new CommonResponse();
|
|
||||||
//充电订单状态
|
//充电订单状态
|
||||||
EtOrderMapping etOrderMapping = orderMappingRepository.findByEvcsOrderNo(startChargeSeq).orElse(null);
|
EtOrderMapping etOrderMapping = orderMappingRepository.findByEvcsOrderNo(startChargeSeq).orElse(null);
|
||||||
if (etOrderMapping == null) {
|
if (etOrderMapping == null) {
|
||||||
@ -135,6 +139,7 @@ public class QueryEquipChargeStatusController {
|
|||||||
response.setData(JSONUtil.toJSONString(equipChargeStatus));
|
response.setData(JSONUtil.toJSONString(equipChargeStatus));
|
||||||
response.setMsg("success");
|
response.setMsg("success");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,11 +45,14 @@ public class QueryStartChargeController {
|
|||||||
|
|
||||||
CommonResponse resp = new CommonResponse();
|
CommonResponse resp = new CommonResponse();
|
||||||
resp.setRet(EvcsConst.RET_FAIL);
|
resp.setRet(EvcsConst.RET_FAIL);
|
||||||
|
StartChargeRequest startChargeRequest = JSONUtil.readParams(commonRequest.getData(), StartChargeRequest.class);
|
||||||
|
if (startChargeRequest == null) {
|
||||||
|
resp.setMsg("Request or token params validation failed");
|
||||||
|
} else {
|
||||||
StartChargeResponse startChargeResponse = new StartChargeResponse();
|
StartChargeResponse startChargeResponse = new StartChargeResponse();
|
||||||
startChargeResponse.setFailReason(0);
|
startChargeResponse.setFailReason(0);
|
||||||
startChargeResponse.setSuccStat(1);
|
startChargeResponse.setSuccStat(1);
|
||||||
startChargeResponse.setStartChargeSeqStat(4);
|
startChargeResponse.setStartChargeSeqStat(4);
|
||||||
StartChargeRequest startChargeRequest = JSONUtil.readParams(commonRequest.getData(), StartChargeRequest.class);
|
|
||||||
String startChargeSeq = startChargeRequest.getStartChargeSeq();
|
String startChargeSeq = startChargeRequest.getStartChargeSeq();
|
||||||
String connectorId = startChargeRequest.getConnectorId();
|
String connectorId = startChargeRequest.getConnectorId();
|
||||||
Map<String, Object> cacheGun = REDIS.getCacheMap("gun:".concat(connectorId));
|
Map<String, Object> cacheGun = REDIS.getCacheMap("gun:".concat(connectorId));
|
||||||
@ -61,11 +64,9 @@ public class QueryStartChargeController {
|
|||||||
etOrderMapping.setEvcsOrderNo(startChargeSeq);
|
etOrderMapping.setEvcsOrderNo(startChargeSeq);
|
||||||
if (!"空闲".equals(status)) {
|
if (!"空闲".equals(status)) {
|
||||||
resp.setMsg("终端状态异常:[".concat(status == null ? "未注册" : status).concat("]"));
|
resp.setMsg("终端状态异常:[".concat(status == null ? "未注册" : status).concat("]"));
|
||||||
resp.setRet("500");
|
|
||||||
emptyHorder(startChargeSeq, connectorId, etOrderMapping);
|
emptyHorder(startChargeSeq, connectorId, etOrderMapping);
|
||||||
} else if ("否".equals(terminalStatus)) {
|
} else if ("否".equals(terminalStatus)) {
|
||||||
resp.setMsg("未插枪");
|
resp.setMsg("未插枪");
|
||||||
resp.setRet("500");
|
|
||||||
emptyHorder(startChargeSeq, connectorId, etOrderMapping);
|
emptyHorder(startChargeSeq, connectorId, etOrderMapping);
|
||||||
} else {
|
} else {
|
||||||
String plateNum = startChargeRequest.getPlateNum();
|
String plateNum = startChargeRequest.getPlateNum();
|
||||||
@ -109,6 +110,7 @@ public class QueryStartChargeController {
|
|||||||
}
|
}
|
||||||
etOrderMappingRepo.save(etOrderMapping);
|
etOrderMappingRepo.save(etOrderMapping);
|
||||||
resp.setData(JSONUtil.toJSONString(startChargeResponse));
|
resp.setData(JSONUtil.toJSONString(startChargeResponse));
|
||||||
|
}
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.xhpc.evcs.api;
|
|||||||
|
|
||||||
import com.xhpc.common.api.dto.ChargingStationDto;
|
import com.xhpc.common.api.dto.ChargingStationDto;
|
||||||
import com.xhpc.evcs.dto.*;
|
import com.xhpc.evcs.dto.*;
|
||||||
|
import com.xhpc.evcs.encryption.EvcsConst;
|
||||||
import com.xhpc.evcs.utils.JSONUtil;
|
import com.xhpc.evcs.utils.JSONUtil;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
@ -19,7 +20,12 @@ public class QueryStationStatusController {
|
|||||||
@PostMapping("/v1/query_station_status")
|
@PostMapping("/v1/query_station_status")
|
||||||
public CommonResponse queryStationsInfo(@RequestBody CommonRequest<StationStatusRequest> commonRequest) throws Exception {
|
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);
|
StationStatusRequest stationStatusRequest = JSONUtil.readParams(commonRequest.getData(), StationStatusRequest.class);
|
||||||
|
if (stationStatusRequest == null) {
|
||||||
|
resp.setMsg("Request or token params validation failed");
|
||||||
|
} else {
|
||||||
String[] stationIDs = stationStatusRequest.getStationIds();
|
String[] stationIDs = stationStatusRequest.getStationIds();
|
||||||
List<StationStatusInfo> stationStatusInfos = new ArrayList<>();
|
List<StationStatusInfo> stationStatusInfos = new ArrayList<>();
|
||||||
//Loading data through redis at first.
|
//Loading data through redis at first.
|
||||||
@ -77,10 +83,10 @@ public class QueryStationStatusController {
|
|||||||
if (stationStatusInfos.size() != 0) {
|
if (stationStatusInfos.size() != 0) {
|
||||||
stationStatusInfoWrappers.setStationStatusInfos(stationStatusInfos);
|
stationStatusInfoWrappers.setStationStatusInfos(stationStatusInfos);
|
||||||
}
|
}
|
||||||
CommonResponse resp = new CommonResponse();
|
|
||||||
resp.setRet("0");
|
resp.setRet("0");
|
||||||
resp.setMsg("Query station status success");
|
resp.setMsg("Query station status success");
|
||||||
resp.setData(JSONUtil.toJSONString(stationStatusInfoWrappers));
|
resp.setData(JSONUtil.toJSONString(stationStatusInfoWrappers));
|
||||||
|
}
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import com.xhpc.evcs.dto.CommonRequest;
|
|||||||
import com.xhpc.evcs.dto.CommonResponse;
|
import com.xhpc.evcs.dto.CommonResponse;
|
||||||
import com.xhpc.evcs.dto.QueryStopChargeRequest;
|
import com.xhpc.evcs.dto.QueryStopChargeRequest;
|
||||||
import com.xhpc.evcs.dto.QueryStopChargeResponse;
|
import com.xhpc.evcs.dto.QueryStopChargeResponse;
|
||||||
|
import com.xhpc.evcs.encryption.EvcsConst;
|
||||||
import com.xhpc.evcs.jpa.OrderMappingRepository;
|
import com.xhpc.evcs.jpa.OrderMappingRepository;
|
||||||
import com.xhpc.evcs.jpa.XhpcChargingPileRepository;
|
import com.xhpc.evcs.jpa.XhpcChargingPileRepository;
|
||||||
import com.xhpc.evcs.utils.JSONUtil;
|
import com.xhpc.evcs.utils.JSONUtil;
|
||||||
@ -40,7 +41,13 @@ public class QueryStopChargeController {
|
|||||||
@PostMapping("/v1/query_stop_charge")
|
@PostMapping("/v1/query_stop_charge")
|
||||||
public CommonResponse queryStopCharge(@RequestBody CommonRequest<QueryStopChargeRequest> commonRequest) throws IOException {
|
public CommonResponse queryStopCharge(@RequestBody CommonRequest<QueryStopChargeRequest> commonRequest) throws IOException {
|
||||||
|
|
||||||
QueryStopChargeRequest queryStopChargeRequest = JSONUtil.readParams(commonRequest.getData(), QueryStopChargeRequest.class);
|
CommonResponse commonResponse = new CommonResponse();
|
||||||
|
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位)
|
// evcs电订单号(27位)
|
||||||
String startChargeSeq = queryStopChargeRequest.getStartChargeSeq();
|
String startChargeSeq = queryStopChargeRequest.getStartChargeSeq();
|
||||||
QueryStopChargeResponse queryStopChargeResponse = new QueryStopChargeResponse();
|
QueryStopChargeResponse queryStopChargeResponse = new QueryStopChargeResponse();
|
||||||
@ -61,7 +68,8 @@ public class QueryStopChargeController {
|
|||||||
String pileNum = connectorId.substring(0, connectorId.length() - 2);
|
String pileNum = connectorId.substring(0, connectorId.length() - 2);
|
||||||
//从数据库中查询对应的桩的版本信息
|
//从数据库中查询对应的桩的版本信息
|
||||||
XhpcChargingPile pileInfo = XhpcChargingPileRepository.findBySerialNumber(pileNum).orElse(null);
|
XhpcChargingPile pileInfo = XhpcChargingPileRepository.findBySerialNumber(pileNum).orElse(null);
|
||||||
String versionNum = pileInfo.getCommunicationProtocolVersion() != null ? pileInfo.getCommunicationProtocolVersion() :
|
String versionNum = pileInfo.getCommunicationProtocolVersion() != null ?
|
||||||
|
pileInfo.getCommunicationProtocolVersion() :
|
||||||
"0A";
|
"0A";
|
||||||
//给对应的枪发送停止充电指令
|
//给对应的枪发送停止充电指令
|
||||||
R r = powerPileService.stopCharging(xhOrderNo, pileNum, connectorId, versionNum);
|
R r = powerPileService.stopCharging(xhOrderNo, pileNum, connectorId, versionNum);
|
||||||
@ -92,8 +100,6 @@ public class QueryStopChargeController {
|
|||||||
queryStopChargeResponse.setStartChargeSeqStat(4);
|
queryStopChargeResponse.setStartChargeSeqStat(4);
|
||||||
queryStopChargeResponse.setSuccStat(1);
|
queryStopChargeResponse.setSuccStat(1);
|
||||||
String data = JSONUtil.toJSONString(queryStopChargeResponse);
|
String data = JSONUtil.toJSONString(queryStopChargeResponse);
|
||||||
CommonResponse commonResponse = new CommonResponse();
|
|
||||||
commonResponse.setRet("1");
|
|
||||||
commonResponse.setMsg("请求停止充电失败");
|
commonResponse.setMsg("请求停止充电失败");
|
||||||
commonResponse.setData(data);
|
commonResponse.setData(data);
|
||||||
return commonResponse;
|
return commonResponse;
|
||||||
@ -107,10 +113,10 @@ public class QueryStopChargeController {
|
|||||||
queryStopChargeResponse.setSuccStat(0);
|
queryStopChargeResponse.setSuccStat(0);
|
||||||
queryStopChargeResponse.setFailReason(0);
|
queryStopChargeResponse.setFailReason(0);
|
||||||
String data = JSONUtil.toJSONString(queryStopChargeResponse);
|
String data = JSONUtil.toJSONString(queryStopChargeResponse);
|
||||||
CommonResponse commonResponse = new CommonResponse();
|
|
||||||
commonResponse.setRet("0");
|
commonResponse.setRet("0");
|
||||||
commonResponse.setMsg("请求停止充电成功");
|
commonResponse.setMsg("请求停止充电成功");
|
||||||
commonResponse.setData(data);
|
commonResponse.setData(data);
|
||||||
|
}
|
||||||
return commonResponse;
|
return commonResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +127,7 @@ public class QueryStopChargeController {
|
|||||||
queryStopChargeResponse.setFailReason(0);
|
queryStopChargeResponse.setFailReason(0);
|
||||||
String data = JSONUtil.toJSONString(queryStopChargeResponse);
|
String data = JSONUtil.toJSONString(queryStopChargeResponse);
|
||||||
CommonResponse commonResponse = new CommonResponse();
|
CommonResponse commonResponse = new CommonResponse();
|
||||||
commonResponse.setRet("0");
|
commonResponse.setRet("500");
|
||||||
commonResponse.setMsg(msg);
|
commonResponse.setMsg(msg);
|
||||||
commonResponse.setData(data);
|
commonResponse.setData(data);
|
||||||
return commonResponse;
|
return commonResponse;
|
||||||
|
|||||||
@ -22,20 +22,25 @@ public class QueryTerminalCodeController {
|
|||||||
public CommonResponse queryTerminalCode(@RequestBody CommonRequest<QueryTerminalCodeRequest> commonRequest) throws IOException {
|
public CommonResponse queryTerminalCode(@RequestBody CommonRequest<QueryTerminalCodeRequest> commonRequest) throws IOException {
|
||||||
|
|
||||||
CommonResponse resp = new CommonResponse();
|
CommonResponse resp = new CommonResponse();
|
||||||
QueryTerminalCodeResponse queryTerminalCodeResponse = new QueryTerminalCodeResponse();
|
|
||||||
QueryTerminalCodeRequest queryTerminalCodeRequest = JSONUtil.readParams(commonRequest.getData(), QueryTerminalCodeRequest.class);
|
|
||||||
resp.setRet(EvcsConst.RET_FAIL);
|
resp.setRet(EvcsConst.RET_FAIL);
|
||||||
resp.setMsg("fail");
|
QueryTerminalCodeRequest queryTerminalCodeRequest = JSONUtil.readParams(commonRequest.getData(),
|
||||||
if (null != queryTerminalCodeRequest) {
|
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();
|
String qRCode = queryTerminalCodeRequest.getQRCode();
|
||||||
if (null != qRCode) {
|
if (null != qRCode) {
|
||||||
|
String[] terminalId = qRCode.split("=");
|
||||||
|
if (terminalId.length == 2) {
|
||||||
resp.setRet(EvcsConst.RET_SUCC);
|
resp.setRet(EvcsConst.RET_SUCC);
|
||||||
resp.setMsg("success");
|
resp.setMsg("success");
|
||||||
String terminalCode = qRCode.split("=")[1];
|
queryTerminalCodeResponse.setTerminalCode(terminalId[1]);
|
||||||
queryTerminalCodeResponse.setTerminalCode(terminalCode);
|
|
||||||
resp.setData(JSONUtil.toJSONString(queryTerminalCodeResponse));
|
resp.setData(JSONUtil.toJSONString(queryTerminalCodeResponse));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import com.xhpc.evcs.domain.XhpcInternetUser;
|
|||||||
import com.xhpc.evcs.dto.CommonResponse;
|
import com.xhpc.evcs.dto.CommonResponse;
|
||||||
import com.xhpc.evcs.dto.TokenRequest;
|
import com.xhpc.evcs.dto.TokenRequest;
|
||||||
import com.xhpc.evcs.dto.TokenResponse;
|
import com.xhpc.evcs.dto.TokenResponse;
|
||||||
|
import com.xhpc.evcs.encryption.EvcsConst;
|
||||||
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
|
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
|
||||||
import com.xhpc.evcs.jpa.XhpcInternetUserRepository;
|
import com.xhpc.evcs.jpa.XhpcInternetUserRepository;
|
||||||
import com.xhpc.evcs.utils.JSONUtil;
|
import com.xhpc.evcs.utils.JSONUtil;
|
||||||
@ -24,6 +25,8 @@ import java.util.Calendar;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController()
|
@RestController()
|
||||||
public class QueryTokenController {
|
public class QueryTokenController {
|
||||||
@ -39,30 +42,24 @@ public class QueryTokenController {
|
|||||||
|
|
||||||
log.debug("<<query token request body: " + tokenRequest);
|
log.debug("<<query token request body: " + tokenRequest);
|
||||||
CommonResponse resp = new CommonResponse();
|
CommonResponse resp = new CommonResponse();
|
||||||
resp.setRet("0");
|
resp.setRet(EvcsConst.RET_FAIL);
|
||||||
resp.setMsg("");
|
|
||||||
String operatorID = tokenRequest.getOperatorId();
|
String operatorID = tokenRequest.getOperatorId();
|
||||||
if (operatorID == null) {
|
if (operatorID == null) {
|
||||||
String decodedData = (String) tokenRequest.getAdditionalProperties().get("Data");
|
String decodedData = (String) tokenRequest.getAdditionalProperties().get("Data");
|
||||||
try {
|
|
||||||
tokenRequest = JSONUtil.readParams(decodedData, TokenRequest.class);
|
tokenRequest = JSONUtil.readParams(decodedData, TokenRequest.class);
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("invalid Data string: {}", decodedData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (tokenRequest == null) {
|
||||||
|
resp.setMsg("Request params validation failed");
|
||||||
|
} else {
|
||||||
operatorID = tokenRequest.getOperatorId();
|
operatorID = tokenRequest.getOperatorId();
|
||||||
TokenResponse tokenResponse = new TokenResponse();
|
TokenResponse tokenResponse = new TokenResponse();
|
||||||
tokenResponse.setOperatorId("MA6DFCTD5");
|
tokenResponse.setOperatorId(REDIS.getCacheObject("global:EVCS_OPID"));
|
||||||
tokenResponse.setSuccStat(0);
|
tokenResponse.setSuccStat(0);
|
||||||
tokenResponse.setFailReason(0);
|
tokenResponse.setFailReason(0);
|
||||||
String data = null; //todo 优化OperatorIdEvcs like
|
|
||||||
XhpcInternetUser xhpcInternetUser =
|
XhpcInternetUser xhpcInternetUser =
|
||||||
xhpcInternetUserRepository.findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(tokenRequest.getOperatorId(), Instant.now(), Instant.now());
|
xhpcInternetUserRepository.findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(tokenRequest.getOperatorId(), Instant.now(), Instant.now());
|
||||||
if (xhpcInternetUser != null) {
|
if (xhpcInternetUser != null) {
|
||||||
String operatorSecret = tokenRequest.getOperatorSecret();
|
String operatorSecret = tokenRequest.getOperatorSecret();
|
||||||
if (operatorSecret == null) {
|
|
||||||
operatorSecret = tokenRequest.getOperatorSecret();
|
|
||||||
}
|
|
||||||
AuthSecretToken authSecretTokenIn =
|
AuthSecretToken authSecretTokenIn =
|
||||||
authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenTypeAndOperatorSecret(
|
authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenTypeAndOperatorSecret(
|
||||||
operatorID, AuthSecretToken.SECRET_TOKEN_TYPE_IN, operatorSecret).orElse(null);
|
operatorID, AuthSecretToken.SECRET_TOKEN_TYPE_IN, operatorSecret).orElse(null);
|
||||||
@ -71,7 +68,6 @@ public class QueryTokenController {
|
|||||||
resp.setMsg("Invalid OperatorID/Secret");
|
resp.setMsg("Invalid OperatorID/Secret");
|
||||||
tokenResponse.setSuccStat(1);
|
tokenResponse.setSuccStat(1);
|
||||||
tokenResponse.setFailReason(2);
|
tokenResponse.setFailReason(2);
|
||||||
resp.setData(data);
|
|
||||||
} else {
|
} else {
|
||||||
String token;
|
String token;
|
||||||
if (authSecretTokenIn.getTokenExpiry() != null && !authSecretTokenIn.getTokenExpiry().before(Calendar.getInstance().getTime())) {
|
if (authSecretTokenIn.getTokenExpiry() != null && !authSecretTokenIn.getTokenExpiry().before(Calendar.getInstance().getTime())) {
|
||||||
@ -87,11 +83,13 @@ public class QueryTokenController {
|
|||||||
tokenResponse.setTokenAvailableTime(Long.valueOf(ChronoUnit.SECONDS.between(Instant.now(), te)).intValue());
|
tokenResponse.setTokenAvailableTime(Long.valueOf(ChronoUnit.SECONDS.between(Instant.now(), te)).intValue());
|
||||||
tokenResponse.setSuccStat(0);
|
tokenResponse.setSuccStat(0);
|
||||||
tokenResponse.setFailReason(0);
|
tokenResponse.setFailReason(0);
|
||||||
|
resp.setRet(EvcsConst.RET_SUCC);
|
||||||
resp.setMsg("Query token success");
|
resp.setMsg("Query token success");
|
||||||
resp.setData(JSONUtil.toJSONString(tokenResponse));
|
resp.setData(JSONUtil.toJSONString(tokenResponse));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resp.setMsg("Cooperation settings or start time not valid");
|
resp.setMsg("Cooperation settings or start time are not valid");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import com.xhpc.evcs.domain.AuthSecretToken;
|
|||||||
import com.xhpc.evcs.dto.CommonRequest;
|
import com.xhpc.evcs.dto.CommonRequest;
|
||||||
import com.xhpc.evcs.dto.CommonResponse;
|
import com.xhpc.evcs.dto.CommonResponse;
|
||||||
import com.xhpc.evcs.encryption.Aes128Cbc;
|
import com.xhpc.evcs.encryption.Aes128Cbc;
|
||||||
|
import com.xhpc.evcs.encryption.EvcsConst;
|
||||||
import com.xhpc.evcs.encryption.HMAC;
|
import com.xhpc.evcs.encryption.HMAC;
|
||||||
import com.xhpc.evcs.http.HttpServletRequestRepeatReadWrapper;
|
import com.xhpc.evcs.http.HttpServletRequestRepeatReadWrapper;
|
||||||
import com.xhpc.evcs.http.HttpServletRequestWritableWrapper;
|
import com.xhpc.evcs.http.HttpServletRequestWritableWrapper;
|
||||||
@ -75,12 +76,21 @@ public class EvcsFilter extends OncePerRequestFilter {
|
|||||||
String servletPath = request.getServletPath();
|
String servletPath = request.getServletPath();
|
||||||
log.debug("servletPath: " + servletPath);
|
log.debug("servletPath: " + servletPath);
|
||||||
CommonRequest commonRequest = JSONUtil.readParams(bodyString, CommonRequest.class);
|
CommonRequest commonRequest = JSONUtil.readParams(bodyString, CommonRequest.class);
|
||||||
|
resp.setRet(EvcsConst.RET_FAIL);
|
||||||
|
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
|
||||||
|
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 {
|
||||||
String operatorId = commonRequest.getOperatorId();
|
String operatorId = commonRequest.getOperatorId();
|
||||||
String authorization = request.getHeader("Authorization");
|
String authorization = request.getHeader("Authorization");
|
||||||
log.debug("Authorization: {}", authorization);
|
log.debug("Authorization: {}", authorization);
|
||||||
AuthSecretToken authSecretTokenIn = null;
|
AuthSecretToken authSecretTokenIn = null;
|
||||||
Date now = Calendar.getInstance().getTime();
|
Date now = Calendar.getInstance().getTime();
|
||||||
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
|
|
||||||
if (servletPath.endsWith("query_token")) {
|
if (servletPath.endsWith("query_token")) {
|
||||||
authSecretTokenIn = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId,
|
authSecretTokenIn = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId,
|
||||||
AuthSecretToken.SECRET_TOKEN_TYPE_IN).orElse(null);
|
AuthSecretToken.SECRET_TOKEN_TYPE_IN).orElse(null);
|
||||||
@ -181,6 +191,7 @@ public class EvcsFilter extends OncePerRequestFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean handleQueryToken(HttpServletRequest request, HttpServletResponse response, FilterChain chain,
|
private boolean handleQueryToken(HttpServletRequest request, HttpServletResponse response, FilterChain chain,
|
||||||
ServletRequest requestWrapper, String bodyString, CommonRequest commonRequest,
|
ServletRequest requestWrapper, String bodyString, CommonRequest commonRequest,
|
||||||
|
|||||||
@ -105,7 +105,7 @@ public class CheckChargeOrders extends CoreDispatcher {
|
|||||||
//推送并处理推送结果
|
//推送并处理推送结果
|
||||||
String result = ok(commonRequest, "/check_charge_orders", authSecretTokenOut);
|
String result = ok(commonRequest, "/check_charge_orders", authSecretTokenOut);
|
||||||
CheckChargeOrderResponseData checkChargeOrderResponseData = JSONUtil.readParams(result,
|
CheckChargeOrderResponseData checkChargeOrderResponseData = JSONUtil.readParams(result,
|
||||||
CheckChargeOrderResponseData.class);
|
CheckChargeOrderResponseData.class); //todo check NPE
|
||||||
if (checkChargeOrderResponseData.getDisputeOrders() == null) {
|
if (checkChargeOrderResponseData.getDisputeOrders() == null) {
|
||||||
//没有争议订单
|
//没有争议订单
|
||||||
REDIS.deleteObject(pushOrderKey);
|
REDIS.deleteObject(pushOrderKey);
|
||||||
|
|||||||
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user