Commit d2376720 authored by shiyu's avatar shiyu

bug修复1

parent c4665ea2
package com.wwdz.ch.core.util;
import com.wwdz.ch.core.consts.CommConsts;
import com.wwdz.ch.core.consts.MediaTypeEnum;
import com.wwdz.ch.core.entity.ImageInfo;
import com.xxdxxs.utils.CommonUtils;
import com.xxdxxs.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -12,6 +15,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
......@@ -123,6 +127,11 @@ public class MediaUtil {
}
/**
* 获取图片的长宽
*
......
......@@ -3,7 +3,9 @@ package com.wwdz.ch.wx.impl.distribution;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.core.consts.CommConsts;
import com.wwdz.ch.core.consts.DistributionEnum;
import com.wwdz.ch.core.consts.MediaTypeEnum;
import com.wwdz.ch.core.consts.ResultCode;
import com.wwdz.ch.core.storage.QiniuStorage;
import com.wwdz.ch.core.type.PageSearchResult;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.CacheUtil;
......@@ -21,10 +23,7 @@ import com.wwdz.ch.wx.entity.vo.distribution.AuctionRecordRowVo;
import com.wwdz.ch.wx.service.distribution.CollectionItemsRelationService;
import com.wwdz.ch.wx.service.distribution.DistributionOrderService;
import com.wwdz.ch.wx.service.distribution.SupplierItemService;
import com.xxdxxs.utils.DateUtils;
import com.xxdxxs.utils.EntityMapper;
import com.xxdxxs.utils.JsonUtils;
import com.xxdxxs.utils.StringUtils;
import com.xxdxxs.utils.*;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
......@@ -34,7 +33,14 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
......@@ -94,6 +100,8 @@ public class SupplierItemServiceImpl implements SupplierItemService {
@Autowired
CollectionShareRecordDao collectionShareRecordDao;
@Autowired
private QiniuStorage qiniuStorage;
@Override
......@@ -539,6 +547,9 @@ public class SupplierItemServiceImpl implements SupplierItemService {
supplierItem.setSupplyPrice(0L);
supplierItem.setRebate(new BigDecimal("0"));
supplierItem.setImages(dto.getImages());
if (StringUtils.hasLength(dto.getVideos())) {
supplierItem.setVideos(getVideosImage(dto.getVideos()));
}
supplierItem.setVideos(dto.getVideos());
supplierItem.setSort(1);
supplierItem.setBuyLimitNum(1);
......@@ -850,4 +861,49 @@ public class SupplierItemServiceImpl implements SupplierItemService {
}
return Result.failed();
}
private String getVideosImage(String vedios) {
String video = "";
String[] images = vedios.split(";");
StringBuffer stringBuffer = new StringBuffer();
Arrays.stream(images).parallel().forEach(image -> {
if (stringBuffer.length() != 0) {
stringBuffer.append(";");
}
try {
String cutImage = MediaUtil.getImageByCutVedio(image);
URL url = new URL(cutImage);
InputStream inputStream = url.openStream();
BufferedImage bufferedImage = ImageIO.read(inputStream);
String keyName = CommConsts.UPLOAD_PRE_DIRECTORY + CommonUtils.getUUID() + "_" + bufferedImage.getWidth() + "x" + bufferedImage.getHeight() + "." + MediaTypeEnum.IMAGE_JPG.getExt();
InputStream imageStream = bufferedImageToInputStream(bufferedImage, MediaTypeEnum.IMAGE_JPG.getExt());
qiniuStorage.store(imageStream, 1, MediaTypeEnum.IMAGE_JPG.getMime(), keyName);
String urlOfSize = qiniuStorage.generateUrl(keyName);
stringBuffer.append(image).append(",").append(urlOfSize);
} catch (Exception e) {
stringBuffer.append(image);
logger.error("视频图片上传失败", e);
}
});
video = stringBuffer.toString();
return video;
}
/**
* 将BufferedImage转换为InputStream
*
* @param image 数据源
* @param type 图片格式
* @return
*/
private static InputStream bufferedImageToInputStream(BufferedImage image, String type) {
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
ImageIO.write(image, type, os);
return new ByteArrayInputStream(os.toByteArray());
} catch (IOException e) {
logger.error("bufferedImageToInputStream 出错,原因: {}", e);
}
return null;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment