Procházet zdrojové kódy

feat-[厦门馆二期]:commonController添加删除文件接口,注释admin修改信息权限

seeseele před 4 měsíci
rodič
revize
a609caf4c7

+ 31 - 4
src/main/java/com/ruoyi/project/common/CommonController.java

@@ -1,5 +1,6 @@
 package com.ruoyi.project.common;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.file.FileUploadUtils;
@@ -12,14 +13,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -97,6 +96,34 @@ public class CommonController
         }
     }
 
+    /**
+     * 通用删除请求(单个)
+     */
+    @PostMapping("/delete")
+    public AjaxResult deleteFile(@RequestBody JSONObject jsonObject) throws Exception
+    {
+        String filePath = jsonObject.getString("filePath");
+
+        String ruoyiPath = RuoYiConfig.getUploadPath();
+
+        //由于在RuoYiConfig.getUploadPath()中带有upload导致文件搜索失败,所以去除
+        String keyword = "/upload";
+        int endIndex = ruoyiPath.indexOf(keyword);
+        if (endIndex != -1) {
+            ruoyiPath = ruoyiPath.substring(0, (ruoyiPath.length()-7));
+        }
+
+        String deletaPath = ruoyiPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
+
+        File file = new File(deletaPath);
+        if (file.isFile() && file.exists()) {
+            if (!file.delete()){
+                return AjaxResult.error();
+            }
+        }
+        return AjaxResult.success();
+    }
+
     @Anonymous
     @PostMapping("/uploadWithoutToken")
     public AjaxResult uploadWithoutToken(MultipartFile file) throws Exception

+ 4 - 4
src/main/java/com/ruoyi/project/system/service/impl/SysRoleServiceImpl.java

@@ -183,10 +183,10 @@ public class SysRoleServiceImpl implements ISysRoleService
     @Override
     public void checkRoleAllowed(SysRole role)
     {
-        if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin())
-        {
-            throw new ServiceException("不允许操作超级管理员角色");
-        }
+//        if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin())
+//        {
+//            throw new ServiceException("不允许操作超级管理员角色");
+//        }
     }
 
     /**

+ 4 - 4
src/main/java/com/ruoyi/project/system/service/impl/SysUserServiceImpl.java

@@ -222,10 +222,10 @@ public class SysUserServiceImpl implements ISysUserService
     @Override
     public void checkUserAllowed(SysUser user)
     {
-        if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin())
-        {
-            throw new ServiceException("不允许操作超级管理员用户");
-        }
+//        if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin())
+//        {
+//            throw new ServiceException("不允许操作超级管理员用户");
+//        }
     }
 
     /**