Showing
1 changed file
with
63 additions
and
44 deletions
@@ -69,64 +69,60 @@ public class InviteSettlementUtils { | @@ -69,64 +69,60 @@ public class InviteSettlementUtils { | ||
69 | LocalDateTime afterFiveMonth = calculateStartTime.plusMonths(5); | 69 | LocalDateTime afterFiveMonth = calculateStartTime.plusMonths(5); |
70 | 70 | ||
71 | // 被邀请来年元旦 | 71 | // 被邀请来年元旦 |
72 | - LocalDateTime calculateFinnalEndTime = LocalDateTime.of(LocalDate.of(inviteTime.getYear() + 1, 1, 1), LocalTime.MIN); | 72 | + LocalDateTime calculateFinalEndTime = LocalDateTime.of(LocalDate.of(inviteTime.getYear() + 1, 1, 1), LocalTime.MIN); |
73 | 73 | ||
74 | BiPredicate<InviteSettlementItem, LocalDateTime> iaAfterOrEqual = (item, month) -> { | 74 | BiPredicate<InviteSettlementItem, LocalDateTime> iaAfterOrEqual = (item, month) -> { |
75 | LocalDateTime createTime = newLocalDateTimeOfEpochSecond(item.getCreateTime()); | 75 | LocalDateTime createTime = newLocalDateTimeOfEpochSecond(item.getCreateTime()); |
76 | return createTime.isAfter(month) || createTime.isEqual(month); | 76 | return createTime.isAfter(month) || createTime.isEqual(month); |
77 | }; | 77 | }; |
78 | - | ||
79 | // 一个月内无需结算 | 78 | // 一个月内无需结算 |
80 | if (settleTime.isBefore(afterOneMonth)) { | 79 | if (settleTime.isBefore(afterOneMonth)) { |
81 | return Pair.of(BigDecimal.ZERO, items); | 80 | return Pair.of(BigDecimal.ZERO, items); |
82 | } | 81 | } |
83 | - | ||
84 | - | ||
85 | - // 一个月内结算金额 | ||
86 | - BigDecimal inOneMonthTotalSettleAmount = items.stream() | ||
87 | - .filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(afterOneMonth)) | ||
88 | - .map(InviteSettlementItem::getOrderAmount) | ||
89 | - .reduce(BigDecimal.ZERO, BigDecimal::add) | ||
90 | - .multiply(BigDecimal.valueOf(0.02)); | ||
91 | - | ||
92 | - // 五个月内只结算1个月内的订单 | ||
93 | - if (settleTime.isBefore(afterFiveMonth)) { | 82 | + // 五个月内 |
83 | + else if (settleTime.isBefore(afterFiveMonth)) { | ||
94 | return Pair.of( | 84 | return Pair.of( |
95 | - inOneMonthTotalSettleAmount, | 85 | + calculateInOneMountTotalSettleAmountOfType2(items, afterOneMonth), |
96 | items.stream().filter(item -> iaAfterOrEqual.test(item, afterOneMonth)).collect(Collectors.toList()) | 86 | items.stream().filter(item -> iaAfterOrEqual.test(item, afterOneMonth)).collect(Collectors.toList()) |
97 | ); | 87 | ); |
98 | } | 88 | } |
99 | - | ||
100 | - // 五个月内结算金额 | ||
101 | - BigDecimal inFiveMonthTotalSettleAmount; | ||
102 | - BigDecimal inFiveMonthTotalOrderAmount = items.stream() | ||
103 | - .filter(item -> iaAfterOrEqual.test(item, afterOneMonth)) | ||
104 | - .filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(calculateFinnalEndTime.isBefore(afterFiveMonth) ? calculateFinnalEndTime : afterFiveMonth)) | ||
105 | - .map(InviteSettlementItem::getOrderAmount) | ||
106 | - .reduce(BigDecimal.ZERO, BigDecimal::add); | ||
107 | - if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(100_0000)) < 0) { | ||
108 | - inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.ZERO); | ||
109 | - } else if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(180_0000)) <= 0) { | ||
110 | - inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.008)); | ||
111 | - } else if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(300_0000)) <= 0) { | ||
112 | - inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.015)); | ||
113 | - } else { | ||
114 | - inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.020)); | ||
115 | - } | ||
116 | - | ||
117 | - // 五个月以后,1年内只结算五个月内的订单 | ||
118 | - if (settleTime.isBefore(afterFiveMonth)) { | ||
119 | - return Pair.of( | ||
120 | - inOneMonthTotalSettleAmount.add(inFiveMonthTotalSettleAmount), | ||
121 | - items.stream().filter(item -> iaAfterOrEqual.test(item, calculateFinnalEndTime.isBefore(afterFiveMonth) ? calculateFinnalEndTime : afterFiveMonth)).collect(Collectors.toList()) | ||
122 | - ); | 89 | + // 五个月后 |
90 | + else { | ||
91 | + if (afterFiveMonth.isBefore(calculateFinalEndTime)) { | ||
92 | + // 年底前 | ||
93 | + if (settleTime.isBefore(calculateFinalEndTime)) { | ||
94 | + return Pair.of( | ||
95 | + calculateInOneMountTotalSettleAmountOfType2(items, afterOneMonth) | ||
96 | + .add(calculateInFiveMountTotalSettleAmountOfType2(items, afterOneMonth, afterFiveMonth, iaAfterOrEqual)), | ||
97 | + items.stream().filter(item -> iaAfterOrEqual.test(item, afterFiveMonth)).collect(Collectors.toList()) | ||
98 | + ); | ||
99 | + } | ||
100 | + // 年后 | ||
101 | + else { | ||
102 | + return Pair.of( | ||
103 | + calculateInOneMountTotalSettleAmountOfType2(items, afterOneMonth) | ||
104 | + .add(calculateInFiveMountTotalSettleAmountOfType2(items, afterOneMonth, afterFiveMonth, iaAfterOrEqual)) | ||
105 | + .add(calculateOutFiveMountTotalSettleAmountOfType2(items, afterFiveMonth, calculateFinalEndTime, iaAfterOrEqual)), | ||
106 | + items.stream().filter(item -> iaAfterOrEqual.test(item, calculateFinalEndTime)).collect(Collectors.toList()) | ||
107 | + ); | ||
108 | + } | ||
109 | + } | ||
110 | + // 五个月后,已经到了下一年 | ||
111 | + else { | ||
112 | + return Pair.of( | ||
113 | + calculateInOneMountTotalSettleAmountOfType2(items, afterOneMonth) | ||
114 | + .add(calculateInFiveMountTotalSettleAmountOfType2(items, afterOneMonth, calculateFinalEndTime, iaAfterOrEqual)), | ||
115 | + items.stream().filter(item -> iaAfterOrEqual.test(item, calculateFinalEndTime)).collect(Collectors.toList()) | ||
116 | + ); | ||
117 | + } | ||
123 | } | 118 | } |
119 | + } | ||
124 | 120 | ||
125 | - // 五个月以后结算金额 | 121 | + private static BigDecimal calculateOutFiveMountTotalSettleAmountOfType2(List<InviteSettlementItem> items, LocalDateTime afterFiveMonth, LocalDateTime calculateEndTime, BiPredicate<InviteSettlementItem, LocalDateTime> iaAfterOrEqual) { |
126 | BigDecimal outFiveMonthTotalSettleAmount; | 122 | BigDecimal outFiveMonthTotalSettleAmount; |
127 | BigDecimal outFiveMonthTotalOrderAmount = items.stream() | 123 | BigDecimal outFiveMonthTotalOrderAmount = items.stream() |
128 | .filter(item -> iaAfterOrEqual.test(item, afterFiveMonth)) | 124 | .filter(item -> iaAfterOrEqual.test(item, afterFiveMonth)) |
129 | - .filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(calculateFinnalEndTime)) | 125 | + .filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(calculateEndTime)) |
130 | .map(InviteSettlementItem::getOrderAmount) | 126 | .map(InviteSettlementItem::getOrderAmount) |
131 | .reduce(BigDecimal.ZERO, BigDecimal::add); | 127 | .reduce(BigDecimal.ZERO, BigDecimal::add); |
132 | if (outFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(180_0000)) < 0) { | 128 | if (outFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(180_0000)) < 0) { |
@@ -138,11 +134,34 @@ public class InviteSettlementUtils { | @@ -138,11 +134,34 @@ public class InviteSettlementUtils { | ||
138 | } else { | 134 | } else { |
139 | outFiveMonthTotalSettleAmount = outFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.018)); | 135 | outFiveMonthTotalSettleAmount = outFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.018)); |
140 | } | 136 | } |
137 | + return outFiveMonthTotalSettleAmount; | ||
138 | + } | ||
139 | + | ||
140 | + private static BigDecimal calculateInFiveMountTotalSettleAmountOfType2(List<InviteSettlementItem> items, LocalDateTime afterOneMonth, LocalDateTime calculateEndTime, BiPredicate<InviteSettlementItem, LocalDateTime> iaAfterOrEqual) { | ||
141 | + BigDecimal inFiveMonthTotalSettleAmount; | ||
142 | + BigDecimal inFiveMonthTotalOrderAmount = items.stream() | ||
143 | + .filter(item -> iaAfterOrEqual.test(item, afterOneMonth)) | ||
144 | + .filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(calculateEndTime)) | ||
145 | + .map(InviteSettlementItem::getOrderAmount) | ||
146 | + .reduce(BigDecimal.ZERO, BigDecimal::add); | ||
147 | + if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(100_0000)) < 0) { | ||
148 | + inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.ZERO); | ||
149 | + } else if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(180_0000)) <= 0) { | ||
150 | + inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.008)); | ||
151 | + } else if (inFiveMonthTotalOrderAmount.compareTo(BigDecimal.valueOf(300_0000)) <= 0) { | ||
152 | + inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.015)); | ||
153 | + } else { | ||
154 | + inFiveMonthTotalSettleAmount = inFiveMonthTotalOrderAmount.multiply(BigDecimal.valueOf(0.020)); | ||
155 | + } | ||
156 | + return inFiveMonthTotalSettleAmount; | ||
157 | + } | ||
141 | 158 | ||
142 | - return Pair.of( | ||
143 | - inOneMonthTotalSettleAmount.add(inFiveMonthTotalSettleAmount).add(outFiveMonthTotalSettleAmount), | ||
144 | - items.stream().filter(item -> iaAfterOrEqual.test(item, calculateFinnalEndTime)).collect(Collectors.toList()) | ||
145 | - ); | 159 | + private static BigDecimal calculateInOneMountTotalSettleAmountOfType2(List<InviteSettlementItem> items, LocalDateTime afterOneMonth) { |
160 | + return items.stream() | ||
161 | + .filter(item -> newLocalDateTimeOfEpochSecond(item.getCreateTime()).isBefore(afterOneMonth)) | ||
162 | + .map(InviteSettlementItem::getOrderAmount) | ||
163 | + .reduce(BigDecimal.ZERO, BigDecimal::add) | ||
164 | + .multiply(BigDecimal.valueOf(0.02)); | ||
146 | } | 165 | } |
147 | 166 | ||
148 | public static ZoneOffset zoneOffset() { | 167 | public static ZoneOffset zoneOffset() { |
-
Please register or login to post a comment