sdk 新增文件复制方法

This commit is contained in:
付庆吉
2021-07-09 15:14:08 +08:00
parent 5e16cb904f
commit e9f667107a
5 changed files with 458 additions and 376 deletions

View File

@ -1,14 +1,14 @@
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.api;
import java.io.File;
import java.util.List;
import java.util.Optional;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentDetail;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentEntity;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.DownloadEntity;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.UploadObject;
import java.io.File;
import java.util.List;
import java.util.Optional;
/**
* 附件客户端工具类
*
@ -103,4 +103,20 @@ public interface AttachmentClient {
*/
String deleteByOid(String objectId);
/**
* 根据业务id复制附件
*
* @param oldBusinessId
* @param newBusinessId
*/
AttachmentDetail copyByBid(String oldBusinessId, String newBusinessId);
/**
* 根据对象id复制附件
*
* @param objectId
* @param newBusinessId
*/
Optional<AttachmentEntity> copyByOid(String objectId, String newBusinessId);
}

View File

@ -1,21 +1,6 @@
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.api;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import cn.hutool.core.util.IdUtil;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.convertor.FileConvertor;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.convertor.ModelConvertor;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentDetail;
@ -23,10 +8,20 @@ import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentEntity;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.DownloadEntity;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.UploadObject;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.service.DocumentCenterService;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.SysStorageVO;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.query.QueryResult;
import cn.hutool.core.util.IdUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import javax.validation.constraints.NotNull;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* 附件工具客户端默认实现
@ -39,13 +34,16 @@ import lombok.extern.slf4j.Slf4j;
public class DefaultAttachmentClient implements AttachmentClient {
/* 附件工具类服务 */
private @Autowired DocumentCenterService documentCenterService;
private @Autowired
DocumentCenterService documentCenterService;
/* 模型转换器 */
private @Autowired ModelConvertor modelConvertor;
private @Autowired
ModelConvertor modelConvertor;
/* 文件转换器 */
private @Autowired FileConvertor fileConvertor;
private @Autowired
FileConvertor fileConvertor;
/**
* 生成业务id
@ -253,7 +251,49 @@ public class DefaultAttachmentClient implements AttachmentClient {
return documentCenterService.deleteByOid(objectId);
}
/**
* 根据业务id复制附件
*
* @param businessId
*/
@Override
public AttachmentDetail copyByBid(String businessId, String newBusinessId) {
AttachmentDetail result = new AttachmentDetail();
this.findByBusinessId(Collections.singletonList(businessId))
.ifPresent(attachmentDetail ->
attachmentDetail.get(businessId).forEach(
o -> this.copyByOid(o.getId(), newBusinessId).ifPresent(result::add)));
return result;
}
/**
* 根据对象id复制附件
*
* @param objectId
*/
@Override
public Optional<AttachmentEntity> copyByOid(String objectId, String newBusinessId) {
//复制
Optional<UploadObject> opt = modelConvertor.toUploadObject(documentCenterService.copyByOid(objectId));
//修改bid
if (opt.isPresent()) {
UploadObject uploadObject = opt.get();
String json = documentCenterService.updateByBid(Collections.singletonList(new SysStorageVO().setFileId(uploadObject.getId()).setObjectId(newBusinessId)));
Optional<UploadObject> updateOtp = modelConvertor.toUploadObject(json);
if (updateOtp.isPresent()) {
UploadObject uo = updateOtp.get();
if (uo.getId() != null && uo.getId().equals(uploadObject.getId())) {
return Optional.of(new AttachmentEntity().setId(uo.getId()).setBid(newBusinessId));
}
}
}
return Optional.empty();
}
/////////////////////////////////////// Private Method
/**
* 根据业务要求, bid下不能挂在同名文件需要去重
*

View File

@ -2,6 +2,7 @@ package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.fallback;
import java.util.List;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.SysStorageVO;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
@ -35,4 +36,13 @@ public class DocumentCenterServiceFallback implements DocumentCenterService {
return new byte[0];
}
@Override
public String updateByBid(List<SysStorageVO> sysStorageVO) {
return null;
}
@Override
public String copyByOid(String fileId) {
return null;
}
}

View File

@ -1,25 +1,21 @@
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.service;
import java.util.List;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.fallback.DocumentCenterServiceFallback;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo.SysStorageVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.fallback.DocumentCenterServiceFallback;
import java.util.List;
/**
* 连接山分的文档中心服务
*
* @author Ajaxfan
*/
//@FeignClient(name = "DocumentCenterService", url = "${document.center.ip-address}", fallback = DocumentCenterServiceFallback.class)
@FeignClient(name = "${document.center.service.id}", fallback = DocumentCenterServiceFallback.class)
@FeignClient(name = "DocumentCenterService", url = "${document.center.ip-address}", fallback = DocumentCenterServiceFallback.class)
//@FeignClient(name = "${document.center.service.id}", fallback = DocumentCenterServiceFallback.class)
public interface DocumentCenterService {
/**
@ -67,4 +63,22 @@ public interface DocumentCenterService {
@RequestMapping(method = RequestMethod.POST, value = "v1.0/files/disk")
String deleteByOid(@RequestParam("fileId") String fileId);
/**
* 根据fileid进行附件的复制
*
* @param fileId
* @return
*/
@RequestMapping(method = RequestMethod.POST, value = "v1.0/files/copy/")
String copyByOid(@RequestParam("fileId") String fileId);
/**
* 根据fileid更新附件表信息
*
* @param sysStorageVO
* @return
*/
@RequestMapping(method = RequestMethod.POST, value = "v1.0/files/update/")
String updateByBid(@RequestBody List<SysStorageVO> sysStorageVO);
}

View File

@ -1,8 +1,10 @@
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.vo;
import lombok.Data;
import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class SysStorageVO {
/* 文件原始名称 */