浏览代码

fix 用户多租户问题
add websocket连接
add 网络泵字段
add 医院信息缓存

18339543638 3 年之前
父节点
当前提交
3d9de3dea9
共有 20 个文件被更改,包括 300 次插入15 次删除
  1. 2 0
      coffee-admin/src/main/java/com/coffee/admin/AdminApplication.java
  2. 1 1
      coffee-admin/src/main/resources/application-dev.yml
  3. 9 1
      coffee-admin/src/main/resources/application.yml
  4. 20 0
      coffee-common/pom.xml
  5. 2 0
      coffee-common/src/main/java/com/coffee/common/bo/SysUserBO.java
  6. 34 0
      coffee-common/src/main/java/com/coffee/common/config/CorsConfig.java
  7. 48 0
      coffee-common/src/main/java/com/coffee/common/config/mybatis/WebConfig.java
  8. 90 0
      coffee-common/src/main/java/com/coffee/common/config/websocket/DefaultWebSocketMsgHandler.java
  9. 26 0
      coffee-common/src/main/java/com/coffee/common/config/websocket/MessagingRequest.java
  10. 22 0
      coffee-common/src/main/java/com/coffee/common/config/websocket/handler/WsHandler.java
  11. 1 1
      coffee-common/src/main/java/com/coffee/common/crud/controller/BaseSaveController.java
  12. 7 0
      coffee-common/src/main/java/com/coffee/common/entity/TenantGenericEntity.java
  13. 3 3
      coffee-system/src/main/java/com/coffee/bus/controller/BusEvaluationTmpController.java
  14. 12 1
      coffee-system/src/main/java/com/coffee/bus/entity/BusNetPumpEntity.java
  15. 2 2
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusHospitalService.java
  16. 4 0
      coffee-system/src/main/java/com/coffee/system/common/dto/SysUserAddDTO.java
  17. 4 2
      coffee-system/src/main/java/com/coffee/system/common/dto/SysUserEditDTO.java
  18. 2 0
      coffee-system/src/main/java/com/coffee/system/common/vo/UserInfoVO.java
  19. 5 4
      coffee-system/src/main/java/com/coffee/system/entity/SysUser.java
  20. 6 0
      pom.xml

+ 2 - 0
coffee-admin/src/main/java/com/coffee/admin/AdminApplication.java

@@ -5,6 +5,7 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.context.annotation.Import;
+import org.tio.websocket.starter.EnableTioWebSocketServer;
 import springfox.documentation.swagger2.annotations.EnableSwagger2;
 
 /**
@@ -15,6 +16,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
 @SpringBootApplication(scanBasePackages ={"com.coffee"}, exclude = {DataSourceAutoConfiguration.class})
 @Import(cn.hutool.extra.spring.SpringUtil.class)
 @EnableSwagger2
+@EnableTioWebSocketServer
 public class AdminApplication {
 
     public static void main(String[] args) {

+ 1 - 1
coffee-admin/src/main/resources/application-dev.yml

@@ -98,4 +98,4 @@ spring:
         # 连接池的最大数据库连接数
         max-active: 8
         # #连接池最大阻塞等待时间(使用负值表示没有限制)
-        max-wait: -1ms
+        max-wait: -1ms

+ 9 - 1
coffee-admin/src/main/resources/application.yml

@@ -17,7 +17,15 @@ server:
     threads:
       io: 16
       worker: 256
-
+tio:
+  websocket:
+    server:
+      port: 9000
+      #心跳检测在业务层面自定义进行
+      heartbeat-timeout: -1
+      #是否支持集群,集群开启需要redis
+    cluster:
+      enabled: false
 # Sa-Token配置
 sa-token:
   # token名称 (同时也是cookie名称)

+ 20 - 0
coffee-common/pom.xml

@@ -12,6 +12,22 @@
     <artifactId>coffee-common</artifactId>
 
     <dependencies>
+        <dependency>
+            <groupId>org.t-io</groupId>
+            <artifactId>tio-websocket-spring-boot-starter</artifactId>
+        </dependency>
+         <!--websocket 模块-->
+        <!--<dependency>-->
+            <!--<groupId>org.springframework.boot</groupId>-->
+            <!--<artifactId>spring-boot-starter-websocket</artifactId>-->
+            <!--<exclusions>-->
+                <!--<exclusion>-->
+                    <!--<groupId>org.springframework.boot</groupId>-->
+                    <!--<artifactId>spring-boot-starter-tomcat</artifactId>-->
+                <!--</exclusion>-->
+            <!--</exclusions>-->
+        <!--</dependency>-->
+         <!--websocket 模块-->
         <!-- web 模块 -->
         <dependency>
             <groupId>org.springframework.boot</groupId>
@@ -92,5 +108,9 @@
             <groupId>io.minio</groupId>
             <artifactId>minio</artifactId>
         </dependency>
+        <dependency>
+            <groupId>jakarta.websocket</groupId>
+            <artifactId>jakarta.websocket-api</artifactId>
+        </dependency>
     </dependencies>
 </project>

+ 2 - 0
coffee-common/src/main/java/com/coffee/common/bo/SysUserBO.java

@@ -107,4 +107,6 @@ public class SysUserBO implements Serializable {
      * (医院)租户id
      **/
     private String tenantId;
