教育训练处考试制证系统后端
huangzhen
2023-09-25 1614615fc9319b8626eb028598b894311992c033
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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));
    }
 
 
 
}