From 91369f634330b9a807faffd445fc6e449bb17667 Mon Sep 17 00:00:00 2001 From: ajaxfan <909938737@qq.com> Date: Mon, 8 Feb 2021 17:35:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E5=8E=BB=E9=87=8D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sdk/api/DefaultAttachmentClient.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mall-ebtp-cloud-attachment-sdk/src/main/java/com/chinaunicom/ebtp/mall/cloud/attachment/sdk/api/DefaultAttachmentClient.java b/mall-ebtp-cloud-attachment-sdk/src/main/java/com/chinaunicom/ebtp/mall/cloud/attachment/sdk/api/DefaultAttachmentClient.java index 2728137..df966f4 100644 --- a/mall-ebtp-cloud-attachment-sdk/src/main/java/com/chinaunicom/ebtp/mall/cloud/attachment/sdk/api/DefaultAttachmentClient.java +++ b/mall-ebtp-cloud-attachment-sdk/src/main/java/com/chinaunicom/ebtp/mall/cloud/attachment/sdk/api/DefaultAttachmentClient.java @@ -187,6 +187,8 @@ public class DefaultAttachmentClient implements AttachmentClient { */ @Override public Optional 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 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 op = findByBusinessId(Arrays.asList(businessId)); + + op.ifPresent(detail -> { + detail.get(businessId).stream().filter(obj -> obj.getFilename().equals(filename)).forEach(obj -> { + deleteByOid(obj.getId()); + }); + }); + } + }