保存未启动三方订单为空的历史订单;优化evcs代码

This commit is contained in:
ZZ 2021-12-08 14:44:51 +08:00
parent afee8e3df2
commit 0cb71ab537
7 changed files with 35 additions and 31 deletions

View File

@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.time.Instant; import java.time.Instant;
import java.util.List;
import java.util.Map; import java.util.Map;
import static cn.hutool.core.util.NumberUtil.isInteger; import static cn.hutool.core.util.NumberUtil.isInteger;
@ -48,16 +47,16 @@ public class QueryEquipAuthController {
String pileId = connectorId.substring(0, connectorId.length() - 2); String pileId = connectorId.substring(0, connectorId.length() - 2);
Map<String, Object> pileDataModel = REDIS.getCacheMap("pile:" + pileId); Map<String, Object> pileDataModel = REDIS.getCacheMap("pile:" + pileId);
Long stationId = Long.parseLong(pileDataModel.get("stationId").toString()); Long stationId = Long.parseLong(pileDataModel.get("stationId").toString());
List<XhpcInternetUser> xhpcInternetUserList = Instant now = Instant.now();
xhpcInternetUserRepository.findByCooperationStartTimeBeforeAndCooperationEndTimeAfterAndOperatorIdEvcsLike(Instant.now(), XhpcInternetUser xhpcInternetUser = xhpcInternetUserRepository
Instant.now(), commonRequest.getOperatorId()); .findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(commonRequest.getOperatorId(), now, now);
if (xhpcInternetUserList.isEmpty()) { if (xhpcInternetUser == null) {
equipAuthResponse.setSuccStat(1); equipAuthResponse.setSuccStat(1);
equipAuthResponse.setFailReason(2); equipAuthResponse.setFailReason(2);
resp.setRet("500"); resp.setRet("500");
resp.setMsg("auth denied"); resp.setMsg("auth denied");
} else { } else {
Long internetUserId = xhpcInternetUserList.get(0).getId(); Long internetUserId = xhpcInternetUser.getInternetUserId();
XhpcStationInternetBlacklist xhpcStationInternetBlacklist = XhpcStationInternetBlacklist xhpcStationInternetBlacklist =
xhpcStationInternetBlacklistRepo.findByChargingStationIdAndInternetUserId(stationId, internetUserId).orElse(null); xhpcStationInternetBlacklistRepo.findByChargingStationIdAndInternetUserId(stationId, internetUserId).orElse(null);
if (null != xhpcStationInternetBlacklist) { if (null != xhpcStationInternetBlacklist) {

View File

@ -9,10 +9,7 @@ import com.xhpc.evcs.dto.CommonResponse;
import com.xhpc.evcs.dto.StartChargeRequest; import com.xhpc.evcs.dto.StartChargeRequest;
import com.xhpc.evcs.dto.StartChargeResponse; import com.xhpc.evcs.dto.StartChargeResponse;
import com.xhpc.evcs.encryption.EvcsConst; import com.xhpc.evcs.encryption.EvcsConst;
import com.xhpc.evcs.jpa.AuthSecretTokenRepository; import com.xhpc.evcs.jpa.*;
import com.xhpc.evcs.jpa.OrderMappingRepository;
import com.xhpc.evcs.jpa.XhpcHistoryOrderRepository;
import com.xhpc.evcs.jpa.XhpcTerminalRepository;
import com.xhpc.evcs.utils.JSONUtil; import com.xhpc.evcs.utils.JSONUtil;
import com.xhpc.order.domain.XhpcHistoryOrder; import com.xhpc.order.domain.XhpcHistoryOrder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -40,6 +37,8 @@ public class QueryStartChargeController {
private XhpcTerminalRepository xhpcTerminalRepository; private XhpcTerminalRepository xhpcTerminalRepository;
@Autowired @Autowired
private PileOrderService pileOrderService; private PileOrderService pileOrderService;
@Autowired
private XhpcInternetUserRepository xhpcInternetUserRepository;
@PostMapping(value = "/v1/query_start_charge") @PostMapping(value = "/v1/query_start_charge")
public CommonResponse queryStartCharge(@RequestBody CommonRequest<StartChargeRequest> commonRequest) throws Exception { public CommonResponse queryStartCharge(@RequestBody CommonRequest<StartChargeRequest> commonRequest) throws Exception {
@ -121,14 +120,19 @@ public class QueryStartChargeController {
emptyHorder.setEndTime(now); emptyHorder.setEndTime(now);
emptyHorder.setCreateTime(now); emptyHorder.setCreateTime(now);
emptyHorder.setUpdateTime(now); emptyHorder.setUpdateTime(now);
emptyHorder.setStopReasonEvcs(9);
String sn = genOrder(connectorId); String sn = genOrder(connectorId);
etOrderMapping.setXhOrderNo(sn); etOrderMapping.setXhOrderNo(sn);
emptyHorder.setSerialNumber(sn); emptyHorder.setSerialNumber(sn);
emptyHorder.setOperatorId3rdptyEvcs(startChargeSeq.substring(0, 9)); emptyHorder.setInternetSerialNumber(startChargeSeq);
String operatorId3rdpty = startChargeSeq.substring(0, 9);
emptyHorder.setOperatorId3rdptyEvcs(operatorId3rdpty);
emptyHorder.setUserId(xhpcInternetUserRepository.queryDbId(operatorId3rdpty));
emptyHorder.setType(1); emptyHorder.setType(1);
emptyHorder.setState(2); emptyHorder.setState(2);
emptyHorder.setChargingStationId(REDIS.getCacheMapValue("pile:".concat(connectorId.substring(0, 14)), "stationId")); emptyHorder.setChargingStationId(REDIS.getCacheMapValue("pile:".concat(connectorId.substring(0, 14)), "stationId"));
emptyHorder.setTerminalId(xhpcTerminalRepository.queryDbId(connectorId)); emptyHorder.setTerminalId(xhpcTerminalRepository.queryDbId(connectorId));
emptyHorder.setConfirmResult(-1);
xhpcHistoryOrderRepository.save(emptyHorder); xhpcHistoryOrderRepository.save(emptyHorder);
} }

View File

@ -41,7 +41,7 @@ public class QueryStationsInfoController {
private XhpcChargingStationRepository xhpcChargingStationRepository; private XhpcChargingStationRepository xhpcChargingStationRepository;
@Autowired @Autowired
private XhpcStationInternetBlacklistRepository xhpcStationInternetBlacklistRepo; private XhpcStationInternetBlacklistRepository xhpcStationInternetBlacklistRepo;
private String[] GUNNAMES = {"", "A", "B", "C", "D"}; private final String[] GUNNAMES = {"", "A", "B", "C", "D"};
@PostMapping("/v1/query_stations_info") @PostMapping("/v1/query_stations_info")
public CommonResponse queryStationsInfo(@RequestBody(required = false) CommonRequest<PageRequest> commonRequest) throws Exception { public CommonResponse queryStationsInfo(@RequestBody(required = false) CommonRequest<PageRequest> commonRequest) throws Exception {
@ -54,14 +54,16 @@ public class QueryStationsInfoController {
response.setPageNo(pageNo); response.setPageNo(pageNo);
//页码总数 //页码总数
String operatorId = commonRequest.getOperatorId(); String operatorId = commonRequest.getOperatorId();
final List<XhpcInternetUser> xhpcInternetUserList = Instant now = Instant.now();
xhpcInternetUserRepository.findByCooperationStartTimeBeforeAndCooperationEndTimeAfterAndOperatorIdEvcsLike(Instant.now(), Instant.now(), operatorId); XhpcInternetUser xhpcInternetUser =
if (xhpcInternetUserList.isEmpty()) { xhpcInternetUserRepository
.findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(operatorId, now, now);
if (xhpcInternetUser == null) {
resp.setRet("1"); resp.setRet("1");
resp.setMsg("Not valid internet user/OperatorID"); resp.setMsg("Not valid internet user/OperatorID");
resp.setData(JSONUtil.toJSONString(response)); resp.setData(JSONUtil.toJSONString(response));
} else { } else {
Long internetUserId = xhpcInternetUserList.get(0).getId(); Long internetUserId = xhpcInternetUser.getInternetUserId();
List<XhpcStationInternetBlacklist> xhpcStationInternetBlacklist = List<XhpcStationInternetBlacklist> xhpcStationInternetBlacklist =
xhpcStationInternetBlacklistRepo.findByInternetUserId(internetUserId); xhpcStationInternetBlacklistRepo.findByInternetUserId(internetUserId);
List<String> stationKeys = new ArrayList<>(REDIS.keys("station:*")); List<String> stationKeys = new ArrayList<>(REDIS.keys("station:*"));

View File

@ -57,7 +57,7 @@ public class QueryTokenController {
tokenResponse.setFailReason(0); tokenResponse.setFailReason(0);
String data = null; //todo 优化OperatorIdEvcs like String data = null; //todo 优化OperatorIdEvcs like
XhpcInternetUser xhpcInternetUser = XhpcInternetUser xhpcInternetUser =
xhpcInternetUserRepository.findByOperatorIdEvcsAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(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) { if (operatorSecret == null) {

View File

@ -3,6 +3,7 @@ package com.xhpc.evcs.jpa;
import com.xhpc.evcs.domain.XhpcInternetUser; import com.xhpc.evcs.domain.XhpcInternetUser;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.QueryByExampleExecutor; import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -13,14 +14,12 @@ import java.util.List;
public interface XhpcInternetUserRepository extends JpaRepository<XhpcInternetUser, Long>, public interface XhpcInternetUserRepository extends JpaRepository<XhpcInternetUser, Long>,
QueryByExampleExecutor<XhpcInternetUser>, JpaSpecificationExecutor<XhpcInternetUser> { QueryByExampleExecutor<XhpcInternetUser>, JpaSpecificationExecutor<XhpcInternetUser> {
XhpcInternetUser findByOperatorIdEvcsAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(String operatorId3rdpty, XhpcInternetUser findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(String operatorId3rdpty,
Instant now, Instant now2); Instant now, Instant now2);
List<XhpcInternetUser> findByCooperationStartTimeBeforeAndCooperationEndTimeAfter(Instant now, Instant now1); List<XhpcInternetUser> findByCooperationStartTimeBeforeAndCooperationEndTimeAfter(Instant now, Instant now1);
List<XhpcInternetUser> findByCooperationStartTimeBeforeAndCooperationEndTimeAfterAndOperatorIdEvcsLike(Instant now, @Query("select t.internetUserId from XhpcInternetUser as t where t.operatorIdEvcs like %?1%")
Instant now1, Long queryDbId(String operatorId3rdpty);
String operatorIdEvcs);
} }

View File

@ -41,9 +41,9 @@ public class NotificationStationStatusTask extends CoreDispatcher {
Collection<String> stationTerminalKeys = REDIS.keys("stationTerminalStatus:*"); Collection<String> stationTerminalKeys = REDIS.keys("stationTerminalStatus:*");
Instant now = Instant.now();
List<XhpcInternetUser> xhpcInternetUserList = List<XhpcInternetUser> xhpcInternetUserList =
xhpcInternetUserRepository.findByCooperationStartTimeBeforeAndCooperationEndTimeAfter(Instant.now(), xhpcInternetUserRepository.findByCooperationStartTimeBeforeAndCooperationEndTimeAfter(now, now);
Instant.now());
for (String stationTerminalKey : stationTerminalKeys) { for (String stationTerminalKey : stationTerminalKeys) {
ChargingStationDto chargingStationDto = REDIS.getCacheObject(stationTerminalKey.replace("stationTerminalStatus", ChargingStationDto chargingStationDto = REDIS.getCacheObject(stationTerminalKey.replace("stationTerminalStatus",
"station")); "station"));
@ -55,7 +55,7 @@ public class NotificationStationStatusTask extends CoreDispatcher {
for (XhpcInternetUser xhpcInternetUser : xhpcInternetUserList) { for (XhpcInternetUser xhpcInternetUser : xhpcInternetUserList) {
XhpcStationInternetBlacklist xhpcStationInternetBlacklist = XhpcStationInternetBlacklist xhpcStationInternetBlacklist =
xhpcStationInternetBlacklistRepo.findByChargingStationIdAndInternetUserId(Long.valueOf(stationTerminalKey.split(":")[1]), xhpcStationInternetBlacklistRepo.findByChargingStationIdAndInternetUserId(Long.valueOf(stationTerminalKey.split(":")[1]),
xhpcInternetUser.getId()).orElse(null); xhpcInternetUser.getInternetUserId()).orElse(null);
if (xhpcStationInternetBlacklist != null) continue; if (xhpcStationInternetBlacklist != null) continue;
AuthSecretToken authSecretTokenOut = AuthSecretToken authSecretTokenOut =
authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(xhpcInternetUser.getOperatorIdEvcs(), SECRET_TOKEN_TYPE_OUT).orElse(null); authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(xhpcInternetUser.getOperatorIdEvcs(), SECRET_TOKEN_TYPE_OUT).orElse(null);

View File

@ -12,7 +12,7 @@ public class XhpcInternetUser extends BaseEntity {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "internet_user_id", nullable = false) @Column(name = "internet_user_id", nullable = false)
private Long id; private Long internetUserId;
@Column(name = "name", length = 30) @Column(name = "name", length = 30)
private String name; private String name;
@ -261,14 +261,14 @@ public class XhpcInternetUser extends BaseEntity {
this.name = name; this.name = name;
} }
public Long getId() { public Long getInternetUserId() {
return id; return internetUserId;
} }
public void setId(Long id) { public void setInternetUserId(Long id) {
this.id = id; this.internetUserId = id;
} }
} }