|
@@ -1,15 +1,12 @@
|
|
package com.usky.dxtop.service.listener;
|
|
package com.usky.dxtop.service.listener;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.usky.dxtop.common.exception.CustomException;
|
|
import com.usky.dxtop.common.exception.CustomException;
|
|
import com.usky.dxtop.common.utils.StringUtils;
|
|
import com.usky.dxtop.common.utils.StringUtils;
|
|
-import com.usky.dxtop.model.MsgLog;
|
|
|
|
import com.usky.dxtop.model.Order;
|
|
import com.usky.dxtop.model.Order;
|
|
import com.usky.dxtop.service.MsgLogService;
|
|
import com.usky.dxtop.service.MsgLogService;
|
|
import com.usky.dxtop.service.OrderService;
|
|
import com.usky.dxtop.service.OrderService;
|
|
import com.usky.dxtop.service.config.rabbitmq.charge.ChargeProduceConfig;
|
|
import com.usky.dxtop.service.config.rabbitmq.charge.ChargeProduceConfig;
|
|
import com.usky.dxtop.service.constant.MsgLogBusinessCode;
|
|
import com.usky.dxtop.service.constant.MsgLogBusinessCode;
|
|
-import com.usky.dxtop.service.emun.MsgLogStatus;
|
|
|
|
import com.usky.dxtop.service.emun.OrderStatus;
|
|
import com.usky.dxtop.service.emun.OrderStatus;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.amqp.core.Message;
|
|
import org.springframework.amqp.core.Message;
|
|
@@ -19,7 +16,6 @@ import org.springframework.stereotype.Component;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
-import java.util.Date;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author yq
|
|
* @author yq
|
|
@@ -37,31 +33,17 @@ public class ChargeMqListener {
|
|
@RabbitListener(queues = ChargeProduceConfig.NAME, containerFactory = ChargeProduceConfig.LISTENER)
|
|
@RabbitListener(queues = ChargeProduceConfig.NAME, containerFactory = ChargeProduceConfig.LISTENER)
|
|
public void dealDeclareMessage(Message message) {
|
|
public void dealDeclareMessage(Message message) {
|
|
try {
|
|
try {
|
|
- //消息类型
|
|
|
|
- String routingKey = message.getMessageProperties().getReceivedRoutingKey();
|
|
|
|
- log.info(routingKey);
|
|
|
|
String s = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
String s = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
- log.info("charge_trans_produce:接受到的消息"+s);
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
- Long msgId = Long.parseLong(jsonObject.get("seq").toString());
|
|
|
|
- MsgLog msgLog = msgLogService.getById(msgId);
|
|
|
|
- if (msgLogService.isRepetition(msgLog)){
|
|
|
|
|
|
+ msgLogService.consumerSuccess(s,msgLog -> {
|
|
Order order = new Order();
|
|
Order order = new Order();
|
|
String orderId = StringUtils.remove(msgLog.getBusinessId(), MsgLogBusinessCode.ORDER);
|
|
String orderId = StringUtils.remove(msgLog.getBusinessId(), MsgLogBusinessCode.ORDER);
|
|
order.setId(Long.parseLong(orderId));
|
|
order.setId(Long.parseLong(orderId));
|
|
- if ("1".equals(jsonObject.get("code").toString())) {
|
|
|
|
|
|
+ if (msgLog.getIsSuccess()){
|
|
order.setOrderFlag(OrderStatus.COMPLETE.getCode());
|
|
order.setOrderFlag(OrderStatus.COMPLETE.getCode());
|
|
- msgLog.setIsSuccess(true);
|
|
|
|
}else {
|
|
}else {
|
|
order.setOrderFlag(OrderStatus.PAYMENT_ERROR_DEBIT.getCode());
|
|
order.setOrderFlag(OrderStatus.PAYMENT_ERROR_DEBIT.getCode());
|
|
- msgLog.setIsSuccess(false);
|
|
|
|
}
|
|
}
|
|
- orderService.updateById(order);
|
|
|
|
- msgLog.setUpdateTime(new Date());
|
|
|
|
- msgLog.setConsequence(s);
|
|
|
|
- msgLog.setMsgFlag(MsgLogStatus.CONSUMER_SUCCESS.getCode());
|
|
|
|
- msgLogService.updateById(msgLog);
|
|
|
|
- }
|
|
|
|
|
|
+ });
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.info("charge_trans_produce"+"异常信息:" + e.getMessage());
|
|
log.info("charge_trans_produce"+"异常信息:" + e.getMessage());
|
|
throw new CustomException(e.getMessage());
|
|
throw new CustomException(e.getMessage());
|