+
+    private String tenantName;
 }

+ 34 - 0
coffee-common/src/main/java/com/coffee/common/config/CorsConfig.java

@@ -0,0 +1,34 @@
+package com.coffee.common.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName CorFilter.java
+ * @Description TODO
+ * @createTime 2022年03月23日 14:49:00
+ */
+//@Configuration
+public class CorsConfig implements WebMvcConfigurer {
+    @Override
+    public void addCorsMappings(CorsRegistry registry) {
+        //添加映射路径
+        registry.addMapping("/**")
+                //是否发送Cookie
+                .allowCredentials(false)
+                //设置放行哪些原始域   SpringBoot2.4.4下低版本使用.allowedOrigins("*")
+                .allowedOriginPatterns("*")
+                .allowedOrigins("*")
+                //放行哪些请求方式
+//                .allowedMethods(new String[]{"GET", "POST", "PUT", "DELETE"})
+                .allowedMethods("*") //或者放行全部
+                //放行哪些原始请求头部信息
+                .allowedHeaders("*")
+                //暴露哪些原始请求头部信息
+                .exposedHeaders("*");
+    }
+}

+ 48 - 0
coffee-common/src/main/java/com/coffee/common/config/mybatis/WebConfig.java

@@ -0,0 +1,48 @@
+package com.coffee.common.config.mybatis;
+
+import java.math.BigInteger;
+import java.nio.charset.Charset;
+import java.util.List;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.StringHttpMessageConverter;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+@Configuration
+@EnableWebMvc
+public class WebConfig implements WebMvcConfigurer {
+
+    @Override
+    public void addResourceHandlers(ResourceHandlerRegistry registry) {
+        registry.addResourceHandler("/statics/**").addResourceLocations("classpath:/statics/");
+    }
+    
+    /**
+     * * 针对Long丢失经度问题;发现后台返回前台的数据不会出现问题。前台请求的数据也是正常的
+     * * 只不过前台js获取到页面上会出现问题,针对以上情况,在前台js中,修改id的name值为id_
+     */
+    @Override
+    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
+        MappingJackson2HttpMessageConverter jackson2HttpMessageConverter =
+                new MappingJackson2HttpMessageConverter();
+        
+        ObjectMapper objectMapper = new ObjectMapper();
+        SimpleModule simpleModule = new SimpleModule();
+        simpleModule.addSerializer(BigInteger.class, ToStringSerializer.instance);
+        simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
+        simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
+        objectMapper.registerModule(simpleModule);
+        jackson2HttpMessageConverter.setObjectMapper(objectMapper);
+        converters.add(jackson2HttpMessageConverter);
+        converters.add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
+    }
+    
+
+}

