whyclxw
2024-09-02 f56f93430cdc8d46a11fbd79c52c63005bc61b30
src/main/java/com/whyc/webSocket/DevInfSocket.java
@@ -1,9 +1,8 @@
package com.whyc.webSocket;
import com.whyc.config.WebSocketConfig;
import com.whyc.dto.Page;
import com.whyc.dto.DevInfDto;
import com.whyc.dto.Response;
import com.whyc.pojo.db_user.UserInf;
import com.whyc.service.DevInfService;
import com.whyc.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
@@ -12,12 +11,8 @@
import javax.servlet.http.HttpSession;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
@@ -52,23 +47,22 @@
    }
    @OnMessage
    public void onMessage(Session session, String message) {
        Page page= ActionUtil.getGson().fromJson(message,Page.class);
        DevInfDto devInfDto = ActionUtil.getGson("yyyy-MM-dd").fromJson(message, DevInfDto.class);
        //UserInf user = (UserInf) this.httpSession.getAttribute("user");
        //final int userId = user.getUid();
        final int userId = 101;
        thread = new Thread("Thread_DinfSocket") {
            @Override
            public void run() {
                Map<String, Object> res = new HashMap<>();
                while (runFlag && !isInterrupted()) {
                    Thread thread = currentThread();
                    threadFlagMap.put(thread.getId(), true);
                    try {
                        Response response=dinfService.getAllInf(userId,page);
                        Response res=dinfService.getAllInf(userId, devInfDto);
                        if (session.isOpen()) {
                            //推送信息
                            synchronized (session) {
                                session.getBasicRemote().sendObject(new Response().set(1, response));
                                session.getBasicRemote().sendObject(res);
                            }
                            threadFlagMap.put(thread.getId(), false);
                        }