问诊项目搭建1024

master
张海宁 2023-10-30 09:08:38 +08:00
parent 5c4aeb18ed
commit 6916510d71
26 changed files with 841 additions and 4 deletions

View File

@ -0,0 +1,10 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AliAccessStaticViaInstance" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliDeprecation" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ADDITIONAL_TAGS" value="Dis" />
</inspection_tool>
</profile>
</component>

View File

@ -1,4 +1,9 @@
<project version="4">
<component name="EntryPointsManager">
<list size="1">
<item index="0" class="java.lang.String" itemvalue="lombok.Data" />
</list>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
@ -7,6 +12,10 @@
</list>
</option>
</component>
<component name="PWA">
<option name="enabled" value="true" />
<option name="wasEnabledAtLeastOnce" value="true" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17 (2)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>

View File

@ -16,6 +16,12 @@
<groupId>com.health</groupId>
<artifactId>health-common-core</artifactId>
</dependency>
<dependency>
<groupId>com.health</groupId>
<artifactId>health-common-security</artifactId>
<version>3.6.6</version>
</dependency>
</dependencies>
<repositories>
@ -25,6 +31,7 @@
<url>http://10.100.1.7:8081/repository/maven-public/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>dragon-release</id>
@ -33,5 +40,4 @@
</repository>
</distributionManagement>
</project>

View File

@ -0,0 +1,46 @@
package com.health.consultation.common.domain;
import lombok.Data;
/**
*
*
* @author Administrator
*/
@Data
public class Chatrecord {
/**
* ID
*/
private String id;
/**
* ID
*/
private String historyChatRecordId;
/**
*
*/
private String doctorChatTimestamp;
/**
*
*/
private String doctorText;
/**
*
*/
private String patientChatTimestamp;
/**
*
*/
private String patientText;
/**
*
*/
private String status;
}

View File

@ -0,0 +1,56 @@
package com.health.consultation.common.domain;
import lombok.Data;
/**
* @author : [Administrator]
* @version : [v1.0]
* @description : []
* @createTime : [2023/10/26 15:58]
* @updateUser : [Administrator]
* @updateTime : [2023/10/26 15:58]
* @updateRemark : []
*/
@Data
public class Inquiry {
/**
* ID
*/
private String id;
/**
* ID
*/
private String doctorId;
/**
* ID
*/
private String patientId;
/**
*
*/
private String patientAvatar;
/**
*
*/
private String lastConsultationTime;
/**
*
*/
private String lastChatRecord;
/**
* ID
*/
private String historyChatRecordId;
/**
*
*/
private String inquiryStatus;
}

View File

@ -0,0 +1,13 @@
package com.health.consultation.common.domain.req;
import lombok.Data;
@Data
public class ReqDoctorMsg {
private String id;
private String msg;
/**
* id
*/
private String hid;
}

View File

@ -0,0 +1,21 @@
package com.health.consultation.common.domain.req;
import lombok.Data;
/**
* @author Administrator
*/
@Data
public class RequestDoctor {
private String id;
/**
*
*/
private String name;
/**
*
*/
private String JobsId;
}

View File

@ -0,0 +1,17 @@
package com.health.consultation.common.domain.resp;
import lombok.Data;
/**
*
*
* @author Administrator
*/
@Data
public class Consultation {
private String role;
private String text;
private String historyChatRecordId;
}

View File

@ -0,0 +1,20 @@
package com.health.consultation.common.domain.resp;
import lombok.Data;
/**
*
*
* @author Administrator
*/
@Data
public class HistoryDoctor {
private String id;//聊天记录ID唯一标识符
private String sessionId;//聊天会话ID
private String senderId;//发送者ID
private String receiverId;//接收者ID
private String message;//聊天消息内容
private String timestamp;//消息发送时间戳
}

View File

@ -0,0 +1,32 @@
package com.health.consultation.common.utils;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* @author : [Administrator]
* @version : [v1.0]
* @description : []
* @createTime : [2023/10/26 20:37]
* @updateUser : [Administrator]
* @updateTime : [2023/10/26 20:37]
* @updateRemark : []
*/
public class FormatConversionUtils {
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern ("yyyyMMddHHmmss");
public static String formatDateTimeToString (LocalDate datetime) {
return datetime.format (FORMATTER);
}
public static LocalDate timeDateFormatter (String dateString) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern ("yyyyMMddHHmmss");
LocalDate date = LocalDate.parse (dateString, formatter);
return date;
}
}

