修改附件sdk
This commit is contained in:
@ -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<DownloadEntity> downloadOriginalFilesByBusinessId(String businessId) {
|
||||
Optional<AttachmentDetail> op = findByBusinessId(Arrays.asList(businessId));
|
||||
@ -186,7 +192,7 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Optional<UploadObject> upload(String businessId, File file) {
|
||||
public Optional<UploadObject> 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<UploadObject> upload(String businessId, String filename, byte[] array) {
|
||||
public Optional<UploadObject> 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<AttachmentDetail> op = findByBusinessId(Arrays.asList(businessId));
|
||||
|
||||
/*
|
||||
* AttachmentDetail 是一个Map类型对象, key 业务id, value: List<AttachmentEntity>
|
||||
*/
|
||||
op.ifPresent(attachmentDetail -> {
|
||||
attachmentDetail.keySet().stream().forEach(key -> {
|
||||
List<AttachmentEntity> 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);
|
||||
|
@ -43,18 +43,20 @@ public class ModelConvertor {
|
||||
* @return
|
||||
*/
|
||||
public Optional<AttachmentEntity> 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<QueryResult> 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<byte[]> 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<DownloadEntity> 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<UploadObject> 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<UploadStreamData> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user