whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/webSocket/TaskManageAdminWebsocket.java
@@ -2,7 +2,6 @@
import com.whyc.config.WebSocketConfig;
import com.whyc.dto.Response;
import com.whyc.factory.ThreadPoolExecutorFactory;
import com.whyc.pojo.FaultUpload;
import com.whyc.pojo.UserInf;
import com.whyc.service.FaultUploadService;
@@ -15,9 +14,6 @@
import javax.websocket.server.ServerEndpoint;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Component
@ServerEndpoint(value = "/taskMAdmin", encoders = WebSocketEncoder.class, configurator = WebSocketConfig.class)
@@ -62,51 +58,11 @@
                    Thread thread = currentThread();
                    threadFlagMap.put(thread.getId(), true);
                    try {
                        Map<String, Response> map = getTaskMAdmin(userId, upload);
                        if (session.isOpen()) {
                            //推送信息
                            synchronized (session) {
                                try {
                                    Map<String, Object> res = new HashMap<>();
                                    while (!currentThread().isInterrupted()) {
                                        ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor();
                                        CountDownLatch latch = new CountDownLatch(5);
                                        poolExecutor.execute(() -> {
                                            //本月
                                            Response monRes = faultUploadService.groupNameCount(1, userId);
                                            res.put("monRes", monRes);
                                            latch.countDown();
                                        });
                                        poolExecutor.execute(() -> {
                                            //本季度
                                            Response quarterRes = faultUploadService.groupNameCount(2, userId);
                                            res.put("quarterRes", quarterRes);
                                            latch.countDown();
                                        });
                                        poolExecutor.execute(() -> {
                                            //本年
                                            Response yearRes = faultUploadService.groupNameCount(3, userId);
                                            res.put("yearRes", yearRes);
                                            latch.countDown();
                                        });
                                        poolExecutor.execute(() -> {
                                            //隐患故障上报进度-最近一周及最近一月-管理
                                            Response lastPeriodRes = faultUploadService.getListOfLastPeriod(1, userId);
                                            res.put("lastPeriodRes", lastPeriodRes);
                                            latch.countDown();
                                        });
                                        poolExecutor.execute(() -> {
                                            //列表分页-管理
                                            Response listRes = faultUploadService.listPage2(upload.getPageNum(), upload.getPageSize(), upload, userId);
                                            res.put("listRes", listRes);
                                            latch.countDown();
                                        });
                                        latch.await(10, TimeUnit.MINUTES);
                                        session.getBasicRemote().sendObject(new Response().set(1, res));
                                        sleep(4000);
                                    }
                                } catch (Exception e) {
                                    this.interrupt();
                                }
                                session.getBasicRemote().sendObject(new Response().set(1, map));
                            }
                            threadFlagMap.put(thread.getId(), false);
                        }
@@ -130,6 +86,65 @@
        threadMap.put(session.getId(), this.thread);
    }
    //获取管理员的数据
    public Map getTaskMAdmin(int userId, FaultUpload upload) {
        Map<String, Object> res = new HashMap<>();
        //本月
        Response monRes = faultUploadService.groupNameCount(1, userId);
        res.put("monRes", monRes);
        //本季度
        Response quarterRes = faultUploadService.groupNameCount(2, userId);
        res.put("quarterRes", quarterRes);
        //本年
        Response yearRes = faultUploadService.groupNameCount(3, userId);
        res.put("yearRes", yearRes);
        //隐患故障上报进度-最近一周及最近一月-管理
        Response lastPeriodRes = faultUploadService.getListOfLastPeriod(1, userId);
        res.put("lastPeriodRes", lastPeriodRes);
        //列表分页-管理
        Response listRes = faultUploadService.listPage2(upload.getPageNum(), upload.getPageSize(), upload, userId);
        res.put("listRes", listRes);
        return res;
    }
   /* //获取管理员的数据
    public Map getTaskMAdmin(int userId, FaultUpload upload) {
        Map<String, Object> res = new HashMap<>();
        try {
            ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor();
            CountDownLatch latch = new CountDownLatch(3);
            poolExecutor.execute(() -> {
                //本月
                Response monRes = faultUploadService.groupNameCount(1, userId);
                res.put("monRes", monRes);
                //本季度
                Response quarterRes = faultUploadService.groupNameCount(2, userId);
                res.put("quarterRes", quarterRes);
                //本年
                Response yearRes = faultUploadService.groupNameCount(3, userId);
                res.put("yearRes", yearRes);
                latch.countDown();
            });
            poolExecutor.execute(() -> {
                //隐患故障上报进度-最近一周及最近一月-管理
                Response lastPeriodRes = faultUploadService.getListOfLastPeriod(1, userId);
                res.put("lastPeriodRes", lastPeriodRes);
                latch.countDown();
            });
            poolExecutor.execute(() -> {
                //列表分页-管理
                Response listRes = faultUploadService.listPage2(upload.getPageNum(), upload.getPageSize(), upload, userId);
                res.put("listRes", listRes);
                latch.countDown();
            });
            latch.await(10, TimeUnit.MINUTES);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return res;
    }*/
    @OnClose
    public void onClose(CloseReason closeReason) {