桩号白名单接口完善

This commit is contained in:
ZZ 2021-07-29 15:00:13 +08:00
parent b93671cece
commit de7be19c31
7 changed files with 92 additions and 23 deletions

View File

@ -1,6 +1,6 @@
package com.xhpc.charging.station.service; package com.xhpc.charging.station.service;
import com.xhpc.common.api.dto.ChargingPileWhitelistDto; import com.xhpc.common.api.dto.ChargingPileDto;
import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.domain.XhpcChargingPile; import com.xhpc.common.domain.XhpcChargingPile;
import com.xhpc.common.domain.XhpcTerminal; import com.xhpc.common.domain.XhpcTerminal;
@ -68,7 +68,7 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService{
} }
//插入redis 桩的编号 //插入redis 桩的编号
ChargingPileWhitelistDto charging = new ChargingPileWhitelistDto(); ChargingPileDto charging = new ChargingPileDto();
charging.setStationId(chargingStationId); charging.setStationId(chargingStationId);
charging.setPileNo(serialNumber); charging.setPileNo(serialNumber);
powerPileService.addPileWhitelist(charging); powerPileService.addPileWhitelist(charging);

View File

@ -1,12 +1,11 @@
package com.xhpc.common.api; package com.xhpc.common.api;
import com.xhpc.common.api.dto.ChargingPileWhitelistDto; import com.xhpc.common.api.dto.ChargingPileDto;
import com.xhpc.common.core.constant.ServiceNameConstants; import com.xhpc.common.core.constant.ServiceNameConstants;
import com.xhpc.common.core.domain.R; import com.xhpc.common.core.domain.R;
import com.xhpc.common.api.factory.PowerPileFallbackFactory; import com.xhpc.common.api.factory.PowerPileFallbackFactory;
import com.xhpc.common.data.down.StartChargingData; import com.xhpc.common.data.down.StartChargingData;
import com.xhpc.common.data.redis.CacheRateModel; import com.xhpc.common.data.redis.CacheRateModel;
import com.xhpc.common.domain.XhpcChargingStation;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
@ -14,8 +13,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import java.util.Set;
@FeignClient(contextId = "powerPileService", value = ServiceNameConstants.PILE_SERVICE, fallbackFactory = PowerPileFallbackFactory.class) @FeignClient(contextId = "powerPileService", value = ServiceNameConstants.PILE_SERVICE, fallbackFactory = PowerPileFallbackFactory.class)
public interface PowerPileService { public interface PowerPileService {
@ -23,7 +20,7 @@ public interface PowerPileService {
R startCharging(@Validated @RequestBody StartChargingData startChargingData); R startCharging(@Validated @RequestBody StartChargingData startChargingData);
@PostMapping(value = "/pile/whitelist") @PostMapping(value = "/pile/whitelist")
R addPileWhitelist(@RequestBody ChargingPileWhitelistDto chargingPileWhitelist); R addPileWhitelist(@RequestBody ChargingPileDto chargingPileDto);
@DeleteMapping(value = "/pile/whitelist/{stationId}/{pileNo}") @DeleteMapping(value = "/pile/whitelist/{stationId}/{pileNo}")
R deletePileWhitelist(@PathVariable("stationId") Long stationId, @PathVariable("pileNo") String pileNo); R deletePileWhitelist(@PathVariable("stationId") Long stationId, @PathVariable("pileNo") String pileNo);

View File

@ -1,9 +1,6 @@
package com.xhpc.common.api.dto; package com.xhpc.common.api.dto;
/** public class ChargingPileDto {
* 费率
*/
public class ChargingPileWhitelistDto {
private Long stationId; private Long stationId;
private String pileNo; private String pileNo;

View File

@ -0,0 +1,54 @@
package com.xhpc.common.api.dto;
import com.xhpc.common.data.redis.CacheRateModel;
import java.util.Set;
public class ChargingStationDto {
private Long stationId;
private Set<String> piles;
private Long rateModelId;
private CacheRateModel rateModel;
public Long getStationId() {
return stationId;
}
public void setStationId(Long stationId) {
this.stationId = stationId;
}
public Set<String> getPiles() {
return piles;
}
public void setPiles(Set<String> piles) {
this.piles = piles;
}
public Long getRateModelId() {
return rateModelId;
}
public void setRateModelId(Long rateModelId) {
this.rateModelId = rateModelId;
}
public CacheRateModel getRateModel() {
return rateModel;
}
public void setRateModel(CacheRateModel rateModel) {
this.rateModel = rateModel;
}
}

View File

@ -1,6 +1,6 @@
package com.xhpc.common.api.factory; package com.xhpc.common.api.factory;
import com.xhpc.common.api.dto.ChargingPileWhitelistDto; import com.xhpc.common.api.dto.ChargingPileDto;
import com.xhpc.common.core.domain.R; import com.xhpc.common.core.domain.R;
import com.xhpc.common.api.PowerPileService; import com.xhpc.common.api.PowerPileService;
import com.xhpc.common.data.down.StartChargingData; import com.xhpc.common.data.down.StartChargingData;
@ -10,8 +10,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Set;
@Component @Component
public class PowerPileFallbackFactory implements FallbackFactory<PowerPileService> { public class PowerPileFallbackFactory implements FallbackFactory<PowerPileService> {
@ -30,7 +28,7 @@ public class PowerPileFallbackFactory implements FallbackFactory<PowerPileServic
} }
@Override @Override
public R addPileWhitelist(ChargingPileWhitelistDto chargingPileWhitelist) { public R addPileWhitelist(ChargingPileDto chargingPileDto) {
return R.fail("增加充电桩白名单失败:" + cause.getMessage()); return R.fail("增加充电桩白名单失败:" + cause.getMessage());
} }

View File

@ -1,9 +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.core.domain.R; import com.xhpc.common.core.domain.R;
import com.xhpc.common.domain.XhpcChargingPile;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import static com.xhpc.pp.server.ChargingPileServer.REDIS; import static com.xhpc.pp.server.ChargingPileServer.REDIS;
@ -12,11 +15,30 @@ import static com.xhpc.pp.server.ChargingPileServer.REDIS;
public class PileController { public class PileController {
@PostMapping("pile/whitelist") @PostMapping("pile/whitelist")
public Object addWhitelist(@RequestBody Set<XhpcChargingPile> whitelist) { public Object addWhitelist(@RequestBody ChargingPileDto chargingPileDto) {
Set<XhpcChargingPile> cacheWhitelist = REDIS.getCacheSet("PILE_WHITELIST"); Set<String> pileWhitelist = REDIS.getCacheSet("PILE_WHITELIST");
cacheWhitelist.addAll(whitelist); String pileNo = chargingPileDto.getPileNo();
REDIS.setCacheSet("PILE_WHITELIST", cacheWhitelist); pileWhitelist.add(pileNo);
REDIS.setCacheSet("PILE_WHITELIST", pileWhitelist);
String pileKey = "pile:".concat(pileNo);
Map<String, Object> 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) {
cacheStation = new ChargingStationDto();
cacheStation.setStationId(stationId);
}
Set<String> stationPiles = cacheStation.getPiles();
if (stationPiles == null) {
stationPiles = new HashSet<>();
cacheStation.setPiles(stationPiles);
}
stationPiles.add(pileNo);
REDIS.setCacheObject(stationKey, cacheStation);
return R.ok(); return R.ok();
} }

View File

@ -1,5 +1,6 @@
package com.xhpc.pp.controller; package com.xhpc.pp.controller;
import com.xhpc.common.api.dto.ChargingStationDto;
import com.xhpc.common.core.domain.R; import com.xhpc.common.core.domain.R;
import com.xhpc.common.data.redis.CacheRateModel; import com.xhpc.common.data.redis.CacheRateModel;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -18,9 +19,9 @@ public class StationController {
public Object setStationRateModel(@PathVariable Long stationId, @PathVariable Long rateModelId, @RequestBody CacheRateModel rateModel) { public Object setStationRateModel(@PathVariable Long stationId, @PathVariable Long rateModelId, @RequestBody CacheRateModel rateModel) {
String skey = "station:".concat(stationId.toString()); String skey = "station:".concat(stationId.toString());
Map<String, Object> cacheStation = REDIS.getCacheMap(skey); ChargingStationDto cacheStation = REDIS.getCacheObject(skey);
cacheStation.put("rateModelId", rateModelId); cacheStation.setRateModelId(rateModelId);
cacheStation.put("rateModel", rateModel); cacheStation.setRateModel(rateModel);
REDIS.setCacheObject(skey, cacheStation); REDIS.setCacheObject(skey, cacheStation);
return R.ok(); return R.ok();
} }