admin
2020-03-06 ce2c33ba07d0b0cbb14ec6b37b72b19d073b15af
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("-", "") + "."
@@ -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());
         }
      }
@@ -597,35 +615,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 +1025,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 +1143,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");
@@ -1444,38 +1441,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 +1502,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 +1526,20 @@
               }
            }
         }
         listNew.add(evaluateNew);
      }
      return list;
      List<GoodsEvaluate> listOBJ = list;
      // 更新商品信息
      executor.execute(new Runnable() {
         @Override
         public void run() {
            updateGoodInfo(listOBJ);
         }
      });
      return listNew;
   }
   @Override