update===>:修改生成房间号方法及推送房间号。

This commit is contained in:
haown 2023-11-02 09:35:47 +08:00
parent 2ebe1e1ece
commit 4e0844558d

View File

@ -1,6 +1,7 @@
package com.xinelu.applet.controller.videoconsultation; package com.xinelu.applet.controller.videoconsultation;
import cn.hutool.core.util.RandomUtil; import com.xinelu.applet.dto.consultationInfo.ConsultationInfoDTO;
import com.xinelu.applet.service.consultationInfo.IConsultationInfoService;
import com.xinelu.common.core.domain.R; import com.xinelu.common.core.domain.R;
import com.xinelu.common.core.dto.MessageTemplate; import com.xinelu.common.core.dto.MessageTemplate;
import com.xinelu.common.enums.MessageContentType; import com.xinelu.common.enums.MessageContentType;
@ -16,6 +17,8 @@ import com.xinelu.common.utils.tencentcloudapi.trtc.v20190722.models.DissolveRoo
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import java.util.Date; import java.util.Date;
import java.util.Random;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -41,6 +44,10 @@ public class VideoConsultationController {
private final static String ENDPOINT = "trtc.tencentcloudapi.com"; private final static String ENDPOINT = "trtc.tencentcloudapi.com";
private final static String REGION = "ap-beijing"; private final static String REGION = "ap-beijing";
@Resource
private IConsultationInfoService consultationInfoService;
@ApiOperation("获取userSig") @ApiOperation("获取userSig")
@GetMapping("getUserSig/{userId}") @GetMapping("getUserSig/{userId}")
public R<String> getUserSig(@PathVariable String userId) { public R<String> getUserSig(@PathVariable String userId) {
@ -49,19 +56,31 @@ public class VideoConsultationController {
return R.ok(userSig); return R.ok(userSig);
} }
@ApiOperation("开始会诊") @ApiOperation("开始视频")
@GetMapping("start/{applyId}") @GetMapping("start/{consultationInfoId}")
public R<String> start(@PathVariable String applyId) { public R<String> start(@PathVariable Long consultationInfoId) {
int roomId = RandomUtil.randomInt(1, 1000); // 房间号
Random random = new Random();
int randomNumber = random.nextInt(900000) + 100000; // 限制范围为 100000-999999
String roomId = String.valueOf(randomNumber);
if (roomId.length() < 6) {
roomId = "0" + roomId; // 补零
}
MessageTemplate msg = new MessageTemplate(); MessageTemplate msg = new MessageTemplate();
msg.setMessage(String.valueOf(roomId)); // 根据图文咨询申请主键查询居民主键
msg.setToKey(applyId); ConsultationInfoDTO consultationInfoDTO = consultationInfoService.selectConsultationInfoById(consultationInfoId);
if (consultationInfoDTO == null) {
return R.fail("生成房间号失败");
}
msg.setMessage(roomId);
msg.setToKey(String.valueOf(consultationInfoDTO.getPatientId()));
msg.setMsgType(MessageContentType.CONSULTATION.name()); msg.setMsgType(MessageContentType.CONSULTATION.name());
msg.setSendTime(new Date()); msg.setSendTime(new Date());
WebSocketUtils.sendMessage(applyId, msg); WebSocketUtils.sendMessage(String.valueOf(consultationInfoDTO.getPatientId()), msg);
return R.ok(String.valueOf(roomId)); return R.ok(roomId);
} }
@ApiOperation("解散房间") @ApiOperation("解散房间")
@GetMapping("dissolveRoom/{roomId}") @GetMapping("dissolveRoom/{roomId}")
public R<?> dissolveRoom(@PathVariable String roomId) throws TencentCloudSDKException { public R<?> dissolveRoom(@PathVariable String roomId) throws TencentCloudSDKException {