Ver Fonte

权限模块优化

高家顺 há 3 anos atrás
pai
commit
d514b8ef86
18 ficheiros alterados com 70 adições e 93 exclusões
  1. 6 7
      src/main/java/com/macro/mall/tiny/common/util/MyFileUtils.java
  2. 1 4
      src/main/java/com/macro/mall/tiny/modules/business/controller/BLineController.java
  3. 0 1
      src/main/java/com/macro/mall/tiny/modules/business/controller/BLineUploadLogController.java
  4. 1 4
      src/main/java/com/macro/mall/tiny/modules/business/controller/BTowerController.java
  5. 7 17
      src/main/java/com/macro/mall/tiny/modules/business/controller/FileController.java
  6. 3 4
      src/main/java/com/macro/mall/tiny/modules/business/service/BDirectoryCacheService.java
  7. 2 3
      src/main/java/com/macro/mall/tiny/modules/business/service/BLineService.java
  8. 0 2
      src/main/java/com/macro/mall/tiny/modules/business/service/BProvinceCacheService.java
  9. 3 1
      src/main/java/com/macro/mall/tiny/modules/business/service/BTowerService.java
  10. 5 6
      src/main/java/com/macro/mall/tiny/modules/business/service/FileService.java
  11. 0 6
      src/main/java/com/macro/mall/tiny/modules/business/service/impl/AsyncHandler.java
  12. 8 9
      src/main/java/com/macro/mall/tiny/modules/business/service/impl/BDirectoryCacheServiceImpl.java
  13. 4 7
      src/main/java/com/macro/mall/tiny/modules/business/service/impl/BLineServiceImpl.java
  14. 9 6
      src/main/java/com/macro/mall/tiny/modules/business/service/impl/BTowerServiceImpl.java
  15. 0 2
      src/main/java/com/macro/mall/tiny/modules/business/service/impl/CommonServiceImpl.java
  16. 14 13
      src/main/java/com/macro/mall/tiny/modules/business/service/impl/FileServiceImpl.java
  17. 6 0
      src/main/java/com/macro/mall/tiny/security/util/AuthUtil.java
  18. 1 1
      src/main/resources/application-dev.yml

+ 6 - 7
src/main/java/com/macro/mall/tiny/common/util/MyFileUtils.java

@@ -100,8 +100,8 @@ public class MyFileUtils {
         return "";
     }
 
