新增上传方法,根据传参清空bid下所有文件

This commit is contained in:
付庆吉
2021-07-12 15:12:52 +08:00
parent a310ea3f8c
commit 6b73b57435
2 changed files with 32 additions and 6 deletions

View File

@ -83,12 +83,24 @@ public interface AttachmentClient {
/**
* 上传资源文件
*
* @param bid
* @param file
* @param businessId
* @param filename
* @param array
* @return
*/
Optional<UploadObject> upload(String businessId, String filename, byte[] array);
/**
* 上传资源文件
*
* @param businessId
* @param filename
* @param array
* @param only true:清空bid下所有文件否则根据附件名称删除
* @return
*/
Optional<UploadObject> upload(String businessId, String filename, byte[] array, boolean only);
/**
* 根据业务id删除附件
*

View File

@ -197,7 +197,7 @@ public class DefaultAttachmentClient implements AttachmentClient {
*/
@Override
public Optional<UploadObject> upload(@NotNull String businessId, @NotNull File file) {
removeDuplicateObject(businessId, file.getName());
removeDuplicateObject(businessId, file.getName(), false);
String res = documentCenterService.upload("ebtp-mall-cloud", businessId, fileConvertor.toMultipartFile(file));
@ -214,7 +214,21 @@ public class DefaultAttachmentClient implements AttachmentClient {
*/
@Override
public Optional<UploadObject> upload(@NotNull String businessId, @NotNull String filename, @NotNull byte[] array) {
removeDuplicateObject(businessId, filename);
return this.upload(businessId, filename, array, false);
}
/**
* 上传资源文件
*
* @param businessId
* @param filename
* @param array
* @param only true:清空bid下所有文件否则根据附件名称删除
* @return
*/
@Override
public Optional<UploadObject> upload(String businessId, String filename, byte[] array, boolean only) {
removeDuplicateObject(businessId, filename, only);
String res = documentCenterService.upload("ebtp-mall-cloud", businessId,
fileConvertor.toMultipartFile(filename, array));
@ -300,12 +314,12 @@ public class DefaultAttachmentClient implements AttachmentClient {
* @param businessId
* @param filename
*/
private void removeDuplicateObject(String businessId, String filename) {
private void removeDuplicateObject(String businessId, String filename, boolean only) {
log.info("remove files {} in business: {} if exists", filename, businessId);
Optional<AttachmentDetail> op = findByBusinessId(Arrays.asList(businessId));
op.ifPresent(detail -> {
detail.get(businessId).stream().filter(obj -> obj.getFilename().equals(filename)).forEach(obj -> {
detail.get(businessId).stream().filter(obj -> only || obj.getFilename().equals(filename)).forEach(obj -> {
deleteByOid(obj.getId());
});
});