60秒心跳检测离线
This commit is contained in:
parent
ee79a722be
commit
2fe8be514a
@ -0,0 +1,21 @@
|
|||||||
|
package com.xhpc.common.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class ConnectorStatusInfo {
|
||||||
|
|
||||||
|
public final static int OFF_LINE = 0;//离网
|
||||||
|
public final static int FREE = 1;//空闲
|
||||||
|
public final static int CONNECTED = 2;//占用(未充电)
|
||||||
|
public final static int CHARGING = 3;//占用(充电中)
|
||||||
|
public final static int BOOKED = 4;//占用(预约锁定)
|
||||||
|
public final static int ERROR = 255;//故障
|
||||||
|
|
||||||
|
private String connectorID;
|
||||||
|
private String operatorID;
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
}
|
||||||
@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
import org.springframework.context.annotation.ImportResource;
|
import org.springframework.context.annotation.ImportResource;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 充电桩服务
|
* 充电桩服务
|
||||||
@ -14,6 +15,7 @@ import org.springframework.context.annotation.ImportResource;
|
|||||||
@EnableFeignClients
|
@EnableFeignClients
|
||||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||||
@ImportResource(locations = {"classpath:svcmainlogic.xml"})
|
@ImportResource(locations = {"classpath:svcmainlogic.xml"})
|
||||||
|
@EnableScheduling
|
||||||
public class XhpcPPApplication {
|
public class XhpcPPApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||||
@ -30,10 +31,12 @@ public class HBLogic implements ServiceLogic {
|
|||||||
String pileNo = (String) req.get("pileNo");
|
String pileNo = (String) req.get("pileNo");
|
||||||
String gunId = (String) req.get("gunId");
|
String gunId = (String) req.get("gunId");
|
||||||
String gunStatus = (String) req.get("gunStatus");
|
String gunStatus = (String) req.get("gunStatus");
|
||||||
int gunStatusInt = Integer.parseInt(gunStatus);
|
Long gunStatusInt = Long.parseLong(gunStatus);
|
||||||
String gunkey = "gun:".concat(pileNo).concat(gunId);
|
String gunkey = "gun:".concat(pileNo).concat(gunId);
|
||||||
Map<String, String> cacheGun = REDIS.getCacheMap(gunkey);
|
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
|
||||||
cacheGun.put("status", stable[gunStatusInt]);
|
cacheGun.put("status", stable[gunStatusInt.intValue()]);
|
||||||
|
cacheGun.put("statusInt", gunStatusInt);
|
||||||
|
cacheGun.put("hbtime", String.valueOf(Calendar.getInstance().getTimeInMillis()));
|
||||||
REDIS.setCacheMap(gunkey, cacheGun);
|
REDIS.setCacheMap(gunkey, cacheGun);
|
||||||
String skey = gunkey.concat(".seqhex");
|
String skey = gunkey.concat(".seqhex");
|
||||||
String seq = seqHex(skey);
|
String seq = seqHex(skey);
|
||||||
|
|||||||
@ -60,7 +60,8 @@ public class RealtimeDataLogic implements ServiceLogic {
|
|||||||
String terminalId = pileNo.concat(gunId);
|
String terminalId = pileNo.concat(gunId);
|
||||||
String gunkey = "gun:".concat(terminalId);
|
String gunkey = "gun:".concat(terminalId);
|
||||||
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
|
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
|
||||||
String statusplain = stable[Integer.parseInt(realtimeData.getStatus())];
|
int statusInt = Integer.parseInt(realtimeData.getStatus());
|
||||||
|
String statusplain = stable[statusInt];
|
||||||
cacheGun.put("pileGunStatus", pvgstable[Integer.parseInt(realtimeData.getPileGunStatus())]);
|
cacheGun.put("pileGunStatus", pvgstable[Integer.parseInt(realtimeData.getPileGunStatus())]);
|
||||||
cacheGun.put("vehicleGunStatus", pvgstable[Integer.parseInt(realtimeData.getVehicleGunStatus())]);
|
cacheGun.put("vehicleGunStatus", pvgstable[Integer.parseInt(realtimeData.getVehicleGunStatus())]);
|
||||||
String hardwareFault = realtimeData.getHardwareFault();
|
String hardwareFault = realtimeData.getHardwareFault();
|
||||||
@ -86,6 +87,7 @@ public class RealtimeDataLogic implements ServiceLogic {
|
|||||||
statusOrSOC = statusplain;
|
statusOrSOC = statusplain;
|
||||||
}
|
}
|
||||||
Integer tr = reverseHexInt(realtimeData.getRemainingTime());
|
Integer tr = reverseHexInt(realtimeData.getRemainingTime());
|
||||||
|
cacheGun.put("statusInt", statusInt);
|
||||||
cacheGun.put("status", statusOrSOC);
|
cacheGun.put("status", statusOrSOC);
|
||||||
cacheGun.put("remainingTime", tr);
|
cacheGun.put("remainingTime", tr);
|
||||||
REDIS.setCacheMap(gunkey, cacheGun);
|
REDIS.setCacheMap(gunkey, cacheGun);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.xhpc.pp.logic;
|
package com.xhpc.pp.logic;
|
||||||
|
|
||||||
|
import com.xhpc.common.dto.ConnectorStatusInfo;
|
||||||
import com.xhpc.pp.config.EarlierBeanConf;
|
import com.xhpc.pp.config.EarlierBeanConf;
|
||||||
import com.xhpc.pp.tx.ServiceParameter;
|
import com.xhpc.pp.tx.ServiceParameter;
|
||||||
import com.xhpc.pp.tx.ServiceResult;
|
import com.xhpc.pp.tx.ServiceResult;
|
||||||
@ -56,10 +57,11 @@ public class RegisterLogic implements ServiceLogic {
|
|||||||
String gunkey = "gun:".concat(pileNo.concat(gunId));
|
String gunkey = "gun:".concat(pileNo.concat(gunId));
|
||||||
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
|
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
|
||||||
cacheGun.put("status", DISCONNECTED);
|
cacheGun.put("status", DISCONNECTED);
|
||||||
|
cacheGun.put("statusInt", ConnectorStatusInfo.OFF_LINE);
|
||||||
cacheGun.put("svcSrv", localIPAndPort);
|
cacheGun.put("svcSrv", localIPAndPort);
|
||||||
REDIS.setCacheMap(gunkey, cacheGun);
|
REDIS.setCacheMap(gunkey, cacheGun);
|
||||||
|
cachePileGunSvcSrv(gunkey);
|
||||||
}
|
}
|
||||||
cachePileGunSvcSrv(pileNo);
|
|
||||||
log.info("pile (re)registered ({}) ", pileNo);
|
log.info("pile (re)registered ({}) ", pileNo);
|
||||||
}
|
}
|
||||||
String skey = "pile:".concat(pileNo).concat(".seqhex");
|
String skey = "pile:".concat(pileNo).concat(".seqhex");
|
||||||
@ -69,11 +71,11 @@ public class RegisterLogic implements ServiceLogic {
|
|||||||
return new ServiceResult(HexUtils.toBytes(resultStr), resultCode);
|
return new ServiceResult(HexUtils.toBytes(resultStr), resultCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cachePileGunSvcSrv(String key) {
|
private void cachePileGunSvcSrv(String gunkey) {
|
||||||
|
|
||||||
String svcKey = "svcSrvPile:".concat(getLocalIPAndPort());
|
String svcKey = "svcSrvGuns:".concat(getLocalIPAndPort());
|
||||||
Set<String> svcPileGuns = REDIS.getCacheSet(svcKey);
|
Set<String> svcPileGuns = REDIS.getCacheSet(svcKey);
|
||||||
svcPileGuns.add(key);
|
svcPileGuns.add(gunkey);
|
||||||
REDIS.setCacheSet(svcKey, svcPileGuns);
|
REDIS.setCacheSet(svcKey, svcPileGuns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,11 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||||
|
import static com.xhpc.pp.logic.RegisterLogic.DISCONNECTED;
|
||||||
|
|
||||||
@Lazy(false)
|
@Lazy(false)
|
||||||
@Component
|
@Component
|
||||||
public class ChargingPileEventHandler implements ClientEventHandler {
|
public class ChargingPileEventHandler implements ClientEventHandler {
|
||||||
@ -27,9 +32,9 @@ public class ChargingPileEventHandler implements ClientEventHandler {
|
|||||||
public void lostConnection(ClientHandler handler) {
|
public void lostConnection(ClientHandler handler) {
|
||||||
|
|
||||||
String pileNo = ChargingPileServer.getPileNo(handler);
|
String pileNo = ChargingPileServer.getPileNo(handler);
|
||||||
// if (pileNo != null) {
|
if (pileNo != null) {
|
||||||
// ChargingPileServer.removeHandler(pileNo);
|
ChargingPileServer.disconnPileNGuns(pileNo);
|
||||||
// }
|
}
|
||||||
log.info("<- ({}) - [{}] - {} ->",
|
log.info("<- ({}) - [{}] - {} ->",
|
||||||
pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
||||||
}
|
}
|
||||||
@ -38,11 +43,11 @@ public class ChargingPileEventHandler implements ClientEventHandler {
|
|||||||
public void closingConnection(ClientHandler handler) {
|
public void closingConnection(ClientHandler handler) {
|
||||||
|
|
||||||
String pileNo = ChargingPileServer.getPileNo(handler);
|
String pileNo = ChargingPileServer.getPileNo(handler);
|
||||||
// ChargingPileServer.removeHandler(pileNo);
|
ChargingPileServer.removeHandler(pileNo);
|
||||||
// String pkey = "pile:".concat(pileNo);
|
String pkey = "pile:".concat(pileNo);
|
||||||
// Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
|
Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
|
||||||
// cachePile.put("status", DISCONNECTED);
|
cachePile.put("status", DISCONNECTED);
|
||||||
// REDIS.setCacheMap(pkey, cachePile);
|
REDIS.setCacheMap(pkey, cachePile);
|
||||||
handler.closeConnection();
|
handler.closeConnection();
|
||||||
log.info("<- ({}) - [{}] - {} ->", pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
log.info("<- ({}) - [{}] - {} ->", pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,15 +75,17 @@ public class ChargingPileServer {
|
|||||||
pileMap.put(handler.getName(), pileNo);
|
pileMap.put(handler.getName(), pileNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeHandler(String pileNo) {
|
public static void disconnPileNGuns(String pileNo) {
|
||||||
|
|
||||||
ClientHandler handler = handlerMap.remove(pileNo);
|
ClientHandler handler = handlerMap.remove(pileNo);
|
||||||
handler.closeConnection();
|
handler.closeConnection();
|
||||||
log.info("handler [{}] for ({}) close connection", handler.getName(), pileNo);
|
log.info("handler [{}] for ({}) close connection", handler.getName(), pileNo);
|
||||||
String pkey = "pile:".concat(pileNo);
|
String pkey = "pile:".concat(pileNo);
|
||||||
Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
|
Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
|
||||||
cachePile.put("status", DISCONNECTED);
|
putemDisconn(pileNo, cachePile);
|
||||||
REDIS.setCacheMap(pkey, cachePile);
|
}
|
||||||
|
|
||||||
|
private static void putemDisconn(String pileNo, Map<String, Object> cachePile) {
|
||||||
String stationTermStatusKey = "stationTerminalStatus:".concat(cachePile.get("stationId").toString());
|
String stationTermStatusKey = "stationTerminalStatus:".concat(cachePile.get("stationId").toString());
|
||||||
for (int i = 1; i <= (int) cachePile.get("gunNum"); i++) {
|
for (int i = 1; i <= (int) cachePile.get("gunNum"); i++) {
|
||||||
String gunkey = "gun:".concat(pileNo).concat(String.format("%02d", i));
|
String gunkey = "gun:".concat(pileNo).concat(String.format("%02d", i));
|
||||||
@ -104,6 +106,18 @@ public class ChargingPileServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeHandler(String pileNo) {
|
||||||
|
|
||||||
|
ClientHandler handler = handlerMap.remove(pileNo);
|
||||||
|
handler.closeConnection();
|
||||||
|
log.info("handler [{}] for ({}) close connection", handler.getName(), pileNo);
|
||||||
|
String pkey = "pile:".concat(pileNo);
|
||||||
|
Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
|
||||||
|
cachePile.put("status", DISCONNECTED);
|
||||||
|
REDIS.setCacheMap(pkey, cachePile);
|
||||||
|
putemDisconn(pileNo, cachePile);
|
||||||
log.info("remove handler [{}] for ({})", handler.getName(), pileNo);
|
log.info("remove handler [{}] for ({})", handler.getName(), pileNo);
|
||||||
pileMap.remove(handler.getName());
|
pileMap.remove(handler.getName());
|
||||||
versionMapper.remove(handler.getName());
|
versionMapper.remove(handler.getName());
|
||||||
|
|||||||
@ -3,15 +3,35 @@ package com.xhpc.pp.server;
|
|||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||||
|
import static com.xhpc.common.dto.ConnectorStatusInfo.OFF_LINE;
|
||||||
|
import static com.xhpc.pp.config.EarlierBeanConf.getLocalIPAndPort;
|
||||||
|
import static com.xhpc.pp.logic.RegisterLogic.DISCONNECTED;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class HBCheckTask {
|
public class HBCheckTask {
|
||||||
|
|
||||||
@Scheduled(fixedRate = 1000)
|
@Scheduled(fixedRate = 10000)
|
||||||
protected void run() throws IOException {
|
protected void run() {
|
||||||
|
|
||||||
System.out.println("hb check");
|
System.out.println("hbchk..");
|
||||||
|
String svcSrvKey = "svcSrvGuns".concat(getLocalIPAndPort());
|
||||||
|
List<String> cacheGunkeyList = REDIS.getCacheList(svcSrvKey);
|
||||||
|
Long now = Calendar.getInstance().getTimeInMillis();
|
||||||
|
for (String gunkey : cacheGunkeyList) {
|
||||||
|
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
|
||||||
|
Long hbtime = (Long) cacheGun.get("hbtime");
|
||||||
|
hbtime = hbtime == null ? 0 : hbtime;
|
||||||
|
if ((now - hbtime) > 60000) {
|
||||||
|
cacheGun.put("statusInt", OFF_LINE);
|
||||||
|
cacheGun.put("status", DISCONNECTED);
|
||||||
|
REDIS.setCacheMap(gunkey, cacheGun);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user