From 60dbf7e536d2003e53538dab42f34dfd8952ad2b Mon Sep 17 00:00:00 2001 From: Guoqs <123@jsowell.com> Date: Wed, 10 Jul 2024 15:43:38 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BF=AE=E6=94=B9=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractHandler.java | 2 +- .../electricbicycles/YKCBusinessService.java | 25 ++++++ .../impl/YKCBusinessServiceImpl.java | 77 +++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) rename jsowell-netty/src/main/java/com/jsowell/netty/handler/{diandanche => electricbicycles}/AbstractHandler.java (98%) create mode 100644 jsowell-netty/src/main/java/com/jsowell/netty/service/electricbicycles/YKCBusinessService.java create mode 100644 jsowell-netty/src/main/java/com/jsowell/netty/service/electricbicycles/impl/YKCBusinessServiceImpl.java diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/diandanche/AbstractHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/AbstractHandler.java similarity index 98% rename from jsowell-netty/src/main/java/com/jsowell/netty/handler/diandanche/AbstractHandler.java rename to jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/AbstractHandler.java index 200a5ac28..732915f63 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/handler/diandanche/AbstractHandler.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/electricbicycles/AbstractHandler.java @@ -1,4 +1,4 @@ -package com.jsowell.netty.handler.diandanche; +package com.jsowell.netty.handler.electricbicycles; import com.google.common.primitives.Bytes; import com.jsowell.common.constant.CacheConstants; diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/service/electricbicycles/YKCBusinessService.java b/jsowell-netty/src/main/java/com/jsowell/netty/service/electricbicycles/YKCBusinessService.java new file mode 100644 index 000000000..9889312e5 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/service/electricbicycles/YKCBusinessService.java @@ -0,0 +1,25 @@ +package com.jsowell.netty.service.electricbicycles; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelId; + +/** + * 云快充处理service + */ + +public interface YKCBusinessService { + /** + * 处理桩发来的请求 + * 不需要应答的返回null + * @param msg 请求报文 + * @param channel 通道信息 + * @return 结果 + */ + byte[] process(byte[] msg, Channel channel); + + /** + * 桩退出 + * @param channelId channelId + */ + void exit(ChannelId channelId); +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/service/electricbicycles/impl/YKCBusinessServiceImpl.java b/jsowell-netty/src/main/java/com/jsowell/netty/service/electricbicycles/impl/YKCBusinessServiceImpl.java new file mode 100644 index 000000000..13893aad0 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/service/electricbicycles/impl/YKCBusinessServiceImpl.java @@ -0,0 +1,77 @@ +package com.jsowell.netty.service.electricbicycles.impl; + +import com.jsowell.common.core.domain.ykc.YKCDataProtocol; +import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.enums.ykc.PileChannelEntity; +import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; +import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.YKCUtils; +import com.jsowell.netty.factory.YKCOperateFactory; +import com.jsowell.netty.handler.yunkuaichong.AbstractHandler; +import com.jsowell.netty.service.electricbicycles.YKCBusinessService; +import com.jsowell.pile.service.OrderBasicInfoService; +import com.jsowell.pile.service.PileConnectorInfoService; +import com.jsowell.pile.service.PileMsgRecordService; +import com.jsowell.pile.service.YKCPushCommandService; +import io.netty.channel.Channel; +import io.netty.channel.ChannelId; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class YKCBusinessServiceImpl implements YKCBusinessService { + + @Autowired + private PileMsgRecordService pileMsgRecordService; + + @Autowired + private PileConnectorInfoService pileConnectorInfoService; + + @Autowired + private OrderBasicInfoService orderBasicInfoService; + + @Autowired + private YKCPushCommandService ykcPushCommandService; + + @Override + public byte[] process(byte[] msg, Channel channel) { + if (!YKCUtils.checkMsg(msg)) { + // 校验不通过,丢弃消息 + return null; + } + YKCDataProtocol ykcDataProtocol = new YKCDataProtocol(msg); + // 获取帧类型 + String frameType = YKCUtils.frameType2Str(ykcDataProtocol.getFrameType()); + // 获取业务处理handler + AbstractHandler invokeStrategy = YKCOperateFactory.getInvokeStrategy(frameType); + return invokeStrategy.supplyProcess(ykcDataProtocol, channel); + } + + @Override + public void exit(ChannelId channelId) { + // 获取桩编号 + String pileSn = PileChannelEntity.getPileSnByChannelId(channelId.asLongText()); + if (StringUtils.isBlank(pileSn)) { + return; + } + log.info("充电桩退出:{}, channelId:{}", pileSn, PileChannelEntity.getChannelByPileSn(pileSn).id()); + + // 充电桩断开连接,所有枪口都设置为【离线】 + pileConnectorInfoService.updateConnectorStatusByPileSn(pileSn, PileConnectorDataBaseStatusEnum.OFF_NETWORK.getValue()); + + // 将此桩正在进行充电的订单状态改为 异常 + orderBasicInfoService.updateOrderStatusAsAbnormal(pileSn); + + // 记录充电桩退出msg + // 保存报文 + String type = YKCFrameTypeCode.PILE_LOG_OUT.getCode() + ""; + String jsonMsg = YKCFrameTypeCode.PILE_LOG_OUT.getValue(); + pileMsgRecordService.save(pileSn, pileSn, type, jsonMsg, ""); + + // 删除桩编号和channel的关系 + // PileChannelEntity.removeByPileSn(pileSn); + } + +}