|
@@ -6,19 +6,18 @@ import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.file.entity.*;
|
|
|
import com.fjhx.file.mapper.FileInfoMapper;
|
|
|
import com.fjhx.file.service.FileInfoService;
|
|
|
import com.obs.services.ObsClient;
|
|
|
-import com.obs.services.model.PostSignatureRequest;
|
|
|
-import com.obs.services.model.PostSignatureResponse;
|
|
|
+import com.obs.services.model.PutObjectRequest;
|
|
|
import com.ruoyi.common.constant.BaseSourceConstant;
|
|
|
import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
@@ -26,8 +25,9 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -84,29 +84,29 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
|
.add(IdUtil.fastSimpleUUID() + (ObjectUtil.isEmpty(suffix) ? "" : "." + suffix))
|
|
|
.toString();
|
|
|
|
|
|
- ObsClient obsClient = null;
|
|
|
-
|
|
|
- try {
|
|
|
- // 获取oss链接客户端
|
|
|
- obsClient = getObsClient();
|
|
|
- // 指定签名有效期为10秒
|
|
|
- long currentTimeMillis = System.currentTimeMillis() + 1000 * 10;
|
|
|
- // 获取签名
|
|
|
- PostSignatureRequest request = new PostSignatureRequest(currentTimeMillis, bucketName, objectKey);
|
|
|
- PostSignatureResponse temporarySignature = obsClient.createPostSignature(request);
|
|
|
+// ObsClient obsClient = null;
|
|
|
+//
|
|
|
+// try {
|
|
|
+// // 获取oss链接客户端
|
|
|
+// obsClient = getObsClient();
|
|
|
+// // 指定签名有效期为10秒
|
|
|
+// long currentTimeMillis = System.currentTimeMillis() + 1000 * 10;
|
|
|
+// // 获取签名
|
|
|
+// PostSignatureRequest request = new PostSignatureRequest(currentTimeMillis, bucketName, objectKey);
|
|
|
+// PostSignatureResponse temporarySignature = obsClient.createPostSignature(request);
|
|
|
// 封装签名
|
|
|
Map<String, String> body = new LinkedHashMap<>();
|
|
|
- body.put("policy", temporarySignature.getPolicy());
|
|
|
+// body.put("policy", temporarySignature.getPolicy());
|
|
|
body.put("AccessKeyId", ak);
|
|
|
- body.put("signature", temporarySignature.getSignature());
|
|
|
+// body.put("signature", temporarySignature.getSignature());
|
|
|
body.put("key", objectKey);
|
|
|
singVo.setUploadBody(body);
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- throw new ServiceException("获取签名失败");
|
|
|
- } finally {
|
|
|
- IoUtil.close(obsClient);
|
|
|
- }
|
|
|
+//
|
|
|
+// } catch (Exception e) {
|
|
|
+// throw new ServiceException("获取签名失败");
|
|
|
+// } finally {
|
|
|
+// IoUtil.close(obsClient);
|
|
|
+// }
|
|
|
|
|
|
// 保存文件
|
|
|
FileInfo fileInfo = new FileInfo();
|
|
@@ -115,7 +115,8 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
|
save(fileInfo);
|
|
|
|
|
|
// 封装文件信息
|
|
|
- singVo.setUploadUrl("https://" + bucketName + "." + endPoint);
|
|
|
+// singVo.setUploadUrl("https://" + bucketName + "." + endPoint);
|
|
|
+ singVo.setUploadUrl("/open/fileInfo/upload");
|
|
|
singVo.setId(fileInfo.getId());
|
|
|
singVo.setFileName(dto.getFileName());
|
|
|
singVo.setFileUrl(url + objectKey);
|
|
@@ -123,6 +124,26 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
|
return singVo;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void upload(UploadBodyDto uploadBody) {
|
|
|
+ MultipartFile file = uploadBody.getFile();
|
|
|
+ String objectKey = uploadBody.getKey();
|
|
|
+
|
|
|
+ ObsClient obsClient = getObsClient();
|
|
|
+ try {
|
|
|
+ PutObjectRequest putObjectRequest = new PutObjectRequest();
|
|
|
+ putObjectRequest.setBucketName(bucketName);
|
|
|
+ putObjectRequest.setObjectKey(objectKey);
|
|
|
+ putObjectRequest.setInput(file.getInputStream());
|
|
|
+ obsClient.putObject(putObjectRequest);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ throw new ServiceException("文件上传失败!");
|
|
|
+ } finally {
|
|
|
+ IoUtil.close(obsClient);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@DS(BaseSourceConstant.BASE)
|
|
|
@Override
|
|
|
public Map<Long, List<FileInfoVo>> getList(FileInfoSelectDto dto) {
|
|
@@ -169,6 +190,7 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
|
|
|
|
/**
|
|
|
* 保存文件--直接插入
|
|
|
+ *
|
|
|
* @param obsFileList 文件列表
|
|
|
* @param businessId 业务id
|
|
|
* @param businessType 业务文件类型
|
|
@@ -189,7 +211,6 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
* @param obsFileList 文件列表
|
|
|
* @param businessId 业务id
|
|
|
* @param businessType 业务文件类型
|
|
@@ -238,22 +259,23 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
|
|
|
|
/**
|
|
|
* 交换业务ID
|
|
|
- * @param oldBusinessId 旧业务id
|
|
|
- * @param newBusinessId 新业务id
|
|
|
+ *
|
|
|
+ * @param oldBusinessId 旧业务id
|
|
|
+ * @param newBusinessId 新业务id
|
|
|
*/
|
|
|
@DS(BaseSourceConstant.BASE)
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void exchangeBusinessId(Long oldBusinessId, Long newBusinessId) {
|
|
|
- List<FileInfo> oldFile = this.list(Wrappers.<FileInfo>query().lambda().select(FileInfo::getId).eq(FileInfo::getBusinessId,oldBusinessId));
|
|
|
- List<FileInfo> newFile = this.list(Wrappers.<FileInfo>query().lambda().select(FileInfo::getId).eq(FileInfo::getBusinessId,newBusinessId));
|
|
|
- if(CollectionUtils.isNotEmpty(oldFile)){
|
|
|
+ List<FileInfo> oldFile = this.list(Wrappers.<FileInfo>query().lambda().select(FileInfo::getId).eq(FileInfo::getBusinessId, oldBusinessId));
|
|
|
+ List<FileInfo> newFile = this.list(Wrappers.<FileInfo>query().lambda().select(FileInfo::getId).eq(FileInfo::getBusinessId, newBusinessId));
|
|
|
+ if (CollectionUtils.isNotEmpty(oldFile)) {
|
|
|
List<Long> ids = oldFile.stream().map(FileInfo::getId).collect(Collectors.toList());
|
|
|
- this.update(Wrappers.<FileInfo>update().lambda().set(FileInfo::getBusinessId,newBusinessId).in(FileInfo::getId,ids));
|
|
|
+ this.update(Wrappers.<FileInfo>update().lambda().set(FileInfo::getBusinessId, newBusinessId).in(FileInfo::getId, ids));
|
|
|
}
|
|
|
- if(CollectionUtils.isNotEmpty(newFile)){
|
|
|
+ if (CollectionUtils.isNotEmpty(newFile)) {
|
|
|
List<Long> ids = newFile.stream().map(FileInfo::getId).collect(Collectors.toList());
|
|
|
- this.update(Wrappers.<FileInfo>update().lambda().set(FileInfo::getBusinessId,oldBusinessId).in(FileInfo::getId,ids));
|
|
|
+ this.update(Wrappers.<FileInfo>update().lambda().set(FileInfo::getBusinessId, oldBusinessId).in(FileInfo::getId, ids));
|
|
|
}
|
|
|
}
|
|
|
|