From 98fc694b9ea4581fc454b177319a89e6f318101f Mon Sep 17 00:00:00 2001 From: ZZ Date: Mon, 25 Oct 2021 18:50:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=AB=E7=94=B5ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xhpc/evcs/dto/ConnectorStatusInfo.java | 7 +-- .../java/com/xhpc/evcs/dto/EquipmentInfo.java | 6 +-- .../xhpc/evcs/api/StationsInfoController.java | 53 +++++++++++-------- .../main/java/com/xhpc/pp/utils/HexUtils.java | 2 +- .../xhpc/pp/controller/TestController.java | 2 +- 5 files changed, 38 insertions(+), 32 deletions(-) diff --git a/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/ConnectorStatusInfo.java b/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/ConnectorStatusInfo.java index 0efb7b43..7d4b5ecf 100644 --- a/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/ConnectorStatusInfo.java +++ b/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/ConnectorStatusInfo.java @@ -5,8 +5,6 @@ import lombok.Getter; import lombok.Setter; import org.apache.commons.lang3.builder.ToStringBuilder; -import javax.persistence.Id; -import javax.persistence.Transient; import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -29,14 +27,13 @@ public class ConnectorStatusInfo { public final static int BOOKED = 4;//占用(预约锁定) public final static int ERROR = 255;//故障 - @Id @JsonProperty("ConnectorID") private String connectorID; - @JsonProperty("OperatorID") + @JsonIgnore() private String operatorID; @JsonProperty("Status") private Integer status; - @Transient + @JsonIgnore private Map additionalProperties = new HashMap(); diff --git a/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/EquipmentInfo.java b/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/EquipmentInfo.java index af7c88d0..164c79fb 100644 --- a/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/EquipmentInfo.java +++ b/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/EquipmentInfo.java @@ -32,7 +32,7 @@ public class EquipmentInfo { @JsonProperty("Power") public Double power; @JsonProperty("ConnectorInfos") - public List connectorInfos = null; + public List connectorStatusInfos; @JsonProperty("EquipmentLng") public Double equipmentLng; @JsonProperty("EquipmentLat") @@ -56,8 +56,8 @@ public class EquipmentInfo { public String toString() { return new ToStringBuilder(this).append("equipmentID", equipmentID).append("manufacturerID", manufacturerID).append( - "equipmentType", equipmentType).append("power", power).append("connectorInfos", connectorInfos).append( - "equipmentLng", equipmentLng).append("equipmentLat", equipmentLat).append("additionalProperties", + "equipmentType", equipmentType).append("power", power).append("connectorInfos", connectorStatusInfos).append( + "equipmentLng", equipmentLng).append("equipmentLat", equipmentLat).append("additionalProperties", additionalProperties).toString(); } diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/StationsInfoController.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/StationsInfoController.java index 506730a2..944861f1 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/StationsInfoController.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/StationsInfoController.java @@ -46,9 +46,16 @@ public class StationsInfoController extends CoreDispatcher { xhpcStationInternetBlacklistRepo.findByInternetUserId(operatorId); List stationKeys = new ArrayList<>(REDIS.keys("station:*")); List validStationKeys = new ArrayList<>(); - for (XhpcStationInternetBlacklist xhpcStationInternetBlack : xhpcStationInternetBlacklist) { - for (String stationKey : stationKeys) { - if (!stationKey.substring(8).equals(xhpcStationInternetBlack.getChargingStationId().toString())) { + 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); } } @@ -65,7 +72,7 @@ public class StationsInfoController extends CoreDispatcher { for (int i = ((pageNo - 1) * pageSize); i < lastOne; i++) { final String stationKey = validStationKeys.get(i); ChargingStationDto chargingStationDto = REDIS.getCacheObject(stationKey); - if (chargingStationDto.getPiles() != null) { + if (chargingStationDto.getPiles() != null) { //todo rm dup or-else? StationInfo station = new StationInfo(); station.setStationStatus(50L); final String stationId = stationKey.replace("station:", ""); @@ -119,13 +126,14 @@ public class StationsInfoController extends CoreDispatcher { for (String pileNo : pileNoSet) { final Map cachePile = REDIS.getCacheMap("pile:".concat(pileNo)); Integer connectorType = (Integer) cachePile.get("connectorType"); - if (connectorType == null) { + if (connectorType == null) { //未缓存 XhpcChargingPile pileExample = new XhpcChargingPile(); pileExample.setSerialNumber(pileNo); Example example = Example.of(pileExample); XhpcChargingPile xhpcChargingPile = xhpcChargingPileRepository.findOne(example).orElse(null); if (xhpcChargingPile != null) { - cachePile.put("connectorType", xhpcChargingPile.getType() == 1 ? Integer.valueOf(4) : Integer.valueOf(3)); + cachePile.put("connectorType", xhpcChargingPile.getType() == null ? Integer.valueOf(4) : + Integer.valueOf(xhpcChargingPile.getType())); cachePile.put("voltageUpperLimits", xhpcChargingPile.getMaxVoltage().intValue()); cachePile.put("voltageLowerLimits", xhpcChargingPile.getMinVoltage().intValue()); cachePile.put("current", xhpcChargingPile.getCurrent()); @@ -140,31 +148,32 @@ public class StationsInfoController extends CoreDispatcher { equipmentInfo.setEquipmentID(pileNo); equipmentInfo.setEquipmentType((Integer) cachePile.get("equipmentType")); equipmentInfo.setPower((Double) cachePile.get("power")); - equipmentInfo.setConnectorInfos(getConnectorInfos(pileNo, cachePile)); + equipmentInfo.setConnectorStatusInfos(getConnectorInfos(pileNo, cachePile)); equipmentInfos.add(equipmentInfo); } return equipmentInfos; } - private List getConnectorInfos(String pileNo, Map cachePile) { + private List getConnectorInfos(String pileNo, Map cachePile) { - List connectorInfos = new ArrayList<>(); - final Object gunNumCache = cachePile.get("gunNum"); - if (gunNumCache == null) return connectorInfos; - int gunNum = (int) gunNumCache; - for (int i = 1; i <= gunNum; i++) { + List connectorStatusInfoList = new ArrayList<>(); + Integer gunNumCache = (Integer) cachePile.get("gunNum"); + gunNumCache = gunNumCache == null ? 1 : gunNumCache; + for (int i = 1; i <= gunNumCache; i++) { String gunId = pileNo.concat(String.format("%02d", i)); - ConnectorInfo connectorInfo = new ConnectorInfo(); + ConnectorStatusInfo connectorInfo = new ConnectorStatusInfo(); connectorInfo.setConnectorID(gunId); - connectorInfo.setConnectorType((Integer) cachePile.get("connectorType")); - connectorInfo.setVoltageUpperLimits((Integer) cachePile.get("voltageUpperLimits")); - connectorInfo.setVoltageLowerLimits((Integer) cachePile.get("voltageLowerLimits")); - connectorInfo.setCurrent((Integer) cachePile.get("current")); - connectorInfo.setPower((Double) cachePile.get("power")); - connectorInfo.setNationalStandard((Integer) cachePile.get("nationalStandard")); - connectorInfos.add(connectorInfo); + Integer statusInt = REDIS.getCacheMapValue("gun:".concat(gunId), "statusInt"); + connectorInfo.setStatus(statusInt == null ? 0 : statusInt); +// connectorInfo.setConnectorType((Integer) cachePile.get("connectorType")); +// connectorInfo.setVoltageUpperLimits((Integer) cachePile.get("voltageUpperLimits")); +// connectorInfo.setVoltageLowerLimits((Integer) cachePile.get("voltageLowerLimits")); +// connectorInfo.setCurrent((Integer) cachePile.get("current")); +// connectorInfo.setPower((Double) cachePile.get("power")); +// connectorInfo.setNationalStandard((Integer) cachePile.get("nationalStandard")); + connectorStatusInfoList.add(connectorInfo); } - return connectorInfos; + return connectorStatusInfoList; } } diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/pp/utils/HexUtils.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/pp/utils/HexUtils.java index 07b09dee..7960ba98 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/pp/utils/HexUtils.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/pp/utils/HexUtils.java @@ -180,7 +180,7 @@ public class HexUtils { public static void main(String[] args) { -// System.out.println(Integer.parseInt("FF00", 16)); + System.out.println(Long.valueOf(10L).toString()); // System.out.println(reverseHexInt("FF00")); // byte[] data1 = toBytes(reverseHex("10270000")); // System.out.println(toInteger(data1, 0, 4)); diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/TestController.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/TestController.java index 57aef7e4..28e207ed 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/TestController.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/TestController.java @@ -21,7 +21,7 @@ public class TestController { @GetMapping("test/{pno}/{ono}/{b}/{gid}") public R test(@PathVariable String pno, @PathVariable String ono, @PathVariable int b, @PathVariable String gid) throws NacosException { -// String serverIp = "172.31.183.135"; +// String serverIp = "127.0.0.1"; // int serverPort = 8848; // String serverAddr = serverIp + ":" + serverPort; // NamingService namingService = NacosFactory.createNamingService(serverAddr);