修改了security权限控制,优化了附件sdk异常处理

This commit is contained in:
ajaxfan
2021-03-12 15:02:20 +08:00
parent 0d86bc88ec
commit 6fbfd5de6e
10 changed files with 105 additions and 232 deletions

View File

@ -41,7 +41,7 @@ public class ModelConvertor {
* @return
*/
public Optional<AttachmentEntity> toAttachmentEntity(String json) {
return Optional.of(json).map(content -> {
return Optional.ofNullable(json).map(content -> {
AttachmentEntity entity = null;
try {
@ -49,7 +49,8 @@ public class ModelConvertor {
log.debug("convert to model: {}", vo);
entity = new AttachmentEntity();
entity.setId(vo.getFileId()).setFilename(vo.getOriginalName()).setBid(vo.getObjectId());
entity.setId(vo.getFileId()).setFilename(vo.getOriginalName()).setBid(vo.getObjectId())
.setKey(vo.getFileName());
} catch (JsonProcessingException e) {
log.error(json);
log.error(e.getMessage());
@ -139,8 +140,8 @@ public class ModelConvertor {
*/
private SysStorageVO tpDownPO(String json) throws JsonMappingException, JsonProcessingException {
log.debug("current convertor json is: {}", json);
return Optional.ofNullable(objectMapper.readValue(json, DownStream.class))
.map(ds -> ds.getData().getSysStorageVO()).orElseGet(SysStorageVO::new);
return Optional.ofNullable(objectMapper.readValue(json, DownStream.class)).map(ds -> ds.getData())
.map(data -> data.getSysStorageVO()).orElseGet(SysStorageVO::new);
}
/**

View File

@ -1,46 +0,0 @@
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.fallback;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentDetail;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentEntity;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.FeedbackMessage;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.Snowflake;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.param.QueryParameter;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.service.QueryService;
@Component
public class QueryServiceFallback implements QueryService {
@Override
public Snowflake getSnokflakId() {
return null;
}
@Override
public AttachmentEntity getObjectDetail(String oid) {
return null;
}
@Override
public AttachmentDetail getAttachmentDetails(QueryParameter param) {
return null;
}
@Override
public FeedbackMessage handleFileUpload(String businessId, MultipartFile file) {
return null;
}
@Override
public byte[] downloadByBid(String bid) {
return null;
}
@Override
public byte[] downloadByOid(String oid) {
return null;
}
}

View File

@ -1,43 +0,0 @@
package com.chinaunicom.ebtp.mall.cloud.attachment.sdk.service;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.config.FeignSupportConfig;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.fallback.QueryServiceFallback;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentDetail;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentEntity;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.FeedbackMessage;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.Snowflake;
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.param.QueryParameter;
@FeignClient(value = "core-service-ebtp-updownload", configuration = FeignSupportConfig.class, fallback = QueryServiceFallback.class)
public interface QueryService {
@RequestMapping(method = RequestMethod.GET, value = "v1/business/id")
Snowflake getSnokflakId();
@RequestMapping(method = RequestMethod.GET, value = "v1/attachment/find/oid/{oid}")
AttachmentEntity getObjectDetail(@PathVariable("oid") String oid);
@RequestMapping(method = RequestMethod.POST, value = "v1/attachment/find")
AttachmentDetail getAttachmentDetails(@RequestBody QueryParameter param);
@RequestMapping(value = "/v1/attachment/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
FeedbackMessage handleFileUpload(@RequestPart(value = "businessId") String businessId,
@RequestPart(value = "file") MultipartFile file);
@GetMapping("/v1/attachment/download/bid/{bid}")
byte[] downloadByBid(@PathVariable("bid") String bid);
@GetMapping("/v1/attachment/download/oid/{oid}")
byte[] downloadByOid(@PathVariable("oid") String oid);
}

View File

@ -7,14 +7,17 @@ public class SysStorageVO {
/* 文件原始名称 */
private String originalName;
/* 附件id */
private String fileId;
/* 业务id */
private String objectId;
/* 文件流 */
private byte[] fileStream;
/* 文件唯一标识 */
private String fileName;
}