Explorar o código

文件上传接口

459242451@qq.com %!s(int64=3) %!d(string=hai) anos
pai
achega
714e59bd64

+ 113 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java

@@ -0,0 +1,113 @@
+package com.ruoyi.web.controller.common;
+
+import com.ruoyi.common.config.RuoYiConfig;
+import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.file.FileUploadUtils;
+import com.ruoyi.common.utils.file.FileUtils;
+import com.ruoyi.framework.config.ServerConfig;
+import lombok.SneakyThrows;
+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.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 通用请求处理
+ *
+ * @author ruoyi
+ */
+@RestController
+public class CommonController {
+
+    @Autowired
+    private ServerConfig serverConfig;
+
+    /**
+     * 通用下载请求
+     *
+     * @param fileName 文件名称
+     * @param delete 是否删除
+     *//*
+    @GetMapping("/common/download")
+    public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
+    {
+        try
+        {
+            if (!FileUtils.checkAllowDownload(fileName))
+            {
+                throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
+            }
+            String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
+            String filePath = RuoYiConfig.getDownloadPath() + fileName;
+
+            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+            FileUtils.setAttachmentResponseHeader(response, realFileName);
+            FileUtils.writeBytes(filePath, response.getOutputStream());
+            if (delete)
+            {
+                FileUtils.deleteFile(filePath);
+            }
+        }
+        catch (Exception e)
+        {
+            log.error("下载文件失败", e);
+        }
+    }*/
+
+    /**
+     * 通用上传请求
+     */
+    @SneakyThrows
+    @PostMapping("/common/upload")
+    public AjaxResult<Map<String, Object>> uploadFile(MultipartFile file) {
+        // 上传文件路径
+        String filePath = RuoYiConfig.getUploadPath();
+        // 上传并返回新文件名称
+        String fileName = FileUploadUtils.upload(filePath, file);
+        String url = serverConfig.getUrl() + fileName;
+        Map<String, Object> result = new HashMap<>();
+        result.put("fileName", fileName.substring(fileName.lastIndexOf("/") + 1));
+        result.put("url", fileName);
+        return AjaxResult.success(result);
+    }
+
+    /**
+     * 本地资源通用下载
+     */
+    /*@GetMapping("/common/download/resource")
+    public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
+            throws Exception
+    {
+        try
+        {
+            if (!FileUtils.checkAllowDownload(resource))
+            {
+                throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
+            }
+            // 本地资源路径
+            String localPath = RuoYiConfig.getProfile();
+            // 数据库资源地址
+            String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
+            // 下载名称
+            String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
+            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+            FileUtils.setAttachmentResponseHeader(response, downloadName);
+            FileUtils.writeBytes(downloadPath, response.getOutputStream());
+        }
+        catch (Exception e)
+        {
+            log.error("下载文件失败", e);
+        }
+    }*/
+}

+ 6 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhdd/DutyEmpController.java

