From 7c03a2c38c499e526f5c4258c35413160d784d04 Mon Sep 17 00:00:00 2001 From: admin <2780501319@qq.com> Date: 星期一, 09 三月 2020 16:47:07 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div --- fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 153 insertions(+), 17 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 9094646..4dc4498 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 @@ -31,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; @@ -1854,7 +1855,27 @@ @Override public void addGoodsEvaluateByDaTaoKe() { try { - List<DaTaoKeDetailV2> list = daTaoKeGoodsDetailV2Service.getGoodsNotInList(1L, null, 1); + boolean addSuccess = false; + 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; } @@ -1873,19 +1894,40 @@ // 鍙戝竷鐢ㄦ埛 ActivityUser user = activityUserService.getRandomByDaTaoKeCid(daTaoKe.getCid()); - String desc = DaTaoKeUtil.getDesc(daTaoKe); - if (!StringUtil.isNullOrEmpty(desc)) { - int index = desc.lastIndexOf("\n"); - String newDesc = desc.substring(index + 1); - if (StringUtil.isNullOrEmpty(newDesc)) { - desc = desc.substring(0, index); - } +// String desc = getDesc(daTaoKe.getDesc()); + String desc = daTaoKe.getDesc().replace(",", "锛�"); + System.out.println(desc); + String[] split = desc.split("锛�"); + System.out.println(split.length); + + int max = 1; + if (Math.random() > 0.5) { + max = 2; } + int e = 0; + String descNew = ""; + if (split.length > 0) { + for (int i = 0; i < split.length; i ++ ) { + if (Math.random() > 0.5 && e < max) { + e++; + descNew += split[i] + DaTaoKeUtil.getRandomCommonEmoji(); + } 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(desc); + goodsEvaluate.setTitle(descNew); goodsEvaluate.setState(1); goodsEvaluate.setDynamicType(1); goodsEvaluate.setType(EvaluateEnum.single); @@ -1899,16 +1941,14 @@ goodsEvaluate.setCreateTime(new Date()); goodsEvaluate.setUpdateTime(new Date()); - - List<ImgInfo> imgList = new ArrayList<>(); - int lineNum = 0; - if (imgList.size() > 0) { - if (imgList.size() == 1) { + List<String> imgs = goodsBrief.getImgList(); + if (imgs.size() > 0) { + if (imgs.size() == 1) { lineNum = 1; - } else if (imgList.size() == 3) { + } else if (imgs.size() == 3) { lineNum = 3; - } else if (imgList.size() <= 4) { + } else if (imgs.size() <= 4) { lineNum = 2; } else { lineNum = 3; @@ -1917,7 +1957,7 @@ goodsEvaluate.setLineNum(lineNum); int i = 0; - List<String> imgs = goodsBrief.getImgList(); + List<ImgInfo> imgList = new ArrayList<>(); for (String img : imgs) { ImgInfo imgInfo = new ImgInfo(); imgInfo.setH(1); @@ -1982,4 +2022,100 @@ LogHelper.errorDetailInfo(e); } } + + + 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