Administrator
2020-02-23 d5dfd55f3dc45948a59cdcfef30e5fbc770f5721
fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java
@@ -1,5 +1,6 @@
package com.yeshi.fanli.service.impl.dynamic;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
@@ -10,6 +11,7 @@
import java.util.UUID;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.core.task.TaskExecutor;
@@ -18,8 +20,6 @@
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.yeshi.utils.tencentcloud.COSManager;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.dao.dynamic.GoodsEvaluateDao;
import com.yeshi.fanli.dto.ConfigParamsDTO;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
@@ -27,7 +27,6 @@
import com.yeshi.fanli.entity.dynamic.CommentInfo;
import com.yeshi.fanli.entity.dynamic.CommentInfo.CommentInfoEnum;
import com.yeshi.fanli.entity.dynamic.GoodsEvaluate;
import com.yeshi.fanli.entity.dynamic.GoodsEvaluate.EvaluateEnum;
import com.yeshi.fanli.entity.dynamic.ImgInfo;
import com.yeshi.fanli.entity.dynamic.ImgInfo.ImgEnum;
import com.yeshi.fanli.entity.dynamic.SimpleGoods;
@@ -76,7 +75,7 @@
   private PinDuoDuoCacheUtil pinDuoDuoCacheUtil;
   @Override
   public void saveHead(MultipartFile file, GoodsEvaluate record) throws GoodsEvaluateException {
   public String saveHead(MultipartFile file, GoodsEvaluate record) throws GoodsEvaluateException {
      Integer state = record.getState();
      if (state == null) {
         state = 0;
@@ -119,13 +118,15 @@
         record.setStartTime(new Date());
      record.setPublishTime(record.getStartTime());
      if (StringUtil.isNullOrEmpty(record.getId())) {
         record.setId(UUID.randomUUID().toString().replace("-", ""));
      String id = record.getId();
      if (StringUtil.isNullOrEmpty(id)) {
         id = UUID.randomUUID().toString().replace("-", "");
         record.setId(id);
         record.setShareNumReal(0);
         record.setCreateTime(new Date());
         goodsEvaluateDao.save(record);
      } else {
         GoodsEvaluate resultObj = goodsEvaluateDao.getById(record.getId());
         GoodsEvaluate resultObj = goodsEvaluateDao.getById(id);
         if (resultObj == null)
            throw new GoodsEvaluateException(1, "修改内容已不存在");
@@ -137,6 +138,7 @@
         resultObj.setTitle(tilte);
         goodsEvaluateDao.save(resultObj);
      }
      return id;
   }
   /**
@@ -206,7 +208,11 @@
            if (StringUtil.isNullOrEmpty(videoUrl)) {
               throw new GoodsEvaluateException(1, "视频链接不能为空");
            }
            InputStream inputStream = filevideo.getInputStream();
            BufferedImage sourceImg = ImageIO.read(inputStream);
            int width = sourceImg.getWidth();
            int height = sourceImg.getHeight();
            String picLink = uploadPicture(filevideo);
            if (imgVideo != null) {
               String url = imgVideo.getUrl();
@@ -218,8 +224,6 @@
            } else {
               imgVideo = new ImgInfo();
               imgVideo.setId(UUID.randomUUID().toString().replace("-", ""));
               imgVideo.setW(1);
               imgVideo.setH(1);
               imgVideo.setLarge(true);
               imgVideo.setPid(pid);
               imgVideo.setUrl(picLink);
@@ -227,6 +231,8 @@
               imgVideo.setVideoUrl(videoUrl);
               imgVideo.setType(ImgEnum.video);
            }
            imgVideo.setW(width);
            imgVideo.setH(height);
         }
      }
@@ -256,10 +262,10 @@
               String picLink = pics[i];
               if (fileRequest != null) {
                  MultipartFile file = fileRequest.getFile("file" + i);
                  if (file == null) {
                     continue;
                  if (file != null) {
                     picLink = uploadPicture(file);
                  }
                  picLink = uploadPicture(file);
               }
               if (picLink.startsWith("http")) {
                  listpic.add(picLink);
@@ -298,8 +304,10 @@
               simpleGoods.setPrice(goodsDetailVO.getCouponPrice());
               CouponInfoVO couponInfo = goodsDetailVO.getCouponInfo();
               if (couponInfo == null) {
                  simpleGoods.setPrice(goodsDetailVO.getZkPrice());
                  simpleGoods.setState(1);
               } else {
                  simpleGoods.setPrice(goodsDetailVO.getCouponPrice());
                  simpleGoods.setAmount(couponInfo.getAmount());
                  simpleGoods.setState(0);
               }
@@ -401,6 +409,11 @@
               throw new GoodsEvaluateException(1, "视频链接不能为空");
            }
            InputStream inputStream = filevideo.getInputStream();
            BufferedImage sourceImg = ImageIO.read(inputStream);
            int width = sourceImg.getWidth();
            int height = sourceImg.getHeight();
            String picLink = uploadPicture(filevideo);
            if (imgVideo != null) {
               String url = imgVideo.getUrl();
@@ -412,8 +425,6 @@
            } else {
               imgVideo = new ImgInfo();
               imgVideo.setId(UUID.randomUUID().toString().replace("-", ""));
               imgVideo.setW(1);
               imgVideo.setH(1);
               imgVideo.setLarge(true);
               imgVideo.setPid(pid);
               imgVideo.setUrl(picLink);
@@ -421,6 +432,8 @@
               imgVideo.setVideoUrl(videoUrl);
               imgVideo.setType(ImgEnum.video);
            }
            imgVideo.setW(width);
            imgVideo.setH(height);
         }
      }
@@ -570,7 +583,7 @@
         }
         commentInfo.setContent(content);
         commentInfo.setType(CommentInfoEnum.goodsCoupon);
         comments.add(currencyCoupon);
         comments.add(commentInfo);
      }
      
      if (currencyCoupon != null) {
@@ -671,11 +684,18 @@
         }
      }
      int width = 0;
      int height = 0;
      List<ImgInfo> listImg = new ArrayList<ImgInfo>();
      if (fileRequest != null) {
         MultipartFile filevideo = fileRequest.getFile("filevideo");
         if (filevideo != null) {
            removePicture(videoPic);
            InputStream inputStream = filevideo.getInputStream();
            BufferedImage sourceImg = ImageIO.read(inputStream);
            width = sourceImg.getWidth();
            height = sourceImg.getHeight();
            String picLink = uploadPicture(filevideo);
            videoPic = picLink;
         }
@@ -696,14 +716,19 @@
         } else {
            imgVideo = new ImgInfo();
            imgVideo.setId(UUID.randomUUID().toString().replace("-", ""));
            imgVideo.setW(1);
            imgVideo.setH(1);
            imgVideo.setLarge(true);
            imgVideo.setPid(pid);
            imgVideo.setUrl(videoPic);
            imgVideo.setUrlHD(videoPic);
            imgVideo.setVideoUrl(imgInfo.getVideoUrl());
            imgVideo.setType(ImgEnum.video);
         }
         if (width > 0) {
            imgVideo.setW(width);
            imgVideo.setH(height);
         } else {
            imgVideo.setW(imgVideo.getW());
            imgVideo.setH(imgVideo.getH());
         }
         listImg.add(imgVideo);
      }
@@ -770,7 +795,11 @@
            if (StringUtil.isNullOrEmpty(videoUrl)) {
               throw new GoodsEvaluateException(1, "视频链接不能为空");
            }
            InputStream inputStream = filevideo.getInputStream();
            BufferedImage sourceImg = ImageIO.read(inputStream);
            int width = sourceImg.getWidth();
            int height = sourceImg.getHeight();
            String picLink = uploadPicture(filevideo);
            if (imgVideo != null) {
               String url = imgVideo.getUrl();
@@ -782,8 +811,6 @@
            } else {
               imgVideo = new ImgInfo();
               imgVideo.setId(UUID.randomUUID().toString().replace("-", ""));
               imgVideo.setW(1);
               imgVideo.setH(1);
               imgVideo.setLarge(true);
               imgVideo.setPid(pid);
               imgVideo.setUrl(picLink);
@@ -791,6 +818,8 @@
               imgVideo.setVideoUrl(videoUrl);
               imgVideo.setType(ImgEnum.video);
            }
            imgVideo.setW(width);
            imgVideo.setH(height);
         }
      }
@@ -1122,3 +1151,4 @@
   }
}