bug修复

This commit is contained in:
guo 2024-03-25 17:36:28 +08:00
parent f8b4739f80
commit f55a15e140
3 changed files with 31 additions and 13 deletions

View File

@ -6,25 +6,24 @@ import com.alibaba.fastjson.JSONArray;
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.zhgd.jeecg.common.util.SpringContextUtils; import com.zhgd.jeecg.common.util.SpringContextUtils;
import com.zhgd.xmgl.enums.ParamEnum;
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatAlarm; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatAlarm;
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData;
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDev; import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDev;
import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDevMapper; import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDevMapper;
import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatAlarmService; import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatAlarmService;
import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService; import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.websocket.*; import javax.websocket.*;
import java.util.Date; import java.util.Date;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@Data
@ClientEndpoint @ClientEndpoint
@Slf4j @Slf4j
@RestController @RestController
@ -154,9 +153,8 @@ public class SafetyHatWSClient {
* @param message 消息内容 * @param message 消息内容
*/ */
public void send(String message) { public void send(String message) {
log.info("发送客户端消息到服务端id{}ms:{}", id, message);
this.session.getAsyncRemote().sendText(message); this.session.getAsyncRemote().sendText(message);
} }
public SafetyHatWSClient(String id) { public SafetyHatWSClient(String id) {

View File

@ -2,6 +2,8 @@ package com.zhgd.xmgl.config;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.websocket.ContainerProvider; import javax.websocket.ContainerProvider;
import javax.websocket.WebSocketContainer; import javax.websocket.WebSocketContainer;
@ -18,6 +20,8 @@ public class WebSocketConfig {
public WebSocketContainer webSocketContainer() { public WebSocketContainer webSocketContainer() {
WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer(); WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();
webSocketContainer.setDefaultMaxSessionIdleTimeout(300000L); webSocketContainer.setDefaultMaxSessionIdleTimeout(300000L);
webSocketContainer.setDefaultMaxBinaryMessageBufferSize(20 * 1024 * 1024);
webSocketContainer.setDefaultMaxTextMessageBufferSize(20 * 1024 * 1024);
return webSocketContainer; return webSocketContainer;
} }
} }

View File

@ -33,13 +33,13 @@ public class SafetyHatTask {
IProjectService projectService; IProjectService projectService;
@Autowired @Autowired
WebSocketContainer webSocketContainer; WebSocketContainer webSocketContainer;
@Autowired //@Autowired
SafetyHatWSClient safetyHatWSClient; SafetyHatWSClient safetyHatWSClient;
/** /**
* 获取安全帽最新数据30秒内的心跳 * 获取安全帽最新数据30秒内的心跳
*/ */
@Scheduled(cron = "*/10 * * * * ?") @Scheduled(cron = "*/20 * * * * ?")
@RequestMapping("getHelmetData") @RequestMapping("getHelmetData")
public void getHelmetData() { public void getHelmetData() {
try { try {
@ -74,6 +74,26 @@ public class SafetyHatTask {
} }
} }
/**
* 测试发生安全帽数据
*/
@RequestMapping("testGetHelmetData")
public void testGetHelmetData() {
SafetyHatWSClient client = new SafetyHatWSClient("jkbdz");
try {
webSocketContainer.connectToServer(client, new URI("wss://caps.runde.pro/wss"));
} catch (DeploymentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
//SafetyHatWSClient.clientMap1.put("jkbdz", client);
String message = "{\"act\":\"ma_login\",\"user_name\":\"jkbdz\",\"access_token\":\"5c26d999d97009fc4b5d3347f6463c17\"}";
client.send(message);
}
/** /**
* 连接ws和登录 * 连接ws和登录
* *
@ -83,14 +103,10 @@ public class SafetyHatTask {
* @throws URISyntaxException * @throws URISyntaxException
*/ */
private SafetyHatWSClient connect(Project project) { private SafetyHatWSClient connect(Project project) {
SafetyHatWSClient client = new SafetyHatWSClient(); SafetyHatWSClient client = new SafetyHatWSClient(project.getHelmetUser());
try { try {
webSocketContainer.connectToServer(client, new URI("wss://caps.runde.pro/wss")); webSocketContainer.connectToServer(client, new URI("wss://caps.runde.pro/wss"));
} catch (DeploymentException e) { } catch (Exception e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace(); e.printStackTrace();
} }
JSONObject token = RundeSafeyHatUtils.getToken(project.getHelmetUser(), project.getHelmetPassword()); JSONObject token = RundeSafeyHatUtils.getToken(project.getHelmetUser(), project.getHelmetPassword());