Administrator
2020-02-23 c713e939be20443e0aa3b1ef4d7f576469b85ca8
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;
@@ -209,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();
@@ -221,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);
@@ -230,6 +231,8 @@
               imgVideo.setVideoUrl(videoUrl);
               imgVideo.setType(ImgEnum.video);
            }
            imgVideo.setW(width);
            imgVideo.setH(height);
         }
      }
@@ -276,6 +279,12 @@
         picNum = 1;
      }
      GoodsDetailVO goodsDetailVO = getGoodsDetailVO(goodsId, goodsType);;
      if (goodsDetailVO == null) {
         throw new GoodsEvaluateException(1, "该商品信息不存在");
      }
      int totalImg = 0;
      if (listpic != null && listpic.size() > 0) {
         for (int i = 0; i < listpic.size(); i++) {
            ImgInfo imgInfo0 = new ImgInfo();
@@ -289,28 +298,26 @@
            if (picNum - 1 == i) {
               imgInfo0.setType(ImgEnum.goods);
               // 商品信息
               GoodsDetailVO goodsDetailVO = getGoodsDetailVO(goodsId, goodsType);
               if (goodsDetailVO == null) {
                  throw new GoodsEvaluateException(1, "该商品信息不存在");
               }
               SimpleGoods simpleGoods = new SimpleGoods();
               simpleGoods.setGoodsId(goodsId);
               simpleGoods.setGoodsType(goodsType);
               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);
               }
               imgInfo0.setGoods(simpleGoods);
               imgInfo0.setGoodsVO(goodsDetailVO);
            } else {
               imgInfo0.setType(ImgEnum.img);
            }
            listImg.add(imgInfo0);
            totalImg ++;
         }
      }
@@ -329,7 +336,19 @@
         }
      }
      
      // 保存图片信息
      int lineNum = 0;
      if (totalImg > 0) {
         if (totalImg == 1) {
            lineNum = 1;
         } else if (totalImg <= 4) {
            lineNum = 2;
         } else {
            lineNum = 3;
         }
      }
      resultObj.setLineNum(lineNum);
      resultObj.setGoods(goodsDetailVO);
      resultObj.setMainPicNum(picNum);
      resultObj.setImgList(listImg);
      goodsEvaluateDao.save(resultObj);
@@ -404,6 +423,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();
@@ -415,8 +439,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);
@@ -424,6 +446,8 @@
               imgVideo.setVideoUrl(videoUrl);
               imgVideo.setType(ImgEnum.video);
            }
            imgVideo.setW(width);
            imgVideo.setH(height);
         }
      }
@@ -443,10 +467,11 @@
         }
      }
      int totalImg = 0;
      if (!StringUtil.isNullOrEmpty(goodsList)) {
         String[] goodsArray = goodsList.split(",");
         if (goodsArray != null && goodsArray.length > 0) {
            for (int i = 0; i < goodsArray.length || i < 9; i++) {
            for (int i = 0; i < goodsArray.length && i < 9; i++) {
               String goodsids = goodsArray[i];
               String[] g = goodsids.split("-");
               GoodsDetailVO goodsDetailVO = getGoodsDetailVO(Long.parseLong(g[0]), Integer.parseInt(g[1]));
@@ -484,6 +509,9 @@
                  simpleGoods.setState(0);
               }
               imgInfo0.setGoods(simpleGoods);
               imgInfo0.setGoodsVO(goodsDetailVO);
               listImg.add(imgInfo0);
               totalImg ++;
            }
         }
      }
@@ -526,6 +554,19 @@
         }
      }
      int lineNum = 0;
      if (totalImg > 0) {
         if (totalImg == 1) {
            lineNum = 1;
         } else if (totalImg <= 4) {
            lineNum = 2;
         } else {
            lineNum = 3;
         }
      }
      resultObj.setLineNum(lineNum);
      // 保存图片信息
      resultObj.setImgList(listImg);
      goodsEvaluateDao.save(resultObj);
@@ -573,7 +614,7 @@
         }
         commentInfo.setContent(content);
         commentInfo.setType(CommentInfoEnum.goodsCoupon);
         comments.add(currencyCoupon);
         comments.add(commentInfo);
      }
      
      if (currencyCoupon != null) {
@@ -674,11 +715,20 @@
         }
      }
      int width = 0;
      int height = 0;
      int width2 = 0;
      int height2 = 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;
         }
@@ -686,6 +736,10 @@
         MultipartFile activityfile = fileRequest.getFile("activityfile");
         if (activityfile != null) {
            removePicture(activityPic);
            InputStream inputStream = activityfile.getInputStream();
            BufferedImage sourceImg = ImageIO.read(inputStream);
            width2 = sourceImg.getWidth();
            height2 = sourceImg.getHeight();
            String picLink = uploadPicture(activityfile);
            activityPic = picLink;
         }
