|
|
|
@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.bnyer.common.core.domain.PayInfo; |
|
|
|
import com.bnyer.common.core.enums.EnumPayStatus; |
|
|
|
import com.bnyer.common.core.enums.EnumSceneCode; |
|
|
|
import com.bnyer.common.core.enums.ResponseEnum; |
|
|
|
import com.bnyer.common.core.exception.ServiceException; |
|
|
|
@ -14,14 +13,14 @@ import com.bnyer.common.rocketmq.config.RocketMqConstant; |
|
|
|
import com.bnyer.pay.bean.dto.AddPayInfoDto; |
|
|
|
import com.bnyer.pay.bean.dto.EditPayInfoNotifyDto; |
|
|
|
import com.bnyer.pay.bean.dto.EditPayInfoSingleDto; |
|
|
|
import com.bnyer.pay.bean.vo.PayInfoDetailsVo; |
|
|
|
import com.bnyer.pay.mapper.PayInfoMapper; |
|
|
|
import com.bnyer.pay.service.PayInfoService; |
|
|
|
import com.bnyer.pay.bean.vo.PayInfoDetailsVo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.rocketmq.client.producer.SendStatus; |
|
|
|
import org.apache.rocketmq.client.producer.SendCallback; |
|
|
|
import org.apache.rocketmq.client.producer.SendResult; |
|
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.messaging.support.GenericMessage; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
@ -86,24 +85,34 @@ public class PayInfoServiceImpl extends ServiceImpl<PayInfoMapper, PayInfo> impl |
|
|
|
vipRechargeMsgObj.put("orderNo",orderNo); |
|
|
|
String vipRechargeMsgStr = JSON.toJSONString(vipRechargeMsgObj); |
|
|
|
// TODO: 2023/04/23可优化为:添加一张消息日志表,字段:topicName,消息内容,消息状态(发送中、成功、失败),错误信息
|
|
|
|
// vipOrderPayNotifyMqTemplate.asyncSend(RocketMqConstant.VIP_ORDER_PAY_NOTIFY_TOPIC,vipRechargeMsgStr,new SendCallback() {
|
|
|
|
// @Override
|
|
|
|
// public void onSuccess(SendResult sendResult) {
|
|
|
|
// log.info("topic:{}消息发送成功",RocketMqConstant.VIP_ORDER_PAY_NOTIFY_TOPIC);
|
|
|
|
// }
|
|
|
|
// @Override
|
|
|
|
// public void onException(Throwable e) {
|
|
|
|
// log.info("topic:{}消息发送失败,error:{}",RocketMqConstant.VIP_ORDER_PAY_NOTIFY_TOPIC,e.getMessage());
|
|
|
|
sendMsg(RocketMqConstant.VIP_ORDER_PAY_NOTIFY_TOPIC,vipRechargeMsgStr); |
|
|
|
// SendStatus sendStatus = vipOrderPayNotifyMqTemplate.syncSend(RocketMqConstant.VIP_ORDER_PAY_NOTIFY_TOPIC,
|
|
|
|
// new GenericMessage<>(vipRechargeMsgStr)).getSendStatus();
|
|
|
|
// if (!Objects.equals(sendStatus, SendStatus.SEND_OK)) {
|
|
|
|
// // 消息发不出去就抛异常,因为订单回调会有多次,几乎不可能每次都无法发送出去,发的出去无所谓
|
|
|
|
// throw new ServiceException(ResponseEnum.SERVER_ERROR);
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
SendStatus sendStatus = vipOrderPayNotifyMqTemplate.syncSend(RocketMqConstant.VIP_ORDER_PAY_NOTIFY_TOPIC, |
|
|
|
new GenericMessage<>(vipRechargeMsgStr)).getSendStatus(); |
|
|
|
if (!Objects.equals(sendStatus, SendStatus.SEND_OK)) { |
|
|
|
// 消息发不出去就抛异常,因为订单回调会有多次,几乎不可能每次都无法发送出去,发的出去无所谓
|
|
|
|
throw new ServiceException(ResponseEnum.SERVER_ERROR); |
|
|
|
// break;
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 发送消息 |
|
|
|
* @param topic |
|
|
|
* @param msg |
|
|
|
* @param <T> |
|
|
|
*/ |
|
|
|
public <T> void sendMsg(String topic, T msg) { |
|
|
|
vipOrderPayNotifyMqTemplate.asyncSend(topic, msg,new SendCallback() { |
|
|
|
@Override |
|
|
|
public void onSuccess(SendResult sendResult) { |
|
|
|
log.info("topic:{}消息发送成功,result:{}",topic,JSON.toJSONString(sendResult)); |
|
|
|
} |
|
|
|
break; |
|
|
|
@Override |
|
|
|
public void onException(Throwable e) { |
|
|
|
log.info("topic:{}消息发送失败,error:{}",topic,e.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|