实时通讯

This commit is contained in:
高保安
2025-12-01 10:08:41 +08:00
commit e6623be1e5
140 changed files with 6032 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
package com.realtime.packets.strategy.impl;
import com.alibaba.fastjson2.JSONObject;
import com.realtime.exception.BusinessException;
import com.realtime.packets.basePackets.BasePackets;
import com.realtime.packets.strategy.PackStrategy;
import com.realtime.packets.strategy.PacketService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PacketServiceImpl implements PacketService {
private final List<PackStrategy> packStrategies;
@Override
public BasePackets getCurrent(JSONObject jsonObject) {
Byte command = jsonObject.getByte("command");
return getCurrent(command).getCurrentPacket(jsonObject);
}
private PackStrategy getCurrent(Byte commandLine) {
long size = packStrategies.stream().filter(item -> item.getCurrent(commandLine)).count();
if (size <= 0) {
throw new BusinessException("没有可用的频道!!");
}
return packStrategies.stream().filter(item -> item.getCurrent(commandLine)).toList().get(0);
}
}