dev_v1.0.1
liu
parent acf463cd48
commit c8794b60d1

@ -46,7 +46,7 @@ public class ResponseConfig implements ResponseBodyAdvice<Object> {
if (Objects.isNull(o)) { if (Objects.isNull(o)) {
return GlobalResult.ok(null, "success"); return JSONUtil.toJsonStr(GlobalResult.ok(null, "success"));
} }
if (o instanceof GlobalResult) { if (o instanceof GlobalResult) {
return o; return o;

@ -17,6 +17,11 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>com.supervision</groupId>
<artifactId>virtual-patient-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -10,4 +10,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/ */
public interface PatientService extends IService<Patient> { public interface PatientService extends IService<Patient> {
Patient queryPatientById(String id);
} }

@ -1,11 +1,14 @@
package com.supervision.service.impl; package com.supervision.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.supervision.exception.BusinessException;
import com.supervision.model.Patient; import com.supervision.model.Patient;
import com.supervision.service.PatientService; import com.supervision.service.PatientService;
import com.supervision.mapper.PatientMapper; import com.supervision.mapper.PatientMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Optional;
/** /**
* @author flevance * @author flevance
* @description vp_patient()Service * @description vp_patient()Service
@ -15,6 +18,10 @@ import org.springframework.stereotype.Service;
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient>
implements PatientService{ implements PatientService{
@Override
public Patient queryPatientById(String id) {
return this.lambdaQuery().eq(Patient::getId, id).oneOpt().orElseThrow(() -> new BusinessException("未找到用户"));
}
} }

@ -8,7 +8,7 @@ import org.springframework.web.socket.config.annotation.EnableWebSocket;
@EnableWebSocket @EnableWebSocket
@SpringBootApplication @SpringBootApplication
@MapperScan(basePackages = {"com.supervision.**"}) @MapperScan(basePackages = {"com.supervision.**.mapper"})
public class VirtualPatientApplication { public class VirtualPatientApplication {
public static void main(String[] args) { public static void main(String[] args) {

@ -1,11 +1,12 @@
package com.supervision.controller; package com.supervision.controller;
import com.supervision.service.AskService;
import com.supervision.websocket.cache.WebSocketUserCache; import com.supervision.websocket.cache.WebSocketUserCache;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.WebSocketSession;
@ -17,18 +18,30 @@ import java.io.IOException;
@RequestMapping("/ask/") @RequestMapping("/ask/")
public class AskController { public class AskController {
@Autowired
private AskService askService;
@ApiOperation("发送消息到页面")
@GetMapping("/sendMessage") @GetMapping("/sendMessage")
public void sendMessage(String message, String sessionId) throws IOException { public void sendMessage(String message, String sessionId) throws IOException {
WebSocketSession session = WebSocketUserCache.getSession(sessionId); WebSocketSession session = WebSocketUserCache.getSession(sessionId);
session.sendMessage(new TextMessage(message)); session.sendMessage(new TextMessage(message));
} }
@ApiOperation("接收页面的语音消息")
@PostMapping("/receiveVoiceFile") @PostMapping("/receiveVoiceFile")
public void receiveVoiceFile(MultipartFile file){ public String receiveVoiceFile(@RequestParam("file") MultipartFile file) throws IOException {
long size = file.getSize(); return askService.receiveVoiceFile(file);
System.out.println(size); }
@ApiOperation("查询对话历史")
public void queryAskHistory(String processId){
} }
} }

@ -0,0 +1,25 @@
package com.supervision.controller;
import com.supervision.model.Patient;
import com.supervision.service.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "病人")
@RestController
@RequestMapping("/patient")
@RequiredArgsConstructor
public class PatientController {
private final PatientService patientService;
@ApiOperation("根据病人ID获取病人")
@GetMapping("queryPatientInfo")
public Patient queryPatientInfo(String id) {
return patientService.queryPatientById(id);
}
}

@ -0,0 +1,11 @@
package com.supervision.service;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
public interface AskService {
String receiveVoiceFile(MultipartFile file) throws IOException;
}

@ -0,0 +1,22 @@
package com.supervision.service.impl;
import cn.hutool.core.codec.Base64;
import com.supervision.service.AskService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@Service
public class AskServiceImpl implements AskService {
@Override
public String receiveVoiceFile(MultipartFile file) throws IOException {
// 首先编码为base64编码
String encode = Base64.encode(file.getBytes());
// TODO 这里调用Python的接口,将文字转换为语音
return encode;
}
}

@ -20,6 +20,7 @@ public class WebSocketUserCache {
public static void login(String id, WebSocketSession socketSession) { public static void login(String id, WebSocketSession socketSession) {
map.put(id, socketSession); map.put(id, socketSession);
log.info("sessionId:{}注册成功", id); log.info("sessionId:{}注册成功", id);
} }
public static void logout(String id) { public static void logout(String id) {

@ -0,0 +1,13 @@
package com.supervision.websocket.dto;
import lombok.Data;
@Data
public class SocketMessageDTO {
private String socketId;
private String userId;
private String data;
}

@ -1,6 +1,8 @@
package com.supervision.websocket.handler; package com.supervision.websocket.handler;
import cn.hutool.json.JSONUtil;
import com.supervision.websocket.cache.WebSocketUserCache; import com.supervision.websocket.cache.WebSocketUserCache;
import com.supervision.websocket.dto.SocketMessageDTO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.TextMessage;
@ -14,18 +16,23 @@ public class AskWebSocketHandler extends TextWebSocketHandler {
public void afterConnectionEstablished(WebSocketSession session) throws Exception { public void afterConnectionEstablished(WebSocketSession session) throws Exception {
// 获取本次 // 获取本次
String id = session.getId(); String id = session.getId();
// 缓存sessionId
WebSocketUserCache.login(id, session); WebSocketUserCache.login(id, session);
// 连接建立时的处理逻辑 // 返回sessionId到前端
SocketMessageDTO socketMessageDTO = new SocketMessageDTO();
socketMessageDTO.setSocketId(id);
socketMessageDTO.setData("链接成功");
session.sendMessage(new TextMessage(JSONUtil.toJsonStr(socketMessageDTO)));
} }
@Override @Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { protected void handleTextMessage(WebSocketSession session, TextMessage message) {
// 处理接收到的文本消息 // 处理接收到的文本消息
log.info("收到消息:{}", message.toString()); log.info("收到消息:{}", message.toString());
} }
@Override @Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { public void afterConnectionClosed(WebSocketSession session, CloseStatus status) {
// 连接关闭时的处理逻辑 // 连接关闭时的处理逻辑
String id = session.getId(); String id = session.getId();
WebSocketUserCache.logout(id); WebSocketUserCache.logout(id);

@ -3,13 +3,26 @@ server:
port: 8899 port: 8899
servlet: servlet:
context-path: / context-path: /
undertow:
# HTTP post内容的最大大小。当值为-1时默认值为大小是无限的
max-http-post-size: -1
# 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理
# 每块buffer的空间大小,越小的空间被利用越充分
buffer-size: 512
# 是否分配的直接内存
direct-buffers: true
spring: spring:
profiles: profiles:
active: dev active: dev
application: application:
name: virtual-patient name: virtual-patient
##数据源配置 servlet:
multipart:
max-file-size: 100MB
max-request-size: 100MB
##数据源配置
datasource: datasource:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
druid: druid:

Loading…
Cancel
Save