Commit 8f56bd20 authored by 33's avatar 33

更新日志

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