|
|
@@ -5,7 +5,9 @@ import com.jzg.commons.entity.vo.InsTaskImagesVo;
|
|
|
import com.jzg.quotation.commons.entity.vo.aggregated.InsuranceUploadImageVo;
|
|
|
import com.jzg.quotation.commons.entity.vo.image.InsuranceImageVo;
|
|
|
import com.jzg.quotation.commons.service.QuotationBaseService;
|
|
|
+import com.jzg.quotation.summary.entity.po.QuoteImageRuleMapping;
|
|
|
import com.jzg.quotation.summary.service.InsTaskImagesService;
|
|
|
+import com.jzg.quotation.summary.service.QuoteImageRuleMappingService;
|
|
|
import io.minio.GetObjectArgs;
|
|
|
import io.minio.MinioClient;
|
|
|
|
|
|
@@ -22,18 +24,19 @@ public class ImageParamHandlerDecorator {
|
|
|
private QuotationBaseService target;
|
|
|
|
|
|
private final MinioClient minioClient;
|
|
|
+
|
|
|
private final String bucketName;
|
|
|
|
|
|
private final InsTaskImagesService insTaskImagesService;
|
|
|
|
|
|
- public ImageParamHandlerDecorator(QuotationBaseService target,
|
|
|
- MinioClient minioClient,
|
|
|
- String bucketName,
|
|
|
- InsTaskImagesService insTaskImagesService) {
|
|
|
+ private final QuoteImageRuleMappingService quoteImageRuleMappingService;
|
|
|
+
|
|
|
+ public ImageParamHandlerDecorator(QuotationBaseService target, MinioClient minioClient, String bucketName, InsTaskImagesService insTaskImagesService, QuoteImageRuleMappingService quoteImageRuleMappingService) {
|
|
|
this.target = target;
|
|
|
this.minioClient = minioClient;
|
|
|
this.bucketName = bucketName;
|
|
|
this.insTaskImagesService = insTaskImagesService;
|
|
|
+ this.quoteImageRuleMappingService = quoteImageRuleMappingService;
|
|
|
}
|
|
|
|
|
|
public void setTarget(QuotationBaseService target) {
|
|
|
@@ -42,20 +45,30 @@ public class ImageParamHandlerDecorator {
|
|
|
|
|
|
/**
|
|
|
* 上传影像
|
|
|
+ *
|
|
|
* @param uploadImageVo
|
|
|
*/
|
|
|
- public void uploadImage(InsuranceUploadImageVo uploadImageVo){
|
|
|
+ public void uploadImage(InsuranceUploadImageVo uploadImageVo) {
|
|
|
|
|
|
- if(Objects.isNull(uploadImageVo.getImageVoList())){
|
|
|
+ if (Objects.isNull(uploadImageVo.getImageVoList())) {
|
|
|
uploadImageVo.setImageVoList(new ArrayList<>());
|
|
|
}
|
|
|
|
|
|
InsTaskImagesVo insTaskImagesVo = insTaskImagesService.selectByQuoteNo(uploadImageVo.getOrder().getQuoteNo());
|
|
|
List<ImagesVo> images = insTaskImagesVo.getImages();
|
|
|
- Map<String, List<ImagesVo>> groupImages = images.stream().collect(Collectors.groupingBy(ImagesVo::getImageType));
|
|
|
+ Map<String, List<ImagesVo>> groupImages = images.stream()
|
|
|
+ .collect(Collectors.groupingBy(ImagesVo::getImageType));
|
|
|
+
|
|
|
+ Map<String, QuoteImageRuleMapping> quoteImageRuleMappingMap = quoteImageRuleMappingService.getQuoteImageRuleMapping(uploadImageVo.getOrder()
|
|
|
+ .fetchCompanyCode());
|
|
|
|
|
|
- groupImages.forEach((imageType,ImageList)->{
|
|
|
+ groupImages.forEach((imageType, ImageList) -> {
|
|
|
InsuranceImageVo vo = new InsuranceImageVo();
|
|
|
+ QuoteImageRuleMapping quoteImageRuleMapping = quoteImageRuleMappingMap.get(imageType);
|
|
|
+ Optional.ofNullable(quoteImageRuleMapping).ifPresent(quoteImageRuleMappingVo -> {
|
|
|
+ vo.setInsuranceImageCode(quoteImageRuleMappingVo.getInsuranceImageCode());
|
|
|
+ vo.setInsuranceImageType(quoteImageRuleMappingVo.getInsuranceImageType());
|
|
|
+ });
|
|
|
vo.setImageCode(imageType);
|
|
|
List<InsuranceImageVo.ImageDTO> imageDTOList = ImageList.stream().map(imageVo -> {
|
|
|
InsuranceImageVo.ImageDTO imageDTO = new InsuranceImageVo.ImageDTO();
|
|
|
@@ -64,6 +77,7 @@ public class ImageParamHandlerDecorator {
|
|
|
byte[] fileToByte = getFileToByte(minioClient, bucketName, imageVo.getFileName());
|
|
|
imageDTO.setImageBase64Str(Base64.getEncoder().encodeToString(fileToByte));
|
|
|
imageDTO.setImageByte(fileToByte);
|
|
|
+ imageDTO.setImageSize(String.valueOf(fileToByte.length));
|
|
|
return imageDTO;
|
|
|
}).collect(Collectors.toList());
|
|
|
vo.setImageBase64List(imageDTOList);
|
|
|
@@ -82,15 +96,17 @@ public class ImageParamHandlerDecorator {
|
|
|
|
|
|
/**
|
|
|
* 获取文件base64
|
|
|
+ *
|
|
|
* @param minioClient
|
|
|
* @param bucketName
|
|
|
* @param imageId
|
|
|
* @return
|
|
|
*/
|
|
|
- public String getFileBase64(MinioClient minioClient,String bucketName,String imageName){
|
|
|
- try (InputStream stream = minioClient.getObject(
|
|
|
- GetObjectArgs.builder().bucket(bucketName).object(imageName).build());
|
|
|
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
|
|
+ public String getFileBase64(MinioClient minioClient, String bucketName, String imageName) {
|
|
|
+ try (InputStream stream = minioClient.getObject(GetObjectArgs.builder()
|
|
|
+ .bucket(bucketName)
|
|
|
+ .object(imageName)
|
|
|
+ .build()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
|
|
|
|
|
// 读取流数据
|
|
|
byte[] buffer = new byte[4096];
|
|
|
@@ -111,14 +127,16 @@ public class ImageParamHandlerDecorator {
|
|
|
|
|
|
/**
|
|
|
* 获取文件bytes数组
|
|
|
+ *
|
|
|
* @param minioClient
|
|
|
* @param bucketName
|
|
|
* @return
|
|
|
*/
|
|
|
- public byte[] getFileToByte(MinioClient minioClient,String bucketName,String imageName){
|
|
|
- try (InputStream stream = minioClient.getObject(
|
|
|
- GetObjectArgs.builder().bucket(bucketName).object(imageName).build());
|
|
|
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
|
|
+ public byte[] getFileToByte(MinioClient minioClient, String bucketName, String imageName) {
|
|
|
+ try (InputStream stream = minioClient.getObject(GetObjectArgs.builder()
|
|
|
+ .bucket(bucketName)
|
|
|
+ .object(imageName)
|
|
|
+ .build()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
|
|
// 读取流数据
|
|
|
byte[] buffer = new byte[4096];
|
|
|
int bytesRead;
|