|
@@ -7,6 +7,8 @@ import com.google.common.collect.Lists;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
|
+import org.springframework.context.ApplicationContextAware;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
import shop.alien.entity.store.LifeBlacklist;
|
|
@@ -19,6 +21,7 @@ import shop.alien.util.common.safe.TextModerationResultVO;
|
|
|
import shop.alien.util.common.safe.TextModerationUtil;
|
|
|
import shop.alien.util.common.safe.TextReviewServiceEnum;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.websocket.*;
|
|
|
import javax.websocket.server.PathParam;
|
|
|
import javax.websocket.server.ServerEndpoint;
|
|
@@ -36,19 +39,28 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
@ServerEndpoint(value = "/socket/{sendId}")
|
|
|
-@RequiredArgsConstructor
|
|
|
-public class WebSocketProcess {
|
|
|
-
|
|
|
- private final LifeMessageMapper lifeMessageMapper;
|
|
|
- private final BaseRedisService baseRedisService;
|
|
|
- private final LifeBlacklistMapper lifeBlacklistMapper;
|
|
|
- private final TextModerationUtil textModerationUtil;
|
|
|
+public class WebSocketProcess implements ApplicationContextAware {
|
|
|
|
|
|
+ private static ApplicationContext applicationContext;
|
|
|
+ private static LifeBlacklistMapper lifeBlacklistMapper;
|
|
|
+ private static LifeMessageMapper lifeMessageMapper;
|
|
|
+ private static BaseRedisService baseRedisService;
|
|
|
+ private static TextModerationUtil textModerationUtil;
|
|
|
/*
|
|
|
* 持有每个webSocket对象,以key-value存储到线程安全ConcurrentHashMap,
|
|
|
*/
|
|
|
private static final ConcurrentHashMap<String, WebSocketProcess> concurrentHashMap = new ConcurrentHashMap<>(12);
|
|
|
|
|
|
+ @Override
|
|
|
+ public void setApplicationContext(ApplicationContext context) {
|
|
|
+ WebSocketProcess.applicationContext = context;
|
|
|
+ // 初始化Mapper
|
|
|
+ WebSocketProcess.lifeBlacklistMapper = context.getBean(LifeBlacklistMapper.class);
|
|
|
+ WebSocketProcess.lifeMessageMapper = context.getBean(LifeMessageMapper.class);
|
|
|
+ WebSocketProcess.baseRedisService = context.getBean(BaseRedisService.class);
|
|
|
+ WebSocketProcess.textModerationUtil = context.getBean(TextModerationUtil.class);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 会话对象
|
|
|
**/
|