diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryEquipAuthController.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryEquipAuthController.java index eb42e951..4d5fa7db 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryEquipAuthController.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryEquipAuthController.java @@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import java.time.Instant; -import java.util.List; import java.util.Map; import static cn.hutool.core.util.NumberUtil.isInteger; @@ -48,16 +47,16 @@ public class QueryEquipAuthController { String pileId = connectorId.substring(0, connectorId.length() - 2); Map pileDataModel = REDIS.getCacheMap("pile:" + pileId); Long stationId = Long.parseLong(pileDataModel.get("stationId").toString()); - List xhpcInternetUserList = - xhpcInternetUserRepository.findByCooperationStartTimeBeforeAndCooperationEndTimeAfterAndOperatorIdEvcsLike(Instant.now(), - Instant.now(), commonRequest.getOperatorId()); - if (xhpcInternetUserList.isEmpty()) { + 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 { - Long internetUserId = xhpcInternetUserList.get(0).getId(); + Long internetUserId = xhpcInternetUser.getInternetUserId(); XhpcStationInternetBlacklist xhpcStationInternetBlacklist = xhpcStationInternetBlacklistRepo.findByChargingStationIdAndInternetUserId(stationId, internetUserId).orElse(null); if (null != xhpcStationInternetBlacklist) { diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStartChargeController.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStartChargeController.java index 24ac3bd2..6c126dee 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStartChargeController.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStartChargeController.java @@ -9,10 +9,7 @@ import com.xhpc.evcs.dto.CommonResponse; import com.xhpc.evcs.dto.StartChargeRequest; import com.xhpc.evcs.dto.StartChargeResponse; import com.xhpc.evcs.encryption.EvcsConst; -import com.xhpc.evcs.jpa.AuthSecretTokenRepository; -import com.xhpc.evcs.jpa.OrderMappingRepository; -import com.xhpc.evcs.jpa.XhpcHistoryOrderRepository; -import com.xhpc.evcs.jpa.XhpcTerminalRepository; +import com.xhpc.evcs.jpa.*; import com.xhpc.evcs.utils.JSONUtil; import com.xhpc.order.domain.XhpcHistoryOrder; import org.springframework.beans.factory.annotation.Autowired; @@ -40,6 +37,8 @@ public class QueryStartChargeController { private XhpcTerminalRepository xhpcTerminalRepository; @Autowired private PileOrderService pileOrderService; + @Autowired + private XhpcInternetUserRepository xhpcInternetUserRepository; @PostMapping(value = "/v1/query_start_charge") public CommonResponse queryStartCharge(@RequestBody CommonRequest commonRequest) throws Exception { @@ -121,14 +120,19 @@ public class QueryStartChargeController { emptyHorder.setEndTime(now); emptyHorder.setCreateTime(now); emptyHorder.setUpdateTime(now); + emptyHorder.setStopReasonEvcs(9); String sn = genOrder(connectorId); etOrderMapping.setXhOrderNo(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.setState(2); emptyHorder.setChargingStationId(REDIS.getCacheMapValue("pile:".concat(connectorId.substring(0, 14)), "stationId")); emptyHorder.setTerminalId(xhpcTerminalRepository.queryDbId(connectorId)); + emptyHorder.setConfirmResult(-1); xhpcHistoryOrderRepository.save(emptyHorder); } diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationsInfoController.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationsInfoController.java index 3f704693..c598f206 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationsInfoController.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationsInfoController.java @@ -41,7 +41,7 @@ public class QueryStationsInfoController { private XhpcChargingStationRepository xhpcChargingStationRepository; @Autowired private XhpcStationInternetBlacklistRepository xhpcStationInternetBlacklistRepo; - private String[] GUNNAMES = {"", "A", "B", "C", "D"}; + private final String[] GUNNAMES = {"", "A", "B", "C", "D"}; @PostMapping("/v1/query_stations_info") public CommonResponse queryStationsInfo(@RequestBody(required = false) CommonRequest commonRequest) throws Exception { @@ -54,14 +54,16 @@ public class QueryStationsInfoController { response.setPageNo(pageNo); //页码总数 String operatorId = commonRequest.getOperatorId(); - final List xhpcInternetUserList = - xhpcInternetUserRepository.findByCooperationStartTimeBeforeAndCooperationEndTimeAfterAndOperatorIdEvcsLike(Instant.now(), Instant.now(), operatorId); - if (xhpcInternetUserList.isEmpty()) { + Instant now = Instant.now(); + XhpcInternetUser xhpcInternetUser = + xhpcInternetUserRepository + .findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(operatorId, now, now); + if (xhpcInternetUser == null) { resp.setRet("1"); resp.setMsg("Not valid internet user/OperatorID"); resp.setData(JSONUtil.toJSONString(response)); } else { - Long internetUserId = xhpcInternetUserList.get(0).getId(); + Long internetUserId = xhpcInternetUser.getInternetUserId(); List xhpcStationInternetBlacklist = xhpcStationInternetBlacklistRepo.findByInternetUserId(internetUserId); List stationKeys = new ArrayList<>(REDIS.keys("station:*")); diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryTokenController.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryTokenController.java index 70103d16..4686b398 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryTokenController.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryTokenController.java @@ -57,7 +57,7 @@ public class QueryTokenController { tokenResponse.setFailReason(0); String data = null; //todo 优化OperatorIdEvcs like XhpcInternetUser xhpcInternetUser = - xhpcInternetUserRepository.findByOperatorIdEvcsAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(tokenRequest.getOperatorId(), Instant.now(), Instant.now()); + xhpcInternetUserRepository.findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(tokenRequest.getOperatorId(), Instant.now(), Instant.now()); if (xhpcInternetUser != null) { String operatorSecret = tokenRequest.getOperatorSecret(); if (operatorSecret == null) { diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/XhpcInternetUserRepository.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/XhpcInternetUserRepository.java index 8bc7d32d..037f7c11 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/XhpcInternetUserRepository.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/XhpcInternetUserRepository.java @@ -3,6 +3,7 @@ package com.xhpc.evcs.jpa; import com.xhpc.evcs.domain.XhpcInternetUser; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.QueryByExampleExecutor; import org.springframework.stereotype.Repository; @@ -13,14 +14,12 @@ import java.util.List; public interface XhpcInternetUserRepository extends JpaRepository, QueryByExampleExecutor, JpaSpecificationExecutor { - XhpcInternetUser findByOperatorIdEvcsAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(String operatorId3rdpty, - Instant now, Instant now2); - + XhpcInternetUser findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(String operatorId3rdpty, + Instant now, Instant now2); List findByCooperationStartTimeBeforeAndCooperationEndTimeAfter(Instant now, Instant now1); - List findByCooperationStartTimeBeforeAndCooperationEndTimeAfterAndOperatorIdEvcsLike(Instant now, - Instant now1, - String operatorIdEvcs); + @Query("select t.internetUserId from XhpcInternetUser as t where t.operatorIdEvcs like %?1%") + Long queryDbId(String operatorId3rdpty); } diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStationStatusTask.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStationStatusTask.java index 1d458b8e..6ec28d03 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStationStatusTask.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStationStatusTask.java @@ -41,9 +41,9 @@ public class NotificationStationStatusTask extends CoreDispatcher { Collection stationTerminalKeys = REDIS.keys("stationTerminalStatus:*"); + Instant now = Instant.now(); List xhpcInternetUserList = - xhpcInternetUserRepository.findByCooperationStartTimeBeforeAndCooperationEndTimeAfter(Instant.now(), - Instant.now()); + xhpcInternetUserRepository.findByCooperationStartTimeBeforeAndCooperationEndTimeAfter(now, now); for (String stationTerminalKey : stationTerminalKeys) { ChargingStationDto chargingStationDto = REDIS.getCacheObject(stationTerminalKey.replace("stationTerminalStatus", "station")); @@ -55,7 +55,7 @@ public class NotificationStationStatusTask extends CoreDispatcher { for (XhpcInternetUser xhpcInternetUser : xhpcInternetUserList) { XhpcStationInternetBlacklist xhpcStationInternetBlacklist = xhpcStationInternetBlacklistRepo.findByChargingStationIdAndInternetUserId(Long.valueOf(stationTerminalKey.split(":")[1]), - xhpcInternetUser.getId()).orElse(null); + xhpcInternetUser.getInternetUserId()).orElse(null); if (xhpcStationInternetBlacklist != null) continue; AuthSecretToken authSecretTokenOut = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(xhpcInternetUser.getOperatorIdEvcs(), SECRET_TOKEN_TYPE_OUT).orElse(null); diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/evcs/domain/XhpcInternetUser.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/evcs/domain/XhpcInternetUser.java index 3f8ed0d3..13120219 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/evcs/domain/XhpcInternetUser.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/evcs/domain/XhpcInternetUser.java @@ -12,7 +12,7 @@ public class XhpcInternetUser extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "internet_user_id", nullable = false) - private Long id; + private Long internetUserId; @Column(name = "name", length = 30) private String name; @@ -261,14 +261,14 @@ public class XhpcInternetUser extends BaseEntity { 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; } }