From e07d3d678941cf9bb08be5413abbc70d527f871a Mon Sep 17 00:00:00 2001 From: ZZ Date: Thu, 29 Jul 2021 16:11:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=A9=E5=8F=B7=E7=99=BD=E5=90=8D=E5=8D=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AE=8C=E5=96=84done.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/XhpcChargingPileServiceImpl.java | 10 +++--- .../com/xhpc/common/api/PowerPileService.java | 16 +++++----- .../common/api/dto/ChargingStationDto.java | 11 ------- .../api/factory/PowerPileFallbackFactory.java | 8 +++-- .../pp/controller/ChargingController.java | 5 +-- .../xhpc/pp/controller/PileController.java | 31 ++++++++++--------- .../xhpc/pp/controller/StationController.java | 10 +++++- 7 files changed, 47 insertions(+), 44 deletions(-) diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java index a82952cf..fc1b26d8 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingPileServiceImpl.java @@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; @@ -59,7 +60,7 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService{ XhpcTerminal xhpcTerminal =new XhpcTerminal(); xhpcTerminal.setChargingStationId(chargingStationId); xhpcTerminal.setChargingPileId(chargingPileId); - xhpcTerminal.setName(serialNumber+"-"+(i+1)); + xhpcTerminal.setName(serialNumber + "-" + (i + 1)); xhpcTerminal.setPileSerialNumber(serialNumber); xhpcTerminal.setWorkStatus(2); xhpcTerminal.setStatus(0); @@ -68,10 +69,9 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService{ } //插入redis 桩的编号 - ChargingPileDto charging = new ChargingPileDto(); - charging.setStationId(chargingStationId); - charging.setPileNo(serialNumber); - powerPileService.addPileWhitelist(charging); + HashSet noSet = new HashSet<>(); + noSet.add(serialNumber); + powerPileService.addPileWhitelist(chargingStationId, noSet); return AjaxResult.success(); } diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PowerPileService.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PowerPileService.java index 689af6e9..ebaa7265 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PowerPileService.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PowerPileService.java @@ -13,19 +13,21 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import java.util.Set; + @FeignClient(contextId = "powerPileService", value = ServiceNameConstants.PILE_SERVICE, fallbackFactory = PowerPileFallbackFactory.class) public interface PowerPileService { - @PostMapping(value = "/charging/start") + @PostMapping("/charging/start") R startCharging(@Validated @RequestBody StartChargingData startChargingData); - @PostMapping(value = "/pile/whitelist") - R addPileWhitelist(@RequestBody ChargingPileDto chargingPileDto); + @PostMapping("pile/whitelist/add/{stationId}") + R addPileWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set pileNoSet); - @DeleteMapping(value = "/pile/whitelist/{stationId}/{pileNo}") - R deletePileWhitelist(@PathVariable("stationId") Long stationId, @PathVariable("pileNo") String pileNo); + @DeleteMapping("pile/whitelist/delete/{stationId}") + R deletePileWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set pileNoSet); - @PostMapping(value = "/station/rateModel/{stationId}/{rateModelId}") - R setStationRateModelId(@PathVariable("stationId") Long stationId, @PathVariable("rateModelId") Long rateModelId, @RequestBody CacheRateModel rateModel); + @PostMapping("/station/rateModel/{stationId}/{rateModelId}") + R setStationRateModel(@PathVariable("stationId") Long stationId, @PathVariable("rateModelId") Long rateModelId, @RequestBody CacheRateModel rateModel); } diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/dto/ChargingStationDto.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/dto/ChargingStationDto.java index 27408160..c4c86aa8 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/dto/ChargingStationDto.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/dto/ChargingStationDto.java @@ -9,7 +9,6 @@ public class ChargingStationDto { private Long stationId; private Set piles; private Long rateModelId; - private CacheRateModel rateModel; public Long getStationId() { @@ -41,14 +40,4 @@ public class ChargingStationDto { this.rateModelId = rateModelId; } - public CacheRateModel getRateModel() { - - return rateModel; - } - - public void setRateModel(CacheRateModel rateModel) { - - this.rateModel = rateModel; - } - } diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/PowerPileFallbackFactory.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/PowerPileFallbackFactory.java index c5ac7ab7..147c6328 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/PowerPileFallbackFactory.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/PowerPileFallbackFactory.java @@ -10,6 +10,8 @@ import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.stereotype.Component; +import java.util.Set; + @Component public class PowerPileFallbackFactory implements FallbackFactory { @@ -28,19 +30,19 @@ public class PowerPileFallbackFactory implements FallbackFactory pileNoSet) { return R.fail("增加充电桩白名单失败:" + cause.getMessage()); } @Override - public R deletePileWhitelist(Long stationId, String pileNo) { + public R deletePileWhitelist(Long stationId, Set pileNoSet) { return R.fail("删除充电桩白名单失败:" + cause.getMessage()); } @Override - public R setStationRateModelId(Long stationId, Long rateModelId, CacheRateModel rateModel) { + public R setStationRateModel(Long stationId, Long rateModelId, CacheRateModel rateModel) { return R.fail("设置电站费率模型失败:" + cause.getMessage()); } diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java index 86e3baff..3b154739 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java @@ -111,8 +111,9 @@ public class ChargingController { // not defined or implemented yet } String msg = HexUtils.toHex(data).concat(ServiceResult.HEX_OK); - log.info("msg2bsent2pile:{}", msg); - return HexUtils.toBytes(msg.concat(CRCCalculator.calcCrc(msg))); + msg = msg.concat(CRCCalculator.calcCrc(msg)); + log.info("charging order[{}], send msg to pile: {}", startChargingData.getOrderNo(), msg); + return HexUtils.toBytes(msg); } } diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/PileController.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/PileController.java index 34b9bc60..1dad93e3 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/PileController.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/PileController.java @@ -6,6 +6,7 @@ import com.xhpc.common.core.domain.R; import org.springframework.web.bind.annotation.*; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -14,18 +15,12 @@ import static com.xhpc.pp.server.ChargingPileServer.REDIS; @RestController public class PileController { - @PostMapping("pile/whitelist") - public Object addWhitelist(@RequestBody ChargingPileDto chargingPileDto) { + @PostMapping("pile/whitelist/add/{stationId}") + public Object addWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set pileNoSet) { Set pileWhitelist = REDIS.getCacheSet("PILE_WHITELIST"); - String pileNo = chargingPileDto.getPileNo(); - pileWhitelist.add(pileNo); + pileWhitelist.addAll(pileNoSet); REDIS.setCacheSet("PILE_WHITELIST", pileWhitelist); - String pileKey = "pile:".concat(pileNo); - Map cachePile = REDIS.getCacheMap(pileKey); - Long stationId = chargingPileDto.getStationId(); - cachePile.put("stationId", stationId); - REDIS.setCacheMap(pileKey, cachePile); String stationKey = "station:".concat(stationId.toString()); ChargingStationDto cacheStation = REDIS.getCacheObject(stationKey); if (cacheStation == null) { @@ -34,19 +29,25 @@ public class PileController { } Set stationPiles = cacheStation.getPiles(); if (stationPiles == null) { - stationPiles = new HashSet<>(); - cacheStation.setPiles(stationPiles); + cacheStation.setPiles(pileNoSet); + } else { + stationPiles.addAll(pileNoSet); } - stationPiles.add(pileNo); REDIS.setCacheObject(stationKey, cacheStation); + for (String pileNo : pileNoSet) { + String pileKey = "pile:".concat(pileNo); + Map cachePile = REDIS.getCacheMap(pileKey); + cachePile.put("stationId", stationId); + REDIS.setCacheMap(pileKey, cachePile); + } return R.ok(); } - @DeleteMapping("pile/whitelist/{pileNo}") - public Object deleteWhitelist(@PathVariable String pileNo) { + @PostMapping("pile/whitelist/delete/{stationId}") + public Object deleteWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set pileNoSet) { Set cacheWhitelist = REDIS.getCacheSet("PILE_WHITELIST"); - cacheWhitelist.remove(pileNo); + cacheWhitelist.removeAll(pileNoSet); REDIS.setCacheSet("PILE_WHITELIST", cacheWhitelist); return R.ok(); } diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/StationController.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/StationController.java index ed1d51c5..12591812 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/StationController.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/StationController.java @@ -8,7 +8,10 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.Set; import static com.xhpc.pp.server.ChargingPileServer.REDIS; @@ -21,8 +24,13 @@ public class StationController { String skey = "station:".concat(stationId.toString()); ChargingStationDto cacheStation = REDIS.getCacheObject(skey); cacheStation.setRateModelId(rateModelId); - cacheStation.setRateModel(rateModel); REDIS.setCacheObject(skey, cacheStation); + String rkey = "rateModel:".concat(rateModelId.toString()); + REDIS.setCacheObject(rkey, rateModel); + String srmkey = "settingRateModel:".concat(stationId.toString()); + Map rateModelPilesMap = new HashMap<>(); + rateModelPilesMap.put(rateModelId.toString(), cacheStation.getPiles()); + REDIS.setCacheMap(srmkey, rateModelPilesMap); return R.ok(); }