From f4a0f2acc63d7785eab108419a4e16f5f688cb95 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期六, 18 一月 2020 12:06:27 +0800 Subject: [PATCH] 用户注册信息 --- fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/DynamicInfoServiceImpl.java | 206 ++++++++++++++++++++++++++++++++++---------------- 1 files changed, 139 insertions(+), 67 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/DynamicInfoServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/DynamicInfoServiceImpl.java index c876f43..6308999 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/DynamicInfoServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/DynamicInfoServiceImpl.java @@ -1,10 +1,14 @@ package com.yeshi.fanli.service.impl.dynamic; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; import javax.annotation.Resource; @@ -15,9 +19,11 @@ import org.springframework.stereotype.Service; import org.yeshi.utils.DateLunarUtil; import org.yeshi.utils.DateUtil; +import org.yeshi.utils.HttpUtil; import org.yeshi.utils.taobao.TbImgUtil; import com.yeshi.fanli.dao.dynamic.DynamicInfoDao; +import com.yeshi.fanli.dto.ConfigParamsDTO; import com.yeshi.fanli.dto.taobao.TaoBaoShopDTO; import com.yeshi.fanli.entity.bus.activity.ActivityRuleUser; import com.yeshi.fanli.entity.bus.activity.ActivityUser; @@ -32,7 +38,7 @@ import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra; import com.yeshi.fanli.entity.taobao.TaoBaoShop; -import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail; +import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2; import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.activity.ActivityUserService; @@ -40,10 +46,10 @@ import com.yeshi.fanli.service.inter.dynamic.DynamicInfoService; import com.yeshi.fanli.service.inter.dynamic.InviteMaterialService; import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; -import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService; +import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService; import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService; -import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsService; +import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailV2Service; import com.yeshi.fanli.service.inter.user.QrCodeService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.MoneyBigDecimalUtil; @@ -72,7 +78,7 @@ private RedisManager redisManager; @Resource - private DaTaoKeGoodsService daTaoKeGoodsService; + private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service; @Resource private JumpDetailV2Service jumpDetailV2Service; @@ -145,7 +151,7 @@ buffer.append(" "); buffer.append("鏃╁畨锝瀄n"); buffer.append("鎴戠殑閭�璇风爜锛氥�愰個璇风爜銆慭n"); - buffer.append("璐墿鐪侀挶杩斿埄鍒窤pp锛氥�愰個璇烽摼鎺ャ��"); + buffer.append("璐墿鐪侀挶鏉挎牀蹇渷App锛氥�愰個璇烽摼鎺ャ��"); content = content.replaceAll("\\,", "\\锛�").replaceAll("\\.", "\\銆�").replaceAll("\\;", "\\锛�") .replaceAll("\\!", "\\锛�").replaceAll("\\?", "\\锛�").replaceAll("\\:", "\\锛�"); @@ -269,6 +275,9 @@ if (StringUtil.isNullOrEmpty(shopLink)) { taoBaoShop.setShopLink(TaoBaoUtil.getShopLink(taoBaoShop.getId())); } + + if(StringUtil.isNullOrEmpty(taoBaoShop.getShopIcon())) + taoBaoShop.setShopIcon(dynamicShopInfo.getShopIcon()); DynamicInfo dynamicVO = new DynamicInfo(); dynamicVO.setId(brandId); @@ -338,9 +347,9 @@ count = 4; } - List<DaTaoKeDetail> listDaTaoKe = daTaoKeGoodsService.getGoodsNotInList(subclassId, null, count); + List<DaTaoKeDetailV2> listDaTaoKe = daTaoKeGoodsDetailV2Service.getGoodsNotInList(subclassId, null, count); - DaTaoKeDetail daTaoKeDetail = null; + DaTaoKeDetailV2 daTaoKeDetail = null; // 鍟嗗搧鍒楄〃 List<GoodsPicture> listPicture = new ArrayList<GoodsPicture>(); // 鍟嗗搧鍒楄〃 @@ -349,7 +358,7 @@ BigDecimal shareMoney = new BigDecimal(0); BigDecimal proportion = hongBaoManageService.getFanLiRate(); - for (DaTaoKeDetail daTaoKe : listDaTaoKe) { + for (DaTaoKeDetailV2 daTaoKe : listDaTaoKe) { if (daTaoKeDetail == null) { daTaoKeDetail = daTaoKe; } @@ -414,7 +423,12 @@ public void insertTimeHotSale() { Long classId = 1L; try { - saveHotSale(classId, 0L); + for (int i = 0; i < 3; i++) { + boolean addSuccess = saveHotSale(classId, 0L); + if (addSuccess) { + break; + } + } } catch (Exception e) { try { LogHelper.errorDetailInfo(e); @@ -427,7 +441,12 @@ List<GoodsClass> list = DaTaoKeUtil.goodsClasses; for (GoodsClass goodsClass : list) { try { - saveHotSale(classId, goodsClass.getId()); + for (int i = 0; i < 3; i++) { + boolean addSuccess = saveHotSale(classId, goodsClass.getId()); + if (addSuccess) { + break; + } + } } catch (Exception e) { try { LogHelper.errorDetailInfo(e); @@ -445,7 +464,8 @@ * @param subclassId * @throws TaobaoGoodsDownException */ - public void saveHotSale(Long classId, Long subclassId) throws TaobaoGoodsDownException { + public boolean saveHotSale(Long classId, Long subclassId) throws TaobaoGoodsDownException { + boolean addSuccess = false; List<Long> listId = null; List<DynamicInfo> listInfo = dynamicInfoDao.query(classId, subclassId); if (listInfo != null && listInfo.size() > 0) { @@ -458,55 +478,44 @@ } } // 澶ф窐瀹㈡暟鎹� - DaTaoKeDetail daTaoKe = daTaoKeGoodsService.getGoodsNotInList(subclassId, listId, 1).get(0); + DaTaoKeDetailV2 daTaoKe = daTaoKeGoodsDetailV2Service.getGoodsNotInList(subclassId, listId, 1).get(0); + if (daTaoKe == null) { + return addSuccess; + } try { daTaoKe = DaTaoKeUtil.filterDaTaoKe(TaoKeApiUtil.searchGoodsDetail(daTaoKe.getGoodsId()), daTaoKe); } catch (Exception e) { } - - // 杩囨护涓虹┖鐨� - if (daTaoKe == null) { - return; + + TaoBaoGoodsBrief taoBaoGoodsBrief = TaoBaoUtil.convert(daTaoKe); + BigDecimal proportion = hongBaoManageService.getFanLiRate(); + TaoBaoGoodsBriefExtra goodsExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), + null); + + if (!goodsExtra.isCoupon() || (goodsExtra.getState() != null && goodsExtra.getState() == 1)) { + return addSuccess; // 宸蹭笅鏋� 銆佹棤鍒� 涓嶅姞鍏� } List<TaoBaoGoodsBrief> listGoods = new ArrayList<TaoBaoGoodsBrief>(); - TaoBaoGoodsBrief taoBaoGoodsBrief = TaoBaoUtil.convert(daTaoKe); listGoods.add(taoBaoGoodsBrief); - BigDecimal proportion = hongBaoManageService.getFanLiRate(); - TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, - proportion.toString(), null); - - // 鍟嗗搧鍥剧墖 + goodsExtra.setTkRate(taoBaoGoodsBrief.getTkRate()); + goodsExtra.setUpdatetime(new Date()); + goodsExtra.setCouponInfo(null); + GoodsPicture goodsPicture = getGoodsPicture(daTaoKe); - if (!taoBaoGoodsBriefExtra.isCoupon()) { - taoBaoGoodsBriefExtra.setState(1); - goodsPicture.setGoodState(1); - } - taoBaoGoodsBriefExtra.setTkRate(taoBaoGoodsBrief.getTkRate()); - taoBaoGoodsBriefExtra.setUpdatetime(new Date()); - taoBaoGoodsBriefExtra.setCouponInfo(null); - goodsPicture.setGoods(taoBaoGoodsBriefExtra); - + goodsPicture.setGoods(goodsExtra); // 鍟嗗搧鍒楄〃 List<GoodsPicture> listPicture = new ArrayList<GoodsPicture>(); listPicture.add(goodsPicture); - - // 鍒嗕韩濂栭噾 - BigDecimal shareMoney = taoBaoGoodsBriefService.getShareGoodsUserHongBao(taoBaoGoodsBrief); - ClientTextStyleVO shareMoneyDesc = new ClientTextStyleVO(); - shareMoneyDesc.setColor("#FFFFFF"); - shareMoneyDesc.setBottomColor("#E8AE48"); - shareMoneyDesc.setContent("棰勪及鍒嗕韩濂栭噾锛毬�" + shareMoney); - // 鑾峰彇鍟嗗搧鍒楄〃鍥剧墖 TaoBaoGoodsBrief taoBaoGoodsBrief2 = TaoKeApiUtil.getSimpleGoodsInfo(daTaoKe.getGoodsId()); List<String> imgList = taoBaoGoodsBrief2.getImgList(); List<String> listimgs = new ArrayList<String>(); - String pic = daTaoKe.getPic(); + String pic = daTaoKe.getMainPic(); listimgs.add(TbImgUtil.getTBSize320Img(pic)); if (imgList != null && imgList.size() > 0) { for (String img : imgList) { @@ -526,8 +535,14 @@ listPicture.add(picture); } } + goodsExtra.setImgList(imgList); - taoBaoGoodsBriefExtra.setImgList(imgList); + // 鍒嗕韩濂栭噾 + BigDecimal shareMoney = taoBaoGoodsBriefService.getShareGoodsUserHongBao(taoBaoGoodsBrief); + ClientTextStyleVO shareMoneyDesc = new ClientTextStyleVO(); + shareMoneyDesc.setColor("#FFFFFF"); + shareMoneyDesc.setBottomColor("#E8AE48"); + shareMoneyDesc.setContent("棰勪及鍒嗕韩濂栭噾锛毬�" + shareMoney); // 缁勭粐鍔ㄦ�佷俊鎭� DynamicInfo dynamicInfo = getDynamicInfo(daTaoKe, classId, subclassId); @@ -550,6 +565,9 @@ // 淇濆瓨淇℃伅 dynamicInfoDao.insert(dynamicInfo); + + addSuccess = true; + return addSuccess; } /** @@ -560,7 +578,7 @@ * @param subclassId * @throws TaobaoGoodsDownException */ - public DynamicInfo getDynamicInfo(DaTaoKeDetail daTaoKe, Long classId, Long subclassId) { + public DynamicInfo getDynamicInfo(DaTaoKeDetailV2 daTaoKe, Long classId, Long subclassId) { DynamicInfo dynamicInfo = new DynamicInfo(); dynamicInfo.setId(UUID.randomUUID().toString().replace("-", "")); dynamicInfo.setClassId(classId); @@ -595,11 +613,11 @@ * @param daTaoKe * @return */ - public GoodsPicture getGoodsPicture(DaTaoKeDetail daTaoKe) { + public GoodsPicture getGoodsPicture(DaTaoKeDetailV2 daTaoKe) { GoodsPicture goodsPicture = new GoodsPicture(); goodsPicture.setH(100); goodsPicture.setW(100); - goodsPicture.setUrl(TbImgUtil.getTBSize320Img(daTaoKe.getPic())); + goodsPicture.setUrl(TbImgUtil.getTBSize320Img(daTaoKe.getMainPic())); goodsPicture.setJumpDetail(jumpDetailV2Service.getByTypeCache("goodsdetail")); String goodsId = daTaoKe.getGoodsId().toString(); @@ -699,8 +717,14 @@ size = inviteInfo.getSize(); } + InputStream asInputStream = HttpUtil.getAsInputStream(picUrl); + + int index = picUrl.lastIndexOf("/"); + String newUrl = picUrl.substring(index + 1); + String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf(".")); + // 鍥剧墖 - String imgLink = qrCodeService.drawInviteQrCodeNew(picUrl, null, null, pX, pY, size, null); + String imgLink = qrCodeService.drawInviteQrCodeNew(asInputStream, urlMd5, null, null, pX, pY, size, null); GoodsPicture p2 = new GoodsPicture(); p2.setW(100); p2.setH(100); @@ -906,17 +930,54 @@ return list; } - - + + private Map<Long, TaoBaoGoodsBrief> getFilterGoodsMap(List<DynamicInfo> list) { + // 鎻愬彇杩囨护鍟嗗搧 + List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); + for (DynamicInfo dynamicInfo : list) { + List<GoodsPicture> gpList = dynamicInfo.getImgs(); + if (gpList != null) + for (GoodsPicture gp : gpList) { + if (gp != null && gp.getGoods() != null) { + TaoBaoGoodsBriefExtra newGoods = new TaoBaoGoodsBriefExtra(); + try { + PropertyUtils.copyProperties(newGoods, gp.getGoods()); + goodsList.add(newGoods); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + + } + } + } + goodsList = taoBaoGoodsUpdateService.filterImportantTaoBaoGoods(goodsList); + Map<Long, TaoBaoGoodsBrief> map = new HashMap<>(); + if (goodsList != null) + for (TaoBaoGoodsBrief goods : goodsList) + map.put(goods.getAuctionId(), goods); + return map; + } + @Override @Cacheable(value = "dynamicCache", key = "'queryV2-'+#platform+'-'+#version+'-'+#start+'-'+#count+'-'+#cid+'-'+#subId") public List<DynamicInfo> queryV2(int platform, int version, int start, int count, Long cid, Long subId) { List<DynamicInfo> listNew = new ArrayList<DynamicInfo>(); List<DynamicInfo> list = dynamicInfoDao.query(start, count, cid, subId); + // 闇�瑕佹洿鏂扮殑鍟嗗搧 + List<TaoBaoGoodsBrief> taoBaoGoodsUpdateList = new ArrayList<>(); if (list != null && list.size() > 0) { + // 鎻愬彇鍟嗗搧 + Map<Long, TaoBaoGoodsBrief> goodsMap = getFilterGoodsMap(list); + BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); BigDecimal shareRate = hongBaoManageService.getShareRate(); - for (DynamicInfo dynamicInfo: list) { + ConfigParamsDTO paramsDTO = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE,hongBaoManageService.getVIPFanLiRate()); + + for (DynamicInfo dynamicInfo : list) { DynamicInfo dynamicNew = new DynamicInfo(); try { PropertyUtils.copyProperties(dynamicNew, dynamicInfo); @@ -924,7 +985,7 @@ e.printStackTrace(); continue; } - + // 搴楅摵淇℃伅 TaoBaoShop shop = dynamicNew.getShop(); if (shop != null) { @@ -943,17 +1004,19 @@ } dynamicNew.setShop(shopNew); } - + List<GoodsPicture> imgsNew = new ArrayList<GoodsPicture>(); List<GoodsPicture> imgs = dynamicNew.getImgs(); if (imgs != null && imgs.size() > 0) { - for (GoodsPicture goodsPicture: imgs) { + for (GoodsPicture goodsPicture : imgs) { TaoBaoGoodsBriefExtra goods = goodsPicture.getGoods(); if (goods == null) { imgsNew.add(goodsPicture); continue; } - + + taoBaoGoodsUpdateList.add(goods); + GoodsPicture goodsNew = new GoodsPicture(); try { PropertyUtils.copyProperties(goodsNew, goodsPicture); @@ -961,19 +1024,27 @@ e.printStackTrace(); continue; } - - GoodsDetailVO detailVO = GoodsDetailVOFactory.convertTaoBaoGoodsBriefExtra(goods, fanLiRate, shareRate); + + // 杩囨护鍒镐俊鎭笌璧勯噾淇℃伅 + goods.setCouponAmount(goodsMap.get(goods.getAuctionId()).getCouponAmount()); + goods.setZkPrice(goodsMap.get(goods.getAuctionId()).getZkPrice()); + goods.setCouponStartFee(goodsMap.get(goods.getAuctionId()).getCouponStartFee()); + goods.setTkRate(goodsMap.get(goods.getAuctionId()).getTkRate()); + + GoodsDetailVO detailVO = GoodsDetailVOFactory.convertTaoBaoGoodsBriefExtra(goods, paramsDTO); + goodsNew.setGoodsVO(detailVO); goodsNew.setGoods(null); - + JumpDetailV2 jumpDetail = goodsNew.getJumpDetail(); if (jumpDetail != null) { - JumpDetailV2 jumpDetailV2 = jumpDetailV2Service.getByTypeCache(jumpDetail.getType(), platform, version); + JumpDetailV2 jumpDetailV2 = jumpDetailV2Service.getByTypeCache(jumpDetail.getType(), + platform, version); if (jumpDetailV2 != null) { goodsNew.setJumpDetail(jumpDetailV2); } } - + imgsNew.add(goodsNew); } dynamicNew.setImgs(imgsNew); @@ -981,7 +1052,7 @@ listNew.add(dynamicNew); } } - + // 鏇存柊鍟嗗搧淇℃伅 executor.execute(new Runnable() { @Override @@ -989,9 +1060,10 @@ updateGoodInfo(list); } }); + + taoBaoGoodsUpdateService.addUpdateQueueAsync(taoBaoGoodsUpdateList); return listNew; } - /** * 鏇存柊鍟嗗搧淇℃伅 @@ -1004,7 +1076,7 @@ if (list == null || list.size() == 0) { return; } - + try { BigDecimal proportion = hongBaoManageService.getFanLiRate(); for (DynamicInfo dynamicInfo : list) { @@ -1045,10 +1117,10 @@ continue; } - Integer state = oldExtra.getState(); - if (state != null && state == 1) { - continue; - } + /* + * Integer state = oldExtra.getState(); if (state != null && state == 1) { + * continue; } + */ TaoBaoGoodsBrief goodsBrief = null; try { @@ -1101,16 +1173,16 @@ dynamicInfo.setDesc(shareMoneyDesc); } } - + // 闇�瑕佹洿鏂颁俊鎭紱 needUpdate = true; } - + // 鏃犳晥鏇存柊淇℃伅 if (!needUpdate) { continue; } - + // 鏇存柊鍟嗗搧淇℃伅 dynamicInfo.setImgs(listPicture); -- Gitblit v1.8.0