+ 90 - 0
coffee-common/src/main/java/com/coffee/common/config/websocket/DefaultWebSocketMsgHandler.java

@@ -0,0 +1,90 @@
+package com.coffee.common.config.websocket;
+
+import cn.dev33.satoken.session.SaSession;
+import cn.dev33.satoken.stp.StpUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.cron.Scheduler;
+import cn.hutool.json.JSONUtil;
+import com.coffee.common.redis.RedisUtils;
+import com.coffee.common.result.R;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+import org.tio.core.ChannelContext;
+import org.tio.core.Tio;
+import org.tio.http.common.HttpRequest;
+import org.tio.http.common.HttpResponse;
+import org.tio.websocket.common.WsRequest;
+import org.tio.websocket.common.WsResponse;
+import org.tio.websocket.server.handler.IWsMsgHandler;
+import reactor.core.scheduler.Schedulers;
+
+@Component
+@Slf4j
+public class DefaultWebSocketMsgHandler implements IWsMsgHandler {
+    RedisUtils redisUtils;
+    RedisTemplate redisTemplate;
+    @Override
+    public HttpResponse handshake(HttpRequest httpRequest, HttpResponse httpResponse, ChannelContext channelContext) throws Exception {
+
+//        if(StrUtil.isEmpty(authorization)){
+//            return httpResponse.setBody(R.fail());
+//        }
+//        httpResponse.setBody("123".getBytes());
+//        throw new CustomException("授权失败");
+//        Tio.send(channelContext,WsResponse.fromText("授权失败","utf-8"));
+
+
+        return httpResponse;
+    }
+
+    @Override
+    public void onAfterHandshaked(HttpRequest httpRequest, HttpResponse httpResponse, ChannelContext channelContext) throws Exception {
+        String authorization = httpRequest.getParam("Authorization");
+        if(log.isDebugEnabled()){
+            log.debug("websocket 握手成功,开始进行权限校验,Authorization:{}",authorization);
+        }
+        if(StrUtil.isNullOrUndefined(authorization)){
+            Tio.send(channelContext,WsResponse.fromText(JSONUtil.toJsonStr(R.fail("授权失败")),"utf-8"));
+            //给返回信息一些时间 todo
+            Thread.sleep(50);
+            channelContext.setClosed(true);
+            return;
+        }
+        SaSession tokenSessionByToken = StpUtil.getTokenSessionByToken(authorization);
+        if(null==tokenSessionByToken){
+            Tio.send(channelContext,WsResponse.fromText(JSONUtil.toJsonStr(R.fail("授权失败")),"utf-8"));
+            if(log.isDebugEnabled()){
+                log.debug("Authorization:{},鉴权失败",authorization);
+            }
+            Tio.unbindToken(channelContext);
+            Thread.sleep(50);
+            channelContext.setClosed(true);
+            return;
+        }
+        Tio.bindToken(channelContext, JSONUtil.toJsonStr(tokenSessionByToken));
+        Tio.send(channelContext,WsResponse.fromText(JSONUtil.toJsonStr(R.success("连接成功")),"utf-8"));
+
+    }
+
+    @Override
+    public Object onBytes(WsRequest wsRequest, byte[] bytes, ChannelContext channelContext) throws Exception {
+        return null;
+    }
+
+    @Override
+    public Object onClose(WsRequest wsRequest, byte[] bytes, ChannelContext channelContext) throws Exception {
+        return null;
+    }
+
+    @Override
+    public Object onText(WsRequest wsRequest, String message, ChannelContext channelContext) throws Exception {
+        System.out.println("接收到文本消息:"+message);
+        if (StrUtil.isEmpty(message)) {
+            Tio.unbindBsId(channelContext);
+            channelContext.setClosed(true);
+            return null;
+        }
+        return null;
+    }
+}

+ 26 - 0
coffee-common/src/main/java/com/coffee/common/config/websocket/MessagingRequest.java

