修改websocket配置
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user