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 62dd38c..b3429b7 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 @@ -10,6 +10,8 @@ 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; @@ -70,12 +72,12 @@ public class DefaultAttachmentClient implements AttachmentClient { // 组织数据存储 modelConvertor.toQueryResult(json).ifPresent(result -> { - result.getData().stream().forEach(data -> { + result.getData().forEach(data -> { detail.add(new AttachmentEntity().setBid(data.getObjectId()).setId(data.getFileId()) .setFilename(data.getOriginalName()).setKey(data.getFileName())); }); }); - return Optional.ofNullable(detail); + return Optional.of(detail); } /** @@ -139,6 +141,10 @@ public class DefaultAttachmentClient implements AttachmentClient { return Optional.empty(); } + /** + * @param businessId + * @return + */ @Override public Optional downloadOriginalFilesByBusinessId(String businessId) { Optional op = findByBusinessId(Arrays.asList(businessId)); @@ -186,7 +192,7 @@ public class DefaultAttachmentClient implements AttachmentClient { * @return */ @Override - public Optional upload(String businessId, File file) { + public Optional upload(@NotNull String businessId, @NotNull File file) { removeDuplicateObject(businessId, file.getName()); String res = documentCenterService.upload("ebtp-mall-cloud", businessId, fileConvertor.toMultipartFile(file)); @@ -196,8 +202,14 @@ public class DefaultAttachmentClient implements AttachmentClient { return modelConvertor.toUploadObject(res); } + /** + * @param businessId + * @param filename + * @param array + * @return + */ @Override - public Optional upload(String businessId, String filename, byte[] array) { + public Optional upload(@NotNull String businessId, @NotNull String filename, @NotNull byte[] array) { removeDuplicateObject(businessId, filename); String res = documentCenterService.upload("ebtp-mall-cloud", businessId, @@ -208,18 +220,17 @@ public class DefaultAttachmentClient implements AttachmentClient { return modelConvertor.toUploadObject(res); } + /** + * @param businessId + * @return + */ @Override public boolean deleteByBid(String businessId) { Optional op = findByBusinessId(Arrays.asList(businessId)); - /* - * AttachmentDetail 是一个Map类型对象, key 业务id, value: List - */ op.ifPresent(attachmentDetail -> { - attachmentDetail.keySet().stream().forEach(key -> { - List list = attachmentDetail.get(key); - - list.stream().forEach(attachmentEntity -> { + attachmentDetail.values().forEach(collection -> { + collection.forEach(attachmentEntity -> { documentCenterService.deleteByOid(attachmentEntity.getId()); }); }); @@ -227,6 +238,10 @@ public class DefaultAttachmentClient implements AttachmentClient { return op.isPresent(); } + /** + * @param objectId + * @return + */ @Override public String deleteByOid(String objectId) { return documentCenterService.deleteByOid(objectId); diff --git a/mall-ebtp-cloud-attachment-sdk/src/main/java/com/chinaunicom/ebtp/mall/cloud/attachment/sdk/convertor/ModelConvertor.java b/mall-ebtp-cloud-attachment-sdk/src/main/java/com/chinaunicom/ebtp/mall/cloud/attachment/sdk/convertor/ModelConvertor.java index bc0c436..852b98c 100644 --- a/mall-ebtp-cloud-attachment-sdk/src/main/java/com/chinaunicom/ebtp/mall/cloud/attachment/sdk/convertor/ModelConvertor.java +++ b/mall-ebtp-cloud-attachment-sdk/src/main/java/com/chinaunicom/ebtp/mall/cloud/attachment/sdk/convertor/ModelConvertor.java @@ -43,18 +43,20 @@ public class ModelConvertor { * @return */ public Optional toAttachmentEntity(String json) { - AttachmentEntity entity = null; + return Optional.of(json).map(content -> { + AttachmentEntity entity = null; - try { - SysStorageVO vo = tpDownPO(json); - log.debug("convert to model: {}", vo); + try { + SysStorageVO vo = tpDownPO(content); + log.debug("convert to model: {}", vo); - entity = new AttachmentEntity(); - entity.setId(vo.getFileId()).setFilename(vo.getOriginalName()).setBid(vo.getObjectId()); - } catch (JsonProcessingException e) { - log.error(e.getMessage()); - } - return Optional.ofNullable(entity); + entity = new AttachmentEntity(); + entity.setId(vo.getFileId()).setFilename(vo.getOriginalName()).setBid(vo.getObjectId()); + } catch (JsonProcessingException e) { + log.error(e.getMessage()); + } + return entity; + }); } /** @@ -62,13 +64,14 @@ public class ModelConvertor { * @return */ public Optional toQueryResult(String json) { - QueryResult result = null; - try { - result = objectMapper.readValue(json, QueryResult.class); - } catch (JsonProcessingException e) { - log.error(e.getMessage()); - } - return Optional.ofNullable(result); + return Optional.of(json).map(content -> { + try { + return objectMapper.readValue(content, QueryResult.class); + } catch (JsonProcessingException e) { + log.error(e.getMessage()); + } + return null; + }); } /** @@ -76,41 +79,53 @@ public class ModelConvertor { * @return */ public Optional toByteArray(String json) { - byte[] array = null; - - try { - array = tpDownPO(json).getFileStream(); - } catch (JsonProcessingException e) { - log.error(e.getMessage()); - } - return Optional.ofNullable(array); + return Optional.of(json).map(content -> { + try { + return tpDownPO(content).getFileStream(); + } catch (JsonProcessingException e) { + log.error(e.getMessage()); + } + return null; + }); } + /** + * @param json + * @return + */ public Optional toDownloadEntity(String json) { - DownloadEntity entity = new DownloadEntity(); - try { - SysStorageVO vo = tpDownPO(json); - entity.setFilename(URLEncoder.DEFAULT.encode(vo.getOriginalName(), Charset.forName("UTF-8"))) - .setStream(vo.getFileStream()); - } catch (JsonMappingException e) { - e.printStackTrace(); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - return Optional.ofNullable(entity); + return Optional.of(json).map(content -> { + DownloadEntity entity = null; + try { + SysStorageVO vo = tpDownPO(content); + + entity = new DownloadEntity(); + entity.setFilename(URLEncoder.DEFAULT.encode(vo.getOriginalName(), Charset.forName("UTF-8"))) + .setStream(vo.getFileStream()); + } catch (JsonProcessingException e) { + log.error(e.getMessage()); + } + return entity; + }); + } + /** + * @param json + * @return + */ public Optional toUploadObject(String json) { - try { - return Optional.ofNullable(new UploadObject().setId(toUploadPO(json).getFileId())); - } catch (JsonProcessingException e) { - log.error(e.getMessage()); - } - return Optional.empty(); + return Optional.of(json).map(content -> { + try { + return new UploadObject().setId(toUploadPO(json).getFileId()); + } catch (JsonProcessingException e) { + log.error(e.getMessage()); + } + return null; + }); } - /////////////////////////////////////////////////////////////////////////// private - /////////////////////////////////////////////////////////////////////////// method + ///////////////////////////////////////////////////////////// private method /** * Json转换为业务实体 * @@ -124,13 +139,17 @@ public class ModelConvertor { return objectMapper.readValue(json, DownStream.class).getData().getSysStorageVO(); } + /** + * @param json + * @return + * @throws JsonMappingException + * @throws JsonProcessingException + */ private SysStorageVO toUploadPO(String json) throws JsonMappingException, JsonProcessingException { log.debug("current convertor json is: {}", json); List list = objectMapper.readValue(json, UploadStream.class).getData(); - if (list.size() > 0) { - return list.get(0).getSysStorageVO(); - } - return null; + return list.stream().findFirst().map(obj -> obj.getSysStorageVO()).orElseGet(SysStorageVO::new); } + } diff --git a/mall-ebtp-cloud-eureka-starter/src/main/resources/eureka-cofiguration.properties b/mall-ebtp-cloud-eureka-starter/src/main/resources/eureka-cofiguration.properties index 83b68ed..ea30d44 100644 --- a/mall-ebtp-cloud-eureka-starter/src/main/resources/eureka-cofiguration.properties +++ b/mall-ebtp-cloud-eureka-starter/src/main/resources/eureka-cofiguration.properties @@ -1,4 +1,3 @@ # 胜智云eureka 统一配置 eureka.client.service-url.defaultZone=http://10.242.31.158:5001/eureka,http://10.242.31.158:5002/eureka,http://10.242.31.158:5003/eureka eureka.instance.prefer-ip-address=true -eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}