Selaa lähdekoodia

templeDesice 2022/8/31

lwhhszx 3 vuotta sitten
vanhempi
commit
dc5a6ea0ce

+ 0 - 2
PAS/src/main/java/cn/cslg/pas/common/config/InnerInterceptor/LizzMybatisIntercepts.java

@@ -55,8 +55,6 @@ public class LizzMybatisIntercepts implements InnerInterceptor {
         String Localsql = boundSql.getSql();
         Map<String,Object> maps= SecurityUtils.getDataScope(); //获得线程里保存的functionId
         if (maps != null) {
-            String q= "token:login:"+maps.get("token").toString().replace("=",":");
-       String a=   redisUtil.get(q);
             SecurityUtils.cleanDataScope(); //当第一次进来后删除线程保存的functionId,避免后续使用的查询sql进来
             Integer functionId =Integer.parseInt(maps.get("functionId").toString());
             String token =maps.get("token").toString();

+ 30 - 0
PAS/src/main/java/cn/cslg/pas/common/utils/SecurityUtils/LoginUtils.java

@@ -0,0 +1,30 @@
+package cn.cslg.pas.common.utils.SecurityUtils;
+
+import cn.cslg.pas.common.utils.RedisUtil;
+import cn.hutool.core.io.FileUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.system.ApplicationHome;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.File;
+
+public class LoginUtils {
+     @Autowired
+     private RedisUtil redisUtil;
+    public static String getToken() {
+        RequestAttributes ra = RequestContextHolder.getRequestAttributes();
+        ServletRequestAttributes sra = (ServletRequestAttributes) ra;
+        HttpServletRequest httpRequest = sra.getRequest();
+        String tem =httpRequest.getHeader("Cookie");
+        return tem;
+    }
+    public  String getId() {
+    String oriToken=LoginUtils.getToken();
+        String q= "token:login:"+oriToken.replace("=",":");
+        String Id= redisUtil.get(q);
+           return Id;
+    }
+}

+ 2 - 2
PAS/src/main/java/cn/cslg/pas/common/utils/auth/AuthAop.java

@@ -49,13 +49,12 @@ public class AuthAop {
         Method method = ms.getMethod();
         checkAuth myAnnotation = method.getAnnotation(checkAuth.class);
         Integer functionId =myAnnotation.FunId();
-
+        // 将请求里的token保存到字段token里
         //RequestContextHolder:持有上下文的Request容器,获取到当前请求的request
         RequestAttributes ra = RequestContextHolder.getRequestAttributes();
         ServletRequestAttributes sra = (ServletRequestAttributes) ra;
         HttpServletRequest httpRequest = sra.getRequest();
         String tem =httpRequest.getHeader("Cookie");
-
         Object[] args = joinPoint.getArgs();
         //遍历参数 修改带有需求字段对象的值
         for (Object obj : args) {
@@ -71,6 +70,7 @@ public class AuthAop {
             } catch (Exception e) {
             }
         }
+
         //根据登录人的id以及功能id获得计算逻辑
         RequestBody requestBody =  new FormBody.Builder()
                 .add("loginId", "4")

+ 44 - 5
PAS/src/main/java/cn/cslg/pas/common/utils/auth/TreeUtils.java

@@ -15,14 +15,42 @@ import java.util.List;
 
 @Component
 public class TreeUtils {
+    /**
+     * 将二叉树json对象转为sql where后的条件语句
+     *liRJ
+     * @param jsonObject 要处理的jsonObject对象
+     * @param dataSource  要使用的数据字典
+     * @param personnelVO 登录人的信息
+     * @return 拼接的sql
+     */
+    // 处理sql语句,返回拼接sql
     public static   String reSql(JSONObject jsonObject,List<DataSource> dataSource,PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
         String sql ="";
+        //符合二叉树形式
        if (jsonObject.containsKey("left")&&jsonObject.containsKey("right")){
       sql=  recursionTree(jsonObject,dataSource,personnelVO);}
-        return sql;
+       // 不符合二叉树形式(单条数据)
+       else{
+           String field =jsonObject.get("field").toString();
+           String value=distinguishFields(jsonObject.get("value").toString(),dataSource,personnelVO);
+           if(jsonObject.get("opr").toString().equals("FIND_IN_SET")){
+               sql ="FIND_IN_SET("+value+","+field+")";
+           }
+           else{
+               sql = field+" "+jsonObject.get("opr").toString()+" "+value;}
+       }
 
+        return sql;
     }
 
+    /**
+     * 将二叉树json对象转为sql where后的条件语句
+     *liRJ
+     * @param jsonObject 要处理的jsonObject对象
+     * @param dataSource  要使用的数据字典
+     * @param personnelVO 登录人的信息
+     * @return 拼接的sql
+     */
     public static   String reCompute(JSONObject jsonObject,Integer id,Object[] object) throws NoSuchFieldException, IllegalAccessException {
 
         String sql=  cRecursionTree(jsonObject,id,object);
@@ -31,7 +59,7 @@ public class TreeUtils {
     }
 
     /**
-     * 将二叉树json对象转为sql where后的条件语句
+     * 递归将二叉树转换为字符串
      *liRJ
      * @param jsonObject jsaonObject
      * @return
@@ -41,18 +69,21 @@ public class TreeUtils {
         String str2 = "";
         JSONObject jsonLeft =jsonObject.getJSONObject("left");
         JSONObject jsonRight =jsonObject.getJSONObject("right");
+        //判断是否含有left分支
         if(jsonLeft.containsKey("left")){
-            str1 = recursionTree(jsonLeft,dataSource,personnelVO);
+            str1 = recursionTree(jsonLeft,dataSource,personnelVO);//递归
         }
         else{
             String field =jsonLeft.get("field").toString();
-            String value=distinguishFields(jsonLeft.get("value").toString(),dataSource,personnelVO);
+            String value=distinguishFields(jsonLeft.get("value").toString(),dataSource,personnelVO); //没有的话解析字符串拼接成子sql
             if(jsonLeft.get("opr").toString().equals("FIND_IN_SET")){
                 str1 ="FIND_IN_SET("+value+","+field+")";
             }
             else{
             str1 = field+" "+jsonLeft.get("opr").toString()+" "+value;}
         }
+
+        //同上部分处理left分支
         if(jsonRight.containsKey("right")){
             str2= recursionTree( jsonRight,dataSource,personnelVO);
         }
@@ -99,16 +130,23 @@ public class TreeUtils {
         return sql;
     };
 
-    //对field部分进行计算 sql查询
+    //对field和value部分进行计算 sql查询
     public static String distinguishFields(String field, List<DataSource> dataSources,PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
+     //获得登录用户部门列表信息
      List<PersonnelVO.DP> dps =personnelVO.getDpList();
+     //获得登录用户角色列表信息
      List<PersonnelVO.PerRole> perRoles =personnelVO.getRList();
         String tem ="";
         String reField =field;
+        //遍历字典数据
         for(DataSource dataSource :dataSources){
+            // 如果匹配上字典字段则进行处理
             if(field.equals(dataSource.getDataSourceField())){
+                // 判断是否是部门信息
                 if(field.contains("DP.")){
+                    // 分割字符串获得部门字段
           String Fields= field.split("\\.")[1];
+          // 遍历部门信息,用反射将对应字段转换成(*,*,...)格式
           for(PersonnelVO.DP dp : dps){
               Class DPClass =dp.getClass();
               Field dataField = DPClass.getDeclaredField(Fields);
@@ -118,6 +156,7 @@ public class TreeUtils {
           }
 reField = "("+tem.substring(0,tem.length() - 1)+")";
                 }
+                //判断是否是角色信息(处理过程同部门信息处理过程)
                 else if(field.contains("PerRole.")){
                     String Fields= field.split("\\.")[1];
                     for(PersonnelVO.PerRole perRole : perRoles){

+ 2 - 0
PAS/src/main/java/cn/cslg/pas/service/ProjectService.java

@@ -6,6 +6,7 @@ import cn.cslg.pas.common.model.PersonnelVO;
 import cn.cslg.pas.common.model.dto.UploadFileDTO;
 import cn.cslg.pas.common.model.params.*;
 import cn.cslg.pas.common.model.vo.*;
+import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
 import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.utils.SecurityUtils.SecurityUtils;
 import cn.cslg.pas.domain.*;
@@ -101,6 +102,7 @@ public class ProjectService extends ServiceImpl<ProjectMapper, Project> {
     private final PatentInventorMergeService patentInventorMergeService;
     private final UserService userService;
     private final ApiUtils apiUtils;
+    private final LoginUtils loginUtils;
 
     public Project getProjectByName(String name) {
         LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();