yj
2020-03-06 bf6ca2b873f4d3c71d2810fad2683b03ae5efe4a
fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java
@@ -16,6 +16,7 @@
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;
@@ -186,8 +187,33 @@
            + type;
      return COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
   }
   private String uploadPicture(File file,String contentType) throws Exception {
   private ImgInfo uploadVideoPicture(MultipartFile filevideo) {
      try {
         File tempFile = new File(FileUtil.getCacheDir() + "/" + filevideo.getOriginalFilename());
         if (tempFile.exists())
            tempFile.delete();
         tempFile.createNewFile();
         filevideo.transferTo(tempFile);
         File destFile = new File(FileUtil.getCacheDir() + "/temp_" + filevideo.getOriginalFilename());
         // 裁剪视频封面,宽高比为2:1
         ImageCropUtil.centerCrop(tempFile, destFile, 2.0f);
         BufferedImage sourceImg = ImageIO.read(new FileInputStream(destFile));
         ImgInfo info = new ImgInfo();
         int width = sourceImg.getWidth();
         int height = sourceImg.getHeight();
         String picLink = uploadPicture(destFile, filevideo.getContentType());
         info.setH(height);
         info.setW(width);
         info.setUrl(picLink);
         return info;
      } catch (Exception e) {
         e.printStackTrace();
      }
      return null;
   }
   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("-", "") + "."
@@ -208,7 +234,7 @@
   }
   @Override
   public void saveSingleGoods(String pid, Long goodsId, Integer goodsType, String videoUrl, Integer picNum,
   public String saveSingleGoods(String pid, Long goodsId, Integer goodsType, String videoUrl, Integer picNum,
         String picUrls, MultipartHttpServletRequest fileRequest) throws GoodsEvaluateException, Exception {
      if (StringUtil.isNullOrEmpty(pid)) {
         throw new GoodsEvaluateException(1, "请保存第一部分信息");
@@ -247,36 +273,28 @@
            if (StringUtil.isNullOrEmpty(videoUrl)) {
               throw new GoodsEvaluateException(1, "视频链接不能为空");
            }
            InputStream inputStream = filevideo.getInputStream();
            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(destFile,filevideo.getContentType());
            ImgInfo info = uploadVideoPicture(filevideo);
            if (info == null)
               throw new GoodsEvaluateException(2, "视频图片上传失败");
            if (imgVideo != null) {
               String url = imgVideo.getUrl();
               if (!StringUtil.isNullOrEmpty(url)) {
                  listDel.add(url);
               }
               imgVideo.setUrl(picLink);
               imgVideo.setUrlHD(picLink);
               imgVideo.setUrl(info.getUrl());
               imgVideo.setUrlHD(info.getUrl());
            } else {
               imgVideo = new ImgInfo();
               imgVideo.setId(UUID.randomUUID().toString().replace("-", ""));
               imgVideo.setLarge(true);
               imgVideo.setPid(pid);
               imgVideo.setUrl(picLink);
               imgVideo.setUrlHD(picLink);
               imgVideo.setUrl(info.getUrl());
               imgVideo.setUrlHD(info.getUrl());
               imgVideo.setVideoUrl(videoUrl);
               imgVideo.setType(ImgEnum.video);
            }
            imgVideo.setW(width);
            imgVideo.setH(height);
            imgVideo.setW(info.getW());
            imgVideo.setH(info.getH());
         }
      }
@@ -443,8 +461,8 @@
       * = false; }
       */
      String commentText = "";
      if (addComment) {
         String commentText = "";
         if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
            TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(1L, goodsId, "0");
            String template = configService.get(ConfigKeyEnum.quickShareTBCommentText.getKey());
@@ -494,6 +512,8 @@
            }
         }
      }
      return commentText;
   }
   private String createTokenAndLink(GoodsDetailVO goodsDetailVO) throws Exception {
@@ -597,35 +617,29 @@
               throw new GoodsEvaluateException(1, "视频链接不能为空");
            }
            InputStream inputStream = filevideo.getInputStream();
            File destFile = new File(FileUtil.getCacheDir() + "/temp_" + filevideo.getName());
            // 裁剪视频封面,宽高比为2:1
            ImageCropUtil.centerCrop(inputStream, destFile, 2.0f);
            ImgInfo info = uploadVideoPicture(filevideo);
            if (info == null)
               throw new GoodsEvaluateException(2, "视频图片上传失败");
            BufferedImage sourceImg = ImageIO.read(new FileInputStream(destFile));
            int width = sourceImg.getWidth();
            int height = sourceImg.getHeight();
            String picLink = uploadPicture(destFile,filevideo.getContentType());
            if (imgVideo != null) {
               String url = imgVideo.getUrl();
               if (!StringUtil.isNullOrEmpty(url)) {
                  listDel.add(url);
               }
               imgVideo.setUrl(picLink);
               imgVideo.setUrlHD(picLink);
               imgVideo.setUrl(info.getUrl());
               imgVideo.setUrlHD(info.getUrl());
            } else {
               imgVideo = new ImgInfo();
               imgVideo.setId(UUID.randomUUID().toString().replace("-", ""));
               imgVideo.setLarge(true);
               imgVideo.setPid(pid);
               imgVideo.setUrl(picLink);
               imgVideo.setUrlHD(picLink);
               imgVideo.setUrl(info.getUrl());
               imgVideo.setUrlHD(info.getUrl());
               imgVideo.setVideoUrl(videoUrl);
               imgVideo.setType(ImgEnum.video);
            }
            imgVideo.setW(width);
            imgVideo.setH(height);
            imgVideo.setW(info.getW());
            imgVideo.setH(info.getH());
         }
      }
