|
@@ -5,7 +5,6 @@ import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
import org.springblade.business.service.ITaskService;
|
|
|
-import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
@@ -54,8 +53,8 @@ public class WebSocket {
|
|
|
this.userId = userId;
|
|
|
//加入map
|
|
|
webSocketMap.put(userId, this);
|
|
|
- addOnlineCount(); //在线数加1
|
|
|
- logger.info("用户{}连接成功,当前在线人数为{}", userId, getOnlineCount());
|
|
|
+ addOnlineCount();//在线数加1
|
|
|
+ logger.info("用户:{}连接成功,当前在线人数为{}人", userId, getOnlineCount());
|
|
|
try {
|
|
|
sendMessage(String.valueOf(this.session.getQueryString()));
|
|
|
} catch (IOException e) {
|
|
@@ -69,7 +68,7 @@ public class WebSocket {
|
|
|
webSocketMap.remove(userId);
|
|
|
webSocketMessageMap.remove(userId);
|
|
|
subOnlineCount(); //在线数减1
|
|
|
- logger.info("用户{}关闭连接!当前在线人数为{}", userId, getOnlineCount());
|
|
|
+ logger.info("用户:{}关闭了连接!当前在线人数为{}人", userId, getOnlineCount());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -79,34 +78,36 @@ public class WebSocket {
|
|
|
*/
|
|
|
@OnMessage
|
|
|
public void onMessage(String message, Session session) {
|
|
|
- webSocketMessageMap.put(userId, message);
|
|
|
- logger.info("来自客户端用户:{} 消息:{}", userId, message);
|
|
|
-
|
|
|
- String projectId = "";
|
|
|
- String contractId = "";
|
|
|
- if (message.contains(",")) {
|
|
|
- projectId = message.split(",")[0];
|
|
|
- contractId = message.split(",")[1];
|
|
|
- } else {
|
|
|
- //后管处理userId
|
|
|
- userId = AuthUtil.getUserId().toString();
|
|
|
- //userId = "1123598821738675201";
|
|
|
- }
|
|
|
+ if (StringUtils.isNotEmpty(userId)) {
|
|
|
+ webSocketMessageMap.put(userId, message);
|
|
|
+ String projectId = "";
|
|
|
+ String contractId = "";
|
|
|
+ if (message.contains(",")) {
|
|
|
+ logger.info("来自客户端用户:{} 消息:{}", userId, message);
|
|
|
+ projectId = message.split(",")[0];
|
|
|
+ contractId = message.split(",")[1];
|
|
|
+ } else {
|
|
|
+ logger.info("来自后管用户:{} 消息:{}", userId, message);
|
|
|
+ userId = message;
|
|
|
+ }
|
|
|
|
|
|
- Map<String, String> stringMap;
|
|
|
- if (StringUtils.isNotEmpty(projectId) && StringUtils.isNotEmpty(contractId) && StringUtils.isNotEmpty(userId)) {
|
|
|
- //客户端
|
|
|
- stringMap = iTaskService.getTaskCount(projectId, contractId, userId);
|
|
|
- } else {
|
|
|
- //后管
|
|
|
- stringMap = iTaskService.getTaskCount(null, null, userId);
|
|
|
- }
|
|
|
+ Map<String, String> stringMap;
|
|
|
+ if (StringUtils.isNotEmpty(projectId) && StringUtils.isNotEmpty(contractId)) {
|
|
|
+ //客户端
|
|
|
+ stringMap = iTaskService.getTaskCount(projectId, contractId, userId);
|
|
|
+ } else {
|
|
|
+ //后管
|
|
|
+ stringMap = iTaskService.getTaskCount(null, null, userId);
|
|
|
+ }
|
|
|
|
|
|
- //客户端切换项目合同段、后管推送消息
|
|
|
- try {
|
|
|
- webSocketMap.get(userId).sendMessage(JSON.toJSONString(stringMap));
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ try {
|
|
|
+ webSocketMap.get(userId).sendMessage(JSON.toJSONString(stringMap));
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.info("未获取到用户信息,接收消息失败");
|
|
|
}
|
|
|
}
|
|
|
|