@@ -0,0 +1,26 @@
+package com.coffee.common.config.websocket;
+
+import java.util.Map;
+import java.util.*;
+public class MessagingRequest {
+
+    /**
+     * 心跳、设备或报警信息,例如ping、device,alarm,patient
+     */
+    private String id;
+
+    /**
+     * 订阅/取消订阅
+     */
+    private Type type;
+
+    /**
+     * 订阅id,如设备id、病人id
+     */
+    private List<String> params;
+
+
+    public enum Type{
+        sub,unsub
+    }
+}

+ 22 - 0
coffee-common/src/main/java/com/coffee/common/config/websocket/handler/WsHandler.java

@@ -0,0 +1,22 @@
+package com.coffee.common.config.websocket.handler;
+
+import org.tio.core.ChannelContext;
+import org.tio.websocket.common.WsRequest;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName WsHandler.java
+ * @Description TODO
+ * @createTime 2022年03月25日 10:27:00
+ */
+public interface WsHandler {
+    String getId();
+
+
+    void subscribe();
+
+    void onBytes(WsRequest wsRequest, byte[] bytes, ChannelContext channelContext);
+
+    void onText(WsRequest wsRequest, String message, ChannelContext channelContext);
+}

+ 1 - 1
coffee-common/src/main/java/com/coffee/common/crud/controller/BaseSaveController.java

@@ -42,7 +42,7 @@ public interface BaseSaveController<E,K extends Serializable> extends
     }
 
 
