保存未启动三方订单为空的历史订单;优化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 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<String, Object> pileDataModel = REDIS.getCacheMap("pile:" + pileId);
Long stationId = Long.parseLong(pileDataModel.get("stationId").toString());
List<XhpcInternetUser> 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) {

View File

@ -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<StartChargeRequest> 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);
}

View File

@ -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<PageRequest> commonRequest) throws Exception {
@ -54,14 +54,16 @@ public class QueryStationsInfoController {
response.setPageNo(pageNo);
//页码总数
String operatorId = commonRequest.getOperatorId();
final List<XhpcInternetUser> 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> xhpcStationInternetBlacklist =
xhpcStationInternetBlacklistRepo.findByInternetUserId(internetUserId);
List<String> stationKeys = new ArrayList<>(REDIS.keys("station:*"));

View File

@ -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) {

View File

@ -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<XhpcInternetUser, Long>,
QueryByExampleExecutor<XhpcInternetUser>, JpaSpecificationExecutor<XhpcInternetUser> {
XhpcInternetUser findByOperatorIdEvcsAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(String operatorId3rdpty,
Instant now, Instant now2);
XhpcInternetUser findByOperatorIdEvcsLikeAndCooperationStartTimeBeforeAndCooperationEndTimeAfter(String operatorId3rdpty,
Instant now, Instant now2);
List<XhpcInternetUser> findByCooperationStartTimeBeforeAndCooperationEndTimeAfter(Instant now, Instant now1);
List<XhpcInternetUser> findByCooperationStartTimeBeforeAndCooperationEndTimeAfterAndOperatorIdEvcsLike(Instant now,
Instant now1,
String operatorIdEvcs);
@Query("select t.internetUserId from XhpcInternetUser as t where t.operatorIdEvcs like %?1%")
Long queryDbId(String operatorId3rdpty);
}

View File

@ -41,9 +41,9 @@ public class NotificationStationStatusTask extends CoreDispatcher {
Collection<String> stationTerminalKeys = REDIS.keys("stationTerminalStatus:*");
Instant now = Instant.now();
List<XhpcInternetUser> 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);

View File

@ -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;
}
}