...
|
...
|
@@ -69,64 +69,60 @@ public class InviteSettlementUtils { |
|
|
LocalDateTime afterFiveMonth = calculateStartTime.plusMonths(5);
|
|
|
|
|
|
// 被邀请来年元旦
|
|
|
LocalDateTime calculateFinnalEndTime = LocalDateTime.of(LocalDate.of(inviteTime.getYear() + 1, 1, 1), LocalTime.MIN);
|
|
|
LocalDateTime calculateFinalEndTime = LocalDateTime.of(LocalDate.of(inviteTime.getYear() + 1, 1, 1), LocalTime.MIN);
|
|
|
|
|
|
BiPredicate<InviteSettlementItem, LocalDateTime> iaAfterOrEqual = (item, month) -> {
|
|
|
LocalDateTime createTime = newLocalDateTimeOfEpochSecond(item.getCreateTime());
|
|
|
return createTime.isAfter(month) || createTime.isEqual(month);
|
|
|
};
|
|
|
|
|
|
// 一个月内无需结算
|
|
|
if (settleTime.isBefore(afterOneMonth)) {
|
|
|
return Pair.of(BigDecimal.ZERO, items);
|
|
|
}
|
|
|
|
|
|
|
|
|
// 一个月内结算金额
|
|
|
BigDecimal inOneMonthTotalSettleAmount = items.stream()
|
|
|
.filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(afterOneMonth))
|
|
|
.map(InviteSettlementItem::getOrderAmount)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
.multiply(BigDecimal.valueOf(0.02));
|
|
|
|
|
|
// 五个月内只结算1个月内的订单
|
|
|
if (settleTime.isBefore(afterFiveMonth)) {
|
|
|
// 五个月内
|
|
|
else if (settleTime.isBefore(afterFiveMonth)) {
|
|
|
return Pair.of(
|
|
|
inOneMonthTotalSettleAmount,
|
|
|
calculateInOneMountTotalSettleAmountOfType2(items, afterOneMonth),
|
|
|
items.stream().filter(item -> iaAfterOrEqual.test(item, afterOneMonth)).collect(Collectors.toList())
|
|
|
);
|
|
|
}
|
|
|
|
|
|
// 五个月内结算金额
|
|
|
BigDecimal inFiveMonthTotalSettleAmount;
|
|
|
BigDecimal inFiveMonthTotalOrderAmount = items.stream()
|
|
|
.filter(item -> iaAfterOrEqual.test(item, afterOneMonth))
|
|
|
.filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(calculateFinnalEndTime.isBefore(afterFiveMonth) ? calculateFinnalEndTime : afterFiveMonth))
|
|
|
.map(InviteSettlementItem::getOrderAmount)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(100_0000)) < 0) {
|
|
|
inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.ZERO);
|
|
|
} else if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(180_0000)) <= 0) {
|
|
|
inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.008));
|
|
|
} else if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(300_0000)) <= 0) {
|
|
|
inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.015));
|
|
|
} else {
|
|
|
inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.020));
|
|
|
}
|
|
|
|
|
|
// 五个月以后,1年内只结算五个月内的订单
|
|
|
if (settleTime.isBefore(afterFiveMonth)) {
|
|
|
return Pair.of(
|
|
|
inOneMonthTotalSettleAmount.add(inFiveMonthTotalSettleAmount),
|
|
|
items.stream().filter(item -> iaAfterOrEqual.test(item, calculateFinnalEndTime.isBefore(afterFiveMonth) ? calculateFinnalEndTime : afterFiveMonth)).collect(Collectors.toList())
|
|
|
);
|
|
|
// 五个月后
|
|
|
else {
|
|
|
if (afterFiveMonth.isBefore(calculateFinalEndTime)) {
|
|
|
// 年底前
|
|
|
if (settleTime.isBefore(calculateFinalEndTime)) {
|
|
|
return Pair.of(
|
|
|
calculateInOneMountTotalSettleAmountOfType2(items, afterOneMonth)
|
|
|
.add(calculateInFiveMountTotalSettleAmountOfType2(items, afterOneMonth, afterFiveMonth, iaAfterOrEqual)),
|
|
|
items.stream().filter(item -> iaAfterOrEqual.test(item, afterFiveMonth)).collect(Collectors.toList())
|
|
|
);
|
|
|
}
|
|
|
// 年后
|
|
|
else {
|
|
|
return Pair.of(
|
|
|
calculateInOneMountTotalSettleAmountOfType2(items, afterOneMonth)
|
|
|
.add(calculateInFiveMountTotalSettleAmountOfType2(items, afterOneMonth, afterFiveMonth, iaAfterOrEqual))
|
|
|
.add(calculateOutFiveMountTotalSettleAmountOfType2(items, afterFiveMonth, calculateFinalEndTime, iaAfterOrEqual)),
|
|
|
items.stream().filter(item -> iaAfterOrEqual.test(item, calculateFinalEndTime)).collect(Collectors.toList())
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
// 五个月后,已经到了下一年
|
|
|
else {
|
|
|
return Pair.of(
|
|
|
calculateInOneMountTotalSettleAmountOfType2(items, afterOneMonth)
|
|
|
.add(calculateInFiveMountTotalSettleAmountOfType2(items, afterOneMonth, calculateFinalEndTime, iaAfterOrEqual)),
|
|
|
items.stream().filter(item -> iaAfterOrEqual.test(item, calculateFinalEndTime)).collect(Collectors.toList())
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 五个月以后结算金额
|
|
|
private static BigDecimal calculateOutFiveMountTotalSettleAmountOfType2(List<InviteSettlementItem> items, LocalDateTime afterFiveMonth, LocalDateTime calculateEndTime, BiPredicate<InviteSettlementItem, LocalDateTime> iaAfterOrEqual) {
|
|
|
BigDecimal outFiveMonthTotalSettleAmount;
|
|
|
BigDecimal outFiveMonthTotalOrderAmount = items.stream()
|
|
|
.filter(item -> iaAfterOrEqual.test(item, afterFiveMonth))
|
|
|
.filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(calculateFinnalEndTime))
|
|
|
.filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(calculateEndTime))
|
|
|
.map(InviteSettlementItem::getOrderAmount)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
if (outFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(180_0000)) < 0) {
|
...
|
...
|
@@ -138,11 +134,34 @@ public class InviteSettlementUtils { |
|
|
} else {
|
|
|
outFiveMonthTotalSettleAmount = outFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.018));
|
|
|
}
|
|
|
return outFiveMonthTotalSettleAmount;
|
|
|
}
|
|
|
|
|
|
private static BigDecimal calculateInFiveMountTotalSettleAmountOfType2(List<InviteSettlementItem> items, LocalDateTime afterOneMonth, LocalDateTime calculateEndTime, BiPredicate<InviteSettlementItem, LocalDateTime> iaAfterOrEqual) {
|
|
|
BigDecimal inFiveMonthTotalSettleAmount;
|
|
|
BigDecimal inFiveMonthTotalOrderAmount = items.stream()
|
|
|
.filter(item -> iaAfterOrEqual.test(item, afterOneMonth))
|
|
|
.filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(calculateEndTime))
|
|
|
.map(InviteSettlementItem::getOrderAmount)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(100_0000)) < 0) {
|
|
|
inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.ZERO);
|
|
|
} else if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(180_0000)) <= 0) {
|
|
|
inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.008));
|
|
|
} else if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(300_0000)) <= 0) {
|
|
|
inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.015));
|
|
|
} else {
|
|
|
inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.020));
|
|
|
}
|
|
|
return inFiveMonthTotalSettleAmount;
|
|
|
}
|
|
|
|
|
|
return Pair.of(
|
|
|
inOneMonthTotalSettleAmount.add(inFiveMonthTotalSettleAmount).add(outFiveMonthTotalSettleAmount),
|
|
|
items.stream().filter(item -> iaAfterOrEqual.test(item, calculateFinnalEndTime)).collect(Collectors.toList())
|
|
|
);
|
|
|
private static BigDecimal calculateInOneMountTotalSettleAmountOfType2(List<InviteSettlementItem> items, LocalDateTime afterOneMonth) {
|
|
|
return items.stream()
|
|
|
.filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(afterOneMonth))
|
|
|
.map(InviteSettlementItem::getOrderAmount)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
.multiply(BigDecimal.valueOf(0.02));
|
|
|
}
|
|
|
|
|
|
public static ZoneOffset zoneOffset() {
|
...
|
...
|
|