Administrator
2025-08-20 9c5ebf3ef8b62884007b7f241a863db4047dbf1b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package cc.mrbird.febs.rabbit.producter;
 
import cc.mrbird.febs.rabbit.constants.ExchangeConstants;
import cc.mrbird.febs.rabbit.constants.RouteKeyConstants;
import cc.mrbird.febs.rabbit.enumerates.RabbitQueueEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.UUID;
 
/**
 * @author wzy
 * @date 2021-09-25
 **/
@Slf4j
@Component
public class AgentProducer implements RabbitTemplate.ConfirmCallback {
 
    /**
     * 配置中配置的RabbitTemplate的是prototype类型,不能直接注入
     */
    private RabbitTemplate rabbitTemplate;
 
    /**
     * 在构造方法上注入RabbitTemplate
     *
     * @param
     */
    @Autowired
    public AgentProducer(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
        rabbitTemplate.setConfirmCallback(this);
    }
 
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
 
    }
 
    public void sendOrderReturn(Long id) {
        log.info("发送消息:{}", id);
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(RabbitQueueEnum.ORDER_RETURN_MONEY.getExchange(), RabbitQueueEnum.ORDER_RETURN_MONEY.getRoute(), id, correlationData);
    }
 
    public void sendOrderCancelDelayMsg(Long id, Long times) {
        log.info("发送自动取消订单消息:{}, {}", id, times);
        rabbitTemplate.convertAndSend(RabbitQueueEnum.ORDER_CANCEL_DELAY_TTL.getExchange(), RabbitQueueEnum.ORDER_CANCEL_DELAY_TTL.getRoute(), id, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setExpiration(String.valueOf(times));
                return message;
            }
        });
    }
 
    public void sendClothesOrderCancelDelayMsg(Long id, Long times) {
        log.info("发送自动取消订单消息:{}, {}", id, times);
        rabbitTemplate.convertAndSend(RabbitQueueEnum.ORDER_CANCEL_DELAY_TTL.getExchange(), RabbitQueueEnum.ORDER_CANCEL_DELAY_TTL.getRoute(), id, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setExpiration(String.valueOf(times));
                return message;
            }
        });
    }
 
    /**
     * 发送代理自动升级消息
     *
     * @param memberId
     */
    public void sendAutoLevelUpMsg(@NotNull Long memberId) {
        log.info("发送代理自动升级消息:{}", memberId);
        rabbitTemplate.convertAndSend(ExchangeConstants.EXCHANGE_DEFAULT, RouteKeyConstants.ROUTE_KEY_DEFAULT, memberId);
    }
 
    public void sendReturnMoneyMsg(Long orderId) {
        log.info("发送返利消息:{}", orderId);
        rabbitTemplate.convertAndSend(RabbitQueueEnum.AGENT_REUTRN_MONEY.getExchange(), RabbitQueueEnum.AGENT_REUTRN_MONEY.getRoute(), orderId);
    }
 
 
    public void sendOrderCoupon(Long id) {
        log.info("发送使用优惠卷消息:{}", id);
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(RabbitQueueEnum.ORDER_COUPON.getExchange(), RabbitQueueEnum.ORDER_COUPON.getRoute(), id, correlationData);
    }
 
    public void sendGetScoreMsg(Long orderId) {
        log.info("发送获得积分消息:{}", orderId);
 
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(RabbitQueueEnum.GET_SCORE_MSG.getExchange(), RabbitQueueEnum.GET_SCORE_MSG.getRoute(), orderId, correlationData);
    }
 
    public void sendVipLevelUp(Long orderId) {
        log.info("发送会员升级消息:{}", orderId);
 
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(RabbitQueueEnum.VIP_LEVEL_UP.getExchange(), RabbitQueueEnum.VIP_LEVEL_UP.getRoute(), orderId, correlationData);
    }
 
    public void sendSaleLevelUp(Long orderId) {
        log.info("发送团长升级:{}", orderId);
 
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(RabbitQueueEnum.SALE_LEVEL_UP.getExchange(), RabbitQueueEnum.SALE_LEVEL_UP.getRoute(), orderId, correlationData);
    }
 
    public void sendCheckActivityItem(Long orderId) {
        log.info("核销活动门票:{}", orderId);
 
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(RabbitQueueEnum.ACTIVITY_ORDER_ITEM_CHECK.getExchange(), RabbitQueueEnum.ACTIVITY_ORDER_ITEM_CHECK.getRoute(), orderId, correlationData);
    }
 
    public void sendAddLike(Long socialId) {
        log.info("点赞:{}", socialId);
 
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(RabbitQueueEnum.CLOTHES_ADD_LIKE.getExchange(), RabbitQueueEnum.CLOTHES_ADD_LIKE.getRoute(), socialId, correlationData);
    }
 
    public void sendAddCollect(Long socialId) {
        log.info("收藏:{}", socialId);
 
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(RabbitQueueEnum.CLOTHES_ADD_COLLECT.getExchange(), RabbitQueueEnum.CLOTHES_ADD_COLLECT.getRoute(), socialId, correlationData);
    }
}