-    @PostMapping("/refresh")
+    @PostMapping("/edit")
     @Operation(summary = "根据ID修改数据")
     default R update(@RequestBody E payload) {
         editAuth();

+ 7 - 0
coffee-common/src/main/java/com/coffee/common/entity/TenantGenericEntity.java

@@ -1,8 +1,12 @@
 package com.coffee.common.entity;
 
+import com.alibaba.fastjson.annotation.JSONField;
 import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.coffee.common.config.mybatis.TenantNameHandler;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import lombok.Getter;
 
 /**
@@ -18,6 +22,9 @@ public abstract class TenantGenericEntity<PK,TN> extends GenericEntity<PK> {
 
     @Getter
     @TableField("tenant_id")
+//    @JsonFormat
+//    @JSONField(serializeUsing = ToStringSerializer.class)
+//    @JsonSerialize(using = ToStringSerializer.class,contentAs=String.class)
     private TN tenantId;
 
     @Getter

+ 3 - 3
coffee-system/src/main/java/com/coffee/bus/controller/BusEvaluationTmpController.java

@@ -19,8 +19,8 @@ import org.springframework.web.bind.annotation.RestController;
  */
 @RestController
 @AllArgsConstructor
-@RequestMapping("/eval/tmp")
-@Api(tags = "评价模板管理",description = "统一权限前缀(eval:tmp),eval:tmp:add")
+@RequestMapping("/eval/temp")
+@Api(tags = "评价模板管理",description = "统一权限前缀(eval:temp),eval:temp:add")
 public class BusEvaluationTmpController extends BaseCrudController<BusEvaluationTmpEntity, String> {
     private final LocalBusEvaluationTmpService evalTmpService;
 
@@ -31,7 +31,7 @@ public class BusEvaluationTmpController extends BaseCrudController<BusEvaluation
      */
     @Override
     public String getPermissionPrefix() {
-        return "eval:tmp";
+        return "eval:temp";
     }
 
     @Override

+ 12 - 1
coffee-system/src/main/java/com/coffee/bus/entity/BusNetPumpEntity.java

@@ -36,13 +36,24 @@ public class BusNetPumpEntity extends TenantGenericEntity<String,String> {
     @ApiModelProperty(value = "网络泵id")
     private String deviceId;
 
-
     @ApiModelProperty(value = "病号")
     private String patientCode;
 
     @ApiModelProperty(value = "病人名称")
     private String patientName;
 
+    @ApiModelProperty(value = "病人性别")
+    private Integer patientSex;
+
+    @ApiModelProperty(value = "科室")
+    private String dept;
+
+    @ApiModelProperty(value = "病区")
+    private String ward;
+
+    @ApiModelProperty(value = "床号")
+    private String bedNo;
+
     @ApiModelProperty(value = "别名")
     private String alias;
 

+ 2 - 2
coffee-system/src/main/java/com/coffee/bus/service/LocalBusHospitalService.java

@@ -55,7 +55,7 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
     }
 
     @Override
-    public void run(String... args) throws Exception {
+    public void run(String... args) {
         List<BusHospitalEntity> hospitalList = this.list();
         if(CollectionUtil.isNotEmpty(hospitalList)){
             Map<String, List<BusHospitalEntity>> collect = hospitalList.stream().collect(Collectors.groupingBy(BusHospitalEntity::getId));
@@ -66,7 +66,7 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
 
     @Override
     public String getName(String id) {
-        if(StrUtil.isEmpty(id)){
+        if(StrUtil.isAllBlank(id)){
             return "";
         }
         return hospitalMap.get(id);

+ 4 - 0
coffee-system/src/main/java/com/coffee/system/common/dto/SysUserAddDTO.java

@@ -137,4 +137,8 @@ public class SysUserAddDTO implements Serializable {
      */
     private List<Long> roleIds;
 
+    @NotNull(message = "用户标识不能为空")
+    private Integer isSys;
+
+    private Long tenantId;
 }

+ 4 - 2
coffee-system/src/main/java/com/coffee/system/common/dto/SysUserEditDTO.java

@@ -123,8 +123,8 @@ public class SysUserEditDTO implements Serializable {
     /**
      * 状态 0否;1是
      */
-    @NotBlank(message = "是否为系统级别用户")
-    private Boolean isSys;
+    @NotNull(message = "是否为系统级别用户")
+    private Integer isSys;
 
     /**
      * 岗位组
@@ -135,4 +135,6 @@ public class SysUserEditDTO implements Serializable {
      * 角色组
      */
     private List<Long> roleIds;
+
+    private Long tenantId;
 }

+ 2 - 0
coffee-system/src/main/java/com/coffee/system/common/vo/UserInfoVO.java

@@ -27,6 +27,8 @@ public class UserInfoVO implements Serializable {
 
     private String tenantId;
 
+    private String tenantName;
+
     private List<RoleInfoVO> roles;
 
     private Integer isSys;

+ 5 - 4
coffee-system/src/main/java/com/coffee/system/entity/SysUser.java

@@ -40,12 +40,12 @@ import java.util.List;
 @ContentFontStyle(fontHeightInPoints = 10)
 @ExcelIgnoreUnannotated
 @TableName("sys_user")
-public class SysUser  {
+public class SysUser extends TenantGenericEntity<Long,Long> {
 
     private static final long serialVersionUID = 1L;
-
-    @TableId
-    private Long id;
+//
+//    @TableId
+//    private Long id;
     /**
      * 账号
      */
@@ -207,5 +207,6 @@ public class SysUser  {
      * 是否为系统级别用户
      *  0、否  1、是
      **/
+    @TableField()
     private Integer isSys;
 }

+ 6 - 0
pom.xml

@@ -34,6 +34,7 @@
         <log4j2.version>2.17.1</log4j2.version>
         <satoken.version>1.29.0</satoken.version>
         <springfox.version>3.0.0</springfox.version>
+        <tio.version>3.6.0.v20200315-RELEASE</tio.version>
     </properties>
 
     <modules>
@@ -70,6 +71,11 @@
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
+            <dependency>
+                <groupId>org.t-io</groupId>
+                <artifactId>tio-websocket-spring-boot-starter</artifactId>
+                <version>${tio.version}</version>
+            </dependency>
             <!--swagger模块 -->
             <dependency>
                 <groupId>io.springfox</groupId>