单元测试 在线支付订单、退款

This commit is contained in:
Lemon
2023-08-30 11:02:18 +08:00
parent 6ae0503956
commit 39087d9b10
3 changed files with 1887 additions and 1865 deletions

View File

@@ -231,23 +231,32 @@ public class SpringBootTestController {
// 生成订单 // 生成订单
// OrderBasicInfo orderBasicInfo = generateAnOrder(); // OrderBasicInfo orderBasicInfo = generateAnOrder();
// System.out.println(orderBasicInfo); // System.out.println(orderBasicInfo);
// 支付订单 // // 支付订单
// int a = payOrder(orderBasicInfo); // int a = payOrder(orderBasicInfo);
// System.out.println(a); // System.out.println(a);
// 结算订单 // 结算订单
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode("C65033300551"); OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode("C46006767636");
settleOrder(orderBasicInfo); settleOrder(orderBasicInfo);
// 订单退款 // 订单退款
BigDecimal payAmount = orderBasicInfo.getPayAmount();
BigDecimal settleAmount = orderBasicInfo.getSettleAmount();
BigDecimal refundAmt = payAmount.subtract(settleAmount);
// 延时分账的,可以部分解冻
memberAdapayRecordService.updateRefundAmountFromFreezeAmount("1234", refundAmt);
// 实时分账,全部解冻
// memberAdapayRecordService.unfreezeAmountAndUpdateSpendAmount("test01", payAmount, refundAmt);
} }
// 生成订单
private OrderBasicInfo generateAnOrder() throws ParseException { private OrderBasicInfo generateAnOrder() throws ParseException {
GenerateOrderDTO dto = new GenerateOrderDTO(); GenerateOrderDTO dto = new GenerateOrderDTO();
PileConnectorDetailVO vo = new PileConnectorDetailVO(); PileConnectorDetailVO vo = new PileConnectorDetailVO();
vo.setStationId("2"); vo.setStationId("2");
dto.setPileConnector(vo); dto.setPileConnector(vo);
dto.setMemberId("67945248"); dto.setMemberId("1");
dto.setStartMode("1"); dto.setStartMode("1");
dto.setPayMode("4"); dto.setPayMode("4");
dto.setPileSn("88000000000001"); dto.setPileSn("88000000000001");
@@ -261,6 +270,7 @@ public class SpringBootTestController {
return orderBasicInfo; return orderBasicInfo;
} }
// 支付订单
private int payOrder(OrderBasicInfo orderBasicInfo) throws Exception { private int payOrder(OrderBasicInfo orderBasicInfo) throws Exception {
// PayOrderDTO dto = new PayOrderDTO(); // PayOrderDTO dto = new PayOrderDTO();
// dto.setMemberId(orderBasicInfo.getMemberId()); // dto.setMemberId(orderBasicInfo.getMemberId());
@@ -271,7 +281,7 @@ public class SpringBootTestController {
// //
// Map<String, Object> map = orderBasicInfoService.payOrder(dto); // Map<String, Object> map = orderBasicInfoService.payOrder(dto);
// return map; // return map;
String paymentId = "test01"; String paymentId = "1234";
BigDecimal amount = orderBasicInfo.getPayAmount(); BigDecimal amount = orderBasicInfo.getPayAmount();
String orderCode = orderBasicInfo.getOrderCode(); String orderCode = orderBasicInfo.getOrderCode();
@@ -315,7 +325,7 @@ public class SpringBootTestController {
} }
// 结算订单
private void settleOrder(OrderBasicInfo orderBasicInfo) { private void settleOrder(OrderBasicInfo orderBasicInfo) {
TransactionRecordsData data = TransactionRecordsData.builder() TransactionRecordsData data = TransactionRecordsData.builder()
.transactionCode(orderBasicInfo.getTransactionCode()) .transactionCode(orderBasicInfo.getTransactionCode())
@@ -346,7 +356,16 @@ public class SpringBootTestController {
.build(); .build();
orderBasicInfoService.settleOrder(data, orderBasicInfo); // orderBasicInfoService.settleOrder(data, orderBasicInfo);
// 获取更新数据后的orderBasicInfo对象
orderBasicInfoService.returnUpdateOrderBasicInfo(orderBasicInfo, data);
// 获取更新数据后的orderDetail对象/更新订单详情 查询订单详情 修改订单数据
OrderDetail orderDetail = orderBasicInfoService.returnUpdateOrderDetail(orderBasicInfo, data);
// 更新数据库
OrderTransactionDTO dto = new OrderTransactionDTO();
dto.setOrderBasicInfo(orderBasicInfo);
dto.setOrderDetail(orderDetail);
transactionService.doUpdateOrder(dto);
} }
@@ -1198,7 +1217,7 @@ public class SpringBootTestController {
length = 17; length = 17;
byte[] vinCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length); byte[] vinCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String vinCode = BytesUtil.ascii2Str(vinCodeByteArr); String vinCode = BytesUtil.ascii2Str(vinCodeByteArr);
System.out.println("桩号:" + pileSn +"申请充电VIN码:" + vinCode); System.out.println("桩号:" + pileSn + "申请充电VIN码:" + vinCode);
/** /**
* 刷卡启动充电 * 刷卡启动充电
@@ -1234,15 +1253,15 @@ public class SpringBootTestController {
accountBalanceByteArr = YKCUtils.getPriceByte(String.valueOf(map.get("accountBalance")), 2); accountBalanceByteArr = YKCUtils.getPriceByte(String.valueOf(map.get("accountBalance")), 2);
// 鉴权成功标识 0x00 失败 0x01 成功 // 鉴权成功标识 0x00 失败 0x01 成功
authenticationFlagByteArr = Constants.oneByteArray; authenticationFlagByteArr = Constants.oneByteArray;
}else { } else {
throw new BusinessException("", "生成vin订单失败"); throw new BusinessException("", "生成vin订单失败");
} }
} }
}catch (BusinessException e){ } catch (BusinessException e) {
e.printStackTrace(); e.printStackTrace();
System.out.println("1"); System.out.println("1");
// log.error("VIN码启动充电鉴权 error:{}, {}", e.getCode(), e.getMessage()); // log.error("VIN码启动充电鉴权 error:{}, {}", e.getCode(), e.getMessage());
}catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
System.out.println("2"); System.out.println("2");
transactionCode = "00000000000000000000000000000000"; transactionCode = "00000000000000000000000000000000";
@@ -2043,7 +2062,7 @@ public class SpringBootTestController {
} }
@Test @Test
public void testGetMemberToken(){ public void testGetMemberToken() {
String memberId = JWTUtils.getMemberId("eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NzY1MTY5MzgsImV4cCI6MTY3OTEwODkzOH0.4MwhZIOpnCfQloR7zEm2hwPOh2yyI2qxbBbTcv_SnZ4"); String memberId = JWTUtils.getMemberId("eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NzY1MTY5MzgsImV4cCI6MTY3OTEwODkzOH0.4MwhZIOpnCfQloR7zEm2hwPOh2yyI2qxbBbTcv_SnZ4");
System.out.println(memberId); System.out.println(memberId);
} }

View File

@@ -339,4 +339,7 @@ public interface IOrderBasicInfoService {
*/ */
void retryRefundOrder(String orderCode) throws BaseAdaPayException; void retryRefundOrder(String orderCode) throws BaseAdaPayException;
void returnUpdateOrderBasicInfo(OrderBasicInfo orderBasicInfo, TransactionRecordsData data);
OrderDetail returnUpdateOrderDetail(OrderBasicInfo orderBasicInfo, TransactionRecordsData data);
} }

View File

@@ -889,7 +889,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
* 返回更新后的OrderBasicInfo对象 * 返回更新后的OrderBasicInfo对象
* 专用方法,其他地方如果要用请仔细检查 * 专用方法,其他地方如果要用请仔细检查
*/ */
private void returnUpdateOrderBasicInfo(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) { public void returnUpdateOrderBasicInfo(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) {
// 订单编号 // 订单编号
String orderCode = orderBasicInfo.getOrderCode(); String orderCode = orderBasicInfo.getOrderCode();
// 消费金额就是订单总金额/交易记录传过来的消费金额 // 消费金额就是订单总金额/交易记录传过来的消费金额
@@ -929,7 +929,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
* *
* @return 查询并更新过数据的orderDetail * @return 查询并更新过数据的orderDetail
*/ */
private OrderDetail returnUpdateOrderDetail(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) { public OrderDetail returnUpdateOrderDetail(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) {
String orderCode = orderBasicInfo.getOrderCode(); String orderCode = orderBasicInfo.getOrderCode();
BigDecimal orderAmount = orderBasicInfo.getOrderAmount(); BigDecimal orderAmount = orderBasicInfo.getOrderAmount();
// 更新订单详情 查询订单详情 修改订单数据 // 更新订单详情 查询订单详情 修改订单数据