增加了附件去重功能
This commit is contained in:
@ -187,6 +187,8 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
||||
*/
|
||||
@Override
|
||||
public Optional<UploadObject> upload(String businessId, File file) {
|
||||
removeDuplicateObject(businessId, file.getName());
|
||||
|
||||
String res = documentCenterService.upload("ebtp-mall-cloud", businessId, fileConvertor.toMultipartFile(file));
|
||||
|
||||
log.debug(res);
|
||||
@ -196,6 +198,8 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
||||
|
||||
@Override
|
||||
public Optional<UploadObject> upload(String businessId, String filename, byte[] array) {
|
||||
removeDuplicateObject(businessId, filename);
|
||||
|
||||
String res = documentCenterService.upload("ebtp-mall-cloud", businessId,
|
||||
fileConvertor.toMultipartFile(filename, array));
|
||||
|
||||
@ -228,4 +232,21 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
||||
return documentCenterService.deleteByOid(objectId);
|
||||
}
|
||||
|
||||
/////////////////////////////////////// Private Method
|
||||
/**
|
||||
* 根据业务要求, bid下不能挂在同名文件,需要去重
|
||||
*
|
||||
* @param businessId
|
||||
* @param filename
|
||||
*/
|
||||
private void removeDuplicateObject(String businessId, String filename) {
|
||||
Optional<AttachmentDetail> op = findByBusinessId(Arrays.asList(businessId));
|
||||
|
||||
op.ifPresent(detail -> {
|
||||
detail.get(businessId).stream().filter(obj -> obj.getFilename().equals(filename)).forEach(obj -> {
|
||||
deleteByOid(obj.getId());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user