修改附件sdk
This commit is contained in:
@ -10,6 +10,8 @@ import java.util.UUID;
|
|||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -70,12 +72,12 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
|||||||
|
|
||||||
// 组织数据存储
|
// 组织数据存储
|
||||||
modelConvertor.toQueryResult(json).ifPresent(result -> {
|
modelConvertor.toQueryResult(json).ifPresent(result -> {
|
||||||
result.getData().stream().forEach(data -> {
|
result.getData().forEach(data -> {
|
||||||
detail.add(new AttachmentEntity().setBid(data.getObjectId()).setId(data.getFileId())
|
detail.add(new AttachmentEntity().setBid(data.getObjectId()).setId(data.getFileId())
|
||||||
.setFilename(data.getOriginalName()).setKey(data.getFileName()));
|
.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();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param businessId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Optional<DownloadEntity> downloadOriginalFilesByBusinessId(String businessId) {
|
public Optional<DownloadEntity> downloadOriginalFilesByBusinessId(String businessId) {
|
||||||
Optional<AttachmentDetail> op = findByBusinessId(Arrays.asList(businessId));
|
Optional<AttachmentDetail> op = findByBusinessId(Arrays.asList(businessId));
|
||||||
@ -186,7 +192,7 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Optional<UploadObject> upload(String businessId, File file) {
|
public Optional<UploadObject> upload(@NotNull String businessId, @NotNull File file) {
|
||||||
removeDuplicateObject(businessId, file.getName());
|
removeDuplicateObject(businessId, file.getName());
|
||||||
|
|
||||||
String res = documentCenterService.upload("ebtp-mall-cloud", businessId, fileConvertor.toMultipartFile(file));
|
String res = documentCenterService.upload("ebtp-mall-cloud", businessId, fileConvertor.toMultipartFile(file));
|
||||||
@ -196,8 +202,14 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
|||||||
return modelConvertor.toUploadObject(res);
|
return modelConvertor.toUploadObject(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param businessId
|
||||||
|
* @param filename
|
||||||
|
* @param array
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@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);
|
removeDuplicateObject(businessId, filename);
|
||||||
|
|
||||||
String res = documentCenterService.upload("ebtp-mall-cloud", businessId,
|
String res = documentCenterService.upload("ebtp-mall-cloud", businessId,
|
||||||
@ -208,18 +220,17 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
|||||||
return modelConvertor.toUploadObject(res);
|
return modelConvertor.toUploadObject(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param businessId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteByBid(String businessId) {
|
public boolean deleteByBid(String businessId) {
|
||||||
Optional<AttachmentDetail> op = findByBusinessId(Arrays.asList(businessId));
|
Optional<AttachmentDetail> op = findByBusinessId(Arrays.asList(businessId));
|
||||||
|
|
||||||
/*
|
|
||||||
* AttachmentDetail 是一个Map类型对象, key 业务id, value: List<AttachmentEntity>
|
|
||||||
*/
|
|
||||||
op.ifPresent(attachmentDetail -> {
|
op.ifPresent(attachmentDetail -> {
|
||||||
attachmentDetail.keySet().stream().forEach(key -> {
|
attachmentDetail.values().forEach(collection -> {
|
||||||
List<AttachmentEntity> list = attachmentDetail.get(key);
|
collection.forEach(attachmentEntity -> {
|
||||||
|
|
||||||
list.stream().forEach(attachmentEntity -> {
|
|
||||||
documentCenterService.deleteByOid(attachmentEntity.getId());
|
documentCenterService.deleteByOid(attachmentEntity.getId());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -227,6 +238,10 @@ public class DefaultAttachmentClient implements AttachmentClient {
|
|||||||
return op.isPresent();
|
return op.isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param objectId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String deleteByOid(String objectId) {
|
public String deleteByOid(String objectId) {
|
||||||
return documentCenterService.deleteByOid(objectId);
|
return documentCenterService.deleteByOid(objectId);
|
||||||
|
@ -43,18 +43,20 @@ public class ModelConvertor {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Optional<AttachmentEntity> toAttachmentEntity(String json) {
|
public Optional<AttachmentEntity> toAttachmentEntity(String json) {
|
||||||
AttachmentEntity entity = null;
|
return Optional.of(json).map(content -> {
|
||||||
|
AttachmentEntity entity = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SysStorageVO vo = tpDownPO(json);
|
SysStorageVO vo = tpDownPO(content);
|
||||||
log.debug("convert to model: {}", vo);
|
log.debug("convert to model: {}", vo);
|
||||||
|
|
||||||
entity = new AttachmentEntity();
|
entity = new AttachmentEntity();
|
||||||
entity.setId(vo.getFileId()).setFilename(vo.getOriginalName()).setBid(vo.getObjectId());
|
entity.setId(vo.getFileId()).setFilename(vo.getOriginalName()).setBid(vo.getObjectId());
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
return Optional.ofNullable(entity);
|
return entity;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,13 +64,14 @@ public class ModelConvertor {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Optional<QueryResult> toQueryResult(String json) {
|
public Optional<QueryResult> toQueryResult(String json) {
|
||||||
QueryResult result = null;
|
return Optional.of(json).map(content -> {
|
||||||
try {
|
try {
|
||||||
result = objectMapper.readValue(json, QueryResult.class);
|
return objectMapper.readValue(content, QueryResult.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
return Optional.ofNullable(result);
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,41 +79,53 @@ public class ModelConvertor {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Optional<byte[]> toByteArray(String json) {
|
public Optional<byte[]> toByteArray(String json) {
|
||||||
byte[] array = null;
|
return Optional.of(json).map(content -> {
|
||||||
|
try {
|
||||||
try {
|
return tpDownPO(content).getFileStream();
|
||||||
array = tpDownPO(json).getFileStream();
|
} catch (JsonProcessingException e) {
|
||||||
} catch (JsonProcessingException e) {
|
log.error(e.getMessage());
|
||||||
log.error(e.getMessage());
|
}
|
||||||
}
|
return null;
|
||||||
return Optional.ofNullable(array);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param json
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public Optional<DownloadEntity> toDownloadEntity(String json) {
|
public Optional<DownloadEntity> toDownloadEntity(String json) {
|
||||||
DownloadEntity entity = new DownloadEntity();
|
return Optional.of(json).map(content -> {
|
||||||
try {
|
DownloadEntity entity = null;
|
||||||
SysStorageVO vo = tpDownPO(json);
|
try {
|
||||||
entity.setFilename(URLEncoder.DEFAULT.encode(vo.getOriginalName(), Charset.forName("UTF-8")))
|
SysStorageVO vo = tpDownPO(content);
|
||||||
.setStream(vo.getFileStream());
|
|
||||||
} catch (JsonMappingException e) {
|
entity = new DownloadEntity();
|
||||||
e.printStackTrace();
|
entity.setFilename(URLEncoder.DEFAULT.encode(vo.getOriginalName(), Charset.forName("UTF-8")))
|
||||||
} catch (JsonProcessingException e) {
|
.setStream(vo.getFileStream());
|
||||||
e.printStackTrace();
|
} catch (JsonProcessingException e) {
|
||||||
}
|
log.error(e.getMessage());
|
||||||
return Optional.ofNullable(entity);
|
}
|
||||||
|
return entity;
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param json
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public Optional<UploadObject> toUploadObject(String json) {
|
public Optional<UploadObject> toUploadObject(String json) {
|
||||||
try {
|
return Optional.of(json).map(content -> {
|
||||||
return Optional.ofNullable(new UploadObject().setId(toUploadPO(json).getFileId()));
|
try {
|
||||||
} catch (JsonProcessingException e) {
|
return new UploadObject().setId(toUploadPO(json).getFileId());
|
||||||
log.error(e.getMessage());
|
} catch (JsonProcessingException e) {
|
||||||
}
|
log.error(e.getMessage());
|
||||||
return Optional.empty();
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////// private
|
///////////////////////////////////////////////////////////// private method
|
||||||
/////////////////////////////////////////////////////////////////////////// method
|
|
||||||
/**
|
/**
|
||||||
* Json转换为业务实体
|
* Json转换为业务实体
|
||||||
*
|
*
|
||||||
@ -124,13 +139,17 @@ public class ModelConvertor {
|
|||||||
return objectMapper.readValue(json, DownStream.class).getData().getSysStorageVO();
|
return objectMapper.readValue(json, DownStream.class).getData().getSysStorageVO();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param json
|
||||||
|
* @return
|
||||||
|
* @throws JsonMappingException
|
||||||
|
* @throws JsonProcessingException
|
||||||
|
*/
|
||||||
private SysStorageVO toUploadPO(String json) throws JsonMappingException, JsonProcessingException {
|
private SysStorageVO toUploadPO(String json) throws JsonMappingException, JsonProcessingException {
|
||||||
log.debug("current convertor json is: {}", json);
|
log.debug("current convertor json is: {}", json);
|
||||||
List<UploadStreamData> list = objectMapper.readValue(json, UploadStream.class).getData();
|
List<UploadStreamData> list = objectMapper.readValue(json, UploadStream.class).getData();
|
||||||
|
|
||||||
if (list.size() > 0) {
|
return list.stream().findFirst().map(obj -> obj.getSysStorageVO()).orElseGet(SysStorageVO::new);
|
||||||
return list.get(0).getSysStorageVO();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# 胜智云eureka 统一配置
|
# 胜智云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.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.prefer-ip-address=true
|
||||||
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
|
|
||||||
|
Reference in New Issue
Block a user