d93c14b8 by 荆蔚杰

升级minio sdk版本,代码修改中

minio批量删除接口修改.
附件删除接口bug修改.
1 parent 3eb2e4dc
...@@ -229,7 +229,7 @@ ...@@ -229,7 +229,7 @@
229 <dependency> 229 <dependency>
230 <groupId>io.minio</groupId> 230 <groupId>io.minio</groupId>
231 <artifactId>minio</artifactId> 231 <artifactId>minio</artifactId>
232 <version>6.0.11</version> 232 <version>8.3.4</version>
233 </dependency> 233 </dependency>
234 234
235 <dependency> 235 <dependency>
......
1 package com.pashanhoo.common.util.fileupload; 1 package com.pashanhoo.common.util.fileupload;
2 2
3 import com.pashanhoo.common.Result; 3 import com.pashanhoo.common.Result;
4 import io.minio.messages.DeleteError;
4 import io.swagger.annotations.Api; 5 import io.swagger.annotations.Api;
5 import io.swagger.annotations.ApiOperation; 6 import io.swagger.annotations.ApiOperation;
6 import io.swagger.annotations.ApiParam; 7 import io.swagger.annotations.ApiParam;
...@@ -10,6 +11,7 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -10,6 +11,7 @@ import org.springframework.web.multipart.MultipartFile;
10 11
11 import javax.servlet.http.HttpServletResponse; 12 import javax.servlet.http.HttpServletResponse;
12 import java.io.IOException; 13 import java.io.IOException;
14 import java.util.ArrayList;
13 import java.util.List; 15 import java.util.List;
14 16
15 /** 17 /**
...@@ -58,4 +60,20 @@ public class FileController { ...@@ -58,4 +60,20 @@ public class FileController {
58 } 60 }
59 } 61 }
60 62
63 @DeleteMapping("/batchDeleteFile")
64 @ApiOperation("批量删除文件")
65 public Result batchDeleteFile(@ApiParam("存储url集合") @RequestBody List<String> saveUrls){
66 try {
67 List<String> msg = new ArrayList<>();
68 Iterable<io.minio.Result<DeleteError>> results = minioUtil.batchRemove(minioConfig.getBucket(), saveUrls);
69 for (io.minio.Result<DeleteError> result : results) {
70 DeleteError deleteError = result.get();
71 msg.add("Error in deleting object " + deleteError.objectName() + ":" + deleteError.message());
72 }
73 return Result.ok(msg.toString());
74 } catch (Exception e) {
75 return Result.exception(e.getMessage());
76 }
77 }
78
61 } 79 }
......
1 package com.pashanhoo.common.util.fileupload; 1 package com.pashanhoo.common.util.fileupload;
2 2
3 import com.pashanhoo.file.entity.vo.FileAttribute; 3 import com.pashanhoo.file.entity.vo.FileAttribute;
4 import io.minio.MinioClient; 4 import io.minio.*;
5 import io.minio.Result;
6 import io.minio.errors.*;
7 import io.minio.messages.DeleteError; 5 import io.minio.messages.DeleteError;
6 import io.minio.messages.DeleteObject;
8 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
10 import org.springframework.util.Assert; 9 import org.springframework.util.Assert;
11 import org.springframework.util.StringUtils; 10 import org.springframework.util.StringUtils;
12 import org.springframework.web.multipart.MultipartFile; 11 import org.springframework.web.multipart.MultipartFile;
13 import org.xmlpull.v1.XmlPullParserException;
14 12
15 import javax.annotation.PostConstruct; 13 import javax.annotation.PostConstruct;
16 import java.io.IOException; 14 import java.io.IOException;
17 import java.io.InputStream; 15 import java.io.InputStream;
18 import java.security.InvalidKeyException;
19 import java.security.NoSuchAlgorithmException;
20 import java.util.*; 16 import java.util.*;
21 17
22 /** 18 /**
...@@ -32,8 +28,13 @@ public class MinioUtil { ...@@ -32,8 +28,13 @@ public class MinioUtil {
32 @PostConstruct 28 @PostConstruct
33 public void init() { 29 public void init() {
34 try { 30 try {
35 minioClient = new MinioClient(String.format("http://%s:%s", minioConfig.getEndpoint(), minioConfig.getPort()), minioConfig.getAccessKeyId(), minioConfig.getAccessKeySecret()); 31 minioClient = MinioClient.builder().endpoint(String.format("http://%s:%s", minioConfig.getEndpoint(), minioConfig.getPort())).credentials(minioConfig.getAccessKeyId(), minioConfig.getAccessKeySecret()).build();
36 } catch (InvalidEndpointException | InvalidPortException e) { 32 boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(minioConfig.getBucket()).build());
33 if (!isExist) {
34 minioClient.makeBucket(MakeBucketArgs.builder().bucket(minioConfig.getBucket()).build());
35 }
36 // minioClient = new MinioClient(String.format("http://%s:%s", minioConfig.getEndpoint(), minioConfig.getPort()), minioConfig.getAccessKeyId(), minioConfig.getAccessKeySecret());
37 } catch (Exception e) {
37 e.printStackTrace(); 38 e.printStackTrace();
38 } 39 }
39 } 40 }
...@@ -63,7 +64,8 @@ public class MinioUtil { ...@@ -63,7 +64,8 @@ public class MinioUtil {
63 // 浏览器直接预览地址,针对图片 64 // 浏览器直接预览地址,针对图片
64 String pUrl = minioConfig.getType() + minioConfig.getEndpoint() + "/file/" + saveUrl; 65 String pUrl = minioConfig.getType() + minioConfig.getEndpoint() + "/file/" + saveUrl;
65 try { 66 try {
66 minioClient.putObject(minioConfig.getBucket(), saveUrl, file.getInputStream(), contentType); 67 minioClient.putObject(PutObjectArgs.builder().bucket(minioConfig.getBucket()).object(saveUrl).stream(file.getInputStream(), file.getSize(), -1).contentType(contentType).build());
68 // minioClient.putObject(minioConfig.getBucket(), saveUrl, file.getInputStream(), contentType);
67 } catch (Exception e) { 69 } catch (Exception e) {
68 e.printStackTrace(); 70 e.printStackTrace();
69 } 71 }
...@@ -101,20 +103,27 @@ public class MinioUtil { ...@@ -101,20 +103,27 @@ public class MinioUtil {
101 * @throws Exception 103 * @throws Exception
102 */ 104 */
103 public void removeObject(String bucketName, String objectName) throws Exception { 105 public void removeObject(String bucketName, String objectName) throws Exception {
104 minioClient.removeObject(bucketName, objectName); 106 minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build());
105 } 107 }
106 108
107 /** 109 /**
108 * 批量删除附件 110 * 批量删除附件
111 *
109 * @param bucketName 存储桶名称 112 * @param bucketName 存储桶名称
110 * @param objectNames 附件存储路径集合 113 * @param objectNames 附件存储路径集合
111 */ 114 */
112 public Iterable batchRemove(String bucketName,Iterable<String> objectNames){ 115 public Iterable<Result<DeleteError>> batchRemove(String bucketName, List<String> objectNames) {
113 return minioClient.removeObjects(bucketName, objectNames); 116 List<DeleteObject> objects = new ArrayList<>(objectNames.size());
117 for (String objectName : objectNames) {
118 objects.add(new DeleteObject(objectName));
119 }
120 Iterable<Result<DeleteError>> results = minioClient.removeObjects(RemoveObjectsArgs.builder().bucket(bucketName).objects(objects).build());
121 return results;
114 } 122 }
115 123
116 /** 124 /**
117 * 通过输入流上传到minio 125 * 通过输入流上传到minio
126 *
118 * @param inputStream 文件输入流 127 * @param inputStream 文件输入流
119 * @param fileName 文件名,去除后缀名 128 * @param fileName 文件名,去除后缀名
120 * @param expandName 带.后缀名 129 * @param expandName 带.后缀名
...@@ -122,7 +131,7 @@ public class MinioUtil { ...@@ -122,7 +131,7 @@ public class MinioUtil {
122 * @return 131 * @return
123 * @throws IOException 132 * @throws IOException
124 */ 133 */
125 public FileAttribute transferToMinio(InputStream inputStream, String fileName, String expandName,String fileSize) throws IOException { 134 public FileAttribute transferToMinio(InputStream inputStream, String fileName, String expandName, String fileSize) throws IOException {
126 String savePath = FileAttachmentUtil.getSavePath(UUID.randomUUID().toString()); 135 String savePath = FileAttachmentUtil.getSavePath(UUID.randomUUID().toString());
127 String contentType = contentTypeMap.get(expandName.toLowerCase()); 136 String contentType = contentTypeMap.get(expandName.toLowerCase());
128 // 下载地址 137 // 下载地址
...@@ -130,7 +139,8 @@ public class MinioUtil { ...@@ -130,7 +139,8 @@ public class MinioUtil {
130 // 浏览器直接预览地址,针对图片 139 // 浏览器直接预览地址,针对图片
131 String pUrl = minioConfig.getType() + minioConfig.getEndpoint() + "/file/" + saveUrl; 140 String pUrl = minioConfig.getType() + minioConfig.getEndpoint() + "/file/" + saveUrl;
132 try { 141 try {
133 minioClient.putObject(minioConfig.getBucket(), saveUrl, inputStream, contentType); 142 minioClient.putObject(PutObjectArgs.builder().bucket(minioConfig.getBucket()).object(saveUrl).stream(inputStream, Long.parseLong(fileSize),-1).contentType(contentType).build());
143 // minioClient.putObject(minioConfig.getBucket(), saveUrl, inputStream, contentType);
134 } catch (Exception e) { 144 } catch (Exception e) {
135 e.printStackTrace(); 145 e.printStackTrace();
136 } 146 }
......
...@@ -43,7 +43,7 @@ public class DgFileController { ...@@ -43,7 +43,7 @@ public class DgFileController {
43 @ApiOperation(value = "批量删除档案文件信息和附件") 43 @ApiOperation(value = "批量删除档案文件信息和附件")
44 public Result deleteDgFileByIds(@ApiParam("档案文件信息ID列表") @RequestBody List<String> bsmFileList) { 44 public Result deleteDgFileByIds(@ApiParam("档案文件信息ID列表") @RequestBody List<String> bsmFileList) {
45 try { 45 try {
46 if (dgfileService.delete(bsmFileList)) { 46 if (dgfileService.deleteFile(bsmFileList)) {
47 return Result.ok("删除成功"); 47 return Result.ok("删除成功");
48 } 48 }
49 } catch (Exception e) { 49 } catch (Exception e) {
......
...@@ -28,10 +28,5 @@ public interface DgFileMapper extends BaseMapper<DgFileDO> { ...@@ -28,10 +28,5 @@ public interface DgFileMapper extends BaseMapper<DgFileDO> {
28 */ 28 */
29 List<DgCatalogWithFileVO> getFileList(@Param("bsmArchive") String bsmArchive); 29 List<DgCatalogWithFileVO> getFileList(@Param("bsmArchive") String bsmArchive);
30 30
31 // /** 31 List<DgFileDO> getFilesById(@Param("bsmFiles") List<String> bsmFiles);
32 // * 更新排序
33 // * @param requests
34 // * @return
35 // */
36 // int updateFileSort(@Param("requests") List<UpdateDgFileRequest> requests);
37 } 32 }
......
...@@ -56,7 +56,7 @@ public interface DgFileService extends IService<DgFileDO> { ...@@ -56,7 +56,7 @@ public interface DgFileService extends IService<DgFileDO> {
56 * @param bsmFileList 56 * @param bsmFileList
57 * @return 57 * @return
58 */ 58 */
59 boolean delete(List<String> bsmFileList) throws Exception; 59 boolean deleteFile(List<String> bsmFileList) throws Exception;
60 60
61 /** 61 /**
62 * 上传材料附件.材料附件信息入库 62 * 上传材料附件.材料附件信息入库
......
...@@ -11,6 +11,8 @@ import com.pashanhoo.file.entity.DgFileDO; ...@@ -11,6 +11,8 @@ import com.pashanhoo.file.entity.DgFileDO;
11 import com.pashanhoo.file.entity.vo.*; 11 import com.pashanhoo.file.entity.vo.*;
12 import com.pashanhoo.file.mapper.DgFileMapper; 12 import com.pashanhoo.file.mapper.DgFileMapper;
13 import com.pashanhoo.file.service.DgFileService; 13 import com.pashanhoo.file.service.DgFileService;
14 import io.minio.Result;
15 import io.minio.messages.DeleteError;
14 import org.springframework.beans.factory.annotation.Autowired; 16 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
16 import org.springframework.transaction.annotation.Transactional; 18 import org.springframework.transaction.annotation.Transactional;
...@@ -18,6 +20,7 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -18,6 +20,7 @@ import org.springframework.web.multipart.MultipartFile;
18 20
19 21
20 import java.util.List; 22 import java.util.List;
23 import java.util.stream.Collectors;
21 24
22 /** 25 /**
23 * <p> 26 * <p>
...@@ -109,16 +112,19 @@ public class DgFileServiceImpl extends ServiceImpl<DgFileMapper, DgFileDO> imple ...@@ -109,16 +112,19 @@ public class DgFileServiceImpl extends ServiceImpl<DgFileMapper, DgFileDO> imple
109 * @return 112 * @return
110 */ 113 */
111 @Override 114 @Override
112 public boolean delete(List<String> bsmFileList) throws Exception { 115 public boolean deleteFile(List<String> bsmFileList) throws Exception {
113 boolean flag = this.removeByIds(bsmFileList);
114 116
115 QueryWrapper<DgFileDO> fileWrapper = new QueryWrapper<>(); 117 //删除minio文件
116 fileWrapper.lambda().in(DgFileDO::getBsmFile, bsmFileList); 118 List<DgFileDO> fileDOList = dgfileMapper.getFilesById(bsmFileList);
117 List<DgFileDO> fileDOList = this.list(fileWrapper); 119 List<String> urls = fileDOList.stream().map(DgFileDO::getFjurl).collect(Collectors.toList());
118 for (DgFileDO fileDO : fileDOList) { 120 for (String url : urls) {
119 minioUtil.removeObject(minioConfig.getBucket(),fileDO.getFjurl()); 121 minioUtil.removeObject(minioConfig.getBucket(), url);
120 } 122 }
121 return flag; 123
124 // Iterable<Result<DeleteError>> results = minioUtil.batchRemove(minioConfig.getBucket(), urls);
125
126 //删除数据库记录
127 return this.removeByIds(bsmFileList);
122 } 128 }
123 129
124 /** 130 /**
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
43 </resultMap> 43 </resultMap>
44 44
45 <select id="getFileList" resultMap="result"> 45 <select id="getFileList" resultMap="result">
46 select DF.*, DAC.XH as catalogXh, DAC.WJMC,DAC.BSM_CATALOG as bsmCatalog,DA.BSM_ARCHIVES 46 select DF.*, DAC.XH as catalogXh, DAC.WJMC, DAC.BSM_CATALOG as bsmCatalog, DA.BSM_ARCHIVES
47 from DG_FILE DF 47 from DG_FILE DF
48 right join DG_ARCHIVES_CATALOG DAC on DAC.BSM_CATALOG = DF.BSM_CATALOG 48 right join DG_ARCHIVES_CATALOG DAC on DAC.BSM_CATALOG = DF.BSM_CATALOG
49 join DG_ARCHIVES DA on DAC.BSM_ARCHIVES = DA.BSM_ARCHIVES 49 join DG_ARCHIVES DA on DAC.BSM_ARCHIVES = DA.BSM_ARCHIVES
...@@ -52,7 +52,19 @@ ...@@ -52,7 +52,19 @@
52 DAC.BSM_ARCHIVES = #{bsmArchive,jdbcType=VARCHAR} 52 DAC.BSM_ARCHIVES = #{bsmArchive,jdbcType=VARCHAR}
53 </if> 53 </if>
54 </where> 54 </where>
55 order by DF.XH,DAC.XH 55 order by DF.XH, DAC.XH
56 </select>
57
58 <select id="getFilesById" resultMap="BaseResultMap">
59 select *
60 from DG_FILE
61 where
62 BSM_FILE in
63 <if test="bsmFiles != null and bsmFiles.size() != 0">
64 <foreach collection="bsmFiles" item="bsmFile" open="(" close=")" separator=",">
65 #{bsmFile,jdbcType=VARCHAR}
66 </foreach>
67 </if>
56 </select> 68 </select>
57 69
58 <!--<update id="updateFileSort">--> 70 <!--<update id="updateFileSort">-->
......