smart-switch-java/smart-switch-service/src/main/java/com/ruoyi/task/reconciliationDate/ReconciliationDateTask.java
2025-02-06 10:35:55 +08:00

112 lines
4.7 KiB
Java

package com.ruoyi.task.reconciliationDate;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.dashboard.service.DashboardService;
import com.ruoyi.ss.channel.domain.vo.ChannelNameVO;
import com.ruoyi.ss.channel.service.ChannelService;
import com.ruoyi.ss.channelWithdraw.domain.vo.ChannelWithdrawNameVO;
import com.ruoyi.ss.channelWithdraw.service.ChannelWithdrawService;
import com.ruoyi.ss.reconciliationDate.domain.ReconciliationDate;
import com.ruoyi.ss.reconciliationDate.domain.enums.ReconciliationDateChannelType;
import com.ruoyi.ss.reconciliationDate.service.ReconciliationDateService;
import lombok.extern.slf4j.Slf4j;
@Component
@Slf4j
public class ReconciliationDateTask {
@Autowired
private DashboardService dashboardService;
@Autowired
private ReconciliationDateService reconciliationDateService;
@Autowired
private ChannelService channelService;
@Autowired
private ChannelWithdrawService channelWithdrawService;
public void recordReconciliationDate(Integer lastDays) {
// 获取昨日日期
LocalDate now = LocalDate.now();
LocalDate startDay = now.minusDays(lastDays);
// 查询所有支付渠道列表
List<ChannelNameVO> channelList = channelService.selectAllChannelNameList();
// 查询所有提现渠道列表
List<ChannelWithdrawNameVO> channelWithdrawList = channelWithdrawService.selectAllChannelNameList();
if (CollectionUtils.isEmptyElement(channelList) && CollectionUtils.isEmptyElement(channelWithdrawList)) {
log.error("渠道列表为空");
return;
}
while (now.isAfter(startDay)) {
// 支付渠道
for (ChannelNameVO channel : channelList) {
if (channel == null) {
continue;
}
this.insertReconciliationDate(startDay, channel.getChannelId(), ReconciliationDateChannelType.PAYMENT, channel.getName());
}
// 提现渠道
for (ChannelWithdrawNameVO channelWithdraw : channelWithdrawList) {
if (channelWithdraw == null) {
continue;
}
this.insertReconciliationDate(startDay, channelWithdraw.getChannelId(), ReconciliationDateChannelType.WITHDRAW, channelWithdraw.getName());
}
startDay = startDay.plusDays(1);
}
}
private void insertReconciliationDate(LocalDate startDay, Long channelId, ReconciliationDateChannelType channelType, String channelName) {
// 获取日期对账数据
ReconciliationDate po = dashboardService.selectReconciliationDateByDate(startDay, channelId, channelType, channelName);
if (po == null) {
log.error("{}对账数据不存在", startDay);
return;
}
if (this.isEmpty(po)) {
log.error("{}对账数据不存在", startDay);
return;
}
// 保存对账数据
int insert = reconciliationDateService.insertReconciliationDate(po);
if (insert != 1) {
log.error("保存对账数据失败,{}", po);
}
}
private boolean isEmpty(ReconciliationDate po) {
// 所有数值类型都为空或者0,则认为对账数据为空
return (po.getActualBonus() == null || po.getActualBonus().compareTo(BigDecimal.ZERO) == 0)
&& (po.getChannelCost() == null || po.getChannelCost().compareTo(BigDecimal.ZERO) == 0)
&& (po.getOrderAmount() == null || po.getOrderAmount().compareTo(BigDecimal.ZERO) == 0)
&& (po.getOrderReceiveAmount() == null || po.getOrderReceiveAmount().compareTo(BigDecimal.ZERO) == 0)
&& (po.getOrderTotalAmount() == null || po.getOrderTotalAmount().compareTo(BigDecimal.ZERO) == 0)
&& (po.getPlatformIncome() == null || po.getPlatformIncome().compareTo(BigDecimal.ZERO) == 0)
&& (po.getReceiveAmount() == null || po.getReceiveAmount().compareTo(BigDecimal.ZERO) == 0)
&& (po.getRefundAmount() == null || po.getRefundAmount().compareTo(BigDecimal.ZERO) == 0)
&& (po.getTotalBonus() == null || po.getTotalBonus().compareTo(BigDecimal.ZERO) == 0)
&& (po.getTotalBonusRefund() == null || po.getTotalBonusRefund().compareTo(BigDecimal.ZERO) == 0)
&& (po.getWithdrawAmount() == null || po.getWithdrawAmount().compareTo(BigDecimal.ZERO) == 0)
&& (po.getWithdrawServiceFee() == null || po.getWithdrawServiceFee().compareTo(BigDecimal.ZERO) == 0);
}
}