支付改造

pull/4/head
zhuyang 2021-10-09 22:23:15 +08:00
parent 001892824c
commit af8f9745e9
13 changed files with 181 additions and 124 deletions

View File

@ -7,7 +7,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc"})
@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc","cn.iocoder.mall.payservice.rpc"})
public class ManagementWebApplication {
public static void main(String[] args) {

View File

@ -2,20 +2,20 @@ package cn.iocoder.mall.managementweb.client.pay.transaction;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionRpc;
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionFeign;
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionPageReqDTO;
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionRespDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class PayTransactionClient {
@DubboReference(version = "${dubbo.consumer.PayTransactionRpc.version}")
private PayTransactionRpc payTransactionRpc;
@Autowired
private PayTransactionFeign payTransactionFeign;
public PageResult<PayTransactionRespDTO> pagePayTransaction(PayTransactionPageReqDTO pageReqDTO) {
CommonResult<PageResult<PayTransactionRespDTO>> pagePayTransactionResult = payTransactionRpc.pagePayTransaction(pageReqDTO);
CommonResult<PageResult<PayTransactionRespDTO>> pagePayTransactionResult = payTransactionFeign.pagePayTransaction(pageReqDTO);
pagePayTransactionResult.checkError();
return pagePayTransactionResult.getData();
}

View File

@ -31,5 +31,9 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,63 @@
package cn.iocoder.mall.payservice.rpc.transaction;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.payservice.rpc.transaction.dto.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
* Title:
* Description:
*
* @author zhuyang
* @version 1.0 2021/10/9
*/
@FeignClient(value = "pay-service")
public interface PayTransactionFeign {
/**
*
*
* @param createReqDTO
* @return
*/
@PostMapping("/pay/transaction/createPayTransaction")
CommonResult<Integer> createPayTransaction(@RequestBody PayTransactionCreateReqDTO createReqDTO);
/**
*
*
* @param submitReqDTO
* @return
*/
@PostMapping("/pay/transaction/submitPayTransaction")
CommonResult<PayTransactionSubmitRespDTO> submitPayTransaction(@RequestBody PayTransactionSubmitReqDTO submitReqDTO);
/**
*
*
* @param getReqDTO
* @return
*/
@PostMapping("/pay/transaction/getPayTransaction")
CommonResult<PayTransactionRespDTO> getPayTransaction(@RequestBody PayTransactionGetReqDTO getReqDTO);
/**
*
*
* @param successReqDTO
* @return
*/
@PostMapping("/pay/transaction/updatePayTransactionSuccess")
CommonResult<Boolean> updatePayTransactionSuccess(@RequestBody PayTransactionSuccessReqDTO successReqDTO);
/**
*
*
* @param pageReqDTO
* @return
*/
@PostMapping("/pay/transaction/pagePayTransaction")
CommonResult<PageResult<PayTransactionRespDTO>> pagePayTransaction(@RequestBody PayTransactionPageReqDTO pageReqDTO);
}

View File

@ -1,52 +0,0 @@
package cn.iocoder.mall.payservice.rpc.transaction;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.payservice.rpc.transaction.dto.*;
/**
* RPC
*/
public interface PayTransactionRpc {
/**
*
*
* @param createReqDTO
* @return
*/
CommonResult<Integer> createPayTransaction(PayTransactionCreateReqDTO createReqDTO);
/**
*
*
* @param submitReqDTO
* @return
*/
CommonResult<PayTransactionSubmitRespDTO> submitPayTransaction(PayTransactionSubmitReqDTO submitReqDTO);
/**
*
*
* @param getReqDTO
* @return
*/
CommonResult<PayTransactionRespDTO> getPayTransaction(PayTransactionGetReqDTO getReqDTO);
/**
*
*
* @param successReqDTO
* @return
*/
CommonResult<Boolean> updatePayTransactionSuccess(PayTransactionSuccessReqDTO successReqDTO);
/**
*
*
* @param pageReqDTO
* @return
*/
CommonResult<PageResult<PayTransactionRespDTO>> pagePayTransaction(PayTransactionPageReqDTO pageReqDTO);
}

View File

@ -2,8 +2,12 @@ package cn.iocoder.mall.payservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class PayServiceApplication {
public static void main(String[] args) {

View File

@ -1,44 +0,0 @@
package cn.iocoder.mall.payservice.rpc.transaction;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.payservice.rpc.transaction.dto.*;
import cn.iocoder.mall.payservice.service.transaction.PayTransactionService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@DubboService
public class PayTransactionRpcImpl implements PayTransactionRpc {
@Autowired
private PayTransactionService payTransactionService;
@Override
public CommonResult<Integer> createPayTransaction(PayTransactionCreateReqDTO createReqDTO) {
return success(payTransactionService.createPayTransaction(createReqDTO));
}
@Override
public CommonResult<PayTransactionSubmitRespDTO> submitPayTransaction(PayTransactionSubmitReqDTO submitReqDTO) {
return success(payTransactionService.submitPayTransaction(submitReqDTO));
}
@Override
public CommonResult<PayTransactionRespDTO> getPayTransaction(PayTransactionGetReqDTO getReqDTO) {
return success(payTransactionService.getPayTransaction(getReqDTO));
}
@Override
public CommonResult<Boolean> updatePayTransactionSuccess(PayTransactionSuccessReqDTO successReqDTO) {
return success(payTransactionService.updateTransactionPaySuccess(successReqDTO.getPayChannel(),
successReqDTO.getParams()));
}
@Override
public CommonResult<PageResult<PayTransactionRespDTO>> pagePayTransaction(PayTransactionPageReqDTO pageReqDTO) {
return success(payTransactionService.pagePayTransaction(pageReqDTO));
}
}

View File

@ -0,0 +1,81 @@
package controller;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.payservice.rpc.transaction.dto.*;
import cn.iocoder.mall.payservice.service.transaction.PayTransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* Title:
* Description:
*
* @author zhuyang
* @version 1.0 2021/10/9
*/
@RestController
@RequestMapping("/pay/transaction")
public class PayTransactionController {
@Autowired
private PayTransactionService payTransactionService;
/**
*
*
* @param createReqDTO
* @return
*/
@PostMapping("createPayTransaction")
CommonResult<Integer> createPayTransaction(@RequestBody PayTransactionCreateReqDTO createReqDTO){
return success(payTransactionService.createPayTransaction(createReqDTO));
}
/**
*
*
* @param submitReqDTO
* @return
*/
@PostMapping("submitPayTransaction")
CommonResult<PayTransactionSubmitRespDTO> submitPayTransaction(@RequestBody PayTransactionSubmitReqDTO submitReqDTO){
return success(payTransactionService.submitPayTransaction(submitReqDTO));
}
/**
*
*
* @param getReqDTO
* @return
*/
@PostMapping("getPayTransaction")
CommonResult<PayTransactionRespDTO> getPayTransaction(@RequestBody PayTransactionGetReqDTO getReqDTO){
return success(payTransactionService.getPayTransaction(getReqDTO));}
/**
*
*
* @param successReqDTO
* @return
*/
@PostMapping("updatePayTransactionSuccess")
CommonResult<Boolean> updatePayTransactionSuccess(@RequestBody PayTransactionSuccessReqDTO successReqDTO){
return success(payTransactionService.updateTransactionPaySuccess(successReqDTO.getPayChannel(),
successReqDTO.getParams()));}
/**
*
*
* @param pageReqDTO
* @return
*/
@PostMapping("pagePayTransaction")
CommonResult<PageResult<PayTransactionRespDTO>> pagePayTransaction(@RequestBody PayTransactionPageReqDTO pageReqDTO){
return success(payTransactionService.pagePayTransaction(pageReqDTO));}
}

View File

@ -8,7 +8,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc","cn.iocoder.mall.searchservice.rpc",
"cn.iocoder.mall.tradeservice.rpc"})
"cn.iocoder.mall.tradeservice.rpc","cn.iocoder.mall.payservice.rpc"})
public class ShopWebApplication {
public static void main(String[] args) {

View File

@ -1,9 +1,9 @@
package cn.iocoder.mall.shopweb.client.pay;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionRpc;
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionFeign;
import cn.iocoder.mall.payservice.rpc.transaction.dto.*;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
@ -11,11 +11,12 @@ import java.util.Objects;
@Service
public class PayTransactionClient {
@DubboReference(version = "${dubbo.consumer.PayTransactionRpc.version}")
private PayTransactionRpc payTransactionRpc;
@Autowired
private PayTransactionFeign payTransactionFeign;
public PayTransactionRespDTO getPayTransaction(Integer userId, String appId, String orderId) {
CommonResult<PayTransactionRespDTO> getPayTransactionResult = payTransactionRpc.getPayTransaction(new PayTransactionGetReqDTO()
CommonResult<PayTransactionRespDTO> getPayTransactionResult = payTransactionFeign.getPayTransaction(new PayTransactionGetReqDTO()
.setAppId(appId).setOrderId(orderId));
getPayTransactionResult.checkError();
if (getPayTransactionResult.getData() == null) {
@ -27,13 +28,13 @@ public class PayTransactionClient {
}
public PayTransactionSubmitRespDTO submitPayTransaction(PayTransactionSubmitReqDTO submitReqDTO) {
CommonResult<PayTransactionSubmitRespDTO> submitPayTransactionResult = payTransactionRpc.submitPayTransaction(submitReqDTO);
CommonResult<PayTransactionSubmitRespDTO> submitPayTransactionResult = payTransactionFeign.submitPayTransaction(submitReqDTO);
submitPayTransactionResult.checkError();
return submitPayTransactionResult.getData();
}
public void updatePayTransactionSuccess(Integer payChannel, String params) {
CommonResult<Boolean> updatePayTransactionSuccessResult = payTransactionRpc.updatePayTransactionSuccess(
CommonResult<Boolean> updatePayTransactionSuccessResult = payTransactionFeign.updatePayTransactionSuccess(
new PayTransactionSuccessReqDTO().setPayChannel(payChannel).setParams(params));
updatePayTransactionSuccessResult.checkError();
}

View File

@ -25,7 +25,7 @@ public interface CartFeign {
* @param addReqDTO
* @return
*/
@PostMapping("addCartItem")
@PostMapping("/trade/cart/addCartItem")
CommonResult<Boolean> addCartItem(@RequestBody CartItemAddReqDTO addReqDTO);
/**
@ -34,7 +34,7 @@ public interface CartFeign {
* @param updateQuantityReqDTO DTO
* @return
*/
@PostMapping("updateCartItemQuantity")
@PostMapping("/trade/cart/updateCartItemQuantity")
CommonResult<Boolean> updateCartItemQuantity(@RequestBody CartItemUpdateQuantityReqDTO updateQuantityReqDTO);
/**
@ -43,7 +43,7 @@ public interface CartFeign {
* @param updateSelectedReqDTO DTO
* @return
*/
@PostMapping("updateCartItemSelected")
@PostMapping("/trade/cart/updateCartItemSelected")
CommonResult<Boolean> updateCartItemSelected(@RequestBody CartItemUpdateSelectedReqDTO updateSelectedReqDTO);
/**
@ -52,10 +52,10 @@ public interface CartFeign {
* @param deleteListReqDTO DTO
* @return
*/
@PostMapping("deleteCartItems")
@PostMapping("/trade/cart/deleteCartItems")
CommonResult<Boolean> deleteCartItems(@RequestBody CartItemDeleteListReqDTO deleteListReqDTO);
@GetMapping("/sumCartItemQuantity")
public CommonResult<Integer> sumCartItemQuantity(@RequestParam("userId") Integer userId) ;
@PostMapping("/listCartItems")
@PostMapping("/trade/cart/listCartItems")
public CommonResult<List<CartItemRespDTO>> listCartItems(@RequestBody CartItemListReqDTO listReqDTO) ;
}

View File

@ -29,7 +29,7 @@ public interface TradeOrderFeign {
* @param createReqDTO
* @return
*/
@PostMapping("createTradeOrder")
@PostMapping("/trade/order/createTradeOrder")
CommonResult<Integer> createTradeOrder(@RequestBody TradeOrderCreateReqDTO createReqDTO);
/**
@ -39,7 +39,7 @@ public interface TradeOrderFeign {
* @param fields {@link cn.iocoder.mall.tradeservice.enums.order.TradeOrderDetailFieldEnum}
* @return
*/
@GetMapping("getTradeOrder")
@GetMapping("/trade/order/getTradeOrder")
CommonResult<TradeOrderRespDTO> getTradeOrder(@RequestParam("tradeOrderId")Integer tradeOrderId, @RequestParam("fields") Collection<String> fields);
/**
*
@ -47,7 +47,7 @@ public interface TradeOrderFeign {
* @param pageDTO
* @return
*/
@PostMapping("pageTradeOrder")
@PostMapping("/trade/order/pageTradeOrder")
CommonResult<PageResult<TradeOrderRespDTO>> pageTradeOrder(@RequestBody TradeOrderPageReqDTO pageDTO);
// TODO 芋艿:需要重构成入参是 DTO方便后续升级返回是 CommonResult用于返回失败的原因
@ -60,6 +60,6 @@ public interface TradeOrderFeign {
* @param payAmount
* @return
*/
@PostMapping("updateTradeOrderPaySuccess")
@PostMapping("/trade/order/updateTradeOrderPaySuccess")
CommonResult<Boolean> updateTradeOrderPaySuccess(@RequestParam("tradeOrderId") String tradeOrderId, @RequestParam("payAmount")Integer payAmount);
}

View File

@ -1,19 +1,19 @@
package cn.iocoder.mall.tradeservice.client.pay;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionRpc;
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionFeign;
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionCreateReqDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class PayTransactionClient {
@DubboReference(version = "${dubbo.consumer.PayTransactionRpc.version}")
private PayTransactionRpc payTransactionRpc;
@Autowired
private PayTransactionFeign payTransactionFeign;
public Integer createPayTransaction(PayTransactionCreateReqDTO createReqDTO) {
CommonResult<Integer> createPayTransactionResult = payTransactionRpc.createPayTransaction(createReqDTO);
CommonResult<Integer> createPayTransactionResult = payTransactionFeign.createPayTransaction(createReqDTO);
createPayTransactionResult.checkError();
return createPayTransactionResult.getData();
}