@@ -699,14 +753,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);
      }
@@ -719,8 +778,6 @@
         } else {
            imgactivity = new ImgInfo();
            imgactivity.setId(UUID.randomUUID().toString().replace("-", ""));
            imgactivity.setW(1);
            imgactivity.setH(1);
            imgactivity.setLarge(true);
            imgactivity.setPid(pid);
            imgactivity.setUrl(activityPic);
@@ -728,8 +785,16 @@
            imgactivity.setActivityUrl(imgInfo.getActivityUrl());
            imgactivity.setType(ImgEnum.activity);
         }
         if (width2 > 0) {
            imgactivity.setW(width2);
            imgactivity.setH(height2);
         } else {
            imgactivity.setW(imgactivity.getW());
            imgactivity.setH(imgactivity.getH());
         }
         listImg.add(imgactivity);
      }
      resultObj.setLineNum(1);
      resultObj.setImgList(listImg);
      goodsEvaluateDao.save(resultObj);
   }
@@ -749,7 +814,8 @@
      ImgInfo imgVideo = null;
      List<String> listDel = new ArrayList<String>();
      List<String> listOld = new ArrayList<String>();
      List<ImgInfo> listOldImgInfo = new ArrayList<ImgInfo>();
      // 处理图片
      List<ImgInfo> resultList = resultObj.getImgList();
      if (resultList != null && resultList.size() > 0) {
@@ -758,6 +824,7 @@
            if (type == ImgEnum.video) {
               imgVideo = info;
            } else if (type == ImgEnum.img) {
               listOldImgInfo.add(info);
               String url = info.getUrl();
               if (!StringUtil.isNullOrEmpty(url)) {
                  listOld.add(url);
@@ -773,7 +840,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();
@@ -785,8 +856,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);
@@ -794,6 +863,8 @@
               imgVideo.setVideoUrl(videoUrl);
               imgVideo.setType(ImgEnum.video);
            }
            imgVideo.setW(width);
            imgVideo.setH(height);
         }
      }
@@ -803,6 +874,7 @@
            if (imgVideo != null && StringUtil.isNullOrEmpty(imgVideo.getUrl())) {
               throw new GoodsEvaluateException(1, "视频封面图不能为空");
            }
            imgVideo.setVideoUrl(videoUrl);
            listImg.add(imgVideo);
         } else {
@@ -824,29 +896,38 @@
               if (fileRequest != null) {
                  MultipartFile file = fileRequest.getFile("file" + i);
                  if (file != null) {
                     InputStream inputStream = file.getInputStream();
                     BufferedImage sourceImg = ImageIO.read(inputStream);
                     int width = sourceImg.getWidth();
                     int height = sourceImg.getHeight();
                     picLink = uploadPicture(file);
                     ImgInfo imgInfo0 = new ImgInfo();
                     imgInfo0.setId(UUID.randomUUID().toString().replace("-", ""));
                     imgInfo0.setLarge(false);
                     imgInfo0.setPid(pid);
                     imgInfo0.setUrl(listpic.get(i));
                     imgInfo0.setUrlHD(listpic.get(i));
                     imgInfo0.setType(ImgEnum.img);
                     imgVideo.setW(width);
                     imgVideo.setH(height);
                     listImg.add(imgInfo0);
                     continue;
                  }
               }
               
               if (picLink.startsWith("http")) {
                  listpic.add(picLink);
                  if(listOldImgInfo != null) {
                     for (ImgInfo imgInfo:listOldImgInfo) {
                        String url = imgInfo.getUrl();
                        if (picLink.equals(url)){
                           listImg.add(imgInfo);
                           break;
                        }
                     }
                  }
               }
            }
         }
      }
      if (listpic != null && listpic.size() > 0) {
         for (int i = 0; i < listpic.size(); i++) {
            ImgInfo imgInfo0 = new ImgInfo();
            imgInfo0.setId(UUID.randomUUID().toString().replace("-", ""));
            imgInfo0.setW(1);
            imgInfo0.setH(1);
            imgInfo0.setLarge(false);
            imgInfo0.setPid(pid);
            imgInfo0.setUrl(listpic.get(i));
            imgInfo0.setUrlHD(listpic.get(i));
            imgInfo0.setType(ImgEnum.img);
            listImg.add(imgInfo0);
         }
      }
@@ -864,7 +945,7 @@
               listDel.add(listOld.get(j));
         }
      }
      resultObj.setLineNum(1);
      resultObj.setImgList(listImg);
      goodsEvaluateDao.save(resultObj);
@@ -1125,3 +1206,4 @@
   }
}