Commit c4c9a96b authored by tangtuo's avatar tangtuo

debug

parent aadccc00
...@@ -6,6 +6,7 @@ import com.fzm.common.entity.dto.OrderDto; ...@@ -6,6 +6,7 @@ import com.fzm.common.entity.dto.OrderDto;
import com.fzm.common.entity.vo.OrderVo; import com.fzm.common.entity.vo.OrderVo;
import com.fzm.common.enums.OrderStatus; import com.fzm.common.enums.OrderStatus;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
...@@ -63,4 +64,12 @@ public interface OrderService extends IService<Order> { ...@@ -63,4 +64,12 @@ public interface OrderService extends IService<Order> {
List<OrderVo> listOrder(Integer payScene); List<OrderVo> listOrder(Integer payScene);
void processOrder(Long orderId, Integer productId, Integer payScene); void processOrder(Long orderId, Integer productId, Integer payScene);
/**
* 更新订单状态
*
* @param orderId
* @return
*/
Boolean renewOrderStatus(Long orderId) throws IOException, InterruptedException;
} }
...@@ -35,7 +35,7 @@ public interface WxPayService { ...@@ -35,7 +35,7 @@ public interface WxPayService {
*/ */
void processOrder(JSONObject jsonObject) throws GeneralSecurityException, InterruptedException; void processOrder(JSONObject jsonObject) throws GeneralSecurityException, InterruptedException;
String queryOrder(Long orderId) throws IOException; String queryOrder(Long orderId) throws IOException, InterruptedException;
/** /**
* 退款 * 退款
......
...@@ -6,12 +6,13 @@ import com.fzm.common.entity.Order; ...@@ -6,12 +6,13 @@ import com.fzm.common.entity.Order;
import com.fzm.common.entity.dto.OrderDto; import com.fzm.common.entity.dto.OrderDto;
import com.fzm.common.entity.dto.OrderProcessMsg; import com.fzm.common.entity.dto.OrderProcessMsg;
import com.fzm.common.entity.vo.OrderVo; import com.fzm.common.entity.vo.OrderVo;
import com.fzm.common.enums.OrderStatus; import com.fzm.common.enums.*;
import com.fzm.common.enums.PayScene; import com.fzm.common.exception.GlobalException;
import com.fzm.common.mapper.OrderMapper; import com.fzm.common.mapper.OrderMapper;
import com.fzm.common.service.CopyrightApplyService; import com.fzm.common.service.CopyrightApplyService;
import com.fzm.common.service.NftService; import com.fzm.common.service.NftService;
import com.fzm.common.service.OrderService; import com.fzm.common.service.OrderService;
import com.fzm.common.service.WxPayService;
import com.fzm.common.utils.JwtUtil; import com.fzm.common.utils.JwtUtil;
import com.fzm.common.utils.SnowflakeUtil; import com.fzm.common.utils.SnowflakeUtil;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
...@@ -20,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -20,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -49,6 +51,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements ...@@ -49,6 +51,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
@Resource @Resource
private OrderMapper orderMapper; private OrderMapper orderMapper;
@Resource
private WxPayService wxPayService;
@Override @Override
public Order getByPaySceneAndProductId(Integer payScene, Integer productId, Integer orderStatus) { public Order getByPaySceneAndProductId(Integer payScene, Integer productId, Integer orderStatus) {
QueryWrapper<Order> queryWrapper = new QueryWrapper<>(); QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
...@@ -135,4 +140,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements ...@@ -135,4 +140,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
OrderProcessMsg orderProcessMsg = new OrderProcessMsg(orderId, productId, payScene); OrderProcessMsg orderProcessMsg = new OrderProcessMsg(orderId, productId, payScene);
rabbitTemplate.convertAndSend("order-exchange", "order.process", orderProcessMsg); rabbitTemplate.convertAndSend("order-exchange", "order.process", orderProcessMsg);
} }
@Override
public Boolean renewOrderStatus(Long orderId) throws IOException, InterruptedException {
Order order = this.getById(orderId);
if (order == null) {
throw GlobalException.newException(ResultCode.DATA_ERROR, "unknown orderId: " + orderId);
}
if (PayType.WXPAY.getCode().equals(order.getPayType())) {
wxPayService.queryOrder(orderId);
}
return true;
}
} }
...@@ -193,10 +193,10 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -193,10 +193,10 @@ public class WxPayServiceImpl implements WxPayService {
if (lock.tryLock(10, TimeUnit.SECONDS)) { if (lock.tryLock(10, TimeUnit.SECONDS)) {
Order order = orderService.getById(out_trade_no); Order order = orderService.getById(out_trade_no);
// 如果订单状态不是待支付,直接返回 // 如果订单状态不是待支付,直接返回
if (!OrderStatus.PAYING.getStatus().equals(order.getOrderStatus())) { // if (!OrderStatus.PAYING.getStatus().equals(order.getOrderStatus())) {
log.warn("当前订单已处理完成, 订单号:==> {}", out_trade_no); // log.warn("当前订单已处理完成, 订单号:==> {}", out_trade_no);
return; // return;
} // }
Integer productId = order.getProductId(); Integer productId = order.getProductId();
// 订单支付成功后,给mq发送一条消息,处理nft发行或版权申请的状态 // 订单支付成功后,给mq发送一条消息,处理nft发行或版权申请的状态
OrderProcessMsg orderProcessMsg = new OrderProcessMsg(out_trade_no, productId, order.getPayScene()); OrderProcessMsg orderProcessMsg = new OrderProcessMsg(out_trade_no, productId, order.getPayScene());
...@@ -220,7 +220,7 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -220,7 +220,7 @@ public class WxPayServiceImpl implements WxPayService {
@Override @Override
public String queryOrder(Long orderId) throws IOException { 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);
httpGet.setHeader("Accept", "application/json"); httpGet.setHeader("Accept", "application/json");
...@@ -229,6 +229,10 @@ public class WxPayServiceImpl implements WxPayService { ...@@ -229,6 +229,10 @@ public class WxPayServiceImpl implements WxPayService {
String result = EntityUtils.toString(response.getEntity()); String result = EntityUtils.toString(response.getEntity());
log.info("查询微信支付订单状态, 当前订单号: {}, 返回结果:{}", orderId, result); log.info("查询微信支付订单状态, 当前订单号: {}, 返回结果:{}", orderId, result);
JSONObject jsonObject = JSONUtil.parseObj(result); JSONObject jsonObject = JSONUtil.parseObj(result);
// 支付成功
if (WxPayStatus.SUCCESS.getStatus().equals(jsonObject.getStr("trade_state"))) {
processOrder(jsonObject);
}
return jsonObject.getStr("trade_state"); return jsonObject.getStr("trade_state");
} }
......
...@@ -12,6 +12,7 @@ import io.swagger.annotations.ApiOperation; ...@@ -12,6 +12,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
...@@ -58,5 +59,10 @@ public class OrderController { ...@@ -58,5 +59,10 @@ public class OrderController {
return ResponseModel.success(orders); return ResponseModel.success(orders);
} }
@PostMapping("/renew-order-status")
@ApiOperation("更新订单状态")
public ResponseModel<Boolean> renewOrderStatus(@RequestParam Long orderId) throws IOException, InterruptedException {
return ResponseModel.success(orderService.renewOrderStatus(orderId));
}
} }
This diff is collapsed.
This diff is collapsed.
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