package com.moral.api.controller;
import com.moral.api.pojo.vo.file.FileVo;
import com.moral.api.service.FileTableService;
import com.moral.constant.ResultMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
*
* 附件表 前端控制器
*
*
* @author moral
* @since 2023-09-21
*/
@RestController
@RequestMapping("/file")
@Api(tags = {"附件"})
public class FileTableController {
private final FileTableService fileTableService;
public FileTableController(FileTableService fileTableService) {
this.fileTableService = fileTableService;
}
@PostMapping("/upload")
@ApiOperation("文件上传")
public ResultMessage upload(@RequestParam("file") @ApiParam(name = "file", value = "上传文件") MultipartFile file,
@RequestParam("sysCode") @ApiParam(name = "sysCode", value = "系统代码") Integer sysCode){
return ResultMessage.ok(fileTableService.upload(file,sysCode));
}
@PostMapping("/multipleUpload")
@ApiOperation("多文件批量上传")
public ResultMessage> upload(@RequestParam("file") @ApiParam(name = "file", value = "上传文件") List file,
@RequestParam("sysCode") @ApiParam(name = "sysCode", value = "系统代码") Integer sysCode){
return ResultMessage.ok(fileTableService.upload(file,sysCode));
}
@GetMapping("/preview/{id}")
@ApiOperation("文件预览")
public void preview(@PathVariable("id") Integer id, HttpServletRequest request, HttpServletResponse response) {
fileTableService.preview(id, request, response);
}
@GetMapping("/preview/cover/{id}")
@ApiOperation("封面图片预览")
public void coverPreview(@PathVariable("id") Integer id, HttpServletRequest request, HttpServletResponse response) {
fileTableService.coverPreview(id, request, response);
}
}