桩号白名单接口完善

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;
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.domain.XhpcChargingPile;
import com.xhpc.common.domain.XhpcTerminal;
@ -68,7 +68,7 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService{
}
//插入redis 桩的编号
ChargingPileWhitelistDto charging = new ChargingPileWhitelistDto();
ChargingPileDto charging = new ChargingPileDto();
charging.setStationId(chargingStationId);
charging.setPileNo(serialNumber);
powerPileService.addPileWhitelist(charging);

View File

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

View File

@ -1,9 +1,6 @@
package com.xhpc.common.api.dto;
/**
* 费率
*/
public class ChargingPileWhitelistDto {
public class ChargingPileDto {
private Long stationId;
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;
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.api.PowerPileService;
import com.xhpc.common.data.down.StartChargingData;
@ -10,8 +10,6 @@ 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<PowerPileService> {
@ -30,7 +28,7 @@ public class PowerPileFallbackFactory implements FallbackFactory<PowerPileServic
}
@Override
public R addPileWhitelist(ChargingPileWhitelistDto chargingPileWhitelist) {
public R addPileWhitelist(ChargingPileDto chargingPileDto) {
return R.fail("增加充电桩白名单失败:" + cause.getMessage());
}

View File

@ -1,9 +1,12 @@
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.domain.XhpcChargingPile;
import org.springframework.web.bind.annotation.*;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import static com.xhpc.pp.server.ChargingPileServer.REDIS;
@ -12,11 +15,30 @@ import static com.xhpc.pp.server.ChargingPileServer.REDIS;
public class PileController {
@PostMapping("pile/whitelist")
public Object addWhitelist(@RequestBody Set<XhpcChargingPile> whitelist) {
public Object addWhitelist(@RequestBody ChargingPileDto chargingPileDto) {
Set<XhpcChargingPile> cacheWhitelist = REDIS.getCacheSet("PILE_WHITELIST");
cacheWhitelist.addAll(whitelist);
REDIS.setCacheSet("PILE_WHITELIST", cacheWhitelist);
Set<String> pileWhitelist = REDIS.getCacheSet("PILE_WHITELIST");
String pileNo = chargingPileDto.getPileNo();
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();
}

View File

@ -1,5 +1,6 @@
package com.xhpc.pp.controller;
import com.xhpc.common.api.dto.ChargingStationDto;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.data.redis.CacheRateModel;
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) {
String skey = "station:".concat(stationId.toString());
Map<String, Object> cacheStation = REDIS.getCacheMap(skey);
cacheStation.put("rateModelId", rateModelId);
cacheStation.put("rateModel", rateModel);
ChargingStationDto cacheStation = REDIS.getCacheObject(skey);
cacheStation.setRateModelId(rateModelId);
cacheStation.setRateModel(rateModel);
REDIS.setCacheObject(skey, cacheStation);
return R.ok();
}