12-03-人员定位-初版
This commit is contained in:
@ -615,15 +615,15 @@ public class GpsEquipmentServiceImpl extends ServiceImpl<GpsEquipmentMapper, Gps
|
|||||||
//检查是否存在
|
//检查是否存在
|
||||||
boolean rydw = RedisUtils.isExistsObject("rydw_cs");
|
boolean rydw = RedisUtils.isExistsObject("rydw_cs");
|
||||||
if (!rydw) {
|
if (!rydw) {
|
||||||
RedisUtils.setCacheObject("rydw_cs",0L,Duration.ofSeconds(expireSeconds));
|
RedisUtils.setCacheObject("rydw_cs",0,Duration.ofSeconds(expireSeconds));
|
||||||
}else {
|
}else {
|
||||||
Long cacheObject = RedisUtils.getCacheObject("rydw_cs");
|
Integer cacheObject = RedisUtils.getCacheObject("rydw_cs");
|
||||||
cacheObject = cacheObject + 1;
|
cacheObject = cacheObject + 1;
|
||||||
RedisUtils.setCacheObject("rydw_cs",cacheObject,true);
|
RedisUtils.setCacheObject("rydw_cs",cacheObject,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//将打卡用户存入Redis中 过期时间为当天23:59:59
|
//将打卡用户存入Redis中 过期时间为当天23:59:59
|
||||||
setPersonToRedis(gpsEquipment,expireSeconds);
|
setPersonToRedis(gpsEquipmentSonBo,expireSeconds);
|
||||||
|
|
||||||
|
|
||||||
// 保存到Redis并设置过期监听
|
// 保存到Redis并设置过期监听
|
||||||
@ -669,10 +669,10 @@ public class GpsEquipmentServiceImpl extends ServiceImpl<GpsEquipmentMapper, Gps
|
|||||||
/**
|
/**
|
||||||
* 打卡人员存入redis
|
* 打卡人员存入redis
|
||||||
*/
|
*/
|
||||||
private void setPersonToRedis(GpsEquipment entity,long time) {
|
private void setPersonToRedis(GpsEquipmentSonBo entity,long time) {
|
||||||
String key = "rydw_userId_:" + entity.getUserId();
|
String key = "rydw_userId_:" + entity.getUserId();
|
||||||
|
|
||||||
// 先删除可能存在的旧监听器
|
// 先删除可能存在的旧数据
|
||||||
if (RedisUtils.isExistsObject(key)) {
|
if (RedisUtils.isExistsObject(key)) {
|
||||||
RedisUtils.deleteObject(key);
|
RedisUtils.deleteObject(key);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -122,16 +122,9 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
|
|||||||
}
|
}
|
||||||
|
|
||||||
Channel channel = ctx.channel();
|
Channel channel = ctx.channel();
|
||||||
channelGroup.writeAndFlush(new TextWebSocketFrame("[系统消息] " + sdf.format(new Date()) + ":" + channel.remoteAddress() + " 上线\n"));
|
// channelGroup.writeAndFlush(new TextWebSocketFrame("[系统消息] " + sdf.format(new Date()) + ":" + channel.remoteAddress() + " 上线\n"));
|
||||||
channelGroup.add(channel);
|
channelGroup.add(channel);
|
||||||
|
|
||||||
//构建推送消息
|
|
||||||
// List<Long> userIds = new ArrayList<>();
|
|
||||||
// //类型转换
|
|
||||||
// for (String s : onlineUserList) {
|
|
||||||
// userIds.add(Long.parseLong(s));
|
|
||||||
// }
|
|
||||||
// List<UserDTO> userDTOS = sysUserService.selectListByIds(userIds);
|
|
||||||
|
|
||||||
//构建各个聊天房间未读 数量
|
//构建各个聊天房间未读 数量
|
||||||
LambdaQueryWrapper<ChatGroup> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<ChatGroup> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
@ -139,12 +132,6 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
|
|||||||
//拿到该用户所参与的房间列表
|
//拿到该用户所参与的房间列表
|
||||||
List<ChatGroup> chatGroups = chatGroupService.list(queryWrapper);
|
List<ChatGroup> chatGroups = chatGroupService.list(queryWrapper);
|
||||||
boolean isHaveSystemRoom = false;
|
boolean isHaveSystemRoom = false;
|
||||||
// //考勤
|
|
||||||
// boolean isHaveAttendanceRoom = false;
|
|
||||||
// //安全
|
|
||||||
// boolean isHaveSafeRoom = false;
|
|
||||||
// //质量
|
|
||||||
// boolean isHaveQualityRoom = false;
|
|
||||||
if (chatGroups != null && !chatGroups.isEmpty()) {
|
if (chatGroups != null && !chatGroups.isEmpty()) {
|
||||||
HashMap<String, Object> roomCounts = new HashMap<>();
|
HashMap<String, Object> roomCounts = new HashMap<>();
|
||||||
for (ChatGroup chatGroup : chatGroups) {
|
for (ChatGroup chatGroup : chatGroups) {
|
||||||
@ -162,15 +149,6 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
|
|||||||
if (!isHaveSystemRoom && chatGroup.getMembers().contains("[" + ChatRoomEnum.SYSTEM.getRoomId())) {
|
if (!isHaveSystemRoom && chatGroup.getMembers().contains("[" + ChatRoomEnum.SYSTEM.getRoomId())) {
|
||||||
isHaveSystemRoom = true;
|
isHaveSystemRoom = true;
|
||||||
}
|
}
|
||||||
// if (!isHaveAttendanceRoom && chatGroup.getMembers().contains("["+ChatRoomEnum.ATTENDANCE.getRoomId())){
|
|
||||||
// isHaveAttendanceRoom = true;
|
|
||||||
// }
|
|
||||||
// if (!isHaveSafeRoom && chatGroup.getMembers().contains("["+ChatRoomEnum.SAFE.getRoomId())){
|
|
||||||
// isHaveSafeRoom = true;
|
|
||||||
// }
|
|
||||||
// if (!isHaveQualityRoom && chatGroup.getMembers().contains("["+ChatRoomEnum.QUALITY.getRoomId())){
|
|
||||||
// isHaveQualityRoom = true;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
JSONObject message = new JSONObject();
|
JSONObject message = new JSONObject();
|
||||||
message.put("type", "3");
|
message.put("type", "3");
|
||||||
@ -189,45 +167,14 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
|
|||||||
chatGroupService.save(chatGroup);
|
chatGroupService.save(chatGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
//考勤
|
|
||||||
// if (!isHaveAttendanceRoom){
|
|
||||||
// ChatGroup chatGroup = new ChatGroup();
|
|
||||||
// chatGroup.setType(String.valueOf(3));
|
|
||||||
// chatGroup.setMembers("["+ChatRoomEnum.ATTENDANCE.getRoomId() +", "+loginUser.getUserId()+"]");
|
|
||||||
// chatGroupService.save(chatGroup);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //安全
|
|
||||||
// if (!isHaveSafeRoom){
|
|
||||||
// ChatGroup chatGroup = new ChatGroup();
|
|
||||||
// chatGroup.setType(String.valueOf(4));
|
|
||||||
// chatGroup.setMembers("["+ChatRoomEnum.SAFE.getRoomId() +", "+loginUser.getUserId()+"]");
|
|
||||||
// chatGroupService.save(chatGroup);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //质量
|
|
||||||
// if (!isHaveQualityRoom){
|
|
||||||
// ChatGroup chatGroup = new ChatGroup();
|
|
||||||
// chatGroup.setType(String.valueOf(5));
|
|
||||||
// chatGroup.setMembers("["+ChatRoomEnum.QUALITY.getRoomId() +", "+loginUser.getUserId()+"]");
|
|
||||||
// chatGroupService.save(chatGroup);
|
|
||||||
// }
|
|
||||||
|
|
||||||
//等待全部创建完成后 初次创建系统房间后 发送一条初始化信息
|
//等待全部创建完成后 初次创建系统房间后 发送一条初始化信息
|
||||||
if (!isHaveSystemRoom) {
|
if (!isHaveSystemRoom) {
|
||||||
sendSystemMessageToUser(loginUser.getUserId(), "注册已顺利完成,为确保您正常参与工作,请联系分包管理员确认所属项目及班组。", "0");
|
sendSystemMessageToUser(loginUser.getUserId(), "注册已顺利完成,为确保您正常参与工作,请联系分包管理员确认所属项目及班组。", "0");
|
||||||
}
|
}
|
||||||
//生成一条未读的聊天记录
|
|
||||||
// ChatHistory chatHistory = new ChatHistory();
|
|
||||||
// chatHistory.setSenderId(99L);
|
|
||||||
// chatHistory.setGeterId(groupServiceOne.getId());
|
|
||||||
// chatHistory.setMessage(jsonObject.toString());
|
|
||||||
// chatHistory.setMessageDate(new Date());
|
|
||||||
// chatHistory.setIsRead("1");//未读
|
|
||||||
// chatHistoryService.save(chatHistory);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
log.info("{} 上线了", ctx.channel().remoteAddress());
|
log.info("{} 通过认证了", ctx.channel().remoteAddress());
|
||||||
super.userEventTriggered(ctx, evt);
|
super.userEventTriggered(ctx, evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,18 +3,19 @@ package org.dromara.websocket.websocket.service;// 路径:com.ruoyi.web.websoc
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.google.common.reflect.TypeToken;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import jakarta.websocket.*;
|
import jakarta.websocket.*;
|
||||||
import jakarta.websocket.server.ServerEndpoint;
|
import jakarta.websocket.server.ServerEndpoint;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.common.core.utils.SpringUtils;
|
import org.dromara.common.core.utils.SpringUtils;
|
||||||
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.domain.GeoPoint;
|
import org.dromara.common.domain.GeoPoint;
|
||||||
import org.dromara.common.redis.utils.RedisUtils;
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
import org.dromara.common.utils.JSTUtil;
|
import org.dromara.common.utils.JSTUtil;
|
||||||
import org.dromara.contractor.domain.SubConstructionUser;
|
import org.dromara.contractor.domain.SubConstructionUser;
|
||||||
import org.dromara.contractor.service.impl.SubConstructionUserServiceImpl;
|
import org.dromara.contractor.service.impl.SubConstructionUserServiceImpl;
|
||||||
import org.dromara.gps.domain.GpsEquipmentSon;
|
import org.dromara.gps.domain.GpsEquipmentSon;
|
||||||
|
import org.dromara.gps.domain.bo.GpsEquipmentSonBo;
|
||||||
|
import org.dromara.gps.service.impl.GpsEquipmentSonServiceImpl;
|
||||||
import org.dromara.project.domain.BusProjectPunchrange;
|
import org.dromara.project.domain.BusProjectPunchrange;
|
||||||
import org.dromara.project.service.impl.BusProjectPunchrangeServiceImpl;
|
import org.dromara.project.service.impl.BusProjectPunchrangeServiceImpl;
|
||||||
import org.dromara.system.domain.vo.SysUserVo;
|
import org.dromara.system.domain.vo.SysUserVo;
|
||||||
@ -23,12 +24,8 @@ import org.dromara.websocket.ChatServerHandler;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.time.*;
|
import java.time.*;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ -41,16 +38,14 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
@Component
|
@Component
|
||||||
public class RydwWebSocketServer {
|
public class RydwWebSocketServer {
|
||||||
|
|
||||||
// @Autowired
|
|
||||||
// private SubConstructionUserServiceImpl subConstructionUserService;
|
|
||||||
private final static SubConstructionUserServiceImpl subConstructionUserService = SpringUtils.getBean(SubConstructionUserServiceImpl.class);
|
private final static SubConstructionUserServiceImpl subConstructionUserService = SpringUtils.getBean(SubConstructionUserServiceImpl.class);
|
||||||
// @Autowired
|
|
||||||
// private BusProjectPunchrangeServiceImpl busProjectPunchrangeService;
|
|
||||||
private final static BusProjectPunchrangeServiceImpl busProjectPunchrangeService = SpringUtils.getBean(BusProjectPunchrangeServiceImpl.class);
|
private final static BusProjectPunchrangeServiceImpl busProjectPunchrangeService = SpringUtils.getBean(BusProjectPunchrangeServiceImpl.class);
|
||||||
// @Autowired
|
|
||||||
// private SysUserServiceImpl sysUserService;
|
|
||||||
private final static SysUserServiceImpl sysUserService = SpringUtils.getBean(SysUserServiceImpl.class);
|
private final static SysUserServiceImpl sysUserService = SpringUtils.getBean(SysUserServiceImpl.class);
|
||||||
|
|
||||||
|
private final static GpsEquipmentSonServiceImpl gpsEquipmentSonService = SpringUtils.getBean(GpsEquipmentSonServiceImpl.class);
|
||||||
|
|
||||||
// 2. 静态会话存储(线程安全,项目启动时即初始化)
|
// 2. 静态会话存储(线程安全,项目启动时即初始化)
|
||||||
private static final Map<String, Session> ONLINE_SESSIONS = new ConcurrentHashMap<>();
|
private static final Map<String, Session> ONLINE_SESSIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@ -71,14 +66,39 @@ public class RydwWebSocketServer {
|
|||||||
log.info("📌 客户端连接成功!会话ID:{},当前在线数:{}", session.getId(), ONLINE_SESSIONS.size());
|
log.info("📌 客户端连接成功!会话ID:{},当前在线数:{}", session.getId(), ONLINE_SESSIONS.size());
|
||||||
// 2. 异步获取并推送初始化数据(避免阻塞连接)
|
// 2. 异步获取并推送初始化数据(避免阻塞连接)
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
|
/* 解析消息 暂定json字符串
|
||||||
|
{
|
||||||
|
"type": "1", 1表示心跳包
|
||||||
|
"projectId":"", 项目id
|
||||||
|
"fbdwId":"", 分包单位id
|
||||||
|
"bzId":"", 班组id
|
||||||
|
"msg": ""
|
||||||
|
}
|
||||||
|
*/
|
||||||
try {
|
try {
|
||||||
//初始化
|
//初始化
|
||||||
Map<String,Object> map;
|
Map<String,Object> map;
|
||||||
//连接成功过后 获取当前项目下所有成员最新坐标
|
//连接成功过后 获取当前项目下所有成员最新坐标
|
||||||
Map<String, List<String>> params = session.getRequestParameterMap();
|
Map<String, List<String>> params = session.getRequestParameterMap();
|
||||||
|
//项目id
|
||||||
|
String projectId = null;
|
||||||
List<String> subscriptionIds = params.get("projectId");
|
List<String> subscriptionIds = params.get("projectId");
|
||||||
String projectId = subscriptionIds.getFirst();
|
if (subscriptionIds != null && !subscriptionIds.isEmpty()) {
|
||||||
map = getData(projectId);
|
projectId = subscriptionIds.getFirst();
|
||||||
|
}
|
||||||
|
//分包单位id
|
||||||
|
List<String> fbdwIds = params.get("fbdwId");
|
||||||
|
String fbdwId =null;
|
||||||
|
if (fbdwIds != null && !fbdwIds.isEmpty()) {
|
||||||
|
fbdwId = fbdwIds.getFirst();
|
||||||
|
}
|
||||||
|
//班组id
|
||||||
|
String bzId = null;
|
||||||
|
List<String> bzIds = params.get("bzId");
|
||||||
|
if (bzIds != null && !bzIds.isEmpty()) {
|
||||||
|
bzId = bzIds.getFirst();
|
||||||
|
}
|
||||||
|
map = getData(projectId, fbdwId, bzId);
|
||||||
|
|
||||||
session.getBasicRemote().sendText(JSON.toJSONString(map));
|
session.getBasicRemote().sendText(JSON.toJSONString(map));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -107,7 +127,17 @@ public class RydwWebSocketServer {
|
|||||||
JSONObject jsonObject = JSON.parseObject(message);
|
JSONObject jsonObject = JSON.parseObject(message);
|
||||||
if (jsonObject.get("type").equals("1")){
|
if (jsonObject.get("type").equals("1")){
|
||||||
if (jsonObject.get("projectId") != null){
|
if (jsonObject.get("projectId") != null){
|
||||||
Map<String, Object> objectMap = getData(jsonObject.get("projectId").toString());
|
String fbdwId = null;
|
||||||
|
//分包单位id
|
||||||
|
if (jsonObject.get("fbdwId") != null) {
|
||||||
|
fbdwId = jsonObject.get("fbdwId").toString();
|
||||||
|
}
|
||||||
|
//班组id
|
||||||
|
String bzId = null;
|
||||||
|
if (jsonObject.get("bzId") != null) {
|
||||||
|
bzId = jsonObject.get("bzId").toString();
|
||||||
|
}
|
||||||
|
Map<String, Object> objectMap = getData(jsonObject.get("projectId").toString(), fbdwId, bzId);
|
||||||
session.getBasicRemote().sendText(JSON.toJSONString(objectMap));
|
session.getBasicRemote().sendText(JSON.toJSONString(objectMap));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,7 +195,7 @@ public class RydwWebSocketServer {
|
|||||||
/**
|
/**
|
||||||
* 获取数据 用于首次和心跳
|
* 获取数据 用于首次和心跳
|
||||||
*/
|
*/
|
||||||
public Map<String,Object> getData(String projectId){
|
public Map<String,Object> getData(String projectId,String fbdwId,String bzId){
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
if (projectId != null && !projectId.isEmpty()){
|
if (projectId != null && !projectId.isEmpty()){
|
||||||
// 获取当天结束时间
|
// 获取当天结束时间
|
||||||
@ -178,11 +208,12 @@ public class RydwWebSocketServer {
|
|||||||
//拿到项目下所有人员
|
//拿到项目下所有人员
|
||||||
LambdaQueryWrapper<SubConstructionUser> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SubConstructionUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(SubConstructionUser::getProjectId, projectId);
|
queryWrapper.eq(SubConstructionUser::getProjectId, projectId);
|
||||||
|
queryWrapper.eq(StringUtils.isNotBlank(fbdwId), SubConstructionUser::getContractorId, fbdwId);
|
||||||
|
queryWrapper.eq(StringUtils.isNotBlank(bzId), SubConstructionUser::getTeamId, bzId);
|
||||||
List<SubConstructionUser> list = subConstructionUserService.list(queryWrapper);
|
List<SubConstructionUser> list = subConstructionUserService.list(queryWrapper);
|
||||||
//获取此项目打卡范围
|
//获取此项目打卡范围
|
||||||
LambdaQueryWrapper<BusProjectPunchrange> busProjectPunchrangeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<BusProjectPunchrange> busProjectPunchrangeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
busProjectPunchrangeLambdaQueryWrapper.eq(BusProjectPunchrange::getProjectId, projectId);
|
busProjectPunchrangeLambdaQueryWrapper.eq(BusProjectPunchrange::getProjectId, projectId);
|
||||||
//打卡范围
|
|
||||||
List<BusProjectPunchrange> busProjectPunchranges = busProjectPunchrangeService.list(busProjectPunchrangeLambdaQueryWrapper);
|
List<BusProjectPunchrange> busProjectPunchranges = busProjectPunchrangeService.list(busProjectPunchrangeLambdaQueryWrapper);
|
||||||
//通过打卡范围构建下方统计数据
|
//通过打卡范围构建下方统计数据
|
||||||
List<Map<String, Map>> allValue = new ArrayList<>();
|
List<Map<String, Map>> allValue = new ArrayList<>();
|
||||||
@ -251,15 +282,12 @@ public class RydwWebSocketServer {
|
|||||||
|
|
||||||
int zrys = 0;
|
int zrys = 0;
|
||||||
int ycry = 0;
|
int ycry = 0;
|
||||||
int dwcs = 0;
|
Integer dwcs = 0;
|
||||||
int zgry = 0;
|
int zgry = 0;
|
||||||
|
|
||||||
if (list != null && !list.isEmpty()){
|
if (list != null && !list.isEmpty()){
|
||||||
//初始化
|
//初始化
|
||||||
List<SysUserVo> gpsList = new ArrayList<>();
|
List<SysUserVo> gpsList = new ArrayList<>();
|
||||||
List<String> onlineUserList = ChatServerHandler.getOnlineUserList();
|
|
||||||
|
|
||||||
|
|
||||||
//循环班组人员列表
|
//循环班组人员列表
|
||||||
for (SubConstructionUser constructionUser : list) {
|
for (SubConstructionUser constructionUser : list) {
|
||||||
//从redis拿到缓存最新坐标
|
//从redis拿到缓存最新坐标
|
||||||
@ -269,7 +297,8 @@ public class RydwWebSocketServer {
|
|||||||
}else {
|
}else {
|
||||||
// zgry++;
|
// zgry++;
|
||||||
}
|
}
|
||||||
GpsEquipmentSon one = RedisUtils.getCacheObject("rydw_userId_:" + constructionUser.getSysUserId());
|
GpsEquipmentSonBo bo = RedisUtils.getCacheObject("rydw_userId_:" + constructionUser.getSysUserId());
|
||||||
|
GpsEquipmentSon one = gpsEquipmentSonService.getById(bo.getId());
|
||||||
|
|
||||||
if (one != null){
|
if (one != null){
|
||||||
//获取人员
|
//获取人员
|
||||||
@ -277,13 +306,12 @@ public class RydwWebSocketServer {
|
|||||||
sysUserVo.setJd(one.getLocLongitude());
|
sysUserVo.setJd(one.getLocLongitude());
|
||||||
sysUserVo.setWd(one.getLocLatitude());
|
sysUserVo.setWd(one.getLocLatitude());
|
||||||
sysUserVo.setZhdwsj(one.getCreateTime());
|
sysUserVo.setZhdwsj(one.getCreateTime());
|
||||||
|
// sysUserVo.setAvatar(1000000L);
|
||||||
boolean isFind = false;
|
boolean isFind = false;
|
||||||
//循环打卡范围 判断是否是异常状态
|
//循环打卡范围 判断是否是异常状态
|
||||||
for (BusProjectPunchrange busProjectPunchrange : busProjectPunchranges) {
|
for (BusProjectPunchrange busProjectPunchrange : busProjectPunchranges) {
|
||||||
//转换范围
|
//转换范围
|
||||||
Gson gson = new Gson();
|
List<String> coordinates = List.of(busProjectPunchrange.getPunchRange());
|
||||||
Type listType = new TypeToken<List<String>>() {}.getType();
|
|
||||||
List<String> coordinates = gson.fromJson(busProjectPunchrange.getPunchRange(), listType);
|
|
||||||
List<GeoPoint> matchingRange = JSTUtil.findMatchingRange(one.getLocLatitude().toString(), one.getLocLongitude().toString(), coordinates);
|
List<GeoPoint> matchingRange = JSTUtil.findMatchingRange(one.getLocLatitude().toString(), one.getLocLongitude().toString(), coordinates);
|
||||||
//如果范围外为 空
|
//如果范围外为 空
|
||||||
if (matchingRange != null && !matchingRange.isEmpty() && !isFind) {
|
if (matchingRange != null && !matchingRange.isEmpty() && !isFind) {
|
||||||
@ -291,13 +319,13 @@ public class RydwWebSocketServer {
|
|||||||
isFind = true;
|
isFind = true;
|
||||||
|
|
||||||
//判断在线状态 如果在线 范围外 则为异常 目前从聊天服务获取
|
//判断在线状态 如果在线 范围外 则为异常 目前从聊天服务获取
|
||||||
if (onlineUserList.contains(constructionUser.getSysUserId().toString())) {
|
if (ChatServerHandler.getOnlineUserList().contains(constructionUser.getSysUserId().toString())) {
|
||||||
sysUserVo.setZxzt("在线");
|
sysUserVo.setZxzt("在线");
|
||||||
//坐标在范围内在岗
|
//坐标在范围内在岗
|
||||||
zgry++;
|
zgry++;
|
||||||
|
|
||||||
String key = busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName();
|
String key = busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName();
|
||||||
//给打卡柱状图赋值
|
//给坐标柱状图赋值
|
||||||
for (Map<String, Map> mapMap : allValue) {
|
for (Map<String, Map> mapMap : allValue) {
|
||||||
//这个map为 id+名字 : 时间段 MAP
|
//这个map为 id+名字 : 时间段 MAP
|
||||||
if (mapMap.containsKey(key)){
|
if (mapMap.containsKey(key)){
|
||||||
@ -305,34 +333,90 @@ public class RydwWebSocketServer {
|
|||||||
LocalDateTime dateTime = one.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
LocalDateTime dateTime = one.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||||
// 获取小时数
|
// 获取小时数
|
||||||
int hour = dateTime.getHour();
|
int hour = dateTime.getHour();
|
||||||
// 根据小时数判断所属区间并增加计数
|
// 根据小时数判断所属区间并增加计数 一个人在一个时间段只能增加一次 设计一个新的redis存储 Key = 范围ID + 时间段 + 用户ID value = 0(未统计)1(已统计) 过期时间 = 今天为止
|
||||||
if (hour >= 6 && hour < 8) {
|
if (hour >= 6 && hour < 8) {
|
||||||
mapMap.get(mapMap.get(key)).put("06:00", (int)mapMap.get(key).get("06:00") + 1);
|
//先从redis判断此人在该时间段是否已经活动过
|
||||||
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":06:00", (int)mapMap.get(key).get("06:00") + 1, Duration.ofSeconds(expireSeconds));
|
boolean b = RedisUtils.isExistsObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "06:00" + "_" + constructionUser.getSysUserId());
|
||||||
|
//如果不存在
|
||||||
|
if (!b) {
|
||||||
|
mapMap.get(key).put("06:00", (int) mapMap.get(key).get("06:00") + 1);
|
||||||
|
//将redis中该时间段人数+1 map中已经加过
|
||||||
|
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":06:00", (int) mapMap.get(key).get("06:00"), Duration.ofSeconds(expireSeconds));
|
||||||
|
//判断数据添加到redis
|
||||||
|
RedisUtils.setCacheObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "06:00" + "_" + constructionUser.getSysUserId(), 1, Duration.ofSeconds(expireSeconds));
|
||||||
|
}
|
||||||
|
|
||||||
} else if (hour >= 8 && hour < 10) {
|
} else if (hour >= 8 && hour < 10) {
|
||||||
mapMap.get(mapMap.get(key)).put("08:00", (int)mapMap.get(key).get("08:00") + 1);
|
//先从redis判断此人在该时间段是否已经活动过
|
||||||
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":08:00", (int)mapMap.get(key).get("08:00") + 1, Duration.ofSeconds(expireSeconds));
|
boolean b = RedisUtils.isExistsObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "08:00" + "_" + constructionUser.getSysUserId());
|
||||||
|
//如果不存在
|
||||||
|
if (!b) {
|
||||||
|
mapMap.get(key).put("08:00", (int) mapMap.get(key).get("08:00") + 1);
|
||||||
|
//将redis中该时间段人数+1
|
||||||
|
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":08:00", (int) mapMap.get(key).get("08:00"), Duration.ofSeconds(expireSeconds));
|
||||||
|
//判断数据添加到redis
|
||||||
|
RedisUtils.setCacheObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "08:00" + "_" + constructionUser.getSysUserId(), 1, Duration.ofSeconds(expireSeconds));
|
||||||
|
}
|
||||||
|
|
||||||
} else if (hour >= 10 && hour < 12) {
|
} else if (hour >= 10 && hour < 12) {
|
||||||
mapMap.get(mapMap.get(key)).put("10:00", (int)mapMap.get(key).get("10:00") + 1);
|
//先从redis判断此人在该时间段是否已经活动过
|
||||||
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":10:00", (int)mapMap.get(key).get("10:00") + 1, Duration.ofSeconds(expireSeconds));
|
boolean b = RedisUtils.isExistsObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "10:00" + "_" + constructionUser.getSysUserId());
|
||||||
|
//如果不存在
|
||||||
|
if (!b) {
|
||||||
|
mapMap.get(key).put("10:00", (int) mapMap.get(key).get("10:00") + 1);
|
||||||
|
//将redis中该时间段人数+1
|
||||||
|
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":10:00", (int) mapMap.get(key).get("10:00"), Duration.ofSeconds(expireSeconds));
|
||||||
|
//判断数据添加到redis
|
||||||
|
RedisUtils.setCacheObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "10:00" + "_" + constructionUser.getSysUserId(), 1, Duration.ofSeconds(expireSeconds));
|
||||||
|
}
|
||||||
|
|
||||||
} else if (hour >= 12 && hour < 14) {
|
} else if (hour >= 12 && hour < 14) {
|
||||||
mapMap.get(mapMap.get(key)).put("12:00", (int)mapMap.get(key).get("12:00") + 1);
|
//先从redis判断此人在该时间段是否已经活动过
|
||||||
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":12:00", (int)mapMap.get(key).get("12:00") + 1, Duration.ofSeconds(expireSeconds));
|
boolean b = RedisUtils.isExistsObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "12:00" + "_" + constructionUser.getSysUserId());
|
||||||
|
//如果不存在
|
||||||
|
if (!b) {
|
||||||
|
mapMap.get(key).put("12:00", (int) mapMap.get(key).get("12:00") + 1);
|
||||||
|
//将redis中该时间段人数+1
|
||||||
|
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":12:00", (int) mapMap.get(key).get("12:00"), Duration.ofSeconds(expireSeconds));
|
||||||
|
//判断数据添加到redis
|
||||||
|
RedisUtils.setCacheObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "12:00" + "_" + constructionUser.getSysUserId(), 1, Duration.ofSeconds(expireSeconds));
|
||||||
|
}
|
||||||
|
|
||||||
} else if (hour >= 14 && hour < 16) {
|
} else if (hour >= 14 && hour < 16) {
|
||||||
mapMap.get(mapMap.get(key)).put("14:00", (int)mapMap.get(key).get("14:00") + 1);
|
//先从redis判断此人在该时间段是否已经活动过
|
||||||
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":14:00", (int)mapMap.get(key).get("14:00") + 1, Duration.ofSeconds(expireSeconds));
|
boolean b = RedisUtils.isExistsObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "14:00" + "_" + constructionUser.getSysUserId());
|
||||||
|
//如果不存在
|
||||||
|
if (!b) {
|
||||||
|
mapMap.get(key).put("14:00", (int) mapMap.get(key).get("14:00") + 1);
|
||||||
|
//将redis中该时间段人数+1
|
||||||
|
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":14:00", (int) mapMap.get(key).get("14:00"), Duration.ofSeconds(expireSeconds));
|
||||||
|
//判断数据添加到redis
|
||||||
|
RedisUtils.setCacheObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "14:00" + "_" + constructionUser.getSysUserId(), 1, Duration.ofSeconds(expireSeconds));
|
||||||
|
}
|
||||||
|
|
||||||
} else if (hour >= 16 && hour < 18) {
|
} else if (hour >= 16 && hour < 18) {
|
||||||
mapMap.get(mapMap.get(key)).put("16:00", (int)mapMap.get(key).get("16:00") + 1);
|
//先从redis判断此人在该时间段是否已经活动过
|
||||||
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":16:00", (int)mapMap.get(key).get("16:00") + 1, Duration.ofSeconds(expireSeconds));
|
boolean b = RedisUtils.isExistsObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "16:00" + "_" + constructionUser.getSysUserId());
|
||||||
|
//如果不存在
|
||||||
|
if (!b) {
|
||||||
|
mapMap.get(key).put("16:00", (int) mapMap.get(key).get("16:00") + 1);
|
||||||
|
//将redis中该时间段人数+1
|
||||||
|
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":16:00", (int) mapMap.get(key).get("16:00"), Duration.ofSeconds(expireSeconds));
|
||||||
|
//判断数据添加到redis
|
||||||
|
RedisUtils.setCacheObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "16:00" + "_" + constructionUser.getSysUserId(), 1, Duration.ofSeconds(expireSeconds));
|
||||||
|
}
|
||||||
|
|
||||||
} else if (hour >= 18 && hour < 20) {
|
} else if (hour >= 18 && hour < 20) {
|
||||||
mapMap.get(mapMap.get(key)).put("18:00", (int)mapMap.get(key).get("18:00") + 1);
|
//先从redis判断此人在该时间段是否已经活动过
|
||||||
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":18:00", (int)mapMap.get(key).get("18:00") + 1, Duration.ofSeconds(expireSeconds));
|
boolean b = RedisUtils.isExistsObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "18:00" + "_" + constructionUser.getSysUserId());
|
||||||
|
//如果不存在
|
||||||
|
if (!b) {
|
||||||
|
mapMap.get(key).put("18:00", (int) mapMap.get(key).get("18:00") + 1);
|
||||||
|
//将redis中该时间段人数+1
|
||||||
|
RedisUtils.setCacheObject(busProjectPunchrange.getId() + ":" + busProjectPunchrange.getPunchName() + ":18:00", (int) mapMap.get(key).get("18:00"), Duration.ofSeconds(expireSeconds));
|
||||||
|
//判断数据添加到redis
|
||||||
|
RedisUtils.setCacheObject("rydw_tj_"+busProjectPunchrange.getId() + "_" + "18:00" + "_" + constructionUser.getSysUserId(), 1, Duration.ofSeconds(expireSeconds));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -341,9 +425,9 @@ public class RydwWebSocketServer {
|
|||||||
}
|
}
|
||||||
//进一步判断状态
|
//进一步判断状态
|
||||||
if (sysUserVo.getZxzt() == null || sysUserVo.getZxzt().isEmpty()){
|
if (sysUserVo.getZxzt() == null || sysUserVo.getZxzt().isEmpty()){
|
||||||
if (onlineUserList.contains(constructionUser.getSysUserId().toString()) && !isFind){
|
if (ChatServerHandler.getOnlineUserList().contains(constructionUser.getSysUserId().toString()) && !isFind){
|
||||||
sysUserVo.setZxzt("异常");
|
sysUserVo.setZxzt("异常");
|
||||||
}else if (!onlineUserList.contains(constructionUser.getSysUserId().toString())){
|
}else if (!ChatServerHandler.getOnlineUserList().contains(constructionUser.getSysUserId().toString())){
|
||||||
sysUserVo.setZxzt("离线");
|
sysUserVo.setZxzt("离线");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -353,6 +437,7 @@ public class RydwWebSocketServer {
|
|||||||
ycry++;
|
ycry++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//人员级GPS坐标列表
|
||||||
gpsList.add(sysUserVo);
|
gpsList.add(sysUserVo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -367,20 +452,85 @@ public class RydwWebSocketServer {
|
|||||||
map.put("ycry",ycry);
|
map.put("ycry",ycry);
|
||||||
|
|
||||||
//总人员数
|
//总人员数
|
||||||
// map.put("zrys",list.size());
|
|
||||||
map.put("zrys",zgry + ycry);
|
map.put("zrys",zgry + ycry);
|
||||||
|
|
||||||
//定位次数
|
//定位次数
|
||||||
Long cacheObject = RedisUtils.getCacheObject("rydw_");
|
if (RedisUtils.isExistsObject("rydw_cs")){
|
||||||
if (cacheObject != null){
|
dwcs = RedisUtils.getCacheObject("rydw_cs");
|
||||||
dwcs = cacheObject.intValue();
|
|
||||||
}
|
}
|
||||||
map.put("dwcs",dwcs);
|
map.put("dwcs",dwcs);
|
||||||
|
|
||||||
//柱状图数据
|
//柱状图数据
|
||||||
map.put("zztsj",allValue);
|
map.put("zztsj",allValue);
|
||||||
|
|
||||||
|
//饼状图数据 区域时间段人数Map list人员列表 busProjectPunchranges打卡范围列表
|
||||||
|
map.put("bztsj",getPieData(allValue, list, busProjectPunchranges));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计饼状图 数据
|
||||||
|
*/
|
||||||
|
public List<Map.Entry<String, Integer>> getPieData(List<Map<String, Map>> value,List<SubConstructionUser> persons,List<BusProjectPunchrange> dkfw) {
|
||||||
|
//redis中有判断标识数据: "rydw_tj_"+busProjectPunchrange.getId() + "_" + "06:00" + "_" + constructionUser.getSysUserId()
|
||||||
|
|
||||||
|
//饼状图数据Map
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
|
||||||
|
for (Map<String, Map> mapMap : value) {
|
||||||
|
//打卡范围ID : 打卡范围名称
|
||||||
|
Set<String> keys = mapMap.keySet();
|
||||||
|
for (String fwIdMc : keys) {
|
||||||
|
//时间段
|
||||||
|
Set keySet = mapMap.get(fwIdMc).keySet();
|
||||||
|
for (Object time : keySet) {
|
||||||
|
//组合key值进行查询redis: 打卡范围ID + "_" + 时间段 + "_" + 用户ID
|
||||||
|
String[] split = fwIdMc.split(":");
|
||||||
|
//分离出范围ID
|
||||||
|
String fwId = split[0];
|
||||||
|
//范围名称
|
||||||
|
String fwMc = split[1];
|
||||||
|
//组合用户id进行循环查询
|
||||||
|
for (SubConstructionUser person : persons) {
|
||||||
|
//在此范围 此时间 循环用户 -> 在此范围 下一个时间 循环用户 -> 在下一个范围 此时间 循环用户
|
||||||
|
String key = "rydw_tj_"+fwId + "_" + time + "_" + person.getSysUserId();
|
||||||
|
//针对时间去重 一个范围内只需要有一个时间段在范围内 其余不统计
|
||||||
|
if (RedisUtils.isExistsObject( key)){
|
||||||
|
//在map中判断 如果有 则不进行添加
|
||||||
|
if (!map.containsKey(fwId + "_" + person.getSysUserId())) {
|
||||||
|
//如果没有 则说明该用户在 这个范围 这个时间段 有数据 可以添加
|
||||||
|
map.put(fwId + "_" + person.getSysUserId(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//循环完成后 可以统计出 在此范围 此用户 是否活跃过
|
||||||
|
Map<String, Integer> countMap = new HashMap<>();
|
||||||
|
//再次进行循环 统计出 一个范围内 多少活跃 用一个新map进行计数
|
||||||
|
map.forEach((key, num) -> {
|
||||||
|
for (BusProjectPunchrange fw : dkfw) {
|
||||||
|
//提取出范围ID
|
||||||
|
String fwId = key.split("_")[0];
|
||||||
|
if (fw.getId().toString().equals(fwId)) {
|
||||||
|
if (!countMap.containsKey(fw.getId() + ":" + fw.getPunchName())){
|
||||||
|
//如果没有则初始化为1人
|
||||||
|
countMap.put(fw.getId() + ":" + fw.getPunchName(), 1);
|
||||||
|
}else {
|
||||||
|
//如果有则进行累加
|
||||||
|
countMap.put(fw.getId() + ":" + fw.getPunchName(), countMap.get(fw.getId() + ":" + fw.getPunchName()) + 1);
|
||||||
|
}
|
||||||
|
//放一条测试数据
|
||||||
|
countMap.put("1000000:测试数据", 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return new ArrayList<>(countMap.entrySet());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user