|
@@ -1,9 +1,13 @@
|
|
-package cn.iocoder.dashboard.modules.system.controller.common;
|
|
|
|
|
|
+package cn.iocoder.dashboard.modules.infra.controller.file;
|
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
import cn.hutool.core.io.IoUtil;
|
|
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
|
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
|
-import cn.iocoder.dashboard.modules.system.dal.dataobject.common.SysFileDO;
|
|
|
|
-import cn.iocoder.dashboard.modules.system.service.common.SysFileService;
|
|
|
|
|
|
+import cn.iocoder.dashboard.common.pojo.PageResult;
|
|
|
|
+import cn.iocoder.dashboard.modules.infra.controller.file.vo.InfFilePageReqVO;
|
|
|
|
+import cn.iocoder.dashboard.modules.infra.controller.file.vo.InfFileRespVO;
|
|
|
|
+import cn.iocoder.dashboard.modules.infra.convert.file.InfFileConvert;
|
|
|
|
+import cn.iocoder.dashboard.modules.infra.dal.dataobject.file.InfFileDO;
|
|
|
|
+import cn.iocoder.dashboard.modules.infra.service.file.InfFileService;
|
|
import cn.iocoder.dashboard.util.servlet.ServletUtils;
|
|
import cn.iocoder.dashboard.util.servlet.ServletUtils;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
@@ -11,40 +15,53 @@ import io.swagger.annotations.ApiImplicitParams;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import javax.validation.Valid;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
|
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
|
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
|
|
|
|
|
@Api(tags = "文件存储")
|
|
@Api(tags = "文件存储")
|
|
@RestController
|
|
@RestController
|
|
-@RequestMapping("/system/file")
|
|
|
|
|
|
+@RequestMapping("/infra/file")
|
|
|
|
+@Validated
|
|
@Slf4j
|
|
@Slf4j
|
|
-public class SysFileController {
|
|
|
|
|
|
+public class InfFileController {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
- private SysFileService fileService;
|
|
|
|
|
|
+ private InfFileService fileService;
|
|
|
|
|
|
|
|
+ @PostMapping("/upload")
|
|
@ApiOperation("上传文件")
|
|
@ApiOperation("上传文件")
|
|
@ApiImplicitParams({
|
|
@ApiImplicitParams({
|
|
- @ApiImplicitParam(name = "path", value = "文件附件", required = true, dataTypeClass = MultipartFile.class),
|
|
|
|
- @ApiImplicitParam(name = "path", value = "文件路径", required = true, example = "yudaoyuanma.png", dataTypeClass = Long.class)
|
|
|
|
|
|
+ @ApiImplicitParam(name = "file", value = "文件附件", required = true, dataTypeClass = MultipartFile.class),
|
|
|
|
+ @ApiImplicitParam(name = "path", value = "文件路径", required = false, example = "yudaoyuanma.png", dataTypeClass = String.class)
|
|
})
|
|
})
|
|
- @PostMapping("/upload")
|
|
|
|
public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file,
|
|
public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file,
|
|
@RequestParam("path") String path) throws IOException {
|
|
@RequestParam("path") String path) throws IOException {
|
|
return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream())));
|
|
return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream())));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @DeleteMapping("/delete")
|
|
|
|
+ @ApiOperation("删除文件")
|
|
|
|
+ @ApiImplicitParam(name = "id", value = "编号", required = true)
|
|
|
|
+ @PreAuthorize("@ss.hasPermission('infra:file:delete')")
|
|
|
|
+ public CommonResult<Boolean> deleteFile(@RequestParam("id") String id) {
|
|
|
|
+ fileService.deleteFile(id);
|
|
|
|
+ return success(true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping("/get/{path}")
|
|
@ApiOperation("下载文件")
|
|
@ApiOperation("下载文件")
|
|
@ApiImplicitParam(name = "path", value = "文件附件", required = true, dataTypeClass = MultipartFile.class)
|
|
@ApiImplicitParam(name = "path", value = "文件附件", required = true, dataTypeClass = MultipartFile.class)
|
|
- @GetMapping("/get/{path}")
|
|
|
|
public void getFile(HttpServletResponse response, @PathVariable("path") String path) throws IOException {
|
|
public void getFile(HttpServletResponse response, @PathVariable("path") String path) throws IOException {
|
|
- SysFileDO file = fileService.getFile(path);
|
|
|
|
|
|
+ InfFileDO file = fileService.getFile(path);
|
|
if (file == null) {
|
|
if (file == null) {
|
|
log.warn("[getFile][path({}) 文件不存在]", path);
|
|
log.warn("[getFile][path({}) 文件不存在]", path);
|
|
response.setStatus(HttpStatus.NOT_FOUND.value());
|
|
response.setStatus(HttpStatus.NOT_FOUND.value());
|
|
@@ -53,4 +70,12 @@ public class SysFileController {
|
|
ServletUtils.writeAttachment(response, path, file.getContent());
|
|
ServletUtils.writeAttachment(response, path, file.getContent());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @GetMapping("/page")
|
|
|
|
+ @ApiOperation("获得文件分页")
|
|
|
|
+ @PreAuthorize("@ss.hasPermission('infra:file:query')")
|
|
|
|
+ public CommonResult<PageResult<InfFileRespVO>> getFilePage(@Valid InfFilePageReqVO pageVO) {
|
|
|
|
+ PageResult<InfFileDO> pageResult = fileService.getFilePage(pageVO);
|
|
|
|
+ return success(InfFileConvert.INSTANCE.convertPage(pageResult));
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|