Commit 481fd670 authored by shiyu's avatar shiyu

后台商品视频上传修改

parent b139fb32
......@@ -4,7 +4,9 @@ import com.github.pagehelper.PageInfo;
import com.wwdz.ch.admin.service.SysSupplierItemService;
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.entity.SupplierItemVo;
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.MediaUtil;
......@@ -14,6 +16,7 @@ import com.wwdz.ch.db.dao.distribution.*;
import com.wwdz.ch.db.domain.distribution.*;
import com.wwdz.ch.db.dto.request.distribution.AuctionRecordRequestDto;
import com.wwdz.ch.db.dto.request.distribution.SupplierItemRequestDto;
import com.xxdxxs.utils.CommonUtils;
import com.xxdxxs.utils.DateUtils;
import com.xxdxxs.utils.EntityMapper;
import com.xxdxxs.utils.StringUtils;
......@@ -26,8 +29,16 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.CollectionUtils;
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.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
......@@ -63,6 +74,9 @@ public class SysSupplierItemServiceImpl implements SysSupplierItemService {
@Autowired
AuctionRecordDao auctionRecordDao;
@Autowired
QiniuStorage qiniuStorage;
@Override
@Transactional
......@@ -84,7 +98,9 @@ public class SysSupplierItemServiceImpl implements SysSupplierItemService {
supplierItem.setRebate(new BigDecimal("0"));
}
supplierItem.setImages(dto.getImages());
supplierItem.setVideos(dto.getVideos());
if (StringUtils.hasLength(dto.getVideos())) {
supplierItem.setVideos(getVideosImage(dto.getVideos()));
}
supplierItem.setSort(1);
supplierItem.setCreateTime(now);
supplierItem.setUpdateTime(now);
......@@ -283,4 +299,49 @@ public class SysSupplierItemServiceImpl implements SysSupplierItemService {
}
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;
}
}
......@@ -63,7 +63,6 @@ public class SupplierItemDaoImpl implements SupplierItemDao {
@Override
public int updateStock(long itemId, int stock) {
SupplierItem supplierItem = new SupplierItem();
supplierItem.setUpdateTime(new Date());
supplierItem.setStock(stock);
SupplierItemExample supplierItemExample = new SupplierItemExample();
SupplierItemExample.Criteria criteria = supplierItemExample.createCriteria();
......
......@@ -18,10 +18,7 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Component
public class LogisticsApi {
......@@ -67,6 +64,8 @@ public class LogisticsApi {
String trails = JsonUtils.getValueByPath(result, "Traces");
List<TrailInfo> trailInfoList = new ArrayList<>();
List<Map<String, Object>> list = JsonUtils.toMapList(trails);
list.sort(Comparator.comparing(map -> String.valueOf(map.get("AcceptTime"))));
Collections.reverse(list);
list.forEach(map -> {
TrailInfo trailInfo = new TrailInfo();
trailInfo.setCreateTime((String) map.get("AcceptTime"));
......
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