大致完成query_station_info接口(未测试)
This commit is contained in:
parent
771a4c8baf
commit
68387d099f
@ -3,7 +3,6 @@ package com.xhpc.evcs.api;
|
||||
import com.xhpc.common.api.dto.ChargingStationDto;
|
||||
import com.xhpc.common.data.redis.CacheRateModel;
|
||||
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;
|
||||
@ -18,7 +17,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -41,13 +39,14 @@ public class QueryStationsInfoController {
|
||||
@PostMapping("/v1/query_stations_info")
|
||||
public CommonResponse queryStationsInfo(@RequestBody(required = false) CommonRequest<PageRequest> commonRequest) throws Exception {
|
||||
|
||||
assert false;
|
||||
//当前页数
|
||||
PageRequest pageRequest1 = commonRequest.transformDataType(PageRequest.class);
|
||||
Integer pageNo1 = pageRequest1.getPageNo();
|
||||
PageStationsInfoResponse response = new PageStationsInfoResponse();
|
||||
response.setPageNo(pageNo1);
|
||||
//页码总数
|
||||
String operatorId = commonRequest.getOperatorId();
|
||||
final PageRequest pageRequest = commonRequest.transformDataType(PageRequest.class);
|
||||
List<StationInfo> stations = new ArrayList<>();
|
||||
int pageCount = 0;
|
||||
List<XhpcStationInternetBlacklist> xhpcStationInternetBlacklist =
|
||||
xhpcStationInternetBlacklistRepo.findByInternetUserId(operatorId);
|
||||
List<XhpcStationInternetBlacklist> xhpcStationInternetBlacklist = xhpcStationInternetBlacklistRepo.findByInternetUserId(operatorId);
|
||||
List<String> stationKeys = new ArrayList<>(REDIS.keys("station:*"));
|
||||
List<String> validStationKeys = new ArrayList<>();
|
||||
for (String stationKey : stationKeys) {
|
||||
@ -65,73 +64,44 @@ public class QueryStationsInfoController {
|
||||
}
|
||||
}
|
||||
if (validStationKeys.size() > 0) {
|
||||
final Integer pageSize = pageRequest.getPageSize();
|
||||
int fullpage = validStationKeys.size() == 0 ? 0 : validStationKeys.size() / pageSize;
|
||||
final Integer pageNo = pageRequest.getPageNo();
|
||||
int plus = validStationKeys.size() % pageSize;
|
||||
assert (pageCount >= pageNo) : "too large pageNo";
|
||||
pageCount = fullpage + (plus == 0 ? 0 : 1);
|
||||
if (pageCount >= pageNo) {
|
||||
Integer lastOne = validStationKeys.size() < pageNo * pageSize ? validStationKeys.size() : pageNo * pageSize;
|
||||
for (int i = ((pageNo - 1) * pageSize); i < lastOne; i++) {
|
||||
final String stationKey = validStationKeys.get(i);
|
||||
ChargingStationDto chargingStationDto = REDIS.getCacheObject(stationKey);
|
||||
if (chargingStationDto.getPiles() != null) { //todo rm dup or-else?
|
||||
StationInfo station = new StationInfo();
|
||||
station.setStationStatus(50);
|
||||
final String stationId = stationKey.replace("station:", "");
|
||||
station.setStationId(stationId);
|
||||
Double lat = chargingStationDto.getLat();
|
||||
if (lat == null) {
|
||||
XhpcChargingStation stationExample = new XhpcChargingStation();
|
||||
stationExample.setId(Long.parseLong(stationId));
|
||||
Example<XhpcChargingStation> example = Example.of(stationExample);
|
||||
XhpcChargingStation xhpcChargingStation =
|
||||
xhpcChargingStationRepository.findOne(example).orElse(null);
|
||||
if (null != xhpcChargingStation) {
|
||||
chargingStationDto.setLat(new BigDecimal(xhpcChargingStation.getLatitude()).setScale(6,
|
||||
RoundingMode.HALF_UP).doubleValue());
|
||||
chargingStationDto.setLng(new BigDecimal(xhpcChargingStation.getLongitude()).setScale(6,
|
||||
RoundingMode.HALF_UP).doubleValue());
|
||||
chargingStationDto.setType(xhpcChargingStation.getType());
|
||||
chargingStationDto.setOperatorId(xhpcChargingStation.getOperatorIdEvcs() == null ? "MA6DFCTD5"
|
||||
: xhpcChargingStation.getOperatorIdEvcs());
|
||||
chargingStationDto.setAddress(xhpcChargingStation.getAddress());
|
||||
chargingStationDto.setAreaCode(xhpcChargingStation.getAreaCode().toString());
|
||||
chargingStationDto.setName(xhpcChargingStation.getName());
|
||||
chargingStationDto.setServiceTel(xhpcChargingStation.getServiceTel());
|
||||
chargingStationDto.setParkNums(xhpcChargingStation.getParkNums());
|
||||
REDIS.setCacheObject(stationKey, chargingStationDto);
|
||||
}
|
||||
}
|
||||
station.setAddress(chargingStationDto.getAddress());
|
||||
station.setStationLat(chargingStationDto.getLat());
|
||||
station.setStationLng(chargingStationDto.getLng());
|
||||
station.setStationType(chargingStationDto.getType());
|
||||
station.setStationStatus(50);
|
||||
station.setParkNums(chargingStationDto.getParkNums());
|
||||
station.setOperatorId(chargingStationDto.getOperatorId());
|
||||
station.setEquipmentOwnerId(chargingStationDto.getOperatorId());
|
||||
station.setStationName(chargingStationDto.getName());
|
||||
station.setCountryCode("CN");
|
||||
station.setServiceTel(chargingStationDto.getServiceTel());
|
||||
station.setAreaCode(chargingStationDto.getAreaCode());
|
||||
station.setConstruction(chargingStationDto.getConstruction());
|
||||
String[] fees = getFees(chargingStationDto.getRateModelId());
|
||||
station.setElectricityFee(fees[0]);
|
||||
station.setServiceFee(fees[1]);
|
||||
List<EquipmentInfo> piles = getEquipmentInfos(chargingStationDto.getPiles());
|
||||
station.setEquipmentInfos(piles);
|
||||
stations.add(station);
|
||||
}
|
||||
}
|
||||
}
|
||||
Integer pageSize1 = pageRequest1.getPageSize();
|
||||
int totalPage = validStationKeys.size() % pageSize1 == 0 ? validStationKeys.size() % pageSize1 : (validStationKeys.size() % pageSize1) + 1;
|
||||
response.setPageCount(totalPage);
|
||||
}
|
||||
PageStationsInfoResponse response = new PageStationsInfoResponse();
|
||||
response.setItemSize(stations.size());
|
||||
response.setPageNo(pageRequest.getPageNo());
|
||||
response.setPageCount(pageCount);
|
||||
response.setStationInfos(stations);
|
||||
//总记录条数
|
||||
response.setItemSize(validStationKeys.size());
|
||||
|
||||
//充电站信息列表
|
||||
List<StationInfo> stationInfos = new ArrayList<>();
|
||||
//计算每页开始索引
|
||||
Integer pageSize1 = pageRequest1.getPageSize();
|
||||
int startIndex = (pageNo1 - 1) * pageSize1;
|
||||
int endIndex = startIndex + (pageSize1 - 1);
|
||||
for (int i = startIndex; i <= endIndex; i++) {
|
||||
String stationKey = validStationKeys.get(i);
|
||||
ChargingStationDto chargingStationDto = REDIS.getCacheObject(stationKey);
|
||||
StationInfo stationInfo = new StationInfo();
|
||||
stationInfo.setStationId(String.valueOf(chargingStationDto.getStationId()));
|
||||
stationInfo.setOperatorId(chargingStationDto.getOperatorId());
|
||||
stationInfo.setEquipmentOwnerId(chargingStationDto.getOperatorId());
|
||||
stationInfo.setStationName(chargingStationDto.getName());
|
||||
stationInfo.setCountryCode("CN");
|
||||
stationInfo.setAreaCode(chargingStationDto.getAreaCode());
|
||||
stationInfo.setAddress(chargingStationDto.getAddress());
|
||||
stationInfo.setServiceTel(chargingStationDto.getServiceTel());
|
||||
stationInfo.setStationType(chargingStationDto.getType());
|
||||
stationInfo.setStationStatus(50);
|
||||
stationInfo.setParkNums(chargingStationDto.getParkNums());
|
||||
stationInfo.setStationLng(chargingStationDto.getLng());
|
||||
stationInfo.setStationLat(chargingStationDto.getLat());
|
||||
stationInfo.setConstruction(chargingStationDto.getConstruction());
|
||||
//获取该充电站的下的所有充电设备列表
|
||||
Set<String> piles = chargingStationDto.getPiles();
|
||||
List<EquipmentInfo> equipmentInfos = getEquipmentInfos(piles);
|
||||
stationInfo.setEquipmentInfos(equipmentInfos);
|
||||
stationInfos.add(stationInfo);
|
||||
}
|
||||
response.setStationInfos(stationInfos);
|
||||
CommonResponse resp = new CommonResponse();
|
||||
resp.setRet("0");
|
||||
resp.setMsg("Query station info success");
|
||||
@ -139,6 +109,104 @@ public class QueryStationsInfoController {
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
||||
// String operatorId = commonRequest.getOperatorId();
|
||||
// final PageRequest pageRequest = commonRequest.transformDataType(PageRequest.class);
|
||||
// List<StationInfo> stations = new ArrayList<>();
|
||||
// int pageCount = 0;
|
||||
// List<XhpcStationInternetBlacklist> xhpcStationInternetBlacklist =
|
||||
// xhpcStationInternetBlacklistRepo.findByInternetUserId(operatorId);
|
||||
// List<String> stationKeys = new ArrayList<>(REDIS.keys("station:*"));
|
||||
// List<String> validStationKeys = new ArrayList<>();
|
||||
// for (String stationKey : stationKeys) {
|
||||
// boolean isValid = true;
|
||||
// for (XhpcStationInternetBlacklist xhpcStationInternetBlack : xhpcStationInternetBlacklist) {
|
||||
// if (stationKey.substring(8).equals(xhpcStationInternetBlack.getChargingStationId().toString())) {
|
||||
// isValid = false;
|
||||
// }
|
||||
// }
|
||||
// ChargingStationDto chargingStationDto = REDIS.getCacheObject(stationKey);
|
||||
// if (chargingStationDto.getPiles() != null) {
|
||||
// if (isValid) {
|
||||
// validStationKeys.add(stationKey);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (validStationKeys.size() > 0) {
|
||||
// final Integer pageSize = pageRequest.getPageSize();
|
||||
// int fullpage = validStationKeys.size() == 0 ? 0 : validStationKeys.size() / pageSize;
|
||||
// final Integer pageNo = pageRequest.getPageNo();
|
||||
// int plus = validStationKeys.size() % pageSize;
|
||||
// assert (pageCount >= pageNo) : "too large pageNo";
|
||||
// pageCount = fullpage + (plus == 0 ? 0 : 1);
|
||||
// if (pageCount >= pageNo) {
|
||||
// Integer lastOne = validStationKeys.size() < pageNo * pageSize ? validStationKeys.size() : pageNo * pageSize;
|
||||
// for (int i = ((pageNo - 1) * pageSize); i < lastOne; i++) {
|
||||
// final String stationKey = validStationKeys.get(i);
|
||||
// ChargingStationDto chargingStationDto = REDIS.getCacheObject(stationKey);
|
||||
// if (chargingStationDto.getPiles() != null) { //todo rm dup or-else?
|
||||
// StationInfo station = new StationInfo();
|
||||
// station.setStationStatus(50);
|
||||
// final String stationId = stationKey.replace("station:", "");
|
||||
// station.setStationId(stationId);
|
||||
// Double lat = chargingStationDto.getLat();
|
||||
// if (lat == null) {
|
||||
// XhpcChargingStation stationExample = new XhpcChargingStation();
|
||||
// stationExample.setId(Long.parseLong(stationId));
|
||||
// Example<XhpcChargingStation> example = Example.of(stationExample);
|
||||
// XhpcChargingStation xhpcChargingStation =
|
||||
// xhpcChargingStationRepository.findOne(example).orElse(null);
|
||||
// if (null != xhpcChargingStation) {
|
||||
// chargingStationDto.setLat(new BigDecimal(xhpcChargingStation.getLatitude()).setScale(6,
|
||||
// RoundingMode.HALF_UP).doubleValue());
|
||||
// chargingStationDto.setLng(new BigDecimal(xhpcChargingStation.getLongitude()).setScale(6,
|
||||
// RoundingMode.HALF_UP).doubleValue());
|
||||
// chargingStationDto.setType(xhpcChargingStation.getType());
|
||||
// chargingStationDto.setOperatorId(xhpcChargingStation.getOperatorIdEvcs() == null ? "MA6DFCTD5"
|
||||
// : xhpcChargingStation.getOperatorIdEvcs());
|
||||
// chargingStationDto.setAddress(xhpcChargingStation.getAddress());
|
||||
// chargingStationDto.setAreaCode(xhpcChargingStation.getAreaCode().toString());
|
||||
// chargingStationDto.setName(xhpcChargingStation.getName());
|
||||
// chargingStationDto.setServiceTel(xhpcChargingStation.getServiceTel());
|
||||
// chargingStationDto.setParkNums(xhpcChargingStation.getParkNums());
|
||||
// REDIS.setCacheObject(stationKey, chargingStationDto);
|
||||
// }
|
||||
// }
|
||||
// station.setAddress(chargingStationDto.getAddress());
|
||||
// station.setStationLat(chargingStationDto.getLat());
|
||||
// station.setStationLng(chargingStationDto.getLng());
|
||||
// station.setStationType(chargingStationDto.getType());
|
||||
// station.setStationStatus(50);
|
||||
// station.setParkNums(chargingStationDto.getParkNums());
|
||||
// station.setOperatorId(chargingStationDto.getOperatorId());
|
||||
// station.setEquipmentOwnerId(chargingStationDto.getOperatorId());
|
||||
// station.setStationName(chargingStationDto.getName());
|
||||
// station.setCountryCode("CN");
|
||||
// station.setServiceTel(chargingStationDto.getServiceTel());
|
||||
// station.setAreaCode(chargingStationDto.getAreaCode());
|
||||
// station.setConstruction(chargingStationDto.getConstruction());
|
||||
// String[] fees = getFees(chargingStationDto.getRateModelId());
|
||||
// station.setElectricityFee(fees[0]);
|
||||
// station.setServiceFee(fees[1]);
|
||||
// List<EquipmentInfo> piles = getEquipmentInfos(chargingStationDto.getPiles());
|
||||
// station.setEquipmentInfos(piles);
|
||||
// stations.add(station);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// PageStationsInfoResponse response = new PageStationsInfoResponse();
|
||||
// response.setItemSize(stations.size());
|
||||
// response.setPageNo(pageRequest.getPageNo());
|
||||
// response.setPageCount(pageCount);
|
||||
// response.setStationInfos(stations);
|
||||
// CommonResponse resp = new CommonResponse();
|
||||
// resp.setRet("0");
|
||||
// resp.setMsg("Query station info success");
|
||||
// resp.setData(JSONUtil.toJSONString(response));
|
||||
// return resp;
|
||||
// }
|
||||
|
||||
private String[] getFees(Long rateModelId) {
|
||||
|
||||
CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(rateModelId.toString()));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user