提交websocket相关代码

dev_2.0.0
liu 2 years ago
parent 60b1b6e46d
commit 001f40204f

@ -1,6 +1,7 @@
package com.supervision.controller; package com.supervision.controller;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.net.NetUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.supervision.constant.UserTokenConstant; import com.supervision.constant.UserTokenConstant;
@ -20,10 +21,12 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.LinkedHashSet;
import java.util.Optional; import java.util.Optional;
@Api(tags = "用户管理") @Api(tags = "用户管理")
@ -38,8 +41,17 @@ public class UserController {
private final UserManageService userManageService; private final UserManageService userManageService;
private final UserResourceCheck userResourceCheck; private final UserResourceCheck userResourceCheck;
@Value("${ws.nginx-ip:}")
private String wsIp;
@Value("${ws.nginx-port:}")
private String wsPort;
@Value("${spring.profiles.active}")
private String active;
@Value("${server.port}")
private String port;
@ApiOperation("登录") @ApiOperation("登录")
@PostMapping("login") @PostMapping("login")
@ -69,7 +81,7 @@ public class UserController {
@ApiOperation("查看资源是否有剩余") @ApiOperation("查看资源是否有剩余")
@GetMapping("resourceIsFree") @GetMapping("resourceIsFree")
public boolean resourceIsFree(){ public boolean resourceIsFree() {
return userResourceCheck.achieveDiagnoseResource(); return userResourceCheck.achieveDiagnoseResource();
} }
@ -77,16 +89,32 @@ public class UserController {
@PutMapping("updateUserInfo") @PutMapping("updateUserInfo")
public boolean updateUserInfo(@RequestBody UserInfoReqVo userInfo) { public boolean updateUserInfo(@RequestBody UserInfoReqVo userInfo) {
return userManageService.updateUserInfo(userInfo); return userManageService.updateUserInfo(userInfo);
} }
@ApiOperation("查看账号信息") @ApiOperation("查看账号信息")
@GetMapping("getUserAccountInfo") @GetMapping("getUserAccountInfo")
public UserInfoResVo getUserAccountInfo() { public UserInfoResVo getUserAccountInfo() {
User user = UserUtil.getUser(); User user = UserUtil.getUser();
return userManageService.getUserAccountInfo(user.getId()); return userManageService.getUserAccountInfo(user.getId());
} }
@ApiOperation("获取本机IP地址,用来给websocket使用")
@GetMapping("queryWebSocketUrl")
public String queryWebSocketUrl() {
String template = "wss://{}:{}/virtual-patient-websocket/";
// 如果是本地开发环境,则获取本机IP地址
if ("dev".equals(active)) {
String localhostStr = NetUtil.getLocalhostStr();
return StrUtil.format(template, localhostStr, port);
} else {
if (StrUtil.isNotBlank(wsIp) && StrUtil.isNotBlank(wsPort)) {
return StrUtil.format(template, wsIp, wsPort);
}
}
throw new BusinessException("未获取到ws的nginx地址,请确认配置文件是否配置");
}
} }

@ -71,4 +71,8 @@ human:
base-url: https://digital-human.jd.com base-url: https://digital-human.jd.com
room-id: /getRoomId room-id: /getRoomId
text-driven: /text_driven text-driven: /text_driven
talk-status: /talkStatus talk-status: /talkStatus
ws:
# nginx的wss地址(如果是wss的,那么带不带s都可以访问)
nginx-ip: 192.168.10.138
nginx-port: 443
Loading…
Cancel
Save