2023-03-04 16:29:55 +08:00
|
|
|
|
package com.jsowell.quartz.task;
|
|
|
|
|
|
|
2025-11-19 11:55:05 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
2025-04-16 15:50:26 +08:00
|
|
|
|
import com.google.common.collect.Lists;
|
2026-03-11 17:55:20 +08:00
|
|
|
|
import com.jsowell.adapay.common.DivMember;
|
|
|
|
|
|
import com.jsowell.adapay.common.PaymentConfirmInfo;
|
|
|
|
|
|
import com.jsowell.adapay.dto.PaymentConfirmParam;
|
2025-11-19 11:55:05 +08:00
|
|
|
|
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
|
2025-02-13 11:49:52 +08:00
|
|
|
|
import com.jsowell.adapay.dto.WithdrawDTO;
|
2026-03-11 17:55:20 +08:00
|
|
|
|
import com.jsowell.adapay.response.PaymentConfirmResponse;
|
2025-11-19 11:55:05 +08:00
|
|
|
|
import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse;
|
2025-02-13 11:49:52 +08:00
|
|
|
|
import com.jsowell.adapay.service.AdapayService;
|
2025-11-14 15:44:24 +08:00
|
|
|
|
import com.jsowell.common.YouDianUtils;
|
2023-07-17 16:44:04 +08:00
|
|
|
|
import com.jsowell.common.constant.CacheConstants;
|
2023-06-05 17:06:07 +08:00
|
|
|
|
import com.jsowell.common.constant.Constants;
|
2023-07-17 16:44:04 +08:00
|
|
|
|
import com.jsowell.common.core.redis.RedisCache;
|
2025-01-15 09:05:55 +08:00
|
|
|
|
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.common.util.DateUtils;
|
2025-04-16 15:50:26 +08:00
|
|
|
|
import com.jsowell.common.util.PageUtils;
|
2023-03-25 16:01:54 +08:00
|
|
|
|
import com.jsowell.common.util.StringUtils;
|
2025-03-25 14:33:58 +08:00
|
|
|
|
import com.jsowell.common.util.spring.SpringUtils;
|
2025-11-14 15:07:50 +08:00
|
|
|
|
import com.jsowell.pile.domain.AdapayUnsplitRecord;
|
2023-07-14 14:33:48 +08:00
|
|
|
|
import com.jsowell.pile.domain.OrderBasicInfo;
|
2023-07-26 19:41:13 +08:00
|
|
|
|
import com.jsowell.pile.domain.PileMerchantInfo;
|
2023-06-05 17:06:07 +08:00
|
|
|
|
import com.jsowell.pile.domain.PileStationInfo;
|
2023-06-03 17:04:15 +08:00
|
|
|
|
import com.jsowell.pile.domain.ykcCommond.PublishPileBillingTemplateCommand;
|
|
|
|
|
|
import com.jsowell.pile.domain.ykcCommond.StartChargingCommand;
|
2023-07-26 19:41:13 +08:00
|
|
|
|
import com.jsowell.pile.service.*;
|
2026-03-11 17:55:20 +08:00
|
|
|
|
import com.jsowell.pile.vo.AdapayUnsplitRecordVO;
|
2025-01-15 09:05:55 +08:00
|
|
|
|
import com.jsowell.pile.vo.base.StationInfoVO;
|
2023-03-25 15:47:09 +08:00
|
|
|
|
import com.jsowell.pile.vo.web.BillingTemplateVO;
|
2023-07-17 16:44:04 +08:00
|
|
|
|
import com.jsowell.thirdparty.amap.service.AMapService;
|
2025-08-15 09:34:38 +08:00
|
|
|
|
import com.jsowell.thirdparty.common.NotificationDTO;
|
|
|
|
|
|
import com.jsowell.thirdparty.common.NotificationService;
|
2023-03-25 11:10:15 +08:00
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
2026-03-11 17:55:20 +08:00
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
2026-03-11 17:55:20 +08:00
|
|
|
|
import java.io.InputStream;
|
2023-03-25 16:01:54 +08:00
|
|
|
|
import java.math.BigDecimal;
|
2026-03-11 17:55:20 +08:00
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
|
import java.nio.file.Paths;
|
2023-07-14 10:56:45 +08:00
|
|
|
|
import java.time.LocalDate;
|
2023-03-25 11:10:15 +08:00
|
|
|
|
import java.time.LocalDateTime;
|
2025-11-14 15:07:50 +08:00
|
|
|
|
import java.util.*;
|
2025-01-15 09:05:55 +08:00
|
|
|
|
import java.util.stream.Collectors;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
@Component("jsowellTask")
|
|
|
|
|
|
public class JsowellTask {
|
|
|
|
|
|
|
2025-02-13 14:00:09 +08:00
|
|
|
|
private final Logger log = LoggerFactory.getLogger(JsowellTask.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private OrderBasicInfoService orderBasicInfoService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private PileBillingTemplateService pileBillingTemplateService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private YKCPushCommandService ykcPushCommandService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private PileMerchantInfoService pileMerchantInfoService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private PileStationInfoService pileStationInfoService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
|
2025-08-15 09:34:38 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private NotificationService notificationService;
|
|
|
|
|
|
|
2025-02-13 14:00:09 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private AMapService aMapService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private AdapayService adapayService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private SettleOrderReportService settleOrderReportService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ThirdPartyStationRelationService thirdPartyStationRelationService;
|
|
|
|
|
|
|
2025-11-14 15:07:50 +08:00
|
|
|
|
// @Autowired
|
|
|
|
|
|
// private OrderUnsplitRecordService orderUnsplitRecordService;
|
|
|
|
|
|
|
2025-04-16 15:50:26 +08:00
|
|
|
|
@Autowired
|
2025-11-14 15:07:50 +08:00
|
|
|
|
private AdapayUnsplitRecordService adapayUnsplitRecordService;
|
2025-04-16 15:50:26 +08:00
|
|
|
|
|
2025-03-25 14:33:58 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 设置挡板, PRE环境不执行
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void setBarrier() {
|
|
|
|
|
|
String env = SpringUtils.getActiveProfile();
|
2025-03-25 14:50:11 +08:00
|
|
|
|
if (StringUtils.equalsIgnoreCase(env, "pre")) {
|
2025-03-25 14:57:25 +08:00
|
|
|
|
log.debug("PRE环境不执行");
|
2025-08-25 16:08:02 +08:00
|
|
|
|
// return;
|
2025-03-25 14:33:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-13 14:00:09 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 关闭15分钟未支付的订单
|
|
|
|
|
|
* close15MinutesOfUnpaidOrders
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void close15MinutesOfUnpaidOrders() {
|
2025-03-25 14:50:11 +08:00
|
|
|
|
String env = SpringUtils.getActiveProfile();
|
|
|
|
|
|
if (StringUtils.equalsIgnoreCase(env, "pre")) {
|
2025-03-25 14:57:25 +08:00
|
|
|
|
log.debug("PRE环境不执行");
|
2025-03-25 14:50:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-02-13 14:00:09 +08:00
|
|
|
|
// log.info("关闭15分钟未支付的订单");
|
|
|
|
|
|
orderBasicInfoService.close15MinutesOfUnpaidOrders();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 关闭启动失败的订单
|
|
|
|
|
|
* 订单支付成功,在15分钟内未启动,
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void closeStartFailedOrder() {
|
2025-03-25 14:50:11 +08:00
|
|
|
|
String env = SpringUtils.getActiveProfile();
|
|
|
|
|
|
if (StringUtils.equalsIgnoreCase(env, "pre")) {
|
2025-03-25 14:57:25 +08:00
|
|
|
|
log.debug("PRE环境不执行");
|
2025-08-25 16:18:46 +08:00
|
|
|
|
// return;
|
2025-03-25 14:50:11 +08:00
|
|
|
|
}
|
2025-02-13 14:00:09 +08:00
|
|
|
|
// 查询出最近2天支付成功,并且订单状态为未启动的订单
|
|
|
|
|
|
String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addDays(new Date(), -2));
|
|
|
|
|
|
String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date());
|
|
|
|
|
|
orderBasicInfoService.closeStartFailedOrder(startTime, endTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询预约充电的订单并启动
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void appointmentOrderStart() {
|
2025-03-25 14:50:11 +08:00
|
|
|
|
String env = SpringUtils.getActiveProfile();
|
|
|
|
|
|
if (StringUtils.equalsIgnoreCase(env, "pre")) {
|
2025-03-25 14:57:25 +08:00
|
|
|
|
log.debug("PRE环境不执行");
|
2025-03-25 14:50:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-02-13 14:00:09 +08:00
|
|
|
|
// 查询出 已支付 设置预约充电 未启动 的订单
|
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
|
List<OrderBasicInfo> list = orderBasicInfoService.getReservedOrder(now);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
log.info("待启动充电订单:{}", list);
|
|
|
|
|
|
for (OrderBasicInfo orderInfo : list) {
|
|
|
|
|
|
// 下发充电桩设置指令
|
|
|
|
|
|
String pileSn = orderInfo.getPileSn();
|
|
|
|
|
|
// 发送启动充电指令前,再次下发计费模板
|
|
|
|
|
|
BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn);
|
|
|
|
|
|
if (billingTemplateVO != null) {
|
|
|
|
|
|
PublishPileBillingTemplateCommand command = PublishPileBillingTemplateCommand.builder()
|
|
|
|
|
|
.billingTemplateVO(billingTemplateVO)
|
|
|
|
|
|
.pileSn(pileSn)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
ykcPushCommandService.pushPublishPileBillingTemplate(command);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 发送启动指令
|
|
|
|
|
|
String connectorCode = orderInfo.getConnectorCode();
|
|
|
|
|
|
String transactionCode = orderInfo.getTransactionCode();
|
|
|
|
|
|
BigDecimal payAmount = orderInfo.getPayAmount();
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(pileSn) || StringUtils.isEmpty(connectorCode)) {
|
|
|
|
|
|
log.warn("appointmentOrderStart-远程启动充电, 充电桩编号和枪口号不能为空");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
log.info("appointmentOrderStart 远程启动充电, 桩号:{}, 枪口号:{}", pileSn, connectorCode);
|
|
|
|
|
|
StartChargingCommand startChargingCommand = StartChargingCommand.builder()
|
|
|
|
|
|
.pileSn(pileSn)
|
|
|
|
|
|
.connectorCode(connectorCode)
|
|
|
|
|
|
.transactionCode(transactionCode)
|
|
|
|
|
|
.chargeAmount(payAmount)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
ykcPushCommandService.pushStartChargingCommand(startChargingCommand);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 计算站点订单报表
|
|
|
|
|
|
* jsowellTask.calculateTheSiteOrdersReport()
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void calculateTheSiteOrdersReport() {
|
2025-03-25 14:50:11 +08:00
|
|
|
|
String env = SpringUtils.getActiveProfile();
|
|
|
|
|
|
if (StringUtils.equalsIgnoreCase(env, "pre")) {
|
2025-03-25 14:57:25 +08:00
|
|
|
|
log.debug("PRE环境不执行");
|
2025-03-25 14:50:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-02-13 14:00:09 +08:00
|
|
|
|
// 查询出所有站点
|
|
|
|
|
|
PileStationInfo pileStationInfo = new PileStationInfo();
|
|
|
|
|
|
pileStationInfo.setDelFlag(Constants.ZERO);
|
|
|
|
|
|
// 查询未删除的站点列表
|
|
|
|
|
|
List<PileStationInfo> list = pileStationInfoService.selectPileStationInfoList(pileStationInfo);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
LocalDate yesterday = LocalDate.now().plusDays(-1);
|
|
|
|
|
|
// 计算每个站点前一天的报表
|
|
|
|
|
|
for (PileStationInfo stationInfo : list) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
settleOrderReportService.generateDailyOrderReports(stationInfo.getId() + "", yesterday.toString());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("计算站点订单报表 发生异常 stationId:{}", stationInfo.getId(), e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 站点的枪口数据推送到高德
|
|
|
|
|
|
* jsowellTask.pushToAMap()
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void pushToAMap() {
|
2025-03-25 14:50:11 +08:00
|
|
|
|
String env = SpringUtils.getActiveProfile();
|
|
|
|
|
|
if (StringUtils.equalsIgnoreCase(env, "pre")) {
|
2025-03-25 14:57:25 +08:00
|
|
|
|
log.debug("PRE环境不执行");
|
2025-03-25 14:50:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-02-13 14:00:09 +08:00
|
|
|
|
Set<String> stationIds = redisCache.getCacheSet(CacheConstants.PUSH_STATION_CONNECTOR);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(stationIds)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
log.info("推送到高德的stationId:{}", stationIds);
|
|
|
|
|
|
for (String stationId : stationIds) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
aMapService.pushChargingDeviceDynamics(stationId);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("推送到高德error", e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 删除缓存
|
|
|
|
|
|
redisCache.deleteObject(CacheConstants.PUSH_STATION_CONNECTOR);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-10 10:05:37 +08:00
|
|
|
|
* 贵州省平台推送充电站实时功率 15分钟执行一次
|
2025-02-13 14:00:09 +08:00
|
|
|
|
*/
|
|
|
|
|
|
public void pushStationRealTimePowerInfo() {
|
2025-03-25 14:50:11 +08:00
|
|
|
|
String env = SpringUtils.getActiveProfile();
|
2025-08-18 08:40:07 +08:00
|
|
|
|
if (StringUtils.equalsIgnoreCase(env, "pre")) {
|
2025-03-25 14:57:25 +08:00
|
|
|
|
log.debug("PRE环境不执行");
|
2025-03-25 14:50:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-08-15 09:34:38 +08:00
|
|
|
|
|
2025-08-18 08:40:07 +08:00
|
|
|
|
List<String> thirdPartyTypeList = Lists.newArrayList(
|
|
|
|
|
|
ThirdPlatformTypeEnum.GUI_ZHOU_PLATFORM.getTypeCode(),
|
2025-08-15 09:34:38 +08:00
|
|
|
|
ThirdPlatformTypeEnum.SI_CHUAN_PLATFORM.getTypeCode(),
|
|
|
|
|
|
ThirdPlatformTypeEnum.JI_LIN_PLATFORM.getTypeCode()
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
for (String thirdPartyType : thirdPartyTypeList) {
|
2025-08-15 08:58:09 +08:00
|
|
|
|
List<StationInfoVO> stationInfoVOS = thirdPartyStationRelationService.selectStationList(thirdPartyType);
|
2025-08-15 09:34:38 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(stationInfoVOS)) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2025-02-13 14:00:09 +08:00
|
|
|
|
|
2025-08-15 08:58:09 +08:00
|
|
|
|
List<String> stationIdList = stationInfoVOS.stream()
|
|
|
|
|
|
.map(StationInfoVO::getStationId)
|
|
|
|
|
|
.collect(Collectors.toList());
|
2025-02-13 14:00:09 +08:00
|
|
|
|
|
2025-08-15 09:34:38 +08:00
|
|
|
|
for (String stationId : stationIdList) {
|
2025-08-15 09:50:38 +08:00
|
|
|
|
try {
|
|
|
|
|
|
NotificationDTO dto = new NotificationDTO();
|
|
|
|
|
|
dto.setStationId(stationId);
|
|
|
|
|
|
dto.setPlatformType(thirdPartyType);
|
|
|
|
|
|
notificationService.notificationStationPowerInfo(dto);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("平台类型:{},站点ID:{},推送充电站实时功率失败", thirdPartyType, stationId, e);
|
|
|
|
|
|
}
|
2025-08-15 09:34:38 +08:00
|
|
|
|
}
|
2025-08-15 08:58:09 +08:00
|
|
|
|
}
|
2025-07-10 10:05:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 推送统计信息 24小时执行一次
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void pushStatisticsInfo() {
|
|
|
|
|
|
String env = SpringUtils.getActiveProfile();
|
2025-11-10 17:07:29 +08:00
|
|
|
|
if (StringUtils.equalsIgnoreCase(env, "pre")) {
|
|
|
|
|
|
log.debug("PRE环境不执行");
|
2025-07-10 10:05:37 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-18 08:40:07 +08:00
|
|
|
|
List<String> thirdPartyTypeList = Lists.newArrayList(
|
|
|
|
|
|
ThirdPlatformTypeEnum.GUI_ZHOU_PLATFORM.getTypeCode(),
|
2025-08-15 09:42:37 +08:00
|
|
|
|
ThirdPlatformTypeEnum.SI_CHUAN_PLATFORM.getTypeCode(),
|
|
|
|
|
|
ThirdPlatformTypeEnum.JI_LIN_PLATFORM.getTypeCode()
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
for (String thirdPartyType : thirdPartyTypeList) {
|
|
|
|
|
|
List<StationInfoVO> stationInfoVOS = thirdPartyStationRelationService.selectStationList(thirdPartyType);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(stationInfoVOS)) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<String> stationIdList = stationInfoVOS.stream()
|
|
|
|
|
|
.map(StationInfoVO::getStationId)
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
for (String stationId : stationIdList) {
|
2025-08-15 09:50:38 +08:00
|
|
|
|
try {
|
|
|
|
|
|
NotificationDTO dto = new NotificationDTO();
|
|
|
|
|
|
dto.setStationId(stationId);
|
|
|
|
|
|
dto.setPlatformType(thirdPartyType);
|
|
|
|
|
|
notificationService.notificationOperationStatsInfo(dto);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("平台类型:{},站点ID:{},推送统计信息失败", thirdPartyType, stationId, e);
|
|
|
|
|
|
}
|
2025-08-15 09:42:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-13 18:10:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-13 14:00:09 +08:00
|
|
|
|
/**
|
2025-02-21 15:50:15 +08:00
|
|
|
|
* 定时任务, 订单分账
|
2025-02-13 14:00:09 +08:00
|
|
|
|
* jsowellTask.processOrderSplitting()
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void processOrderSplitting() {
|
2025-03-25 14:50:11 +08:00
|
|
|
|
String env = SpringUtils.getActiveProfile();
|
|
|
|
|
|
if (StringUtils.equalsIgnoreCase(env, "pre")) {
|
2025-03-25 14:57:25 +08:00
|
|
|
|
log.debug("PRE环境不执行");
|
2025-03-25 14:50:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-02-13 14:00:09 +08:00
|
|
|
|
// 查询运营商列表
|
|
|
|
|
|
List<PileMerchantInfo> pileMerchantInfos = pileMerchantInfoService.selectPileMerchantInfoList(null);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(pileMerchantInfos)) {
|
|
|
|
|
|
log.info("定时任务,处理订单分账, 未查询到运营商列表,直接返回");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 获取日期
|
|
|
|
|
|
LocalDate yesterday = LocalDate.now().plusDays(-1);
|
|
|
|
|
|
|
|
|
|
|
|
// 设置挡板,8月1号之后的订单按照实际进行分账
|
2025-02-21 15:50:15 +08:00
|
|
|
|
// LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
|
// LocalDateTime dateTime = LocalDateTime.of(2023, 8, 2, 0, 0, 0);
|
|
|
|
|
|
// if (now.isBefore(dateTime)) {
|
|
|
|
|
|
// log.info("当前时间:{}早于:{}, 不进行分账处理", DateUtils.formatDateTime(now), DateUtils.formatDateTime(dateTime));
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// 调生成运营商日报方法
|
|
|
|
|
|
pileMerchantInfos.parallelStream().forEach(merchant -> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
orderBasicInfoService.orderSplittingOperations(merchant.getId() + "", yesterday.toString());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("生成运营商日报异常, merchantId:{}", merchant.getId(), e);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生成运营商日报表
|
|
|
|
|
|
* jsowellTask.generateMerchantBill()
|
2025-03-05 16:07:47 +08:00
|
|
|
|
*
|
|
|
|
|
|
*
|
2025-02-21 15:50:15 +08:00
|
|
|
|
*/
|
|
|
|
|
|
public void generateMerchantBill() {
|
2025-03-25 14:50:11 +08:00
|
|
|
|
String env = SpringUtils.getActiveProfile();
|
|
|
|
|
|
if (StringUtils.equalsIgnoreCase(env, "pre")) {
|
2025-03-25 14:57:25 +08:00
|
|
|
|
log.debug("PRE环境不执行");
|
2025-03-25 14:50:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-02-21 15:50:15 +08:00
|
|
|
|
// 查询运营商列表
|
|
|
|
|
|
List<PileMerchantInfo> pileMerchantInfos = pileMerchantInfoService.selectPileMerchantInfoList(null);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(pileMerchantInfos)) {
|
|
|
|
|
|
log.info("定时任务,处理订单分账, 未查询到运营商列表,直接返回");
|
2025-02-13 14:00:09 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-02-21 15:50:15 +08:00
|
|
|
|
// 获取日期
|
|
|
|
|
|
LocalDate yesterday = LocalDate.now().plusDays(-1);
|
2025-02-13 14:00:09 +08:00
|
|
|
|
|
2025-02-20 16:50:30 +08:00
|
|
|
|
// 调生成运营商日报方法
|
2025-02-18 10:39:20 +08:00
|
|
|
|
pileMerchantInfos.parallelStream().forEach(merchant -> {
|
2025-02-20 15:44:35 +08:00
|
|
|
|
try {
|
|
|
|
|
|
orderBasicInfoService.generateMerchantBill(merchant.getId() + "", yesterday.toString());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("生成运营商日报异常, merchantId:{}", merchant.getId(), e);
|
|
|
|
|
|
}
|
2025-02-18 10:39:20 +08:00
|
|
|
|
});
|
2025-02-13 14:00:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-02-20 15:44:35 +08:00
|
|
|
|
* 定时任务,自动提现
|
|
|
|
|
|
* jsowellTask.automaticPayouts()
|
2025-02-13 14:00:09 +08:00
|
|
|
|
*/
|
2025-02-20 15:44:35 +08:00
|
|
|
|
public void automaticPayouts() {
|
2025-03-25 14:50:11 +08:00
|
|
|
|
String env = SpringUtils.getActiveProfile();
|
|
|
|
|
|
if (StringUtils.equalsIgnoreCase(env, "pre")) {
|
2025-03-25 14:57:25 +08:00
|
|
|
|
log.debug("PRE环境不执行");
|
2025-03-25 14:50:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 查询开启自动提现运营商列表
|
2025-03-13 13:43:30 +08:00
|
|
|
|
// List<PileMerchantInfo> pileMerchantInfos = pileMerchantInfoService.selectPileMerchantInfoList(null);
|
|
|
|
|
|
List<PileMerchantInfo> pileMerchantInfos = pileMerchantInfoService.selectAutoWithdrawalMerchantInfoList();
|
2025-02-20 15:44:35 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(pileMerchantInfos)) {
|
|
|
|
|
|
log.info("定时任务,自动提现, 未查询到运营商列表,直接返回");
|
|
|
|
|
|
return;
|
2025-02-13 11:49:52 +08:00
|
|
|
|
}
|
2025-02-20 15:44:35 +08:00
|
|
|
|
|
|
|
|
|
|
// 调提现方法
|
|
|
|
|
|
pileMerchantInfos.parallelStream().forEach(merchant -> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
WithdrawDTO dto = new WithdrawDTO();
|
|
|
|
|
|
dto.setMerchantId(merchant.getId() + "");
|
|
|
|
|
|
dto.setFeeAmt("0");
|
|
|
|
|
|
adapayService.drawCash(dto);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("生成运营商日报异常, merchantId:{}", merchant.getId(), e);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-02-13 11:49:52 +08:00
|
|
|
|
}
|
2025-02-20 15:44:35 +08:00
|
|
|
|
|
2025-04-16 15:50:26 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 处理未分帐订单
|
2025-04-17 10:03:33 +08:00
|
|
|
|
* jsowellTask.processUnSettledOrder()
|
2025-04-16 15:50:26 +08:00
|
|
|
|
*/
|
|
|
|
|
|
public void processUnSettledOrder() {
|
2025-11-14 14:48:15 +08:00
|
|
|
|
// processUnSettledOrderOld(); // 旧方法
|
2025-11-14 16:03:26 +08:00
|
|
|
|
for (int i = 0; i < 35; i++) {
|
2025-11-14 16:13:31 +08:00
|
|
|
|
int batchNum = i + 1;
|
2025-11-19 11:55:05 +08:00
|
|
|
|
processUnSettledOrderV2(batchNum); // 新方法
|
2025-11-14 16:03:26 +08:00
|
|
|
|
}
|
2025-11-14 14:48:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-11 17:55:20 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 处理adapay_unsplit_record待分账数据,统一分账到memberId=0
|
|
|
|
|
|
* 依赖queryList(),请先完成settle_amount/due_refund_amount等字段补齐
|
|
|
|
|
|
* jsowellTask.processUnsplitRecordToDefaultMember()
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void processUnsplitRecordToDefaultMember() {
|
|
|
|
|
|
processUnsplitRecordToDefaultMember(Constants.DEFAULT_APP_ID, 500);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 处理adapay_unsplit_record待分账数据,统一分账到memberId=0
|
|
|
|
|
|
* jsowellTask.processUnsplitRecordToDefaultMember(wechatAppId, pageSize)
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void processUnsplitRecordToDefaultMember(String wechatAppId, Integer pageSize) {
|
|
|
|
|
|
int size = pageSize == null || pageSize <= 0 ? 500 : pageSize;
|
|
|
|
|
|
int pageNum = 1;
|
|
|
|
|
|
int total = 0;
|
|
|
|
|
|
int success = 0;
|
|
|
|
|
|
int skipped = 0;
|
|
|
|
|
|
int failed = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
PageUtils.startPage(pageNum, size);
|
|
|
|
|
|
List<AdapayUnsplitRecordVO> list = adapayUnsplitRecordService.queryList();
|
|
|
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.info("处理未分账数据到默认账户, pageNum:{}, pageSize:{}, 当前页:{}条", pageNum, size, list.size());
|
|
|
|
|
|
for (AdapayUnsplitRecordVO item : list) {
|
|
|
|
|
|
total++;
|
|
|
|
|
|
String paymentId = item.getPaymentId();
|
|
|
|
|
|
String orderCode = item.getOrderCode();
|
|
|
|
|
|
BigDecimal waitSplitAmount = parseAmount(item.getWaitSplitAmount());
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(paymentId) || waitSplitAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
|
skipped++;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BigDecimal confirmAmt = getLatestConfirmAmount(waitSplitAmount, item.getPayAmount(), paymentId, wechatAppId);
|
|
|
|
|
|
if (confirmAmt.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
|
skipped++;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PaymentConfirmResponse response;
|
|
|
|
|
|
try {
|
|
|
|
|
|
DivMember divMember = new DivMember();
|
|
|
|
|
|
divMember.setMemberId(Constants.ZERO);
|
|
|
|
|
|
divMember.setAmount(confirmAmt.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
|
|
|
|
|
|
divMember.setFeeFlag(Constants.Y);
|
|
|
|
|
|
|
|
|
|
|
|
PaymentConfirmParam param = PaymentConfirmParam.builder()
|
|
|
|
|
|
.paymentId(paymentId)
|
|
|
|
|
|
.divMemberList(Lists.newArrayList(divMember))
|
|
|
|
|
|
.confirmAmt(confirmAmt)
|
|
|
|
|
|
.orderCode(orderCode)
|
|
|
|
|
|
.wechatAppId(wechatAppId)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
response = adapayService.createPaymentConfirmRequest(param);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
failed++;
|
|
|
|
|
|
log.error("处理未分账数据到默认账户异常, paymentId:{}, orderCode:{}, confirmAmt:{}",
|
|
|
|
|
|
paymentId, orderCode, confirmAmt, e);
|
|
|
|
|
|
markSplitResult(paymentId, "FAILED");
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (response != null && response.isSuccess()) {
|
|
|
|
|
|
success++;
|
|
|
|
|
|
updateConfirmedSplitAmount(item, confirmAmt, paymentId);
|
|
|
|
|
|
markSplitResult(paymentId, "SUCCESS");
|
|
|
|
|
|
log.info("处理未分账数据成功, paymentId:{}, orderCode:{}, confirmAmt:{}, response:{}",
|
|
|
|
|
|
paymentId, orderCode, confirmAmt, JSON.toJSONString(response));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
failed++;
|
|
|
|
|
|
String errorCode = response == null ? "response_null" : response.getError_code();
|
|
|
|
|
|
String errorMsg = response == null ? "response_is_null" : response.getError_msg();
|
|
|
|
|
|
log.error("处理未分账数据失败, paymentId:{}, orderCode:{}, confirmAmt:{}, errorCode:{}, errorMsg:{}",
|
|
|
|
|
|
paymentId, orderCode, confirmAmt, errorCode, errorMsg);
|
|
|
|
|
|
markSplitResult(paymentId, "FAILED");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (list.size() < size) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
pageNum++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.info("处理未分账数据到默认账户结束, total:{}, success:{}, skipped:{}, failed:{}",
|
|
|
|
|
|
total, success, skipped, failed);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 从Excel导入adapay_unsplit_record,并补齐缺失字段
|
|
|
|
|
|
* 默认文件路径:doc/万车充小程序-未分账明细.xlsx
|
|
|
|
|
|
* jsowellTask.importAdapayUnsplitRecordAndCompleteFields()
|
|
|
|
|
|
*/
|
2026-03-12 15:23:32 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 从默认路径导入未分账明细并补齐缺失字段(无参入口)
|
|
|
|
|
|
* 默认读取 doc/万车充小程序-未分账明细.xlsx(相对于工作目录)
|
|
|
|
|
|
* jsowellTask.importAdapayUnsplitRecordAndCompleteFields()
|
|
|
|
|
|
*/
|
2026-03-11 17:55:20 +08:00
|
|
|
|
public void importAdapayUnsplitRecordAndCompleteFields() {
|
|
|
|
|
|
importAdapayUnsplitRecordAndCompleteFields("doc/万车充小程序-未分账明细.xlsx");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-12 16:12:34 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 补齐 adapay_unsplit_record 表中缺失字段(独立入口,可单独作为定时任务调用)
|
|
|
|
|
|
* 以指定时间范围内的未分账记录为目标,补齐 orderCode、退款金额、结算金额、桩类型
|
|
|
|
|
|
* jsowellTask.completeAdapayUnsplitRecordFields(startTime, endTime)
|
|
|
|
|
|
* 示例:jsowellTask.completeAdapayUnsplitRecordFields('2024-01-01 00:00:00', '2025-12-31 23:59:59')
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void completeAdapayUnsplitRecordFields(String startTime, String endTime) {
|
|
|
|
|
|
int updatedCount = completeUnsplitRecordMissingFields(startTime, endTime, 1000);
|
|
|
|
|
|
log.info("补齐未分账数据缺失字段完成, startTime:{}, endTime:{}, 更新:{}条", startTime, endTime, updatedCount);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-11 17:55:20 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 从Excel导入adapay_unsplit_record,并补齐缺失字段
|
2026-03-12 15:23:32 +08:00
|
|
|
|
* 流程:
|
|
|
|
|
|
* 1. 校验文件路径(相对路径自动拼接工作目录转为绝对路径)
|
|
|
|
|
|
* 2. 解析Excel,逐行转换为 AdapayUnsplitRecord,调用 insertOrUpdateSelective 写入数据库
|
|
|
|
|
|
* 3. 以导入数据的支付时间范围为条件,分页查询已入库记录,补齐 orderCode/退款金额/结算金额/桩类型等缺失字段
|
2026-03-11 17:55:20 +08:00
|
|
|
|
* jsowellTask.importAdapayUnsplitRecordAndCompleteFields(文件路径)
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void importAdapayUnsplitRecordAndCompleteFields(String filePath) {
|
2026-03-12 15:23:32 +08:00
|
|
|
|
// 相对路径转绝对路径(基于 JVM 工作目录)
|
2026-03-11 17:55:20 +08:00
|
|
|
|
Path path = Paths.get(filePath);
|
|
|
|
|
|
if (!path.isAbsolute()) {
|
|
|
|
|
|
path = Paths.get(System.getProperty("user.dir"), filePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!Files.exists(path)) {
|
|
|
|
|
|
log.error("导入未分账数据失败,文件不存在:{}", path.toAbsolutePath());
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-12 15:23:32 +08:00
|
|
|
|
// 第一步:读取Excel,将每行数据 insertOrUpdate 到 adapay_unsplit_record 表
|
2026-03-11 17:55:20 +08:00
|
|
|
|
ImportSummary summary = importAdapayUnsplitRecord(path);
|
|
|
|
|
|
|
|
|
|
|
|
if (summary.successRows == 0) {
|
|
|
|
|
|
log.info("导入未分账数据结束,未写入任何数据,统计:{}", summary);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-12 15:23:32 +08:00
|
|
|
|
// 第二步:以导入数据中最早/最晚支付时间为范围,补齐已入库记录的缺失字段
|
|
|
|
|
|
// 若 Excel 中无有效支付时间,则使用兜底时间范围(2024-01-01 至当前时间)
|
2026-03-11 17:55:20 +08:00
|
|
|
|
String startTime = summary.minPayTime == null
|
|
|
|
|
|
? "2024-01-01 00:00:00"
|
|
|
|
|
|
: DateUtils.formatDateTime(summary.minPayTime);
|
|
|
|
|
|
String endTime = summary.maxPayTime == null
|
|
|
|
|
|
? DateUtils.getDateTime()
|
|
|
|
|
|
: DateUtils.formatDateTime(summary.maxPayTime);
|
|
|
|
|
|
|
|
|
|
|
|
int updatedCount = completeUnsplitRecordMissingFields(startTime, endTime, 1000);
|
|
|
|
|
|
log.info("导入并补齐未分账数据完成, 导入统计:{}, 补齐更新:{}条", summary, updatedCount);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-12 15:23:32 +08:00
|
|
|
|
private static final int IMPORT_BATCH_SIZE = 500;
|
|
|
|
|
|
|
2026-03-11 17:55:20 +08:00
|
|
|
|
private ImportSummary importAdapayUnsplitRecord(Path filePath) {
|
|
|
|
|
|
ImportSummary summary = new ImportSummary();
|
|
|
|
|
|
DataFormatter formatter = new DataFormatter();
|
|
|
|
|
|
|
|
|
|
|
|
try (InputStream inputStream = Files.newInputStream(filePath);
|
|
|
|
|
|
Workbook workbook = WorkbookFactory.create(inputStream)) {
|
|
|
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
|
|
|
if (sheet == null) {
|
|
|
|
|
|
log.error("导入未分账数据失败,Excel没有sheet, file:{}", filePath.toAbsolutePath());
|
|
|
|
|
|
return summary;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Row headerRow = sheet.getRow(sheet.getFirstRowNum());
|
|
|
|
|
|
if (headerRow == null) {
|
|
|
|
|
|
log.error("导入未分账数据失败,Excel没有表头, file:{}", filePath.toAbsolutePath());
|
|
|
|
|
|
return summary;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Integer> headerIndexMap = buildHeaderIndexMap(headerRow, formatter);
|
|
|
|
|
|
List<String> requiredHeaders = Lists.newArrayList(
|
|
|
|
|
|
"商户号", "支付时间", "交易流水号", "交易订单号", "交易订单金额", "已确认分账金额", "已撤销金额", "支付确认撤销金额", "剩余未分账金额"
|
|
|
|
|
|
);
|
|
|
|
|
|
for (String requiredHeader : requiredHeaders) {
|
|
|
|
|
|
if (!headerIndexMap.containsKey(normalizeHeader(requiredHeader))) {
|
|
|
|
|
|
log.error("导入未分账数据失败,缺少字段:{}, file:{}", requiredHeader, filePath.toAbsolutePath());
|
|
|
|
|
|
return summary;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int firstDataRow = sheet.getFirstRowNum() + 1;
|
|
|
|
|
|
int lastDataRow = sheet.getLastRowNum();
|
2026-03-12 15:23:32 +08:00
|
|
|
|
// 批量收集记录,每 IMPORT_BATCH_SIZE 条执行一次批量 upsert,减少数据库交互次数
|
|
|
|
|
|
List<AdapayUnsplitRecord> batch = new ArrayList<>(IMPORT_BATCH_SIZE);
|
2026-03-11 17:55:20 +08:00
|
|
|
|
for (int rowNum = firstDataRow; rowNum <= lastDataRow; rowNum++) {
|
|
|
|
|
|
Row row = sheet.getRow(rowNum);
|
|
|
|
|
|
if (row == null || isRowEmpty(row)) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
summary.totalRows++;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
AdapayUnsplitRecord record = convertRowToRecord(row, headerIndexMap, formatter);
|
|
|
|
|
|
if (record == null) {
|
|
|
|
|
|
summary.skippedRows++;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2026-03-12 15:23:32 +08:00
|
|
|
|
batch.add(record);
|
2026-03-11 17:55:20 +08:00
|
|
|
|
summary.updatePayTimeRange(record.getPayTime());
|
2026-03-12 15:23:32 +08:00
|
|
|
|
|
|
|
|
|
|
// 达到批量大小时执行一次批量写入
|
|
|
|
|
|
if (batch.size() >= IMPORT_BATCH_SIZE) {
|
|
|
|
|
|
adapayUnsplitRecordService.batchInsertOrUpdateSelective(batch);
|
|
|
|
|
|
summary.successRows += batch.size();
|
|
|
|
|
|
batch.clear();
|
|
|
|
|
|
}
|
2026-03-11 17:55:20 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
summary.failedRows++;
|
|
|
|
|
|
log.error("导入未分账数据失败, rowNum:{}, file:{}", rowNum + 1, filePath.toAbsolutePath(), e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (summary.totalRows % 1000 == 0) {
|
|
|
|
|
|
log.info("导入未分账数据进行中, total:{}, success:{}, skipped:{}, failed:{}",
|
|
|
|
|
|
summary.totalRows, summary.successRows, summary.skippedRows, summary.failedRows);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-03-12 15:23:32 +08:00
|
|
|
|
// 处理剩余不足一批的记录
|
|
|
|
|
|
if (!batch.isEmpty()) {
|
|
|
|
|
|
adapayUnsplitRecordService.batchInsertOrUpdateSelective(batch);
|
|
|
|
|
|
summary.successRows += batch.size();
|
|
|
|
|
|
}
|
2026-03-11 17:55:20 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("导入未分账数据失败, file:{}", filePath.toAbsolutePath(), e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return summary;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int completeUnsplitRecordMissingFields(String startTime, String endTime, int pageSize) {
|
|
|
|
|
|
int pageNum = 1;
|
|
|
|
|
|
int updatedCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
PageUtils.startPage(pageNum, pageSize);
|
|
|
|
|
|
List<AdapayUnsplitRecord> list = adapayUnsplitRecordService.queryUnsplitOrders(startTime, endTime);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Set<String> orderCodeSet = new HashSet<>();
|
|
|
|
|
|
for (AdapayUnsplitRecord record : list) {
|
|
|
|
|
|
if (StringUtils.isBlank(record.getOrderCode())) {
|
|
|
|
|
|
String extractedOrderCode = extractOrderCode(record.getOrderNo());
|
|
|
|
|
|
if (StringUtils.isNotBlank(extractedOrderCode)) {
|
|
|
|
|
|
record.setOrderCode(extractedOrderCode);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isNotBlank(record.getOrderCode())) {
|
|
|
|
|
|
orderCodeSet.add(record.getOrderCode());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, OrderBasicInfo> orderMap = new HashMap<>();
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(orderCodeSet)) {
|
|
|
|
|
|
List<OrderBasicInfo> orderList = orderBasicInfoService.selectOrderTemp(orderCodeSet);
|
|
|
|
|
|
orderMap = orderList.stream()
|
|
|
|
|
|
.collect(Collectors.toMap(OrderBasicInfo::getOrderCode, v -> v, (k1, k2) -> k1));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<AdapayUnsplitRecord> updateList = new ArrayList<>();
|
|
|
|
|
|
Date now = DateUtils.getNowDate();
|
|
|
|
|
|
for (AdapayUnsplitRecord record : list) {
|
|
|
|
|
|
boolean needUpdate = false;
|
|
|
|
|
|
|
|
|
|
|
|
String orderCode = record.getOrderCode();
|
|
|
|
|
|
if (StringUtils.isBlank(orderCode)) {
|
|
|
|
|
|
orderCode = extractOrderCode(record.getOrderNo());
|
|
|
|
|
|
if (StringUtils.isNotBlank(orderCode)) {
|
|
|
|
|
|
record.setOrderCode(orderCode);
|
|
|
|
|
|
needUpdate = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(orderCode)) {
|
|
|
|
|
|
OrderBasicInfo orderBasicInfo = orderMap.get(orderCode);
|
|
|
|
|
|
if (orderBasicInfo != null) {
|
|
|
|
|
|
BigDecimal refundAmount = orderBasicInfo.getRefundAmount();
|
|
|
|
|
|
if (!isSameAmount(record.getDueRefundAmount(), refundAmount)) {
|
|
|
|
|
|
record.setDueRefundAmount(refundAmount);
|
|
|
|
|
|
needUpdate = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
BigDecimal settleAmount = orderBasicInfo.getSettleAmount();
|
|
|
|
|
|
if (!isSameAmount(record.getSettleAmount(), settleAmount)) {
|
|
|
|
|
|
record.setSettleAmount(settleAmount);
|
|
|
|
|
|
needUpdate = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
String pileType = YouDianUtils.isEBikePileSn(orderBasicInfo.getPileSn()) ? "eBike" : "EV";
|
|
|
|
|
|
if (!StringUtils.equals(record.getPileType(), pileType)) {
|
|
|
|
|
|
record.setPileType(pileType);
|
|
|
|
|
|
needUpdate = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (needUpdate) {
|
|
|
|
|
|
record.setUpdateTime(now);
|
|
|
|
|
|
updateList.add(record);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(updateList)) {
|
|
|
|
|
|
adapayUnsplitRecordService.updateBatchSelective(updateList);
|
|
|
|
|
|
updatedCount += updateList.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (list.size() < pageSize) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
pageNum++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return updatedCount;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private BigDecimal getLatestConfirmAmount(BigDecimal waitSplitAmount, String payAmount, String paymentId, String wechatAppId) {
|
|
|
|
|
|
BigDecimal confirmAmt = waitSplitAmount;
|
|
|
|
|
|
try {
|
|
|
|
|
|
QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO();
|
|
|
|
|
|
dto.setWechatAppId(wechatAppId);
|
|
|
|
|
|
dto.setPaymentId(paymentId);
|
|
|
|
|
|
QueryPaymentConfirmDetailResponse response = adapayService.queryPaymentConfirmList(dto);
|
|
|
|
|
|
BigDecimal latestRemaining = calculateLatestRemainingAmount(payAmount, response);
|
|
|
|
|
|
if (latestRemaining.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
|
confirmAmt = waitSplitAmount.min(latestRemaining);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.warn("查询汇付确认金额异常,使用数据库待分账金额继续处理, paymentId:{}, waitSplitAmount:{}",
|
|
|
|
|
|
paymentId, waitSplitAmount, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
return confirmAmt;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private BigDecimal calculateLatestRemainingAmount(String payAmount, QueryPaymentConfirmDetailResponse response) {
|
|
|
|
|
|
BigDecimal payAmt = parseAmount(payAmount);
|
|
|
|
|
|
if (payAmt.compareTo(BigDecimal.ZERO) <= 0 || response == null || CollectionUtils.isEmpty(response.getPaymentConfirms())) {
|
|
|
|
|
|
return payAmt;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BigDecimal maxConfirmedAmt = BigDecimal.ZERO;
|
|
|
|
|
|
BigDecimal maxReservedAmt = BigDecimal.ZERO;
|
|
|
|
|
|
List<PaymentConfirmInfo> confirms = response.getPaymentConfirms();
|
|
|
|
|
|
for (PaymentConfirmInfo confirm : confirms) {
|
|
|
|
|
|
BigDecimal confirmedAmt = parseAmount(confirm.getConfirmedAmt());
|
|
|
|
|
|
BigDecimal reservedAmt = parseAmount(confirm.getReservedAmt());
|
|
|
|
|
|
if (confirmedAmt.compareTo(maxConfirmedAmt) > 0) {
|
|
|
|
|
|
maxConfirmedAmt = confirmedAmt;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (reservedAmt.compareTo(maxReservedAmt) > 0) {
|
|
|
|
|
|
maxReservedAmt = reservedAmt;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
BigDecimal latestRemaining = payAmt.subtract(maxConfirmedAmt).subtract(maxReservedAmt);
|
|
|
|
|
|
return latestRemaining.compareTo(BigDecimal.ZERO) > 0 ? latestRemaining : BigDecimal.ZERO;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void updateConfirmedSplitAmount(AdapayUnsplitRecordVO item, BigDecimal confirmAmt, String paymentId) {
|
|
|
|
|
|
BigDecimal oldConfirmedAmt = parseAmount(item.getConfirmedSplitAmount());
|
|
|
|
|
|
BigDecimal newConfirmedAmt = oldConfirmedAmt.add(confirmAmt).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
AdapayUnsplitRecord updateRecord = new AdapayUnsplitRecord();
|
|
|
|
|
|
updateRecord.setPaymentId(paymentId);
|
|
|
|
|
|
updateRecord.setConfirmedSplitAmount(newConfirmedAmt);
|
|
|
|
|
|
updateRecord.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
|
adapayUnsplitRecordService.insertOrUpdateSelective(updateRecord);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void markSplitResult(String paymentId, String splitFlag) {
|
|
|
|
|
|
AdapayUnsplitRecord updateRecord = new AdapayUnsplitRecord();
|
|
|
|
|
|
updateRecord.setPaymentId(paymentId);
|
|
|
|
|
|
updateRecord.setSplitFlag(splitFlag);
|
|
|
|
|
|
updateRecord.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
|
adapayUnsplitRecordService.insertOrUpdateSelective(updateRecord);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private AdapayUnsplitRecord convertRowToRecord(Row row, Map<String, Integer> headerIndexMap, DataFormatter formatter) {
|
|
|
|
|
|
String paymentId = getCellString(row, headerIndexMap.get(normalizeHeader("交易流水号")), formatter);
|
|
|
|
|
|
if (StringUtils.isBlank(paymentId)) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String orderNo = getCellString(row, headerIndexMap.get(normalizeHeader("交易订单号")), formatter);
|
|
|
|
|
|
Date payTime = parsePayTime(getCell(row, headerIndexMap.get(normalizeHeader("支付时间"))), formatter);
|
|
|
|
|
|
|
|
|
|
|
|
AdapayUnsplitRecord record = new AdapayUnsplitRecord();
|
|
|
|
|
|
record.setMerchantCode(getCellString(row, headerIndexMap.get(normalizeHeader("商户号")), formatter));
|
|
|
|
|
|
record.setPayTime(payTime);
|
|
|
|
|
|
record.setPaymentId(paymentId);
|
|
|
|
|
|
record.setOrderNo(orderNo);
|
|
|
|
|
|
record.setOrderCode(extractOrderCode(orderNo));
|
|
|
|
|
|
record.setPayAmount(getCellDecimal(row, headerIndexMap.get(normalizeHeader("交易订单金额")), formatter));
|
|
|
|
|
|
record.setConfirmedSplitAmount(getCellDecimal(row, headerIndexMap.get(normalizeHeader("已确认分账金额")), formatter));
|
|
|
|
|
|
record.setRefundAmount(getCellDecimal(row, headerIndexMap.get(normalizeHeader("已撤销金额")), formatter));
|
|
|
|
|
|
record.setPaymentRevokeAmount(getCellDecimal(row, headerIndexMap.get(normalizeHeader("支付确认撤销金额")), formatter));
|
|
|
|
|
|
record.setRemainingSplitAmount(getCellDecimal(row, headerIndexMap.get(normalizeHeader("剩余未分账金额")), formatter));
|
|
|
|
|
|
record.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
|
return record;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Integer> buildHeaderIndexMap(Row headerRow, DataFormatter formatter) {
|
|
|
|
|
|
Map<String, Integer> headerIndexMap = new HashMap<>();
|
|
|
|
|
|
short firstCellNum = headerRow.getFirstCellNum();
|
|
|
|
|
|
short lastCellNum = headerRow.getLastCellNum();
|
|
|
|
|
|
if (firstCellNum < 0 || lastCellNum < 0) {
|
|
|
|
|
|
return headerIndexMap;
|
|
|
|
|
|
}
|
|
|
|
|
|
for (int cellIndex = firstCellNum; cellIndex < lastCellNum; cellIndex++) {
|
|
|
|
|
|
Cell cell = headerRow.getCell(cellIndex, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
|
|
|
|
|
if (cell == null) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
String header = normalizeHeader(formatter.formatCellValue(cell));
|
|
|
|
|
|
if (StringUtils.isNotBlank(header)) {
|
|
|
|
|
|
headerIndexMap.put(header, cellIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return headerIndexMap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String getCellString(Row row, Integer columnIndex, DataFormatter formatter) {
|
|
|
|
|
|
Cell cell = getCell(row, columnIndex);
|
|
|
|
|
|
if (cell == null) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
String value = formatter.formatCellValue(cell);
|
|
|
|
|
|
return StringUtils.isBlank(value) ? null : value.trim();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Cell getCell(Row row, Integer columnIndex) {
|
|
|
|
|
|
if (row == null || columnIndex == null) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
return row.getCell(columnIndex, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private BigDecimal getCellDecimal(Row row, Integer columnIndex, DataFormatter formatter) {
|
|
|
|
|
|
String value = getCellString(row, columnIndex, formatter);
|
|
|
|
|
|
return parseAmount(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Date parsePayTime(Cell cell, DataFormatter formatter) {
|
|
|
|
|
|
if (cell == null) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (cell.getCellType() == CellType.NUMERIC) {
|
|
|
|
|
|
return DateUtil.getJavaDate(cell.getNumericCellValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (cell.getCellType() == CellType.FORMULA && cell.getCachedFormulaResultType() == CellType.NUMERIC) {
|
|
|
|
|
|
return DateUtil.getJavaDate(cell.getNumericCellValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String value = formatter.formatCellValue(cell);
|
|
|
|
|
|
if (StringUtils.isBlank(value)) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
Date date = DateUtils.parseDate(value.trim());
|
|
|
|
|
|
if (date != null) {
|
|
|
|
|
|
return date;
|
|
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
return DateUtil.getJavaDate(Double.parseDouble(value.trim()));
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.warn("解析支付时间失败,value:{}", value);
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String extractOrderCode(String orderNo) {
|
|
|
|
|
|
if (StringUtils.isBlank(orderNo)) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
int index = orderNo.indexOf("_");
|
2026-03-12 15:36:51 +08:00
|
|
|
|
String orderCode = index > 0 ? orderNo.substring(0, index) : orderNo;
|
|
|
|
|
|
// order_code 字段长度限制为 16,超长则无法匹配订单,返回 null
|
2026-03-12 16:13:15 +08:00
|
|
|
|
if (orderCode.length() >= 16) {
|
|
|
|
|
|
log.warn("order_code 字段长度超出限制,order_no:{}", orderNo);
|
|
|
|
|
|
}
|
2026-03-12 15:36:51 +08:00
|
|
|
|
return orderCode.length() <= 16 ? orderCode : null;
|
2026-03-11 17:55:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String normalizeHeader(String header) {
|
|
|
|
|
|
return header == null ? "" : header.replace(" ", "").trim();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isSameAmount(BigDecimal left, BigDecimal right) {
|
|
|
|
|
|
if (left == null && right == null) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (left == null || right == null) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return left.compareTo(right) == 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private BigDecimal parseAmount(String value) {
|
|
|
|
|
|
if (StringUtils.isBlank(value)) {
|
|
|
|
|
|
return BigDecimal.ZERO;
|
|
|
|
|
|
}
|
|
|
|
|
|
String normalizedValue = value.replace(",", "").trim();
|
|
|
|
|
|
try {
|
|
|
|
|
|
return new BigDecimal(normalizedValue);
|
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
|
log.warn("解析数字失败,value:{}", value);
|
|
|
|
|
|
return BigDecimal.ZERO;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isRowEmpty(Row row) {
|
|
|
|
|
|
if (row == null) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
short firstCellNum = row.getFirstCellNum();
|
|
|
|
|
|
short lastCellNum = row.getLastCellNum();
|
|
|
|
|
|
if (firstCellNum < 0 || lastCellNum < 0) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
for (int i = firstCellNum; i < lastCellNum; i++) {
|
|
|
|
|
|
Cell cell = row.getCell(i, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
|
|
|
|
|
if (cell == null) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (cell.getCellType() != CellType.BLANK) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static class ImportSummary {
|
|
|
|
|
|
private int totalRows;
|
|
|
|
|
|
private int successRows;
|
|
|
|
|
|
private int skippedRows;
|
|
|
|
|
|
private int failedRows;
|
|
|
|
|
|
private Date minPayTime;
|
|
|
|
|
|
private Date maxPayTime;
|
|
|
|
|
|
|
|
|
|
|
|
private void updatePayTimeRange(Date payTime) {
|
|
|
|
|
|
if (payTime == null) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (minPayTime == null || payTime.before(minPayTime)) {
|
|
|
|
|
|
minPayTime = payTime;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (maxPayTime == null || payTime.after(maxPayTime)) {
|
|
|
|
|
|
maxPayTime = payTime;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String toString() {
|
|
|
|
|
|
return "{"
|
|
|
|
|
|
+ "\"totalRows\":" + totalRows
|
|
|
|
|
|
+ ", \"successRows\":" + successRows
|
|
|
|
|
|
+ ", \"skippedRows\":" + skippedRows
|
|
|
|
|
|
+ ", \"failedRows\":" + failedRows
|
|
|
|
|
|
+ ", \"minPayTime\":\"" + (minPayTime == null ? "" : DateUtils.formatDateTime(minPayTime)) + "\""
|
|
|
|
|
|
+ ", \"maxPayTime\":\"" + (maxPayTime == null ? "" : DateUtils.formatDateTime(maxPayTime)) + "\""
|
|
|
|
|
|
+ "}";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-18 13:33:26 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* V1方法,获取退款金额与结算金额
|
|
|
|
|
|
* @param batchNum
|
|
|
|
|
|
*/
|
|
|
|
|
|
private void processUnSettledOrderV1(int batchNum) {
|
2025-11-14 14:48:15 +08:00
|
|
|
|
String startTime = "2025-01-01 00:00:00";
|
|
|
|
|
|
String endTime = "2025-12-31 23:59:59";
|
|
|
|
|
|
|
|
|
|
|
|
// 查询未分帐订单
|
|
|
|
|
|
PageUtils.startPage(1, 1000);
|
2025-11-14 15:07:50 +08:00
|
|
|
|
List<AdapayUnsplitRecord> list = adapayUnsplitRecordService.queryUnsplitOrders(startTime, endTime);
|
2025-11-14 16:13:31 +08:00
|
|
|
|
log.info("第{}批次,共查询到{}条数据", batchNum, list.size());
|
2025-11-14 15:07:50 +08:00
|
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
2025-04-17 13:46:12 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-14 15:07:50 +08:00
|
|
|
|
// 转为map, key:orderCode, value:AdapayUnsplitRecord
|
2025-11-14 16:20:05 +08:00
|
|
|
|
Map<String, AdapayUnsplitRecord> map = list.stream().collect(Collectors.toMap(AdapayUnsplitRecord::getOrderCode, v -> v, (k1, k2) -> k1));
|
2025-11-14 15:07:50 +08:00
|
|
|
|
|
|
|
|
|
|
// 取keySet
|
|
|
|
|
|
Set<String> orderCodes = map.keySet();
|
|
|
|
|
|
|
|
|
|
|
|
// 查询订单的退款金额与结算金额
|
|
|
|
|
|
List<OrderBasicInfo> orderList = orderBasicInfoService.selectOrderTemp(orderCodes);
|
|
|
|
|
|
// 转为map, key:orderCode, value:OrderBasicInfo
|
2025-11-14 16:20:05 +08:00
|
|
|
|
Map<String, OrderBasicInfo> orderMap = orderList.stream().collect(Collectors.toMap(OrderBasicInfo::getOrderCode, v -> v, (k1, k2) -> k1));
|
2025-11-14 15:07:50 +08:00
|
|
|
|
|
|
|
|
|
|
List<AdapayUnsplitRecord> updateList = new ArrayList<>();
|
|
|
|
|
|
//更新map
|
|
|
|
|
|
for (String orderCode : orderCodes) {
|
|
|
|
|
|
OrderBasicInfo orderBasicInfo = orderMap.get(orderCode);
|
2025-11-14 15:54:01 +08:00
|
|
|
|
if (Objects.isNull(orderBasicInfo)) {
|
|
|
|
|
|
// log.error("未查询到订单:{}", orderCode);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2025-11-14 15:07:50 +08:00
|
|
|
|
AdapayUnsplitRecord adapayUnsplitRecord = map.get(orderCode);
|
|
|
|
|
|
adapayUnsplitRecord.setDueRefundAmount(orderBasicInfo.getRefundAmount());
|
|
|
|
|
|
adapayUnsplitRecord.setSettleAmount(orderBasicInfo.getSettleAmount());
|
2025-11-14 15:44:24 +08:00
|
|
|
|
String pileSn = orderBasicInfo.getPileSn();
|
|
|
|
|
|
adapayUnsplitRecord.setPileType(YouDianUtils.isEBikePileSn(pileSn) ? "eBike" : "EV");
|
2025-11-14 15:07:50 +08:00
|
|
|
|
updateList.add(adapayUnsplitRecord);
|
2025-04-16 15:50:26 +08:00
|
|
|
|
}
|
2025-11-14 15:07:50 +08:00
|
|
|
|
adapayUnsplitRecordService.updateBatchSelective(updateList);
|
2025-11-14 16:13:31 +08:00
|
|
|
|
log.info("第{}批次,共更新{}条数据", batchNum, updateList.size());
|
2025-04-16 15:50:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-19 11:55:05 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 更新adapay_unsplit_record表, 去汇付查询最新的数据
|
|
|
|
|
|
* @param batchNum
|
|
|
|
|
|
*/
|
2025-11-18 13:33:26 +08:00
|
|
|
|
private void processUnSettledOrderV2(int batchNum) {
|
2025-11-19 11:55:05 +08:00
|
|
|
|
String startTime = "2025-01-01 00:00:00";
|
|
|
|
|
|
String endTime = "2025-12-31 23:59:59";
|
2025-11-18 13:33:26 +08:00
|
|
|
|
|
2025-11-19 11:55:05 +08:00
|
|
|
|
// 查询未分帐订单
|
|
|
|
|
|
PageUtils.startPage(1, 3);
|
|
|
|
|
|
List<AdapayUnsplitRecord> list = adapayUnsplitRecordService.queryUnsplitOrders(startTime, endTime);
|
|
|
|
|
|
|
|
|
|
|
|
// 根据paymentId去汇付查询最新数据
|
|
|
|
|
|
for (AdapayUnsplitRecord adapayUnsplitRecord : list) {
|
|
|
|
|
|
String paymentId = adapayUnsplitRecord.getPaymentId();
|
|
|
|
|
|
|
|
|
|
|
|
QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO();
|
|
|
|
|
|
dto.setWechatAppId(Constants.DEFAULT_APP_ID);
|
|
|
|
|
|
dto.setPaymentId(paymentId);
|
|
|
|
|
|
QueryPaymentConfirmDetailResponse response = adapayService.queryPaymentConfirmList(dto);
|
|
|
|
|
|
System.out.println(JSON.toJSONString(response));
|
|
|
|
|
|
}
|
2025-11-18 13:33:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-04 16:37:58 +08:00
|
|
|
|
public void updateOrderReview() {
|
|
|
|
|
|
LocalDate yesterday = DateUtils.getYesterday();
|
|
|
|
|
|
LocalDateTime start = yesterday.atStartOfDay();
|
|
|
|
|
|
LocalDateTime end = yesterday.atTime(23, 59, 59);
|
2026-02-05 14:51:20 +08:00
|
|
|
|
|
|
|
|
|
|
orderBasicInfoService.updateOrderReviewFlagTemp(start, end, null);
|
2026-02-04 16:37:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-14 15:07:50 +08:00
|
|
|
|
// private void processUnSettledOrderOld() {
|
|
|
|
|
|
// String startTime = "2023-01-01 00:00:00";
|
|
|
|
|
|
// String endTime = "2024-12-31 23:59:59";
|
|
|
|
|
|
//
|
|
|
|
|
|
// // 使用redis控制请求api
|
|
|
|
|
|
// Boolean setnx = redisCache.setnx(CacheConstants.PROCESS_UNSPLIT_ORDERS, Constants.ONE, 65);
|
|
|
|
|
|
// if (!setnx) {
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// // 查询未分帐订单
|
|
|
|
|
|
// PageUtils.startPage(1, 10);
|
|
|
|
|
|
// List<OrderUnsplitRecord> list = orderUnsplitRecordService.queryUnsplitOrders(startTime, endTime);
|
|
|
|
|
|
//
|
|
|
|
|
|
// log.info("处理未分帐订单start, 当前时间:{}, 查询出[{}]条未分账订单, 下面进行处理", DateUtils.getDateTime(), list.size());
|
|
|
|
|
|
// int count = 0;
|
|
|
|
|
|
// for (OrderUnsplitRecord orderUnsplitRecord : list) {
|
|
|
|
|
|
// String paymentId = orderUnsplitRecord.getPaymentId();
|
|
|
|
|
|
// String orderCode = orderUnsplitRecord.getOrderCode();
|
|
|
|
|
|
// BigDecimal confirmAmt = orderUnsplitRecord.getSettleAmount();
|
|
|
|
|
|
//
|
|
|
|
|
|
// DivMember divMember = new DivMember();
|
|
|
|
|
|
// divMember.setMemberId(Constants.ZERO); // 若是商户本身时,传入0
|
|
|
|
|
|
// divMember.setAmount(AdapayUtil.formatAmount(confirmAmt));
|
|
|
|
|
|
// divMember.setFeeFlag(Constants.Y);
|
|
|
|
|
|
//
|
|
|
|
|
|
// PaymentConfirmParam param = PaymentConfirmParam.builder()
|
|
|
|
|
|
// .paymentId(paymentId)
|
|
|
|
|
|
// .divMemberList(Lists.newArrayList(divMember))
|
|
|
|
|
|
// .confirmAmt(confirmAmt)
|
|
|
|
|
|
// .orderCode(orderCode)
|
|
|
|
|
|
// .wechatAppId(Constants.DEFAULT_APP_ID) // 默认使用万车充的appId
|
|
|
|
|
|
// .build();
|
|
|
|
|
|
// // 延时分账,使用确认交易API
|
|
|
|
|
|
// PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequest(param);
|
|
|
|
|
|
//
|
|
|
|
|
|
// // 如果确认交易成功,则更新订单状态为已分账
|
|
|
|
|
|
// if (paymentConfirmResponse.isSuccess()) {
|
|
|
|
|
|
// count++;
|
|
|
|
|
|
// orderUnsplitRecord.setStatus(AdapayStatusEnum.SUCCEEDED.getValue());
|
|
|
|
|
|
// orderUnsplitRecordService.updateOrderUnsplitRecord(orderUnsplitRecord);
|
|
|
|
|
|
// log.info("processUnsplitOrders, 分账成功, paymentId:{}", paymentId);
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// // error_type:api_error, error_code:confirm_amt_over_limit, error_msg当前确认金额 > 支付金额 - 已支付确认金额 - 已支付撤销金额
|
|
|
|
|
|
// if (paymentConfirmResponse.getError_code().equals("confirm_amt_over_limit")) {
|
|
|
|
|
|
// // 查询paymentId的总分账金额
|
|
|
|
|
|
// BigDecimal totalSplitAmount;
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// totalSplitAmount = adapayService.getTotalSplitAmountByPaymentId(paymentId);
|
|
|
|
|
|
// } catch (BaseAdaPayException e) {
|
|
|
|
|
|
// throw new RuntimeException(e);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (totalSplitAmount.compareTo(confirmAmt) == 0) {
|
|
|
|
|
|
// // 如果总分账金额等于当前分账金额,则更新订单状态为已分账
|
|
|
|
|
|
// orderUnsplitRecord.setStatus(AdapayStatusEnum.SUCCEEDED.getValue());
|
|
|
|
|
|
// orderUnsplitRecordService.updateOrderUnsplitRecord(orderUnsplitRecord);
|
|
|
|
|
|
// log.info("processUnsplitOrders, 分账成功, paymentId:{}", paymentId);
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// log.info("processUnsplitOrders, 分账失败, paymentId:{}, 错误信息:{}", paymentId, paymentConfirmResponse.getError_msg());
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// // error_type:invalid_request_error, error_code:payment_over_time_doing, error_msg:数据正在处理中,请稍后再试
|
|
|
|
|
|
// if (paymentConfirmResponse.getError_code().equals("payment_over_time_doing")) {
|
|
|
|
|
|
// log.info("processUnsplitOrders, 分账失败, paymentId:{}, 错误信息:{}", paymentId, paymentConfirmResponse.getError_msg());
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // error_type:invalid_request_error, error_code:refund_repeate_request, error_msg:请求过于频繁
|
|
|
|
|
|
// if (paymentConfirmResponse.getError_code().equals("refund_repeate_request")) {
|
|
|
|
|
|
// log.info("processUnsplitOrders, 分账失败, paymentId:{}, 错误信息:{}", paymentId, paymentConfirmResponse.getError_msg());
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// log.info("处理未分帐订单end, 当前时间:[{}], 成功分账[{}]条订单", DateUtils.getDateTime(), count);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|