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/util/rocketmq/consumer/redpack/RedPackMessageListener.java | 105 ++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 72 insertions(+), 33 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/redpack/RedPackMessageListener.java b/fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/redpack/RedPackMessageListener.java index 1974202..c739be7 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/redpack/RedPackMessageListener.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/redpack/RedPackMessageListener.java @@ -8,19 +8,21 @@ import com.aliyun.openservices.ons.api.ConsumeContext; import com.aliyun.openservices.ons.api.Message; import com.aliyun.openservices.ons.api.MessageListener; +import com.aliyun.openservices.ons.api.Producer; import com.google.gson.Gson; -import com.yeshi.fanli.dto.mq.BaseMQMsgBody; import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum; import com.yeshi.fanli.dto.mq.order.body.OrderMQMsg; import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg; import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum; -import com.yeshi.fanli.dto.mq.user.body.IntegralTaskMQMsg; import com.yeshi.fanli.dto.mq.user.body.UserAccountBindingMQMsg; import com.yeshi.fanli.dto.mq.user.body.UserInviteMQMsg; +import com.yeshi.fanli.dto.mq.user.body.UserRedPackGiftMQMsg; import com.yeshi.fanli.log.LogHelper; +import com.yeshi.fanli.service.inter.redpack.RedPackGiveRecordService; import com.yeshi.fanli.service.inter.redpack.RedPackWinInviteService; import com.yeshi.fanli.service.inter.user.UserSystemCouponService; import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.rocketmq.MQTopicName; /** @@ -34,46 +36,75 @@ @Resource private UserSystemCouponService userSystemCouponService; - + @Resource private RedPackWinInviteService redPackWinInviteService; + @Resource + private RedPackGiveRecordService redPackGiveRecordService; + + @Resource(name = "producer") + private Producer producer; + @Override public Action consume(Message message, ConsumeContext context) { - LogHelper.mqInfo("consumer-RedPackMessageListener", message.getTopic(), message.getTag(), + LogHelper.mqInfo("consumer-RedPackMessageListener", message.getMsgID(), message.getTopic(), message.getTag(), new String(message.getBody())); String tag = message.getTag(); if (tag == null) tag = ""; - BaseMQMsgBody baseBody = new Gson().fromJson(new String(message.getBody()), BaseMQMsgBody.class); - if (baseBody.isTest() != Constant.IS_TEST) - return Action.ReconsumeLater; - if (MQTopicName.TOPIC_ORDER.name().equalsIgnoreCase(message.getTopic())) { - if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiActual.name())) {// 杩斿埄鍒拌处 - OrderMoneyRecievedMQMsg orderMoneyRecievedMQMsg = new Gson().fromJson(new String(message.getBody()), - OrderMoneyRecievedMQMsg.class); - if (orderMoneyRecievedMQMsg.getType() == OrderMoneyRecievedMQMsg.TYPE_SHARE) { - try {// 涓婄骇鍒嗕韩璁㈠崟濂栧姳 - redPackWinInviteService.orderArriveReward(orderMoneyRecievedMQMsg.getUid(), - orderMoneyRecievedMQMsg.getSourceType(), orderMoneyRecievedMQMsg.getOrderId()); - } catch (Exception e) { - e.printStackTrace(); - } + if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderStatistic.name())) {// 璁㈠崟缁熻 + OrderMQMsg orderMQMsg = new Gson().fromJson(new String(message.getBody()), OrderMQMsg.class); + // 鍙戦��24灏忔椂寤舵椂娑堟伅 + // 娴嬭瘯鏃跺彂閫� + int hour = 24; + if (Constant.IS_TEST) { + hour = 1; } - } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderStatistic.name())) {// 璁㈠崟缁熻 - OrderMQMsg orderMQMsg = new Gson().fromJson(new String(message.getBody()), - OrderMQMsg.class); - if (orderMQMsg.isValid()) { + orderMQMsg.setDelayHour(hour); + Message msg = new Message(message.getTopic(), OrderTopicTagEnum.orderStatisticDelay.name(), + new Gson().toJson(orderMQMsg).getBytes()); + if (orderMQMsg.getStaticticDate().getTime() + 1000 * 60 * 60L * hour > System.currentTimeMillis())// 鏃堕棿鏄惁宸茬粡杩囦簡 + msg.setStartDeliverTime(orderMQMsg.getStaticticDate().getTime() + 1000 * 60 * 60L * hour); + else + msg.setStartDeliverTime(System.currentTimeMillis() + 1000 * 60); + producer.send(msg); + return Action.CommitMessage; + } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderStatisticDelay.name())) {// 璁㈠崟缁熻 + OrderMQMsg orderMQMsg = new Gson().fromJson(new String(message.getBody()), OrderMQMsg.class); + int hour = 24; + if (Constant.IS_TEST) { + hour = 1; + } + + if (orderMQMsg.getDelayHour() == hour) { try {// 閭�璇峰鍔� redPackWinInviteService.inviteSucceedReward(orderMQMsg.getUid()); } catch (Exception e) { - e.printStackTrace(); + LogHelper.errorDetailInfo(e); + return Action.ReconsumeLater; } } + return Action.CommitMessage; + } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiSeparateByOrderNo.name())) {// 璁㈠崟鍒拌处锛堟寜璁㈠崟鍙峰鐞嗭級 + OrderMoneyRecievedMQMsg orderMoneyRecievedMQMsg = new Gson().fromJson(new String(message.getBody()), + OrderMoneyRecievedMQMsg.class); + + if (orderMoneyRecievedMQMsg.getType() == OrderMoneyRecievedMQMsg.TYPE_INVITE) { + if (!StringUtil.isNullOrEmpty(orderMoneyRecievedMQMsg.getOrderId()) + && orderMoneyRecievedMQMsg.getUid() != null) { + try { + redPackWinInviteService.inviteOrderArriveReward(orderMoneyRecievedMQMsg.getUid(), + orderMoneyRecievedMQMsg.getSourceType(), orderMoneyRecievedMQMsg.getOrderId()); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + return Action.CommitMessage; } - } else if (MQTopicName.TOPIC_USER.name().equalsIgnoreCase(message.getTopic())) { boolean inviteSucceedReward = false; Long uid = null; @@ -81,7 +112,8 @@ UserAccountBindingMQMsg userAccountBindingMQMsg = new Gson().fromJson(new String(message.getBody()), UserAccountBindingMQMsg.class); Integer type = userAccountBindingMQMsg.getType(); - if (type == UserAccountBindingMQMsg.TYPE_PHONE || type == UserAccountBindingMQMsg.TYPE_TAOBAO) { + if (type == UserAccountBindingMQMsg.TYPE_PHONE || type == UserAccountBindingMQMsg.TYPE_WX + || type == UserAccountBindingMQMsg.TYPE_TAOBAO) { inviteSucceedReward = true; uid = userAccountBindingMQMsg.getUid(); } @@ -90,21 +122,28 @@ UserInviteMQMsg.class); inviteSucceedReward = true; uid = userInviteMQMsg.getWorkerId(); - } else if (tag.equalsIgnoreCase(UserTopicTagEnum.integralTaskFinish.name())) {// 閲戝竵浠诲姟瀹屾垚 - IntegralTaskMQMsg integralTaskMQMsg = new Gson().fromJson(new String(message.getBody()), - IntegralTaskMQMsg.class); - inviteSucceedReward = true; - uid = integralTaskMQMsg.getUid(); + + redPackWinInviteService.initCreateRedPackWin(userInviteMQMsg.getBossId(), + userInviteMQMsg.getWorkerId()); + + } else if (tag.equalsIgnoreCase(UserTopicTagEnum.redPackGiftDrawback.name())) {// 绾㈠寘璧犻�� + UserRedPackGiftMQMsg userRedPackGiftMQMsg = new Gson().fromJson(new String(message.getBody()), + UserRedPackGiftMQMsg.class); + try { // 绾㈠寘璧犻�佸埌鏈熸湭棰嗗彇 + redPackGiveRecordService.overdueByPrimaryKey(userRedPackGiftMQMsg.getId()); + } catch (Exception e) { + e.printStackTrace(); + } + return Action.CommitMessage; } - - if (inviteSucceedReward ) { + + if (inviteSucceedReward) { try {// 閭�璇峰鍔� redPackWinInviteService.inviteSucceedReward(uid); } catch (Exception e) { e.printStackTrace(); } } - } return Action.CommitMessage; } -- Gitblit v1.8.0