提交 | 用户 | 时间
|
722af2
|
1 |
package com.dl.web.controller.system; |
X |
2 |
|
|
3 |
|
|
4 |
import cn.dev33.satoken.annotation.SaCheckPermission; |
|
5 |
import cn.hutool.core.util.ObjectUtil; |
|
6 |
import com.dl.common.annotation.Log; |
|
7 |
import com.dl.common.core.controller.BaseController; |
|
8 |
import com.dl.common.core.domain.PageQuery; |
|
9 |
import com.dl.common.core.domain.R; |
|
10 |
import com.dl.common.core.page.TableDataInfo; |
|
11 |
import com.dl.common.core.validate.QueryGroup; |
|
12 |
import com.dl.common.enums.BusinessType; |
|
13 |
import com.dl.system.domain.bo.SysOssBo; |
|
14 |
import com.dl.system.domain.vo.SysOssVo; |
|
15 |
import com.dl.system.service.ISysOssService; |
|
16 |
import lombok.RequiredArgsConstructor; |
|
17 |
import org.springframework.http.MediaType; |
|
18 |
import org.springframework.validation.annotation.Validated; |
|
19 |
import org.springframework.web.bind.annotation.*; |
|
20 |
import org.springframework.web.multipart.MultipartFile; |
|
21 |
|
|
22 |
import javax.servlet.http.HttpServletResponse; |
|
23 |
import javax.validation.constraints.NotEmpty; |
|
24 |
import java.io.IOException; |
|
25 |
import java.util.Arrays; |
|
26 |
import java.util.HashMap; |
|
27 |
import java.util.List; |
|
28 |
import java.util.Map; |
|
29 |
|
|
30 |
/** |
|
31 |
* 文件上传 控制层 |
|
32 |
* |
|
33 |
* @author Lion Li |
|
34 |
*/ |
|
35 |
@Validated |
|
36 |
@RequiredArgsConstructor |
|
37 |
@RestController |
|
38 |
@RequestMapping("/system/oss") |
|
39 |
public class SysOssController extends BaseController { |
|
40 |
|
|
41 |
private final ISysOssService iSysOssService; |
|
42 |
|
|
43 |
/** |
|
44 |
* 查询OSS对象存储列表 |
|
45 |
*/ |
|
46 |
@SaCheckPermission("system:oss:list") |
|
47 |
@GetMapping("/list") |
|
48 |
public TableDataInfo<SysOssVo> list(@Validated(QueryGroup.class) SysOssBo bo, PageQuery pageQuery) { |
|
49 |
return iSysOssService.queryPageList(bo, pageQuery); |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* 查询OSS对象基于id串 |
|
54 |
* |
|
55 |
* @param ossIds OSS对象ID串 |
|
56 |
*/ |
|
57 |
@SaCheckPermission("system:oss:list") |
|
58 |
@GetMapping("/listByIds/{ossIds}") |
|
59 |
public R<List<SysOssVo>> listByIds(@NotEmpty(message = "主键不能为空") |
|
60 |
@PathVariable Long[] ossIds) { |
|
61 |
List<SysOssVo> list = iSysOssService.listByIds(Arrays.asList(ossIds)); |
|
62 |
return R.ok(list); |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* 上传OSS对象存储 |
|
67 |
* |
|
68 |
* @param file 文件 |
|
69 |
*/ |
|
70 |
@SaCheckPermission("system:oss:upload") |
|
71 |
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT) |
|
72 |
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
|
73 |
public R<Map<String, String>> upload(@RequestPart("file") MultipartFile file) { |
|
74 |
if (ObjectUtil.isNull(file)) { |
|
75 |
return R.fail("上传文件不能为空"); |
|
76 |
} |
|
77 |
SysOssVo oss = iSysOssService.upload(file); |
|
78 |
Map<String, String> map = new HashMap<>(2); |
|
79 |
map.put("url", oss.getUrl()); |
|
80 |
map.put("fileName", oss.getOriginalName()); |
|
81 |
map.put("ossId", oss.getOssId().toString()); |
|
82 |
return R.ok(map); |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* 下载OSS对象 |
|
87 |
* |
|
88 |
* @param ossId OSS对象ID |
|
89 |
*/ |
|
90 |
@SaCheckPermission("system:oss:download") |
|
91 |
@GetMapping("/download/{ossId}") |
|
92 |
public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException { |
|
93 |
iSysOssService.download(ossId,response); |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* 删除OSS对象存储 |
|
98 |
* |
|
99 |
* @param ossIds OSS对象ID串 |
|
100 |
*/ |
|
101 |
@SaCheckPermission("system:oss:remove") |
|
102 |
@Log(title = "OSS对象存储", businessType = BusinessType.DELETE) |
|
103 |
@DeleteMapping("/{ossIds}") |
|
104 |
public R<Void> remove(@NotEmpty(message = "主键不能为空") |
|
105 |
@PathVariable Long[] ossIds) { |
|
106 |
return toAjax(iSysOssService.deleteWithValidByIds(Arrays.asList(ossIds), true)); |
|
107 |
} |
|
108 |
|
|
109 |
} |