admin
2020-03-05 58720dd94aae4c360e9a18c5e608033c85d4e11f
fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java
@@ -1,6 +1,8 @@
package com.yeshi.fanli.service.impl.dynamic;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
@@ -20,7 +22,7 @@
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.yeshi.utils.DateUtil;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.ImageCropUtil;
import org.yeshi.utils.tencentcloud.COSManager;
import com.yeshi.fanli.dao.dynamic.GoodsEvaluateDao;
@@ -54,11 +56,11 @@
import com.yeshi.fanli.service.manger.goods.ConvertLinkManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.FilePathEnum;
import com.yeshi.fanli.util.FileUtil;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.cache.JDGoodsCacheUtil;
import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil;
import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.util.jd.JDApiUtil;
import com.yeshi.fanli.util.jd.JDUtil;
@@ -86,7 +88,6 @@
   @Resource(name = "taskExecutor")
   private TaskExecutor executor;
   @Resource
   private JDGoodsCacheUtil jdGoodsCacheUtil;
@@ -101,8 +102,6 @@
   
   @Resource
   private ConvertLinkManager convertLinkManager;
   @Override
   public String saveHead(MultipartFile file, GoodsEvaluate record) throws GoodsEvaluateException {
@@ -188,6 +187,14 @@
      return COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
   }
   private String uploadPicture(File file,String contentType) throws Exception {
      InputStream inputStream = new FileInputStream(file);
      String type = contentType.substring(contentType.indexOf("/") + 1);
      String filePath = FilePathEnum.goodsEvaluate.getPath() + UUID.randomUUID().toString().replace("-", "") + "."
            + type;
      return COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
   }
   /**
    * 删除图片
    * 
@@ -241,11 +248,16 @@
               throw new GoodsEvaluateException(1, "视频链接不能为空");
            }
            InputStream inputStream = filevideo.getInputStream();
            BufferedImage sourceImg = ImageIO.read(inputStream);
            File destFile = new File(FileUtil.getCacheDir() + "/temp_" + filevideo.getName());
            // 裁剪视频封面,宽高比为2:1
            ImageCropUtil.centerCrop(inputStream, destFile, 2.0f);
            BufferedImage sourceImg = ImageIO.read(new FileInputStream(destFile));
            int width = sourceImg.getWidth();
            int height = sourceImg.getHeight();
            String picLink = uploadPicture(filevideo);
            String picLink =  uploadPicture(destFile,filevideo.getContentType());
            if (imgVideo != null) {
               String url = imgVideo.getUrl();
               if (!StringUtil.isNullOrEmpty(url)) {
@@ -426,10 +438,10 @@
      } 
      
      /*
       * // 无券不能自动 生成评论 CouponInfoVO couponInfo1 = goodsDetailVO.getCouponInfo(); if
       * (couponInfo1 == null) { addComment = false; }
       * // 无券不能自动 生成评论 CouponInfoVO couponInfo1 =
       * goodsDetailVO.getCouponInfo(); if (couponInfo1 == null) { addComment
       * = false; }
       */
      
      if (addComment) {
         String commentText = "";
@@ -444,7 +456,8 @@
               couponUrl = couponInfo.getLink();
            }
            String materialId = "https://item.jd.com/" + goodsId + ".html";
            String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "","1");
            String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl,
                  JDApiUtil.POSITION_SHARE + "", "1");
            String template = configService.get(ConfigKeyEnum.quickShareJDCommentText.getKey());
            commentText = template.replace("[链接]", jumpLink);         
         } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
@@ -461,8 +474,8 @@
            commentText = commentText.replace("[券后价]", goodsDetailVO.getCouponPrice().toString());
         }
         
         commentText =commentText.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n");
         commentText = commentText.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n").replace("\r\n\r\n",
               "\r\n");
         
         CommentInfo commentInfo = new CommentInfo();
         commentInfo.setId(UUID.randomUUID().toString().replace("-", ""));
