2025-10-10 11:54:35 +08:00
|
|
|
|
package com.jsowell.service;
|
|
|
|
|
|
|
2025-10-10 13:32:53 +08:00
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import com.google.common.collect.Maps;
|
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.dto.DebugOrderDTO;
|
|
|
|
|
|
import com.jsowell.pile.dto.QueryOrderSplitRecordDTO;
|
|
|
|
|
|
import com.jsowell.pile.service.OrderBasicInfoService;
|
2025-10-10 13:32:53 +08:00
|
|
|
|
import com.jsowell.pile.vo.web.OrderPaymentDetailVO;
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
2025-10-10 11:54:35 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
2025-10-10 13:32:53 +08:00
|
|
|
|
import java.util.Map;
|
2025-10-10 11:54:35 +08:00
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class SplitBillService {
|
|
|
|
|
|
|
2025-10-10 13:32:53 +08:00
|
|
|
|
private final Logger log = LoggerFactory.getLogger(SplitBillService.class);
|
|
|
|
|
|
|
2025-10-10 11:54:35 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private OrderBasicInfoService orderBasicInfoService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private TempService tempService;
|
2025-10-10 13:32:53 +08:00
|
|
|
|
|
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)
|
2025-10-10 13:32:53 +08:00
|
|
|
|
List<OrderPaymentDetailVO> recordList = orderBasicInfoService.getSplitOrders(dto);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(recordList)) {
|
|
|
|
|
|
log.info("重试运营商分账-根据参数未查询到符合条件的订单, param:{}", dto);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-10 13:10:56 +08:00
|
|
|
|
// 获取 paymentIdList
|
2025-10-10 13:32:53 +08:00
|
|
|
|
// List<String> paymentIdList = recordList.stream()
|
|
|
|
|
|
// .map(OrderPaymentDetailVO::getPaymentId)
|
|
|
|
|
|
// .collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
// 循环一次,获得paymentIdList 与 Map
|
|
|
|
|
|
List<String> paymentIdList = Lists.newArrayList();
|
|
|
|
|
|
Map<String, OrderPaymentDetailVO> paymentIdMap = Maps.newHashMap();
|
|
|
|
|
|
for (OrderPaymentDetailVO orderPaymentDetailVO : recordList) {
|
|
|
|
|
|
paymentIdList.add(orderPaymentDetailVO.getPaymentId());
|
|
|
|
|
|
paymentIdMap.put(orderPaymentDetailVO.getPaymentId(), orderPaymentDetailVO);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断订单是否已经成功分账, 将未分账的订单进行筛选、汇总
|
2025-10-10 13:10:56 +08:00
|
|
|
|
List<String> unSplitPaymentIdList = adapayService.getSplitInfoByPaymentIdList(paymentIdList);
|
2025-10-10 13:32:53 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(unSplitPaymentIdList)) {
|
|
|
|
|
|
log.info("重试运营商分账-所有订单都已经成功分账");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-10 11:54:35 +08:00
|
|
|
|
// 将 paymentIdList 与 recordList 进行匹配,筛选出 orderCodeList
|
2025-10-10 13:32:53 +08:00
|
|
|
|
List<String> orderCodeList = Lists.newArrayList();
|
|
|
|
|
|
// Set<String> paymentIdSet = new HashSet<>(unSplitPaymentIdList);
|
|
|
|
|
|
// List<String> orderCodeList = recordList.stream()
|
|
|
|
|
|
// .filter(record -> paymentIdSet.contains(record.getPaymentId()))
|
|
|
|
|
|
// .map(OrderPaymentDetailVO::getOrderCode)
|
|
|
|
|
|
// .collect(Collectors.toList());
|
|
|
|
|
|
for (String unSplitPaymentId : unSplitPaymentIdList) {
|
|
|
|
|
|
OrderPaymentDetailVO orderPaymentDetailVO = paymentIdMap.get(unSplitPaymentId);
|
|
|
|
|
|
if (orderPaymentDetailVO != null) {
|
|
|
|
|
|
orderCodeList.add(orderPaymentDetailVO.getOrderCode());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-10 11:54:35 +08:00
|
|
|
|
|
|
|
|
|
|
// 调用 debugOrder 接口进行重新分账
|
|
|
|
|
|
for (String orderCode : orderCodeList) {
|
|
|
|
|
|
DebugOrderDTO debugOrderDTO = new DebugOrderDTO();
|
|
|
|
|
|
debugOrderDTO.setOrderCode(orderCode);
|
|
|
|
|
|
debugOrderDTO.setReSplitFlag(Constants.ONE);
|
|
|
|
|
|
|
2025-10-10 13:32:53 +08:00
|
|
|
|
try {
|
|
|
|
|
|
tempService.debugOrder(debugOrderDTO);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("重试运营商分账-debugOrder接口调用异常, param:{}", debugOrderDTO, e);
|
|
|
|
|
|
}
|
2025-10-10 11:54:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|