package com.ruoyi.file.controller;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.file.constants.FileProjectConstants;
|
import com.ruoyi.file.service.AttachmentService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
|
/**
|
* @email 1603559716@qq.com
|
* @author: zf
|
* @date: 2023/8/29
|
* @time: 10:53
|
*/
|
@Api(tags = "附件")
|
@RestController
|
@RequestMapping("attachment")
|
public class AttachmentController extends BaseController {
|
|
@Autowired
|
private AttachmentService attachmentService;
|
|
|
/**
|
* 根据标识查询文件具体信息
|
* @param key
|
* @return
|
*/
|
@ApiOperation(value = "根据标识查询文件具体信息")
|
@GetMapping("/get/key/{key}")
|
public AjaxResult findByKey(@PathVariable String key) {
|
return success(attachmentService.findByKey(key));
|
}
|
|
/**
|
* 根据id获取文件
|
* @param id
|
* @return
|
*/
|
|
@GetMapping("/get/id/{id}")
|
public AjaxResult get(@PathVariable Long id) {
|
return success(attachmentService.findById(id));
|
}
|
|
/**
|
* 删除文件数据
|
* @param id
|
* @return
|
*/
|
@ApiOperation(value = "删除文件数据")
|
@GetMapping("/delete/{id}")
|
public AjaxResult delete(@PathVariable Long id) {
|
attachmentService.delete(id);
|
return success();
|
|
}
|
|
/**
|
* 单个文件上传
|
* @Description 上传文件(返回文件标识)
|
* @Param [file, module]
|
**/
|
@ApiOperation(value = "上传文件(返回文件标识)")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "file", value = "文件",required = true),
|
@ApiImplicitParam(name = "module", dataTypeClass = String.class,value = "模块",required = true,example = "accountPath"),
|
})
|
@PostMapping("/upload/key")
|
public AjaxResult uploadReturnKey(@RequestParam("file") MultipartFile
|
file, @RequestParam("module") String module) {
|
return success(attachmentService.saveFileToPath(file, module, FileProjectConstants.ReturnType.KEY));
|
}
|
|
/**
|
* 单个文件
|
* @Description 上传文件(返回文件信息)
|
* @Param [file, module]
|
**/
|
@ApiOperation(value = "上传文件(返回文件信息)")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "file",value = "文件",required = true),
|
@ApiImplicitParam(name = "module", dataTypeClass = String.class,value = "模块",required = true,example = "accountPath"),
|
})
|
@PostMapping("/upload/detail")
|
public AjaxResult uploadReturnDetail(@RequestParam("file") MultipartFile
|
file, @RequestParam("module") String module) {
|
return success(attachmentService.saveFileToPath(file, module, FileProjectConstants.ReturnType.DETAIL));
|
}
|
/**
|
* 单个文件
|
* @Description 上传文件(返回访问路径)
|
* @Date 2021/4/20 19:28
|
* @Param [file, module]
|
**/
|
@ApiOperation(value = "上传文件(返回访问路径)")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "file",value = "文件",required = true),
|
@ApiImplicitParam(name = "module", dataTypeClass = String.class,value = "模块",required = true,example = "accountPath"),
|
})
|
@PostMapping("/upload/url")
|
public AjaxResult uploadReturnUrl(@RequestParam("file") MultipartFile file, @RequestParam("module") String module) {
|
return success(attachmentService.saveFileToPath(file, module, FileProjectConstants.ReturnType.URL));
|
}
|
|
/**
|
* 批量文件
|
* @Description 上传文件(返回文件信息)
|
* @Param [file, module]
|
**/
|
@ApiOperation(value = "批量上传文件(返回文件信息)")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "file", value = "文件",required = true),
|
@ApiImplicitParam(name = "module", dataTypeClass = String.class,value = "模块",required = true,example = "accountPath"),
|
})
|
@PostMapping("/upload/batch/detail")
|
public AjaxResult uploadBatchReturnDetail(@RequestParam("file") MultipartFile[]
|
file, @RequestParam("module") String module) {
|
return success(attachmentService.saveBatchFileToPath(file, module));
|
}
|
|
/**
|
* @return org.springframework.http.ResponseEntity<byte [ ]>
|
* @Description 获取下载文件流
|
* @Param [key]
|
**/
|
|
@GetMapping("/downloadFile/{key}")
|
public void download(@PathVariable String key, HttpServletResponse response) {
|
attachmentService.downloadForStream(response, key);
|
}
|
|
/**
|
* @return void
|
* @Description 文件下载
|
* @Param [key, response, request]
|
**/
|
|
@RequestMapping(value = "/downloadFileById/{id}", method = {RequestMethod.POST, RequestMethod.GET})
|
public void downloadFileByKey(@PathVariable Long id, HttpServletResponse response, HttpServletRequest
|
request) {
|
attachmentService.downloadById(response, request, id);
|
}
|
|
/**
|
* @Description 获取下载文件路径
|
* @Param [key]
|
**/
|
|
@GetMapping("/downloadUrl/{key}")
|
public AjaxResult downLoad( @PathVariable String key) {
|
return success(attachmentService.findByKey(key));
|
}
|
|
|
|
}
|