Ver código fonte

加入医院的信息

gaodm 4 anos atrás
pai
commit
18bab17e5c

+ 22 - 0
doc/001.00000000初始化脚本/cdss_init.sql

@@ -204,6 +204,28 @@ CREATE TABLE `sys_user_role` (
 -- ----------------------------
 INSERT INTO `sys_user_role` VALUES ('1', 'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '1', '-1', '');
 
+-- ----------------------------
+-- Table structure for sys_user_hospital
+-- ----------------------------
+DROP TABLE IF EXISTS `sys_user_hospital`;
+CREATE TABLE `sys_user_hospital` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
+  `is_deleted` char(1) NOT NULL DEFAULT 'N' COMMENT '是否删除,N:未删除,Y:删除',
+  `gmt_create` datetime NOT NULL DEFAULT '1970-01-01 12:00:00' COMMENT '记录创建时间',
+  `gmt_modified` datetime NOT NULL DEFAULT '1970-01-01 12:00:00' COMMENT '记录修改时间,如果时间是1970年则表示纪录未修改',
+  `creator` varchar(20) NOT NULL DEFAULT '0' COMMENT '创建人,0表示无创建人值',
+  `modifier` varchar(20) NOT NULL DEFAULT '0' COMMENT '修改人,如果为0则表示纪录未修改',
+  `user_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '用户主键',
+  `hospital_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '医院ID',
+  `remark` varchar(255) DEFAULT NULL COMMENT '备注',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='用户-机构表映射表';
+
+-- ----------------------------
+-- Records of sys_user_hospital
+-- ----------------------------
+INSERT INTO `sys_user_hospital` VALUES ('1', 'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '1', '1', null);
+
 DROP TABLE IF EXISTS `kl_version_detail`;
 CREATE TABLE `kl_version_detail` (
   `id` BIGINT(20) NOT NULL AUTO_INCREMENT,

+ 1 - 0
src/main/java/com/diagbot/config/CustomTokenEnhancer.java

@@ -21,6 +21,7 @@ public class CustomTokenEnhancer implements TokenEnhancer {
         final Map<String, Object> additionalInfo = new HashMap<>();
         SysUserUaa user = (SysUserUaa) authentication.getUserAuthentication().getPrincipal();
         additionalInfo.put("user_id", user.getId());
+        additionalInfo.put("hosp_id", user.getHospitalId());
         //		additionalInfo.put("authorities", user.getAuthorities());
         ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
         return accessToken;

+ 13 - 0
src/main/java/com/diagbot/entity/SysUserUaa.java

@@ -70,6 +70,11 @@ public class SysUserUaa implements UserDetails, Serializable {
      */
     private Integer type;
 
+    /**
+     * 医院ID
+     */
+    private Long hospitalId;
+
     private List<? extends GrantedAuthority> authorities;
 
     @Override
@@ -178,6 +183,14 @@ public class SysUserUaa implements UserDetails, Serializable {
         this.type = type;
     }
 
+    public Long getHospitalId() {
+        return hospitalId;
+    }
+
+    public void setHospitalId(Long hospitalId) {
+        this.hospitalId = hospitalId;
+    }
+
     @Override
     public String toString() {
         return "User{" +

+ 2 - 0
src/main/java/com/diagbot/mapper/SysUserUaaMapper.java

@@ -12,4 +12,6 @@ import com.diagbot.entity.SysUserUaa;
  */
 public interface SysUserUaaMapper {
     SysUserUaa getByUserName(String username);
+
+    SysUserUaa getHospByUserName(String username);
 }

+ 10 - 0
src/main/java/com/diagbot/service/UrlUserService.java

@@ -43,6 +43,16 @@ public class UrlUserService implements UserDetailsService {
                 }
             }
             user.setGrantedAuthorities(grantedAuthorities);
+            if (user.getType().equals(ConstantEnum.OUTER_USER.getKey())) {
+                SysUserUaa userHosp = userUaaMapper.getHospByUserName(userName);
+                if (null == userHosp) {
+                    throw new UsernameNotFoundException("医院管理人员: " + userName + " 未绑定医院");
+                } else {
+                    user.setHospitalId(userHosp.getHospitalId());
+                }
+            } else {
+                user.setHospitalId(-1L);
+            }
             return user;
         } else {
             throw new UsernameNotFoundException("admin: " + userName + " do not exist");

+ 9 - 9
src/main/java/com/diagbot/util/SysUserUtils.java

@@ -45,15 +45,15 @@ public class SysUserUtils {
         return SysJwtUtil.getUserId(oauthDetails.getTokenValue());
     }
 
-//    /**
-//     * 获取当前请求用户的医院ID
-//     *
-//     * @return
-//     */
-//    public static String getCurrentHospitalID() {
-//        OAuth2AuthenticationDetails oauthDetails = (OAuth2AuthenticationDetails) SecurityContextHolder.getContext().getAuthentication().getDetails();
-//        return SysJwtUtil.getHospId(oauthDetails.getTokenValue());
-//    }
+    /**
+     * 获取当前请求用户的医院ID
+     *
+     * @return
+     */
+    public static String getCurrentHospitalID() {
+        OAuth2AuthenticationDetails oauthDetails = (OAuth2AuthenticationDetails) SecurityContextHolder.getContext().getAuthentication().getDetails();
+        return SysJwtUtil.getHospId(oauthDetails.getTokenValue());
+    }
 
 
     /**

+ 17 - 0
src/main/resources/mapper/SysUserUaaMapper.xml

@@ -33,4 +33,21 @@
         where is_deleted = 'N' and u.status = 1 and u.username= #{username}
 	</select>
 
+    <select id="getHospByUserName" parameterType="java.lang.String" resultMap="userUaaHospMap">
+        SELECT
+            u.*, uh.hospital_id AS hospitalId
+        FROM
+            sys_user u,
+            sys_user_hospital uh,
+            tran_hospital_info h
+        WHERE
+            u.is_deleted = 'N'
+        AND u.status = 1
+        AND u.username = #{username}
+        AND u.id = uh.user_id
+        AND uh.is_deleted = 'N'
+        AND h.id = uh.hospital_id
+        AND h.is_deleted = 'N'
+	</select>
+
 </mapper>