瀏覽代碼

20240914_sun

15143018065 1 月之前
父節點
當前提交
d554f24dca

+ 93 - 25
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/EncryptionUtils.java

@@ -23,53 +23,82 @@ public class EncryptionUtils {
         } catch (Exception e) {
             //
         }
+        // 检测是用token/固定key加密的情况
+        int enCount = 0;
+        int tokenCount = 0;
+        int keyCount = 0;
         for (Field field : fields) {
             if (field.isAnnotationPresent(EncryptionV.class)) {
                 field.setAccessible(true);
                 Object attObj = null;
                 try {
                     attObj = field.get(t);
-                } catch (Exception e) {
-                    //
-                }
+                } catch (Exception ignored) {}
                 if (ObjectUtils.isNotEmpty(attObj)) {
                     String beforeSet = attObj.toString();
                     if (beforeSet.contains("✱")) {
                         throw new ServiceException("s✱"+field.getAnnotation(ApiModelProperty.class).value() + "属性包含非法字符,请修改后提交"+"e✱");
                     } else {
-                        // 先根据token进行一次解密 如果解密成功了说明传过来的数据是这次取出来的 这种情况根据token解密处理后 再加密存储
+                        enCount ++;
                         String beforeSetEnToken = null;
                         try {
                             beforeSetEnToken = SecurityUtils.sm4decrypt_ECB(SecurityUtils.getEncryptKey(), beforeSet);
-                        } catch(Exception e) {
-                            //
-                        }
+                        } catch(Exception ignored) {}
                         String beforeSetEnKey = null;
                         try {
                             beforeSetEnKey = SecurityUtils.sm4decrypt_ECB(key, beforeSet);
-                        } catch(Exception e) {
-                            //
-                        }
-                        if (StringUtils.isNotEmpty(beforeSetEnToken) && StringUtils.isEmpty(beforeSetEnKey)) {
-                            if((java.nio.charset.Charset.forName("GBK").newEncoder().canEncode(beforeSetEnToken)) && isMessyCode(beforeSetEnToken)){
-                                beforeSet = beforeSetEnToken;
-                            }
-                        } else if (StringUtils.isNotEmpty(beforeSetEnKey) && StringUtils.isEmpty(beforeSetEnToken)) {
-                            if((java.nio.charset.Charset.forName("GBK").newEncoder().canEncode(beforeSetEnKey)) && isMessyCode(beforeSetEnKey)){
-                                beforeSet = beforeSetEnKey;
-                            }
-                        } else if (StringUtils.isNotEmpty(beforeSetEnToken) && StringUtils.isNotEmpty(beforeSetEnKey)) {
+                        } catch(Exception ignored) {}
+                        if (StringUtils.isNotEmpty(beforeSetEnToken)) {
                             if((java.nio.charset.Charset.forName("GBK").newEncoder().canEncode(beforeSetEnToken)) && isMessyCode(beforeSetEnToken)){
-                                beforeSet = beforeSetEnToken;
+                                tokenCount ++;
                             }
+                        }
+                        if (StringUtils.isNotEmpty(beforeSetEnKey)) {
                             if((java.nio.charset.Charset.forName("GBK").newEncoder().canEncode(beforeSetEnKey)) && isMessyCode(beforeSetEnKey)){
-                                beforeSet = beforeSetEnKey;
+                                keyCount ++;
                             }
                         }
-                        try {
-                            field.set(t, SecurityUtils.sm4encrypt_ECB(key, beforeSet));
-                        } catch (Exception e) {
-                            //
+                    }
+                }
+            }
+        }
+
+        if (enCount > 0) {
+            // 存在加密且有值的字段
+            String status = "none";
+            if (enCount == tokenCount) {
+                // token 加密情况
+                status = "token";
+            } else if (enCount == keyCount) {
+                // 固定key 加密情况
+                status = "key";
+            }
+            for (Field field : fields) {
+                if (field.isAnnotationPresent(EncryptionV.class)) {
+                    field.setAccessible(true);
+                    Object attObj = null;
+                    try {
+                        attObj = field.get(t);
+                    } catch (Exception e) {
+                        //
+                    }
+                    if (ObjectUtils.isNotEmpty(attObj)) {
+                        String beforeSet = attObj.toString();
+                        if (beforeSet.contains("✱")) {
+                            throw new ServiceException("s✱"+field.getAnnotation(ApiModelProperty.class).value() + "属性包含非法字符,请修改后提交"+"e✱");
+                        } else {
+                            if (StringUtils.equals(status, "token")) {
+                                try {
+                                    beforeSet = SecurityUtils.sm4decrypt_ECB(SecurityUtils.getEncryptKey(), beforeSet);
+                                } catch (Exception ignored) {}
+                            } else if (StringUtils.equals(status, "key")) {
+                                try {
+                                    beforeSet = SecurityUtils.sm4decrypt_ECB(key, beforeSet);
+                                } catch (Exception ignored) {}
+                            }
+                            try {
+                                field.set(t, SecurityUtils.sm4encrypt_ECB(key, beforeSet));
+                            } catch (Exception ignored) {}
                         }
                     }
                 }
@@ -209,6 +238,45 @@ public class EncryptionUtils {
 //        }
 //    }
 
+    public static <T> void decryptCommon(T t) {
+        Class<?> bean;
+        Field[] fields = new Field[0];
+        try {
+            bean = t.getClass();
+            fields = bean.getDeclaredFields();
+        } catch (Exception e) {
+            //
+        }
+        for (Field field : fields) {
+            if (field.isAnnotationPresent(EncryptionV.class)) {
+                field.setAccessible(true);
+                Object attObj = null;
+                try {
+                    attObj = field.get(t);
+                } catch (Exception e) {
+                    //
+                }
+                if (ObjectUtils.isNotEmpty(attObj)) {
+                    String beforeSet = attObj.toString();
+                    if (beforeSet.contains("✱")) {
+                        throw new ServiceException("s✱"+field.getAnnotation(ApiModelProperty.class).value() + "属性包含非法字符,请修改后提交"+"e✱");
+                    } else {
+                        try {
+                            String en = SecurityUtils.sm4decrypt_ECB(key, beforeSet);
+                            if (StringUtils.isNotEmpty(en)) {
+                                if (java.nio.charset.Charset.forName("GBK").newEncoder().canEncode(en)) {
+                                    field.set(t, en);
+                                }
+                            }
+                        } catch (Exception e) {
+                            //
+                        }
+                    }
+                }
+            }
+        }
+    }
+
     private static boolean isMessyCode(String fileName) {
         try {
             for (int i = fileName.length(); --i >= 0; ) {

+ 1 - 1
ruoyi-modules/mz-organization-jg/src/main/resources/mapper/organization/YljgJcxxOtherMapper.xml

@@ -203,7 +203,7 @@
                a.update_unit_name,
                a.sqstlx,
                a.sqstbh
-        from `mz-cloud`.yljgsq_jcxx a
+        from `yl_service`.yljgsq_jcxx a
     </sql>
 
 

+ 14 - 14
ruoyi-modules/mz-organization-khgl/src/main/resources/mapper/organization/YljgKhRztzxxMapper.xml

@@ -75,22 +75,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         `create_time_str` AS `create_time_str`,
         (
         SELECT
-        `mz-cloud`.`yljg_fwcd_fj`.`fjmc`
+        `yl_service`.`yljg_fwcd_fj`.`fjmc`
         FROM
-        `mz-cloud`.`yljg_fwcd_fj`
+        `yl_service`.`yljg_fwcd_fj`
         WHERE
         (
-        `mz-cloud`.`yljg_fwcd_fj`.`id` = `fj_id`
+        `yl_service`.`yljg_fwcd_fj`.`id` = `fj_id`
         )
         ) AS `rzfj`,
         (
         SELECT
-        `mz-cloud`.`yljg_fwcd_cw`.`cwh`
+        `yl_service`.`yljg_fwcd_cw`.`cwh`
         FROM
-        `mz-cloud`.`yljg_fwcd_cw`
+        `yl_service`.`yljg_fwcd_cw`
         WHERE
         (
-        `mz-cloud`.`yljg_fwcd_cw`.`id` = `cw_id`
+        `yl_service`.`yljg_fwcd_cw`.`id` = `cw_id`
         )
         ) AS `rzcw`,
         `yjrzrq` AS `yjrzrq`,
@@ -98,7 +98,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         `rzzt` AS `rzzt`,
         `create_by` AS `blr`
         FROM
-        `mz-cloud`.`yljg_kh_htxx`
+        `yl_service`.`yljg_kh_htxx`
         <where>
             `status` = '0'
             <if test="xm != null  and xm != ''"> and xm like concat('%', #{xm}, '%')</if>
@@ -128,22 +128,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         `create_time_str` AS `create_time_str`,
         (
         SELECT
-        `mz-cloud`.`yljg_fwcd_fj`.`fjmc`
+        `yl_service`.`yljg_fwcd_fj`.`fjmc`
         FROM
-        `mz-cloud`.`yljg_fwcd_fj`
+        `yl_service`.`yljg_fwcd_fj`
         WHERE
         (
-        `mz-cloud`.`yljg_fwcd_fj`.`id` = `fj_id`
+        `yl_service`.`yljg_fwcd_fj`.`id` = `fj_id`
         )
         ) AS `rzfj`,
         (
         SELECT
-        `mz-cloud`.`yljg_fwcd_cw`.`cwh`
+        `yl_service`.`yljg_fwcd_cw`.`cwh`
         FROM
-        `mz-cloud`.`yljg_fwcd_cw`
+        `yl_service`.`yljg_fwcd_cw`
         WHERE
         (
-        `mz-cloud`.`yljg_fwcd_cw`.`id` = `cw_id`
+        `yl_service`.`yljg_fwcd_cw`.`id` = `cw_id`
         )
         ) AS `rzcw`,
         `yjrzrq` AS `yjrzrq`,
@@ -151,7 +151,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         `rzzt` AS `rzzt`,
         `create_by` AS `blr`
         FROM
-        `mz-cloud`.`yljg_kh_htxx`
+        `yl_service`.`yljg_kh_htxx`
         <where>
             sjrzsj is not null and sjrzsj != ''
             <if test="xm != null  and xm != ''"> and xm like concat('%', #{xm}, '%')</if>

+ 1 - 1
ruoyi-modules/mz-system-ext/src/main/java/com/ruoyi/system/service/impl/SysDeptJlServiceImpl.java

@@ -296,7 +296,7 @@ public class SysDeptJlServiceImpl implements ISysDeptJlService {
     @PostConstruct
     public void init()
     {
-        loadingDeptCache();
+//        loadingDeptCache();
     }
 
     @PostConstruct