@@ -483,7 +496,6 @@
      }
   }
   private String createTokenAndLink(GoodsDetailVO goodsDetailVO) throws Exception {
      String commentText = "";
      if (goodsDetailVO.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) {
@@ -499,11 +511,13 @@
            couponUrl = couponInfo.getLink();
         }
         String materialId = "https://item.jd.com/" + goodsDetailVO.getGoodsId() + ".html";
         String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "","1");
         String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "",
               "1");
         String template = configService.get(ConfigKeyEnum.quickShareJDCommentText.getKey());
         commentText = template.replace("[链接]", jumpLink);         
      } else if (goodsDetailVO.getGoodsType()  == Constant.SOURCE_TYPE_PDD) {
         String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsDetailVO.getGoodsId(), PinDuoDuoApiUtil.PID_SHARE + "", "1");
         String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsDetailVO.getGoodsId(),
               PinDuoDuoApiUtil.PID_SHARE + "", "1");
         String template = configService.get(ConfigKeyEnum.quickSharePDDCommentText.getKey());
         commentText = template.replace("[链接]", jumpLink);
      }
@@ -584,11 +598,15 @@
            }
            InputStream inputStream = filevideo.getInputStream();
            BufferedImage sourceImg = ImageIO.read(inputStream);
            File destFile = new File(FileUtil.getCacheDir() + "/temp_" + filevideo.getName());
            // 裁剪视频封面,宽高比为2:1
            ImageCropUtil.centerCrop(inputStream, destFile, 2.0f);
            BufferedImage sourceImg = ImageIO.read(new FileInputStream(destFile));
            int width = sourceImg.getWidth();
            int height = sourceImg.getHeight();
            String picLink = uploadPicture(filevideo);
            String picLink = uploadPicture(destFile,filevideo.getContentType());
            if (imgVideo != null) {
               String url = imgVideo.getUrl();
               if (!StringUtil.isNullOrEmpty(url)) {
@@ -743,9 +761,9 @@
      }
   }
   @Override
   public void saveGoodsComment(String id, int kind, List<CommentInfo> comments) throws GoodsEvaluateException, Exception {
   public void saveGoodsComment(String id, int kind, List<CommentInfo> comments)
         throws GoodsEvaluateException, Exception {
      if (comments == null || comments.size() == 0 ) {
         throw new GoodsEvaluateException(1, "内容不能为空");
      }
@@ -860,7 +878,8 @@
   }
   @Override
   public void saveCurrencyCoupon(String pid, int kind, CommentInfo commentInfo) throws GoodsEvaluateException, Exception {
   public void saveCurrencyCoupon(String pid, int kind, CommentInfo commentInfo)
         throws GoodsEvaluateException, Exception {
      if (StringUtil.isNullOrEmpty(pid)) {
         throw new GoodsEvaluateException(1, "请保存第一部分信息");
      }
@@ -995,10 +1014,15 @@
            removePicture(videoPic);
            InputStream inputStream = filevideo.getInputStream();
            BufferedImage sourceImg = ImageIO.read(inputStream);
            File destFile = new File(FileUtil.getCacheDir() + "/temp_" + filevideo.getName());
            // 裁剪视频封面,宽高比为2:1
            ImageCropUtil.centerCrop(inputStream, destFile, 2.0f);
            BufferedImage sourceImg = ImageIO.read(new FileInputStream(destFile));
            width = sourceImg.getWidth();
            height = sourceImg.getHeight();
            String picLink = uploadPicture(filevideo);
            String picLink =  uploadPicture(destFile,filevideo.getContentType());
            videoPic = picLink;
         }
@@ -1114,11 +1138,18 @@
               throw new GoodsEvaluateException(1, "视频链接不能为空");
            }
            InputStream inputStream = filevideo.getInputStream();
            BufferedImage sourceImg = ImageIO.read(inputStream);
            File destFile = new File(FileUtil.getCacheDir() + "/temp_" + filevideo.getName());
            // 裁剪视频封面,宽高比为2:1
            ImageCropUtil.centerCrop(inputStream, destFile, 2.0f);
            BufferedImage sourceImg = ImageIO.read(new FileInputStream(destFile));
            int width = sourceImg.getWidth();
            int height = sourceImg.getHeight();
            String picLink = uploadPicture(filevideo);
            String picLink =  uploadPicture(destFile,filevideo.getContentType());
            if (imgVideo != null) {
               String url = imgVideo.getUrl();
               if (!StringUtil.isNullOrEmpty(url)) {
@@ -1719,8 +1750,8 @@
               } else {
                  commentText = commentText.replace("[券后价]", goodsVO.getCouponPrice().toString());
               }
               commentText =commentText.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n");
               commentText = commentText.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n")
                     .replace("\r\n\r\n", "\r\n");
               
               CommentInfo commentInfo = new CommentInfo();
               commentInfo.setId(UUID.randomUUID().toString().replace("-", ""));