From 651a15c78f668bef3859d9ed1bb7ad0b669d3600 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 03 七月 2020 17:52:07 +0800 Subject: [PATCH] 多APP优化 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java | 191 +++++++++++++++++++++++++++++++++++------------ 1 files changed, 140 insertions(+), 51 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java index 5b4fd29..3d64611 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudServiceImpl.java @@ -8,6 +8,9 @@ import javax.annotation.Resource; +import com.yeshi.fanli.entity.SystemEnum; +import com.yeshi.fanli.exception.taobao.TaoBaoConvertLinkException; +import com.yeshi.fanli.service.manger.goods.TaoBaoLinkManager; import org.springframework.core.task.TaskExecutor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -73,6 +76,7 @@ import com.yeshi.fanli.service.inter.user.cloud.UserCloudService; import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService; import com.yeshi.fanli.service.manger.goods.ConvertLinkManager; +import com.yeshi.fanli.service.manger.msg.RocketMQManager; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.ImageToBase64; import com.yeshi.fanli.util.MoneyBigDecimalUtil; @@ -134,23 +138,13 @@ @Resource private PinDuoDuoCacheUtil pinDuoDuoCacheUtil; - @Resource - private QrCodeService qrCodeService; + @Resource private RedisManager redisManager; @Resource - private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService; - - @Resource - private HongBaoManageService hongBaoManageService; - - @Resource private ShareGoodsTextTemplateService shareGoodsTextTemplateService; - - @Resource - private CommonGoodsService commonGoodsService; @Resource private UserCloudSendRecordService userCloudSendRecordService; @@ -161,8 +155,8 @@ @Resource private UserCloudManageService userCloudManageService; - @Resource(name = "producer") - private Producer producer; + @Resource + private RocketMQManager rocketMQManager; @Resource private UserOtherMsgNotificationService userOtherMsgNotificationService; @@ -170,11 +164,11 @@ @Resource private PushService pushService; - @Resource - private UserSystemMsgService userSystemMsgService; - @Resource(name = "taskExecutor") private TaskExecutor executor; + + @Resource + private TaoBaoLinkManager taoBaoLinkManager; @Override public UserCloud getValidByUid(Long uid) { @@ -407,6 +401,7 @@ } private void sendCircleByDynamic(Long uid, String id, int way) throws UserCloudException { + long time1= java.lang.System.currentTimeMillis(); UserInfo user = userInfoService.getUserByIdWithMybatis(uid); if (user == null) throw new UserCloudException(1, "鐢ㄦ埛淇℃伅涓嶅瓨鍦�"); @@ -427,7 +422,11 @@ if (StringUtil.isNullOrEmpty(relationId)) throw new UserCloudException(2, "娣樺疂鏈巿鏉冿紝璇峰墠寰�\"鎴戠殑\"缁戝畾娣樺疂璐﹀彿"); + + long time2= java.lang.System.currentTimeMillis(); + LogHelper.test("sendCircleByDynamic淇濋獙璇佺敤鎴风姸鎬侊細" + (time2 - time1)); + // 楠岃瘉鏄惁寮�閫� UserCloud userCloud = userCloudMapper.getValidByUid(uid); if (userCloud == null) @@ -441,6 +440,10 @@ if (StringUtil.isNullOrEmpty(wxId)) throw new UserCloudException(1003, "寰俊鍙蜂笉瀛樺湪锛岃鍏堝井淇$櫥褰�"); + long time3= java.lang.System.currentTimeMillis(); + LogHelper.test("sendCircleByDynamic楠岃瘉鏄惁婊¤冻寮�閫氾細" + (time3 - time2)); + + // 楠岃瘉寮�鍚姸鎬� List<UserCloudGroup> listGroup = userCloudGroupService.listByUid(uid); if (listGroup == null || listGroup.size() == 0) @@ -455,6 +458,9 @@ if (listOpen.size() == 0) throw new UserCloudException(1005, "璇峰厛寮�鍚簯鍙戝崟缇ゅ姛鑳�"); + long time4= java.lang.System.currentTimeMillis(); + LogHelper.test("sendCircleByDynamic楠岃瘉鏄惁寮�鍚細" + (time4 - time3)); + // 楠岃瘉鍙戝湀鏄惁鍙 GoodsEvaluate evaluate = goodsEvaluateService.getById(id); if (evaluate == null || evaluate.getState() == 0) @@ -468,6 +474,9 @@ if (comments == null || comments.size() == 0) throw new UserCloudException(1, "璇ュ唴瀹逛笉鑳借浆閾�"); + long time5= java.lang.System.currentTimeMillis(); + LogHelper.test("sendCircleByDynamic楠岃瘉鍙戝湀鍐呭鏄惁婊¤冻锛�" + (time5 - time4)); + // 妫�娴嬪井淇℃槸鍚︾櫥褰曠姸鎬� if (!AitaokerApiUtil.onlineCheck(robotId)) { // 閫氱煡鐧诲綍寰俊 @@ -476,6 +485,9 @@ throw new UserCloudException(1003, "寰俊宸叉帀绾匡紝闇�瑕侀噸鏂版壂鎻忎簩缁寸爜鐧诲綍"); } + long time6= java.lang.System.currentTimeMillis(); + LogHelper.test("sendCircleByDynamic楠岃瘉鍙戞槸鍚︾櫥褰曪細" + (time6 - time5)); + boolean hasToken = false; List<String> listComment = new ArrayList<>(); for (CommentInfo commentInfo : comments) { @@ -513,7 +525,18 @@ if (!hasToken) throw new UserCloudException(1, "璇ュ唴瀹瑰寘鍚彲杞摼鍙d护鎴栭摼鎺�"); + + // 寮傛鎵ц鍙戦�� + executor.execute(new Runnable() { + @Override + public void run() { + sendEvaluate(uid, evaluate, way, userCloud, listOpen, listComment); + } + }); + } + private void sendEvaluate(Long uid, GoodsEvaluate evaluate, int way, UserCloud userCloud, + List<UserCloudGroup> listOpen, List<String> listComment) { ImgInfo imgVideo = null; List<String> listImg = new ArrayList<>(); @@ -528,10 +551,14 @@ } } + + + String wxId = userCloud.getWxId(); + Integer robotId = userCloud.getRobotId(); // 淇濆瓨鍙戦�佽褰� UserCloudSendRecord sendRecord = new UserCloudSendRecord(); sendRecord.setUid(uid); - sendRecord.setSendId(id); + sendRecord.setSendId(evaluate.getId()); sendRecord.setSendWay(way); sendRecord.setWxId(wxId); sendRecord.setRobotId(robotId); @@ -540,6 +567,7 @@ UserCloudSendRecord result = userCloudSendRecordService.save(sendRecord); String pid = result.getId(); + for (UserCloudGroup cloudGroup : listOpen) { String title = evaluate.getTitle(); @@ -597,10 +625,10 @@ if (macsend) sendContent.setTitle(title); } - + SystemEnum system=userInfoService.getUserSystem(uid); // 鍙戦�佸浘鐗� int num = 1; - String picNum = configService.get(ConfigKeyEnum.robotCloudGroupPictureNum.getKey()); + String picNum = configService.getValue(ConfigKeyEnum.robotCloudGroupPictureNum.getKey(),system); if (!StringUtil.isNullOrEmpty(picNum)) { num = Integer.parseInt(picNum); } @@ -632,7 +660,9 @@ userCloudSendContentService.save(sendContent); } } - + + + @Override @Transactional(rollbackFor = Exception.class) public void sendCustomGoods(Long uid, Long goodsId, Integer goodsType, Long sellerId) throws UserCloudException { @@ -672,6 +702,8 @@ private void sendCircleByGoods(Long uid, Long goodsId, Integer goodsType, Long storeId, Long sellerId, int way) throws UserCloudException { + long begainTime = java.lang.System.currentTimeMillis(); + // 楠岃瘉鏄惁鎺堟潈 UserInfo user = userInfoService.getUserByIdWithMybatis(uid); if (user == null) @@ -694,11 +726,19 @@ if (StringUtil.isNullOrEmpty(relationId)) throw new UserCloudException(2, "娣樺疂鏈巿鏉冿紝璇峰墠寰�\"鎴戠殑\"缁戝畾娣樺疂璐﹀彿"); + long time2 = java.lang.System.currentTimeMillis(); + LogHelper.test("sendCircleByGoods楠岃瘉鐢ㄦ埛鑰楁椂锛�" + (time2 - begainTime)); + + // 楠岃瘉鏄惁寮�閫� UserCloud userCloud = userCloudMapper.getValidByUid(uid); if (userCloud == null) throw new UserCloudException(1001, "浜戝彂鍗曞凡杩囨湡"); - + + long time3= java.lang.System.currentTimeMillis(); + LogHelper.test("sendCircleByGoods楠岃瘉鏄惁寮�閫氾細" + (time3 - time2)); + + long time4 = time3; // 鍔犲叆鎴戠殑澶囬�夊簱 if (storeId == null) { try { @@ -710,6 +750,8 @@ + "]鍘熷洜锛�" + e.getMsg()); throw new UserCloudException(1, "鍔犲叆浜戝彂鍗曞閫夊簱澶辫触"); } + time4= java.lang.System.currentTimeMillis(); + LogHelper.test("sendCircleByGoods鍔犲叆澶囬�夊簱锛�" + (time4 - time3)); } // 鑷�夊簱鍟嗗搧鏄惁鎵撳紑 @@ -736,6 +778,9 @@ if (listGroup == null || listGroup.size() == 0) throw new UserCloudException(1003, "璇峰厛鐧诲綍寰俊"); + long time5= java.lang.System.currentTimeMillis(); + LogHelper.test("sendCircleByGoods楠岃瘉鏄惁缁戝畾寰俊锛�" + (time5 - time4)); + List<UserCloudGroup> listOpen = new ArrayList<>(); for (UserCloudGroup cloudGrou : listGroup) { if (cloudGrou.getState()) { @@ -754,6 +799,9 @@ throw new UserCloudException(1003, "寰俊宸叉帀绾匡紝闇�瑕侀噸鏂版壂鎻忎簩缁寸爜鐧诲綍"); } + long time6= java.lang.System.currentTimeMillis(); + LogHelper.test("sendCircleByGoods楠岃瘉鏄惁鐧诲綍寰俊锛�" + (time6 - time5)); + // 淇濆瓨鍙戦�佽褰� UserCloudSendRecord sendRecord = new UserCloudSendRecord(); sendRecord.setUid(uid); @@ -770,6 +818,9 @@ sendRecord.setSendWay(UserCloudSendRecord.SEND_WAY_MANUAL); } UserCloudSendRecord result = userCloudSendRecordService.save(sendRecord); + + long time7= java.lang.System.currentTimeMillis(); + LogHelper.test("sendCircleByGoods淇濆瓨鍙戦�佽褰曪細" + (time7 - time6)); try { if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { @@ -792,7 +843,8 @@ record.setUpdateTime(new Date()); userCloudGoodsService.updateByPrimaryKeySelective(record); } - + long time8= java.lang.System.currentTimeMillis(); + LogHelper.test("sendCircleByGoods鎵ц鍙戦�侊細" + (time8 - time7)); } catch (UserCloudException e) { LogHelper.cloudInfo("autoSendCustomGoods - [uid:" + uid + " 搴搃d:" + storeId + "]鍘熷洜锛�" + e.getMsg()); // 鏇存柊鍙戝崟璁板綍 @@ -812,7 +864,6 @@ * 娣樺疂鍟嗗搧淇℃伅澶勭悊 * * @param user - * @param inviteCode * @param robotId * @param wxId * @param goodsId @@ -824,8 +875,8 @@ List<UserCloudGroup> listOpen, String pid) throws UserCloudException { TaoBaoLink taoBaoLink = null; try { - taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(user.getId(), goodsId, relationId); - } catch (ShareGoodsException e) { + taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(user.getId(), goodsId, relationId,null); + } catch (TaoBaoConvertLinkException e) { LogHelper.errorDetailInfo(e); throw new UserCloudException(1, "璇ュ晢鍝佸凡涓嬫灦"); } @@ -848,15 +899,22 @@ } String sales = TaoBaoUtil.getSaleCount(goods.getBiz30day()); + SystemEnum system=userInfoService.getUserSystem(user.getId()); + // 鑾峰彇鎺ㄨ崘璇� String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, goods.getTitle(), sales, - couponAmount, description); + couponAmount, description,system); // 鑾峰彇璇勮璇� String commentText = shareGoodsTextTemplateService.getCommentTextByTaoToken(coupon, taoBaoLink.getTaoToken(), - goods.getZkPrice().toString(), quanPrice); + goods.getZkPrice().toString(), quanPrice,system); - // 浜戝彂鍗� - sendGoods(robotId, wxId, listOpen, recommendText, commentText, goods.getImgList(), user.getId(), pid); + // 寮傛鎵ц鍙戦�� + executor.execute(new Runnable() { + @Override + public void run() { + sendGoods(robotId, wxId, listOpen, recommendText, commentText, goods.getImgList(), user.getId(), pid); + } + }); } /** @@ -899,9 +957,11 @@ String sales = JDUtil.getSaleCount(jdGoods.getInOrderCount30Days()); + SystemEnum system=userInfoService.getUserSystem(user.getId()); + // 鑾峰彇鎺ㄨ崘璇� String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, jdGoods.getSkuName(), sales, - couponAmount, null); + couponAmount, null,system); // 鑾峰彇璇勮璇� BigDecimal price = jdGoods.getPrice(); @@ -911,10 +971,16 @@ } String zkPrice = BigDecimalUtil.getWithNoZera(price).toString(); String commentText = shareGoodsTextTemplateService.getCommentTextByLink(coupon, jumpLink, zkPrice, quanPrice, - ConfigKeyEnum.quickShareJDCommentText); + ConfigKeyEnum.quickShareJDCommentText,system); - // 浜戝彂鍗� - sendGoods(robotId, wxId, listOpen, recommendText, commentText, jdGoods.getImageList(), user.getId(), pid); + // 寮傛鎵ц鍙戦�� + executor.execute(new Runnable() { + @Override + public void run() { + sendGoods(robotId, wxId, listOpen, recommendText, commentText, jdGoods.getImageList(), user.getId(), pid); + } + }); + } /** @@ -955,23 +1021,33 @@ sales = "0"; } + SystemEnum system=userInfoService.getUserSystem(user.getId()); + // 鑾峰彇鎺ㄨ崘璇� String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, goods.getGoodsName(), sales, - couponAmount, null); + couponAmount, null,system); // 鑾峰彇璇勮璇� String zkPrice = MoneyBigDecimalUtil.div(new BigDecimal(goods.getMinGroupPrice()), new BigDecimal(100)) .setScale(2).toString(); String commentText = shareGoodsTextTemplateService.getCommentTextByLink(coupon, jumpLink, zkPrice, quanPrice, - ConfigKeyEnum.quickSharePDDCommentText); + ConfigKeyEnum.quickSharePDDCommentText,system); List<String> list = null; String[] goodsGalleryUrls = goods.getGoodsGalleryUrls(); if (goodsGalleryUrls != null && goodsGalleryUrls.length > 0) { list = Arrays.asList(goodsGalleryUrls); } - // 浜戝彂鍗� - sendGoods(robotId, wxId, listOpen, recommendText, commentText, list, user.getId(), pid); + + List<String> list2 = list; + // 寮傛鎵ц鍙戦�� + executor.execute(new Runnable() { + @Override + public void run() { + sendGoods(robotId, wxId, listOpen, recommendText, commentText, list2, user.getId(), pid); + } + }); + } /** @@ -999,16 +1075,22 @@ boolean coupon = false; String quanPrice = ""; String couponAmount = ""; + SystemEnum system=userInfoService.getUserSystem(user.getId()); // 鑾峰彇鎺ㄨ崘璇� String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, goods.getGoodsName(), null, - couponAmount, null); + couponAmount, null,system); // 鑾峰彇璇勮璇� String commentText = shareGoodsTextTemplateService.getCommentTextByLink(coupon, jumpLink, - goods.getMarketPrice(), quanPrice, ConfigKeyEnum.quickShareVIPCommentText); + goods.getMarketPrice(), quanPrice, ConfigKeyEnum.quickShareVIPCommentText,system); - // 浜戝彂鍗� - sendGoods(robotId, wxId, listOpen, recommendText, commentText, goods.getGoodsDetailPictures(), user.getId(), - pid); + // 寮傛鎵ц鍙戦�� + executor.execute(new Runnable() { + @Override + public void run() { + sendGoods(robotId, wxId, listOpen, recommendText, commentText, goods.getGoodsDetailPictures(), user.getId(), + pid); + } + }); } /** @@ -1040,21 +1122,28 @@ coupon = true; } + SystemEnum system=userInfoService.getUserSystem(user.getId()); + // 鑾峰彇鎺ㄨ崘璇� String recommendText = shareGoodsTextTemplateService.getRecommendText(coupon, - goods.getCommodityInfo().getCommodityName(), sales, couponAmount, null); + goods.getCommodityInfo().getCommodityName(), sales, couponAmount, null,system); // 鐢熸垚蹇嵎鍒嗕韩鍐呭 - String template = configService.get(ConfigKeyEnum.quickShareSuNingCommentText.getKey()); + String template = configService.getValue(ConfigKeyEnum.quickShareSuNingCommentText.getKey(),system); String commentText = shareGoodsTextTemplateService.createQuickShareTextSuNing(template, goods, jumpLink); List<String> imgList = new ArrayList<>(); for (SuningGoodsImg img : goods.getCommodityInfo().getPictureUrl()) { imgList.add(img.getPicUrl()); } - - // 浜戝彂鍗� - sendGoods(robotId, wxId, listOpen, recommendText, commentText, imgList, user.getId(), pid); + + executor.execute(new Runnable() { + @Override + public void run() { + // 浜戝彂鍗� + sendGoods(robotId, wxId, listOpen, recommendText, commentText, imgList, user.getId(), pid); + } + }); } /** @@ -1112,10 +1201,10 @@ if (macsend) sendContent.setTitle(title); } - + SystemEnum system=userInfoService.getUserSystem(uid); // 鍙戦�佸浘鐗� int num = 1; - String picNum = configService.get(ConfigKeyEnum.robotCloudGroupPictureNum.getKey()); + String picNum = configService.getValue(ConfigKeyEnum.robotCloudGroupPictureNum.getKey(),system); if (!StringUtil.isNullOrEmpty(picNum)) { num = Integer.parseInt(picNum); } @@ -1205,7 +1294,7 @@ UserCloudMQMsg msg = new UserCloudMQMsg(uid, evaluateId, UserCloudMQMsg.TYPE_EVALUATE); Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userCloud, msg); - producer.send(message); + rocketMQManager.sendNormalMsg(message, null); } } catch (Exception e) { LogHelper.errorDetailInfo(e); @@ -1239,7 +1328,7 @@ UserCloudMQMsg msg = new UserCloudMQMsg(uid, UserCloudMQMsg.TYPE_PUSH); Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userCloud, msg); message.setStartDeliverTime(java.lang.System.currentTimeMillis() + 1000 * 60 * 10); - producer.send(message); + rocketMQManager.sendNormalMsg(message, null); } // 鏇存柊宸叉彁閱� -- Gitblit v1.8.0