充值抵扣数据统计逻辑: 账期>=启用日期月份,抵扣日期<启用日期,最后将结果按账期到期日结转应收单 使用java写一个案例
时间: 2023-11-27 13:50:44 浏览: 125
假设有一个充值抵扣的数据表,表名为recharge_deduction,包含以下字段:
- id:充值抵扣的记录id
- user_id:用户id
- recharge_amount:充值金额
- deduction_amount:抵扣金额
- recharge_date:充值日期
- deduction_date:抵扣日期
现在需要统计账期>=启用日期月份,抵扣日期<启用日期的数据,并将结果按账期到期日结转应收单。下面是一个用Java实现的例子:
```java
import java.time.LocalDate;
import java.util.List;
public class RechargeDeductionStatistics {
// 启用日期
private LocalDate enableDate;
// 账期到期日
private LocalDate dueDate;
// 充值抵扣数据列表
private List<RechargeDeduction> data;
public RechargeDeductionStatistics(LocalDate enableDate, LocalDate dueDate, List<RechargeDeduction> data) {
this.enableDate = enableDate;
this.dueDate = dueDate;
this.data = data;
}
// 统计数据并返回应收单列表
public List<Receivable> statistics() {
// 初始化应收单列表
List<Receivable> receivables = new ArrayList<>();
// 遍历充值抵扣数据列表
for (RechargeDeduction item : data) {
// 判断是否符合统计条件
if (item.getDeductionDate().isBefore(enableDate) && item.getRechargeDate().plusMonths(1).isAfter(enableDate)) {
// 按照账期到期日生成应收单
Receivable receivable = new Receivable(item.getUserId(), item.getDeductionAmount(), dueDate);
receivables.add(receivable);
}
}
return receivables;
}
}
// 充值抵扣记录类
class RechargeDeduction {
private long id;
private long userId;
private double rechargeAmount;
private double deductionAmount;
private LocalDate rechargeDate;
private LocalDate deductionDate;
public RechargeDeduction(long id, long userId, double rechargeAmount, double deductionAmount, LocalDate rechargeDate, LocalDate deductionDate) {
this.id = id;
this.userId = userId;
this.rechargeAmount = rechargeAmount;
this.deductionAmount = deductionAmount;
this.rechargeDate = rechargeDate;
this.deductionDate = deductionDate;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public double getRechargeAmount() {
return rechargeAmount;
}
public void setRechargeAmount(double rechargeAmount) {
this.rechargeAmount = rechargeAmount;
}
public double getDeductionAmount() {
return deductionAmount;
}
public void setDeductionAmount(double deductionAmount) {
this.deductionAmount = deductionAmount;
}
public LocalDate getRechargeDate() {
return rechargeDate;
}
public void setRechargeDate(LocalDate rechargeDate) {
this.rechargeDate = rechargeDate;
}
public LocalDate getDeductionDate() {
return deductionDate;
}
public void setDeductionDate(LocalDate deductionDate) {
this.deductionDate = deductionDate;
}
}
// 应收单类
class Receivable {
private long userId;
private double amount;
private LocalDate dueDate;
public Receivable(long userId, double amount, LocalDate dueDate) {
this.userId = userId;
this.amount = amount;
this.dueDate = dueDate;
}
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public LocalDate getDueDate() {
return dueDate;
}
public void setDueDate(LocalDate dueDate) {
this.dueDate = dueDate;
}
}
```
使用方法:
```java
// 假设启用日期为2021年4月1日,账期到期日为2021年5月31日
LocalDate enableDate = LocalDate.of(2021, 4, 1);
LocalDate dueDate = LocalDate.of(2021, 5, 31);
// 假设充值抵扣数据列表已经准备好
List<RechargeDeduction> data = ...
// 创建充值抵扣统计对象
RechargeDeductionStatistics statistics = new RechargeDeductionStatistics(enableDate, dueDate, data);
// 统计数据并获取应收单列表
List<Receivable> receivables = statistics.statistics();
```
阅读全文