Commit 8f56bd20 authored by 33's avatar 33

更新日志

parent 920cc093
...@@ -32,7 +32,6 @@ import java.util.List; ...@@ -32,7 +32,6 @@ import java.util.List;
* @date 2022/1/19 15:42 * @date 2022/1/19 15:42
*/ */
@Service @Service
@Transactional(rollbackFor = RuntimeException.class)
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService { public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
@Resource @Resource
private NftService nftService; private NftService nftService;
...@@ -67,6 +66,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements ...@@ -67,6 +66,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
} }
@Override @Override
@Transactional(rollbackFor = RuntimeException.class)
public Order createOrder(OrderDto orderDto) { public Order createOrder(OrderDto orderDto) {
Charge charge = chargeService.getByType(orderDto.getPayScene()); Charge charge = chargeService.getByType(orderDto.getPayScene());
if (!orderDto.getFee().equals(charge.getFee())) { if (!orderDto.getFee().equals(charge.getFee())) {
...@@ -121,6 +121,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements ...@@ -121,6 +121,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
} }
@Override @Override
@Transactional(rollbackFor = RuntimeException.class)
public Boolean cancel(Long orderId, OrderStatus orderStatus) { public Boolean cancel(Long orderId, OrderStatus orderStatus) {
Order order = this.getById(orderId); Order order = this.getById(orderId);
Integer productId = order.getProductId(); Integer productId = order.getProductId();
......
...@@ -52,7 +52,6 @@ import java.util.concurrent.TimeUnit; ...@@ -52,7 +52,6 @@ import java.util.concurrent.TimeUnit;
*/ */
@Slf4j @Slf4j
@Service @Service
@Transactional(rollbackFor = RuntimeException.class)
public class WxPayServiceImpl implements WxPayService { public class WxPayServiceImpl implements WxPayService {
@Resource @Resource
private CloseableHttpClient httpClient; private CloseableHttpClient httpClient;
...@@ -75,6 +74,8 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -75,6 +74,8 @@ public class WxPayServiceImpl implements WxPayService {
@Resource @Resource
private RefundService refundService; private RefundService refundService;
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Object> payJsapi(JsapiPayDto jsapiPayDto) throws Exception { public Map<String, Object> payJsapi(JsapiPayDto jsapiPayDto) throws Exception {
RLock lock = redisson.getLock("pay-" + jsapiPayDto.getOrderId()); RLock lock = redisson.getLock("pay-" + jsapiPayDto.getOrderId());
if (!lock.tryLock(10, TimeUnit.SECONDS)) { if (!lock.tryLock(10, TimeUnit.SECONDS)) {
...@@ -155,6 +156,7 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -155,6 +156,7 @@ public class WxPayServiceImpl implements WxPayService {
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public Boolean notifyH5(HttpServletRequest request) { public Boolean notifyH5(HttpServletRequest request) {
try { try {
String requestBodyData = this.getRequestBodyData(request); String requestBodyData = this.getRequestBodyData(request);
...@@ -175,6 +177,7 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -175,6 +177,7 @@ public class WxPayServiceImpl implements WxPayService {
@Override @Override
@Transactional(rollbackFor = Exception.class)
public void processOrder(JSONObject jsonObject) throws InterruptedException { public void processOrder(JSONObject jsonObject) throws InterruptedException {
// 获取订单号 // 获取订单号
Long out_trade_no = jsonObject.getLong("out_trade_no"); Long out_trade_no = jsonObject.getLong("out_trade_no");
...@@ -189,10 +192,7 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -189,10 +192,7 @@ public class WxPayServiceImpl implements WxPayService {
log.warn("当前订单已处理完成, 订单号:==> {}", out_trade_no); log.warn("当前订单已处理完成, 订单号:==> {}", out_trade_no);
return; return;
} }
Integer productId = order.getProductId();
// 订单支付成功后,给mq发送一条消息,处理nft发行或版权申请的状态
OrderProcessMsg orderProcessMsg = new OrderProcessMsg(out_trade_no, productId, order.getPayScene());
rabbitTemplate.convertAndSend("order-exchange", "order.process", orderProcessMsg);
// 修改订单状态 // 修改订单状态
orderService.updateOrderStatus(out_trade_no, OrderStatus.PAYED); orderService.updateOrderStatus(out_trade_no, OrderStatus.PAYED);
// 插入支付流水记录 // 插入支付流水记录
...@@ -204,6 +204,11 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -204,6 +204,11 @@ public class WxPayServiceImpl implements WxPayService {
payment.setSuccessTime(jsonObject.getStr("success_time")); payment.setSuccessTime(jsonObject.getStr("success_time"));
payment.setContent(JSONUtil.toJsonStr(jsonObject)); payment.setContent(JSONUtil.toJsonStr(jsonObject));
paymentService.save(payment); paymentService.save(payment);
// 订单支付成功后,给mq发送一条消息,处理nft发行或版权申请的状态
Integer productId = order.getProductId();
OrderProcessMsg orderProcessMsg = new OrderProcessMsg(out_trade_no, productId, order.getPayScene());
rabbitTemplate.convertAndSend("order-exchange", "order.process", orderProcessMsg);
} }
} finally { } finally {
lock.unlock(); lock.unlock();
...@@ -212,6 +217,7 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -212,6 +217,7 @@ public class WxPayServiceImpl implements WxPayService {
@Override @Override
@Transactional(rollbackFor = Exception.class)
public String queryOrder(Long orderId) throws IOException, InterruptedException { public String queryOrder(Long orderId) throws IOException, InterruptedException {
String url = String.format("https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/%s?mchid=%s", orderId, wxPayProperties.getMchId()); String url = String.format("https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/%s?mchid=%s", orderId, wxPayProperties.getMchId());
HttpGet httpGet = new HttpGet(url); HttpGet httpGet = new HttpGet(url);
...@@ -229,6 +235,7 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -229,6 +235,7 @@ public class WxPayServiceImpl implements WxPayService {
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public Boolean refund(Long orderId, Integer channel) throws IOException, InterruptedException { public Boolean refund(Long orderId, Integer channel) throws IOException, InterruptedException {
boolean result; boolean result;
RLock lock = redisson.getLock("refund-" + orderId); RLock lock = redisson.getLock("refund-" + orderId);
...@@ -238,7 +245,7 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -238,7 +245,7 @@ public class WxPayServiceImpl implements WxPayService {
try { try {
Order order = orderService.getById(orderId); Order order = orderService.getById(orderId);
if (order == null || !order.getOrderStatus().equals(OrderStatus.PAYED.getStatus())) { if (order == null || !order.getOrderStatus().equals(OrderStatus.PAYED.getStatus())) {
throw GlobalException.newException(ResultCode.REFUND_FAILED, "当前订单未支付成功"); throw GlobalException.newException(ResultCode.REFUND_FAILED, "当前订单未支付成功:" + orderId);
} }
// 订单金额=0的时候,直接返回 // 订单金额=0的时候,直接返回
if (order.getFee() <= 0) { if (order.getFee() <= 0) {
...@@ -282,7 +289,7 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -282,7 +289,7 @@ public class WxPayServiceImpl implements WxPayService {
refund.setRefundId(jsonObject.getStr("refund_id")); refund.setRefundId(jsonObject.getStr("refund_id"));
refund.setTransactionId(jsonObject.getStr("transaction_id")); refund.setTransactionId(jsonObject.getStr("transaction_id"));
refund.setUserReceivedAccount(jsonObject.getStr("user_received_account")); refund.setUserReceivedAccount(jsonObject.getStr("user_received_account"));
refund.setRefundStatus(channel); refund.setRefundStatus(RefundStatus.REFUNDING.getStatus());
// 修改订单状态为退款中 // 修改订单状态为退款中
orderService.updateOrderStatus(orderId, OrderStatus.REFUNDING); orderService.updateOrderStatus(orderId, OrderStatus.REFUNDING);
result = true; result = true;
...@@ -295,7 +302,7 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -295,7 +302,7 @@ public class WxPayServiceImpl implements WxPayService {
refund.setId(out_refund_no); refund.setId(out_refund_no);
refund.setFee(order.getFee()); refund.setFee(order.getFee());
refund.setOrderId(orderId); refund.setOrderId(orderId);
refund.setChannel(RefundLaunchChannel.USER.getCode()); refund.setChannel(channel);
refundService.saveOrUpdate(refund); refundService.saveOrUpdate(refund);
// 如果是用户端发起的退款, 失败时则需抛出异常,告知系统管理员退款失败 // 如果是用户端发起的退款, 失败时则需抛出异常,告知系统管理员退款失败
if (RefundLaunchChannel.USER.getCode().equals(channel)) { if (RefundLaunchChannel.USER.getCode().equals(channel)) {
...@@ -309,6 +316,7 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -309,6 +316,7 @@ public class WxPayServiceImpl implements WxPayService {
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public Boolean notifyRefund(HttpServletRequest request) { public Boolean notifyRefund(HttpServletRequest request) {
try { try {
String requestBodyData = this.getRequestBodyData(request); String requestBodyData = this.getRequestBodyData(request);
...@@ -327,6 +335,7 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -327,6 +335,7 @@ public class WxPayServiceImpl implements WxPayService {
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public void processRefund(JSONObject obj) throws InterruptedException { public void processRefund(JSONObject obj) throws InterruptedException {
Long out_trade_no = obj.getLong("out_trade_no"); Long out_trade_no = obj.getLong("out_trade_no");
Long out_refund_no = obj.getLong("out_refund_no"); Long out_refund_no = obj.getLong("out_refund_no");
......
...@@ -22,6 +22,7 @@ import org.apache.commons.lang3.StringUtils; ...@@ -22,6 +22,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/** /**
* @author tangtuo * @author tangtuo
...@@ -46,10 +47,9 @@ public class NftListener { ...@@ -46,10 +47,9 @@ public class NftListener {
* @param msg * @param msg
*/ */
@RabbitListener(queues = "nft.publish.queue") @RabbitListener(queues = "nft.publish.queue")
@Transactional(rollbackFor = Exception.class)
public void listenNftPublish(NftPublishMsg msg) throws Exception { public void listenNftPublish(NftPublishMsg msg) throws Exception {
if (log.isDebugEnabled()) { log.info("收到确认nft发行结果的消息: {}", msg);
log.debug("收到确认nft发行结果的消息: {}", msg);
}
Nft nft = nftService.getById(msg.getId()); Nft nft = nftService.getById(msg.getId());
User user = userService.getUserByWallet(nft.getPublishAddress()); User user = userService.getUserByWallet(nft.getPublishAddress());
......
...@@ -14,6 +14,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -14,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/** /**
* @author tangtuo * @author tangtuo
...@@ -29,10 +30,9 @@ public class OrderListener { ...@@ -29,10 +30,9 @@ public class OrderListener {
private final WxPayService wxPayService; private final WxPayService wxPayService;
@RabbitListener(queues = "order.process.queue") @RabbitListener(queues = "order.process.queue")
@Transactional(rollbackFor = Exception.class)
public void listenProcessOrder(OrderProcessMsg msg) throws Exception { public void listenProcessOrder(OrderProcessMsg msg) throws Exception {
if (log.isDebugEnabled()) { log.info("收到处理订单的消息: {}", msg);
log.debug("收到处理订单的消息: {}", msg);
}
try { try {
if (PayScene.NFT.getCode().equals(msg.getPayScene())) { if (PayScene.NFT.getCode().equals(msg.getPayScene())) {
...@@ -43,8 +43,7 @@ public class OrderListener { ...@@ -43,8 +43,7 @@ public class OrderListener {
copyrightApplyService.updateRegisterState(msg.getProductId(), CopyrightApplyState.TO_BE_REVIEWED.getCode()); copyrightApplyService.updateRegisterState(msg.getProductId(), CopyrightApplyState.TO_BE_REVIEWED.getCode());
} }
} catch (Exception e) { } catch (Exception e) {
// 处理失败,需要主动发起退款 log.error("nft发行时发生异常", e);
wxPayService.refund(msg.getOrderId(), RefundLaunchChannel.USER.getCode());
// nft发行时发生异常,则需要把nft的状态改成发行失败 // nft发行时发生异常,则需要把nft的状态改成发行失败
if (msg.getPayScene().equals(PayScene.NFT.getCode())) { if (msg.getPayScene().equals(PayScene.NFT.getCode())) {
Nft nft = new Nft(); Nft nft = new Nft();
...@@ -52,6 +51,8 @@ public class OrderListener { ...@@ -52,6 +51,8 @@ public class OrderListener {
nft.setPublishStatus(PublishStatus.FAILED.getCode()); nft.setPublishStatus(PublishStatus.FAILED.getCode());
nftService.updateById(nft); nftService.updateById(nft);
} }
// 处理失败,需要主动发起退款
wxPayService.refund(msg.getOrderId(), RefundLaunchChannel.USER.getCode());
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment