Parcourir la source

是否为医生角色

lihong il y a 2 ans
Parent
commit
3fe10c039c

+ 8 - 8
src/main/java/cn/hnthyy/thmz/Utils/StringUtil.java

@@ -246,19 +246,19 @@ public class StringUtil {
     }
 
     public static String getExceptionToString(Throwable e) {
-        if (e == null){
-            return "";
+        if (e == null) {
+            return "" ;
         }
         PrintWriter printWriter = null;
+        StringWriter stringWriter = null;
         try {
-            StringWriter stringWriter = new StringWriter();
-             printWriter = new PrintWriter(stringWriter);
+            stringWriter = new StringWriter();
+            printWriter = new PrintWriter(stringWriter);
             e.printStackTrace(printWriter);
             return stringWriter.toString();
-        }finally {
-            if(printWriter != null){
-                printWriter.close();
-            }
+        } finally {
+            IoUtil.close(printWriter);
+            IoUtil.close(stringWriter);
         }
     }
 }

+ 21 - 0
src/main/java/cn/hnthyy/thmz/controller/mz/RoleController.java

@@ -1,5 +1,6 @@
 package cn.hnthyy.thmz.controller.mz;
 
+import cn.hnthyy.thmz.Utils.R;
 import cn.hnthyy.thmz.Utils.TokenUtil;
 import cn.hnthyy.thmz.comment.UserLoginToken;
 import cn.hnthyy.thmz.entity.thmz.Menu;
@@ -12,6 +13,7 @@ import cn.hnthyy.thmz.service.thmz.*;
 import cn.hnthyy.thmz.vo.RoleMenuRelationVo;
 import cn.hnthyy.thmz.vo.RoleMenuVo;
 import cn.hnthyy.thmz.vo.RoleVo;
+import cn.hutool.core.collection.CollUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -75,6 +77,25 @@ public class RoleController {
             return resultMap;
         }
     }
+    /**
+     * @description:检查是否为医生角色
+     * @author: lihong
+     * @date: 2023/8/23 16:18
+     * @return: cn.hnthyy.thmz.Utils.R
+     **/
+    @UserLoginToken
+    @GetMapping("/checkDoctorRoleByUser")
+    public R checkDoctorRoleByUser(){
+        User user = TokenUtil.getUser();
+        List<UserRoleRelation> userRoleRelations = userRoleRelationService.queryByUserId(user.getId());
+        if(CollUtil.isNotEmpty(userRoleRelations)){
+            //10 为 门诊医生角色id
+            if (userRoleRelations.stream().anyMatch(o -> o.getRoleId() != null && o.getRoleId() == 10)) {
+                    return R.ok().put("data",true);
+            }
+        }
+        return R.ok().put("data", false);
+    }
 
     /**
      * 根据主键查询角色