三方站点信息查询黑名单判断

This commit is contained in:
ZZ 2021-10-25 17:34:17 +08:00
parent 58cbecf8ac
commit fab6246b02
2 changed files with 25 additions and 7 deletions

View File

@ -3,9 +3,11 @@ package com.xhpc.evcs.api;
import com.xhpc.common.api.dto.ChargingStationDto;
import com.xhpc.evcs.domain.XhpcChargingPile;
import com.xhpc.evcs.domain.XhpcChargingStation;
import com.xhpc.evcs.domain.XhpcStationInternetBlacklist;
import com.xhpc.evcs.dto.*;
import com.xhpc.evcs.jpa.XhpcChargingPileRepository;
import com.xhpc.evcs.jpa.XhpcChargingStationRepository;
import com.xhpc.evcs.jpa.XhpcStationInternetBlacklistRepository;
import com.xhpc.evcs.utils.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -29,6 +31,8 @@ public class StationsInfoController extends CoreDispatcher {
private XhpcChargingPileRepository xhpcChargingPileRepository;
@Autowired
private XhpcChargingStationRepository xhpcChargingStationRepository;
@Autowired
private XhpcStationInternetBlacklistRepository xhpcStationInternetBlacklistRepo;
@PostMapping("/v1/query_stations_info")
public CommonResponse queryStationsInfo(@RequestBody CommonRequest<PageRequest> commonRequest) throws Exception {
@ -37,19 +41,29 @@ public class StationsInfoController extends CoreDispatcher {
String operatorId = commonRequest.getOperatorId();
final PageRequest pageRequest = commonRequest.transformDataType(PageRequest.class);
List<StationInfo> stations = new ArrayList<>();
int pageCount = 1;
if (operatorId.equals("765367656")) {
List<String> stationKeys = new ArrayList<>(REDIS.keys("station:*"));
int pageCount = 0;
List<XhpcStationInternetBlacklist> xhpcStationInternetBlacklist =
xhpcStationInternetBlacklistRepo.findByInternetUserId(operatorId);
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();
int fullpage = stationKeys.size() == 0 ? 0 : stationKeys.size() / pageSize;
int fullpage = validStationKeys.size() == 0 ? 0 : validStationKeys.size() / pageSize;
final Integer pageNo = pageRequest.getPageNo();
int plus = stationKeys.size() % pageSize;
int plus = validStationKeys.size() % pageSize;
assert (pageCount >= pageNo) : "too large pageNo";
pageCount = fullpage + (plus == 0 ? 0 : 1);
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++) {
final String stationKey = stationKeys.get(i);
final String stationKey = validStationKeys.get(i);
ChargingStationDto chargingStationDto = REDIS.getCacheObject(stationKey);
if (chargingStationDto.getPiles() != null) {
StationInfo station = new StationInfo();

View File

@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
@ -14,4 +15,7 @@ public interface XhpcStationInternetBlacklistRepository extends JpaRepository<Xh
Optional<XhpcStationInternetBlacklist> findByChargingStationIdAndInternetUserId(Long stationId, String substring);
List<XhpcStationInternetBlacklist> findByInternetUserId(String substring);
}