修改websocket配置
This commit is contained in:
@@ -19,7 +19,7 @@ public interface RemoteWebSocketMessageService {
|
||||
* @param webSocketMsgType webSocket消息类型
|
||||
* @param data 消息数据
|
||||
*/
|
||||
void publishMessage(List<Long> sessionKey, WebSocketMsgType webSocketMsgType, Object data);
|
||||
void publishMessage(List<Long> sessionKey, WebSocketMsgType webSocketMsgType, String data);
|
||||
|
||||
/**
|
||||
* 发布订阅的消息(群发)
|
||||
@@ -27,7 +27,7 @@ public interface RemoteWebSocketMessageService {
|
||||
* @param webSocketMsgType webSocket消息类型
|
||||
* @param data 消息数据
|
||||
*/
|
||||
void publishAll(WebSocketMsgType webSocketMsgType, Object data);
|
||||
void publishAll(WebSocketMsgType webSocketMsgType, String data);
|
||||
|
||||
/**
|
||||
* 向指定的用户的指定会话发送消息
|
||||
@@ -36,6 +36,6 @@ public interface RemoteWebSocketMessageService {
|
||||
* @param webSocketMsgType webSocket消息类型
|
||||
* @param data 消息数据
|
||||
*/
|
||||
void sendMessage(Long userId, WebSocketMsgType webSocketMsgType, Object data);
|
||||
void sendMessage(Long userId, WebSocketMsgType webSocketMsgType, String data);
|
||||
|
||||
}
|
||||
|
@@ -7,8 +7,9 @@ package org.dromara.resource.api.domain;
|
||||
*/
|
||||
public enum WebSocketMsgType {
|
||||
|
||||
ALARM_MSG(100);
|
||||
ALARM_MSG(100),
|
||||
|
||||
MOBILE_QRCODE(200);
|
||||
/**
|
||||
* 消息类型编码
|
||||
* 大类型 - 100,200,300,400 累加100
|
||||
|
@@ -2,6 +2,7 @@ package org.dromara.common.websocket.holder;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
@@ -14,6 +15,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*
|
||||
* @author zendwang
|
||||
*/
|
||||
@Slf4j
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class WebSocketSessionHolder {
|
||||
|
||||
@@ -26,10 +28,10 @@ public class WebSocketSessionHolder {
|
||||
* @param session 要添加的WebSocket会话
|
||||
*/
|
||||
public static void addSession(Long sessionKey, WebSocketSession session) {
|
||||
System.out.println(USER_SESSION_MAP);
|
||||
log.info("USER_SESSION_MAP={}", USER_SESSION_MAP);
|
||||
removeSession(sessionKey);
|
||||
USER_SESSION_MAP.put(sessionKey, session);
|
||||
System.out.println(USER_SESSION_MAP);
|
||||
log.info("USER_SESSION_MAP={}", USER_SESSION_MAP);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +40,7 @@ public class WebSocketSessionHolder {
|
||||
* @param sessionKey 要移除的会话键
|
||||
*/
|
||||
public static void removeSession(Long sessionKey) {
|
||||
System.out.println(USER_SESSION_MAP);
|
||||
log.info("USER_SESSION_MAP={}", USER_SESSION_MAP);
|
||||
WebSocketSession session = USER_SESSION_MAP.remove(sessionKey);
|
||||
try {
|
||||
session.close(CloseStatus.BAD_DATA);
|
||||
@@ -53,7 +55,7 @@ public class WebSocketSessionHolder {
|
||||
* @return 与给定会话键对应的WebSocket会话,如果不存在则返回null
|
||||
*/
|
||||
public static WebSocketSession getSessions(Long sessionKey) {
|
||||
System.out.println(USER_SESSION_MAP);
|
||||
log.info("USER_SESSION_MAP={}", USER_SESSION_MAP);
|
||||
return USER_SESSION_MAP.get(sessionKey);
|
||||
}
|
||||
|
||||
|
@@ -1,43 +1,39 @@
|
||||
package org.dromara.property.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.common.core.constant.GlobalConstants;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
import org.dromara.common.core.validate.EditGroup;
|
||||
import org.dromara.common.excel.utils.ExcelUtil;
|
||||
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||
import org.dromara.common.log.annotation.Log;
|
||||
import org.dromara.common.log.enums.BusinessType;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.common.web.core.BaseController;
|
||||
import org.dromara.property.domain.bo.QrCodeInfo;
|
||||
import org.dromara.property.domain.bo.TbVisitorManagementBo;
|
||||
import org.dromara.property.domain.vo.TbVisitorManagementVo;
|
||||
import org.dromara.property.service.ITbVisitorManagementService;
|
||||
import org.dromara.resource.api.RemoteWebSocketMessageService;
|
||||
import org.dromara.resource.api.domain.WebSocketMsgType;
|
||||
import org.dromara.system.api.RemoteConfigService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.*;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.common.core.constant.GlobalConstants;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.common.websocket.dto.WebSocketMessageDto;
|
||||
import org.dromara.common.websocket.holder.WebSocketSessionHolder;
|
||||
import org.dromara.common.websocket.utils.WebSocketUtils;
|
||||
import org.dromara.property.domain.bo.QrCodeInfo;
|
||||
import org.dromara.resource.api.RemoteMessageService;
|
||||
import org.dromara.system.api.RemoteConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||
import org.dromara.common.log.annotation.Log;
|
||||
import org.dromara.common.web.core.BaseController;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
import org.dromara.common.core.validate.EditGroup;
|
||||
import org.dromara.common.log.enums.BusinessType;
|
||||
import org.dromara.common.excel.utils.ExcelUtil;
|
||||
import org.dromara.property.domain.vo.TbVisitorManagementVo;
|
||||
import org.dromara.property.domain.bo.TbVisitorManagementBo;
|
||||
import org.dromara.property.service.ITbVisitorManagementService;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 访客管理
|
||||
* 前端访问路由地址为:/property/visitorManagement
|
||||
@@ -53,9 +49,9 @@ public class TbVisitorManagementController extends BaseController {
|
||||
|
||||
private final ITbVisitorManagementService tbVisitorManagementService;
|
||||
@DubboReference
|
||||
private final RemoteConfigService remoteConfigService;
|
||||
|
||||
|
||||
private RemoteConfigService remoteConfigService;
|
||||
@DubboReference
|
||||
private RemoteWebSocketMessageService remoteWebSocketMessageService;
|
||||
|
||||
|
||||
/**
|
||||
@@ -69,43 +65,40 @@ public class TbVisitorManagementController extends BaseController {
|
||||
|
||||
/**
|
||||
* 获取二维码uuid
|
||||
*
|
||||
* @param qrCodeInfo
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/getcode")
|
||||
public R<String> getcode(QrCodeInfo qrCodeInfo) {
|
||||
String userid =StpUtil.getLoginId().toString();
|
||||
String userid = StpUtil.getLoginId().toString();
|
||||
String[] split = userid.split(":");
|
||||
Long s1 = Long.valueOf(split[1]);
|
||||
qrCodeInfo.setUserid(s1);
|
||||
String s = remoteConfigService.selectQrTimeOut();
|
||||
int i = Integer.parseInt(s);
|
||||
UUID value = UUID.randomUUID();
|
||||
RedisUtils.setCacheObject(GlobalConstants.CAPTCHA_CODE_KEY+"Qrcode"+value, qrCodeInfo, Duration.ofSeconds(i));
|
||||
RedisUtils.setCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + "Qrcode" + value, qrCodeInfo, Duration.ofSeconds(i));
|
||||
return R.ok(value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送二维码被扫信息
|
||||
*
|
||||
* @param qrcode
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/useqr")
|
||||
public R<String> useqr(String qrcode) {
|
||||
QrCodeInfo qrCodeInfo = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY +"Qrcode" + qrcode);
|
||||
if (qrCodeInfo==null) {
|
||||
QrCodeInfo qrCodeInfo = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + "Qrcode" + qrcode);
|
||||
if (qrCodeInfo == null) {
|
||||
return R.fail("二维码已过期");
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("type","qrcode");
|
||||
jsonObject.put("date",qrcode);
|
||||
System.out.println(WebSocketSessionHolder.getSessions(1L));
|
||||
System.out.println(WebSocketSessionHolder.getSessionsAll());
|
||||
WebSocketMessageDto webSocketMessage = new WebSocketMessageDto();
|
||||
webSocketMessage.setMessage(jsonObject.toString());
|
||||
webSocketMessage.setSessionKeys(List.of(qrCodeInfo.getUserid()));
|
||||
WebSocketUtils.publishMessage(webSocketMessage);
|
||||
// WebSocketUtils.sendMessage(qrCodeInfo.getUserid(),jsonObject.toString());
|
||||
jsonObject.put("type", "qrcode");
|
||||
jsonObject.put("date", qrcode);
|
||||
|
||||
remoteWebSocketMessageService.publishMessage(List.of(qrCodeInfo.getUserid()), WebSocketMsgType.MOBILE_QRCODE, jsonObject.toString());
|
||||
return R.ok("二维码可用");
|
||||
|
||||
}
|
||||
@@ -129,7 +122,7 @@ public class TbVisitorManagementController extends BaseController {
|
||||
@SaCheckPermission("property:visitorManagement:query")
|
||||
@GetMapping("/{id}")
|
||||
public R<TbVisitorManagementVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable("id") Long id) {
|
||||
@PathVariable("id") Long id) {
|
||||
return R.ok(tbVisitorManagementService.queryById(id));
|
||||
}
|
||||
|
||||
@@ -141,8 +134,8 @@ public class TbVisitorManagementController extends BaseController {
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/add")
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody TbVisitorManagementBo bo) {
|
||||
QrCodeInfo info = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY +"Qrcode" + bo.getQrCodeId());
|
||||
if (info==null){
|
||||
QrCodeInfo info = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + "Qrcode" + bo.getQrCodeId());
|
||||
if (info == null) {
|
||||
return R.fail("请确认Qr码有效");
|
||||
}
|
||||
bo.setType(0);
|
||||
@@ -151,6 +144,7 @@ public class TbVisitorManagementController extends BaseController {
|
||||
|
||||
/**
|
||||
* h5端新增访客管理
|
||||
*
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
@@ -159,8 +153,8 @@ public class TbVisitorManagementController extends BaseController {
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/addH5VistorManagement")
|
||||
public R<Void> addH5VistorManagement(@Validated(AddGroup.class) @RequestBody TbVisitorManagementBo bo) {
|
||||
QrCodeInfo info = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY +"Qrcode" + bo.getQrCodeId());
|
||||
if (info==null){
|
||||
QrCodeInfo info = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + "Qrcode" + bo.getQrCodeId());
|
||||
if (info == null) {
|
||||
return R.fail("请确认Qr码有效");
|
||||
}
|
||||
bo.setType(0);
|
||||
|
@@ -31,9 +31,9 @@ public class FaceCaptureConsumer implements RocketMQListener<MessageExt> {
|
||||
|
||||
@Override
|
||||
public void onMessage(MessageExt ext) {
|
||||
log.info("消费人脸抓拍数据,数据长度={}", ext.getBody().length);
|
||||
try {
|
||||
FaceCapture capture = JSONObject.parseObject(ext.getBody(), FaceCapture.class);
|
||||
log.info("消费人脸抓拍数据,设备={},数据长度={}", capture.getDeviceIp(), ext.getBody().length);
|
||||
eventAlarmReportService.handleCaptureImg(capture.getDeviceIp(), capture.getSmallImg(), capture.getBigImg());
|
||||
} catch (Exception e) {
|
||||
log.error("消费人脸抓拍数据处理失败,", e);
|
||||
|
@@ -6,6 +6,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -312,7 +313,7 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService, Applic
|
||||
Boolean insert = alarmEventProcessService.insert(process);
|
||||
log.info("事件处理信息写入完成,result= {}", insert);
|
||||
// 进行消息推送
|
||||
webSocketMessageService.publishMessage(List.of(bo.getSolveId()), WebSocketMsgType.ALARM_MSG, sisAlarmEvents);
|
||||
webSocketMessageService.publishMessage(List.of(bo.getSolveId()), WebSocketMsgType.ALARM_MSG, JSONObject.toJSONString(sisAlarmEvents));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ import java.util.List;
|
||||
public class RemoteWebSocketMessageServiceImpl implements RemoteWebSocketMessageService {
|
||||
|
||||
@Override
|
||||
public void publishMessage(List<Long> sessionKey, WebSocketMsgType webSocketMsgType, Object data) {
|
||||
public void publishMessage(List<Long> sessionKey, WebSocketMsgType webSocketMsgType, String data) {
|
||||
WebSocketMessageDto dto = new WebSocketMessageDto();
|
||||
dto.setSessionKeys(sessionKey);
|
||||
dto.setMessage(createMsg(webSocketMsgType, data));
|
||||
@@ -34,7 +34,7 @@ public class RemoteWebSocketMessageServiceImpl implements RemoteWebSocketMessage
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publishAll(WebSocketMsgType webSocketMsgType, Object data) {
|
||||
public void publishAll(WebSocketMsgType webSocketMsgType, String data) {
|
||||
try {
|
||||
WebSocketUtils.publishAll(createMsg(webSocketMsgType, data));
|
||||
} catch (Exception e) {
|
||||
@@ -44,7 +44,7 @@ public class RemoteWebSocketMessageServiceImpl implements RemoteWebSocketMessage
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(Long userId, WebSocketMsgType webSocketMsgType, Object data) {
|
||||
public void sendMessage(Long userId, WebSocketMsgType webSocketMsgType, String data) {
|
||||
try {
|
||||
WebSocketUtils.sendMessage(userId, createMsg(webSocketMsgType, data));
|
||||
} catch (Exception e) {
|
||||
|
Reference in New Issue
Block a user