Commit c99b51f86ff2cdc98c30f1b9468c5fde3951c30f
1 parent
9dc2e741
Exists in
dev
附件相关接口
Showing
12 changed files
with
1685 additions
and
0 deletions
Show diff stats
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/controller/FileController.java
0 → 100644
@@ -0,0 +1,185 @@ | @@ -0,0 +1,185 @@ | ||
1 | +package com.chinagas.modules.schsf.controller; | ||
2 | + | ||
3 | +import com.chinagas.common.core.domain.AjaxResult; | ||
4 | +import com.chinagas.common.core.utils.uuid.IdUtils; | ||
5 | +import com.chinagas.modules.schsf.domain.McFile; | ||
6 | +import com.chinagas.modules.schsf.service.McFileService; | ||
7 | +import com.chinagas.modules.schsf.utils.minio.MinioProperties; | ||
8 | +import com.chinagas.modules.schsf.utils.minio.MinioUtil; | ||
9 | +import io.minio.BucketExistsArgs; | ||
10 | +import io.minio.MakeBucketArgs; | ||
11 | +import io.minio.MinioClient; | ||
12 | +import io.minio.PutObjectArgs; | ||
13 | +import lombok.extern.slf4j.Slf4j; | ||
14 | +import org.springframework.beans.factory.annotation.Autowired; | ||
15 | +import org.springframework.web.bind.annotation.*; | ||
16 | +import org.springframework.web.multipart.MultipartFile; | ||
17 | + | ||
18 | +import javax.annotation.Resource; | ||
19 | +import javax.servlet.http.HttpServletResponse; | ||
20 | +import java.time.LocalDate; | ||
21 | +import java.time.format.DateTimeFormatter; | ||
22 | +import java.util.ArrayList; | ||
23 | +import java.util.HashSet; | ||
24 | +import java.util.Random; | ||
25 | + | ||
26 | +/** | ||
27 | + * 市场化收费,文件控制层 | ||
28 | + */ | ||
29 | +@RestController | ||
30 | +@Slf4j | ||
31 | +@RequestMapping("/file") | ||
32 | +public class FileController { | ||
33 | + | ||
34 | + @Resource | ||
35 | + private MinioUtil minioUtil; | ||
36 | + @Autowired | ||
37 | + private MinioClient minioClient; | ||
38 | + @Autowired | ||
39 | + private MinioProperties minioProperties; | ||
40 | + @Resource | ||
41 | + private McFileService mcFileService; | ||
42 | + | ||
43 | + private final Long maxSize = (long) (1024 * 1024 * 20); | ||
44 | + | ||
45 | + | ||
46 | + /** | ||
47 | + * 批量文件上传 | ||
48 | + * | ||
49 | + * @param file | ||
50 | + * @return | ||
51 | + */ | ||
52 | + @PostMapping("/upload") | ||
53 | + public AjaxResult minioUpload(MultipartFile[] file) { | ||
54 | + // 判断文件是否为空 | ||
55 | + if (null == file || 0 == file.length) { | ||
56 | + return null; | ||
57 | + } | ||
58 | + if (!cheakIsRepeat(file)) { | ||
59 | + throw new RuntimeException("文件名不允许重复"); | ||
60 | + } | ||
61 | + String bucketName = minioProperties.getBucket(); | ||
62 | + ArrayList<McFile> list = new ArrayList<>(); | ||
63 | + String fileName = null; | ||
64 | + try { | ||
65 | + // 判断存储桶是否存在 不存在则创建 | ||
66 | + createBucket(bucketName); | ||
67 | + for (int i = 0; i < file.length; i++) { | ||
68 | + // 文件名 | ||
69 | + String originalFilename = file[i].getOriginalFilename(); | ||
70 | + // 判断大小 | ||
71 | + if (file[i].getSize() > maxSize) { | ||
72 | + throw new RuntimeException("文件" + "<" + originalFilename + ">" + "过大,请上传小于20M文件!"); | ||
73 | + } | ||
74 | + String file_uuid = IdUtils.fastSimpleUUID(); | ||
75 | + McFile McFile = new McFile(); | ||
76 | + // 后缀 | ||
77 | + String extension = originalFilename.substring(originalFilename.lastIndexOf(".")); | ||
78 | + if (!extension.equalsIgnoreCase(".pdf") | ||
79 | + && !extension.equalsIgnoreCase(".doc") | ||
80 | + && !extension.equalsIgnoreCase(".docx") | ||
81 | + && !extension.equalsIgnoreCase(".xlsx") | ||
82 | + && !extension.equalsIgnoreCase(".xls") | ||
83 | + && !extension.equalsIgnoreCase(".jpg") | ||
84 | + && !extension.equalsIgnoreCase(".jpeg") | ||
85 | + && !extension.equalsIgnoreCase(".png")) { | ||
86 | + throw new RuntimeException("文件" + "<" + originalFilename + ">" + "格式不正确"); | ||
87 | + } | ||
88 | + // 新的文件名 = 时间戳_随机数.后缀名 | ||
89 | + assert originalFilename != null; | ||
90 | + long now = System.currentTimeMillis() / 1000; | ||
91 | + String format = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); | ||
92 | + fileName = format + "_" + now + "_" + new Random().nextInt(1000) + extension; | ||
93 | + // 启动minio客户端,文件名传新生成的随机名 | ||
94 | + minioClient.putObject( | ||
95 | + PutObjectArgs.builder().bucket(bucketName).object(fileName).stream( | ||
96 | + file[i].getInputStream(), file[i].getSize(), -1) | ||
97 | + .contentType(file[i].getContentType()) | ||
98 | + .build()); | ||
99 | + // 用于图片预览,直接访问桶名+文件名 | ||
100 | + String url = minioProperties.getEndpoint() + "/" + bucketName + "/" + fileName; | ||
101 | + // 持久化存储原文件名 | ||
102 | + McFile.setFileName(originalFilename); | ||
103 | + McFile.setUrl(url); | ||
104 | + McFile.setUuid(file_uuid); | ||
105 | + McFile.setExtension(extension); | ||
106 | + McFile.setFileSize(file[i].getSize()); | ||
107 | + list.add(McFile); | ||
108 | + } | ||
109 | + } catch (Exception e) { | ||
110 | + throw new RuntimeException(e); | ||
111 | + } | ||
112 | + list.stream().forEach(o -> { | ||
113 | + mcFileService.insertMcFile(o); | ||
114 | + }); | ||
115 | + return AjaxResult.success(list); | ||
116 | + } | ||
117 | + | ||
118 | + public void createBucket(String bucketName) throws Exception { | ||
119 | + if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())) { | ||
120 | + minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build()); | ||
121 | + } | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
125 | + * 文件下载 | ||
126 | + * | ||
127 | + * @param | ||
128 | + * @param res | ||
129 | + * @return | ||
130 | + */ | ||
131 | + @GetMapping("/download") | ||
132 | + public AjaxResult download(String uuid, HttpServletResponse res) { | ||
133 | + McFile McFile = mcFileService.selectMcFileByUuid(uuid); | ||
134 | + if (McFile == null) { | ||
135 | + throw new RuntimeException("文件不存在或已被删除!"); | ||
136 | + } | ||
137 | + minioUtil.download(McFile, res); | ||
138 | + return AjaxResult.success(); | ||
139 | + } | ||
140 | + | ||
141 | + | ||
142 | + @GetMapping("/getByUuid/{uuid}") | ||
143 | + public AjaxResult download(@PathVariable("uuid") String uuid) { | ||
144 | + McFile McFile = mcFileService.selectMcFileByUuid(uuid); | ||
145 | + if (McFile == null) { | ||
146 | + throw new RuntimeException("文件不存在或已被删除!"); | ||
147 | + } | ||
148 | + return AjaxResult.success(McFile); | ||
149 | + } | ||
150 | + | ||
151 | + | ||
152 | +// /** | ||
153 | +// * 批量下载 | ||
154 | +// * | ||
155 | +// * @param uuid | ||
156 | +// * @param zip | ||
157 | +// * @param res | ||
158 | +// * @param req | ||
159 | +// */ | ||
160 | +// @GetMapping("/batchDownload") | ||
161 | +// public void batchDownload(String[] uuid, String zip, HttpServletResponse res, HttpServletRequest req) { | ||
162 | +// List<McFile> list = mcFileService.selectFileByUuid(uuid); | ||
163 | +//// ArrayList<String> fileNames = new ArrayList<>(); | ||
164 | +//// list.stream().forEach(o -> { | ||
165 | +//// // 获取minio中的真实文件名 | ||
166 | +//// fileNames.add(o.getUrl().substring(o.getUrl().indexOf("t/")+2)); | ||
167 | +//// }); | ||
168 | +// minioUtil.batchDownload1(list, zip, res, req); | ||
169 | +// } | ||
170 | + | ||
171 | + | ||
172 | + | ||
173 | + | ||
174 | + private static boolean cheakIsRepeat(MultipartFile[] array) { | ||
175 | + HashSet<MultipartFile> hashSet = new HashSet<>(); | ||
176 | + for (int i = 0; i < array.length; i++) { | ||
177 | + hashSet.add(array[i]); | ||
178 | + } | ||
179 | + if (hashSet.size() == array.length) { | ||
180 | + return true; | ||
181 | + } else { | ||
182 | + return false; | ||
183 | + } | ||
184 | + } | ||
185 | +} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/domain/McFile.java
0 → 100644
@@ -0,0 +1,142 @@ | @@ -0,0 +1,142 @@ | ||
1 | +package com.chinagas.modules.schsf.domain; | ||
2 | + | ||
3 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | ||
4 | +import com.alibaba.excel.annotation.ExcelProperty; | ||
5 | +import com.chinagas.common.core.web.domain.BaseEntity; | ||
6 | + | ||
7 | +@ExcelIgnoreUnannotated | ||
8 | +public class McFile extends BaseEntity | ||
9 | +{ | ||
10 | + private static final long serialVersionUID = 1L; | ||
11 | + | ||
12 | + /** 自增id */ | ||
13 | + private Long id; | ||
14 | + | ||
15 | + /** 唯一标识 */ | ||
16 | + @ExcelProperty(value = "唯一标识") | ||
17 | + private String uuid; | ||
18 | + | ||
19 | + /** 文件名称 */ | ||
20 | + @ExcelProperty(value = "文件名称") | ||
21 | + private String fileName; | ||
22 | + | ||
23 | + /** 文件拓展名,如.txt */ | ||
24 | + @ExcelProperty(value = "文件拓展名,如.txt") | ||
25 | + private String extension; | ||
26 | + | ||
27 | + /** 文件路径 */ | ||
28 | + @ExcelProperty(value = "文件路径") | ||
29 | + private String path; | ||
30 | + | ||
31 | + /** 下载链接 */ | ||
32 | + @ExcelProperty(value = "下载链接") | ||
33 | + private String url; | ||
34 | + | ||
35 | + /** 删除标志(0:未删除,1:已删除) */ | ||
36 | + @ExcelProperty(value = "删除标志") | ||
37 | + private String defFlag; | ||
38 | + | ||
39 | + /** 是否被引用过(0:未被引用过,1:已被引用过) */ | ||
40 | + @ExcelProperty(value = "是否被引用过") | ||
41 | + private String cited; | ||
42 | + | ||
43 | + /** 被引用次数 */ | ||
44 | + @ExcelProperty(value = "被引用次数") | ||
45 | + private Long count; | ||
46 | + | ||
47 | + /** 文件大小(kb) */ | ||
48 | + @ExcelProperty(value = "文件大小(kb)") | ||
49 | + private Long fileSize; | ||
50 | + | ||
51 | + public void setId(Long id) | ||
52 | + { | ||
53 | + this.id = id; | ||
54 | + } | ||
55 | + | ||
56 | + public Long getId() | ||
57 | + { | ||
58 | + return id; | ||
59 | + } | ||
60 | + public void setUuid(String uuid) | ||
61 | + { | ||
62 | + this.uuid = uuid; | ||
63 | + } | ||
64 | + | ||
65 | + public String getUuid() | ||
66 | + { | ||
67 | + return uuid; | ||
68 | + } | ||
69 | + public void setFileName(String fileName) | ||
70 | + { | ||
71 | + this.fileName = fileName; | ||
72 | + } | ||
73 | + | ||
74 | + public String getFileName() | ||
75 | + { | ||
76 | + return fileName; | ||
77 | + } | ||
78 | + public void setExtension(String extension) | ||
79 | + { | ||
80 | + this.extension = extension; | ||
81 | + } | ||
82 | + | ||
83 | + public String getExtension() | ||
84 | + { | ||
85 | + return extension; | ||
86 | + } | ||
87 | + public void setPath(String path) | ||
88 | + { | ||
89 | + this.path = path; | ||
90 | + } | ||
91 | + | ||
92 | + public String getPath() | ||
93 | + { | ||
94 | + return path; | ||
95 | + } | ||
96 | + public void setUrl(String url) | ||
97 | + { | ||
98 | + this.url = url; | ||
99 | + } | ||
100 | + | ||
101 | + public String getUrl() | ||
102 | + { | ||
103 | + return url; | ||
104 | + } | ||
105 | + public void setDefFlag(String defFlag) | ||
106 | + { | ||
107 | + this.defFlag = defFlag; | ||
108 | + } | ||
109 | + | ||
110 | + public String getDefFlag() | ||
111 | + { | ||
112 | + return defFlag; | ||
113 | + } | ||
114 | + public void setCited(String cited) | ||
115 | + { | ||
116 | + this.cited = cited; | ||
117 | + } | ||
118 | + | ||
119 | + public String getCited() | ||
120 | + { | ||
121 | + return cited; | ||
122 | + } | ||
123 | + public void setCount(Long count) | ||
124 | + { | ||
125 | + this.count = count; | ||
126 | + } | ||
127 | + | ||
128 | + public Long getCount() | ||
129 | + { | ||
130 | + return count; | ||
131 | + } | ||
132 | + public void setFileSize(Long fileSize) | ||
133 | + { | ||
134 | + this.fileSize = fileSize; | ||
135 | + } | ||
136 | + | ||
137 | + public Long getFileSize() | ||
138 | + { | ||
139 | + return fileSize; | ||
140 | + } | ||
141 | + | ||
142 | +} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/mapper/McFileMapper.java
0 → 100644
@@ -0,0 +1,65 @@ | @@ -0,0 +1,65 @@ | ||
1 | +package com.chinagas.modules.schsf.mapper; | ||
2 | + | ||
3 | +import com.chinagas.modules.schsf.domain.McFile; | ||
4 | + | ||
5 | +import java.util.List; | ||
6 | + | ||
7 | +/** | ||
8 | + * 市场化收费相关文件Mapper接口 | ||
9 | + * | ||
10 | + * @author lidwd | ||
11 | + * @date 2024-05-22 | ||
12 | + */ | ||
13 | +public interface McFileMapper | ||
14 | +{ | ||
15 | + /** | ||
16 | + * 查询市场化收费相关文件 | ||
17 | + * | ||
18 | + * @param id 市场化收费相关文件主键 | ||
19 | + * @return 市场化收费相关文件 | ||
20 | + */ | ||
21 | + public McFile selectMcFileById(Long id); | ||
22 | + | ||
23 | + /** | ||
24 | + * 查询市场化收费相关文件列表 | ||
25 | + * | ||
26 | + * @param mcFile 市场化收费相关文件 | ||
27 | + * @return 市场化收费相关文件集合 | ||
28 | + */ | ||
29 | + public List<McFile> selectMcFileList(McFile mcFile); | ||
30 | + | ||
31 | + /** | ||
32 | + * 新增市场化收费相关文件 | ||
33 | + * | ||
34 | + * @param mcFile 市场化收费相关文件 | ||
35 | + * @return 结果 | ||
36 | + */ | ||
37 | + public int insertMcFile(McFile mcFile); | ||
38 | + | ||
39 | + /** | ||
40 | + * 修改市场化收费相关文件 | ||
41 | + * | ||
42 | + * @param mcFile 市场化收费相关文件 | ||
43 | + * @return 结果 | ||
44 | + */ | ||
45 | + public int updateMcFile(McFile mcFile); | ||
46 | + | ||
47 | + /** | ||
48 | + * 删除市场化收费相关文件 | ||
49 | + * | ||
50 | + * @param id 市场化收费相关文件主键 | ||
51 | + * @return 结果 | ||
52 | + */ | ||
53 | + public int deleteMcFileById(Long id); | ||
54 | + | ||
55 | + /** | ||
56 | + * 批量删除市场化收费相关文件 | ||
57 | + * | ||
58 | + * @param ids 需要删除的数据主键集合 | ||
59 | + * @return 结果 | ||
60 | + */ | ||
61 | + public int deleteMcFileByIds(Long[] ids); | ||
62 | + | ||
63 | + McFile selectMcFileByUuid(String uuid); | ||
64 | + | ||
65 | +} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/service/McFileService.java
0 → 100644
@@ -0,0 +1,59 @@ | @@ -0,0 +1,59 @@ | ||
1 | +package com.chinagas.modules.schsf.service; | ||
2 | + | ||
3 | +import com.chinagas.modules.schsf.domain.McFile; | ||
4 | + | ||
5 | +import java.util.List; | ||
6 | + | ||
7 | +public interface McFileService { | ||
8 | + | ||
9 | + /** | ||
10 | + * 查询市场化收费相关文件 | ||
11 | + * | ||
12 | + * @param id 市场化收费相关文件主键 | ||
13 | + * @return 市场化收费相关文件 | ||
14 | + */ | ||
15 | + public McFile selectMcFileById(Long id); | ||
16 | + | ||
17 | + /** | ||
18 | + * 查询市场化收费相关文件列表 | ||
19 | + * | ||
20 | + * @param mcFile 市场化收费相关文件 | ||
21 | + * @return 市场化收费相关文件集合 | ||
22 | + */ | ||
23 | + public List<McFile> selectMcFileList(McFile mcFile); | ||
24 | + | ||
25 | + /** | ||
26 | + * 新增市场化收费相关文件 | ||
27 | + * | ||
28 | + * @param mcFile 市场化收费相关文件 | ||
29 | + * @return 结果 | ||
30 | + */ | ||
31 | + public int insertMcFile(McFile mcFile); | ||
32 | + | ||
33 | + /** | ||
34 | + * 修改市场化收费相关文件 | ||
35 | + * | ||
36 | + * @param mcFile 市场化收费相关文件 | ||
37 | + * @return 结果 | ||
38 | + */ | ||
39 | + public int updateMcFile(McFile mcFile); | ||
40 | + | ||
41 | + /** | ||
42 | + * 批量删除市场化收费相关文件 | ||
43 | + * | ||
44 | + * @param ids 需要删除的市场化收费相关文件主键集合 | ||
45 | + * @return 结果 | ||
46 | + */ | ||
47 | + public int deleteMcFileByIds(Long[] ids); | ||
48 | + | ||
49 | + /** | ||
50 | + * 删除市场化收费相关文件信息 | ||
51 | + * | ||
52 | + * @param id 市场化收费相关文件主键 | ||
53 | + * @return 结果 | ||
54 | + */ | ||
55 | + public int deleteMcFileById(Long id); | ||
56 | + | ||
57 | + McFile selectMcFileByUuid(String uuid); | ||
58 | + | ||
59 | +} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/service/impl/McFileServiceImpl.java
0 → 100644
@@ -0,0 +1,100 @@ | @@ -0,0 +1,100 @@ | ||
1 | +package com.chinagas.modules.schsf.service.impl; | ||
2 | + | ||
3 | +import com.chinagas.common.core.utils.DateUtils; | ||
4 | +import com.chinagas.common.security.utils.SecurityUtils; | ||
5 | +import com.chinagas.modules.schsf.service.McFileService; | ||
6 | +import com.chinagas.modules.schsf.domain.McFile; | ||
7 | +import com.chinagas.modules.schsf.mapper.McFileMapper; | ||
8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
9 | +import org.springframework.stereotype.Service; | ||
10 | + | ||
11 | +import java.util.List; | ||
12 | + | ||
13 | +/** | ||
14 | + * 市场化收费相关文件Service业务层处理 | ||
15 | + * | ||
16 | + * @author lidwd | ||
17 | + * @date 2024-05-22 | ||
18 | + */ | ||
19 | +@Service | ||
20 | +public class McFileServiceImpl implements McFileService { | ||
21 | + @Autowired | ||
22 | + private McFileMapper mcFileMapper; | ||
23 | + | ||
24 | + /** | ||
25 | + * 查询市场化收费相关文件 | ||
26 | + * | ||
27 | + * @param id 市场化收费相关文件主键 | ||
28 | + * @return 市场化收费相关文件 | ||
29 | + */ | ||
30 | + @Override | ||
31 | + public McFile selectMcFileById(Long id) { | ||
32 | + return mcFileMapper.selectMcFileById(id); | ||
33 | + } | ||
34 | + | ||
35 | + /** | ||
36 | + * 查询市场化收费相关文件列表 | ||
37 | + * | ||
38 | + * @param mcFile 市场化收费相关文件 | ||
39 | + * @return 市场化收费相关文件 | ||
40 | + */ | ||
41 | + @Override | ||
42 | + public List<McFile> selectMcFileList(McFile mcFile) { | ||
43 | + return mcFileMapper.selectMcFileList(mcFile); | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * 新增市场化收费相关文件 | ||
48 | + * | ||
49 | + * @param mcFile 市场化收费相关文件 | ||
50 | + * @return 结果 | ||
51 | + */ | ||
52 | + @Override | ||
53 | + public int insertMcFile(McFile mcFile) { | ||
54 | + mcFile.setCreateTime(DateUtils.getNowLocal()); | ||
55 | + mcFile.setCreateBy(SecurityUtils.getUserId().toString()); | ||
56 | + mcFile.setUpdateTime(DateUtils.getNowLocal()); | ||
57 | + mcFile.setUpdateBy(SecurityUtils.getUserId().toString()); | ||
58 | + return mcFileMapper.insertMcFile(mcFile); | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * 修改市场化收费相关文件 | ||
63 | + * | ||
64 | + * @param mcFile 市场化收费相关文件 | ||
65 | + * @return 结果 | ||
66 | + */ | ||
67 | + @Override | ||
68 | + public int updateMcFile(McFile mcFile) { | ||
69 | + mcFile.setUpdateTime(DateUtils.getNowLocal()); | ||
70 | + mcFile.setUpdateBy(SecurityUtils.getUserId().toString()); | ||
71 | + return mcFileMapper.updateMcFile(mcFile); | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
75 | + * 批量删除市场化收费相关文件 | ||
76 | + * | ||
77 | + * @param ids 需要删除的市场化收费相关文件主键 | ||
78 | + * @return 结果 | ||
79 | + */ | ||
80 | + @Override | ||
81 | + public int deleteMcFileByIds(Long[] ids) { | ||
82 | + return mcFileMapper.deleteMcFileByIds(ids); | ||
83 | + } | ||
84 | + | ||
85 | + /** | ||
86 | + * 删除市场化收费相关文件信息 | ||
87 | + * | ||
88 | + * @param id 市场化收费相关文件主键 | ||
89 | + * @return 结果 | ||
90 | + */ | ||
91 | + @Override | ||
92 | + public int deleteMcFileById(Long id) { | ||
93 | + return mcFileMapper.deleteMcFileById(id); | ||
94 | + } | ||
95 | + | ||
96 | + @Override | ||
97 | + public McFile selectMcFileByUuid(String uuid) { | ||
98 | + return mcFileMapper.selectMcFileByUuid(uuid); | ||
99 | + } | ||
100 | +} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/utils/StyleUtils.java
0 → 100644
@@ -0,0 +1,91 @@ | @@ -0,0 +1,91 @@ | ||
1 | +package com.chinagas.modules.schsf.utils; | ||
2 | + | ||
3 | +import com.alibaba.excel.write.metadata.style.WriteCellStyle; | ||
4 | +import com.alibaba.excel.write.metadata.style.WriteFont; | ||
5 | +import org.apache.poi.ss.usermodel.BorderStyle; | ||
6 | +import org.apache.poi.ss.usermodel.HorizontalAlignment; | ||
7 | +import org.apache.poi.ss.usermodel.VerticalAlignment; | ||
8 | + | ||
9 | +/** | ||
10 | + * EasyExcel 样式工具类 | ||
11 | + * | ||
12 | + * @author zhl | ||
13 | + * @date 2023-12-29 | ||
14 | + */ | ||
15 | +public class StyleUtils { | ||
16 | + /** | ||
17 | + * 标题样式 | ||
18 | + * @return | ||
19 | + */ | ||
20 | + public static WriteCellStyle getHeadStyle(){ | ||
21 | + // 头的策略 | ||
22 | + WriteCellStyle headWriteCellStyle = new WriteCellStyle(); | ||
23 | + // 背景颜色 | ||
24 | +// headWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE1.getIndex()); | ||
25 | +// headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND); | ||
26 | + | ||
27 | + // 字体 | ||
28 | + WriteFont headWriteFont = new WriteFont(); | ||
29 | + headWriteFont.setFontName("宋体");//设置字体名字 | ||
30 | + headWriteFont.setFontHeightInPoints((short)14);//设置字体大小 | ||
31 | + headWriteFont.setBold(true);//字体加粗 | ||
32 | + headWriteCellStyle.setWriteFont(headWriteFont); //在样式用应用设置的字体; | ||
33 | + | ||
34 | + // 样式 | ||
35 | + headWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框; | ||
36 | + headWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色; | ||
37 | + headWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边框; | ||
38 | + headWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色; | ||
39 | + headWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框; | ||
40 | + headWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色; | ||
41 | + headWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框; | ||
42 | + headWriteCellStyle.setTopBorderColor((short) 0); //设置顶边框颜色; | ||
43 | + | ||
44 | + headWriteCellStyle.setWrapped(true); //设置自动换行; | ||
45 | + | ||
46 | + headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//设置水平对齐的样式为居中对齐; | ||
47 | + headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐的样式为居中对齐; | ||
48 | + headWriteCellStyle.setShrinkToFit(true);//设置文本收缩至合适 | ||
49 | + | ||
50 | + return headWriteCellStyle; | ||
51 | + } | ||
52 | + | ||
53 | + | ||
54 | + /** | ||
55 | + * 内容样式 | ||
56 | + * @return | ||
57 | + */ | ||
58 | + public static WriteCellStyle getContentStyle(){ | ||
59 | + // 内容的策略 | ||
60 | + WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); | ||
61 | + | ||
62 | + // 背景绿色 | ||
63 | + // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定 | ||
64 | +// contentWriteCellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); | ||
65 | +// contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND); | ||
66 | + | ||
67 | + // 设置字体 | ||
68 | + WriteFont contentWriteFont = new WriteFont(); | ||
69 | + contentWriteFont.setFontHeightInPoints((short) 12);//设置字体大小 | ||
70 | + contentWriteFont.setFontName("宋体"); //设置字体名字 | ||
71 | + contentWriteCellStyle.setWriteFont(contentWriteFont);//在样式用应用设置的字体; | ||
72 | + | ||
73 | + //设置样式; | ||
74 | + contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框; | ||
75 | + contentWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色; | ||
76 | + contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边框; | ||
77 | + contentWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色; | ||
78 | + contentWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框; | ||
79 | + contentWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色; | ||
80 | + contentWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框; | ||
81 | + contentWriteCellStyle.setTopBorderColor((short) 0); ///设置顶边框颜色; | ||
82 | + | ||
83 | + contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);// 水平居中 | ||
84 | + contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中 | ||
85 | + contentWriteCellStyle.setWrapped(true); //设置自动换行; | ||
86 | + | ||
87 | +// contentWriteCellStyle.setShrinkToFit(true);//设置文本收缩至合适 | ||
88 | + | ||
89 | + return contentWriteCellStyle; | ||
90 | + } | ||
91 | +} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/utils/minio/MinioConfig.java
0 → 100644
@@ -0,0 +1,66 @@ | @@ -0,0 +1,66 @@ | ||
1 | +package com.chinagas.modules.schsf.utils.minio; | ||
2 | + | ||
3 | +import io.minio.MinioClient; | ||
4 | +import org.springframework.beans.factory.annotation.Autowired; | ||
5 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
6 | +import org.springframework.context.annotation.Bean; | ||
7 | +import org.springframework.context.annotation.Configuration; | ||
8 | + | ||
9 | +@Configuration | ||
10 | +@EnableConfigurationProperties(MinioProperties.class) | ||
11 | +public class MinioConfig { | ||
12 | + | ||
13 | + @Autowired | ||
14 | + private MinioProperties minioProperties; | ||
15 | + | ||
16 | + @Bean | ||
17 | + public MinioClient minioClient(){ | ||
18 | + return MinioClient.builder() | ||
19 | + .endpoint(minioProperties.getEndpoint()) | ||
20 | + .credentials(minioProperties.getAccessKey(),minioProperties.getSecretKey()) | ||
21 | + .build(); | ||
22 | + } | ||
23 | + | ||
24 | + /** | ||
25 | + * 获取 MinioClient | ||
26 | + * 取消ssl认证 | ||
27 | + */ | ||
28 | +// @Bean | ||
29 | +// public MinioClient minioClient() throws NoSuchAlgorithmException, KeyManagementException { | ||
30 | +//// return MinioClient.builder().endpoint(minioInfo.getEndpoint()) | ||
31 | +//// .credentials(minioInfo.getAccesskey(),minioInfo.getSecretkey()) | ||
32 | +//// .build(); | ||
33 | +// //取消ssl认证 | ||
34 | +// final TrustManager[] trustAllCerts = new TrustManager[]{ | ||
35 | +// new X509TrustManager() { | ||
36 | +// @Override | ||
37 | +// public void checkClientTrusted(X509Certificate[] x509Certificates, String s) { | ||
38 | +// } | ||
39 | +// @Override | ||
40 | +// public void checkServerTrusted(X509Certificate[] x509Certificates, String s) { | ||
41 | +// } | ||
42 | +// @Override | ||
43 | +// public X509Certificate[] getAcceptedIssuers() { | ||
44 | +// return new X509Certificate[]{}; | ||
45 | +// } | ||
46 | +// } | ||
47 | +// }; | ||
48 | +// | ||
49 | +// X509TrustManager x509TrustManager = (X509TrustManager) trustAllCerts[0]; | ||
50 | +// final SSLContext sslContext = SSLContext.getInstance("SSL"); | ||
51 | +// sslContext.init(null, trustAllCerts, new SecureRandom()); | ||
52 | +// final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); | ||
53 | +// OkHttpClient.Builder builder = new OkHttpClient.Builder(); | ||
54 | +// builder.sslSocketFactory(sslSocketFactory,x509TrustManager); | ||
55 | +// | ||
56 | +// builder.hostnameVerifier((s, sslSession) -> true); | ||
57 | +// OkHttpClient okHttpClient = builder.build(); | ||
58 | +// | ||
59 | +// return MinioClient.builder() | ||
60 | +// .endpoint(minioProperties.getEndpoint()) | ||
61 | +// .httpClient(okHttpClient).region("eu-west-1") | ||
62 | +// .credentials(minioProperties.getAccessKey() | ||
63 | +// , minioProperties.getSecretKey()).build(); | ||
64 | +// } | ||
65 | + | ||
66 | +} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/utils/minio/MinioProperties.java
0 → 100644
@@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
1 | +package com.chinagas.modules.schsf.utils.minio; | ||
2 | + | ||
3 | +import lombok.Data; | ||
4 | +import org.springframework.boot.context.properties.ConfigurationProperties; | ||
5 | +import org.springframework.stereotype.Component; | ||
6 | + | ||
7 | +@ConfigurationProperties(prefix = "minio") | ||
8 | +@Component | ||
9 | +@Data | ||
10 | +public class MinioProperties { | ||
11 | + | ||
12 | + /** | ||
13 | + * 连接地址 | ||
14 | + */ | ||
15 | + private String endpoint; | ||
16 | + /** | ||
17 | + * 用户名 | ||
18 | + */ | ||
19 | + private String accessKey; | ||
20 | + /** | ||
21 | + * 密码 | ||
22 | + */ | ||
23 | + private String secretKey; | ||
24 | + /** | ||
25 | + * 域名 | ||
26 | + */ | ||
27 | + private String nginxHost; | ||
28 | + /** | ||
29 | + * 默认文件桶 | ||
30 | + */ | ||
31 | + private String bucket; | ||
32 | + | ||
33 | +} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/utils/minio/MinioService.java
0 → 100644
@@ -0,0 +1,276 @@ | @@ -0,0 +1,276 @@ | ||
1 | +package com.chinagas.modules.schsf.utils.minio;//package com.chinagas.modules.insight.utils.minio; | ||
2 | +// | ||
3 | +//import com.google.common.collect.Lists; | ||
4 | +//import io.minio.*; | ||
5 | +//import io.minio.errors.ErrorResponseException; | ||
6 | +//import io.minio.errors.InvalidResponseException; | ||
7 | +//import io.minio.errors.XmlParserException; | ||
8 | +//import io.minio.messages.DeleteError; | ||
9 | +//import io.minio.messages.DeleteObject; | ||
10 | +//import lombok.extern.slf4j.Slf4j; | ||
11 | +//import org.springframework.beans.factory.annotation.Autowired; | ||
12 | +//import org.springframework.stereotype.Component; | ||
13 | +//import org.springframework.web.multipart.MultipartFile; | ||
14 | +//import sun.misc.BASE64Encoder; | ||
15 | +// | ||
16 | +//import javax.servlet.ServletOutputStream; | ||
17 | +//import javax.servlet.http.HttpServletRequest; | ||
18 | +//import javax.servlet.http.HttpServletResponse; | ||
19 | +//import java.io.BufferedOutputStream; | ||
20 | +//import java.io.IOException; | ||
21 | +//import java.io.InputStream; | ||
22 | +//import java.io.UnsupportedEncodingException; | ||
23 | +//import java.security.NoSuchAlgorithmException; | ||
24 | +//import java.util.List; | ||
25 | +//import java.util.stream.Collectors; | ||
26 | +//import java.util.zip.ZipEntry; | ||
27 | +//import java.util.zip.ZipOutputStream; | ||
28 | +// | ||
29 | +//@Component | ||
30 | +//@Slf4j | ||
31 | +//public class MinioService { | ||
32 | +// @Autowired | ||
33 | +// private MinioClient minioClient; | ||
34 | +// | ||
35 | +// /** | ||
36 | +// * description: 判断bucket是否存在,不存在则创建 | ||
37 | +// * @return: void | ||
38 | +// */ | ||
39 | +// public void existBucket(String name) { | ||
40 | +// try { | ||
41 | +// boolean exists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(name).build()); | ||
42 | +// if (!exists) { | ||
43 | +// minioClient.makeBucket(MakeBucketArgs.builder().bucket(name).build()); | ||
44 | +// } | ||
45 | +// } catch (Exception e) { | ||
46 | +// e.printStackTrace(); | ||
47 | +// } | ||
48 | +// } | ||
49 | +// | ||
50 | +// /** | ||
51 | +// * 创建存储bucket | ||
52 | +// * @param bucketName 存储bucket名称 | ||
53 | +// * @return Boolean | ||
54 | +// */ | ||
55 | +// public Boolean makeBucket(String bucketName) { | ||
56 | +// try { | ||
57 | +// minioClient.makeBucket(MakeBucketArgs.builder() | ||
58 | +// .bucket(bucketName) | ||
59 | +// .build()); | ||
60 | +// } catch (Exception e) { | ||
61 | +// e.printStackTrace(); | ||
62 | +// return false; | ||
63 | +// } | ||
64 | +// return true; | ||
65 | +// } | ||
66 | +// | ||
67 | +// /** | ||
68 | +// * 删除存储bucket | ||
69 | +// * @param bucketName 存储bucket名称 | ||
70 | +// * @return Boolean | ||
71 | +// */ | ||
72 | +// public Boolean removeBucket(String bucketName) { | ||
73 | +// try { | ||
74 | +// minioClient.removeBucket(RemoveBucketArgs.builder() | ||
75 | +// .bucket(bucketName) | ||
76 | +// .build()); | ||
77 | +// } catch (Exception e) { | ||
78 | +// e.printStackTrace(); | ||
79 | +// return false; | ||
80 | +// } | ||
81 | +// return true; | ||
82 | +// } | ||
83 | +// | ||
84 | +// /** | ||
85 | +// * description: 上传文件 | ||
86 | +// * @param multipartFile | ||
87 | +// * @return: java.lang.String | ||
88 | +// */ | ||
89 | +// public List<TxFileinfo> upload(MultipartFile[] multipartFile) { | ||
90 | +// | ||
91 | +// List<TxFileinfo> txFileinfos = Lists.newArrayList(); | ||
92 | +// for (MultipartFile file : multipartFile) { | ||
93 | +// String fileName = file.getOriginalFilename(); | ||
94 | +// String[] split = fileName.split("\\."); | ||
95 | +// String suffix = null; | ||
96 | +// if (split.length > 1) { | ||
97 | +// fileName = split[0] + "_" + System.currentTimeMillis() + "." + split[1]; | ||
98 | +// suffix = split[1]; | ||
99 | +// } else { | ||
100 | +// fileName = fileName + System.currentTimeMillis(); | ||
101 | +// } | ||
102 | +// | ||
103 | +// InputStream in = null; | ||
104 | +// try { | ||
105 | +// in = file.getInputStream(); | ||
106 | +// minioClient.putObject(PutObjectArgs.builder() | ||
107 | +// .bucket(bucketName) | ||
108 | +// .object(fileName) | ||
109 | +// .stream(in, in.available(), -1) | ||
110 | +// .contentType(file.getContentType()) | ||
111 | +// .build() | ||
112 | +// ); | ||
113 | +// TxFileinfo txFileinfo = getTxFileinfo(file, fileName, suffix); | ||
114 | +// txFileinfos.add(txFileinfo); | ||
115 | +// } catch (Exception e) { | ||
116 | +// e.printStackTrace(); | ||
117 | +// } finally { | ||
118 | +// if (in != null) { | ||
119 | +// try { | ||
120 | +// in.close(); | ||
121 | +// } catch (IOException e) { | ||
122 | +// e.printStackTrace(); | ||
123 | +// } | ||
124 | +// } | ||
125 | +// } | ||
126 | +// } | ||
127 | +// return txFileinfos; | ||
128 | +// } | ||
129 | +// | ||
130 | +// | ||
131 | +// /** | ||
132 | +// * 通过文件名称下载文件 | ||
133 | +// * | ||
134 | +// * | ||
135 | +// */ | ||
136 | +// public void download(String filename, HttpServletResponse res, HttpServletRequest req) throws IOException, | ||
137 | +// InvalidKeyException, | ||
138 | +// InvalidResponseException, InsufficientDataException, NoSuchAlgorithmException, ServerException, InternalException, XmlParserException, ErrorResponseException, ServerException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException { | ||
139 | +// BucketExistsArgs bucketArgs = BucketExistsArgs.builder().bucket(bucketName).build(); | ||
140 | +// boolean bucketExists = minioClient.bucketExists(bucketArgs); | ||
141 | +// GetObjectArgs objectArgs = GetObjectArgs.builder().bucket(bucketName) | ||
142 | +// .object(filename).build(); | ||
143 | +// try (GetObjectResponse response = minioClient.getObject(objectArgs)) { | ||
144 | +// byte[] buf = new byte[1024]; | ||
145 | +// int len; | ||
146 | +// try (FastByteArrayOutputStream os = new FastByteArrayOutputStream()) { | ||
147 | +// while ((len = response.read(buf)) != -1) { | ||
148 | +// os.write(buf, 0, len); | ||
149 | +// } | ||
150 | +// os.flush(); | ||
151 | +// byte[] bytes = os.toByteArray(); | ||
152 | +// res.setCharacterEncoding("utf-8"); | ||
153 | +// res.setContentType("application/force-download");// 设置强制下载不打开 | ||
154 | +// res.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); | ||
155 | +//// filenameEncoding 方法兼容不同浏览器编码 | ||
156 | +// res.addHeader("Content-Disposition", "attachment;fileName=" + filenameEncoding(filename,req)); | ||
157 | +// try (ServletOutputStream stream = res.getOutputStream()) { | ||
158 | +// stream.write(bytes); | ||
159 | +// stream.flush(); | ||
160 | +// } | ||
161 | +// } | ||
162 | +// | ||
163 | +// } catch (Exception e) { | ||
164 | +// e.printStackTrace(); | ||
165 | +// } | ||
166 | +// } | ||
167 | +// | ||
168 | +// /** | ||
169 | +// * @description: 批量下载 | ||
170 | +// * @date: 2022/8/17 16:50 | ||
171 | +// * @param: filenames: 多个文件名称 | ||
172 | +// * @Param: zip: 压缩包名称 | ||
173 | +// * @Param: res: 响应对象 | ||
174 | +// * @return: void | ||
175 | +// **/ | ||
176 | +// public void batchDownload(List<String> filenames, String zip, HttpServletResponse res, HttpServletRequest req){ | ||
177 | +// try { | ||
178 | +// BucketExistsArgs bucketArgs = BucketExistsArgs.builder().bucket(bucketName).build(); | ||
179 | +// boolean bucketExists = minioClient.bucketExists(bucketArgs); | ||
180 | +// BufferedOutputStream bos = null; | ||
181 | +// res.reset(); | ||
182 | +// bos = new BufferedOutputStream(res.getOutputStream()); | ||
183 | +// ZipOutputStream out = new ZipOutputStream(bos); | ||
184 | +// res.setHeader("Access-Control-Allow-Origin", "*"); | ||
185 | +// for (int i=0;i<filenames.size();i++) { | ||
186 | +// GetObjectArgs objectArgs = GetObjectArgs.builder().bucket(bucketName) | ||
187 | +// .object(filenames.get(i)).build(); | ||
188 | +// InputStream object = minioClient.getObject(objectArgs); | ||
189 | +// byte buf[] = new byte[1024]; | ||
190 | +// int length = 0; | ||
191 | +// res.setCharacterEncoding("utf-8"); | ||
192 | +// res.setContentType("application/force-download");// 设置强制下载不打开 | ||
193 | +// res.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); | ||
194 | +// res.setHeader("Content-Disposition", "attachment;filename=" + filenameEncoding(zip,req) + ".zip"); | ||
195 | +// out.putNextEntry(new ZipEntry(filenames.get(i))); | ||
196 | +// while ((length = object.read(buf)) > 0) { | ||
197 | +// out.write(buf, 0, length); | ||
198 | +// } | ||
199 | +// } | ||
200 | +// out.close(); | ||
201 | +// bos.close(); | ||
202 | +// } catch (Exception e) { | ||
203 | +// e.printStackTrace(); | ||
204 | +// } | ||
205 | +// } | ||
206 | +// | ||
207 | +// /** | ||
208 | +// * 设置不同浏览器编码 | ||
209 | +// * @param filename 文件名称 | ||
210 | +// * @param request 请求对象 | ||
211 | +// */ | ||
212 | +// public static String filenameEncoding(String filename, HttpServletRequest request) throws UnsupportedEncodingException { | ||
213 | +// // 获得请求头中的User-Agent | ||
214 | +// String agent = request.getHeader("User-Agent"); | ||
215 | +// // 根据不同的客户端进行不同的编码 | ||
216 | +// | ||
217 | +// if (agent.contains("MSIE")) { | ||
218 | +// // IE浏览器 | ||
219 | +// filename = URLEncoder.encode(filename, "utf-8"); | ||
220 | +// } else if (agent.contains("Firefox")) { | ||
221 | +// // 火狐浏览器 | ||
222 | +// BASE64Encoder base64Encoder = new BASE64Encoder(); | ||
223 | +// filename = "=?utf-8?B?" + base64Encoder.encode(filename.getBytes("utf-8")) + "?="; | ||
224 | +// } else { | ||
225 | +// // 其它浏览器 | ||
226 | +// filename = URLEncoder.encode(filename, "utf-8"); | ||
227 | +// } | ||
228 | +// return filename; | ||
229 | +// } | ||
230 | +// | ||
231 | +// | ||
232 | +// /** | ||
233 | +// * 批量删除文件对象 | ||
234 | +// * @param bucketName 存储bucket名称 | ||
235 | +// * @param objects 对象名称集合 | ||
236 | +// */ | ||
237 | +// public Iterable<Result<DeleteError>> removeObjects(String bucketName, List<String> objects) { | ||
238 | +// List<DeleteObject> dos = objects.stream().map(e -> new DeleteObject(e)).collect(Collectors.toList()); | ||
239 | +// Iterable<Result<DeleteError>> results = minioClient.removeObjects(RemoveObjectsArgs.builder().bucket(bucketName).objects(dos).build()); | ||
240 | +// return results; | ||
241 | +// } | ||
242 | +// | ||
243 | +// /** | ||
244 | +// * @description:获取文件预览接口 | ||
245 | +// * @date: 2022/8/18 9:44 | ||
246 | +// * @param: fileName: 文件名 | ||
247 | +// * @Param: bucketName: 桶名 | ||
248 | +// * @Param: previewExpiry: 预览到期时间(小时) | ||
249 | +// * @return: java.lang.String | ||
250 | +// **/ | ||
251 | +// public String getPreviewUrl(String fileName, String bucketName,Integer previewExpiry) { | ||
252 | +// if (StringUtils.isNotBlank(fileName)) { | ||
253 | +// bucketName = StringUtils.isNotBlank(bucketName) ? bucketName : this.bucketName; | ||
254 | +// try { | ||
255 | +// minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(fileName).build()); | ||
256 | +// if (null != previewExpiry){ | ||
257 | +// return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder() | ||
258 | +// .method(Method.GET) | ||
259 | +// .bucket(bucketName) | ||
260 | +// .object(fileName) | ||
261 | +// .expiry(previewExpiry, TimeUnit.HOURS) | ||
262 | +// .build()); | ||
263 | +// }else { | ||
264 | +// return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder() | ||
265 | +// .method(Method.GET) | ||
266 | +// .bucket(bucketName) | ||
267 | +// .object(fileName) | ||
268 | +// .build()); | ||
269 | +// } | ||
270 | +// } catch (Exception e) { | ||
271 | +// e.printStackTrace(); | ||
272 | +// } | ||
273 | +// } | ||
274 | +// return null; | ||
275 | +// } | ||
276 | +//} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/utils/minio/MinioUtil.java
0 → 100644
@@ -0,0 +1,413 @@ | @@ -0,0 +1,413 @@ | ||
1 | +package com.chinagas.modules.schsf.utils.minio; | ||
2 | + | ||
3 | +import com.chinagas.common.core.utils.uuid.IdUtils; | ||
4 | +import com.chinagas.modules.schsf.domain.McFile; | ||
5 | +import io.minio.*; | ||
6 | +import io.minio.errors.*; | ||
7 | +import io.minio.http.Method; | ||
8 | +import io.minio.messages.Bucket; | ||
9 | +import lombok.extern.slf4j.Slf4j; | ||
10 | +import net.coobird.thumbnailator.Thumbnails; | ||
11 | +import org.apache.commons.fileupload.FileItem; | ||
12 | +import org.apache.commons.fileupload.FileItemFactory; | ||
13 | +import org.apache.commons.fileupload.disk.DiskFileItemFactory; | ||
14 | +import org.springframework.beans.factory.annotation.Autowired; | ||
15 | +import org.springframework.stereotype.Component; | ||
16 | +import org.springframework.web.multipart.MultipartFile; | ||
17 | +import org.springframework.web.multipart.commons.CommonsMultipartFile; | ||
18 | +import sun.misc.BASE64Encoder; | ||
19 | + | ||
20 | +import javax.servlet.ServletOutputStream; | ||
21 | +import javax.servlet.http.HttpServletRequest; | ||
22 | +import javax.servlet.http.HttpServletResponse; | ||
23 | +import java.io.*; | ||
24 | +import java.net.URLEncoder; | ||
25 | +import java.security.InvalidKeyException; | ||
26 | +import java.security.NoSuchAlgorithmException; | ||
27 | +import java.time.LocalDate; | ||
28 | +import java.time.format.DateTimeFormatter; | ||
29 | +import java.util.ArrayList; | ||
30 | +import java.util.List; | ||
31 | +import java.util.Optional; | ||
32 | +import java.util.Random; | ||
33 | +import java.util.zip.ZipEntry; | ||
34 | +import java.util.zip.ZipOutputStream; | ||
35 | + | ||
36 | +@Component | ||
37 | +@Slf4j | ||
38 | +public class MinioUtil { | ||
39 | + | ||
40 | + @Autowired | ||
41 | + private MinioProperties minioProperties; | ||
42 | + | ||
43 | + @Autowired | ||
44 | + private MinioClient minioClient; | ||
45 | + | ||
46 | + private final Long maxSize = (long) (1024 * 1024); | ||
47 | + | ||
48 | + /** | ||
49 | + * 创建bucket | ||
50 | + */ | ||
51 | + public void createBucket(String bucketName) throws Exception { | ||
52 | + if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())) { | ||
53 | + minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build()); | ||
54 | + } | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * 上传文件 | ||
59 | + */ | ||
60 | + public List<McFile> uploadFile(MultipartFile[] file, String bucketName) throws Exception { | ||
61 | + // 判断文件是否为空 | ||
62 | + if (null == file || 0 == file.length) { | ||
63 | + return null; | ||
64 | + } | ||
65 | +// HashMap<Object, String> map = new HashMap<>(); | ||
66 | + ArrayList<McFile> list = new ArrayList<>(); | ||
67 | + String fileName = null; | ||
68 | + // 判断存储桶是否存在 不存在则创建 | ||
69 | + createBucket(bucketName); | ||
70 | + for (int i = 0; i < file.length; i++) { | ||
71 | + String file_uuid = IdUtils.fastSimpleUUID(); | ||
72 | + McFile McFile = new McFile(); | ||
73 | + // 文件名 | ||
74 | + String originalFilename = file[i].getOriginalFilename(); | ||
75 | + // 后缀 | ||
76 | + String extension = originalFilename.substring(originalFilename.lastIndexOf(".")); | ||
77 | + if (!extension.equalsIgnoreCase("pdf") || !extension.equalsIgnoreCase("docx") | ||
78 | + || !extension.equalsIgnoreCase("xlsx") || !extension.equalsIgnoreCase("xls")) { | ||
79 | + throw new RuntimeException("文件" + originalFilename + "文件格式不正确"); | ||
80 | + } | ||
81 | + // 新的文件名 = 时间戳_随机数.后缀名 | ||
82 | + assert originalFilename != null; | ||
83 | + long now = System.currentTimeMillis() / 1000; | ||
84 | + String format = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); | ||
85 | + fileName = format + "_" + now + "_" + new Random().nextInt(1000) + extension; | ||
86 | + // 开始上传 | ||
87 | + log.info("file压缩前大小:{}", file[i].getSize()); | ||
88 | + if (file[i].getSize() > maxSize) { | ||
89 | + FileItemFactory fileItemFactory = new DiskFileItemFactory(); | ||
90 | + FileItem fileItem = fileItemFactory.createItem(fileName, "text/plain", true, fileName); | ||
91 | + OutputStream outputStream = fileItem.getOutputStream(); | ||
92 | + Thumbnails.of(file[i].getInputStream()).scale(1f).outputFormat(originalFilename.substring(originalFilename.lastIndexOf(".") + 1)).outputQuality(0.25f).toOutputStream(outputStream); | ||
93 | + file[i] = new CommonsMultipartFile(fileItem); | ||
94 | + } | ||
95 | + log.info("file压缩后大小:{}", file[i].getSize()); | ||
96 | + minioClient.putObject( | ||
97 | + PutObjectArgs.builder().bucket(bucketName).object(fileName).stream( | ||
98 | + file[i].getInputStream(), file[i].getSize(), -1) | ||
99 | + .contentType(file[i].getContentType()) | ||
100 | + .build()); | ||
101 | + String url = minioProperties.getEndpoint() + "/" + bucketName + "/" + fileName; | ||
102 | +// String urlHost = minioProperties.getNginxHost() + "/" + bucketName + "/" + fileName; | ||
103 | +// map.put("bucket", bucketName); | ||
104 | +// map.put("url", url); | ||
105 | + McFile.setFileName(originalFilename); | ||
106 | + McFile.setUrl(url); | ||
107 | + McFile.setUuid(file_uuid); | ||
108 | + McFile.setExtension(extension); | ||
109 | + list.add(McFile); | ||
110 | + } | ||
111 | + return list; | ||
112 | + } | ||
113 | + | ||
114 | + /** | ||
115 | + * 获取全部bucket | ||
116 | + * | ||
117 | + * @return | ||
118 | + */ | ||
119 | + public List<Bucket> getAllBuckets() throws Exception { | ||
120 | + return minioClient.listBuckets(); | ||
121 | + } | ||
122 | + | ||
123 | + /** | ||
124 | + * 根据bucketName获取信息 | ||
125 | + * | ||
126 | + * @param bucketName bucket名称 | ||
127 | + */ | ||
128 | + public Optional<Bucket> getBucket(String bucketName) throws IOException, InvalidKeyException, NoSuchAlgorithmException, InsufficientDataException, InvalidResponseException, InternalException, ErrorResponseException, ServerException, XmlParserException, ServerException { | ||
129 | + return minioClient.listBuckets().stream().filter(b -> b.name().equals(bucketName)).findFirst(); | ||
130 | + } | ||
131 | + | ||
132 | + /** | ||
133 | + * 根据bucketName删除信息 | ||
134 | + * | ||
135 | + * @param bucketName bucket名称 | ||
136 | + */ | ||
137 | + public void removeBucket(String bucketName) throws Exception { | ||
138 | + minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build()); | ||
139 | + } | ||
140 | + | ||
141 | + /** | ||
142 | + * 获取⽂件外链 | ||
143 | + * | ||
144 | + * @param bucketName bucket名称 | ||
145 | + * @param objectName ⽂件名称 | ||
146 | + * @param expires 过期时间 <=7 | ||
147 | + * @return url | ||
148 | + */ | ||
149 | + public String getObjectURL(String bucketName, String objectName, Integer expires) throws Exception { | ||
150 | + return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder().bucket(bucketName).object(objectName).expiry(expires).build()); | ||
151 | + } | ||
152 | + | ||
153 | + /** | ||
154 | + * 获取⽂件 | ||
155 | + * | ||
156 | + * @param bucketName bucket名称 | ||
157 | + * @param objectName ⽂件名称 | ||
158 | + * @return ⼆进制流 | ||
159 | + */ | ||
160 | + public InputStream getObject(String bucketName, String objectName) throws Exception { | ||
161 | + return minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(objectName).build()); | ||
162 | + } | ||
163 | + | ||
164 | + /** | ||
165 | + * 上传⽂件 | ||
166 | + * | ||
167 | + * @param bucketName bucket名称 | ||
168 | + * @param objectName ⽂件名称 | ||
169 | + * @param stream ⽂件流 | ||
170 | + * @throws Exception https:// docs.minio.io/cn/java-minioClient-api-reference.html#putObject | ||
171 | + */ | ||
172 | + public void putObject(String bucketName, String objectName, InputStream stream) throws | ||
173 | + Exception { | ||
174 | + minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(objectName).stream(stream, stream.available(), -1).contentType(objectName.substring(objectName.lastIndexOf("."))).build()); | ||
175 | + } | ||
176 | + | ||
177 | + /** | ||
178 | + * 上传⽂件 | ||
179 | + * | ||
180 | + * @param bucketName bucket名称 | ||
181 | + * @param objectName ⽂件名称 | ||
182 | + * @param stream ⽂件流 | ||
183 | + * @param size ⼤⼩ | ||
184 | + * @param contextType 类型 | ||
185 | + * @throws Exception https:// docs.minio.io/cn/java-minioClient-api-reference.html#putObject | ||
186 | + */ | ||
187 | + public void putObject(String bucketName, String objectName, InputStream stream, long | ||
188 | + size, String contextType) throws Exception { | ||
189 | + minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(objectName).stream(stream, size, -1).contentType(contextType).build()); | ||
190 | + } | ||
191 | + | ||
192 | + /** | ||
193 | + * 获取⽂件信息 | ||
194 | + * | ||
195 | + * @param bucketName bucket名称 | ||
196 | + * @param objectName ⽂件名称 | ||
197 | + * @throws Exception https:// docs.minio.io/cn/java-minioClient-api-reference.html#statObject | ||
198 | + */ | ||
199 | + public StatObjectResponse getObjectInfo(String bucketName, String objectName) throws Exception { | ||
200 | + return minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(objectName).build()); | ||
201 | + } | ||
202 | + | ||
203 | + /** | ||
204 | + * 删除⽂件 | ||
205 | + * | ||
206 | + * @param bucketName bucket名称 | ||
207 | + * @param objectName ⽂件名称 | ||
208 | + * @throws Exception https:// docs.minio.io/cn/java-minioClient-apireference.html#removeObject | ||
209 | + */ | ||
210 | + public void removeObject(String bucketName, String objectName) throws Exception { | ||
211 | + minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build()); | ||
212 | + } | ||
213 | + | ||
214 | + | ||
215 | + /*** | ||
216 | + * 上传视频 | ||
217 | + * @param file | ||
218 | + * @param bucketName | ||
219 | + * @return | ||
220 | + * @throws Exception | ||
221 | + */ | ||
222 | + public UploadResponse uploadVideo(MultipartFile file, String bucketName) throws Exception { | ||
223 | + // 判断文件是否为空 | ||
224 | + if (null == file || 0 == file.getSize()) { | ||
225 | + return null; | ||
226 | + } | ||
227 | + // 判断存储桶是否存在 不存在则创建 | ||
228 | + createBucket(bucketName); | ||
229 | + // 文件名 | ||
230 | + String originalFilename = file.getOriginalFilename(); | ||
231 | + // 新的文件名 = 时间戳_随机数.后缀名 | ||
232 | + assert originalFilename != null; | ||
233 | + long now = System.currentTimeMillis() / 1000; | ||
234 | + String format = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); | ||
235 | + String fileName = format + "_" + now + "_" + new Random().nextInt(1000) + | ||
236 | + originalFilename.substring(originalFilename.lastIndexOf(".")); | ||
237 | + // 开始上传 | ||
238 | + log.info("file大小:{}", file.getSize()); | ||
239 | + minioClient.putObject( | ||
240 | + PutObjectArgs.builder().bucket(bucketName).object(fileName).stream( | ||
241 | + file.getInputStream(), file.getSize(), -1) | ||
242 | + .contentType("video/mp4") | ||
243 | + .build()); | ||
244 | + String url = minioProperties.getEndpoint() + "/" + bucketName + "/" + fileName; | ||
245 | + String urlHost = minioProperties.getNginxHost() + "/" + bucketName + "/" + fileName; | ||
246 | + return new UploadResponse(url, urlHost); | ||
247 | + } | ||
248 | + | ||
249 | + /** | ||
250 | + * 文件下载 | ||
251 | + * | ||
252 | + * @param McFile 文件实体 | ||
253 | + * @param res response | ||
254 | + * @return Boolean | ||
255 | + */ | ||
256 | + public void download(McFile McFile, HttpServletResponse res) { | ||
257 | +// res.reset(); | ||
258 | + try (InputStream inputStream = minioClient.getObject(GetObjectArgs.builder() | ||
259 | + .bucket(minioProperties.getBucket()) | ||
260 | + .object(McFile.getUrl().substring(McFile.getUrl().indexOf("t/")+2)) | ||
261 | + .build())) { | ||
262 | + ServletOutputStream outputStream = res.getOutputStream(); | ||
263 | + res.setContentType("application/octet-stream"); | ||
264 | + res.setCharacterEncoding("utf-8"); | ||
265 | + res.addHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(McFile.getFileName(), "UTF-8")); | ||
266 | + byte[] bytes = new byte[1024]; | ||
267 | + int len; | ||
268 | + while ((len = inputStream.read(bytes)) > 0) { | ||
269 | + outputStream.write(bytes, 0, len); | ||
270 | + } | ||
271 | + outputStream.close(); | ||
272 | + } catch (Exception e) { | ||
273 | + e.printStackTrace(); | ||
274 | + } | ||
275 | + } | ||
276 | + | ||
277 | + /** | ||
278 | + * 批量下载 | ||
279 | + * | ||
280 | + * @param filenames | ||
281 | + * @param zip | ||
282 | + * @param res | ||
283 | + * @param req | ||
284 | + */ | ||
285 | + public void batchDownload(List<String> filenames, String zip, HttpServletResponse res, HttpServletRequest req) { | ||
286 | + try { | ||
287 | + BucketExistsArgs bucketArgs = BucketExistsArgs.builder().bucket(minioProperties.getBucket()).build(); | ||
288 | + boolean bucketExists = minioClient.bucketExists(bucketArgs); | ||
289 | + BufferedOutputStream bos = null; | ||
290 | + long now = System.currentTimeMillis() / 1000; | ||
291 | + String format = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); | ||
292 | + String fileName = format + "_" + now + "_" + new Random().nextInt(1000); | ||
293 | +// res.reset(); | ||
294 | + bos = new BufferedOutputStream(res.getOutputStream()); | ||
295 | + ZipOutputStream out = new ZipOutputStream(bos); | ||
296 | + res.setHeader("Access-Control-Allow-Origin", "*"); | ||
297 | + for (int i = 0; i < filenames.size(); i++) { | ||
298 | + GetObjectArgs objectArgs = GetObjectArgs.builder().bucket(minioProperties.getBucket()) | ||
299 | + .object(filenames.get(i)).build(); | ||
300 | + InputStream object = minioClient.getObject(objectArgs); | ||
301 | + byte buf[] = new byte[1024]; | ||
302 | + int length = 0; | ||
303 | + res.setCharacterEncoding("utf-8"); | ||
304 | + // 设置强制下载不打开 | ||
305 | + res.setContentType("application/force-download"); | ||
306 | + res.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); | ||
307 | + res.setHeader("Content-Disposition", "attachment;filename=" + filenameEncoding(fileName, req) + ".zip"); | ||
308 | + out.putNextEntry(new ZipEntry(filenames.get(i))); | ||
309 | + while ((length = object.read(buf)) > 0) { | ||
310 | + out.write(buf, 0, length); | ||
311 | + } | ||
312 | + } | ||
313 | + out.close(); | ||
314 | + bos.close(); | ||
315 | + } catch (Exception e) { | ||
316 | + e.printStackTrace(); | ||
317 | + } | ||
318 | + } | ||
319 | + | ||
320 | + public void batchDownload1(List<McFile> list, String zip, HttpServletResponse res, HttpServletRequest req) { | ||
321 | + try { | ||
322 | + BucketExistsArgs bucketArgs = BucketExistsArgs.builder().bucket(minioProperties.getBucket()).build(); | ||
323 | + boolean bucketExists = minioClient.bucketExists(bucketArgs); | ||
324 | + BufferedOutputStream bos = null; | ||
325 | + long now = System.currentTimeMillis() / 1000; | ||
326 | + String format = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); | ||
327 | + String fileName = format + "_" + now + "_" + new Random().nextInt(1000); | ||
328 | +// res.reset(); | ||
329 | + bos = new BufferedOutputStream(res.getOutputStream()); | ||
330 | + ZipOutputStream out = new ZipOutputStream(bos); | ||
331 | + res.setHeader("Access-Control-Allow-Origin", "*"); | ||
332 | + for (McFile McFile : list) { | ||
333 | + GetObjectArgs objectArgs = GetObjectArgs.builder().bucket(minioProperties.getBucket()) | ||
334 | + .object(McFile.getUrl().substring(McFile.getUrl().indexOf("t/")+2)).build(); | ||
335 | + InputStream object = minioClient.getObject(objectArgs); | ||
336 | + byte buf[] = new byte[1024]; | ||
337 | + int length = 0; | ||
338 | + res.setCharacterEncoding("utf-8"); | ||
339 | + // 设置强制下载不打开 | ||
340 | + res.setContentType("application/force-download"); | ||
341 | + res.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); | ||
342 | + res.setHeader("Content-Disposition", "attachment;filename=" + filenameEncoding(fileName, req) + ".zip"); | ||
343 | + out.putNextEntry(new ZipEntry(McFile.getFileName())); | ||
344 | + while ((length = object.read(buf)) > 0) { | ||
345 | + out.write(buf, 0, length); | ||
346 | + } | ||
347 | + } | ||
348 | + out.close(); | ||
349 | + bos.close(); | ||
350 | + } catch (Exception e) { | ||
351 | + e.printStackTrace(); | ||
352 | + } | ||
353 | + } | ||
354 | + | ||
355 | + /** | ||
356 | + * 设置不同浏览器编码 | ||
357 | + * | ||
358 | + * @param filename 文件名称 | ||
359 | + * @param request 请求对象 | ||
360 | + */ | ||
361 | + public static String filenameEncoding(String filename, HttpServletRequest request) throws UnsupportedEncodingException { | ||
362 | + // 获得请求头中的User-Agent | ||
363 | + String agent = request.getHeader("User-Agent"); | ||
364 | + // 根据不同的客户端进行不同的编码 | ||
365 | + | ||
366 | + if (agent.contains("MSIE")) { | ||
367 | + // IE浏览器 | ||
368 | + filename = URLEncoder.encode(filename, "utf-8"); | ||
369 | + } else if (agent.contains("Firefox")) { | ||
370 | + // 火狐浏览器 | ||
371 | + BASE64Encoder base64Encoder = new BASE64Encoder(); | ||
372 | + filename = "=?utf-8?B?" + base64Encoder.encode(filename.getBytes("utf-8")) + "?="; | ||
373 | + } else { | ||
374 | + // 其它浏览器 | ||
375 | + filename = URLEncoder.encode(filename, "utf-8"); | ||
376 | + } | ||
377 | + return filename; | ||
378 | + } | ||
379 | + | ||
380 | + /** | ||
381 | + * 预览图片 | ||
382 | + * | ||
383 | + * @param fileName | ||
384 | + * @return | ||
385 | + */ | ||
386 | + public String preview(String fileName) { | ||
387 | + // 查看文件地址 | ||
388 | + GetPresignedObjectUrlArgs build = new GetPresignedObjectUrlArgs().builder().bucket(minioProperties.getBucket()).object(fileName).method(Method.GET).build(); | ||
389 | + try { | ||
390 | + String url = minioClient.getPresignedObjectUrl(build); | ||
391 | + return url; | ||
392 | + } catch (Exception e) { | ||
393 | + e.printStackTrace(); | ||
394 | + } | ||
395 | + return null; | ||
396 | + } | ||
397 | + | ||
398 | + /** | ||
399 | + * 删除 | ||
400 | + * | ||
401 | + * @param fileName | ||
402 | + * @return | ||
403 | + * @throws Exception | ||
404 | + */ | ||
405 | + public boolean remove(String fileName) { | ||
406 | + try { | ||
407 | + minioClient.removeObject(RemoveObjectArgs.builder().bucket(minioProperties.getBucket()).object(fileName).build()); | ||
408 | + } catch (Exception e) { | ||
409 | + return false; | ||
410 | + } | ||
411 | + return true; | ||
412 | + } | ||
413 | +} |
zr-cloud/zr-modules/zr-schsf/src/main/java/com/chinagas/modules/schsf/utils/minio/UploadResponse.java
0 → 100644
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +package com.chinagas.modules.schsf.utils.minio; | ||
2 | + | ||
3 | +import lombok.AllArgsConstructor; | ||
4 | +import lombok.Data; | ||
5 | +import lombok.NoArgsConstructor; | ||
6 | + | ||
7 | +@Data | ||
8 | +@NoArgsConstructor | ||
9 | +@AllArgsConstructor | ||
10 | +public class UploadResponse { | ||
11 | + | ||
12 | + private String minIoUrl; | ||
13 | + | ||
14 | + private String nginxUrl; | ||
15 | +} |
zr-cloud/zr-modules/zr-schsf/src/main/resources/mapper/McFileMapper.xml
0 → 100644
@@ -0,0 +1,240 @@ | @@ -0,0 +1,240 @@ | ||
1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
2 | +<!DOCTYPE mapper | ||
3 | + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
4 | + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
5 | +<mapper namespace="com.chinagas.modules.schsf.mapper.McFileMapper"> | ||
6 | + <resultMap type="com.chinagas.modules.schsf.domain.McFile" id="McFileResult"> | ||
7 | + <result property="id" column="id"/> | ||
8 | + <result property="uuid" column="uuid"/> | ||
9 | + <result property="fileName" column="file_name"/> | ||
10 | + <result property="extension" column="extension"/> | ||
11 | + <result property="path" column="path"/> | ||
12 | + <result property="url" column="url"/> | ||
13 | + <result property="createTime" column="create_time"/> | ||
14 | + <result property="createBy" column="create_by"/> | ||
15 | + <result property="updateTime" column="update_time"/> | ||
16 | + <result property="updateBy" column="update_by"/> | ||
17 | + <result property="defFlag" column="def_flag"/> | ||
18 | + <result property="cited" column="cited"/> | ||
19 | + <result property="count" column="count"/> | ||
20 | + <result property="fileSize" column="file_size"/> | ||
21 | + </resultMap> | ||
22 | + | ||
23 | + <sql id="selectMcFileVo"> | ||
24 | + select id, | ||
25 | + uuid, | ||
26 | + file_name, | ||
27 | + extension, | ||
28 | + path, | ||
29 | + url, | ||
30 | + create_time, | ||
31 | + create_by, | ||
32 | + update_time, | ||
33 | + update_by, | ||
34 | + def_flag, | ||
35 | + cited, | ||
36 | + count, | ||
37 | + file_size | ||
38 | + from mc_file | ||
39 | + </sql> | ||
40 | + | ||
41 | + <select id="selectMcFileList" parameterType="com.chinagas.modules.schsf.domain.McFile" resultMap="McFileResult"> | ||
42 | + <include refid="selectMcFileVo"/> | ||
43 | + <where> | ||
44 | + <if test="uuid != null and uuid != ''"> | ||
45 | + and uuid = #{uuid} | ||
46 | + </if> | ||
47 | + <if test="fileName != null and fileName != ''"> | ||
48 | + and file_name like concat('%', #{fileName}, '%') | ||
49 | + </if> | ||
50 | + <if test="extension != null and extension != ''"> | ||
51 | + and extension = #{extension} | ||
52 | + </if> | ||
53 | + <if test="path != null and path != ''"> | ||
54 | + and path = #{path} | ||
55 | + </if> | ||
56 | + <if test="url != null and url != ''"> | ||
57 | + and url = #{url} | ||
58 | + </if> | ||
59 | + <if test="defFlag != null and defFlag != ''"> | ||
60 | + and def_flag = #{defFlag} | ||
61 | + </if> | ||
62 | + <if test="cited != null and cited != ''"> | ||
63 | + and cited = #{cited} | ||
64 | + </if> | ||
65 | + <if test="count != null"> | ||
66 | + and count = #{count} | ||
67 | + </if> | ||
68 | + <if test="fileSize != null"> | ||
69 | + and file_size = #{fileSize} | ||
70 | + </if> | ||
71 | + </where> | ||
72 | + </select> | ||
73 | + | ||
74 | + <select id="selectMcFileById" parameterType="Long" resultMap="McFileResult"> | ||
75 | + <include refid="selectMcFileVo"/> | ||
76 | + where id = #{id} | ||
77 | + </select> | ||
78 | + | ||
79 | + | ||
80 | + | ||
81 | + <select id="selectMcFileByUuid" parameterType="String" resultMap="McFileResult"> | ||
82 | + <include refid="selectMcFileVo"/> | ||
83 | + where uuid = #{uuid} | ||
84 | + </select> | ||
85 | + | ||
86 | + | ||
87 | + | ||
88 | + | ||
89 | + <insert id="insertMcFile" parameterType="com.chinagas.modules.schsf.domain.McFile"> | ||
90 | + insert into mc_file | ||
91 | + <trim prefix="(" suffix=")" suffixOverrides=","> | ||
92 | + <if test="id != null"> | ||
93 | + id, | ||
94 | + </if> | ||
95 | + <if test="uuid != null"> | ||
96 | + uuid, | ||
97 | + </if> | ||
98 | + <if test="fileName != null"> | ||
99 | + file_name, | ||
100 | + </if> | ||
101 | + <if test="extension != null"> | ||
102 | + extension, | ||
103 | + </if> | ||
104 | + <if test="path != null"> | ||
105 | + path, | ||
106 | + </if> | ||
107 | + <if test="url != null"> | ||
108 | + url, | ||
109 | + </if> | ||
110 | + <if test="createTime != null"> | ||
111 | + create_time, | ||
112 | + </if> | ||
113 | + <if test="createBy != null"> | ||
114 | + create_by, | ||
115 | + </if> | ||
116 | + <if test="updateTime != null"> | ||
117 | + update_time, | ||
118 | + </if> | ||
119 | + <if test="updateBy != null"> | ||
120 | + update_by, | ||
121 | + </if> | ||
122 | + <if test="defFlag != null"> | ||
123 | + def_flag, | ||
124 | + </if> | ||
125 | + <if test="cited != null"> | ||
126 | + cited, | ||
127 | + </if> | ||
128 | + <if test="count != null"> | ||
129 | + count, | ||
130 | + </if> | ||
131 | + <if test="fileSize != null"> | ||
132 | + file_size, | ||
133 | + </if> | ||
134 | + </trim> | ||
135 | + <trim prefix="values (" suffix=")" suffixOverrides=","> | ||
136 | + <if test="id != null"> | ||
137 | + #{id}, | ||
138 | + </if> | ||
139 | + <if test="uuid != null"> | ||
140 | + #{uuid}, | ||
141 | + </if> | ||
142 | + <if test="fileName != null"> | ||
143 | + #{fileName}, | ||
144 | + </if> | ||
145 | + <if test="extension != null"> | ||
146 | + #{extension}, | ||
147 | + </if> | ||
148 | + <if test="path != null"> | ||
149 | + #{path}, | ||
150 | + </if> | ||
151 | + <if test="url != null"> | ||
152 | + #{url}, | ||
153 | + </if> | ||
154 | + <if test="createTime != null"> | ||
155 | + #{createTime}, | ||
156 | + </if> | ||
157 | + <if test="createBy != null"> | ||
158 | + #{createBy}, | ||
159 | + </if> | ||
160 | + <if test="updateTime != null"> | ||
161 | + #{updateTime}, | ||
162 | + </if> | ||
163 | + <if test="updateBy != null"> | ||
164 | + #{updateBy}, | ||
165 | + </if> | ||
166 | + <if test="defFlag != null"> | ||
167 | + #{defFlag}, | ||
168 | + </if> | ||
169 | + <if test="cited != null"> | ||
170 | + #{cited}, | ||
171 | + </if> | ||
172 | + <if test="count != null"> | ||
173 | + #{count}, | ||
174 | + </if> | ||
175 | + <if test="fileSize != null"> | ||
176 | + #{fileSize}, | ||
177 | + </if> | ||
178 | + </trim> | ||
179 | + </insert> | ||
180 | + | ||
181 | + <update id="updateMcFile" parameterType="com.chinagas.modules.schsf.domain.McFile"> | ||
182 | + update mc_file | ||
183 | + <trim prefix="SET" suffixOverrides=","> | ||
184 | + <if test="uuid != null"> | ||
185 | + uuid = #{uuid}, | ||
186 | + </if> | ||
187 | + <if test="fileName != null"> | ||
188 | + file_name = #{fileName}, | ||
189 | + </if> | ||
190 | + <if test="extension != null"> | ||
191 | + extension = #{extension}, | ||
192 | + </if> | ||
193 | + <if test="path != null"> | ||
194 | + path = #{path}, | ||
195 | + </if> | ||
196 | + <if test="url != null"> | ||
197 | + url = #{url}, | ||
198 | + </if> | ||
199 | + <if test="createTime != null"> | ||
200 | + create_time = #{createTime}, | ||
201 | + </if> | ||
202 | + <if test="createBy != null"> | ||
203 | + create_by = #{createBy}, | ||
204 | + </if> | ||
205 | + <if test="updateTime != null"> | ||
206 | + update_time = #{updateTime}, | ||
207 | + </if> | ||
208 | + <if test="updateBy != null"> | ||
209 | + update_by = #{updateBy}, | ||
210 | + </if> | ||
211 | + <if test="defFlag != null"> | ||
212 | + def_flag = #{defFlag}, | ||
213 | + </if> | ||
214 | + <if test="cited != null"> | ||
215 | + cited = #{cited}, | ||
216 | + </if> | ||
217 | + <if test="count != null"> | ||
218 | + count = #{count}, | ||
219 | + </if> | ||
220 | + <if test="fileSize != null"> | ||
221 | + file_size = #{fileSize}, | ||
222 | + </if> | ||
223 | + </trim> | ||
224 | + where id = #{id} | ||
225 | + </update> | ||
226 | + | ||
227 | + <delete id="deleteMcFileById" parameterType="Long"> | ||
228 | + delete | ||
229 | + from mc_file | ||
230 | + where id = #{id} | ||
231 | + </delete> | ||
232 | + | ||
233 | + <delete id="deleteMcFileByIds" parameterType="String"> | ||
234 | + delete | ||
235 | + from mc_file where id in | ||
236 | + <foreach item="id" collection="array" open="(" separator="," close=")"> | ||
237 | + #{id} | ||
238 | + </foreach> | ||
239 | + </delete> | ||
240 | +</mapper> |