@@ -1013,17 +1027,12 @@
         if (filevideo != null) {
            removePicture(videoPic);
            InputStream inputStream = filevideo.getInputStream();
            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(destFile,filevideo.getContentType());
            videoPic = picLink;
            ImgInfo info = uploadVideoPicture(filevideo);
            if (info == null)
               throw new GoodsEvaluateException(2, "视频图片上传失败");
            videoPic = info.getUrl();
            width=info.getW();
            height=info.getH();
         }
         MultipartFile activityfile = fileRequest.getFile("activityfile");
@@ -1136,39 +1145,29 @@
         if (filevideo != null) {
            if (StringUtil.isNullOrEmpty(videoUrl)) {
               throw new GoodsEvaluateException(1, "视频链接不能为空");
            }
            InputStream inputStream = filevideo.getInputStream();
            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(destFile,filevideo.getContentType());
            }
            ImgInfo info = uploadVideoPicture(filevideo);
            if (info == null)
               throw new GoodsEvaluateException(2, "视频图片上传失败");
            if (imgVideo != null) {
               String url = imgVideo.getUrl();
               if (!StringUtil.isNullOrEmpty(url)) {
                  listDel.add(url);
               }
               imgVideo.setUrl(picLink);
               imgVideo.setUrlHD(picLink);
               imgVideo.setUrl(info.getUrl());
               imgVideo.setUrlHD(info.getUrl());
            } else {
               imgVideo = new ImgInfo();
               imgVideo.setId(UUID.randomUUID().toString().replace("-", ""));
               imgVideo.setLarge(true);
               imgVideo.setPid(pid);
               imgVideo.setUrl(picLink);
               imgVideo.setUrlHD(picLink);
               imgVideo.setUrl(info.getUrl());
               imgVideo.setUrlHD(info.getUrl());
               imgVideo.setVideoUrl(videoUrl);
               imgVideo.setType(ImgEnum.video);
            }
            imgVideo.setW(width);
            imgVideo.setH(height);
            imgVideo.setW(info.getW());
            imgVideo.setH(info.getH());
         }
         activityFile = fileRequest.getFile("activityFile");
@@ -1232,8 +1231,8 @@
                     imgInfo0.setUrl(picLink);
                     imgInfo0.setUrlHD(picLink);
                     imgInfo0.setType(ImgEnum.img);
                     imgVideo.setW(1);
                     imgVideo.setH(1);
                     imgInfo0.setW(1);
                     imgInfo0.setH(1);
                     listImg.add(imgInfo0);
                     continue;
                  }
@@ -1444,38 +1443,38 @@
   }
   @Override
   @Cacheable(value = "dynamicCache", key = "'queryMaterialsCache-'+#start+'-'+#type")
   // @Cacheable(value = "dynamicCache", key =
   // "'queryMaterialsCache-'+#start+'-'+#type")
   public List<GoodsEvaluate> queryMaterialsCache(int start, int count, int type) throws Exception {
      List<GoodsEvaluate> list = goodsEvaluateDao.queryValid(start, count, type);
      List<GoodsEvaluate> listOBJ = list;
      // 更新商品信息
      executor.execute(new Runnable() {
         @Override
         public void run() {
            updateGoodInfo(listOBJ);
         }
      });
      if (list == null) {
         list = new ArrayList<>();
      }
      Date now = new Date();
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      List<GoodsEvaluate> listNew = new ArrayList<>();
      for (GoodsEvaluate goodsEvaluate : list) {
         GoodsEvaluate evaluateNew = new GoodsEvaluate();
         try {
            PropertyUtils.copyProperties(evaluateNew, goodsEvaluate);
         } catch (Exception e) {
            e.printStackTrace();
            continue;
         }
         int comment = 0;
         List<CommentInfo> comments = goodsEvaluate.getComments();
         List<CommentInfo> comments = evaluateNew.getComments();
         if (comments != null && comments.size() > 0) {
            EvaluateEnum typeEnum = goodsEvaluate.getType();
            EvaluateEnum typeEnum = evaluateNew.getType();
            List<CommentInfo> commentNew = new ArrayList<>();
            for (CommentInfo commentInfo : comments) {
               comment++;
               CommentInfoEnum typeComment = commentInfo.getTypeEnum();
               if (typeComment != null && typeComment == CommentInfoEnum.goodsCoupon) {
                  GoodsDetailVO goods = goodsEvaluate.getGoods();
                  GoodsDetailVO goods = evaluateNew.getGoods();
                  if (goods.isHasCoupon()) {
                     commentNew.add(commentInfo);
                     continue;
@@ -1505,17 +1504,17 @@
               commentNew.add(commentInfo);
            }
            goodsEvaluate.setComments(commentNew);
            evaluateNew.setComments(commentNew);
            if (typeEnum != null && typeEnum == EvaluateEnum.single) {
               if (comment > 0 && commentNew.size() == 0) { // 所有券评论下架
                  GoodsDetailVO goods = goodsEvaluate.getGoods();
                  GoodsDetailVO goods = evaluateNew.getGoods();
                  if (goods != null) {
                     goods.setState(1); // 评论不存在 下架
                     LogHelper.test("获取列表商品下架1");
                  }
                  List<ImgInfo> imgList = goodsEvaluate.getImgList();
                  List<ImgInfo> imgList = evaluateNew.getImgList();
                  if (imgList != null) {
                     for (ImgInfo imgInfo : imgList) {
                        SimpleGoods simpleGoods = imgInfo.getGoods();
@@ -1529,9 +1528,20 @@
               }
            }
         }
         listNew.add(evaluateNew);
      }
      return list;
      List<GoodsEvaluate> listOBJ = list;
      // 更新商品信息
      executor.execute(new Runnable() {
         @Override
         public void run() {
            updateGoodInfo(listOBJ);
         }
      });
      return listNew;
   }
   @Override