jinpengyong
2023-09-27 68e22957db996437fa20a9a4aa5ff37c54d4056f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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;
 
/**
 * <p>
 * 附件表 前端控制器
 * </p>
 *
 * @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<FileVo> 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<List<FileVo>> upload(@RequestParam("file") @ApiParam(name = "file", value = "上传文件") List<MultipartFile> 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);
    }
 
}