@@ -48,7 +48,7 @@ public class DutyEmpController extends BaseController {
      * 查询值班排班信息列表
      */
     @ApiOperation("查询值班排班信息列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:dutyEmp:list')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:dutyEmp:list')")
     @GetMapping("/list")
     public AjaxResult<List<DutyEmpVo>> list(@Validated(QueryGroup.class) DutyEmpBo bo) {
         return AjaxResult.success(iDutyEmpService.listVo(Wrappers.<DutyEmp>lambdaQuery().orderByAsc(DutyEmp::getPeriod)));
@@ -58,7 +58,7 @@ public class DutyEmpController extends BaseController {
      * 导出值班排班信息列表
      */
     @ApiOperation("导出值班排班信息列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:dutyEmp:export')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:dutyEmp:export')")
     @Log(title = "值班排班信息", businessType = BusinessType.EXPORT)
     @GetMapping("/export")
     public void export(@Validated DutyEmpBo bo, HttpServletResponse response) {
@@ -70,7 +70,7 @@ public class DutyEmpController extends BaseController {
      * 获取值班排班信息详细信息
      */
     @ApiOperation("获取值班排班信息详细信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:dutyEmp:query')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:dutyEmp:query')")
     @GetMapping("/{id}")
     public AjaxResult<DutyEmpVo> getInfo(@NotNull(message = "主键不能为空")
                                                   @PathVariable("id") Long id) {
@@ -81,7 +81,7 @@ public class DutyEmpController extends BaseController {
      * 新增值班排班信息
      */
     @ApiOperation("新增值班排班信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:dutyEmp:add')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:dutyEmp:add')")
     @Log(title = "值班排班信息", businessType = BusinessType.INSERT)
     @RepeatSubmit()
     @PostMapping()
@@ -93,7 +93,7 @@ public class DutyEmpController extends BaseController {
      * 修改值班排班信息
      */
     @ApiOperation("修改值班排班信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:dutyEmp:edit')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:dutyEmp:edit')")
     @Log(title = "值班排班信息", businessType = BusinessType.UPDATE)
     @RepeatSubmit()
     @PutMapping()
@@ -105,7 +105,7 @@ public class DutyEmpController extends BaseController {
      * 删除值班排班信息
      */
     @ApiOperation("删除值班排班信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:dutyEmp:remove')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:dutyEmp:remove')")
     @Log(title = "值班排班信息" , businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")

+ 6 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhdd/DutyReportController.java

@@ -46,7 +46,7 @@ public class DutyReportController extends BaseController {
      * 查询值班报告信息列表
      */
     @ApiOperation("查询值班报告信息列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:list')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:list')")
     @GetMapping("/list")
     public TableDataInfo<DutyReportVo> list(@Validated(QueryGroup.class) DutyReportBo bo) {
         return iDutyReportService.queryPageList(bo);
@@ -56,7 +56,7 @@ public class DutyReportController extends BaseController {
      * 导出值班报告信息列表
      */
     @ApiOperation("导出值班报告信息列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:export')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:export')")
     @Log(title = "值班报告信息", businessType = BusinessType.EXPORT)
     @GetMapping("/export")
     public void export(@Validated DutyReportBo bo, HttpServletResponse response) {
@@ -68,7 +68,7 @@ public class DutyReportController extends BaseController {
      * 获取值班报告信息详细信息
      */
     @ApiOperation("获取值班报告信息详细信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:query')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:query')")
     @GetMapping("/{id}")
     public AjaxResult<DutyReportVo> getInfo(@NotNull(message = "主键不能为空")
                                                   @PathVariable("id") Long id) {
@@ -79,7 +79,7 @@ public class DutyReportController extends BaseController {
      * 新增值班报告信息
      */
     @ApiOperation("新增值班报告信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:add')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:add')")
     @Log(title = "值班报告信息", businessType = BusinessType.INSERT)
     @RepeatSubmit()
     @PostMapping()
@@ -91,7 +91,7 @@ public class DutyReportController extends BaseController {
      * 修改值班报告信息
      */
     @ApiOperation("修改值班报告信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:edit')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:edit')")
     @Log(title = "值班报告信息", businessType = BusinessType.UPDATE)
     @RepeatSubmit()
     @PutMapping()
@@ -103,7 +103,7 @@ public class DutyReportController extends BaseController {
      * 删除值班报告信息
      */
     @ApiOperation("删除值班报告信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:remove')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:dutyReport:remove')")
     @Log(title = "值班报告信息" , businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")

+ 6 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhdd/IncidentController.java

@@ -55,7 +55,7 @@ public class IncidentController extends BaseController {
      * 查询事件基础列表
      */
     @ApiOperation("查询事件基础列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:incident:list')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:incident:list')")
     @GetMapping("/list")
     public TableDataInfo<IncidentVo> list(@Validated(QueryGroup.class) IncidentBo bo) {
         return iIncidentService.queryPageList(bo);
@@ -65,7 +65,7 @@ public class IncidentController extends BaseController {
      * 导出事件基础列表
      */
     @ApiOperation("导出事件基础列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:incident:export')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:incident:export')")
     @Log(title = "事件基础", businessType = BusinessType.EXPORT)
     @GetMapping("/export")
     public void export(@Validated IncidentBo bo, HttpServletResponse response) {
@@ -77,7 +77,7 @@ public class IncidentController extends BaseController {
      * 获取事件基础详细信息
      */
     @ApiOperation("获取事件基础详细信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:incident:query')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:incident:query')")
     @GetMapping("/{id}")
     public AjaxResult<Map<String, Object>> getInfo(@NotNull(message = "主键不能为空")
                                           @PathVariable("id") Long id) {
@@ -92,7 +92,7 @@ public class IncidentController extends BaseController {
      * 新增事件基础
      */
     @ApiOperation("新增事件基础")
-    @PreAuthorize("@ss.hasPermi('zhdd:incident:add')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:incident:add')")
     @Log(title = "事件基础", businessType = BusinessType.INSERT)
     @RepeatSubmit()
     @PostMapping()
@@ -106,7 +106,7 @@ public class IncidentController extends BaseController {
      * 修改事件基础
      */
     @ApiOperation("修改事件基础")
-    @PreAuthorize("@ss.hasPermi('zhdd:incident:edit')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:incident:edit')")
     @Log(title = "事件基础", businessType = BusinessType.UPDATE)
     @RepeatSubmit()
     @PutMapping()
@@ -118,7 +118,7 @@ public class IncidentController extends BaseController {
      * 删除事件基础
      */
     @ApiOperation("删除事件基础")
-    @PreAuthorize("@ss.hasPermi('zhdd:incident:remove')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:incident:remove')")
     @Log(title = "事件基础", businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")

+ 6 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhdd/IncidentProcessController.java

@@ -46,7 +46,7 @@ public class IncidentProcessController extends BaseController {
      * 查询事件处置流程列表
      */
     @ApiOperation("查询事件处置流程列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:list')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:list')")
     @GetMapping("/list")
     public TableDataInfo<IncidentProcessVo> list(@Validated(QueryGroup.class) IncidentProcessBo bo) {
         return iIncidentProcessService.queryPageList(bo);
@@ -56,7 +56,7 @@ public class IncidentProcessController extends BaseController {
      * 导出事件处置流程列表
      */
     @ApiOperation("导出事件处置流程列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:export')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:export')")
     @Log(title = "事件处置流程", businessType = BusinessType.EXPORT)
     @GetMapping("/export")
     public void export(@Validated IncidentProcessBo bo, HttpServletResponse response) {
@@ -68,7 +68,7 @@ public class IncidentProcessController extends BaseController {
      * 获取事件处置流程详细信息
      */
     @ApiOperation("获取事件处置流程详细信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:query')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:query')")
     @GetMapping("/{id}")
     public AjaxResult<IncidentProcessVo> getInfo(@NotNull(message = "主键不能为空")
                                                   @PathVariable("id") Long id) {
@@ -79,7 +79,7 @@ public class IncidentProcessController extends BaseController {
      * 新增事件处置流程
      */
     @ApiOperation("新增事件处置流程")
-    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:add')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:add')")
     @Log(title = "事件处置流程", businessType = BusinessType.INSERT)
     @RepeatSubmit()
     @PostMapping()
@@ -91,7 +91,7 @@ public class IncidentProcessController extends BaseController {
      * 修改事件处置流程
      */
     @ApiOperation("修改事件处置流程")
-    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:edit')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:edit')")
     @Log(title = "事件处置流程", businessType = BusinessType.UPDATE)
     @RepeatSubmit()
     @PutMapping()
@@ -103,7 +103,7 @@ public class IncidentProcessController extends BaseController {
      * 删除事件处置流程
      */
     @ApiOperation("删除事件处置流程")
-    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:remove')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:incidentProcess:remove')")
     @Log(title = "事件处置流程" , businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")

+ 5 - 5
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhdd/PlanController.java

@@ -46,7 +46,7 @@ public class PlanController extends BaseController {
      * 查询预案管理列表
      */
     @ApiOperation("查询预案管理列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:plan:list')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:plan:list')")
     @GetMapping("/list")
     public TableDataInfo<PlanVo> list(@Validated(QueryGroup.class) PlanBo bo) {
         return iPlanService.queryPageList(bo);
@@ -56,7 +56,7 @@ public class PlanController extends BaseController {
      * 获取预案管理详细信息
      */
     @ApiOperation("获取预案管理详细信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:plan:query')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:plan:query')")
     @GetMapping("/{id}")
     public AjaxResult<PlanVo> getInfo(@NotNull(message = "主键不能为空")
                                                   @PathVariable("id") Long id) {
@@ -67,7 +67,7 @@ public class PlanController extends BaseController {
      * 新增预案管理
      */
     @ApiOperation("新增预案管理")
-    @PreAuthorize("@ss.hasPermi('zhdd:plan:add')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:plan:add')")
     @Log(title = "预案管理", businessType = BusinessType.INSERT)
     @RepeatSubmit()
     @PostMapping()
@@ -79,7 +79,7 @@ public class PlanController extends BaseController {
      * 修改预案管理
      */
     @ApiOperation("修改预案管理")
-    @PreAuthorize("@ss.hasPermi('zhdd:plan:edit')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:plan:edit')")
     @Log(title = "预案管理", businessType = BusinessType.UPDATE)
     @RepeatSubmit()
     @PutMapping()
@@ -91,7 +91,7 @@ public class PlanController extends BaseController {
      * 删除预案管理
      */
     @ApiOperation("删除预案管理")
-    @PreAuthorize("@ss.hasPermi('zhdd:plan:remove')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:plan:remove')")
     @Log(title = "预案管理" , businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")

+ 6 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhdd/PlanTaskController.java

@@ -46,7 +46,7 @@ public class PlanTaskController extends BaseController {
      * 查询预案任务管理列表
      */
     @ApiOperation("查询预案任务管理列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:planTask:list')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:planTask:list')")
     @GetMapping("/list")
     public AjaxResult<List<PlanTaskVo>> list(@Validated(QueryGroup.class) PlanTaskBo bo) {
         return AjaxResult.success(iPlanTaskService.queryList(bo));
@@ -56,7 +56,7 @@ public class PlanTaskController extends BaseController {
      * 导出预案任务管理列表
      */
     @ApiOperation("导出预案任务管理列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:planTask:export')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:planTask:export')")
     @Log(title = "预案任务管理", businessType = BusinessType.EXPORT)
     @GetMapping("/export")
     public void export(@Validated PlanTaskBo bo, HttpServletResponse response) {
@@ -68,7 +68,7 @@ public class PlanTaskController extends BaseController {
      * 获取预案任务管理详细信息
      */
     @ApiOperation("获取预案任务管理详细信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:planTask:query')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:planTask:query')")
     @GetMapping("/{id}")
     public AjaxResult<PlanTaskVo> getInfo(@NotNull(message = "主键不能为空")
                                                   @PathVariable("id") Long id) {
@@ -79,7 +79,7 @@ public class PlanTaskController extends BaseController {
      * 新增预案任务管理
      */
     @ApiOperation("新增预案任务管理")
-    @PreAuthorize("@ss.hasPermi('zhdd:planTask:add')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:planTask:add')")
     @Log(title = "预案任务管理", businessType = BusinessType.INSERT)
     @RepeatSubmit()
     @PostMapping()
@@ -91,7 +91,7 @@ public class PlanTaskController extends BaseController {
      * 修改预案任务管理
      */
     @ApiOperation("修改预案任务管理")
-    @PreAuthorize("@ss.hasPermi('zhdd:planTask:edit')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:planTask:edit')")
     @Log(title = "预案任务管理", businessType = BusinessType.UPDATE)
     @RepeatSubmit()
     @PutMapping()
@@ -103,7 +103,7 @@ public class PlanTaskController extends BaseController {
      * 删除预案任务管理
      */
     @ApiOperation("删除预案任务管理")
-    @PreAuthorize("@ss.hasPermi('zhdd:planTask:remove')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:planTask:remove')")
     @Log(title = "预案任务管理" , businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")

+ 6 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhdd/ResourceController.java

@@ -46,7 +46,7 @@ public class ResourceController extends BaseController {
      * 查询应急资源列表
      */
     @ApiOperation("查询应急资源列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:resource:list')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:resource:list')")
     @GetMapping("/list")
     public TableDataInfo<ResourceVo> list(@Validated(QueryGroup.class) ResourceBo bo) {
         return iResourceService.queryPageList(bo);
@@ -56,7 +56,7 @@ public class ResourceController extends BaseController {
      * 导出应急资源列表
      */
     @ApiOperation("导出应急资源列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:resource:export')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:resource:export')")
     @Log(title = "应急资源", businessType = BusinessType.EXPORT)
     @GetMapping("/export")
     public void export(@Validated ResourceBo bo, HttpServletResponse response) {
@@ -68,7 +68,7 @@ public class ResourceController extends BaseController {
      * 获取应急资源详细信息
      */
     @ApiOperation("获取应急资源详细信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:resource:query')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:resource:query')")
     @GetMapping("/{id}")
     public AjaxResult<ResourceVo> getInfo(@NotNull(message = "主键不能为空")
                                                   @PathVariable("id") Long id) {
@@ -79,7 +79,7 @@ public class ResourceController extends BaseController {
      * 新增应急资源
      */
     @ApiOperation("新增应急资源")
-    @PreAuthorize("@ss.hasPermi('zhdd:resource:add')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:resource:add')")
     @Log(title = "应急资源", businessType = BusinessType.INSERT)
     @RepeatSubmit()
     @PostMapping()
@@ -91,7 +91,7 @@ public class ResourceController extends BaseController {
      * 修改应急资源
      */
     @ApiOperation("修改应急资源")
-    @PreAuthorize("@ss.hasPermi('zhdd:resource:edit')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:resource:edit')")
     @Log(title = "应急资源", businessType = BusinessType.UPDATE)
     @RepeatSubmit()
     @PutMapping()
@@ -103,7 +103,7 @@ public class ResourceController extends BaseController {
      * 删除应急资源
      */
     @ApiOperation("删除应急资源")
-    @PreAuthorize("@ss.hasPermi('zhdd:resource:remove')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:resource:remove')")
     @Log(title = "应急资源" , businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")

+ 6 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhdd/ResourceDetailController.java

@@ -46,7 +46,7 @@ public class ResourceDetailController extends BaseController {
      * 查询应急资源明细列表
      */
     @ApiOperation("查询应急资源明细列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:list')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:list')")
     @GetMapping("/list")
     public TableDataInfo<ResourceDetailVo> list(@Validated(QueryGroup.class) ResourceDetailBo bo) {
         return iResourceDetailService.queryPageList(bo);
@@ -56,7 +56,7 @@ public class ResourceDetailController extends BaseController {
      * 导出应急资源明细列表
      */
     @ApiOperation("导出应急资源明细列表")
-    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:export')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:export')")
     @Log(title = "应急资源明细", businessType = BusinessType.EXPORT)
     @GetMapping("/export")
     public void export(@Validated ResourceDetailBo bo, HttpServletResponse response) {
@@ -68,7 +68,7 @@ public class ResourceDetailController extends BaseController {
      * 获取应急资源明细详细信息
      */
     @ApiOperation("获取应急资源明细详细信息")
-    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:query')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:query')")
     @GetMapping("/{id}")
     public AjaxResult<ResourceDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                                   @PathVariable("id") Long id) {
@@ -79,7 +79,7 @@ public class ResourceDetailController extends BaseController {
      * 新增应急资源明细
      */
     @ApiOperation("新增应急资源明细")
-    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:add')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:add')")
     @Log(title = "应急资源明细", businessType = BusinessType.INSERT)
     @RepeatSubmit()
     @PostMapping()
@@ -91,7 +91,7 @@ public class ResourceDetailController extends BaseController {
      * 修改应急资源明细
      */
     @ApiOperation("修改应急资源明细")
-    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:edit')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:edit')")
     @Log(title = "应急资源明细", businessType = BusinessType.UPDATE)
     @RepeatSubmit()
     @PutMapping()
@@ -103,7 +103,7 @@ public class ResourceDetailController extends BaseController {
      * 删除应急资源明细
      */
     @ApiOperation("删除应急资源明细")
-    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:remove')")
+//    @PreAuthorize("@ss.hasPermi('zhdd:resourceDetail:remove')")
     @Log(title = "应急资源明细" , businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")

+ 21 - 0
ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java

@@ -32,13 +32,34 @@ public class RuoYiConfig
     /** 实例演示开关 */
     private boolean demoEnabled;
 
+    /** 上传路径 */
+    private static String profile;
+
     /** 获取地址开关 */
     @Getter
     private static boolean addressEnabled;
 
+    public static String getProfile()
+    {
+        return profile;
+    }
+
+    public void setProfile(String profile)
+    {
+        RuoYiConfig.profile = profile;
+    }
+
     public void setAddressEnabled(boolean addressEnabled)
     {
         RuoYiConfig.addressEnabled = addressEnabled;
     }
 
+    /**
+     * 获取上传路径
+     */
+    public static String getUploadPath()
+    {
+        return getProfile() + "/upload";
+    }
+
 }

+ 5 - 0
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java

@@ -134,6 +134,11 @@ public class Constants
      */
     public static final String SYS_DICT_KEY = "sys_dict:";
 
+    /**
+     * 资源映射路径 前缀
+     */
+    public static final String RESOURCE_PREFIX = "/profile";
+
 	/**
 	 * RMI 远程方法调用
 	 */

+ 205 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java

@@ -0,0 +1,205 @@
+package com.ruoyi.common.utils.file;
+
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.RandomUtil;
+import com.ruoyi.common.config.RuoYiConfig;
+import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.exception.file.FileNameLengthLimitExceededException;
+import com.ruoyi.common.exception.file.FileSizeLimitExceededException;
+import com.ruoyi.common.exception.file.InvalidExtensionException;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.StringUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.springframework.cloud.commons.util.IdUtils;
+import org.springframework.util.FileCopyUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * 文件上传工具类
+ *
+ * @author ruoyi
+ */
+public class FileUploadUtils {
+    /**
+     * 默认大小 50M
+     */
+    public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024;
+
+    /**
+     * 默认的文件名最大长度 100
+     */
+    public static final int DEFAULT_FILE_NAME_LENGTH = 100;
+
+    /**
+     * 默认上传的地址
+     */
+    private static String defaultBaseDir = RuoYiConfig.getProfile();
+
+    public static void setDefaultBaseDir(String defaultBaseDir) {
+        FileUploadUtils.defaultBaseDir = defaultBaseDir;
+    }
+
+    public static String getDefaultBaseDir() {
+        return defaultBaseDir;
+    }
+
+    /**
+     * 以默认配置进行文件上传
+     *
+     * @param file 上传的文件
+     * @return 文件名称
+     * @throws Exception
+     */
+    public static final String upload(MultipartFile file) throws IOException {
+        try {
+            return upload(getDefaultBaseDir(), file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
+        } catch (Exception e) {
+            throw new IOException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * 根据文件路径上传
+     *
+     * @param baseDir 相对应用的基目录
+     * @param file    上传的文件
+     * @return 文件名称
+     * @throws IOException
+     */
+    public static final String upload(String baseDir, MultipartFile file) throws IOException {
+        try {
+            return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
+        } catch (Exception e) {
+            throw new IOException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * 文件上传
+     *
+     * @param baseDir          相对应用的基目录
+     * @param file             上传的文件
+     * @param allowedExtension 上传文件类型
+     * @return 返回上传成功的文件名
+     * @throws FileSizeLimitExceededException       如果超出最大大小
+     * @throws FileNameLengthLimitExceededException 文件名太长
+     * @throws IOException                          比如读写文件出错时
+     * @throws InvalidExtensionException            文件校验异常
+     */
+    public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
+        throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
+        InvalidExtensionException {
+        int fileNamelength = file.getOriginalFilename().length();
+        if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) {
+            throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
+        }
+
+        assertAllowed(file, allowedExtension);
+
+        String fileName = extractFilename(file);
+
+        File desc = getAbsoluteFile(baseDir, fileName);
+        file.transferTo(desc);
+        String pathFileName = getPathFileName(baseDir, fileName);
+        return pathFileName;
+    }
+
+    /**
+     * 编码文件名
+     */
+    public static final String extractFilename(MultipartFile file) {
+        String fileName = file.getOriginalFilename();
+        String extension = getExtension(file);
+        fileName = DateUtils.datePath() + "/" + FileUtil.getPrefix(fileName) + "_" + RandomUtil.randomNumbers(4) + "." + extension;
+        return fileName;
+    }
+
+    private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException {
+        File desc = new File(uploadDir + File.separator + fileName);
+
+        if (!desc.exists()) {
+            if (!desc.getParentFile().exists()) {
+                desc.getParentFile().mkdirs();
+            }
+        }
+        return desc;
+    }
+
+    private static final String getPathFileName(String uploadDir, String fileName) throws IOException {
+        int dirLastIndex = RuoYiConfig.getProfile().length() + 1;
+        String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
+        String pathFileName = Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
+        return pathFileName;
+    }
+
+    /**
+     * 文件大小校验
+     *
+     * @param file 上传的文件
+     * @return
+     * @throws FileSizeLimitExceededException 如果超出最大大小
+     * @throws InvalidExtensionException
+     */
+    public static final void assertAllowed(MultipartFile file, String[] allowedExtension)
+        throws FileSizeLimitExceededException, InvalidExtensionException {
+        long size = file.getSize();
+        if (DEFAULT_MAX_SIZE != -1 && size > DEFAULT_MAX_SIZE) {
+            throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
+        }
+
+        String fileName = file.getOriginalFilename();
+        String extension = getExtension(file);
+        if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension)) {
+            if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION) {
+                throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension,
+                    fileName);
+            } else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION) {
+                throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension,
+                    fileName);
+            } else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION) {
+                throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension,
+                    fileName);
+            } else if (allowedExtension == MimeTypeUtils.VIDEO_EXTENSION) {
+                throw new InvalidExtensionException.InvalidVideoExtensionException(allowedExtension, extension,
+                    fileName);
+            } else {
+                throw new InvalidExtensionException(allowedExtension, extension, fileName);
+            }
+        }
+
+    }
+
+    /**
+     * 判断MIME类型是否是允许的MIME类型
+     *
+     * @param extension
+     * @param allowedExtension
+     * @return
+     */
+    public static final boolean isAllowedExtension(String extension, String[] allowedExtension) {
+        for (String str : allowedExtension) {
+            if (str.equalsIgnoreCase(extension)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 获取文件名的后缀
+     *
+     * @param file 表单文件
+     * @return 后缀名
+     */
+    public static final String getExtension(MultipartFile file) {
+        String extension = FilenameUtils.getExtension(file.getOriginalFilename());
+        if (StringUtils.isEmpty(extension)) {
+            extension = MimeTypeUtils.getExtension(file.getContentType());
+        }
+        return extension;
+    }
+}

+ 59 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/MimeTypeUtils.java

@@ -0,0 +1,59 @@
+package com.ruoyi.common.utils.file;
+
+/**
+ * 媒体类型工具类
+ * 
+ * @author ruoyi
+ */
+public class MimeTypeUtils
+{
+    public static final String IMAGE_PNG = "image/png";
+
+    public static final String IMAGE_JPG = "image/jpg";
+
+    public static final String IMAGE_JPEG = "image/jpeg";
+
+    public static final String IMAGE_BMP = "image/bmp";
+
+    public static final String IMAGE_GIF = "image/gif";
+    
+    public static final String[] IMAGE_EXTENSION = { "bmp", "gif", "jpg", "jpeg", "png" };
+
+    public static final String[] FLASH_EXTENSION = { "swf", "flv" };
+
+    public static final String[] MEDIA_EXTENSION = { "swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg",
+            "asf", "rm", "rmvb" };
+
+    public static final String[] VIDEO_EXTENSION = { "mp4", "avi", "rmvb" };
+
+    public static final String[] DEFAULT_ALLOWED_EXTENSION = {
+            // 图片
+            "bmp", "gif", "jpg", "jpeg", "png",
+            // word excel powerpoint
+            "doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt",
+            // 压缩文件
+            "rar", "zip", "gz", "bz2",
+            // 视频格式
+            "mp4", "avi", "rmvb",
+            // pdf
+            "pdf" };
+
+    public static String getExtension(String prefix)
+    {
+        switch (prefix)
+        {
+            case IMAGE_PNG:
+                return "png";
+            case IMAGE_JPG:
+                return "jpg";
+            case IMAGE_JPEG:
+                return "jpeg";
+            case IMAGE_BMP:
+                return "bmp";
+            case IMAGE_GIF:
+                return "gif";
+            default:
+                return "";
+        }
+    }
+}

+ 1 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -113,6 +113,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
             .antMatchers("/actuator/**").anonymous()
             // 应急指挥相关
             .antMatchers("/zhdd/**").permitAll()
+            .antMatchers("/common/upload").permitAll()
             // 除上面外的所有请求全部需要鉴权认证
             .anyRequest().authenticated()
             .and()