diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationsInfoController.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationsInfoController.java index 1e4dd5d9..056f600e 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationsInfoController.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationsInfoController.java @@ -1,6 +1,7 @@ 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; @@ -116,6 +117,9 @@ public class QueryStationsInfoController { 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 piles = getEquipmentInfos(chargingStationDto.getPiles()); station.setEquipmentInfos(piles); stations.add(station); @@ -135,6 +139,65 @@ public class QueryStationsInfoController { return resp; } + private String[] getFees(Long rateModelId) { + + CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(rateModelId.toString())); + if (cacheRateModel.getPp() != null) return cacheRateModel.getPp(); + String[] tfPricesSeq = cacheRateModel.getTfPricesSeq(); + String startTf = "00:00"; + String endTf = ""; + String previousTf = tfPricesSeq[0]; + Integer elecPrice = 0; + Integer svcPrice = 0; + List tfrmes = new ArrayList<>(); //电费 + List tfrmss = new ArrayList<>(); // 服务费 + for (int i = 1; i < tfPricesSeq.length; i++) { + if (!previousTf.equals(tfPricesSeq[i])) { + if (previousTf.equals("00")) { + elecPrice = cacheRateModel.getT1Price(); + svcPrice = cacheRateModel.getT1SvcPrice(); + } else if (previousTf.equals("01")) { + elecPrice = cacheRateModel.getT2Price(); + svcPrice = cacheRateModel.getT2SvcPrice(); + } else if (previousTf.equals("02")) { + elecPrice = cacheRateModel.getT3Price(); + svcPrice = cacheRateModel.getT3SvcPrice(); + } else { // 03 + elecPrice = cacheRateModel.getT4Price(); + svcPrice = cacheRateModel.getT4SvcPrice(); + } + if (i % 2 != 0) { + endTf = String.format("%02d", i / 2).concat(":30"); + } else { + endTf = String.format("%02d", i / 2).concat(":00"); + } + String electfrm = + startTf.concat("~").concat(endTf).concat(",").concat(BigDecimal.valueOf(elecPrice).divide(BigDecimal.valueOf(100000L)).setScale(2).toString()); + String svcfrm = + startTf.concat("~").concat(endTf).concat(",").concat(BigDecimal.valueOf(svcPrice).divide(BigDecimal.valueOf(100000L)).setScale(2).toString()); + previousTf = tfPricesSeq[i]; + startTf = endTf; + tfrmes.add(electfrm); + tfrmss.add(svcfrm); + } + if (i == 47 && !endTf.startsWith("24:00")) { + endTf = "24:00"; + String electfrm = + startTf.concat("~").concat(endTf).concat(",").concat(BigDecimal.valueOf(elecPrice).divide(BigDecimal.valueOf(100000L)).setScale(2).toString()); + String svcfrm = + startTf.concat("~").concat(endTf).concat(",").concat(BigDecimal.valueOf(svcPrice).divide(BigDecimal.valueOf(100000L)).setScale(2).toString()); + tfrmes.add(electfrm); + tfrmss.add(svcfrm); + } + } + String[] pp = new String[2]; + pp[0] = "电费:".concat(String.join(";", tfrmes)); + pp[1] = "服务费:".concat(String.join(";", tfrmss)); + cacheRateModel.setPp(pp); + REDIS.setCacheObject("rateModel:".concat(rateModelId.toString()), cacheRateModel); + return pp; + } + private List getEquipmentInfos(Set pileNoSet) { List equipmentInfos = new ArrayList<>(); @@ -178,7 +241,7 @@ public class QueryStationsInfoController { String gunId = pileNo.concat(String.format("%02d", i)); ConnectorInfo connectorInfo = new ConnectorInfo(); connectorInfo.setConnectorID(gunId); - String connectorName = (String) REDIS.getCacheMapValue("gun:".concat(gunId), "terminalName"); //todo setem in redis! + String connectorName = REDIS.getCacheMapValue("gun:".concat(gunId), "terminalName"); //todo setem in redis! connectorInfo.setConnectorName(connectorName == null ? Integer.parseInt(pileNo.substring(5, 10)) + "号桩 " + GUNNAMES[i] + "枪" : connectorName); diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/redis/CacheRateModel.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/redis/CacheRateModel.java index f1f015ff..e767b97e 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/redis/CacheRateModel.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/data/redis/CacheRateModel.java @@ -12,6 +12,17 @@ public class CacheRateModel { private Integer t4SvcPrice; //谷服务费价格 private Integer lossRate; //计损比例 private String[] tfPricesSeq; //48个字符串48个时段,每个时段的值为4个值之一 → 00: 尖费率 01: 峰费率 02: 平费率 03: 谷费率 + private String[] pp; //00:00~07:00,0.16格式电费/服务费 + + public String[] getPp() { + + return pp; + } + + public void setPp(String[] pp) { + + this.pp = pp; + } public Integer getT1Price() {