update 修改结构

This commit is contained in:
Guoqs
2024-07-10 15:43:38 +08:00
parent 3400dde845
commit 60dbf7e536
3 changed files with 103 additions and 1 deletions

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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);
}
}