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