桩号白名单接口完善done.
This commit is contained in:
parent
16792b4b98
commit
e07d3d6789
@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService{
|
|||||||
XhpcTerminal xhpcTerminal =new XhpcTerminal();
|
XhpcTerminal xhpcTerminal =new XhpcTerminal();
|
||||||
xhpcTerminal.setChargingStationId(chargingStationId);
|
xhpcTerminal.setChargingStationId(chargingStationId);
|
||||||
xhpcTerminal.setChargingPileId(chargingPileId);
|
xhpcTerminal.setChargingPileId(chargingPileId);
|
||||||
xhpcTerminal.setName(serialNumber+"-"+(i+1));
|
xhpcTerminal.setName(serialNumber + "-" + (i + 1));
|
||||||
xhpcTerminal.setPileSerialNumber(serialNumber);
|
xhpcTerminal.setPileSerialNumber(serialNumber);
|
||||||
xhpcTerminal.setWorkStatus(2);
|
xhpcTerminal.setWorkStatus(2);
|
||||||
xhpcTerminal.setStatus(0);
|
xhpcTerminal.setStatus(0);
|
||||||
@ -68,10 +69,9 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//插入redis 桩的编号
|
//插入redis 桩的编号
|
||||||
ChargingPileDto charging = new ChargingPileDto();
|
HashSet<String> noSet = new HashSet<>();
|
||||||
charging.setStationId(chargingStationId);
|
noSet.add(serialNumber);
|
||||||
charging.setPileNo(serialNumber);
|
powerPileService.addPileWhitelist(chargingStationId, noSet);
|
||||||
powerPileService.addPileWhitelist(charging);
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,19 +13,21 @@ 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 {
|
||||||
|
|
||||||
@PostMapping(value = "/charging/start")
|
@PostMapping("/charging/start")
|
||||||
R startCharging(@Validated @RequestBody StartChargingData startChargingData);
|
R startCharging(@Validated @RequestBody StartChargingData startChargingData);
|
||||||
|
|
||||||
@PostMapping(value = "/pile/whitelist")
|
@PostMapping("pile/whitelist/add/{stationId}")
|
||||||
R addPileWhitelist(@RequestBody ChargingPileDto chargingPileDto);
|
R addPileWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set<String> pileNoSet);
|
||||||
|
|
||||||
@DeleteMapping(value = "/pile/whitelist/{stationId}/{pileNo}")
|
@DeleteMapping("pile/whitelist/delete/{stationId}")
|
||||||
R deletePileWhitelist(@PathVariable("stationId") Long stationId, @PathVariable("pileNo") String pileNo);
|
R deletePileWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set<String> pileNoSet);
|
||||||
|
|
||||||
@PostMapping(value = "/station/rateModel/{stationId}/{rateModelId}")
|
@PostMapping("/station/rateModel/{stationId}/{rateModelId}")
|
||||||
R setStationRateModelId(@PathVariable("stationId") Long stationId, @PathVariable("rateModelId") Long rateModelId, @RequestBody CacheRateModel rateModel);
|
R setStationRateModel(@PathVariable("stationId") Long stationId, @PathVariable("rateModelId") Long rateModelId, @RequestBody CacheRateModel rateModel);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,6 @@ public class ChargingStationDto {
|
|||||||
private Long stationId;
|
private Long stationId;
|
||||||
private Set<String> piles;
|
private Set<String> piles;
|
||||||
private Long rateModelId;
|
private Long rateModelId;
|
||||||
private CacheRateModel rateModel;
|
|
||||||
|
|
||||||
public Long getStationId() {
|
public Long getStationId() {
|
||||||
|
|
||||||
@ -41,14 +40,4 @@ public class ChargingStationDto {
|
|||||||
this.rateModelId = rateModelId;
|
this.rateModelId = rateModelId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CacheRateModel getRateModel() {
|
|
||||||
|
|
||||||
return rateModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRateModel(CacheRateModel rateModel) {
|
|
||||||
|
|
||||||
this.rateModel = rateModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,8 @@ 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> {
|
||||||
|
|
||||||
@ -28,19 +30,19 @@ public class PowerPileFallbackFactory implements FallbackFactory<PowerPileServic
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public R addPileWhitelist(ChargingPileDto chargingPileDto) {
|
public R addPileWhitelist(Long stationId, Set<String> pileNoSet) {
|
||||||
|
|
||||||
return R.fail("增加充电桩白名单失败:" + cause.getMessage());
|
return R.fail("增加充电桩白名单失败:" + cause.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public R deletePileWhitelist(Long stationId, String pileNo) {
|
public R deletePileWhitelist(Long stationId, Set<String> pileNoSet) {
|
||||||
|
|
||||||
return R.fail("删除充电桩白名单失败:" + cause.getMessage());
|
return R.fail("删除充电桩白名单失败:" + cause.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public R setStationRateModelId(Long stationId, Long rateModelId, CacheRateModel rateModel) {
|
public R setStationRateModel(Long stationId, Long rateModelId, CacheRateModel rateModel) {
|
||||||
|
|
||||||
return R.fail("设置电站费率模型失败:" + cause.getMessage());
|
return R.fail("设置电站费率模型失败:" + cause.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -111,8 +111,9 @@ public class ChargingController {
|
|||||||
// not defined or implemented yet
|
// not defined or implemented yet
|
||||||
}
|
}
|
||||||
String msg = HexUtils.toHex(data).concat(ServiceResult.HEX_OK);
|
String msg = HexUtils.toHex(data).concat(ServiceResult.HEX_OK);
|
||||||
log.info("msg2bsent2pile:{}", msg);
|
msg = msg.concat(CRCCalculator.calcCrc(msg));
|
||||||
return HexUtils.toBytes(msg.concat(CRCCalculator.calcCrc(msg)));
|
log.info("charging order[{}], send msg to pile: {}", startChargingData.getOrderNo(), msg);
|
||||||
|
return HexUtils.toBytes(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.xhpc.common.core.domain.R;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -14,18 +15,12 @@ import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
|||||||
@RestController
|
@RestController
|
||||||
public class PileController {
|
public class PileController {
|
||||||
|
|
||||||
@PostMapping("pile/whitelist")
|
@PostMapping("pile/whitelist/add/{stationId}")
|
||||||
public Object addWhitelist(@RequestBody ChargingPileDto chargingPileDto) {
|
public Object addWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set<String> pileNoSet) {
|
||||||
|
|
||||||
Set<String> pileWhitelist = REDIS.getCacheSet("PILE_WHITELIST");
|
Set<String> pileWhitelist = REDIS.getCacheSet("PILE_WHITELIST");
|
||||||
String pileNo = chargingPileDto.getPileNo();
|
pileWhitelist.addAll(pileNoSet);
|
||||||
pileWhitelist.add(pileNo);
|
|
||||||
REDIS.setCacheSet("PILE_WHITELIST", pileWhitelist);
|
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());
|
String stationKey = "station:".concat(stationId.toString());
|
||||||
ChargingStationDto cacheStation = REDIS.getCacheObject(stationKey);
|
ChargingStationDto cacheStation = REDIS.getCacheObject(stationKey);
|
||||||
if (cacheStation == null) {
|
if (cacheStation == null) {
|
||||||
@ -34,19 +29,25 @@ public class PileController {
|
|||||||
}
|
}
|
||||||
Set<String> stationPiles = cacheStation.getPiles();
|
Set<String> stationPiles = cacheStation.getPiles();
|
||||||
if (stationPiles == null) {
|
if (stationPiles == null) {
|
||||||
stationPiles = new HashSet<>();
|
cacheStation.setPiles(pileNoSet);
|
||||||
cacheStation.setPiles(stationPiles);
|
} else {
|
||||||
|
stationPiles.addAll(pileNoSet);
|
||||||
}
|
}
|
||||||
stationPiles.add(pileNo);
|
|
||||||
REDIS.setCacheObject(stationKey, cacheStation);
|
REDIS.setCacheObject(stationKey, cacheStation);
|
||||||
|
for (String pileNo : pileNoSet) {
|
||||||
|
String pileKey = "pile:".concat(pileNo);
|
||||||
|
Map<String, Object> cachePile = REDIS.getCacheMap(pileKey);
|
||||||
|
cachePile.put("stationId", stationId);
|
||||||
|
REDIS.setCacheMap(pileKey, cachePile);
|
||||||
|
}
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("pile/whitelist/{pileNo}")
|
@PostMapping("pile/whitelist/delete/{stationId}")
|
||||||
public Object deleteWhitelist(@PathVariable String pileNo) {
|
public Object deleteWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set<String> pileNoSet) {
|
||||||
|
|
||||||
Set<String> cacheWhitelist = REDIS.getCacheSet("PILE_WHITELIST");
|
Set<String> cacheWhitelist = REDIS.getCacheSet("PILE_WHITELIST");
|
||||||
cacheWhitelist.remove(pileNo);
|
cacheWhitelist.removeAll(pileNoSet);
|
||||||
REDIS.setCacheSet("PILE_WHITELIST", cacheWhitelist);
|
REDIS.setCacheSet("PILE_WHITELIST", cacheWhitelist);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,10 @@ 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.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
||||||
|
|
||||||
@ -21,8 +24,13 @@ public class StationController {
|
|||||||
String skey = "station:".concat(stationId.toString());
|
String skey = "station:".concat(stationId.toString());
|
||||||
ChargingStationDto cacheStation = REDIS.getCacheObject(skey);
|
ChargingStationDto cacheStation = REDIS.getCacheObject(skey);
|
||||||
cacheStation.setRateModelId(rateModelId);
|
cacheStation.setRateModelId(rateModelId);
|
||||||
cacheStation.setRateModel(rateModel);
|
|
||||||
REDIS.setCacheObject(skey, cacheStation);
|
REDIS.setCacheObject(skey, cacheStation);
|
||||||
|
String rkey = "rateModel:".concat(rateModelId.toString());
|
||||||
|
REDIS.setCacheObject(rkey, rateModel);
|
||||||
|
String srmkey = "settingRateModel:".concat(stationId.toString());
|
||||||
|
Map<String, Object> rateModelPilesMap = new HashMap<>();
|
||||||
|
rateModelPilesMap.put(rateModelId.toString(), cacheStation.getPiles());
|
||||||
|
REDIS.setCacheMap(srmkey, rateModelPilesMap);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user