yj
2020-03-07 c6037befc88e7e92e93fb928ce20078b6fe293d8
fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java
@@ -187,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("-", "") + "."
@@ -209,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, "请保存第一部分信息");
@@ -248,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());
         }
      }
@@ -444,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());
@@ -495,6 +512,8 @@
            }
         }
      }
      return commentText;
   }
   private String createTokenAndLink(GoodsDetailVO goodsDetailVO) throws Exception {
@@ -598,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());
         }
      }
@@ -1014,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");
@@ -1064,6 +1072,7 @@
         listImg.add(imgVideo);
      }
      int totalImg = 0;
      if (!StringUtil.isNullOrEmpty(activityPic) || !StringUtil.isNullOrEmpty(imgInfo.getActivityUrl())) {
         if (imgactivity != null) {
            imgactivity.setUrl(activityPic);
@@ -1087,8 +1096,21 @@
            imgactivity.setH(imgactivity.getH());
         }
         listImg.add(imgactivity);
         totalImg ++;
      }
      resultObj.setLineNum(1);
      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);
   }
@@ -1137,39 +1159,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");
@@ -1215,6 +1227,7 @@
         listImg.add(imgActivity);
      }
      int totalImg = 0;
      // 编辑图片
      if (!StringUtil.isNullOrEmpty(picUrls)) {
         String[] pics = picUrls.split(",");
@@ -1233,9 +1246,10 @@
                     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);
                     totalImg ++;
                     continue;
                  }
               }
@@ -1246,6 +1260,7 @@
                        String url = imgInfo.getUrl();
                        if (picLink.equals(url)) {
                           listImg.add(imgInfo);
                           totalImg ++;
                           break;
                        }
                     }
@@ -1269,7 +1284,19 @@
               listDel.add(listOld.get(j));
         }
      }
      resultObj.setLineNum(1);
      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);
@@ -1445,18 +1472,18 @@
   }
   @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);
      if (list == null) {
         list = new ArrayList<>();
      }
      Date now = new Date();
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      List<GoodsEvaluate> listNew = new ArrayList<>();
      for (GoodsEvaluate goodsEvaluate : list) {
         GoodsEvaluate evaluateNew = new GoodsEvaluate();
         try {
            PropertyUtils.copyProperties(evaluateNew, goodsEvaluate);
@@ -1464,7 +1491,7 @@
            e.printStackTrace();
            continue;
         }
         int comment = 0;
         List<CommentInfo> comments = evaluateNew.getComments();
         if (comments != null && comments.size() > 0) {
@@ -1472,32 +1499,45 @@
            List<CommentInfo> commentNew = new ArrayList<>();
            for (CommentInfo commentInfo : comments) {
               if (StringUtil.isNullOrEmpty(commentInfo.getContent()) &&
                     StringUtil.isNullOrEmpty(commentInfo.getCoupon())) {
                  continue;
               }
               CommentInfo commentInfoNew = new CommentInfo();
               try {
                  PropertyUtils.copyProperties(commentInfoNew, commentInfo);
               } catch (Exception e) {
                  e.printStackTrace();
                  continue;
               }
               comment++;
               CommentInfoEnum typeComment = commentInfo.getTypeEnum();
               CommentInfoEnum typeComment = commentInfoNew.getTypeEnum();
               if (typeComment != null && typeComment == CommentInfoEnum.goodsCoupon) {
                  GoodsDetailVO goods = evaluateNew.getGoods();
                  if (goods.isHasCoupon()) {
                     commentNew.add(commentInfo);
                  if (goods != null && goods.isHasCoupon()) {
                     commentNew.add(commentInfoNew);
                     continue;
                  }
               }
               String coupon = commentInfo.getCoupon();
               String endTime = commentInfo.getEndTime();
               String coupon = commentInfoNew.getCoupon();
               String endTime = commentInfoNew.getEndTime();
               if (!StringUtil.isNullOrEmpty(coupon) && !StringUtil.isNullOrEmpty(endTime)) {
                  Date endDay = sdf.parse(endTime);
                  if (endDay.getTime() > now.getTime()) {
                     int daysBetween = DateUtil.daysBetween(now, endDay);
                     if (daysBetween > 0) {
                     String daysBetween = DateUtil.dateDiff5(now, endDay);
                     if (!StringUtil.isNullOrEmpty(daysBetween)) {
                        ClientTextStyleVO styleVO = new ClientTextStyleVO();
                        styleVO.setColor("#E5005C");
                        styleVO.setContent(daysBetween + "天后过期");
                        styleVO.setContent(daysBetween + "后过期");
                        List<ClientTextStyleVO> tagList = commentInfo.getTagList();
                        List<ClientTextStyleVO> tagList = commentInfoNew.getTagList();
                        tagList.add(styleVO);
                        commentInfo.setTagList(tagList);
                        commentInfoNew.setTagList(tagList);
                        commentNew.add(commentInfo);
                        commentNew.add(commentInfoNew);
                        continue;
                     }
                  }
@@ -1529,7 +1569,7 @@
               }
            }
         }
         listNew.add(evaluateNew);
      }
@@ -1541,7 +1581,7 @@
            updateGoodInfo(listOBJ);
         }
      });
      return listNew;
   }