wangliang 2 жил өмнө
parent
commit
6edc5bb8c2

+ 2 - 31
distributed-print/src/main/java/com/qmth/distributed/print/api/MenuCustomController.java

@@ -4,8 +4,6 @@ package com.qmth.distributed.print.api;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.distributed.print.business.bean.params.TSchoolPrivilegeParam;
-import com.qmth.teachcloud.common.bean.dto.PrivilegeDto;
-import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.*;
 import com.qmth.teachcloud.common.enums.PrivilegeEnum;
 import com.qmth.teachcloud.common.service.*;
@@ -62,35 +60,8 @@ public class MenuCustomController {
     @ApiOperation(value = "查询自定义菜单权限")
     @ApiResponses({@ApiResponse(code = 200, message = "菜单权限信息", response = SysPrivilege.class)})
     @RequestMapping(value = "/custom/list", method = RequestMethod.POST)
-    public Result rolePrivilegeCountSync() {
-        QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
-        sysPrivilegeQueryWrapper.lambda()
-                .eq(SysPrivilege::getEnable, true)
-                .eq(SysPrivilege::getDefaultAuth, false)
-                .ne(SysPrivilege::getType, PrivilegeEnum.URL)
-                .notIn(SysPrivilege::getId, SystemConstant.MENU_MANAGE);
-        List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
-        List<PrivilegeDto> privilegeDtoList = null;
-        if (Objects.nonNull(sysPrivilegeList) && sysPrivilegeList.size() > 0) {
-            Set<Long> privilegeIds = new HashSet<>();
-            Map<Long, SysPrivilege> sysPrivilegeMap = new HashMap<>();
-            for (SysPrivilege s : sysPrivilegeList) {
-                if (!Objects.equals(s.getType(), PrivilegeEnum.MENU)) {
-                    privilegeIds.add(s.getId());
-                }
-                sysPrivilegeMap.put(s.getId(), s);
-            }
-            for (Long l : privilegeIds) {
-                List<SysPrivilege> sysPrivileges = sysPrivilegeService.findByConnectByParentId(l);
-                for (SysPrivilege s : sysPrivileges) {
-                    sysPrivilegeMap.put(s.getId(), s);
-                }
-            }
-            List<SysPrivilege> list = new ArrayList<>(sysPrivilegeMap.values());
-            Collections.sort(list);
-            privilegeDtoList = (List<PrivilegeDto>) sysPrivilegeService.getMenuTreeCommon(list);
-        }
-        return ResultUtil.ok(privilegeDtoList);
+    public Result customList() {
+        return ResultUtil.ok(sysPrivilegeService.addCustomList());
     }
 
     @ApiOperation(value = "学校新增/修改自定义菜单权限")

+ 1 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -145,6 +145,7 @@ public class SystemConstant {
     public static final String ROLE_CACHE = "role:cache";
     public static final String AUTH_INFO_CACHE = "auth:info:cache";
     public static final String TXT_CHARSET_CACHE = "charset:txt:cache";
+    public static final String CUSTOM_PRIVILEGE_CACHE = "custom:privilege:cache";
 
     /**
      * 报表缓存

+ 21 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/SysPrivilegeService.java

@@ -51,4 +51,25 @@ public interface SysPrivilegeService extends IService<SysPrivilege> {
      * @return
      */
     Collection<?> getMenuTreeCommon(Collection<?> sysPrivilegeList);
+
+    /**
+     * 获取自定义菜单
+     *
+     * @return
+     */
+    List<PrivilegeDto> addCustomList();
+
+    /**
+     * 更新自定义菜单
+     *
+     * @return
+     */
+    List<PrivilegeDto> updateCustomList();
+
+    /**
+     * 删除自定义菜单
+     *
+     * @return
+     */
+    void removeCustomList();
 }

+ 67 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysPrivilegeServiceImpl.java

@@ -22,6 +22,9 @@ import com.qmth.teachcloud.common.util.JacksonUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.util.LinkedMultiValueMap;
 
@@ -284,4 +287,68 @@ public class SysPrivilegeServiceImpl extends ServiceImpl<SysPrivilegeMapper, Sys
         }
         return new ArrayList<>(map.values());
     }
