package com.yeshi.fanli.util.mq.rabbit.consumer;
|
|
import com.google.gson.Gson;
|
import com.rabbitmq.client.Channel;
|
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
import com.yeshi.fanli.exception.order.TaoBaoWeiQuanException;
|
import com.yeshi.fanli.log.LogHelper;
|
import com.yeshi.fanli.service.inter.order.OrderProcessService;
|
import com.yeshi.fanli.util.RedisKeyEnum;
|
import com.yeshi.fanli.util.RedisManager;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.mq.rabbit.RabbitmqMsgConsumeUtil;
|
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.nio.charset.StandardCharsets;
|
|
/**
|
* @author hxh
|
* @title: QueueHelloWorldListener
|
* @description:
|
* @date 2024/9/26 13:47
|
*/
|
@Component
|
public class FanliOrderNewListener {
|
@Resource
|
private RabbitTemplate rabbitTemplate;
|
|
@Resource
|
private RedisManager redisManager;
|
|
@Resource
|
private OrderProcessService orderProcessService;
|
|
|
@RabbitListener(queues = "fanli-order-new-fanli", ackMode = "MANUAL")
|
public void onMessage(Message message, Channel channel) throws Exception {
|
RabbitmqMsgConsumeUtil.processMessage(message, channel, rabbitTemplate, () -> {
|
String result = new String(message.getBody(), StandardCharsets.UTF_8);
|
if (!StringUtil.isNullOrEmpty(result)) {
|
HongBaoV2 hongbao = new Gson().fromJson(result, HongBaoV2.class);
|
try {
|
if (hongbao != null) {
|
String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.hongBaoFanLi,
|
hongbao.getId() + "");
|
if (StringUtil.isNullOrEmpty(redisManager.getCommonString(key))) {
|
// 处理之后要隔2小时再次进行处理
|
redisManager.cacheCommonString(key, "1", 60 * 60 * 2);
|
orderProcessService.fanli(hongbao);
|
}
|
}
|
} catch (TaoBaoWeiQuanException e) {
|
try {
|
LogHelper.errorDetailInfo(e);
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
throw e;
|
} catch (Exception e) {
|
try {
|
LogHelper.errorDetailInfo(e, "HongBaoV2-ID:" + hongbao.getId(), "");
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
throw e;
|
}
|
}
|
});
|
}
|
}
|