View File

@ -32,10 +32,83 @@
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.health</groupId>
<artifactId>health-consultation-common</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.20</version>
</dependency>
<dependency>
<groupId>com.health</groupId>
<artifactId>base-system-common</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- RuoYi Common DataSource -->
<dependency>
<groupId>com.health</groupId>
<artifactId>health-common-datasource</artifactId>
</dependency>
<!-- RuoYi Common DataScope -->
<dependency>
<groupId>com.health</groupId>
<artifactId>health-common-datascope</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.taobao.arthas</groupId>
<artifactId>arthas-client</artifactId>
<version>3.6.7</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,29 @@
package com.health.consultation.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @author Administrator
*/
@EnableFeignClients
@SpringBootApplication
public class ConsultationsMain {
public static void main (String[] args) {
SpringApplication.run (ConsultationsMain.class, args);
System.out.println ("模块启动成功" +
"1" +
"2" +
"3" +
"4" +
"5" +
"6" +
"7" +
"8" +
"9" +
"0" +
"-" +
"=");
}
}

View File

@ -0,0 +1,17 @@
package com.health.consultation.server.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
* @author Administrator
*/
@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter () {
return new ServerEndpointExporter ();
}
}

View File

@ -1,24 +1,86 @@
package com.health.consultation.server.controller;
import com.alibaba.fastjson2.JSONObject;
import com.health.common.core.domain.Result;
import com.health.consultation.common.domain.req.ReqDoctorMsg;
import com.health.consultation.common.domain.resp.Consultation;
import com.health.consultation.common.domain.resp.HistoryDoctor;
import com.health.consultation.server.service.InquiryService;
import com.health.consultation.server.service.WebSocketServer;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author Administrator
* @Dis
*/
@RestController
@RequestMapping ("/iQL")
public class InquiryController {
@Autowired
InquiryService inquiryService;
@Autowired
WebSocketServer webSocketServer;
/**
* doctor
*
* @return Consultation
*/
@PostMapping ("/inquiries")
public Result<List<Consultation>> getDoctorInquiries () {
List<Consultation> list = inquiryService.getDoctorInquiries ();
return Result.success (list);
}
@PostMapping ("/get")
public Result GetAListOfHistoricalChats () {
/**
* @param userId
*
* @return com.health.common.core.domain.Result<java.util.List < com.health.consultation.common.domain.resp.HistoryDoctor>>
*
* @author zhn
* @description //患者咨询医生
* @createTime ${Date} ${Time}
**/
@PostMapping ("/setUpConsultation")
public Result<List<HistoryDoctor>> setUpConsultation (String userId) {
return inquiryService.setUpConsultation (userId);
return Result.success ();
}
@PostMapping ("/chat")
public Result setMsgDoctor (@RequestBody ReqDoctorMsg reqDoctorMsg) {
try {
webSocketServer.sendMessage (JSONObject.toJSONString (reqDoctorMsg.getMsg ()), Long.valueOf (reqDoctorMsg.getHid ()));
return inquiryService.setMsgDoctor (reqDoctorMsg);
}
catch (Exception e) {
e.printStackTrace ();
return Result.error ();
}
}
@Data
@Accessors (chain = true)
public static class WebsocketResponse {
private String userId;
private String userName;
private int age;
}
}

View File

@ -0,0 +1,40 @@
package com.health.consultation.server.mapper;
import com.health.consultation.common.domain.Chatrecord;
import com.health.consultation.common.domain.resp.Consultation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author : [Administrator]
* @version : [v1.0]
* @description : []
* @createTime : [2023/10/26 16:26]
* @updateUser : [Administrator]
* @updateTime : [2023/10/26 16:26]
* @updateRemark : []
*/
@Mapper
public interface InquiryMapper {
/**
* @param doctorId
*
* @return java.util.List<com.health.consultation.common.domain.resp.Consultation>
*
* @author zhn
* @description //TODO
* @createTime ${Date} ${Time}
**/
List<Consultation> getDoctorInquiries (@Param ("doctorId") String doctorId);
int setUpConsultation (@Param ("doctorId") String doctorId, @Param ("userId") String userId);
List<Chatrecord> viewTheChatLog (@Param ("userId") String userId);
}

View File

@ -0,0 +1,40 @@
package com.health.consultation.server.service;
import com.health.common.core.domain.Result;
import com.health.consultation.common.domain.req.ReqDoctorMsg;
import com.health.consultation.common.domain.resp.Consultation;
import com.health.consultation.common.domain.resp.HistoryDoctor;
import java.util.List;
/**
* @author Administrator
*/
public interface InquiryService {
/**
*
*
* @return List<Consultation>
*/
List<Consultation> getDoctorInquiries ();
/**
* idlist
*
* @param userId
*
* @return
*/
Result<List<HistoryDoctor>> setUpConsultation (String userId);
/**
*
*
* @param reqDoctorMsg
*
* @return
*/
Result setMsgDoctor (ReqDoctorMsg reqDoctorMsg);
}

View File

@ -0,0 +1,152 @@
package com.health.consultation.server.service;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
/**
* @author Administrator
*/
@Log4j2
@Component
@ServerEndpoint ("/webSocket/1")
public class WebSocketServer {
/**
* 线list
*/
private final static List<Session> SESSIONS = Collections.synchronizedList (new ArrayList<> ());
private static int onlineCount = 0;
private static CopyOnWriteArraySet<WebSocketServer> webSocketSet = new CopyOnWriteArraySet<> ();
/**
* concurrent线setMyWebSocket
*/
private static ConcurrentHashMap<String, WebSocketServer> webSocketMap = new ConcurrentHashMap ();
private Session session;
private String userId;
/**
*
*
* @return
*/
public static synchronized int getOnlineCount () {
return onlineCount;
}
@OnOpen
public void onOpen (Session session, @PathParam ("userId") String userId) {
this.session = session;
this.userId = userId;
SESSIONS.add (session);
if (webSocketMap.containsKey (userId)) {
webSocketMap.remove (userId);
webSocketMap.put (userId, this);
}
else {
webSocketMap.put (userId, this);
addOnlineCount ();
}
// log.info("【websocket消息】有新的连接, 总数:{}", webSocketSet.size());
log.info ("[连接ID:{}] 建立连接, 当前连接数:{}", this.userId, webSocketMap.size ());
}
/**
*
*/
public static synchronized void addOnlineCount () {
WebSocketServer.onlineCount++;
}
/**
*
*/
@OnClose
public void onClose () {
webSocketSet.remove (this);
if (webSocketMap.containsKey (userId)) {
webSocketMap.remove (userId);
subOnlineCount ();
}
// log.info("【websocket消息】连接断开, 总数:{}", webSocketSet.size());
log.info ("[连接ID:{}] 断开连接, 当前连接数:{}", userId, webSocketMap.size ());
}
/**
*
*/
public static synchronized void subOnlineCount () {
WebSocketServer.onlineCount--;
}
/**
*
*
* @param session
* @param error
*/
@OnError
public void onError (Session session, Throwable error) {
log.info ("[连接ID:{}] 错误原因:{}", this.userId, error.getMessage ());
error.printStackTrace ();
}
/**
*
*
* @param message
*/
@OnMessage
public void onMessage (String message) {
// log.info("【websocket消息】收到客户端发来的消息:{}", message);
log.info ("[连接ID:{}] 收到消息:{}", this.userId, message);
}
/**
*
*
* @param message
* @param userId
*/
public void sendMessage (String message, Long userId) {
WebSocketServer webSocketServer = webSocketMap.get (String.valueOf (userId));
if (webSocketServer != null) {
log.info ("【websocket消息】推送消息, message={}", message);
try {
webSocketServer.session.getBasicRemote ().sendText (message);
}
catch (Exception e) {
e.printStackTrace ();
log.error ("[连接ID:{}] 发送消息失败, 消息:{}", this.userId, message, e);
}
}
}
/**
*
*
* @param message
*/
public void sendMassMessage (String message) {
try {
for (Session session : SESSIONS) {
if (session.isOpen ()) {
session.getBasicRemote ().sendText (message);
log.info ("[连接ID:{}] 发送消息:{}", session.getRequestParameterMap ().get ("userId"), message);
}
}
}
catch (Exception e) {
e.printStackTrace ();
}
}
}

View File

@ -0,0 +1,90 @@
package com.health.consultation.server.service.impl;
import com.health.common.core.domain.Result;
import com.health.common.redis.service.RedisService;
import com.health.consultation.common.domain.Chatrecord;
import com.health.consultation.common.domain.req.ReqDoctorMsg;
import com.health.consultation.common.domain.resp.Consultation;
import com.health.consultation.common.domain.resp.HistoryDoctor;
import com.health.consultation.server.mapper.InquiryMapper;
import com.health.consultation.server.service.InquiryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author Administrator
*/
@Service
public class InquiryServiceImpl implements InquiryService {
@Autowired
InquiryMapper inquiryMapper;
@Autowired
RedisService redisService;
/**
*
*
* @return List<Consultation>
*/
@Override
public List<Consultation> getDoctorInquiries () {
//获取请求的医生信息(携带科室+个人信息+权限信息)
List<Consultation> cacheList = redisService.getCacheList ("1chat");
for (Consultation consultation : cacheList) {
}
String doctorId = "";
if (cacheList.isEmpty ()) {
List<Consultation> list = inquiryMapper.getDoctorInquiries (doctorId);
redisService.setCacheList ("1chat", list);
return list;
}
return cacheList;
}
/**
* idlist
*
* @param userId
*
* @return
*/
@Override
public Result<List<HistoryDoctor>> setUpConsultation (String userId) {
//对医生角色权限判断,没权限直接返回提示入驻
String doctorId = "1";
//查看咨询列表是否有这个患者(redis查询)
List<Chatrecord> list = inquiryMapper.viewTheChatLog (userId);
if (list.isEmpty ()) {
//没有就添加到咨询列表(mysql=>redis添加redis的key:医生名+患者id+患者名)
int i = inquiryMapper.setUpConsultation (doctorId, userId);
}
//有就返回最后聊天的记录+结束时间(redis取值)
// Todo 扣除患者h币+
return null;
}
/**
*
*
* @param reqDoctorMsg
*
* @return
*/
@Override
public Result setMsgDoctor (ReqDoctorMsg reqDoctorMsg) {
// TODO 聊天记录存到mysql=>到redis
return Result.success ();
}
}

View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,5 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
</profile>
</component>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="FormatOnSaveOptions">
<option name="myRunOnSave" value="true" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="OptimizeOnSaveOptions">
<option name="myRunOnSave" value="true" />
</component>
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/resources.iml" filepath="$PROJECT_DIR$/.idea/resources.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../../.." vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,29 @@
# Tomcat
server:
port: 8083
# Spring
spring:
application:
# 应用名称
name: health-consultation-server
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 10.100.1.5:8848
config:
# 配置中心地址
server-addr: 10.100.1.5:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.health.consultation.server.mapper.InquiryMapper">
<sql id="doctor">
select *
from inquiry
</sql>
<update id="setUpConsultation">
INSERT INTO `health-consultation`.`inquiry` (`doctor_id`, `patient_id`)
VALUES (#{doctorId}, #{userId});
</update>
<update id="viewTheChatLog">
</update>
<select id="getDoctorInquiries" resultType="com.health.consultation.common.domain.resp.Consultation">
SELECT c.role,
c.text,
c.history_chat_record_id
FROM inquiry i
LEFT JOIN ChatRecord c ON i.history_chat_record_id = c.history_chat_record_id
WHERE c.role IS NOT NULL
AND c.role &lt;&gt; ''
AND i.doctor_id = '1'
</select>
</mapper>

View File

@ -17,11 +17,13 @@
<artifactId>health-modules</artifactId>
<version>3.6.3</version>
</parent>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>dragon-public</id>
@ -29,6 +31,7 @@
<url>http://10.100.1.7:8081/repository/maven-public/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>dragon-release</id>
@ -36,4 +39,5 @@
<url>http://10.100.1.7:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>
</project>