三方站点信息查询黑名单判断
This commit is contained in:
parent
58cbecf8ac
commit
fab6246b02
@ -3,9 +3,11 @@ package com.xhpc.evcs.api;
|
|||||||
import com.xhpc.common.api.dto.ChargingStationDto;
|
import com.xhpc.common.api.dto.ChargingStationDto;
|
||||||
import com.xhpc.evcs.domain.XhpcChargingPile;
|
import com.xhpc.evcs.domain.XhpcChargingPile;
|
||||||
import com.xhpc.evcs.domain.XhpcChargingStation;
|
import com.xhpc.evcs.domain.XhpcChargingStation;
|
||||||
|
import com.xhpc.evcs.domain.XhpcStationInternetBlacklist;
|
||||||
import com.xhpc.evcs.dto.*;
|
import com.xhpc.evcs.dto.*;
|
||||||
import com.xhpc.evcs.jpa.XhpcChargingPileRepository;
|
import com.xhpc.evcs.jpa.XhpcChargingPileRepository;
|
||||||
import com.xhpc.evcs.jpa.XhpcChargingStationRepository;
|
import com.xhpc.evcs.jpa.XhpcChargingStationRepository;
|
||||||
|
import com.xhpc.evcs.jpa.XhpcStationInternetBlacklistRepository;
|
||||||
import com.xhpc.evcs.utils.JSONUtil;
|
import com.xhpc.evcs.utils.JSONUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -29,6 +31,8 @@ public class StationsInfoController extends CoreDispatcher {
|
|||||||
private XhpcChargingPileRepository xhpcChargingPileRepository;
|
private XhpcChargingPileRepository xhpcChargingPileRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
private XhpcChargingStationRepository xhpcChargingStationRepository;
|
private XhpcChargingStationRepository xhpcChargingStationRepository;
|
||||||
|
@Autowired
|
||||||
|
private XhpcStationInternetBlacklistRepository xhpcStationInternetBlacklistRepo;
|
||||||
|
|
||||||
@PostMapping("/v1/query_stations_info")
|
@PostMapping("/v1/query_stations_info")
|
||||||
public CommonResponse queryStationsInfo(@RequestBody CommonRequest<PageRequest> commonRequest) throws Exception {
|
public CommonResponse queryStationsInfo(@RequestBody CommonRequest<PageRequest> commonRequest) throws Exception {
|
||||||
@ -37,19 +41,29 @@ public class StationsInfoController extends CoreDispatcher {
|
|||||||
String operatorId = commonRequest.getOperatorId();
|
String operatorId = commonRequest.getOperatorId();
|
||||||
final PageRequest pageRequest = commonRequest.transformDataType(PageRequest.class);
|
final PageRequest pageRequest = commonRequest.transformDataType(PageRequest.class);
|
||||||
List<StationInfo> stations = new ArrayList<>();
|
List<StationInfo> stations = new ArrayList<>();
|
||||||
int pageCount = 1;
|
int pageCount = 0;
|
||||||
if (operatorId.equals("765367656")) {
|
List<XhpcStationInternetBlacklist> xhpcStationInternetBlacklist =
|
||||||
|
xhpcStationInternetBlacklistRepo.findByInternetUserId(operatorId);
|
||||||
List<String> stationKeys = new ArrayList<>(REDIS.keys("station:*"));
|
List<String> stationKeys = new ArrayList<>(REDIS.keys("station:*"));
|
||||||
|
List<String> validStationKeys = new ArrayList<>();
|
||||||
|
for (XhpcStationInternetBlacklist xhpcStationInternetBlack : xhpcStationInternetBlacklist) {
|
||||||
|
for (String stationKey : stationKeys) {
|
||||||
|
if (!stationKey.substring(8).equals(xhpcStationInternetBlack.getChargingStationId().toString())) {
|
||||||
|
validStationKeys.add(stationKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (validStationKeys.size() > 0) {
|
||||||
final Integer pageSize = pageRequest.getPageSize();
|
final Integer pageSize = pageRequest.getPageSize();
|
||||||
int fullpage = stationKeys.size() == 0 ? 0 : stationKeys.size() / pageSize;
|
int fullpage = validStationKeys.size() == 0 ? 0 : validStationKeys.size() / pageSize;
|
||||||
final Integer pageNo = pageRequest.getPageNo();
|
final Integer pageNo = pageRequest.getPageNo();
|
||||||
int plus = stationKeys.size() % pageSize;
|
int plus = validStationKeys.size() % pageSize;
|
||||||
assert (pageCount >= pageNo) : "too large pageNo";
|
assert (pageCount >= pageNo) : "too large pageNo";
|
||||||
pageCount = fullpage + (plus == 0 ? 0 : 1);
|
pageCount = fullpage + (plus == 0 ? 0 : 1);
|
||||||
if (pageCount >= pageNo) {
|
if (pageCount >= pageNo) {
|
||||||
Integer lastOne = stationKeys.size() < pageNo * pageSize ? stationKeys.size() : pageNo * pageSize;
|
Integer lastOne = validStationKeys.size() < pageNo * pageSize ? validStationKeys.size() : pageNo * pageSize;
|
||||||
for (int i = ((pageNo - 1) * pageSize); i < lastOne; i++) {
|
for (int i = ((pageNo - 1) * pageSize); i < lastOne; i++) {
|
||||||
final String stationKey = stationKeys.get(i);
|
final String stationKey = validStationKeys.get(i);
|
||||||
ChargingStationDto chargingStationDto = REDIS.getCacheObject(stationKey);
|
ChargingStationDto chargingStationDto = REDIS.getCacheObject(stationKey);
|
||||||
if (chargingStationDto.getPiles() != null) {
|
if (chargingStationDto.getPiles() != null) {
|
||||||
StationInfo station = new StationInfo();
|
StationInfo station = new StationInfo();
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|||||||
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@ -14,4 +15,7 @@ public interface XhpcStationInternetBlacklistRepository extends JpaRepository<Xh
|
|||||||
|
|
||||||
|
|
||||||
Optional<XhpcStationInternetBlacklist> findByChargingStationIdAndInternetUserId(Long stationId, String substring);
|
Optional<XhpcStationInternetBlacklist> findByChargingStationIdAndInternetUserId(Long stationId, String substring);
|
||||||
|
|
||||||
|
List<XhpcStationInternetBlacklist> findByInternetUserId(String substring);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user