服务:桩号白名单,电站费率模型设置/修改(参考showDoc新增文档)
This commit is contained in:
parent
838ed627ba
commit
4665e59741
@ -7,13 +7,26 @@ import com.xhpc.common.data.down.StartChargingData;
|
||||
import com.xhpc.common.data.up.OrderData;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
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 = "/pile/charging/order")
|
||||
@PostMapping(value = "/charging/order")
|
||||
R<OrderData> startCharging(@Validated @RequestBody StartChargingData startChargingData);
|
||||
|
||||
@PostMapping(value = "/pile/whitelist")
|
||||
R addPileWhitelist(@RequestBody Set<String> whitelist);
|
||||
|
||||
@DeleteMapping(value = "/pile/whitelist/{pileNo}")
|
||||
R deletePileWhitelist(@PathVariable("pileNo") String pileNo);
|
||||
|
||||
@DeleteMapping(value = "/station/rateModel/{stationId}/{rateModelId}")
|
||||
R setStationRateModelId(@PathVariable("stationId") Long stationId, @PathVariable("rateModelId") Long rateModelId);
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
package com.xhpc.common.data.redis;
|
||||
|
||||
public class CachePile {
|
||||
|
||||
private Long chargingStationId;
|
||||
private Long rateModelId;
|
||||
private Long pileNo;
|
||||
|
||||
public Long getChargingStationId() {
|
||||
|
||||
return chargingStationId;
|
||||
}
|
||||
|
||||
public void setChargingStationId(Long chargingStationId) {
|
||||
|
||||
this.chargingStationId = chargingStationId;
|
||||
}
|
||||
|
||||
public Long getRateModelId() {
|
||||
|
||||
return rateModelId;
|
||||
}
|
||||
|
||||
public void setRateModelId(Long rateModelId) {
|
||||
|
||||
this.rateModelId = rateModelId;
|
||||
}
|
||||
|
||||
public Long getPileNo() {
|
||||
|
||||
return pileNo;
|
||||
}
|
||||
|
||||
public void setPileNo(Long pileNo) {
|
||||
|
||||
this.pileNo = pileNo;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.xhpc.common.data.redis;
|
||||
|
||||
public class CacheStation {
|
||||
|
||||
private Long chargingPileId;
|
||||
private Long chargingStationId;
|
||||
private Long rateModelId;
|
||||
|
||||
public Long getChargingPileId() {
|
||||
|
||||
return chargingPileId;
|
||||
}
|
||||
|
||||
public void setChargingPileId(Long chargingPileId) {
|
||||
|
||||
this.chargingPileId = chargingPileId;
|
||||
}
|
||||
|
||||
public Long getChargingStationId() {
|
||||
|
||||
return chargingStationId;
|
||||
}
|
||||
|
||||
public void setChargingStationId(Long chargingStationId) {
|
||||
|
||||
this.chargingStationId = chargingStationId;
|
||||
}
|
||||
|
||||
public Long getRateModelId() {
|
||||
|
||||
return rateModelId;
|
||||
}
|
||||
|
||||
public void setRateModelId(Long rateModelId) {
|
||||
|
||||
this.rateModelId = rateModelId;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,10 +1,19 @@
|
||||
package com.xhpc.pp.config;
|
||||
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.xhpc.pp.logic.RegisterLogic;
|
||||
import com.xhpc.pp.utils.SpringContextHolder;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.ruoyi.common.core.utils.GetIpAndPort.getLocalIP;
|
||||
import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
||||
|
||||
@Configuration
|
||||
public class EarlierBeanConf {
|
||||
@ -20,6 +29,26 @@ public class EarlierBeanConf {
|
||||
this.springContextHolder = springContextHolder;
|
||||
}
|
||||
|
||||
public static boolean ifreg(String pileNo) throws NacosException {
|
||||
|
||||
Map<String, Object> cachePile = REDIS.getCacheMap("pile:".concat(pileNo));
|
||||
String server = (String) cachePile.get("server");
|
||||
if (server != null) {
|
||||
String nacosServer = REDIS.getCacheObject("nacos").toString();
|
||||
NamingService namingService = NacosFactory.createNamingService(nacosServer);
|
||||
List<Instance> ppInstances = namingService.getAllInstances("xhpc-power-pile");
|
||||
String status = (String) cachePile.get("status");
|
||||
for (Instance i : ppInstances) {
|
||||
if (i.getIp().concat("#").concat(Integer.valueOf(i.getPort()).toString()).equals(server)) {
|
||||
if (!RegisterLogic.DISCONNECTED.equals(status)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Value("${server.port}")
|
||||
public void setPort(String port) {
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ public class ChargingController {
|
||||
return r;
|
||||
}
|
||||
|
||||
@PostMapping("pile/charging/order")
|
||||
@PostMapping("charging/order")
|
||||
public Object startCharging(@Validated @RequestBody StartChargingData startChargingData) {
|
||||
|
||||
return new OrderData();
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
package com.xhpc.pp.controller;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
||||
|
||||
@RestController
|
||||
public class PileController {
|
||||
|
||||
@PostMapping("pile/whitelist")
|
||||
public Object addWhitelist(@RequestBody Set<String> whitelist) {
|
||||
|
||||
Set<String> cacheWhitelist = REDIS.getCacheSet("PILE_WHITELIST");
|
||||
cacheWhitelist.addAll(whitelist);
|
||||
REDIS.setCacheSet("PILE_WHITELIST", cacheWhitelist);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping("pile/whitelist/{pileNo}")
|
||||
public Object deleteWhitelist(@PathVariable String pileNo) {
|
||||
|
||||
Set<String> cacheWhitelist = REDIS.getCacheSet("PILE_WHITELIST");
|
||||
cacheWhitelist.remove(pileNo);
|
||||
REDIS.setCacheSet("PILE_WHITELIST", cacheWhitelist);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package com.xhpc.pp.controller;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
||||
|
||||
@RestController
|
||||
public class StationController {
|
||||
|
||||
@PostMapping("station/rateModel/{stationId}/{rateModelId}")
|
||||
public Object setStationRateModel(@PathVariable Long stationId, @PathVariable Long rateModelId) {
|
||||
|
||||
String skey = "station:".concat(stationId.toString());
|
||||
Map<String, Object> cacheStation = REDIS.getCacheMap(skey);
|
||||
cacheStation.put("rateModelId", rateModelId);
|
||||
REDIS.setCacheObject(skey, cacheStation);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@ -10,7 +10,6 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@ -31,23 +30,18 @@ public class RegisterLogic implements ServiceLogic {
|
||||
String resultCode = ServiceResult.OK;
|
||||
String hexCode = ServiceResult.HEX_OK;
|
||||
String pileNo = (String) req.get("pileNo");
|
||||
Set<String> pileSnPool = REDIS.getCacheSet("PILE_SN_POOL");
|
||||
// ? = REDIS.getCacheSet(pileNo); todo
|
||||
//todo set rate model to cache
|
||||
if (!pileSnPool.contains(pileNo)) {
|
||||
Set<String> whitelist = REDIS.getCacheSet("PILE_WHITELIST");
|
||||
if (!whitelist.contains(pileNo)) {
|
||||
hexCode = ServiceResult.HEX_FAIL;
|
||||
resultCode = ServiceResult.FAIL;
|
||||
}
|
||||
int gunNum = Integer.parseInt(req.get("gunNum").toString());
|
||||
for (int gunN = 1; gunN <= gunNum; gunN++) {
|
||||
String gunId = String.format("%02d", (int) gunN);
|
||||
Map<String, Object> cacheGun = REDIS.getCacheMap(pileNo.concat(gunId));
|
||||
if (cacheGun == null) {
|
||||
cacheGun = new HashMap<>();
|
||||
}
|
||||
int seq = (int) cacheGun.getOrDefault("seq", 0);
|
||||
cacheGun.put("seq", seq);
|
||||
REDIS.setCacheMap(pileNo.concat(gunId), cacheGun);
|
||||
String pileGun = "gun:".concat(pileNo.concat(gunId));
|
||||
Map<String, Object> cacheGun = REDIS.getCacheMap(pileGun);
|
||||
cacheGun.put("seq", 0);
|
||||
REDIS.setCacheMap(pileGun, cacheGun);
|
||||
}
|
||||
String resultStr = "680C00000002".concat(pileNo).concat(hexCode);
|
||||
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.xhpc.pp.server;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.xhpc.pp.config.EarlierBeanConf;
|
||||
import com.xhpc.pp.domain.ServiceField;
|
||||
import com.xhpc.pp.logic.FieldLogic;
|
||||
import com.xhpc.pp.logic.ServiceMainLogic;
|
||||
@ -17,7 +19,6 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static com.ruoyi.common.core.utils.GetIpAndPort.getLocalIP;
|
||||
import static com.xhpc.pp.config.EarlierBeanConf.getLocalIPAndPort;
|
||||
import static com.xhpc.pp.logic.RegisterLogic.REGISTERED;
|
||||
import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
||||
@ -68,12 +69,12 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
|
||||
}
|
||||
process(handler, d);
|
||||
}
|
||||
} catch (TxException e) {
|
||||
} catch (TxException | NacosException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void process(ClientHandler handler, byte[] data) throws TxException, IOException {
|
||||
private void process(ClientHandler handler, byte[] data) throws TxException, IOException, NacosException {
|
||||
|
||||
String serviceName = HexUtils.toHex(data, 5, 6);
|
||||
String version = ChargingPileServer.getVersion(handler.getName());
|
||||
@ -95,17 +96,24 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void reg(ClientHandler handler, String pileNo, Map<String, Object> req) {
|
||||
private void reg(ClientHandler handler, String pileNo, Map<String, Object> req) throws NacosException {
|
||||
|
||||
if (!EarlierBeanConf.ifreg(pileNo)) {
|
||||
log.info("pile already registered >>>> [{}] ", pileNo);
|
||||
return;
|
||||
}
|
||||
ChargingPileServer.putHandler(pileNo, handler);
|
||||
ChargingPileServer.putVersion(handler.getName(), (String) req.get("version"));
|
||||
Map<String, Object> pileCache = REDIS.getCacheMap(pileNo);
|
||||
String pileKey = "pile:".concat(pileNo);
|
||||
Map<String, Object> pileCache = REDIS.getCacheMap(pileKey);
|
||||
pileCache.put("status", REGISTERED);
|
||||
pileCache.put("server", getLocalIPAndPort());
|
||||
REDIS.setCacheMap(pileNo, pileCache);
|
||||
Set<String> pilesAtHost = REDIS.getCacheSet(getLocalIP());
|
||||
pilesAtHost.add(pileNo);
|
||||
log.info("pile registered >>>> [{}] ", pileNo);
|
||||
REDIS.setCacheMap(pileKey, pileCache);
|
||||
String svcKey = "ppSvcSrv:".concat(getLocalIPAndPort());
|
||||
Set<String> svcPiles = REDIS.getCacheSet(svcKey);
|
||||
svcPiles.add(pileKey);
|
||||
REDIS.setCacheSet(svcKey, svcPiles);
|
||||
log.info("pile registering >>>> [{}] ", pileNo);
|
||||
}
|
||||
|
||||
private List<byte[]> parseDataList(byte[] data) {
|
||||
|
||||
@ -27,16 +27,19 @@ public class ChargingPileEventHandler implements ClientEventHandler {
|
||||
public void lostConnection(ClientHandler handler) {
|
||||
|
||||
String pileNo = ChargingPileServer.getPileNo(handler);
|
||||
log.info("lost connection -> [{}] {} <- {}",
|
||||
pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
||||
if (pileNo != null) {
|
||||
ChargingPileServer.removeHandler(pileNo);
|
||||
}
|
||||
log.info("lost connection -> [{}] {} <- {}",
|
||||
pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closingConnection(ClientHandler handler) {
|
||||
|
||||
String pileNo = ChargingPileServer.getPileNo(handler);
|
||||
ChargingPileServer.removeHandler(pileNo);
|
||||
handler.closeConnection();
|
||||
log.info("closing connection -> " + handler.getName() + " <-");
|
||||
}
|
||||
|
||||
|
||||
@ -19,9 +19,7 @@ import org.springframework.stereotype.Component;
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.xhpc.pp.logic.RegisterLogic.DISCONNECTED;
|
||||
|
||||
@ -50,13 +48,6 @@ public class ChargingPileServer {
|
||||
public void init() {
|
||||
|
||||
REDIS = redisService;
|
||||
|
||||
REDIS.deleteObject("PILE_SN_POOL");
|
||||
Set<String> PILE_SN_POOL = new HashSet<>();
|
||||
//todo add pile sn whitelist
|
||||
PILE_SN_POOL.add("55031412782305");
|
||||
REDIS.setCacheSet("PILE_SN_POOL", PILE_SN_POOL);
|
||||
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@ -96,9 +87,10 @@ public class ChargingPileServer {
|
||||
public static void removeHandler(String pileNo) {
|
||||
|
||||
ClientHandler handler = handlerMap.remove(pileNo);
|
||||
Map<String, Object> cacheMap = REDIS.getCacheMap(pileNo);
|
||||
cacheMap.put("Status", DISCONNECTED);
|
||||
REDIS.setCacheMap(pileNo, cacheMap);
|
||||
String pileKey = "pile:".concat(pileNo);
|
||||
Map<String, Object> cacheMap = REDIS.getCacheMap(pileKey);
|
||||
cacheMap.put("status", DISCONNECTED);
|
||||
REDIS.setCacheMap(pileKey, cacheMap);
|
||||
if (handler != null) {
|
||||
log.info("remove handler [{}] for [{}]", handler.getName(), pileNo);
|
||||
pileMap.remove(handler.getName());
|
||||
@ -108,12 +100,10 @@ public class ChargingPileServer {
|
||||
|
||||
public static void sendClientMsg(String pileNo, byte[] msg) {
|
||||
|
||||
if (!HexUtils.toHex(msg).startsWith("00101005")) {
|
||||
log.info("server send msg >>>> [{}] |{}|", pileNo, HexUtils.toHex(msg));
|
||||
}
|
||||
if (pileNo.length() < 16) {
|
||||
if (pileNo.length() < 14) {
|
||||
pileNo = "0000000000000000" + pileNo;
|
||||
pileNo = pileNo.substring(pileNo.length() - 16);
|
||||
pileNo = pileNo.substring(pileNo.length() - 14);
|
||||
}
|
||||
ClientHandler handler = handlerMap.get(pileNo);
|
||||
if (handler == null || !handler.isOpen()) {
|
||||
|
||||
@ -4,7 +4,7 @@ ppsvc:
|
||||
|
||||
# Tomcat
|
||||
server:
|
||||
port: ${random.int(1300,1400)}
|
||||
port: 1300
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user