From 001f40204ffd5c17c0ee0967f499ad22858f38e4 Mon Sep 17 00:00:00 2001 From: liu Date: Wed, 20 Dec 2023 13:12:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4websocket=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserController.java | 36 ++++++++++++++++--- .../src/main/resources/application-test.yml | 6 +++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/virtual-patient-web/src/main/java/com/supervision/controller/UserController.java b/virtual-patient-web/src/main/java/com/supervision/controller/UserController.java index 77406317..c469d1e4 100644 --- a/virtual-patient-web/src/main/java/com/supervision/controller/UserController.java +++ b/virtual-patient-web/src/main/java/com/supervision/controller/UserController.java @@ -1,6 +1,7 @@ package com.supervision.controller; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.net.NetUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.supervision.constant.UserTokenConstant; @@ -20,10 +21,12 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.*; import java.time.LocalDateTime; +import java.util.LinkedHashSet; import java.util.Optional; @Api(tags = "用户管理") @@ -38,8 +41,17 @@ public class UserController { 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("登录") @PostMapping("login") @@ -69,7 +81,7 @@ public class UserController { @ApiOperation("查看资源是否有剩余") @GetMapping("resourceIsFree") - public boolean resourceIsFree(){ + public boolean resourceIsFree() { return userResourceCheck.achieveDiagnoseResource(); } @@ -77,16 +89,32 @@ public class UserController { @PutMapping("updateUserInfo") public boolean updateUserInfo(@RequestBody UserInfoReqVo userInfo) { - return userManageService.updateUserInfo(userInfo); + return userManageService.updateUserInfo(userInfo); } @ApiOperation("查看账号信息") @GetMapping("getUserAccountInfo") public UserInfoResVo getUserAccountInfo() { - User user = UserUtil.getUser(); 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地址,请确认配置文件是否配置"); + } + } diff --git a/virtual-patient-web/src/main/resources/application-test.yml b/virtual-patient-web/src/main/resources/application-test.yml index 3f8cc605..c2e5506b 100644 --- a/virtual-patient-web/src/main/resources/application-test.yml +++ b/virtual-patient-web/src/main/resources/application-test.yml @@ -71,4 +71,8 @@ human: base-url: https://digital-human.jd.com room-id: /getRoomId text-driven: /text_driven - talk-status: /talkStatus \ No newline at end of file + talk-status: /talkStatus +ws: + # nginx的wss地址(如果是wss的,那么带不带s都可以访问) + nginx-ip: 192.168.10.138 + nginx-port: 443 \ No newline at end of file