-    public static List<BFile> getSonFiles(String basePath, AdminUserDetails userDetails) {
-        boolean access = AuthUtil.checkAccess(userDetails, AuthUtil.ACCESS);
+    public static List<BFile> getSonFiles(String basePath) {
+        boolean access = AuthUtil.checkAccess(AuthUtil.ACCESS);
         return getSonFiles(basePath, null, access);
     }
 
@@ -135,15 +135,14 @@ public class MyFileUtils {
     }
 
     /**
-     * @param userDetails
      * @return com.macro.mall.tiny.modules.business.model.BDirectory
      * @describe 获取根目录下的所有文件夹
      * @author gjs
      * @date 2021/4/2
      * @since J7.23.0
      */
-    public static BDirectory getRootDirectory(AdminUserDetails userDetails) {
-        final boolean access = AuthUtil.checkAccess(userDetails, AuthUtil.ACCESS);
+    public static BDirectory getRootDirectory() {
+        final boolean access = AuthUtil.checkAccess(AuthUtil.ACCESS);
         final File rootDirectory = new File(UploadConfig.powerPath);
         return getAllAuthDirectory(rootDirectory, access);
     }
@@ -178,9 +177,9 @@ public class MyFileUtils {
         return thisFile;
     }
 
-    public static List<BFileDetail> getFileDetailList(String path, AdminUserDetails userDetails) {
+    public static List<BFileDetail> getFileDetailList(String path) {
         if (StringUtils.isBlank(path)) return Lists.newArrayList();
-        boolean access = AuthUtil.checkAccess(userDetails, AuthUtil.ACCESS);
+        boolean access = AuthUtil.checkAccess(AuthUtil.ACCESS);
         File oriDic = new File(path);
         if (!oriDic.exists() || oriDic.isFile() || (!access && path.contains(String.valueOf(UploadConfig.AUTH_STR)))) {
             return Lists.newArrayList();

+ 1 - 4
src/main/java/com/macro/mall/tiny/modules/business/controller/BLineController.java

@@ -2,14 +2,12 @@ package com.macro.mall.tiny.modules.business.controller;
 
 
 import com.macro.mall.tiny.common.api.CommonResult;
-import com.macro.mall.tiny.domain.AdminUserDetails;
 import com.macro.mall.tiny.modules.business.model.BFile;
 import com.macro.mall.tiny.modules.business.model.BLine;
 import com.macro.mall.tiny.modules.business.service.BLineService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.web.bind.annotation.*;
 
 import javax.websocket.server.PathParam;
@@ -60,8 +58,7 @@ public class BLineController {
     @RequestMapping(value = "/getFile/{id}", method = RequestMethod.GET)
     @ResponseBody
     public CommonResult<List<BFile>> getFile(@PathVariable Long id) {
-        AdminUserDetails userDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-        List<BFile> data = lineService.getFile(id, userDetails);
+        List<BFile> data = lineService.getFile(id);
         return CommonResult.success(data);
     }
 }

+ 0 - 1
src/main/java/com/macro/mall/tiny/modules/business/controller/BLineUploadLogController.java

@@ -2,7 +2,6 @@ package com.macro.mall.tiny.modules.business.controller;
 
 
 import com.macro.mall.tiny.common.api.CommonResult;
-import com.macro.mall.tiny.modules.business.model.BLine;
 import com.macro.mall.tiny.modules.business.model.BLineUploadLog;
 import com.macro.mall.tiny.modules.business.service.BLineUploadLogService;
 import io.swagger.annotations.Api;

+ 1 - 4
src/main/java/com/macro/mall/tiny/modules/business/controller/BTowerController.java

@@ -2,14 +2,12 @@ package com.macro.mall.tiny.modules.business.controller;
 
 
 import com.macro.mall.tiny.common.api.CommonResult;
-import com.macro.mall.tiny.domain.AdminUserDetails;
 import com.macro.mall.tiny.modules.business.model.BFile;
 import com.macro.mall.tiny.modules.business.model.BTower;
 import com.macro.mall.tiny.modules.business.service.BTowerService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
@@ -43,8 +41,7 @@ public class BTowerController {
     @RequestMapping(value = "/getFile/{id}", method = RequestMethod.GET)
     @ResponseBody
     public CommonResult<Map<String, List<BFile>>> getFile(@PathVariable Long id) {
-        AdminUserDetails userDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-        Map<String, List<BFile>> data = towerService.getFile(id, userDetails);
+        Map<String, List<BFile>> data = towerService.getFile(id);
         return CommonResult.success(data);
     }
 

+ 7 - 17
src/main/java/com/macro/mall/tiny/modules/business/controller/FileController.java

@@ -4,7 +4,6 @@ import com.google.common.collect.Lists;
 import com.macro.mall.tiny.common.api.CommonResult;
 import com.macro.mall.tiny.common.util.MyFileUtils;
 import com.macro.mall.tiny.config.UploadConfig;
-import com.macro.mall.tiny.domain.AdminUserDetails;
 import com.macro.mall.tiny.modules.business.dto.FileDownloadParam;
 import com.macro.mall.tiny.modules.business.dto.FileUploadParam;
 import com.macro.mall.tiny.modules.business.model.BDirectory;
@@ -23,13 +22,11 @@ import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;
-import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
-import javax.websocket.server.PathParam;
 import java.io.*;
 import java.net.URLEncoder;
 import java.nio.file.Files;
@@ -71,10 +68,9 @@ public class FileController {
         Integer chunk = fileUploadParam.getChunk();
         MultipartFile file = fileUploadParam.getFile();
         String charset = fileUploadParam.getCharset();
-        AdminUserDetails userDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
 
         if (chunks != null && chunks != 0) {
-            fileService.uploadWithBlock(name, lineName, provinceId, size, chunks, chunk, file, userDetails, charset);
+            fileService.uploadWithBlock(name, lineName, provinceId, size, chunks, chunk, file, charset);
         } else {
             fileService.upload(file);
         }
@@ -110,8 +106,7 @@ public class FileController {
     @ApiOperation("获取全部文件夹接口")
     @GetMapping("/getAllDirectory")
     public CommonResult<BDirectory> getDirectory() {
-        AdminUserDetails userDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-        final BDirectory directory = fileService.getRootDirectory(userDetails);
+        final BDirectory directory = fileService.getRootDirectory();
         return CommonResult.success(directory);
     }
 
@@ -126,24 +121,21 @@ public class FileController {
     @ApiOperation("获取文件夹下全部文件详细接口")
     @PostMapping("/getFileDetail")
     public CommonResult<List<BFileDetail>> getFileDetail(@RequestBody Map<String,String> params) {
-        AdminUserDetails userDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-        List<BFileDetail> fileDetailList = fileService.getFileDetailList(params.get("path"), userDetails);
+        List<BFileDetail> fileDetailList = fileService.getFileDetailList(params.get("path"));
         return CommonResult.success(fileDetailList);
     }
 
     @ApiOperation("获取文件夹下全部文件/文件夹")
     @PostMapping("/getFile")
     public CommonResult<List<BFile>> getFile(@RequestBody Map<String,String> params) {
-        AdminUserDetails userDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-        List<BFile> fileDetailList = fileService.getFileList(params.get("path"), userDetails);
+        List<BFile> fileDetailList = fileService.getFileList(params.get("path"));
         return CommonResult.success(fileDetailList);
     }
 
     @ApiOperation("文件下载接口")
     @PostMapping("/download")
     public void downLoad(HttpServletResponse response, @RequestBody Map<String,String> params) throws Exception {
-        AdminUserDetails userDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-        boolean access = AuthUtil.checkAccess(userDetails, AuthUtil.ACCESS);
+        boolean access = AuthUtil.checkAccess(AuthUtil.ACCESS);
         File file = new File(params.get("path"));
         if (file.getName().contains(String.valueOf(UploadConfig.AUTH_STR)) && !access) return;
         if (file.exists()) { //判断文件父目录是否存在
@@ -171,8 +163,7 @@ public class FileController {
     @ApiOperation("多文件压缩下载接口")
     @PostMapping("/multiFileZipDownload")
     public void multiFileZipDownload(HttpServletResponse response, @Validated @RequestBody FileDownloadParam fileDownloadParam) throws Exception {
-        AdminUserDetails userDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-        boolean access = AuthUtil.checkAccess(userDetails, AuthUtil.ACCESS);
+        boolean access = AuthUtil.checkAccess(AuthUtil.ACCESS);
         OutputStream outputStream = response.getOutputStream();
         ParallelScatterZipCreator scatterZipCreator = new ParallelScatterZipCreator();
         ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(outputStream);
@@ -218,8 +209,7 @@ public class FileController {
     @ApiOperation("文件删除接口")
     @PostMapping("/delete")
     public CommonResult<String> delete(@RequestBody Map<String,String> params) throws IOException {
-        AdminUserDetails userDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-        boolean deleteFile = fileService.deleteFile(params.get("path"), userDetails);
+        boolean deleteFile = fileService.deleteFile(params.get("path"));
         if (deleteFile) {
             return CommonResult.success("删除成功");
         } else {

+ 3 - 4
src/main/java/com/macro/mall/tiny/modules/business/service/BDirectoryCacheService.java

@@ -1,6 +1,5 @@
 package com.macro.mall.tiny.modules.business.service;
 
-import com.macro.mall.tiny.domain.AdminUserDetails;
 import com.macro.mall.tiny.modules.business.model.BDirectory;
 
 /**
@@ -10,11 +9,11 @@ import com.macro.mall.tiny.modules.business.model.BDirectory;
  */
 public interface BDirectoryCacheService {
 
-    BDirectory getDirectory(AdminUserDetails userDetails);
+    BDirectory getDirectory();
 
-    void setDirectory(AdminUserDetails userDetails, BDirectory directory);
+    void setDirectory(BDirectory directory);
 
-    void delDirectory(AdminUserDetails userDetails);
+    void delDirectoryAdmin();
 
     void delDirectory();
 

+ 2 - 3
src/main/java/com/macro/mall/tiny/modules/business/service/BLineService.java

@@ -1,9 +1,8 @@
 package com.macro.mall.tiny.modules.business.service;
 
-import com.macro.mall.tiny.domain.AdminUserDetails;
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.macro.mall.tiny.modules.business.model.BFile;
 import com.macro.mall.tiny.modules.business.model.BLine;
-import com.baomidou.mybatisplus.extension.service.IService;
 
 import java.util.List;
 
@@ -21,5 +20,5 @@ public interface BLineService extends IService<BLine> {
 
     List<BLine> findByKey(String key);
 
-    List<BFile> getFile(Long id, AdminUserDetails userDetails);
+    List<BFile> getFile(Long id);
 }

+ 0 - 2
src/main/java/com/macro/mall/tiny/modules/business/service/BProvinceCacheService.java

@@ -2,8 +2,6 @@ package com.macro.mall.tiny.modules.business.service;
 
 
 import com.macro.mall.tiny.modules.business.model.BProvince;
-import com.macro.mall.tiny.modules.ums.model.UmsAdmin;
-import com.macro.mall.tiny.modules.ums.model.UmsResource;
 
 import java.util.List;
 

+ 3 - 1
src/main/java/com/macro/mall/tiny/modules/business/service/BTowerService.java

@@ -20,7 +20,9 @@ public interface BTowerService extends IService<BTower> {
 
     long saveAndUpdate(List<BTower> towerList);
 
-    Map<String, List<BFile>> getFile(Long id, AdminUserDetails userDetails);
+    Map<String, List<BFile>> getFile(Long id);
+
+    void setHasFile(List<BTower> towerList);
 
     void setHasFile(List<BTower> towerList, AdminUserDetails userDetails);
 

+ 5 - 6
src/main/java/com/macro/mall/tiny/modules/business/service/FileService.java

@@ -1,6 +1,5 @@
 package com.macro.mall.tiny.modules.business.service;
 
-import com.macro.mall.tiny.domain.AdminUserDetails;
 import com.macro.mall.tiny.modules.business.model.BDirectory;
 import com.macro.mall.tiny.modules.business.model.BFile;
 import com.macro.mall.tiny.modules.business.model.BFileDetail;
@@ -18,14 +17,14 @@ public interface FileService {
 
     void upload(MultipartFile file) throws IOException;
 
-    void uploadWithBlock(String name, String lineName, Long provinceId, Long size, Integer chunks, Integer chunk, MultipartFile file, AdminUserDetails userDetails, String charset) throws IOException;
+    void uploadWithBlock(String name, String lineName, Long provinceId, Long size, Integer chunks, Integer chunk, MultipartFile file, String charset) throws IOException;
 
-    BDirectory getRootDirectory(AdminUserDetails userDetails);
+    BDirectory getRootDirectory();
 
-    List<BFileDetail> getFileDetailList(String path, AdminUserDetails userDetails);
+    List<BFileDetail> getFileDetailList(String path);
 
-    List<BFile> getFileList(String path, AdminUserDetails userDetails);
+    List<BFile> getFileList(String path);
 
-    boolean deleteFile(String path, AdminUserDetails userDetails) throws IOException;
+    boolean deleteFile(String path) throws IOException;
 
 }

+ 0 - 6
src/main/java/com/macro/mall/tiny/modules/business/service/impl/AsyncHandler.java

@@ -20,23 +20,17 @@ import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 import org.apache.commons.compress.utils.IOUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.io.*;
 import java.math.BigDecimal;
-import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
 import java.util.*;
 import java.util.stream.Collectors;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipInputStream;
 
 /**
  * @author gjs

+ 8 - 9
src/main/java/com/macro/mall/tiny/modules/business/service/impl/BDirectoryCacheServiceImpl.java

@@ -1,7 +1,6 @@
 package com.macro.mall.tiny.modules.business.service.impl;
 
 import com.macro.mall.tiny.common.service.RedisService;
-import com.macro.mall.tiny.domain.AdminUserDetails;
 import com.macro.mall.tiny.modules.business.model.BDirectory;
 import com.macro.mall.tiny.modules.business.service.BDirectoryCacheService;
 import com.macro.mall.tiny.security.util.AuthUtil;
@@ -25,24 +24,24 @@ public class BDirectoryCacheServiceImpl implements BDirectoryCacheService {
     @Value("${redis.key.directory}")
     private String REDIS_KEY_DIRECTORY;
 
-    private String getKey(AdminUserDetails userDetails) {
-        final boolean access = AuthUtil.checkAccess(userDetails, AuthUtil.ACCESS);
+    private String getKey() {
+        final boolean access = AuthUtil.checkAccess(AuthUtil.ACCESS);
         return REDIS_DATABASE + ":" + REDIS_KEY_DIRECTORY + ":" + (access ? 1 : 0);
     }
 
     @Override
-    public BDirectory getDirectory(AdminUserDetails userDetails) {
-        return (BDirectory) redisService.get(getKey(userDetails));
+    public BDirectory getDirectory() {
+        return (BDirectory) redisService.get(getKey());
     }
 
     @Override
-    public void setDirectory(AdminUserDetails userDetails, BDirectory directory) {
-        redisService.set(getKey(userDetails), directory, REDIS_EXPIRE);
+    public void setDirectory(BDirectory directory) {
+        redisService.set(getKey(), directory, REDIS_EXPIRE);
     }
 
     @Override
-    public void delDirectory(AdminUserDetails userDetails) {
-        redisService.del(getKey(userDetails));
+    public void delDirectoryAdmin() {
+        redisService.del(getKey());
     }
 
     @Override

+ 4 - 7
src/main/java/com/macro/mall/tiny/modules/business/service/impl/BLineServiceImpl.java

@@ -1,20 +1,18 @@
 package com.macro.mall.tiny.modules.business.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
-import com.google.common.collect.Lists;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.macro.mall.tiny.common.exception.Asserts;
 import com.macro.mall.tiny.common.util.MyFileUtils;
 import com.macro.mall.tiny.config.UploadConfig;
-import com.macro.mall.tiny.domain.AdminUserDetails;
+import com.macro.mall.tiny.modules.business.mapper.BLineMapper;
 import com.macro.mall.tiny.modules.business.mapper.BProvinceMapper;
 import com.macro.mall.tiny.modules.business.model.BFile;
 import com.macro.mall.tiny.modules.business.model.BLine;
-import com.macro.mall.tiny.modules.business.mapper.BLineMapper;
 import com.macro.mall.tiny.modules.business.model.BProvince;
 import com.macro.mall.tiny.modules.business.model.BTower;
 import com.macro.mall.tiny.modules.business.service.BLineCacheService;
 import com.macro.mall.tiny.modules.business.service.BLineService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.macro.mall.tiny.security.util.AuthUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -23,7 +21,6 @@ import org.springframework.stereotype.Service;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
-import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 /**
@@ -79,8 +76,8 @@ public class BLineServiceImpl extends ServiceImpl<BLineMapper, BLine> implements
     }
 
     @Override
-    public List<BFile> getFile(Long id, AdminUserDetails userDetails) {
-        boolean auth = AuthUtil.checkAccess(userDetails, AuthUtil.ACCESS);
+    public List<BFile> getFile(Long id) {
+        boolean auth = AuthUtil.checkAccess(AuthUtil.ACCESS);
         BLine line = lineMapper.selectById(id);
         if (line == null) Asserts.fail("该线路不存在,id:" + id);
         BProvince province = provinceMapper.selectById(line.getProvinceId());

+ 9 - 6
src/main/java/com/macro/mall/tiny/modules/business/service/impl/BTowerServiceImpl.java

@@ -18,9 +18,9 @@ import com.macro.mall.tiny.modules.business.service.BTowerService;
 import com.macro.mall.tiny.security.util.AuthUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.stereotype.Service;
 
-import java.io.File;
 import java.io.FilenameFilter;
 import java.util.HashMap;
 import java.util.List;
@@ -52,11 +52,8 @@ public class BTowerServiceImpl extends ServiceImpl<BTowerMapper, BTower> impleme
     }
 
     @Override
-    public Map<String, List<BFile>> getFile(Long id, AdminUserDetails userDetails) {
-        if (userDetails == null) {
-            Asserts.fail("查询失败,未获取到当前用户");
-        }
-        boolean auth = AuthUtil.checkAccess(userDetails, AuthUtil.ACCESS);
+    public Map<String, List<BFile>> getFile(Long id) {
+        boolean auth = AuthUtil.checkAccess(AuthUtil.ACCESS);
 
         HashMap<String, List<BFile>> resultMap = new HashMap<>();
 
@@ -109,6 +106,12 @@ public class BTowerServiceImpl extends ServiceImpl<BTowerMapper, BTower> impleme
     }
 
     @Override
+    public void setHasFile(List<BTower> towerList) {
+        AdminUserDetails userDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+        setHasFile(towerList, userDetails);
+    }
+
+    @Override
     public void setHasFile(List<BTower> towerList, AdminUserDetails userDetails) {
         if (towerList == null || towerList.size() == 0) {
             return;

+ 0 - 2
src/main/java/com/macro/mall/tiny/modules/business/service/impl/CommonServiceImpl.java

@@ -1,8 +1,6 @@
 package com.macro.mall.tiny.modules.business.service.impl;
 
-import cn.hutool.json.JSON;
 import cn.hutool.json.JSONObject;
-import cn.hutool.json.JSONUtil;
 import com.macro.mall.tiny.modules.business.model.Weather;
 import com.macro.mall.tiny.modules.business.service.CommonService;
 import lombok.extern.slf4j.Slf4j;

+ 14 - 13
src/main/java/com/macro/mall/tiny/modules/business/service/impl/FileServiceImpl.java

@@ -17,6 +17,7 @@ import com.macro.mall.tiny.security.util.AuthUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -80,7 +81,6 @@ public class FileServiceImpl implements FileService {
                                 Integer chunks,
                                 Integer chunk,
                                 MultipartFile file,
-                                AdminUserDetails userDetails,
                                 String charset) throws IOException {
         putChunkMap(name, chunks);
         String target = UploadConfig.tempPath + name;
@@ -88,38 +88,39 @@ public class FileServiceImpl implements FileService {
         addChunk(name, chunk);
         if (isUploaded(name)) {
             removeKey(name);
+            AdminUserDetails userDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
             asyncHandler.handleDocument(provinceId, target, lineName, userDetails, charset);
         }
     }
 
     @Override
-    public BDirectory getRootDirectory(AdminUserDetails userDetails) {
-        BDirectory directory = directoryCacheService.getDirectory(userDetails);
+    public BDirectory getRootDirectory() {
+        BDirectory directory = directoryCacheService.getDirectory();
         if (directory != null) {
             return directory;
         }
-        directory = MyFileUtils.getRootDirectory(userDetails);
+        directory = MyFileUtils.getRootDirectory();
         if (directory != null) {
-            directoryCacheService.setDirectory(userDetails, directory);
+            directoryCacheService.setDirectory(directory);
         } else {
-            directoryCacheService.setDirectory(userDetails, new BDirectory());
+            directoryCacheService.setDirectory(new BDirectory());
         }
         return directory;
     }
 
     @Override
-    public List<BFileDetail> getFileDetailList(String path, AdminUserDetails userDetails) {
-        return MyFileUtils.getFileDetailList(path, userDetails);
+    public List<BFileDetail> getFileDetailList(String path) {
+        return MyFileUtils.getFileDetailList(path);
     }
 
     @Override
-    public List<BFile> getFileList(String path, AdminUserDetails userDetails) {
-        return MyFileUtils.getSonFiles(path, userDetails);
+    public List<BFile> getFileList(String path) {
+        return MyFileUtils.getSonFiles(path);
     }
 
     @Override
-    public boolean deleteFile(String path, AdminUserDetails userDetails) throws IOException {
-        boolean delete = AuthUtil.checkAccess(userDetails, AuthUtil.DELETE);
+    public boolean deleteFile(String path) throws IOException {
+        boolean delete = AuthUtil.checkAccess(AuthUtil.DELETE);
         Path filePath = Paths.get(path);
         if (!delete) {
             Asserts.fail("您没有删除权限");
@@ -169,7 +170,7 @@ public class FileServiceImpl implements FileService {
             towerMapper.delete(towerQueryWrapper);
         } else {
             List<BTower> towerList = towerMapper.selectList(towerQueryWrapper);
-            towerService.setHasFile(towerList, userDetails);
+            towerService.setHasFile(towerList);
         }
 
         // 后续清楚缓存处理

+ 6 - 0
src/main/java/com/macro/mall/tiny/security/util/AuthUtil.java

@@ -1,6 +1,7 @@
 package com.macro.mall.tiny.security.util;
 
 import com.macro.mall.tiny.domain.AdminUserDetails;
+import org.springframework.security.core.context.SecurityContextHolder;
 
 /**
  * @author gjs
@@ -21,4 +22,9 @@ public class AuthUtil {
         }
         return false;
     }
+
+    public static boolean checkAccess(String resource) {
+        AdminUserDetails userDetails = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+        return checkAccess(userDetails, resource);
+    }
 }

+ 1 - 1
src/main/resources/application-dev.yml

@@ -2,7 +2,7 @@ spring:
   datasource:
     url: jdbc:mysql://localhost:3306/power_system?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
     username: root
-    password: abc45628
+    password: root
   redis:
     host: localhost # Redis服务器地址
     database: 0 # Redis数据库索引(默认为0)