桩号白名单done.计费模型设置逻辑todo..

This commit is contained in:
ZZ 2021-07-29 16:42:40 +08:00
parent dc8773fc85
commit db1e7397cb
6 changed files with 26 additions and 41 deletions

View File

@ -1,14 +1,11 @@
package com.xhpc.common.api.dto; package com.xhpc.common.api.dto;
import com.xhpc.common.data.redis.CacheRateModel;
import java.util.Set; import java.util.Set;
public class ChargingStationDto { public class ChargingStationDto {
private Long stationId; private Long stationId;
private Set<String> piles; private Set<String> piles;
private Set<String> pilesSettingRateModel;
private Long rateModelId; private Long rateModelId;
public Long getStationId() { public Long getStationId() {
@ -31,16 +28,6 @@ public class ChargingStationDto {
this.piles = piles; this.piles = piles;
} }
public Set<String> getPilesSettingRateModel() {
return pilesSettingRateModel;
}
public void setPilesSettingRateModel(Set<String> pilesSettingRateModel) {
this.pilesSettingRateModel = pilesSettingRateModel;
}
public Long getRateModelId() { public Long getRateModelId() {
return rateModelId; return rateModelId;

View File

@ -2,9 +2,9 @@ package com.xhpc.pp.controller;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.xhpc.common.api.PowerPileService;
import com.xhpc.common.core.domain.R; import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.utils.HttpUtils; import com.xhpc.common.core.utils.HttpUtils;
import com.xhpc.common.api.PowerPileService;
import com.xhpc.common.data.down.StartChargingData; import com.xhpc.common.data.down.StartChargingData;
import com.xhpc.pp.server.ChargingPileServer; import com.xhpc.pp.server.ChargingPileServer;
import com.xhpc.pp.tx.ServiceResult; import com.xhpc.pp.tx.ServiceResult;
@ -49,8 +49,8 @@ public class ChargingController {
public Object startCharging(@Validated @RequestBody StartChargingData startChargingData) { public Object startCharging(@Validated @RequestBody StartChargingData startChargingData) {
String pileNo = startChargingData.getPileNo(); String pileNo = startChargingData.getPileNo();
String pileKey = "pile:".concat(pileNo); String pkey = "pile:".concat(pileNo);
Map<String, String> cachePile = REDIS.getCacheMap(pileKey); Map<String, String> cachePile = REDIS.getCacheMap(pkey);
if (cachePile.isEmpty()) { if (cachePile.isEmpty()) {
return R.fail("充电桩未注册"); return R.fail("充电桩未注册");
} }

View File

@ -1,12 +1,12 @@
package com.xhpc.pp.controller; package com.xhpc.pp.controller;
import com.xhpc.common.api.dto.ChargingPileDto;
import com.xhpc.common.api.dto.ChargingStationDto; import com.xhpc.common.api.dto.ChargingStationDto;
import com.xhpc.common.core.domain.R; import com.xhpc.common.core.domain.R;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -30,17 +30,19 @@ public class PileController {
Set<String> stationPiles = cacheStation.getPiles(); Set<String> stationPiles = cacheStation.getPiles();
if (stationPiles == null) { if (stationPiles == null) {
cacheStation.setPiles(pileNoSet); cacheStation.setPiles(pileNoSet);
cacheStation.setPilesSettingRateModel(pileNoSet);
} else { } else {
cacheStation.getPiles().addAll(pileNoSet); cacheStation.getPiles().addAll(pileNoSet);
cacheStation.getPilesSettingRateModel().addAll(pileNoSet);
} }
REDIS.setCacheObject(stationKey, cacheStation); REDIS.setCacheObject(stationKey, cacheStation);
String rmskey = "rateModelStation:".concat(stationId.toString());
Set<String> cacheSettingRateModelSet = REDIS.getCacheSet(rmskey);
cacheSettingRateModelSet.addAll(pileNoSet);
REDIS.setCacheSet(rmskey, cacheSettingRateModelSet);
for (String pileNo : pileNoSet) { for (String pileNo : pileNoSet) {
String pileKey = "pile:".concat(pileNo); String pkey = "pile:".concat(pileNo);
Map<String, Object> cachePile = REDIS.getCacheMap(pileKey); Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
cachePile.put("stationId", stationId); cachePile.put("stationId", stationId);
REDIS.setCacheMap(pileKey, cachePile); REDIS.setCacheMap(pkey, cachePile);
} }
return R.ok(); return R.ok();
} }
@ -54,8 +56,11 @@ public class PileController {
String stationKey = "station:".concat(stationId.toString()); String stationKey = "station:".concat(stationId.toString());
ChargingStationDto cacheStation = REDIS.getCacheObject(stationKey); ChargingStationDto cacheStation = REDIS.getCacheObject(stationKey);
cacheStation.getPiles().removeAll(pileNoSet); cacheStation.getPiles().removeAll(pileNoSet);
cacheStation.getPilesSettingRateModel().removeAll(pileNoSet);
REDIS.setCacheObject(stationKey, cacheStation); REDIS.setCacheObject(stationKey, cacheStation);
String rmskey = "rateModelStation:".concat(stationId.toString());
Set<String> cacheSettingRateModelSet = REDIS.getCacheSet(rmskey);
cacheSettingRateModelSet.removeAll(pileNoSet);
REDIS.setCacheSet(rmskey, cacheSettingRateModelSet);
return R.ok(); return R.ok();
} }

View File

@ -8,11 +8,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; 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; import static com.xhpc.pp.server.ChargingPileServer.REDIS;
@RestController @RestController
@ -27,10 +22,8 @@ public class StationController {
REDIS.setCacheObject(skey, cacheStation); REDIS.setCacheObject(skey, cacheStation);
String rkey = "rateModel:".concat(rateModelId.toString()); String rkey = "rateModel:".concat(rateModelId.toString());
REDIS.setCacheObject(rkey, rateModel); REDIS.setCacheObject(rkey, rateModel);
String srmkey = "settingRateModel:".concat(stationId.toString()); String rmskey = "rateModelStation:".concat(stationId.toString());
Map<String, Object> rateModelPilesMap = new HashMap<>(); REDIS.setCacheSet(rmskey, cacheStation.getPiles());
rateModelPilesMap.put(rateModelId.toString(), cacheStation.getPiles());
REDIS.setCacheMap(srmkey, rateModelPilesMap);
return R.ok(); return R.ok();
} }

View File

@ -104,11 +104,11 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
} }
ChargingPileServer.putHandler(pileNo, handler); ChargingPileServer.putHandler(pileNo, handler);
ChargingPileServer.putVersion(handler.getName(), (String) req.get("version")); ChargingPileServer.putVersion(handler.getName(), (String) req.get("version"));
String pileKey = "pile:".concat(pileNo); String pkey = "pile:".concat(pileNo);
Map<String, Object> pileCache = REDIS.getCacheMap(pileKey); Map<String, Object> pileCache = REDIS.getCacheMap(pkey);
pileCache.put("status", REGISTERED); pileCache.put("status", REGISTERED);
pileCache.put("svcSrv", getLocalIPAndPort()); pileCache.put("svcSrv", getLocalIPAndPort());
REDIS.setCacheMap(pileKey, pileCache); REDIS.setCacheMap(pkey, pileCache);
cachePileGunSvcSrv("svcSrvPile:", pileNo); cachePileGunSvcSrv("svcSrvPile:", pileNo);
int gunNum = Integer.parseInt(req.get("gunNum").toString()); int gunNum = Integer.parseInt(req.get("gunNum").toString());
for (int gunN = 1; gunN <= gunNum; gunN++) { for (int gunN = 1; gunN <= gunNum; gunN++) {

View File

@ -87,10 +87,10 @@ public class ChargingPileServer {
public static void removeHandler(String pileNo) { public static void removeHandler(String pileNo) {
ClientHandler handler = handlerMap.remove(pileNo); ClientHandler handler = handlerMap.remove(pileNo);
String pileKey = "pile:".concat(pileNo); String pkey = "pile:".concat(pileNo);
Map<String, Object> cacheMap = REDIS.getCacheMap(pileKey); Map<String, Object> cacheMap = REDIS.getCacheMap(pkey);
cacheMap.put("status", DISCONNECTED); cacheMap.put("status", DISCONNECTED);
REDIS.setCacheMap(pileKey, cacheMap); REDIS.setCacheMap(pkey, cacheMap);
if (handler != null) { if (handler != null) {
log.info("remove handler [{}] for [{}]", handler.getName(), pileNo); log.info("remove handler [{}] for [{}]", handler.getName(), pileNo);
pileMap.remove(handler.getName()); pileMap.remove(handler.getName());