快电ing

This commit is contained in:
ZZ 2021-10-25 18:50:51 +08:00
parent fab6246b02
commit 98fc694b9e
5 changed files with 38 additions and 32 deletions

View File

@ -5,8 +5,6 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -29,14 +27,13 @@ public class ConnectorStatusInfo {
public final static int BOOKED = 4;//占用预约锁定) public final static int BOOKED = 4;//占用预约锁定)
public final static int ERROR = 255;//故障 public final static int ERROR = 255;//故障
@Id
@JsonProperty("ConnectorID") @JsonProperty("ConnectorID")
private String connectorID; private String connectorID;
@JsonProperty("OperatorID") @JsonIgnore()
private String operatorID; private String operatorID;
@JsonProperty("Status") @JsonProperty("Status")
private Integer status; private Integer status;
@Transient
@JsonIgnore @JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>(); private Map<String, Object> additionalProperties = new HashMap<String, Object>();

View File

@ -32,7 +32,7 @@ public class EquipmentInfo {
@JsonProperty("Power") @JsonProperty("Power")
public Double power; public Double power;
@JsonProperty("ConnectorInfos") @JsonProperty("ConnectorInfos")
public List<ConnectorInfo> connectorInfos = null; public List<ConnectorStatusInfo> connectorStatusInfos;
@JsonProperty("EquipmentLng") @JsonProperty("EquipmentLng")
public Double equipmentLng; public Double equipmentLng;
@JsonProperty("EquipmentLat") @JsonProperty("EquipmentLat")
@ -56,7 +56,7 @@ public class EquipmentInfo {
public String toString() { public String toString() {
return new ToStringBuilder(this).append("equipmentID", equipmentID).append("manufacturerID", manufacturerID).append( return new ToStringBuilder(this).append("equipmentID", equipmentID).append("manufacturerID", manufacturerID).append(
"equipmentType", equipmentType).append("power", power).append("connectorInfos", connectorInfos).append( "equipmentType", equipmentType).append("power", power).append("connectorInfos", connectorStatusInfos).append(
"equipmentLng", equipmentLng).append("equipmentLat", equipmentLat).append("additionalProperties", "equipmentLng", equipmentLng).append("equipmentLat", equipmentLat).append("additionalProperties",
additionalProperties).toString(); additionalProperties).toString();
} }

View File

@ -46,9 +46,16 @@ public class StationsInfoController extends CoreDispatcher {
xhpcStationInternetBlacklistRepo.findByInternetUserId(operatorId); xhpcStationInternetBlacklistRepo.findByInternetUserId(operatorId);
List<String> stationKeys = new ArrayList<>(REDIS.keys("station:*")); List<String> stationKeys = new ArrayList<>(REDIS.keys("station:*"));
List<String> validStationKeys = new ArrayList<>(); List<String> validStationKeys = new ArrayList<>();
for (XhpcStationInternetBlacklist xhpcStationInternetBlack : xhpcStationInternetBlacklist) {
for (String stationKey : stationKeys) { for (String stationKey : stationKeys) {
if (!stationKey.substring(8).equals(xhpcStationInternetBlack.getChargingStationId().toString())) { 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); validStationKeys.add(stationKey);
} }
} }
@ -65,7 +72,7 @@ public class StationsInfoController extends CoreDispatcher {
for (int i = ((pageNo - 1) * pageSize); i < lastOne; i++) { for (int i = ((pageNo - 1) * pageSize); i < lastOne; i++) {
final String stationKey = validStationKeys.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) { //todo rm dup or-else?
StationInfo station = new StationInfo(); StationInfo station = new StationInfo();
station.setStationStatus(50L); station.setStationStatus(50L);
final String stationId = stationKey.replace("station:", ""); final String stationId = stationKey.replace("station:", "");
@ -119,13 +126,14 @@ public class StationsInfoController extends CoreDispatcher {
for (String pileNo : pileNoSet) { for (String pileNo : pileNoSet) {
final Map<String, Object> cachePile = REDIS.getCacheMap("pile:".concat(pileNo)); final Map<String, Object> cachePile = REDIS.getCacheMap("pile:".concat(pileNo));
Integer connectorType = (Integer) cachePile.get("connectorType"); Integer connectorType = (Integer) cachePile.get("connectorType");
if (connectorType == null) { if (connectorType == null) { //未缓存
XhpcChargingPile pileExample = new XhpcChargingPile(); XhpcChargingPile pileExample = new XhpcChargingPile();
pileExample.setSerialNumber(pileNo); pileExample.setSerialNumber(pileNo);
Example<XhpcChargingPile> example = Example.of(pileExample); Example<XhpcChargingPile> example = Example.of(pileExample);
XhpcChargingPile xhpcChargingPile = xhpcChargingPileRepository.findOne(example).orElse(null); XhpcChargingPile xhpcChargingPile = xhpcChargingPileRepository.findOne(example).orElse(null);
if (xhpcChargingPile != 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("voltageUpperLimits", xhpcChargingPile.getMaxVoltage().intValue());
cachePile.put("voltageLowerLimits", xhpcChargingPile.getMinVoltage().intValue()); cachePile.put("voltageLowerLimits", xhpcChargingPile.getMinVoltage().intValue());
cachePile.put("current", xhpcChargingPile.getCurrent()); cachePile.put("current", xhpcChargingPile.getCurrent());
@ -140,31 +148,32 @@ public class StationsInfoController extends CoreDispatcher {
equipmentInfo.setEquipmentID(pileNo); equipmentInfo.setEquipmentID(pileNo);
equipmentInfo.setEquipmentType((Integer) cachePile.get("equipmentType")); equipmentInfo.setEquipmentType((Integer) cachePile.get("equipmentType"));
equipmentInfo.setPower((Double) cachePile.get("power")); equipmentInfo.setPower((Double) cachePile.get("power"));
equipmentInfo.setConnectorInfos(getConnectorInfos(pileNo, cachePile)); equipmentInfo.setConnectorStatusInfos(getConnectorInfos(pileNo, cachePile));
equipmentInfos.add(equipmentInfo); equipmentInfos.add(equipmentInfo);
} }
return equipmentInfos; return equipmentInfos;
} }
private List<ConnectorInfo> getConnectorInfos(String pileNo, Map<String, Object> cachePile) { private List<ConnectorStatusInfo> getConnectorInfos(String pileNo, Map<String, Object> cachePile) {
List<ConnectorInfo> connectorInfos = new ArrayList<>(); List<ConnectorStatusInfo> connectorStatusInfoList = new ArrayList<>();
final Object gunNumCache = cachePile.get("gunNum"); Integer gunNumCache = (Integer) cachePile.get("gunNum");
if (gunNumCache == null) return connectorInfos; gunNumCache = gunNumCache == null ? 1 : gunNumCache;
int gunNum = (int) gunNumCache; for (int i = 1; i <= gunNumCache; i++) {
for (int i = 1; i <= gunNum; i++) {
String gunId = pileNo.concat(String.format("%02d", i)); String gunId = pileNo.concat(String.format("%02d", i));
ConnectorInfo connectorInfo = new ConnectorInfo(); ConnectorStatusInfo connectorInfo = new ConnectorStatusInfo();
connectorInfo.setConnectorID(gunId); connectorInfo.setConnectorID(gunId);
connectorInfo.setConnectorType((Integer) cachePile.get("connectorType")); Integer statusInt = REDIS.getCacheMapValue("gun:".concat(gunId), "statusInt");
connectorInfo.setVoltageUpperLimits((Integer) cachePile.get("voltageUpperLimits")); connectorInfo.setStatus(statusInt == null ? 0 : statusInt);
connectorInfo.setVoltageLowerLimits((Integer) cachePile.get("voltageLowerLimits")); // connectorInfo.setConnectorType((Integer) cachePile.get("connectorType"));
connectorInfo.setCurrent((Integer) cachePile.get("current")); // connectorInfo.setVoltageUpperLimits((Integer) cachePile.get("voltageUpperLimits"));
connectorInfo.setPower((Double) cachePile.get("power")); // connectorInfo.setVoltageLowerLimits((Integer) cachePile.get("voltageLowerLimits"));
connectorInfo.setNationalStandard((Integer) cachePile.get("nationalStandard")); // connectorInfo.setCurrent((Integer) cachePile.get("current"));
connectorInfos.add(connectorInfo); // connectorInfo.setPower((Double) cachePile.get("power"));
// connectorInfo.setNationalStandard((Integer) cachePile.get("nationalStandard"));
connectorStatusInfoList.add(connectorInfo);
} }
return connectorInfos; return connectorStatusInfoList;
} }
} }

View File

@ -180,7 +180,7 @@ public class HexUtils {
public static void main(String[] args) { 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")); // System.out.println(reverseHexInt("FF00"));
// byte[] data1 = toBytes(reverseHex("10270000")); // byte[] data1 = toBytes(reverseHex("10270000"));
// System.out.println(toInteger(data1, 0, 4)); // System.out.println(toInteger(data1, 0, 4));

View File

@ -21,7 +21,7 @@ public class TestController {
@GetMapping("test/{pno}/{ono}/{b}/{gid}") @GetMapping("test/{pno}/{ono}/{b}/{gid}")
public R test(@PathVariable String pno, @PathVariable String ono, @PathVariable int b, @PathVariable String gid) throws NacosException { 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; // int serverPort = 8848;
// String serverAddr = serverIp + ":" + serverPort; // String serverAddr = serverIp + ":" + serverPort;
// NamingService namingService = NacosFactory.createNamingService(serverAddr); // NamingService namingService = NacosFactory.createNamingService(serverAddr);