+
+    @Override
+    @CacheEvict(value = SystemConstant.CUSTOM_PRIVILEGE_CACHE)
+    public void removeCustomList() {
+
+    }
+
+    /**
+     * 获取自定义菜单
+     *
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.CUSTOM_PRIVILEGE_CACHE)
+    public List<PrivilegeDto> addCustomList() {
+        return this.commonCustomList();
+    }
+
+    /**
+     * 更新自定义菜单
+     *
+     * @return
+     */
+    @Override
+    @CachePut(value = SystemConstant.CUSTOM_PRIVILEGE_CACHE, unless = "#result == null")
+    public List<PrivilegeDto> updateCustomList() {
+        return this.commonCustomList();
+    }
+
+    /**
+     * 自定义菜单公用
+     *
+     * @return
+     */
+    private List<PrivilegeDto> commonCustomList() {
+        QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
+        sysPrivilegeQueryWrapper.lambda()
+                .eq(SysPrivilege::getEnable, true)
+                .eq(SysPrivilege::getDefaultAuth, false)
+                .ne(SysPrivilege::getType, PrivilegeEnum.URL)
+                .notIn(SysPrivilege::getId, SystemConstant.MENU_MANAGE);
+        List<SysPrivilege> sysPrivilegeList = this.list(sysPrivilegeQueryWrapper);
+        List<PrivilegeDto> privilegeDtoList = null;
+        if (Objects.nonNull(sysPrivilegeList) && sysPrivilegeList.size() > 0) {
+            Set<Long> privilegeIds = new HashSet<>();
+            Map<Long, SysPrivilege> sysPrivilegeMap = new HashMap<>();
+            for (SysPrivilege s : sysPrivilegeList) {
+                if (!Objects.equals(s.getType(), PrivilegeEnum.MENU)) {
+                    privilegeIds.add(s.getId());
+                }
+                sysPrivilegeMap.put(s.getId(), s);
+            }
+            for (Long l : privilegeIds) {
+                List<SysPrivilege> sysPrivileges = this.findByConnectByParentId(l);
+                for (SysPrivilege s : sysPrivileges) {
+                    sysPrivilegeMap.put(s.getId(), s);
+                }
+            }
+            List<SysPrivilege> list = new ArrayList<>(sysPrivilegeMap.values());
+            Collections.sort(list);
+            privilegeDtoList = (List<PrivilegeDto>) this.getMenuTreeCommon(list);
+        }
+        return privilegeDtoList;
+    }
 }

+ 68 - 125
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/Zip4jUtil.java

@@ -1,5 +1,6 @@
 package com.qmth.teachcloud.common.util;
 
+import cn.hutool.core.collection.CollectionUtil;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import net.lingala.zip4j.core.ZipFile;
@@ -12,6 +13,7 @@ import org.springframework.util.CollectionUtils;
 
 import java.io.File;
 import java.util.List;
