分期缴款,计算每期最低缴款金额(负数则本期最低缴款0万元)、最高可缴纳金额
//应缴金额 w(万元) 认购金额+认购费
// Integer total = 130 + 10;
Integer total = getTotalAmount();
//实缴金额 含认购费 首期/全款 paidIn为空对象
// List<Integer> paidIn = new ArrayList<>();
// paidIn.add(50 + 10);
//实缴金额 含认购费 首期/全款 paidIn为空对象
List<Integer> paidIn = getPaidInList();
if (paidIn == null) {
paidIn = new ArrayList<>();
}
//分期/全款(due只有一条)应缴金额 //首期/全款含认购费
// List<Integer> due = new ArrayList<>();
// due.add(30 + 10);
// due.add(30);
// due.add(20);
// due.add(40);
// due.add(10);
List<Integer> due = getDueList();
if (due == null) {
due = new ArrayList<>();
}
int paidInSize = paidIn.size();
int duSize = due.size();
if (paidInSize > duSize || paidInSize == duSize) {
throw new BizException("订单缴款完成,无需再次缴款!");
}
//实缴总金额
Integer paidInTotal = paidIn.stream().reduce(Integer::sum).orElseGet(() -> 0);
//当前最高可缴纳金额
int i = total - paidInTotal;
System.out.println("当前最高可缴纳金额:" + i + "w");
int stages = 0;
//本期应缴金额,不分期时
if (duSize == 1) {
System.out.println("不分期 应/最低缴纳金额:" + i + "w");
}
//分期时
else {
//如果等于则证明只剩最后一期需要缴纳
boolean b = paidInSize + 1 < duSize;
if (b) {
// 应实缴金额 - 实缴金额 - 当期以后的金额总数
stages = total - paidInTotal - due.subList(paidInSize + 1, duSize).stream().reduce(Integer::sum).orElseGet(() -> 0);
} else {
// 应实缴金额 - 实缴金额 - 最后一期的金额
stages = total - paidInTotal;
}
System.out.println(paidInSize + 1 + "期,应该/最低缴纳金额为:" + Math.max(stages, 0) + "w");
}