diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/websocket/websocket/service/RydwWebSocketServer.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/websocket/websocket/service/RydwWebSocketServer.java index 813475c5..27986bdb 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/websocket/websocket/service/RydwWebSocketServer.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/websocket/websocket/service/RydwWebSocketServer.java @@ -24,8 +24,7 @@ import org.springframework.stereotype.Component; import java.io.IOException; import java.lang.reflect.Type; -import java.time.LocalDateTime; -import java.time.ZoneId; +import java.time.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -112,7 +111,7 @@ public class RydwWebSocketServer { session.getBasicRemote().sendText(JSON.toJSONString(objectMap)); } } - session.getBasicRemote().sendText("服务端已收到消息:" + message); +// session.getBasicRemote().sendText("服务端已收到消息:" + message); } catch (IOException e) { log.error("📤 回复会话[{}]失败:{}", session.getId(), e.getMessage()); } @@ -169,6 +168,13 @@ public class RydwWebSocketServer { public Map getData(String projectId){ Map map = new HashMap<>(); if (projectId != null && !projectId.isEmpty()){ + // 获取当天结束时间 + LocalDate today = LocalDate.now(); + LocalDateTime endOfDay = LocalDateTime.of(today, LocalTime.MAX); // 23:59:59.999999999 + long expireAt = endOfDay.atZone(ZoneId.systemDefault()).toEpochSecond(); + // 计算剩余秒数 + long now = System.currentTimeMillis() / 1000; + long expireSeconds = expireAt - now; //拿到项目下所有人员 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(SubConstructionUser::getProjectId, projectId); @@ -182,13 +188,61 @@ public class RydwWebSocketServer { List> allValue = new ArrayList<>(); for (BusProjectPunchrange busProjectPunchrange : busProjectPunchranges) { Map map2 = new HashMap<>(); - map2.put("06:00",0); - map2.put("08:00",0); - map2.put("10:00",0); - map2.put("12:00",0); - map2.put("14:00",0); - map2.put("16:00",0); - map2.put("18:00",0); + + boolean existsObject = RedisUtils.isExistsObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":06:00"); + if (!existsObject) { + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":06:00", 0, Duration.ofSeconds(expireSeconds)); + map2.put("06:00",0); + }else { + map2.put("06:00",RedisUtils.getCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":06:00")); + } + + existsObject = RedisUtils.isExistsObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":08:00"); + if (!existsObject) { + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":08:00", 0, Duration.ofSeconds(expireSeconds)); + map2.put("08:00",0); + }else { + map2.put("08:00",RedisUtils.getCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":08:00")); + } + + existsObject = RedisUtils.isExistsObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":10:00"); + if (!existsObject) { + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":10:00", 0, Duration.ofSeconds(expireSeconds)); + map2.put("10:00",0); + }else { + map2.put("10:00",RedisUtils.getCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":10:00")); + } + + existsObject = RedisUtils.isExistsObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":12:00"); + if (!existsObject) { + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":12:00", 0, Duration.ofSeconds(expireSeconds)); + map2.put("12:00",0); + }else { + map2.put("12:00",RedisUtils.getCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":12:00")); + } + + existsObject = RedisUtils.isExistsObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":14:00"); + if (!existsObject) { + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":14:00", 0, Duration.ofSeconds(expireSeconds)); + map2.put("14:00",0); + }else { + map2.put("14:00",RedisUtils.getCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":14:00")); + } + + existsObject = RedisUtils.isExistsObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":16:00"); + if (!existsObject) { + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":16:00", 0, Duration.ofSeconds(expireSeconds)); + map2.put("16:00",0); + }else { + map2.put("16:00",RedisUtils.getCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":16:00")); + } + + if (!existsObject) { + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":18:00", 0, Duration.ofSeconds(expireSeconds)); + map2.put("18:00",0); + }else { + map2.put("18:00",RedisUtils.getCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":18:00")); + } Map map1 = new HashMap<>(); map1.put(busProjectPunchrange.getId()+":"+busProjectPunchrange.getPunchName(),map2); @@ -254,24 +308,31 @@ public class RydwWebSocketServer { // 根据小时数判断所属区间并增加计数 if (hour >= 6 && hour < 8) { mapMap.get(mapMap.get(key)).put("06:00", (int)mapMap.get(key).get("06:00") + 1); + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":06:00", (int)mapMap.get(key).get("06:00") + 1, Duration.ofSeconds(expireSeconds)); + } else if (hour >= 8 && hour < 10) { -// map2.put("08:00", ((Integer) map2.get("08:00")) + 1); mapMap.get(mapMap.get(key)).put("08:00", (int)mapMap.get(key).get("08:00") + 1); + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":08:00", (int)mapMap.get(key).get("08:00") + 1, Duration.ofSeconds(expireSeconds)); } else if (hour >= 10 && hour < 12) { -// map2.put("10:00", ((Integer) map2.get("10:00")) + 1); mapMap.get(mapMap.get(key)).put("10:00", (int)mapMap.get(key).get("10:00") + 1); + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":10:00", (int)mapMap.get(key).get("10:00") + 1, Duration.ofSeconds(expireSeconds)); + } else if (hour >= 12 && hour < 14) { -// map2.put("12:00", ((Integer) map2.get("12:00")) + 1); mapMap.get(mapMap.get(key)).put("12:00", (int)mapMap.get(key).get("12:00") + 1); + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":12:00", (int)mapMap.get(key).get("12:00") + 1, Duration.ofSeconds(expireSeconds)); + } else if (hour >= 14 && hour < 16) { -// map2.put("14:00", ((Integer) map2.get("14:00")) + 1); mapMap.get(mapMap.get(key)).put("14:00", (int)mapMap.get(key).get("14:00") + 1); + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":14:00", (int)mapMap.get(key).get("14:00") + 1, Duration.ofSeconds(expireSeconds)); + } else if (hour >= 16 && hour < 18) { -// map2.put("16:00", ((Integer) map2.get("16:00")) + 1); mapMap.get(mapMap.get(key)).put("16:00", (int)mapMap.get(key).get("16:00") + 1); + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":16:00", (int)mapMap.get(key).get("16:00") + 1, Duration.ofSeconds(expireSeconds)); + } else if (hour >= 18 && hour < 20) { -// map2.put("18:00", ((Integer) map2.get("18:00")) + 1); mapMap.get(mapMap.get(key)).put("18:00", (int)mapMap.get(key).get("18:00") + 1); + RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":18:00", (int)mapMap.get(key).get("18:00") + 1, Duration.ofSeconds(expireSeconds)); + } } } @@ -294,9 +355,6 @@ public class RydwWebSocketServer { gpsList.add(sysUserVo); } -// if (constructionUser.getStatus().equals("0")){ -// zgry++; -// } } //地图实时坐标