| | |
| | | import com.aliyun.openservices.ons.api.Producer;
|
| | | import com.aliyun.openservices.ons.api.SendResult;
|
| | | import com.google.gson.Gson;
|
| | | import com.yeshi.fanli.dto.order.OrderMQMsgDTO;
|
| | | import com.yeshi.fanli.dto.order.OrderMoneyRecievedMQMsgDTO;
|
| | | import com.yeshi.fanli.dto.user.coupon.UserSystemCouponUseMQMsgDTO;
|
| | | 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.UserSystemCouponUseMQMsg;
|
| | | import com.yeshi.fanli.entity.bus.user.UserSystemCouponRecord;
|
| | | import com.yeshi.fanli.entity.mq.MQUnSendInfo;
|
| | | import com.yeshi.fanli.entity.system.SystemCoupon;
|
| | | import com.yeshi.fanli.exception.money.OrderMoneySettleException;
|
| | | import com.yeshi.fanli.exception.mq.MQUnSendInfoException;
|
| | | import com.yeshi.fanli.exception.order.InviteOrderSubsidyException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.mq.MQUnSendInfoService;
|
| | | import com.yeshi.fanli.service.inter.order.InviteOrderSubsidyService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderMoneySettleService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
|
| | | /**
|
| | |
| | |
|
| | | @Override
|
| | | public Action consume(Message message, ConsumeContext context) {
|
| | |
|
| | | if (!Constant.IS_TASK) {// 非任务服务器不能消费消息
|
| | | return Action.ReconsumeLater;
|
| | | }
|
| | | LogHelper.mqInfo("consumer:InviteOrderSubsidyMessageListener", message.getMsgID(), message.getTopic(),
|
| | | message.getTag(), new String(message.getBody()));
|
| | | String tag = message.getTag();
|
| | |
|
| | | if (MQTopicName.TOPIC_ORDER.name().equalsIgnoreCase(message.getTopic())) {
|
| | | // 查询上级红包
|
| | | OrderMQMsgDTO dto = new Gson().fromJson(new String(message.getBody()), OrderMQMsgDTO.class);
|
| | | if (dto != null) {
|
| | | try {
|
| | | inviteOrderSubsidyService.addOrUpdateByOrder(dto.getOrderId(), dto.getType());
|
| | | } catch (InviteOrderSubsidyException e) {
|
| | | return Action.ReconsumeLater;
|
| | | }
|
| | | }
|
| | | } else if (MQTopicName.TOPIC_FANLI.name().equalsIgnoreCase(message.getTopic())) {
|
| | | if (message.getTag().equalsIgnoreCase("actual")) {
|
| | | OrderMoneyRecievedMQMsgDTO dto = new Gson().fromJson(new String(message.getBody()),
|
| | | OrderMoneyRecievedMQMsgDTO.class);
|
| | | if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderStatistic.name())
|
| | | || tag.equalsIgnoreCase(OrderTopicTagEnum.orderUpdate.name())) {
|
| | | // 查询上级红包
|
| | | OrderMQMsg dto = new Gson().fromJson(new String(message.getBody()), OrderMQMsg.class);
|
| | | if (dto != null) {
|
| | | if (dto.getType() == OrderMoneyRecievedMQMsgDTO.TYPE_ZIGOU) {// 自购到账
|
| | | try {
|
| | | inviteOrderSubsidyService.addOrUpdateByOrder(dto.getOrderId(), dto.getType());
|
| | | } catch (InviteOrderSubsidyException e) {
|
| | | return Action.ReconsumeLater;
|
| | | }
|
| | | }
|
| | | } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiActual.name())) {
|
| | | OrderMoneyRecievedMQMsg dto = new Gson().fromJson(new String(message.getBody()),
|
| | | OrderMoneyRecievedMQMsg.class);
|
| | | if (dto != null) {
|
| | | if (dto.getType() == OrderMoneyRecievedMQMsg.TYPE_ZIGOU) {// 自购到账
|
| | | // 判断订单号是否在补贴中
|
| | | long count = inviteOrderSubsidyService.countByOrderIdAndSourceType(dto.getOrderId(),
|
| | | dto.getSourceType());
|
| | | if (count > 0) {// 延时消息发送
|
| | | sendOrderSubsidyUpdateLater(dto, 5);
|
| | | }
|
| | | } else if (dto.getType() == OrderMoneyRecievedMQMsgDTO.TYPE_INVITE) {// 邀请到账
|
| | | } else if (dto.getType() == OrderMoneyRecievedMQMsg.TYPE_INVITE) {// 邀请到账
|
| | | // 补贴到账
|
| | | try {
|
| | | orderMoneySettleService.inviteSubsidySettle(dto.getUid(), message.getKey());
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | } else if (message.getTag().equalsIgnoreCase("delay")) {
|
| | | OrderMoneyRecievedMQMsgDTO dto = new Gson().fromJson(new String(message.getBody()),
|
| | | OrderMoneyRecievedMQMsgDTO.class);
|
| | | } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiDelay.name())) {
|
| | | OrderMoneyRecievedMQMsg dto = new Gson().fromJson(new String(message.getBody()),
|
| | | OrderMoneyRecievedMQMsg.class);
|
| | | if (dto != null) {
|
| | | if (dto.getType() == OrderMoneyRecievedMQMsgDTO.TYPE_ZIGOU) {// 延时时间已到
|
| | | if (dto.getType() == OrderMoneyRecievedMQMsg.TYPE_ZIGOU) {// 延时时间已到
|
| | | // 判断订单号是否在补贴中
|
| | | long count = inviteOrderSubsidyService.countByOrderIdAndSourceType(dto.getOrderId(),
|
| | | dto.getSourceType());
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | } else if (MQTopicName.TOPIC_SYSTEM_COUPON_USE.name().equalsIgnoreCase(message.getTopic())) {// 奖励券使用成功
|
| | | UserSystemCouponUseMQMsgDTO dto = new Gson().fromJson(new String(message.getBody()),
|
| | | UserSystemCouponUseMQMsgDTO.class);
|
| | | if (dto != null) {
|
| | | long count = inviteOrderSubsidyService.countByOrderIdAndSourceType(dto.getOrderId(),
|
| | | dto.getSourceType());
|
| | | if (count > 0) {
|
| | | // 使相关订单失效
|
| | | inviteOrderSubsidyService.invalidByOrderIdAndSourceType(dto.getOrderId(), dto.getSourceType());
|
| | | } else if (MQTopicName.TOPIC_USER.name().equalsIgnoreCase(message.getTopic())) {
|
| | | if (tag.equalsIgnoreCase(UserTopicTagEnum.useSystemCoupon.name())) {
|
| | | UserSystemCouponUseMQMsg dto = new Gson().fromJson(new String(message.getBody()),
|
| | | UserSystemCouponUseMQMsg.class);
|
| | | if (dto != null && dto.getCouponType()
|
| | | .equalsIgnoreCase(SystemCoupon.CouponTypeEnum.rebatePercentCoupon.name())) {// 返利奖励券的使用
|
| | | long count = inviteOrderSubsidyService.countByOrderIdAndSourceType(dto.getOrderId(),
|
| | | dto.getSourceType());
|
| | | if (count > 0) {
|
| | | // 使相关订单失效
|
| | | inviteOrderSubsidyService.invalidByOrderIdAndSourceType(dto.getOrderId(), dto.getSourceType());
|
| | | }
|
| | | return Action.CommitMessage;
|
| | | }
|
| | | return Action.CommitMessage;
|
| | | }
|
| | | //
|
| | | }
|
| | | return Action.CommitMessage;
|
| | | }
|
| | |
| | | *
|
| | | * @param day
|
| | | */
|
| | | private boolean sendOrderSubsidyUpdateLater(OrderMoneyRecievedMQMsgDTO dto, int day) {
|
| | | private boolean sendOrderSubsidyUpdateLater(OrderMoneyRecievedMQMsg dto, int day) {
|
| | |
|
| | | Message msg = new Message(MQTopicName.TOPIC_FANLI.name(), "delay", new Gson().toJson(dto).getBytes());
|
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiDelay, dto);
|
| | | msg.setKey(dto.getSourceType() + "_" + dto.getOrderId());
|
| | | long delayTime = System.currentTimeMillis() + 1000 * 60 * 60 * 24L * day;
|
| | | long delayTime = System.currentTimeMillis() + (Constant.IS_TEST ? 1000 * 30L : 1000 * 60 * 60 * 24L * day);
|
| | | msg.setStartDeliverTime(delayTime);
|
| | | SendResult sendResult = producer.send(msg);
|
| | | if (sendResult != null) {
|