mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-08 20:10:16 +08:00
update 校验channel是否保存
This commit is contained in:
@@ -18,11 +18,29 @@ public class PileChannelEntity {
|
|||||||
*/
|
*/
|
||||||
private static final ConcurrentHashMap<String, Channel> manager = new ConcurrentHashMap<>();
|
private static final ConcurrentHashMap<String, Channel> manager = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public static void put(String pileSn, Channel channel) {
|
/**
|
||||||
|
* 校验channel是否保存
|
||||||
|
*/
|
||||||
|
public static void checkChannel(String pileSn, Channel channel) {
|
||||||
if (manager.containsKey(pileSn)) {
|
if (manager.containsKey(pileSn)) {
|
||||||
log.error("桩编号:【{}】已经是连接状态", pileSn);
|
// 如果manager中存在pileSn的连接,取出来对比
|
||||||
|
Channel sourceChannel = manager.get(pileSn);
|
||||||
|
if (sourceChannel != null) {
|
||||||
|
// 两个做对比
|
||||||
|
String sourceChannelId = sourceChannel.id().asLongText();
|
||||||
|
String channelId = channel.id().asLongText();
|
||||||
|
if (!StringUtils.equals(sourceChannelId, channelId)) {
|
||||||
|
// 不一致则更新
|
||||||
|
manager.put(pileSn, channel);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 为空就put
|
||||||
|
manager.put(pileSn, channel);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果manager中不存在pileSn的连接,则保存
|
||||||
|
manager.put(pileSn, channel);
|
||||||
}
|
}
|
||||||
manager.put(pileSn, channel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,12 +4,11 @@ import com.google.common.primitives.Bytes;
|
|||||||
import com.jsowell.common.constant.Constants;
|
import com.jsowell.common.constant.Constants;
|
||||||
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
|
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
|
||||||
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
|
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
|
||||||
import com.jsowell.common.core.redis.RedisCache;
|
import com.jsowell.common.enums.ykc.PileChannelEntity;
|
||||||
import com.jsowell.common.util.BytesUtil;
|
import com.jsowell.common.util.BytesUtil;
|
||||||
import com.jsowell.common.util.YKCUtils;
|
import com.jsowell.common.util.YKCUtils;
|
||||||
import com.jsowell.netty.factory.YKCOperateFactory;
|
import com.jsowell.netty.factory.YKCOperateFactory;
|
||||||
import com.jsowell.pile.service.IPileBasicInfoService;
|
import com.jsowell.pile.service.IPileBasicInfoService;
|
||||||
import com.jsowell.pile.service.IPileConnectorInfoService;
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -24,15 +23,9 @@ public class HeartbeatRequestHandler extends AbstractHandler {
|
|||||||
|
|
||||||
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.HEART_BEAT_CODE.getBytes());
|
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.HEART_BEAT_CODE.getBytes());
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisCache redisCache;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IPileBasicInfoService pileBasicInfoService;
|
private IPileBasicInfoService pileBasicInfoService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IPileConnectorInfoService pileConnectorInfoService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
YKCOperateFactory.register(type, this);
|
YKCOperateFactory.register(type, this);
|
||||||
@@ -54,6 +47,9 @@ public class HeartbeatRequestHandler extends AbstractHandler {
|
|||||||
// 保存时间
|
// 保存时间
|
||||||
saveLastTime(pileSn);
|
saveLastTime(pileSn);
|
||||||
|
|
||||||
|
// 校验channel
|
||||||
|
PileChannelEntity.checkChannel(pileSn, channel);
|
||||||
|
|
||||||
// 枪号
|
// 枪号
|
||||||
startIndex += length;
|
startIndex += length;
|
||||||
length = 1;
|
length = 1;
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ public class LoginRequestHandler extends AbstractHandler {
|
|||||||
if (pileInfoVO != null) {
|
if (pileInfoVO != null) {
|
||||||
flag = Constants.zeroByteArray;
|
flag = Constants.zeroByteArray;
|
||||||
// 登录成功,保存桩号和channel的关系
|
// 登录成功,保存桩号和channel的关系
|
||||||
PileChannelEntity.put(pileSn, channel);
|
PileChannelEntity.checkChannel(pileSn, channel);
|
||||||
// 更改桩和该桩下的枪口状态分别为 在线、空闲 公共方法修改状态
|
// 更改桩和该桩下的枪口状态分别为 在线、空闲 公共方法修改状态
|
||||||
pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, null, null, null);
|
pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, null, null, null);
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
|
|||||||
import com.jsowell.common.core.redis.RedisCache;
|
import com.jsowell.common.core.redis.RedisCache;
|
||||||
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
|
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
|
||||||
import com.jsowell.common.enums.ykc.OrderStatusEnum;
|
import com.jsowell.common.enums.ykc.OrderStatusEnum;
|
||||||
|
import com.jsowell.common.enums.ykc.PileChannelEntity;
|
||||||
import com.jsowell.common.enums.ykc.StartModeEnum;
|
import com.jsowell.common.enums.ykc.StartModeEnum;
|
||||||
import com.jsowell.common.enums.ykc.YKCPileFaultReasonEnum;
|
import com.jsowell.common.enums.ykc.YKCPileFaultReasonEnum;
|
||||||
import com.jsowell.common.util.BytesUtil;
|
import com.jsowell.common.util.BytesUtil;
|
||||||
@@ -108,6 +109,9 @@ public class UploadRealTimeMonitorHandler extends AbstractHandler {
|
|||||||
// 保存时间
|
// 保存时间
|
||||||
saveLastTime(pileSn);
|
saveLastTime(pileSn);
|
||||||
|
|
||||||
|
// 校验channel
|
||||||
|
PileChannelEntity.checkChannel(pileSn, channel);
|
||||||
|
|
||||||
// 枪号
|
// 枪号
|
||||||
startIndex += length;
|
startIndex += length;
|
||||||
length = 1;
|
length = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user