2025-10-10 11:54:35 +08:00
|
|
|
|
package com.jsowell.service;
|
|
|
|
|
|
|
2025-10-10 13:10:56 +08:00
|
|
|
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
|
|
|
|
|
import com.jsowell.adapay.service.AdapayService;
|
2025-10-10 11:54:35 +08:00
|
|
|
|
import com.jsowell.common.constant.Constants;
|
|
|
|
|
|
import com.jsowell.pile.domain.OrderSplitRecord;
|
|
|
|
|
|
import com.jsowell.pile.dto.DebugOrderDTO;
|
|
|
|
|
|
import com.jsowell.pile.dto.QueryOrderSplitRecordDTO;
|
|
|
|
|
|
import com.jsowell.pile.service.OrderBasicInfoService;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class SplitBillService {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private OrderBasicInfoService orderBasicInfoService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private TempService tempService;
|
2025-10-10 13:10:56 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private AdapayService adapayService;
|
2025-10-10 11:54:35 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 重试运营商分账
|
|
|
|
|
|
* @param dto
|
|
|
|
|
|
*/
|
2025-10-10 13:10:56 +08:00
|
|
|
|
public void retryMerchantSplit(QueryOrderSplitRecordDTO dto) throws BaseAdaPayException {
|
2025-10-10 11:54:35 +08:00
|
|
|
|
// 首先根据 merchantId、startTime、endTime 查出日期区间内所有订单信息(包括 paymentId)
|
|
|
|
|
|
List<OrderSplitRecord> recordList = orderBasicInfoService.getSplitOrders(dto);
|
2025-10-10 13:10:56 +08:00
|
|
|
|
// 获取 paymentIdList
|
|
|
|
|
|
List<String> paymentIdList = recordList.stream()
|
|
|
|
|
|
.map(OrderSplitRecord::getPaymentId)
|
|
|
|
|
|
.collect(Collectors.toList());
|
2025-10-10 11:54:35 +08:00
|
|
|
|
// 判断订单是否已经成功分账
|
|
|
|
|
|
// 将未分账的订单进行筛选、汇总
|
2025-10-10 13:10:56 +08:00
|
|
|
|
List<String> unSplitPaymentIdList = adapayService.getSplitInfoByPaymentIdList(paymentIdList);
|
2025-10-10 11:54:35 +08:00
|
|
|
|
// 将 paymentIdList 与 recordList 进行匹配,筛选出 orderCodeList
|
2025-10-10 13:10:56 +08:00
|
|
|
|
Set<String> paymentIdSet = new HashSet<>(unSplitPaymentIdList);
|
2025-10-10 11:54:35 +08:00
|
|
|
|
List<String> orderCodeList = recordList.stream()
|
|
|
|
|
|
.filter(record -> paymentIdSet.contains(record.getPaymentId()))
|
|
|
|
|
|
.map(OrderSplitRecord::getOrderCode)
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
// 调用 debugOrder 接口进行重新分账
|
|
|
|
|
|
for (String orderCode : orderCodeList) {
|
|
|
|
|
|
DebugOrderDTO debugOrderDTO = new DebugOrderDTO();
|
|
|
|
|
|
debugOrderDTO.setOrderCode(orderCode);
|
|
|
|
|
|
debugOrderDTO.setReSplitFlag(Constants.ONE);
|
|
|
|
|
|
|
|
|
|
|
|
tempService.debugOrder(debugOrderDTO);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|