| | |
| | | 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; |
| | | import com.whyc.util.ActionUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | @OnMessage |
| | | public void onMessage(Session session, String message) { |
| | | UserInf user = (UserInf) this.httpSession.getAttribute("user"); |
| | | final int userId = user.getUId().intValue(); |
| | | //final int userId = 1041; |
| | | /*UserInf user = (UserInf) this.httpSession.getAttribute("user"); |
| | | final int userId = user.getUId().intValue();*/ |
| | | final int userId = 1041; |
| | | FaultUpload upload = ActionUtil.getGson().fromJson(message, FaultUpload.class); |
| | | thread = new Thread("Thread_RealTime") { |
| | | @Override |
| | |
| | | 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); |
| | | } |
| | |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | //获取管理员的数据 |
| | | public Map getTaskMAdmin(int userId, FaultUpload upload) { |
| | | Map<String, Object> res = new HashMap<>(); |
| | | try { |
| | | 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); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(CloseReason closeReason) { |