心跳包内逻辑改为异步处理

This commit is contained in:
Guoqs
2024-12-13 15:45:40 +08:00
parent e24a37185a
commit 19c6bf810e

View File

@@ -6,13 +6,17 @@ import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.pile.service.PileBasicInfoService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 充电桩心跳包
*/
@@ -25,6 +29,9 @@ public class HeartbeatRequestHandler extends AbstractYkcHandler {
@Autowired
private PileBasicInfoService pileBasicInfoService;
// 引入线程池
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
@Override
public void afterPropertiesSet() throws Exception {
YKCOperateFactory.register(type, this);
@@ -65,11 +72,20 @@ public class HeartbeatRequestHandler extends AbstractYkcHandler {
// updateStatus(pileSn, pileConnectorNum, connectorStatus);
// 公共方法修改状态
try {
pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, pileConnectorNum, connectorStatus, null);
} catch (Exception e) {
log.error("公共方法修改状态error", e);
}
// try {
// pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, pileConnectorNum, connectorStatus, null);
// } catch (Exception e) {
// log.error("公共方法修改状态error", e);
// }
// 异步修改状态
CompletableFuture.runAsync(() -> {
try {
pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, pileConnectorNum, connectorStatus, null);
} catch (Exception e) {
log.error("公共方法修改状态error", e);
}
}, executor);
// 心跳应答置0
byte[] flag = Constants.zeroByteArray;