This commit is contained in:
2023-08-30 11:18:58 +08:00
4 changed files with 1885 additions and 1757 deletions

View File

@@ -28,6 +28,7 @@ import com.jsowell.common.core.domain.entity.SysDictData;
import com.jsowell.common.core.domain.ykc.LoginRequestData;
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.AcquirerEnum;
import com.jsowell.common.enums.DelFlagEnum;
import com.jsowell.common.enums.ykc.*;
import com.jsowell.common.exception.BusinessException;
@@ -54,6 +55,8 @@ import com.jsowell.pile.transaction.service.TransactionService;
import com.jsowell.pile.util.SnUtils;
import com.jsowell.pile.vo.base.PileInfoVO;
import com.jsowell.pile.vo.uniapp.MemberVO;
import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO;
import com.jsowell.pile.vo.uniapp.SendMessageVO;
import com.jsowell.pile.vo.web.BalanceDeductionAmountVO;
import com.jsowell.pile.vo.web.BillingTemplateVO;
import com.jsowell.pile.vo.web.OrderListVO;
@@ -217,40 +220,155 @@ public class SpringBootTestController {
@Autowired
private TransactionService transactionService;
@Autowired
private OrderPayRecordService orderPayRecordService;
/**
* 单元测试,测试订单流程
*/
@Test
public void testTheOrderProcess() {
public void testTheOrderProcess() throws Exception {
// 生成订单
OrderBasicInfo orderBasicInfo = generateAnOrder();
// 支付订单
PayOrderDTO dto = new PayOrderDTO();
payOrder(dto);
// OrderBasicInfo orderBasicInfo = generateAnOrder();
// System.out.println(orderBasicInfo);
// // 支付订单
// int a = payOrder(orderBasicInfo);
// System.out.println(a);
// 结算订单
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode("C46006767636");
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() {
OrderBasicInfo orderBasicInfo = new OrderBasicInfo();
OrderDetail detail = new OrderDetail();
// 生成订单
private OrderBasicInfo generateAnOrder() throws ParseException {
GenerateOrderDTO dto = new GenerateOrderDTO();
PileConnectorDetailVO vo = new PileConnectorDetailVO();
vo.setStationId("2");
dto.setPileConnector(vo);
dto.setMemberId("1");
dto.setStartMode("1");
dto.setPayMode("4");
dto.setPileSn("88000000000001");
dto.setConnectorCode("01");
dto.setChargeAmount(new BigDecimal("10"));
// 查询充电桩的计费模板
BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(dto.getPileSn());
dto.setBillingTemplate(billingTemplateVO);
OrderBasicInfo orderBasicInfo = orderBasicInfoService.saveOrder2Database(dto);
OrderTransactionDTO dto = new OrderTransactionDTO();
dto.setOrderBasicInfo(orderBasicInfo);
dto.setOrderDetail(detail);
transactionService.doCreateOrder(dto);
return orderBasicInfo;
}
private OrderBasicInfo payOrder(PayOrderDTO dto) {
return null;
// 支付订单
private int payOrder(OrderBasicInfo orderBasicInfo) throws Exception {
// PayOrderDTO dto = new PayOrderDTO();
// dto.setMemberId(orderBasicInfo.getMemberId());
// dto.setOrderCode(orderBasicInfo.getOrderCode());
// dto.setStartMode(orderBasicInfo.getStartMode());
// dto.setPayMode(orderBasicInfo.getPayMode());
// dto.setPayAmount(orderBasicInfo.getPayAmount());
//
// Map<String, Object> map = orderBasicInfoService.payOrder(dto);
// return map;
String paymentId = "1234";
BigDecimal amount = orderBasicInfo.getPayAmount();
String orderCode = orderBasicInfo.getOrderCode();
JSONObject json = new JSONObject();
json.put("paymentId", paymentId);
json.put("amount", amount);
// 记录订单支付流水
OrderPayRecord orderPayRecord = OrderPayRecord.builder()
.orderCode(orderCode)
.payMode(OrderPayRecordEnum.WECHATPAY_PAYMENT.getValue())
.payAmount(amount)
.acquirer(AcquirerEnum.ADAPAY.getValue())
.deductionRecord(json.toJSONString())
.createBy(null)
.build();
orderPayRecordService.batchInsert(Lists.newArrayList(orderPayRecord));
// 更新冻结金额 支付成功后全部冻结
memberAdapayRecordService.updateFreezeAmount(paymentId, amount);
// 支付订单成功
PayOrderSuccessCallbackDTO callbackDTO = PayOrderSuccessCallbackDTO.builder()
.orderCode(orderCode)
.payAmount(amount)
.payMode(OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())
.acquirer(AcquirerEnum.ADAPAY.getValue())
.build();
// 订单支付成功 支付回调
// orderBasicInfoService.payOrderSuccessCallback(callbackDTO);
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(callbackDTO.getOrderCode());
// 修改订单
orderInfo.setPayMode(callbackDTO.getPayMode());
orderInfo.setPayStatus(Constants.ONE);
orderInfo.setPayAmount(callbackDTO.getPayAmount());
orderInfo.setPayTime(new Date());
orderInfo.setChargeStartTime(new Date());
orderInfo.setOrderStatus(OrderStatusEnum.IN_THE_CHARGING.getValue());
return orderBasicInfoService.updateOrderBasicInfo(orderInfo);
}
// 结算订单
private void settleOrder(OrderBasicInfo orderBasicInfo) {
TransactionRecordsData data = TransactionRecordsData.builder()
.transactionCode(orderBasicInfo.getTransactionCode())
.pileSn(orderBasicInfo.getPileSn())
.connectorCode(orderBasicInfo.getConnectorCode())
.startTime("2023-03-10 17:10:24")
.endTime("2023-03-10 17:10:46")
.sharpPrice("1.10000")
.sharpUsedElectricity("2.0000")
.sharpAmount("2.2000")
.peakPrice("1.20000")
.peakUsedElectricity("0")
.peakAmount("0")
.flatPrice("1.30000")
.flatUsedElectricity("0")
.flatAmount("0")
.valleyPrice("1.40000")
.valleyUsedElectricity("0")
.valleyAmount("0")
.totalElectricity("2")
.consumptionAmount("5.3000")
.vinCode("\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000")
.transactionIdentifier("01")
.transactionTime("2023-03-10 17:10:46")
.stopReasonMsg("结束充电APP远程停止")
.logicCard("0")
.createTime(new Date())
.build();
// 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);
}
/**
* 测试多笔支付情况,解冻部分金额
*/
@@ -1099,7 +1217,7 @@ public class SpringBootTestController {
length = 17;
byte[] vinCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String vinCode = BytesUtil.ascii2Str(vinCodeByteArr);
System.out.println("桩号:" + pileSn +"申请充电VIN码:" + vinCode);
System.out.println("桩号:" + pileSn + "申请充电VIN码:" + vinCode);
/**
* 刷卡启动充电
@@ -1135,15 +1253,15 @@ public class SpringBootTestController {
accountBalanceByteArr = YKCUtils.getPriceByte(String.valueOf(map.get("accountBalance")), 2);
// 鉴权成功标识 0x00 失败 0x01 成功
authenticationFlagByteArr = Constants.oneByteArray;
}else {
} else {
throw new BusinessException("", "生成vin订单失败");
}
}
}catch (BusinessException e){
} catch (BusinessException e) {
e.printStackTrace();
System.out.println("1");
// log.error("VIN码启动充电鉴权 error:{}, {}", e.getCode(), e.getMessage());
}catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
System.out.println("2");
transactionCode = "00000000000000000000000000000000";
@@ -1944,7 +2062,7 @@ public class SpringBootTestController {
}
@Test
public void testGetMemberToken(){
public void testGetMemberToken() {
String memberId = JWTUtils.getMemberId("eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NzY1MTY5MzgsImV4cCI6MTY3OTEwODkzOH0.4MwhZIOpnCfQloR7zEm2hwPOh2yyI2qxbBbTcv_SnZ4");
System.out.println(memberId);
}

View File

@@ -78,4 +78,9 @@ public class GenerateOrderDTO extends BasicPileDTO{
* 车牌号码
*/
private String plateNumber;
/**
* 站点id
*/
private String stationId;
}

View File

@@ -58,6 +58,8 @@ public interface IOrderBasicInfoService {
*/
List<OrderListVO> selectChargingOrder(String pileSn);
public OrderBasicInfo saveOrder2Database(GenerateOrderDTO dto) throws ParseException;
/**
* 修改订单
*
@@ -337,4 +339,7 @@ public interface IOrderBasicInfoService {
*/
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对象
* 专用方法,其他地方如果要用请仔细检查
*/
private void returnUpdateOrderBasicInfo(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) {
public void returnUpdateOrderBasicInfo(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) {
// 订单编号
String orderCode = orderBasicInfo.getOrderCode();
// 消费金额就是订单总金额/交易记录传过来的消费金额
@@ -929,7 +929,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
*
* @return 查询并更新过数据的orderDetail
*/
private OrderDetail returnUpdateOrderDetail(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) {
public OrderDetail returnUpdateOrderDetail(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) {
String orderCode = orderBasicInfo.getOrderCode();
BigDecimal orderAmount = orderBasicInfo.getOrderAmount();
// 更新订单详情 查询订单详情 修改订单数据
@@ -3250,7 +3250,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
* @param dto
* @return
*/
private OrderBasicInfo saveOrder2Database(GenerateOrderDTO dto) throws ParseException {
public OrderBasicInfo saveOrder2Database(GenerateOrderDTO dto) throws ParseException {
String orderCode = generateNewOrderCode();
String transactionCode = IdUtils.generateTransactionCode(dto.getPileSn(), dto.getConnectorCode());