2024-10-08 09:38:54 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 抖音关注:程序员三丙
|
|
|
|
|
|
* 知识星球:https://t.zsxq.com/j9b21
|
|
|
|
|
|
*/
|
|
|
|
|
|
package sanbing.jcpp.app.service;
|
|
|
|
|
|
|
2024-10-23 17:07:57 +08:00
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
import sanbing.jcpp.app.data.PileSession;
|
|
|
|
|
|
import sanbing.jcpp.app.service.cache.session.PileSessionCacheKey;
|
|
|
|
|
|
import sanbing.jcpp.infrastructure.cache.CacheValueWrapper;
|
|
|
|
|
|
import sanbing.jcpp.infrastructure.cache.TransactionalCache;
|
|
|
|
|
|
import sanbing.jcpp.infrastructure.queue.discovery.ServiceInfoProvider;
|
|
|
|
|
|
import sanbing.jcpp.infrastructure.util.trace.Tracer;
|
|
|
|
|
|
import sanbing.jcpp.infrastructure.util.trace.TracerContextUtil;
|
|
|
|
|
|
import sanbing.jcpp.proto.gen.ProtocolProto;
|
2024-10-22 17:11:05 +08:00
|
|
|
|
import sanbing.jcpp.proto.gen.ProtocolProto.DownlinkRequestMessage;
|
2024-10-23 17:07:57 +08:00
|
|
|
|
import sanbing.jcpp.protocol.adapter.DownlinkController;
|
2024-10-08 09:38:54 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @author baigod
|
|
|
|
|
|
*/
|
2024-10-23 17:07:57 +08:00
|
|
|
|
@Slf4j
|
|
|
|
|
|
public abstract class DownlinkCallService {
|
2024-10-08 09:38:54 +08:00
|
|
|
|
|
2024-10-23 17:07:57 +08:00
|
|
|
|
@Resource
|
|
|
|
|
|
protected ServiceInfoProvider serviceInfoProvider;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
protected DownlinkController downlinkController;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
protected TransactionalCache<PileSessionCacheKey, PileSession> pileSessionCache;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${cache.type}")
|
|
|
|
|
|
protected String cacheType;
|
|
|
|
|
|
|
|
|
|
|
|
public void sendDownlinkMessage(DownlinkRequestMessage.Builder downlinkMessageBuilder, String pileCode) {
|
|
|
|
|
|
CacheValueWrapper<PileSession> pileSessionCacheValueWrapper = pileSessionCache.get(new PileSessionCacheKey(pileCode));
|
|
|
|
|
|
|
|
|
|
|
|
if (pileSessionCacheValueWrapper == null) {
|
|
|
|
|
|
log.warn("充电桩会话不存在 {}", pileCode);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PileSession pileSession = pileSessionCacheValueWrapper.get();
|
|
|
|
|
|
|
|
|
|
|
|
if (serviceInfoProvider.isMonolith() &&
|
|
|
|
|
|
("caffeine".equalsIgnoreCase(cacheType)) || serviceInfoProvider.getServiceId().equalsIgnoreCase(pileSession.getNodeId())) {
|
|
|
|
|
|
|
|
|
|
|
|
downlinkController.onDownlink(downlinkMessageBuilder.build())
|
|
|
|
|
|
.setResultHandler(result -> log.debug("下行消息发送完成"));
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Tracer currentTracer = TracerContextUtil.getCurrentTracer();
|
|
|
|
|
|
|
|
|
|
|
|
downlinkMessageBuilder.setTracer(ProtocolProto.TracerProto.newBuilder()
|
|
|
|
|
|
.setId(currentTracer.getTraceId())
|
|
|
|
|
|
.setOrigin(currentTracer.getOrigin())
|
|
|
|
|
|
.setTs(currentTracer.getTracerTs())
|
|
|
|
|
|
.build());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_sendDownlinkMessage(downlinkMessageBuilder.build(), pileSession);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected abstract void _sendDownlinkMessage(DownlinkRequestMessage downlinkMessage, PileSession pileSession);
|
2024-10-08 09:38:54 +08:00
|
|
|
|
}
|