From d8fc4263dad4bf8112a9146dd8afbaceb6d4ea10 Mon Sep 17 00:00:00 2001 From: yj <Administrator@192> Date: 星期一, 09 三月 2020 22:28:48 +0800 Subject: [PATCH] 自动发圈 --- fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java | 615 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 502 insertions(+), 113 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java index 9e33f5b..c252c6d 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java +++ b/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; @@ -30,6 +31,7 @@ import com.yeshi.fanli.dto.jd.JDCouponInfo; import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; import com.yeshi.fanli.entity.bus.activity.ActivityUser; +import com.yeshi.fanli.entity.bus.clazz.GoodsClass; import com.yeshi.fanli.entity.dynamic.CommentInfo; import com.yeshi.fanli.entity.dynamic.CommentInfo.CommentInfoEnum; import com.yeshi.fanli.entity.dynamic.DynamicInfo; @@ -43,6 +45,7 @@ import com.yeshi.fanli.entity.system.ConfigKeyEnum; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.entity.taobao.TaoBaoLink; +import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2; import com.yeshi.fanli.exception.dynamic.ActivityUserException; import com.yeshi.fanli.exception.dynamic.GoodsEvaluateException; import com.yeshi.fanli.exception.goods.ConvertLinkExceptionException; @@ -53,10 +56,12 @@ import com.yeshi.fanli.service.inter.dynamic.GoodsEvaluateService; import com.yeshi.fanli.service.inter.goods.ShareGoodsService; import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; +import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailV2Service; 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.MoneyBigDecimalUtil; import com.yeshi.fanli.util.RedisManager; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.cache.JDGoodsCacheUtil; @@ -65,7 +70,9 @@ import com.yeshi.fanli.util.jd.JDApiUtil; import com.yeshi.fanli.util.jd.JDUtil; import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil; +import com.yeshi.fanli.util.taobao.DaTaoKeUtil; import com.yeshi.fanli.util.taobao.TaoBaoUtil; +import com.yeshi.fanli.util.taobao.TaoKeApiUtil; import com.yeshi.fanli.vo.goods.CouponInfoVO; import com.yeshi.fanli.vo.goods.GoodsDetailVO; import com.yeshi.fanli.vo.msg.ClientTextStyleVO; @@ -103,12 +110,16 @@ @Resource private ConvertLinkManager convertLinkManager; + @Resource + private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service; + @Override public String saveHead(MultipartFile file, GoodsEvaluate record) throws GoodsEvaluateException { Integer state = record.getState(); if (state == null) { state = 0; } + record.setState(state); String tilte = record.getTitle(); if (StringUtil.isNullOrEmpty(tilte)) { @@ -160,6 +171,7 @@ if (resultObj == null) throw new GoodsEvaluateException(1, "淇敼鍐呭宸蹭笉瀛樺湪"); + resultObj.setState(record.getState()); resultObj.setUser(record.getUser()); resultObj.setShareNum(record.getShareNum()); resultObj.setWeight(record.getWeight()); @@ -186,8 +198,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 +245,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 +284,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()); } } @@ -409,6 +438,8 @@ if (totalImg > 0) { if (totalImg == 1) { lineNum = 1; + } else if (totalImg == 3) { + lineNum = 3; } else if (totalImg <= 4) { lineNum = 2; } else { @@ -438,13 +469,12 @@ } /* - * // 鏃犲埜涓嶈兘鑷姩 鐢熸垚璇勮 CouponInfoVO couponInfo1 = - * goodsDetailVO.getCouponInfo(); if (couponInfo1 == null) { addComment - * = false; } + * // 鏃犲埜涓嶈兘鑷姩 鐢熸垚璇勮 CouponInfoVO couponInfo1 = goodsDetailVO.getCouponInfo(); if + * (couponInfo1 == null) { addComment = 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()); @@ -466,12 +496,12 @@ commentText = template.replace("[閾炬帴]", jumpLink); } - commentText = commentText.replace("[鍘熶环]", goodsDetailVO.getZkPrice().toString()); + commentText = commentText.replace("[鍘熶环]", MoneyBigDecimalUtil.getWithNoZera(goodsDetailVO.getZkPrice())+""); if (!goodsDetailVO.isHasCoupon()) { commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘"); commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", ""); } else { - commentText = commentText.replace("[鍒稿悗浠穄", goodsDetailVO.getCouponPrice().toString()); + commentText = commentText.replace("[鍒稿悗浠穄", MoneyBigDecimalUtil.getWithNoZera(goodsDetailVO.getCouponPrice())+""); } commentText = commentText.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", @@ -494,6 +524,8 @@ } } } + + return commentText; } private String createTokenAndLink(GoodsDetailVO goodsDetailVO) throws Exception { @@ -597,35 +629,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()); } } @@ -738,6 +764,8 @@ if (totalImg > 0) { if (totalImg == 1) { lineNum = 1; + } else if (totalImg == 3) { + lineNum = 3; } else if (totalImg <= 4) { lineNum = 2; } else { @@ -1013,17 +1041,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"); @@ -1063,6 +1086,7 @@ listImg.add(imgVideo); } + int totalImg = 0; if (!StringUtil.isNullOrEmpty(activityPic) || !StringUtil.isNullOrEmpty(imgInfo.getActivityUrl())) { if (imgactivity != null) { imgactivity.setUrl(activityPic); @@ -1086,8 +1110,23 @@ 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 == 3) { + lineNum = 3; + } else if (totalImg <= 4) { + lineNum = 2; + } else { + lineNum = 3; + } + } + + resultObj.setLineNum(lineNum); resultObj.setImgList(listImg); goodsEvaluateDao.save(resultObj); } @@ -1136,39 +1175,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"); @@ -1214,6 +1243,7 @@ listImg.add(imgActivity); } + int totalImg = 0; // 缂栬緫鍥剧墖 if (!StringUtil.isNullOrEmpty(picUrls)) { String[] pics = picUrls.split(","); @@ -1227,14 +1257,15 @@ ImgInfo imgInfo0 = new ImgInfo(); imgInfo0.setId(UUID.randomUUID().toString().replace("-", "")); - imgInfo0.setLarge(true); + imgInfo0.setLarge(false); imgInfo0.setPid(pid); 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; } } @@ -1245,6 +1276,7 @@ String url = imgInfo.getUrl(); if (picLink.equals(url)) { listImg.add(imgInfo); + totalImg++; break; } } @@ -1268,7 +1300,21 @@ listDel.add(listOld.get(j)); } } - resultObj.setLineNum(1); + + int lineNum = 0; + if (totalImg > 0) { + if (totalImg == 1) { + lineNum = 1; + } else if (totalImg == 3) { + lineNum = 3; + } else if (totalImg <= 4) { + lineNum = 2; + } else { + lineNum = 3; + } + } + + resultObj.setLineNum(lineNum); resultObj.setImgList(listImg); goodsEvaluateDao.save(resultObj); @@ -1444,78 +1490,93 @@ } @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"); + 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); + } 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++; + if (StringUtil.isNullOrEmpty(commentInfo.getContent()) + && StringUtil.isNullOrEmpty(commentInfo.getCoupon())) { + continue; + } - CommentInfoEnum typeComment = commentInfo.getTypeEnum(); + CommentInfo commentInfoNew = new CommentInfo(); + try { + PropertyUtils.copyProperties(commentInfoNew, commentInfo); + } catch (Exception e) { + e.printStackTrace(); + continue; + } + + comment++; + CommentInfoEnum typeComment = commentInfoNew.getTypeEnum(); if (typeComment != null && typeComment == CommentInfoEnum.goodsCoupon) { - GoodsDetailVO goods = goodsEvaluate.getGoods(); - if (goods.isHasCoupon()) { - commentNew.add(commentInfo); + GoodsDetailVO goods = evaluateNew.getGoods(); + 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)) { + List<ClientTextStyleVO> tagListNew = new ArrayList<>(); + List<ClientTextStyleVO> tagList = commentInfoNew.getTagList(); + if (tagList != null) { + tagListNew.addAll(tagList); + } + ClientTextStyleVO styleVO = new ClientTextStyleVO(); styleVO.setColor("#E5005C"); - styleVO.setContent(daysBetween + "澶╁悗杩囨湡"); - - List<ClientTextStyleVO> tagList = commentInfo.getTagList(); - tagList.add(styleVO); - commentInfo.setTagList(tagList); - - commentNew.add(commentInfo); + styleVO.setContent(daysBetween + "鍚庤繃鏈�"); + tagListNew.add(styleVO); + commentInfoNew.setTagList(tagListNew); + commentNew.add(commentInfoNew); continue; } } } - commentNew.add(commentInfo); + commentNew.add(commentInfoNew); } - 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 +1590,20 @@ } } } + + listNew.add(evaluateNew); } - return list; + List<GoodsEvaluate> listOBJ = list; + // 鏇存柊鍟嗗搧淇℃伅 + executor.execute(new Runnable() { + @Override + public void run() { + updateGoodInfo(listOBJ); + } + }); + + return listNew; } @Override @@ -1739,7 +1811,9 @@ } imgInfo.setGoods(simpleGoods); - TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(1L, goodsVO.getGoodsId(), null); + TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(1L, goodsVO.getGoodsId(), "0"); + +// TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(Constant.LINK_TOKEN_VERIFY_UID, goodsVO.getGoodsId(), null); String template = configService.get(ConfigKeyEnum.quickShareTBCommentText.getKey()); String commentText = template.replace("[娣樺彛浠", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken())); @@ -1775,4 +1849,319 @@ } } + @Override + public void addGoodsEvaluateByDaTaoKe() { + List<Long> listId = null; + List<GoodsEvaluate> listExist = goodsEvaluateDao.querySingleExist(); + if (listExist != null && listExist.size() > 0) { + listId = new ArrayList<Long>(); + for (GoodsEvaluate goodsEvaluate : listExist) { + GoodsDetailVO goods = goodsEvaluate.getGoods(); + if (goods != null && goods.getGoodsType() == 1) { + listId.add(goods.getGoodsId()); + } + } + } + // 鐑攢鍗曞搧鐨勫垎绫� + List<GoodsClass> listClass = DaTaoKeUtil.goodsClasses; + int ci = (int) (Math.random() * listClass.size()); + Long subId = listClass.get(ci).getId(); + + List<DaTaoKeDetailV2> list = daTaoKeGoodsDetailV2Service.getGoodsNotInList(subId, listId, 1); + if (list == null || list.size() == 0) { + return; + } + + for (int i = 0; i < list.size(); i++) { + boolean cerateGoods = cerateGoods(list.get(i)); + if (cerateGoods) { + break; + } + } + } + + private boolean cerateGoods(DaTaoKeDetailV2 daTaoKe) { + try { + TaoBaoGoodsBrief goodsBrief = redisManager.getTaoBaoGoodsBrief(daTaoKe.getGoodsId()); + if (goodsBrief == null) { + return false; + } + + BigDecimal couponAmount = goodsBrief.getCouponAmount(); + if (couponAmount == null || couponAmount.compareTo(new BigDecimal(0)) < 1) { + return false; + } + + BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); + BigDecimal shareRate = hongBaoManageService.getShareRate(); + BigDecimal vipFanLiRate = hongBaoManageService.getVIPFanLiRate(); + ConfigParamsDTO params = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE, vipFanLiRate); + GoodsDetailVO goodsVO = GoodsDetailVOFactory.convertTaoBao(goodsBrief, params); + // 鍙戝竷鐢ㄦ埛 + ActivityUser user = activityUserService.getRandomByDaTaoKeCid(daTaoKe.getCid()); + + String desc = daTaoKe.getDesc().replace(",", "锛�"); + String[] split = desc.split("锛�"); + int max = 1; + if (Math.random() > 0.5) { + max = 2; + } + int e = 0; + String emojis = ""; + String descNew = ""; + if (split.length > 0) { + for (int i = 0; i < split.length; i++) { + if (Math.random() > 0.5 && e < max) { + for (int j = 0; j < 10; j++) { + String emojisTemp = DaTaoKeUtil.getEvaluateEmojis(); + if (!emojis.equals(emojisTemp)) { + emojis = emojisTemp; + break; + } + } + e++; + descNew += split[i] + emojis; + } else { + descNew += split[i] + "锛�"; + } + } + } else { + descNew = desc; + } + + if (descNew.endsWith("锛�")) { + descNew = descNew.substring(0, descNew.length() - 1); + } + + GoodsEvaluate goodsEvaluate = new GoodsEvaluate(); + goodsEvaluate.setId(UUID.randomUUID().toString().replace("-", "")); + goodsEvaluate.setUser(user); + goodsEvaluate.setTitle(descNew); + goodsEvaluate.setState(1); + goodsEvaluate.setDynamicType(1); + goodsEvaluate.setType(EvaluateEnum.single); + + goodsEvaluate.setShareNum((int) (Math.random() * 5000) + 1000); + goodsEvaluate.setShareNumReal(0); + goodsEvaluate.setWeight(0.0); + goodsEvaluate.setStartTime(new Date()); + goodsEvaluate.setEndTime(DateUtil.plusDayDate(3, new Date())); + goodsEvaluate.setPublishTime(new Date()); + goodsEvaluate.setCreateTime(new Date()); + goodsEvaluate.setUpdateTime(new Date()); + + List<String> goodsimgs = goodsBrief.getImgList(); + + List<String> imgs = new ArrayList<>(); + if (!StringUtil.isNullOrEmpty(goodsBrief.getPictUrlWhite())) { + imgs.add(goodsBrief.getPictUrlWhite()); + } + imgs.addAll(goodsimgs); + + int lineNum = 0; + if (imgs.size() > 0) { + if (imgs.size() == 1) { + lineNum = 1; + } else if (imgs.size() == 3) { + lineNum = 3; + } else if (imgs.size() <= 4) { + lineNum = 2; + } else { + lineNum = 3; + } + } + goodsEvaluate.setLineNum(lineNum); + + int i = 0; + List<ImgInfo> imgList = new ArrayList<>(); + for (String img : imgs) { + ImgInfo imgInfo = new ImgInfo(); + imgInfo.setH(1); + imgInfo.setW(1); + imgInfo.setLarge(false); + imgInfo.setUrl(img); + imgInfo.setUrlHD(img); + if (i != 0) { + imgInfo.setType(ImgEnum.img); + } else { + imgInfo.setType(ImgEnum.goods); + SimpleGoods simpleGoods = new SimpleGoods(); + simpleGoods.setGoodsId(goodsVO.getGoodsId()); + simpleGoods.setGoodsType(goodsVO.getGoodsType()); + simpleGoods.setState(goodsVO.getState()); + CouponInfoVO couponInfo = goodsVO.getCouponInfo(); + if (couponInfo == null) { + simpleGoods.setPrice(goodsVO.getZkPrice()); + } else { + simpleGoods.setPrice(goodsVO.getCouponPrice()); + simpleGoods.setAmount(couponInfo.getAmount()); + } + imgInfo.setGoods(simpleGoods); + imgInfo.setGoodsVO(goodsVO); + + // TaoBaoLink taoBaoLink = + // shareGoodsService.getTaoBaoLinkForShare(Constant.LINK_TOKEN_VERIFY_UID, + // goodsVO.getGoodsId(), null); + + String token = shareGoodsService.createTaoBaoToken(Constant.LINK_TOKEN_VERIFY_UID, goodsBrief); + + String template = configService.get(ConfigKeyEnum.quickShareTBCommentText.getKey()); + String commentText = template.replace("[娣樺彛浠", TaoBaoUtil.filterTaoToken(token)); + + commentText = commentText.replace("[鍘熶环]", MoneyBigDecimalUtil.getWithNoZera(goodsVO.getZkPrice())+""); + if (!goodsVO.isHasCoupon()) { + commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘"); + commentText = commentText.replace("銆愬埜鍚庝环銆慬鍒稿悗浠穄鍏�", ""); + } else { + commentText = commentText.replace("[鍒稿悗浠穄", MoneyBigDecimalUtil.getWithNoZera(goodsVO.getCouponPrice())+""); + } + 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("-", "")); + commentInfo.setContent(commentText); + commentInfo.setTypeEnum(CommentInfoEnum.goodsCoupon); + commentInfo.setType(CommentInfoEnum.goodsCoupon.getDesc()); + + String text2 = ""; + String evaluateEmojis = configService.get(ConfigKeyEnum.evaluateEmojis.getKey()); + if (!StringUtil.isNullOrEmpty(evaluateEmojis)) { + text2 = evaluateEmojis + "\n"; + } + + String evaluateText = configService.get(ConfigKeyEnum.evaluateText.getKey()); + if (!StringUtil.isNullOrEmpty(evaluateText)) { + text2 += evaluateText; + } + + String dtitle = daTaoKe.getDtitle(); + if (!StringUtil.isNullOrEmpty(dtitle)) { + text2 = text2 + dtitle +"\n"; + } else if (!StringUtil.isNullOrEmpty(evaluateText)) { + text2 += "\n"; + } + text2 += "鍏堥銆�"+ couponAmount +"鍏冧紭鎯犲埜銆戜笅鍗�"; + + CommentInfo commentInfo2 = new CommentInfo(); + commentInfo2.setId(UUID.randomUUID().toString().replace("-", "")); + commentInfo2.setContent(text2); + commentInfo2.setTypeEnum(CommentInfoEnum.goodsCoupon); + commentInfo2.setType(""); + + + List<CommentInfo> commentsNew = new ArrayList<>(); + commentsNew.add(commentInfo); + commentsNew.add(commentInfo2); + goodsEvaluate.setComments(commentsNew); + + goodsEvaluate.setGoods(goodsVO); + } + imgList.add(imgInfo); + i++; + } + goodsEvaluate.setImgList(imgList); + goodsEvaluateDao.save(goodsEvaluate); + } catch (Exception e) { + e.printStackTrace(); + LogHelper.errorDetailInfo(e); + return false; + } + return true; + } + + private String getDesc(String desc) { + System.out.println(desc); + String newDesc = ""; + int emoji = 0; + String content = desc.replace("锛�", ","); + while (content.length() > 0) { + int length = 0; + boolean end = true; + for (int i = 0; i < content.length(); i++) { + if (content.substring(0, i).length() >= 18) { + length = i; + end = false; + break; + } + } + + if (end) { + length = content.length(); + } + + String introduce = content.substring(0, length); + System.out.println(introduce); + if (verify(introduce)) { + if (emoji >= 4) { + introduce = introduce.replace(",", "\n"); // 闇�瑕佹崲琛� + } else { + emoji++; + introduce = introduce.replace(",", DaTaoKeUtil.getRandomCommonEmoji() + "\n"); // 闇�瑕佹崲琛� + } + } + + // 闅忔満鏇挎崲emoji + if (emoji <= 4 && Math.random() > 0.5) { + introduce = introduce.replace(",", DaTaoKeUtil.getRandomCommonEmoji()); + emoji++; + } + newDesc += introduce; + content = content.substring(length); + } + return newDesc; + } + + private boolean verify(String content) { + // 18涓瓧绗﹀唴锛堝寘鍚爣鐐逛篃绠椾竴涓瓧绗︼級鏈夊涓�楀彿锛屽垯涓嶆崲琛� + char d = ','; + int count = 0; + char chs[] = content.toCharArray();// 杞崲鎴恈har鏁扮粍 + for (int i = 0; i < chs.length; i++) { + if (d == chs[i]) { + count++; + } + } + if (count > 1) { + return false; + } + + // 涔﹀悕鍙凤紝澶ф嫭鍙凤紝灏忔嫭鍙烽噷闈㈢殑鍐呭涓嶆崲琛� + if (content.contains("[") && content.contains("]")) { + return false; + } else if (content.contains("銆�") && content.contains("銆�")) { + return false; + } else if (content.contains("{") && content.contains("}")) { + return false; + } else if (content.contains("(") && content.contains(")")) { + return false; + } + + int index = content.lastIndexOf(","); + // (闄ゅ紑閫楀彿浠ュ鐨勭鍙凤級鎰熷徆鍙�/鍙ュ彿/闂彿鍓嶉潰鏈夐�楀彿锛屼笉鎹㈣ + if (content.contains("!") && index < content.lastIndexOf("!")) { + return false; + } + + if (content.contains("锛�") && index < content.lastIndexOf("锛�")) { + return false; + } + + if (content.contains("銆�") && index < content.lastIndexOf("銆�")) { + return false; + } + + if (content.contains("?") && index < content.lastIndexOf("?")) { + return false; + } + + if (content.contains("锛�") && index < content.lastIndexOf("锛�")) { + return false; + } + + if (content.contains("锛�")) { + return false; + } + return true; + } } -- Gitblit v1.8.0