| | |
| | | package com.yeshi.fanli.util.rocketmq.consumer.order;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | |
| | | 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.order.CommonOrder;
|
| | | 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.CommonOrderException;
|
| | | import com.yeshi.fanli.exception.order.InviteOrderSubsidyException;
|
| | | import com.yeshi.fanli.exception.order.OrderTeamRewardException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.mq.MQUnSendInfoService;
|
| | | import com.yeshi.fanli.service.inter.order.CommonOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.InviteOrderSubsidyService;
|
| | | import com.yeshi.fanli.service.inter.order.InviteOrderSubsidyServiceV2;
|
| | | 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.TimeUtil;
|
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
|
| | |
| | | private InviteOrderSubsidyService inviteOrderSubsidyService;
|
| | |
|
| | | @Resource
|
| | | private InviteOrderSubsidyServiceV2 inviteOrderSubsidyServiceV2;
|
| | |
|
| | | @Resource
|
| | | private UserSystemCouponRecordService userSystemCouponRecordService;
|
| | |
|
| | | @Resource(name = "producer")
|
| | |
| | |
|
| | | @Resource
|
| | | private OrderMoneySettleService orderMoneySettleService;
|
| | |
|
| | | @Resource
|
| | | private CommonOrderService commonOrderService;
|
| | |
|
| | | // 团队奖励开始时间
|
| | | private static final long TEAM_REWARD_START_TIME = TimeUtil.convertToTimeTemp("2019-04-15", "yyyy-MM-dd");
|
| | |
|
| | | public InviteOrderSubsidyMessageListener() {
|
| | |
|
| | |
| | | // 查询上级红包
|
| | | OrderMQMsg dto = new Gson().fromJson(new String(message.getBody()), OrderMQMsg.class);
|
| | | if (dto != null) {
|
| | | try {
|
| | | inviteOrderSubsidyService.addOrUpdateByOrder(dto.getOrderId(), dto.getType());
|
| | | } catch (InviteOrderSubsidyException e) {
|
| | | // 查询出订单创建时间
|
| | | Date orderTime = commonOrderService.getThirdCreateTime(dto.getOrderId(), dto.getType());
|
| | | if (orderTime.getTime() >= TEAM_REWARD_START_TIME) {
|
| | | try {
|
| | | inviteOrderSubsidyServiceV2.addOrUpdateByOrder(dto.getOrderId(), dto.getType());
|
| | | return Action.CommitMessage;
|
| | | } catch (InviteOrderSubsidyException e) {
|
| | | e.printStackTrace();
|
| | | LogHelper.errorDetailInfo(e, new Gson().toJson(dto), "");
|
| | | } catch (OrderTeamRewardException e) {
|
| | | e.printStackTrace();
|
| | | LogHelper.errorDetailInfo(e, new Gson().toJson(dto), "");
|
| | | } catch (CommonOrderException e) {
|
| | | e.printStackTrace();
|
| | | LogHelper.errorDetailInfo(e, new Gson().toJson(dto), "");
|
| | | }
|
| | | return Action.ReconsumeLater;
|
| | | } else {
|
| | | try {
|
| | | inviteOrderSubsidyService.addOrUpdateByOrder(dto.getOrderId(), dto.getType());
|
| | | } catch (InviteOrderSubsidyException e) {
|
| | | LogHelper.errorDetailInfo(e, new Gson().toJson(dto), "");
|
| | | return Action.ReconsumeLater;
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiActual.name())) {
|
| | | OrderMoneyRecievedMQMsg dto = new Gson().fromJson(new String(message.getBody()),
|
| | |
| | | && record.getCouponType()
|
| | | .equalsIgnoreCase(SystemCoupon.CouponTypeEnum.rebatePercentCoupon.name())
|
| | | && record.getGoodSource() == dto.getSourceType()) {// 成功使用了奖励券
|
| | | inviteOrderSubsidyService.invalidByOrderIdAndSourceType(dto.getOrderId(),
|
| | | dto.getSourceType());
|
| | |
|
| | | Date orderTime = commonOrderService.getThirdCreateTime(dto.getOrderId(), dto.getType());
|
| | | if (orderTime.getTime() >= TEAM_REWARD_START_TIME) {
|
| | | inviteOrderSubsidyServiceV2.invalidByOrderIdAndSourceType(dto.getOrderId(),
|
| | | dto.getSourceType());
|
| | | } else
|
| | |
|
| | | inviteOrderSubsidyService.invalidByOrderIdAndSourceType(dto.getOrderId(),
|
| | | dto.getSourceType());
|
| | | } else {
|
| | | // 使数据有效
|
| | | inviteOrderSubsidyService.validByOrderIdAndSourceType(dto.getOrderId(),
|
| | | dto.getSourceType());
|
| | | try {
|
| | | Date orderTime = commonOrderService.getThirdCreateTime(dto.getOrderId(),
|
| | | dto.getType());
|
| | | if (orderTime.getTime() >= TEAM_REWARD_START_TIME) {
|
| | | inviteOrderSubsidyServiceV2.validByOrderIdAndSourceType(dto.getOrderId(),
|
| | | dto.getSourceType());
|
| | | } else
|
| | |
|
| | | inviteOrderSubsidyService.validByOrderIdAndSourceType(dto.getOrderId(),
|
| | | dto.getSourceType());
|
| | | } catch (InviteOrderSubsidyException e) {
|
| | | e.printStackTrace();
|
| | | return Action.ReconsumeLater;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | dto.getSourceType());
|
| | | if (count > 0) {
|
| | | // 使相关订单失效
|
| | | inviteOrderSubsidyService.invalidByOrderIdAndSourceType(dto.getOrderId(), dto.getSourceType());
|
| | | Date orderTime = commonOrderService.getThirdCreateTime(dto.getOrderId(), dto.getSourceType());
|
| | | if (orderTime.getTime() >= TEAM_REWARD_START_TIME) {
|
| | | inviteOrderSubsidyServiceV2.invalidByOrderIdAndSourceType(dto.getOrderId(),
|
| | | dto.getSourceType());
|
| | | } else
|
| | | inviteOrderSubsidyService.invalidByOrderIdAndSourceType(dto.getOrderId(),
|
| | | dto.getSourceType());
|
| | | }
|
| | | return Action.CommitMessage;
|
| | | }
|