| | |
| | | package com.yeshi.fanli.util.rocketmq.consumer.order;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import com.aliyun.openservices.ons.api.Action;
|
| | | 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.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
|
| | | import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.order.HongBaoOrder;
|
| | | import com.yeshi.fanli.entity.order.HongBaoV2SettleTemp;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoV2SettleTempService;
|
| | | import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
|
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
|
| | | /**
|
| | | * 订单到账消费
|
| | | * |
| | | * @author Administrator
|
| | | *
|
| | | */
|
| | | @Component
|
| | | public class OrderMoneyRecievedMessageListener implements MessageListener {
|
| | |
|
| | | @Resource
|
| | | private HongBaoV2SettleTempService hongBaoV2SettleTempService;
|
| | |
|
| | | @Resource
|
| | | private HongBaoV2Service hongBaoV2Service;
|
| | |
|
| | | @Resource
|
| | | private HongBaoOrderService hongBaoOrderService;
|
| | |
|
| | | @Resource
|
| | | private Producer producer;
|
| | |
|
| | | private int getHongBaoType(int type) {
|
| | | switch (type) {
|
| | | case HongBaoV2.TYPE_YIJI:
|
| | | case HongBaoV2.TYPE_ERJI:
|
| | | case HongBaoV2.TYPE_SHARE_YIJI:
|
| | | case HongBaoV2.TYPE_SHARE_ERJI:
|
| | | return OrderMoneyRecievedMQMsg.TYPE_INVITE;
|
| | | case HongBaoV2.TYPE_SHARE_GOODS:
|
| | | return OrderMoneyRecievedMQMsg.TYPE_SHARE;
|
| | | case HongBaoV2.TYPE_ZIGOU:
|
| | | return OrderMoneyRecievedMQMsg.TYPE_ZIGOU;
|
| | | }
|
| | | return 0;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Action consume(Message message, ConsumeContext context) {
|
| | | // 根据红包做订单分发
|
| | | if (MQTopicName.TOPIC_ORDER.name().equalsIgnoreCase(message.getTopic())) {
|
| | | if (OrderTopicTagEnum.orderFanLiActual.name().equalsIgnoreCase(message.getTag())) {
|
| | | String key = message.getKey();
|
| | | List<HongBaoV2SettleTemp> list = hongBaoV2SettleTempService.listByKey(key);
|
| | | Map<String, BigDecimal> moneyMap = new HashMap<>();
|
| | | // 临时订单消息
|
| | | for (HongBaoV2SettleTemp temp : list) {
|
| | | long hongBaoId = temp.getHongBaoId();
|
| | | HongBaoV2 v2 = hongBaoV2Service.selectByPrimaryKey(hongBaoId);
|
| | | if (v2 != null) {
|
| | | long mainHongBaoId = v2.getId();
|
| | | if (v2.getParent() != null)
|
| | | mainHongBaoId = v2.getParent().getId();
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderService.selectDetailByHongBaoId(mainHongBaoId);
|
| | | if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {
|
| | | String mapKey = String.format("%s#%s#%s#%s", hongBaoOrder.getCommonOrder().getOrderNo(),
|
| | | hongBaoOrder.getCommonOrder().getSourceType(), v2.getUserInfo().getId(),
|
| | | getHongBaoType(v2.getType()));
|
| | | if (moneyMap.get(mapKey) == null)
|
| | | moneyMap.put(mapKey, new BigDecimal(0));
|
| | | moneyMap.put(mapKey, moneyMap.get(mapKey).add(v2.getMoney()));
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | for (Iterator<String> its = moneyMap.keySet().iterator(); its.hasNext();) {
|
| | | String mapKey = its.next();
|
| | | String[] mapKeys = mapKey.split("#");
|
| | | String orderNo = mapKeys[0];
|
| | | String sourceType = mapKeys[1];
|
| | | String uid = mapKeys[2];
|
| | | String type = mapKeys[3];
|
| | | OrderMoneyRecievedMQMsg msg = new OrderMoneyRecievedMQMsg(Integer.parseInt(type),
|
| | | Long.parseLong(uid), Integer.parseInt(sourceType), orderNo, moneyMap.get(mapKey),
|
| | | new Date(), 0);
|
| | | producer.send(MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER,
|
| | | OrderTopicTagEnum.orderFanLiSeparateByOrderNo, msg));
|
| | | }
|
| | |
|
| | | return Action.CommitMessage;
|
| | | }
|
| | | }
|
| | |
|
| | | return Action.CommitMessage;
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.util.rocketmq.consumer.order; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.aliyun.openservices.ons.api.Action; |
| | | 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.order.OrderTopicTagEnum; |
| | | import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg; |
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2; |
| | | import com.yeshi.fanli.entity.order.HongBaoOrder; |
| | | import com.yeshi.fanli.entity.order.HongBaoV2SettleTemp; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoV2SettleTempService; |
| | | import com.yeshi.fanli.service.inter.order.HongBaoOrderService; |
| | | import com.yeshi.fanli.service.inter.order.HongBaoV2Service; |
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory; |
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName; |
| | | |
| | | /** |
| | | * 订单到账消费 |
| | | * |
| | | * @author Administrator |
| | | * |
| | | */ |
| | | @Component |
| | | public class OrderMoneyRecievedMessageListener implements MessageListener { |
| | | |
| | | @Resource |
| | | private HongBaoV2SettleTempService hongBaoV2SettleTempService; |
| | | |
| | | @Resource |
| | | private HongBaoV2Service hongBaoV2Service; |
| | | |
| | | @Resource |
| | | private HongBaoOrderService hongBaoOrderService; |
| | | |
| | | @Resource |
| | | private Producer producer; |
| | | |
| | | private int getHongBaoType(int type) { |
| | | switch (type) { |
| | | case HongBaoV2.TYPE_YIJI: |
| | | case HongBaoV2.TYPE_ERJI: |
| | | case HongBaoV2.TYPE_SHARE_YIJI: |
| | | case HongBaoV2.TYPE_SHARE_ERJI: |
| | | return OrderMoneyRecievedMQMsg.TYPE_INVITE; |
| | | case HongBaoV2.TYPE_SHARE_GOODS: |
| | | return OrderMoneyRecievedMQMsg.TYPE_SHARE; |
| | | case HongBaoV2.TYPE_ZIGOU: |
| | | return OrderMoneyRecievedMQMsg.TYPE_ZIGOU; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | @Override |
| | | public Action consume(Message message, ConsumeContext context) { |
| | | LogHelper.mqInfo("consumer:OrderMoneyRecievedMessageListener", message.getMsgID(), message.getTopic(), |
| | | message.getTag(), new String(message.getBody())); |
| | | // 根据红包做订单分发 |
| | | if (MQTopicName.TOPIC_ORDER.name().equalsIgnoreCase(message.getTopic())) { |
| | | if (OrderTopicTagEnum.orderFanLiActual.name().equalsIgnoreCase(message.getTag())) { |
| | | String key = message.getKey(); |
| | | List<HongBaoV2SettleTemp> list = hongBaoV2SettleTempService.listByKey(key); |
| | | Map<String, BigDecimal> moneyMap = new HashMap<>(); |
| | | // 临时订单消息 |
| | | for (HongBaoV2SettleTemp temp : list) { |
| | | long hongBaoId = temp.getHongBaoId(); |
| | | HongBaoV2 v2 = hongBaoV2Service.selectByPrimaryKey(hongBaoId); |
| | | if (v2 != null) { |
| | | long mainHongBaoId = v2.getId(); |
| | | if (v2.getParent() != null) |
| | | mainHongBaoId = v2.getParent().getId(); |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderService.selectDetailByHongBaoId(mainHongBaoId); |
| | | if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) { |
| | | // 按订单号与用户统计资金 |
| | | String mapKey = String.format("%s#%s#%s#%s", hongBaoOrder.getCommonOrder().getOrderNo(), |
| | | hongBaoOrder.getCommonOrder().getSourceType(), v2.getUserInfo().getId(), |
| | | getHongBaoType(v2.getType())); |
| | | if (moneyMap.get(mapKey) == null) |
| | | moneyMap.put(mapKey, new BigDecimal(0)); |
| | | moneyMap.put(mapKey, moneyMap.get(mapKey).add(v2.getMoney())); |
| | | } |
| | | } |
| | | } |
| | | |
| | | for (Iterator<String> its = moneyMap.keySet().iterator(); its.hasNext();) { |
| | | String mapKey = its.next(); |
| | | String[] mapKeys = mapKey.split("#"); |
| | | String orderNo = mapKeys[0]; |
| | | String sourceType = mapKeys[1]; |
| | | String uid = mapKeys[2]; |
| | | String type = mapKeys[3]; |
| | | OrderMoneyRecievedMQMsg msg = new OrderMoneyRecievedMQMsg(Integer.parseInt(type), |
| | | Long.parseLong(uid), Integer.parseInt(sourceType), orderNo, moneyMap.get(mapKey), |
| | | new Date(), 0); |
| | | LogHelper.test(String.format("批量返利到账订单分发:\n key值:%s \n 内容:%s", key, new Gson().toJson(msg))); |
| | | producer.send(MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, |
| | | OrderTopicTagEnum.orderFanLiSeparateByOrderNo, msg)); |
| | | } |
| | | |
| | | return Action.CommitMessage; |
| | | } |
| | | } |
| | | |
| | | return Action.CommitMessage; |
| | | } |
| | | |
| | | } |