+import java.util.Objects;
 import java.util.Optional;
 
 /**
@@ -38,28 +40,7 @@ public class Zip4jUtil {
         if (CollectionUtils.isEmpty(files)) {
             throw ExceptionResultEnum.ERROR.exception("没有待压缩的文件");
         }
-        try {
-            // 生成的压缩文件
-            ZipFile zipFile = new ZipFile(scrPath);
-            ZipParameters parameters = new ZipParameters();
-            // 压缩方式
-            parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
-            // 压缩级别
-            parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
-            // 要打包的文件夹
-            File[] fs = files.toArray(new File[0]);
-            // 遍历test文件夹下所有的文件、文件夹
-            for (File f : fs) {
-                if (f.isDirectory()) {
-                    zipFile.addFolder(f.getPath(), parameters);
-                } else {
-                    zipFile.addFile(f, parameters);
-                }
-            }
-        } catch (Exception e) {
-            log.error(SystemConstant.LOG_ERROR, e);
-            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
-        }
+        commonZipFile(scrPath, null, files, null);
     }
 
     /**
@@ -74,32 +55,7 @@ public class Zip4jUtil {
             throw ExceptionResultEnum.ERROR.exception("压缩文件必须为zip");
         }
         Optional.ofNullable(destPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("压缩路径不能为空"));
-        try {
-            // 生成的压缩文件
-            ZipFile zipFile = new ZipFile(scrPath);
-            ZipParameters parameters = new ZipParameters();
-            // 压缩方式
-            parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
-            // 压缩级别
-            parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
-            // 要打包的文件夹
-            File currentFile = new File(destPath);
-            if (!currentFile.exists()) {
-                throw ExceptionResultEnum.ERROR.exception("待压缩的路径不存在");
-            }
-            File[] fs = currentFile.listFiles();
-            // 遍历test文件夹下所有的文件、文件夹
-            for (File f : fs) {
-                if (f.isDirectory()) {
-                    zipFile.addFolder(f.getPath(), parameters);
-                } else {
-                    zipFile.addFile(f, parameters);
-                }
-            }
-        } catch (Exception e) {
-            log.error(SystemConstant.LOG_ERROR, e);
-            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
-        }
+        commonZipFile(scrPath, destPath, null, null);
     }
 
     /**
@@ -119,34 +75,7 @@ public class Zip4jUtil {
             throw ExceptionResultEnum.ERROR.exception("没有待压缩的文件");
         }
         Optional.ofNullable(password).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("压缩密码不能为空"));
-        try {
-            // 生成的压缩文件
-            ZipFile zipFile = new ZipFile(scrPath);
-            ZipParameters parameters = new ZipParameters();
-            // 压缩级别
-            parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
-            // 压缩级别
-            parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
-            parameters.setEncryptFiles(true);
-            parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
-            parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
-            Optional.ofNullable(password).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("压缩密码不能为空"));
-            parameters.setPassword(password);
-
-            // 要打包的文件夹
-            File[] fs = files.toArray(new File[0]);
-            // 遍历test文件夹下所有的文件、文件夹
-            for (File f : fs) {
-                if (f.isDirectory()) {
-                    zipFile.addFolder(f.getPath(), parameters);
-                } else {
-                    zipFile.addFile(f, parameters);
-                }
-            }
-        } catch (Exception e) {
-            log.error(SystemConstant.LOG_ERROR, e);
-            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
-        }
+        commonZipFile(scrPath, null, files, password);
     }
 
     /**
@@ -163,38 +92,7 @@ public class Zip4jUtil {
         }
         Optional.ofNullable(destPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("压缩路径不能为空"));
         Optional.ofNullable(password).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("压缩密码不能为空"));
-        try {
-            // 生成的压缩文件
-            ZipFile zipFile = new ZipFile(scrPath);
-            ZipParameters parameters = new ZipParameters();
-            // 压缩级别
-            parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
-            // 压缩级别
-            parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
-            parameters.setEncryptFiles(true);
-            parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
-            parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
-            Optional.ofNullable(password).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("压缩密码不能为空"));
-            parameters.setPassword(password);
-
-            // 要打包的文件夹
-            File currentFile = new File(destPath);
-            if (!currentFile.exists()) {
-                throw ExceptionResultEnum.ERROR.exception("待压缩的路径不存在");
-            }
-            File[] fs = currentFile.listFiles();
-            // 遍历test文件夹下所有的文件、文件夹
-            for (File f : fs) {
-                if (f.isDirectory()) {
-                    zipFile.addFolder(f.getPath(), parameters);
-                } else {
-                    zipFile.addFile(f, parameters);
-                }
-            }
-        } catch (Exception e) {
-            log.error(SystemConstant.LOG_ERROR, e);
-            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
-        }
+        commonZipFile(scrPath, destPath, null, password);
     }
 
     /**
@@ -206,13 +104,7 @@ public class Zip4jUtil {
     public static void unzip(String scrPath, String destPath) {
         Optional.ofNullable(scrPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("原始路径不能为空"));
         Optional.ofNullable(destPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("解压路径不能为空"));
-        try {
-            ZipFile zipFile = new ZipFile(scrPath);
-            zipFile.extractAll(destPath);
-        } catch (ZipException e) {
-            log.error(SystemConstant.LOG_ERROR, e);
-            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
-        }
+        commonUnZipFile(scrPath, destPath, null);
     }
 
     /**
@@ -226,9 +118,20 @@ public class Zip4jUtil {
         Optional.ofNullable(scrPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("原始路径不能为空"));
         Optional.ofNullable(destPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("解压路径不能为空"));
         Optional.ofNullable(password).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("解压密码不能为空"));
+        commonUnZipFile(scrPath, destPath, password);
+    }
+
+    /**
+     * 解压zip包
+     *
+     * @param scrPath
+     * @param destPath
+     * @param password
+     */
+    private static void commonUnZipFile(String scrPath, String destPath, String password) {
         try {
             ZipFile zipFile = new ZipFile(scrPath);
-            if (zipFile.isEncrypted()) {
+            if (Objects.nonNull(password) && zipFile.isEncrypted()) {
                 zipFile.setPassword(password);
             }
             zipFile.extractAll(destPath);
@@ -238,13 +141,53 @@ public class Zip4jUtil {
         }
     }
 
-//    public static void main(String[] args) throws ZipException {
-//        List<File> fileList = Arrays.asList(new File("/Users/king/Downloads/pdf-temp/pdf/2022/08/12/2ecb7386e70940c585be4bbf062a3f51.pdf"),
-//                new File("/Users/king/Downloads/pdf-temp/pdf/2022/08/12/8f67b08558bb4841b0109d95efc7ea4a.pdf"));
-//        zipFile("/Users/king/Downloads/test1.zip", fileList);
-//        zipFile("/Users/king/Downloads/test2.zip", "/Users/king/Downloads/file-temp");
-//        zipEncryptFile("/Users/king/Downloads/test1.zip", "/Users/king/Downloads/pdf-temp", "123456");
-//        unzip("/Users/king/Downloads/test2.zip", "/Users/king/Downloads/test2");
-//        unzipEncryptFile("/Users/king/Downloads/test1.zip", "/Users/king/Downloads/test1", "123456");
-//    }
+    /**
+     * 压缩zip包
+     *
+     * @param scrPath
+     * @param destPath
+     * @param files
+     * @param password
+     */
+    private static void commonZipFile(String scrPath, String destPath, List<File> files, String password) {
+        try {
+            // 生成的压缩文件
+            ZipFile zipFile = new ZipFile(scrPath);
+            ZipParameters parameters = new ZipParameters();
+            // 压缩级别
+            parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
+            // 压缩级别
+            parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
+            if (Objects.nonNull(password)) {
+                parameters.setEncryptFiles(true);
+                parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
+                parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
+                parameters.setPassword(password);
+            }
+
+            File[] fs = null;
+            if (CollectionUtil.isEmpty(files)) {
+                // 要打包的文件夹
+                fs = files.toArray(new File[0]);
+            } else if (Objects.nonNull(destPath)) {
+                File currentFile = new File(destPath);
+                if (!currentFile.exists()) {
+                    throw ExceptionResultEnum.ERROR.exception("待压缩的路径不存在");
+                }
+                fs = currentFile.listFiles();
+            }
+
+            // 遍历test文件夹下所有的文件、文件夹
+            for (File f : fs) {
+                if (f.isDirectory()) {
+                    zipFile.addFolder(f.getPath(), parameters);
+                } else {
+                    zipFile.addFile(f, parameters);
+                }
+            }
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
+        }
+    }
 }