mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
819 lines
32 KiB
Java
819 lines
32 KiB
Java
import com.alibaba.fastjson2.JSON;
|
||
import com.alibaba.fastjson2.JSONArray;
|
||
import com.alibaba.fastjson2.JSONObject;
|
||
import com.github.pagehelper.PageHelper;
|
||
import com.google.common.collect.Lists;
|
||
import com.google.common.collect.Maps;
|
||
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||
import com.huifu.adapay.model.Payment;
|
||
import com.huifu.adapay.model.PaymentReverse;
|
||
import com.huifu.adapay.model.Refund;
|
||
import com.jsowell.JsowellApplication;
|
||
import com.jsowell.adapay.common.PaymentConfirmInfo;
|
||
import com.jsowell.adapay.dto.PaymentConfirmParam;
|
||
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
|
||
import com.jsowell.adapay.operation.PaymentReverseOperation;
|
||
import com.jsowell.adapay.response.PaymentConfirmResponse;
|
||
import com.jsowell.adapay.response.PaymentReverseResponse;
|
||
import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse;
|
||
import com.jsowell.adapay.service.AdapayService;
|
||
import com.jsowell.adapay.vo.AdapayCorpMemberVO;
|
||
import com.jsowell.adapay.vo.OrderSplitResult;
|
||
import com.jsowell.api.uniapp.customer.TempController;
|
||
import com.jsowell.common.constant.CacheConstants;
|
||
import com.jsowell.common.core.redis.RedisCache;
|
||
import com.jsowell.common.enums.ykc.ScenarioEnum;
|
||
import com.jsowell.common.util.DateUtils;
|
||
import com.jsowell.pile.domain.OrderBasicInfo;
|
||
import com.jsowell.pile.domain.OrderDetail;
|
||
import com.jsowell.pile.domain.OrderUnsplitRecord;
|
||
import com.jsowell.pile.dto.AfterSettleOrderDTO;
|
||
import com.jsowell.pile.dto.DebugOrderDTO;
|
||
import com.jsowell.pile.service.AdapayUnsplitRecordService;
|
||
import com.jsowell.pile.service.OrderBasicInfoService;
|
||
import com.jsowell.pile.service.OrderUnsplitRecordService;
|
||
import com.jsowell.pile.vo.AdapayUnsplitRecordVO;
|
||
import org.apache.commons.collections4.CollectionUtils;
|
||
import org.junit.Test;
|
||
import org.junit.runner.RunWith;
|
||
import org.slf4j.Logger;
|
||
import org.slf4j.LoggerFactory;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.boot.test.context.SpringBootTest;
|
||
import org.springframework.scheduling.annotation.Scheduled;
|
||
import org.springframework.test.context.ActiveProfiles;
|
||
import org.springframework.test.context.junit4.SpringRunner;
|
||
import org.springframework.util.StopWatch;
|
||
|
||
import java.io.BufferedReader;
|
||
import java.io.FileReader;
|
||
import java.io.IOException;
|
||
import java.math.BigDecimal;
|
||
import java.util.*;
|
||
import java.util.concurrent.TimeUnit;
|
||
|
||
/**
|
||
* 专用处理汇付支付相关
|
||
*/
|
||
@ActiveProfiles("dev")
|
||
@SpringBootTest(classes = JsowellApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||
@RunWith(SpringRunner.class)
|
||
public class PaymentTestController {
|
||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||
String wechatAppId1 = "wxbb3e0d474569481d"; // 万车充
|
||
|
||
String wechatAppId2 = "wx20abc5210391649c"; // 嘉佳充电
|
||
|
||
String adapayAppId = "app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa"; // 固定参数, 汇付配置的万车充小程序appId
|
||
|
||
@Autowired
|
||
private RedisCache redisCache;
|
||
|
||
@Autowired
|
||
private OrderUnsplitRecordService orderUnsplitRecordService;
|
||
|
||
@Autowired
|
||
private AdapayService adapayService;
|
||
|
||
@Autowired
|
||
private OrderBasicInfoService orderBasicInfoService;
|
||
|
||
@Autowired
|
||
private AdapayUnsplitRecordService adapayUnsplitRecordService;
|
||
|
||
/**
|
||
* 从payment_ids文件中获取支付id, 并批量查询分账信息
|
||
* 如需撤销分账, 请使用 {@link PaymentTestController#testCreateConfirmReverse()} 可以本地运行
|
||
* 如需重新分账, 请使用 {@link TempController#debugOrder(DebugOrderDTO)} 需要使用ApiPost调用pre环境接口
|
||
*/
|
||
@Test
|
||
public void queryCreateConfirmReverseNew() throws BaseAdaPayException {
|
||
StopWatch stopWatch = new StopWatch("批量查询分账信息");
|
||
List<String> paymentIdList = getPaymentIdList(); // 查询分账信息
|
||
stopWatch.start();
|
||
Map<String, List<String>> splitInfoMap = adapayService.getSplitInfoMapByPaymentIdList(paymentIdList);
|
||
stopWatch.stop();
|
||
System.out.println("耗时:" + stopWatch.getLastTaskTimeMillis() + ", splitInfoMap:" + JSON.toJSONString(splitInfoMap));
|
||
}
|
||
|
||
/**
|
||
* 获取支付idList
|
||
* @return
|
||
*/
|
||
public List<String> getPaymentIdList() {
|
||
List<String> resultList = Lists.newArrayList();
|
||
// List<String> paymentIdList1 = getPaymentIdList1();
|
||
List<String> paymentIdListForFile = getPaymentIdListForFile();
|
||
resultList.addAll(paymentIdListForFile);
|
||
return resultList;
|
||
}
|
||
|
||
/**
|
||
* 从文件中读取paymentId
|
||
* @return
|
||
* @throws IOException
|
||
*/
|
||
public List<String> getPaymentIdListForFile() {
|
||
List<String> list =new ArrayList<String>();
|
||
try {
|
||
String path = "src/test/resources/payment_ids";
|
||
FileReader fileReader = new FileReader(path);
|
||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||
String str = null;
|
||
while ((str = bufferedReader.readLine()) != null) {
|
||
if (str.trim().length() > 2) {
|
||
list.add(str);
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
|
||
}
|
||
// System.out.println(list);
|
||
return list;
|
||
}
|
||
|
||
/**
|
||
* 提现方法
|
||
*
|
||
*/
|
||
@Test
|
||
public void withdraw() {
|
||
String merchantId = "87";
|
||
String orderNo = "drawcash_" + merchantId + "_" + System.currentTimeMillis();
|
||
BigDecimal cashAmt = new BigDecimal("2013.81");
|
||
String adapayMemberId = "AM67987250";
|
||
// String adapayAppId = "app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa"; // 固定参数, 汇付配置的万车充小程序appId
|
||
String settleAccountId = "0600303988488384";
|
||
String wechatAppId = wechatAppId1;
|
||
try {
|
||
adapayService.createDrawcashRequest(orderNo, cashAmt, adapayMemberId, adapayAppId, settleAccountId, wechatAppId);
|
||
} catch (BaseAdaPayException e) {
|
||
throw new RuntimeException(e);
|
||
}
|
||
}
|
||
|
||
|
||
public static void main(String[] args) {
|
||
List<String> orderCodeList = Lists.newArrayList();
|
||
orderCodeList.add("C44107428110");
|
||
orderCodeList.add("877828180449136640");
|
||
orderCodeList.add("OP86761657642_20231110055438");
|
||
orderCodeList.add("C80813283397_20231110055123");
|
||
for (String orderCode : orderCodeList) {
|
||
// 如果orderCode长度大于12并且有下划线, 则根据下划线切割只取第一部分
|
||
if (orderCode.length() > 12 && orderCode.contains("_")) {
|
||
orderCode = orderCode.substring(0, orderCode.indexOf("_"));
|
||
}
|
||
System.out.println(orderCode);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 从文件中读取paymentId和未分帐金额
|
||
*/
|
||
public List<Map<String, String>> getPaymentIdListAndAmountForFile() {
|
||
List<Map<String, String>> list = Lists.newArrayList();
|
||
try {
|
||
String path = "src/test/resources/paymentIdAndAmount";
|
||
FileReader fileReader = new FileReader(path);
|
||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||
String str;
|
||
while ((str = bufferedReader.readLine()) != null) {
|
||
if (str.trim().length() > 2) {
|
||
// str根据逗号切割 002212023102515344310563156645282902016,C88208113664,20.0,2.15,17.85,2023-10-25 15:34:49
|
||
String[] strArr = str.split(",");
|
||
String paymentId = strArr[0]; // 支付id
|
||
String orderCode = strArr[1]; // 订单编号
|
||
String payAmount = strArr[2]; // 支付金额
|
||
String refundAmount = strArr[3]; // 退款金额
|
||
String settleAmount = strArr[4]; // 结算金额
|
||
String orderTime = strArr[5]; // 订单时间
|
||
|
||
// 如果orderCode长度大于12并且有下划线, 则根据下划线切割只取第一部分
|
||
if (orderCode.length() > 12 && orderCode.contains("_")) {
|
||
orderCode = orderCode.substring(0, orderCode.indexOf("_"));
|
||
}
|
||
|
||
Map<String, String> map = Maps.newHashMap();
|
||
map.put("paymentId", paymentId);
|
||
map.put("orderCode", orderCode);
|
||
map.put("payAmount", payAmount);
|
||
map.put("refundAmount", refundAmount);
|
||
map.put("settleAmount", settleAmount);
|
||
map.put("orderTime", orderTime);
|
||
list.add(map);
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
|
||
}
|
||
// System.out.println(list);
|
||
return list;
|
||
}
|
||
|
||
@Test
|
||
public void saveOrderUnsplitRecordTest() {
|
||
List<Map<String, String>> mapList = getPaymentIdListAndAmountForFile();
|
||
|
||
List<OrderUnsplitRecord> orderUnsplitRecordList = Lists.newArrayList();
|
||
for (Map<String, String> stringMap : mapList) {
|
||
OrderUnsplitRecord orderUnsplitRecord = new OrderUnsplitRecord();
|
||
orderUnsplitRecord.setPaymentId(stringMap.get("paymentId"));
|
||
orderUnsplitRecord.setStatus("");
|
||
orderUnsplitRecord.setOrderCode(stringMap.get("orderCode"));
|
||
orderUnsplitRecord.setPayAmount(new BigDecimal(stringMap.get("payAmount")));
|
||
orderUnsplitRecord.setRefundAmount(new BigDecimal(stringMap.get("refundAmount")));
|
||
orderUnsplitRecord.setSettleAmount(new BigDecimal(stringMap.get("settleAmount")));
|
||
orderUnsplitRecord.setOrderTime(DateUtils.parseDate(stringMap.get("orderTime")));
|
||
orderUnsplitRecordList.add(orderUnsplitRecord);
|
||
}
|
||
|
||
orderUnsplitRecordService.batchInsert(orderUnsplitRecordList);
|
||
}
|
||
|
||
/**
|
||
* 从文件获取批量分账参数
|
||
* adapayMemberId 待分账的汇付会员id
|
||
* paymentList 待分账的订单信息(包含订单编号, 结算金额, 支付id)
|
||
*/
|
||
public Map<String, Object> getPaymentConfirmParamFromFile() {
|
||
Map<String, Object> paramMap = Maps.newHashMap();
|
||
|
||
// 待分账汇付会员id, 如需分给对应商户就填写正确的汇付会员id
|
||
String adapayMemberId = "0";
|
||
|
||
// 待分账订单信息, 需要重新分账的订单信息(针对未分账的订单)
|
||
List<Map<String, String>> mapList = getPaymentIdListAndAmountForFile();
|
||
JSONArray jsonArray = new JSONArray();
|
||
for (Map<String, String> map : mapList) {
|
||
JSONObject jsonObject = new JSONObject();
|
||
jsonObject.put("orderCode", map.get("orderCode"));
|
||
jsonObject.put("settleAmount", map.get("settleAmount"));
|
||
jsonObject.put("paymentId", map.get("paymentId"));
|
||
jsonArray.add(jsonObject);
|
||
}
|
||
|
||
paramMap.put("adapayMemberId", adapayMemberId);
|
||
paramMap.put("paymentList", jsonArray);
|
||
return paramMap;
|
||
}
|
||
|
||
/**
|
||
* 执行分账并处理重试逻辑
|
||
* @deprecated
|
||
*/
|
||
private void executeWithRetry(PaymentConfirmParam param, int retryCount) {
|
||
PaymentConfirmResponse response = adapayService.createPaymentConfirmRequest(param);
|
||
if (!response.isFailed()) {
|
||
logger.info("分账成功: paymentId={}", param.getPaymentId());
|
||
return;
|
||
}
|
||
|
||
// 失败时记录日志
|
||
logger.error("分账失败: paymentId={}, 重试次数={}, 错误信息={}", param.getPaymentId(), retryCount, response.getError_msg());
|
||
|
||
// 如果未达到最大重试次数,将任务放入延迟队列
|
||
if (retryCount < 3) {
|
||
retryCount++;
|
||
logger.info("将分账任务放入延迟队列: paymentId={}, 重试次数={}", param.getPaymentId(), retryCount);
|
||
redisCache.setCacheObject(
|
||
CacheConstants.DELAYED_PAYMENT_CONFIRM_QUEUE + param.getPaymentId(),
|
||
param,
|
||
60, // 延迟1分钟
|
||
TimeUnit.SECONDS
|
||
);
|
||
} else {
|
||
logger.error("分账失败超过最大重试次数: paymentId={}", param.getPaymentId());
|
||
// 记录最终失败的任务,便于后续处理
|
||
recordFailedPayment(param);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 记录最终失败的分账任务
|
||
*/
|
||
private void recordFailedPayment(PaymentConfirmParam param) {
|
||
String failedKey = CacheConstants.FAILED_PAYMENT_CONFIRM_LIST;
|
||
redisCache.setCacheList(failedKey, Lists.newArrayList(param));
|
||
logger.error("记录最终失败的分账任务: paymentId={}", param.getPaymentId());
|
||
}
|
||
|
||
/**
|
||
* 处理延迟队列中的分账任务
|
||
* @deprecated
|
||
*/
|
||
@Scheduled(fixedDelay = 60000) // 每分钟执行一次
|
||
public void processDelayedPaymentConfirm() {
|
||
String delayedQueueKey = CacheConstants.DELAYED_PAYMENT_CONFIRM_QUEUE + "*";
|
||
Collection<String> keys = redisCache.keys(delayedQueueKey);
|
||
for (String key : keys) {
|
||
PaymentConfirmParam param = redisCache.getCacheObject(key);
|
||
if (param != null) {
|
||
int retryCount = Integer.parseInt(key.split("_")[key.split("_").length - 1]);
|
||
executeWithRetry(param, retryCount);
|
||
redisCache.deleteObject(key); // 处理完成后删除任务
|
||
}
|
||
}
|
||
}
|
||
|
||
@Test
|
||
public void getTotalSplitAmountByPaymentIdTest() {
|
||
String paymentId = "002212023102523235110563274707384705024";
|
||
try {
|
||
BigDecimal amount = adapayService.getTotalSplitAmountByPaymentId(paymentId);
|
||
System.out.println("分账金额: " + amount);
|
||
} catch (BaseAdaPayException e) {
|
||
throw new RuntimeException(e);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 批量支付确认撤销
|
||
* 用于撤销分账
|
||
* @throws BaseAdaPayException
|
||
*/
|
||
@Test
|
||
public void testCreateConfirmReverse() throws BaseAdaPayException {
|
||
List<String> list = getPaymentIdList(); // 批量支付确认撤销
|
||
|
||
list.parallelStream().forEach(paymentId -> {
|
||
// 查询支付确认id
|
||
QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO();
|
||
dto.setPaymentId(paymentId);
|
||
dto.setWechatAppId(wechatAppId1);
|
||
QueryPaymentConfirmDetailResponse response = adapayService.queryPaymentConfirmList(dto);
|
||
if (response != null) {
|
||
List<PaymentConfirmInfo> confirms = response.getPaymentConfirms();
|
||
// System.out.println("支付id:" + paymentId + ", 确认信息:" + JSON.toJSONString(confirms));
|
||
if (CollectionUtils.isNotEmpty(confirms)) {
|
||
for (PaymentConfirmInfo confirm : confirms) {
|
||
try {
|
||
adapayService.createConfirmReverse(confirm.getId(), wechatAppId1);
|
||
} catch (BaseAdaPayException e) {
|
||
throw new RuntimeException(e);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
/**
|
||
* 查询支付确认对象列表
|
||
*/
|
||
@Test
|
||
public void queryPaymentConfirmListTest() {
|
||
String paymentId = "002212025100113085610819328178783772672";
|
||
// 查询支付确认id
|
||
QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO();
|
||
dto.setPaymentId(paymentId);
|
||
dto.setWechatAppId(wechatAppId1);
|
||
QueryPaymentConfirmDetailResponse response = adapayService.queryPaymentConfirmList(dto);
|
||
System.out.println("查询支付确认对象列表:{}" + JSON.toJSONString(response));
|
||
System.out.println("支付确认id:" + response.getPaymentConfirms().get(0).getId());
|
||
}
|
||
|
||
/**
|
||
* 查询退款信息
|
||
*/
|
||
@Test
|
||
public void queryRefundTest() {
|
||
List<String> list = getPaymentIdList(); // 查询退款信息
|
||
for (String paymentId : list) {
|
||
Map<String, Object> refundParams = Maps.newHashMap();
|
||
refundParams.put("payment_id", paymentId);
|
||
try {
|
||
Map<String, Object> refund = Refund.query(refundParams, wechatAppId2);
|
||
System.out.println("支付id:" + paymentId + ", 退款信息:" + JSON.toJSONString(refund));
|
||
System.out.println();
|
||
} catch (BaseAdaPayException e) {
|
||
throw new RuntimeException(e);
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 查询支付撤销信息
|
||
*/
|
||
@Test
|
||
public void queryPaymentReverseTest() {
|
||
List<String> list = getPaymentIdList(); // 查询支付撤销信息
|
||
for (String paymentId : list) {
|
||
try {
|
||
Map<String, Object> reverse = Maps.newHashMap();
|
||
reverse.put("payment_id", paymentId);
|
||
reverse.put("app_id", wechatAppId2);
|
||
Map<String, Object> response = PaymentReverse.queryList(reverse, wechatAppId2);
|
||
System.out.printf("支付id: %s, 支付撤销信息: %s%n", paymentId, JSON.toJSONString(response));
|
||
System.out.println();
|
||
} catch (BaseAdaPayException e) {
|
||
throw new RuntimeException(e);
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 延迟分账未确认调撤销调撤销接口退款/部分退
|
||
*/
|
||
@Test
|
||
public void createPaymentReverseRequestTest() {
|
||
String paymentId = "002212025010720373310722683516795273216";
|
||
BigDecimal refundAmount = new BigDecimal("1.08");
|
||
String memberId = "48781184";
|
||
String orderCode = "C67335843091";
|
||
|
||
// 延迟分账未确认调撤销调撤销接口退款
|
||
PaymentReverseOperation operation = new PaymentReverseOperation();
|
||
operation.setPaymentId(paymentId);
|
||
operation.setReverseAmt(refundAmount);
|
||
operation.setMerchantKey(wechatAppId1);
|
||
operation.setMemberId(memberId);
|
||
operation.setScenarioType(ScenarioEnum.ORDER.getValue());
|
||
operation.setOrderCode(orderCode);
|
||
PaymentReverseResponse response = adapayService.createPaymentReverseRequest(operation);
|
||
System.out.println(JSON.toJSONString(response));
|
||
}
|
||
|
||
/**
|
||
* 由于限制单笔转账1万,转账方法改为循环创建
|
||
* @throws BaseAdaPayException
|
||
*/
|
||
@Test
|
||
public void cycleCreateBalancePayment() throws BaseAdaPayException {
|
||
BigDecimal totalAmount = new BigDecimal("156821.00"); // TODO 需要转账的总金额
|
||
String outMemberId = "AM84864234"; // TODO 出账memberId
|
||
String inMemberId = "0"; // 入账memberId
|
||
String title = "提取余额到自己账户"; // 标题
|
||
String desc = "2025年9月27日10点26分,售后需求:客户重新添加结算账户, 原账户余额无法提取, 由现下打款给客户"; // 描述
|
||
String wechatAppId = wechatAppId1; // 万车充id
|
||
|
||
// 计算转账次数
|
||
BigDecimal singleLimit = new BigDecimal("10000.00"); // 单笔限额
|
||
int count = totalAmount.divide(singleLimit, 0, BigDecimal.ROUND_UP).intValue();
|
||
|
||
// 计算每次转账金额
|
||
BigDecimal remainingAmount = totalAmount;
|
||
List<BigDecimal> transferAmounts = new ArrayList<>();
|
||
while (remainingAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||
// 计算当前转账金额(取剩余金额和单笔最大金额中的较小值)
|
||
BigDecimal currentAmount = remainingAmount.min(singleLimit);
|
||
transferAmounts.add(currentAmount);
|
||
// 减去已转账金额
|
||
remainingAmount = remainingAmount.subtract(currentAmount);
|
||
}
|
||
|
||
logger.info("计算转账次数:{}", count);
|
||
logger.info("转账金额:{}", transferAmounts);
|
||
|
||
// 循环创建转账
|
||
for (int i = 0; i < count; i++) {
|
||
String transAmt = transferAmounts.get(i).toString(); // 金额
|
||
adapayService.createBalancePaymentRequest(outMemberId, inMemberId, transAmt, title, desc, wechatAppId);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 提取余额到自己账户, 转账超过1万使用循环创建{@link PaymentTestController#cycleCreateBalancePayment()}
|
||
*/
|
||
@Test
|
||
public void createBalancePaymentRequestTest() {
|
||
String outMemberId = "AM84864234"; // 出账memberId
|
||
String inMemberId = "0"; // 入账memberId
|
||
String transAmt = "10000.00"; // 金额
|
||
String title = "提取余额到自己账户"; // 标题
|
||
String desc = "2025年9月27日10点26分,售后需求:客户重新添加结算账户, 原账户余额无法提取, 由现下打款给客户"; // 描述
|
||
String wechatAppId = wechatAppId1; // 万车充id
|
||
adapayService.createBalancePaymentRequest(outMemberId, inMemberId, transAmt, title, desc, wechatAppId);
|
||
}
|
||
|
||
/**
|
||
*
|
||
*/
|
||
@Test
|
||
public void createBalancePaymentRequestTest2() {
|
||
String outMemberId = "0"; // 出账memberId
|
||
String inMemberId = "ACM25158725"; // 入账memberId
|
||
String transAmt = "42.7"; // 金额
|
||
String title = "订单金额补分账"; // 标题
|
||
String desc = "补C69401257710,C86364369573结算金额"; // 描述
|
||
String wechatAppId = wechatAppId1; // 万车充id
|
||
adapayService.createBalancePaymentRequest(outMemberId, inMemberId, transAmt, title, desc, wechatAppId);
|
||
}
|
||
|
||
/**
|
||
* 校验订单分账金额
|
||
*/
|
||
@Test
|
||
public void verifyOrderConfirmAmountTest() throws BaseAdaPayException {
|
||
String orderCode = "C21960272918";
|
||
List<String> paymentIds = Lists.newArrayList("002212024121307453510713429549121368064");
|
||
BigDecimal settleAmount = new BigDecimal("19.37");
|
||
String wechatAppId = wechatAppId1;
|
||
OrderSplitResult orderSplitResult = orderBasicInfoService.verifyOrderConfirmAmount(paymentIds, orderCode, settleAmount, wechatAppId);
|
||
System.out.println(JSON.toJSONString(orderSplitResult));
|
||
}
|
||
|
||
/**
|
||
* 查询未分帐金额
|
||
*/
|
||
@Test
|
||
public void queryPaymentConfirmDetailTest() throws BaseAdaPayException {
|
||
|
||
// 查询支付确认id
|
||
QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO();
|
||
dto.setPaymentConfirmId("0022120250914002345990812975021684928512");
|
||
dto.setWechatAppId(wechatAppId1);
|
||
// 查询分账信息
|
||
PaymentConfirmInfo paymentConfirmInfo = adapayService.queryPaymentConfirmDetail(dto);
|
||
System.out.println(JSON.toJSONString(paymentConfirmInfo));
|
||
}
|
||
|
||
private List<String> getAdapayMemberIds() {
|
||
List<String> list = new ArrayList<>();
|
||
list.add("ACM25743626");
|
||
list.add("ACM69424215");
|
||
list.add("ACM27437238");
|
||
list.add("ACM84442005");
|
||
list.add("ACM42810916");
|
||
list.add("ACM48576257");
|
||
list.add("ACM67580043");
|
||
list.add("ACM67738893");
|
||
list.add("ACM23489463");
|
||
list.add("ACM40991242");
|
||
list.add("ACM48720983");
|
||
list.add("ACM82507085");
|
||
list.add("ACM25511707");
|
||
list.add("ACM48152528");
|
||
list.add("ACM84659934");
|
||
list.add("ACM29123898");
|
||
list.add("ACM82792551");
|
||
list.add("ACM44398405");
|
||
list.add("ACM61290230");
|
||
list.add("ACM84693947");
|
||
list.add("ACM25158725");
|
||
list.add("ACM25530730");
|
||
list.add("ACM48910890");
|
||
list.add("ACM88601280");
|
||
list.add("ACM61634334");
|
||
list.add("ACM80895702");
|
||
list.add("ACM63995722");
|
||
list.add("ACM46639968");
|
||
list.add("ACM61026608");
|
||
list.add("ACM21943395");
|
||
list.add("ACM42242307");
|
||
list.add("ACM46086128");
|
||
list.add("ACM46272826");
|
||
list.add("ACM82731955");
|
||
list.add("ACM69232006");
|
||
list.add("ACM65039881");
|
||
list.add("ACM84868091");
|
||
list.add("ACM65835351");
|
||
list.add("ACM84007115");
|
||
list.add("ACM82710624");
|
||
list.add("ACM63191244");
|
||
list.add("ACM80665158");
|
||
list.add("ACM88877099");
|
||
list.add("ACM23253592");
|
||
list.add("ACM40744704");
|
||
list.add("ACM82585598");
|
||
list.add("ACM61630517");
|
||
list.add("ACM86381094");
|
||
list.add("ACM44105905");
|
||
list.add("ACM42282057");
|
||
list.add("ACM46270169");
|
||
list.add("ACM48532303");
|
||
list.add("ACM69867986");
|
||
list.add("ACM25576542");
|
||
list.add("ACM80057656");
|
||
list.add("ACM42459200");
|
||
list.add("ACM46046815");
|
||
list.add("ACM61085115");
|
||
list.add("ACM25916276");
|
||
list.add("ACM69804831");
|
||
list.add("ACM65455320");
|
||
list.add("ACM84845205");
|
||
list.add("ACM48173891");
|
||
list.add("ACM84486182");
|
||
list.add("ACM46460819");
|
||
list.add("ACM63740826");
|
||
list.add("ACM63191096");
|
||
list.add("ACM48918479");
|
||
list.add("ACM29522241");
|
||
list.add("ACM27416361");
|
||
list.add("ACM48956267");
|
||
list.add("ACM65098379");
|
||
list.add("ACM46251134");
|
||
list.add("ACM42491105");
|
||
list.add("ACM27859047");
|
||
list.add("ACM86788208");
|
||
list.add("ACM46692941");
|
||
list.add("ACM80410442");
|
||
list.add("ACM27036391");
|
||
list.add("ACM27853386");
|
||
list.add("ACM23654452");
|
||
list.add("ACM40782726");
|
||
list.add("ACM63571448");
|
||
list.add("ACM29566538");
|
||
list.add("ACM46846737");
|
||
list.add("ACM29393542");
|
||
list.add("ACM23485623");
|
||
list.add("ACM82526496");
|
||
list.add("ACM27663450");
|
||
list.add("ACM88831475");
|
||
list.add("ACM69048024");
|
||
list.add("ACM65854572");
|
||
list.add("ACM88261510");
|
||
list.add("ACM42497015");
|
||
list.add("ACM61807959");
|
||
list.add("ACM25116331");
|
||
list.add("ACM82399802");
|
||
list.add("ACM88079897");
|
||
list.add("ACM61630935");
|
||
list.add("ACM44799744");
|
||
list.add("ACM40326146");
|
||
list.add("ACM88603166");
|
||
list.add("ACM86592402");
|
||
list.add("ACM61254324");
|
||
list.add("ACM69882166");
|
||
list.add("ACM44124955");
|
||
list.add("ACM65683299");
|
||
list.add("ACM82102763");
|
||
list.add("ACM48321794");
|
||
list.add("ACM69673479");
|
||
list.add("ACM67500600");
|
||
list.add("ACM86172597");
|
||
list.add("ACM42491905");
|
||
list.add("ACM67751788");
|
||
list.add("ACM42854259");
|
||
list.add("ACM61465505");
|
||
list.add("ACM25576943");
|
||
list.add("ACM65622214");
|
||
list.add("ACM88035944");
|
||
list.add("ACM44582427");
|
||
list.add("ACM61296391");
|
||
list.add("ACM69426703");
|
||
list.add("ACM44924010");
|
||
list.add("ACM23673274");
|
||
list.add("ACM84045137");
|
||
list.add("ACM80205384");
|
||
list.add("ACM44398211");
|
||
list.add("ACM29908562");
|
||
list.add("ACM23698348");
|
||
list.add("ACM80266727");
|
||
list.add("ACM63556694");
|
||
list.add("ACM29560453");
|
||
list.add("ACM63706872");
|
||
list.add("ACM46652838");
|
||
list.add("ACM65854139");
|
||
list.add("ACM67183933");
|
||
list.add("ACM69802535");
|
||
list.add("ACM46829664");
|
||
list.add("ACM21143070");
|
||
list.add("ACM61425221");
|
||
list.add("ACM42244668");
|
||
list.add("ACM40326509");
|
||
list.add("ACM21949831");
|
||
list.add("ACM63383478");
|
||
list.add("ACM40700033");
|
||
list.add("ACM42056483");
|
||
list.add("ACM61862227");
|
||
list.add("ACM65681312");
|
||
list.add("ACM21181689");
|
||
list.add("ACM80876335");
|
||
list.add("ACM63552660");
|
||
list.add("ACM69082641");
|
||
list.add("ACM23447202");
|
||
list.add("ACM61024342");
|
||
list.add("ACM46046494");
|
||
list.add("ACM88607781");
|
||
list.add("ACM86579709");
|
||
list.add("ACM65858167");
|
||
list.add("ACM42261148");
|
||
list.add("ACM42077124");
|
||
list.add("ACM48994471");
|
||
list.add("ACM88873084");
|
||
list.add("ACM84250847");
|
||
list.add("ACM88073310");
|
||
list.add("ACM65818689");
|
||
list.add("ACM42810992");
|
||
list.add("ACM21968250");
|
||
list.add("ACM42666015");
|
||
list.add("ACM42227741");
|
||
list.add("ACM44968744");
|
||
list.add("ACM65202789");
|
||
list.add("ACM25576713");
|
||
list.add("ACM25196954");
|
||
list.add("ACM48530698");
|
||
list.add("ACM25380172");
|
||
list.add("ACM23468349");
|
||
list.add("ACM65227435");
|
||
list.add("ACM23270264");
|
||
list.add("ACM82944298");
|
||
list.add("ACM65056931");
|
||
list.add("ACM25720476");
|
||
list.add("ACM82948898");
|
||
list.add("ACM46449658");
|
||
list.add("ACM69844311");
|
||
list.add("ACM82794891");
|
||
list.add("ACM42474874");
|
||
list.add("ACM48557876");
|
||
list.add("ACM69061582");
|
||
list.add("ACM84062890");
|
||
list.add("ACM21981947");
|
||
list.add("ACM23447601");
|
||
list.add("ACM46000454");
|
||
list.add("ACM80897090");
|
||
list.add("ACM40594777");
|
||
return list;
|
||
}
|
||
|
||
@Test
|
||
public void queryAdapayMember() throws BaseAdaPayException {
|
||
// 查询所有运营商的adapayMemberId
|
||
// String adapayMemberId = "ACM25158725";
|
||
List<String> nullInfoList = new ArrayList<>();
|
||
List<String> targetList = new ArrayList<>();
|
||
|
||
List<String> adapayMemberIds = getAdapayMemberIds();
|
||
for (String memberId : adapayMemberIds) {
|
||
AdapayCorpMemberVO adapayCorpMemberVO = adapayService.queryCorpAdapayMemberInfo(memberId, wechatAppId1);
|
||
if (adapayCorpMemberVO == null) {
|
||
nullInfoList.add(memberId);
|
||
continue;
|
||
}
|
||
String settleAccountId = adapayCorpMemberVO.getSettleAccountId();
|
||
if (settleAccountId == null) {
|
||
targetList.add(memberId);
|
||
}
|
||
}
|
||
logger.info("无信息运营商:{}", nullInfoList);
|
||
logger.info("无结算账户运营商:{}", targetList);
|
||
|
||
}
|
||
|
||
@Test
|
||
public void closeOrder() throws BaseAdaPayException {
|
||
String paymentId = "002212025070811225010788498509816119296";
|
||
Map<String, Object> map = new LinkedHashMap<>();
|
||
map.put("payment_id", paymentId);
|
||
Map<String, Object> close = Payment.close(map, wechatAppId1);
|
||
logger.info("关单接口调用结果:{}", close);
|
||
|
||
}
|
||
|
||
/**
|
||
* 处理OrderSplitRecord中值为0的数据
|
||
* @throws BaseAdaPayException
|
||
*/
|
||
@Test
|
||
public void handleOrderSplitRecord() throws BaseAdaPayException {
|
||
String orderCode = "C48131824908";
|
||
|
||
// 根据订单号查询订单信息
|
||
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
|
||
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode);
|
||
|
||
// 组装after参数
|
||
AfterSettleOrderDTO afterSettleOrderDTO = AfterSettleOrderDTO.builder()
|
||
.orderCode(orderBasicInfo.getOrderCode())
|
||
.merchantId(orderBasicInfo.getMerchantId())
|
||
.stationId(orderBasicInfo.getStationId())
|
||
.orderPayAmount(orderBasicInfo.getPayAmount()) // 支付金额
|
||
.orderConsumeAmount(orderBasicInfo.getOrderAmount()) // 消费金额
|
||
.orderSettleAmount(orderBasicInfo.getSettleAmount()) // 结算金额
|
||
.orderElectricityAmount(orderDetail.getTotalElectricityAmount()) // 电费金额
|
||
.orderElectricityDiscountAmount(orderDetail.getDiscountElectricityAmount()) // 电费折扣金额
|
||
.orderServiceAmount(orderDetail.getTotalServiceAmount()) // 服务费金额
|
||
.orderServiceDiscountAmount(orderDetail.getDiscountServiceAmount()) // 服务费折扣金额
|
||
.orderRefundAmount(orderBasicInfo.getRefundAmount()) // 退款金额
|
||
.orderBasicInfo(orderBasicInfo)
|
||
.build();
|
||
|
||
orderBasicInfoService.splittingMethodTemp(afterSettleOrderDTO);
|
||
|
||
}
|
||
|
||
@Test
|
||
public void processUnSettledOrder() {
|
||
// 现查询需要分账或者退款的数据
|
||
int pageNum = 1;
|
||
int pageSize = 3;
|
||
PageHelper.startPage(pageNum, pageSize);
|
||
List<AdapayUnsplitRecordVO> adapayUnsplitRecordVOS = adapayUnsplitRecordService.queryList();
|
||
for (AdapayUnsplitRecordVO adapayUnsplitRecordVO : adapayUnsplitRecordVOS) {
|
||
System.out.println(adapayUnsplitRecordVO);
|
||
// 获取待分账金额
|
||
String waitSplitAmount = adapayUnsplitRecordVO.getWaitSplitAmount();
|
||
// 如果waitSplitAmount > 0, 调用分账接口
|
||
if (waitSplitAmount != null && !"".equals(waitSplitAmount)) {
|
||
// 调用分账接口
|
||
}
|
||
|
||
// 获取待退款金额
|
||
String refundPayAmount = adapayUnsplitRecordVO.getRefundPayAmount();
|
||
}
|
||
PageHelper.clearPage();
|
||
}
|
||
}
|