|
|
@@ -186,7 +186,6 @@ public class ElderlyAskLeaveServiceImpl implements ElderlyAskLeaveService {
|
|
|
private void processRefundItem(ElderlyAskLeaveDO elderlyAskLeaveDO, OutboundRefundItemDO item,
|
|
|
LocalDate outLocalDate, LocalDate endLocalDate, int totalDays,
|
|
|
OutboundRefundConfigDO config) {
|
|
|
- String configName = config.getName();
|
|
|
// 获取退费规则
|
|
|
RefundRule rule = getRefundRule(config, item);
|
|
|
|
|
|
@@ -306,7 +305,7 @@ public class ElderlyAskLeaveServiceImpl implements ElderlyAskLeaveService {
|
|
|
|
|
|
// 根据退费类型处理(传入实际退费开始的日期,用于计算归属月份)
|
|
|
processRefundByType(elderlyAskLeaveDO, item, expenseItemDO,
|
|
|
- adjustedStart, adjustedEnd, overlapDays, adjustedIncludeEndDay, configName, adjustedStart);
|
|
|
+ adjustedStart, adjustedEnd, overlapDays, adjustedIncludeEndDay, config, adjustedStart);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -399,31 +398,34 @@ public class ElderlyAskLeaveServiceImpl implements ElderlyAskLeaveService {
|
|
|
*/
|
|
|
private void processRefundByType(ElderlyAskLeaveDO elderlyAskLeaveDO, OutboundRefundItemDO outboundRefundItem,
|
|
|
ExpenseItemDO expenseItemDO, LocalDate startDate, LocalDate endDate,
|
|
|
- int refundDays, boolean includeEndDay, String configName, LocalDate actualRefundStartDate) {
|
|
|
+ int refundDays, boolean includeEndDay, OutboundRefundConfigDO config, LocalDate actualRefundStartDate) {
|
|
|
+
|
|
|
+ boolean isAutoCross = config.getIsAutoCross() == null || Objects.equals(config.getIsAutoCross(), 1);
|
|
|
+ String configName = config.getName();
|
|
|
|
|
|
if (Objects.equals(outboundRefundItem.getType(), 1)) {
|
|
|
// 固定金额退费
|
|
|
- processFixedAmountRefund(elderlyAskLeaveDO, outboundRefundItem, startDate, endDate, refundDays, includeEndDay, configName, actualRefundStartDate);
|
|
|
+ processFixedAmountRefund(elderlyAskLeaveDO, outboundRefundItem, startDate, endDate, refundDays, includeEndDay, configName, actualRefundStartDate, isAutoCross);
|
|
|
} else if (outboundRefundItem.getType() == 2) {
|
|
|
// 比例退费
|
|
|
- processProportionalRefund(elderlyAskLeaveDO, outboundRefundItem, startDate, endDate, refundDays, includeEndDay, configName, actualRefundStartDate);
|
|
|
+ processProportionalRefund(elderlyAskLeaveDO, outboundRefundItem, startDate, endDate, refundDays, includeEndDay, configName, actualRefundStartDate, isAutoCross);
|
|
|
} else {
|
|
|
// 按月份天数计算
|
|
|
processMonthlyRefunds(elderlyAskLeaveDO, outboundRefundItem, expenseItemDO,
|
|
|
- startDate, endDate, refundDays, includeEndDay, configName, actualRefundStartDate);
|
|
|
+ startDate, endDate, refundDays, includeEndDay, configName, actualRefundStartDate, isAutoCross);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void processFixedAmountRefund(ElderlyAskLeaveDO elderlyAskLeaveDO, OutboundRefundItemDO outboundRefundItem,
|
|
|
- LocalDate startDate, LocalDate endDate, int refundDays, boolean includeEndDay, String configName, LocalDate actualRefundStartDate) {
|
|
|
+ LocalDate startDate, LocalDate endDate, int refundDays, boolean includeEndDay, String configName, LocalDate actualRefundStartDate, boolean isAutoCross) {
|
|
|
BigDecimal dailyAmount = resolveCustomAmount(outboundRefundItem, outboundRefundItem.getAmount());
|
|
|
|
|
|
// 判断是否跨月
|
|
|
YearMonth startMonth = YearMonth.from(startDate);
|
|
|
YearMonth endMonth = YearMonth.from(endDate);
|
|
|
|
|
|
- if (startMonth.equals(endMonth)) {
|
|
|
- // 不跨月,按原逻辑处理
|
|
|
+ if (startMonth.equals(endMonth) || !isAutoCross) {
|
|
|
+ // 不跨月(或不允许自动跨月),按原逻辑处理(所有费用合并到一条记录)
|
|
|
DailyExpensesDO dailyExpenses = createBaseExpenseRecord(elderlyAskLeaveDO, outboundRefundItem, startDate, endDate);
|
|
|
BigDecimal totalAmount = dailyAmount.multiply(BigDecimal.valueOf(refundDays)).setScale(8, RoundingMode.DOWN);
|
|
|
|
|
|
@@ -480,7 +482,7 @@ public class ElderlyAskLeaveServiceImpl implements ElderlyAskLeaveService {
|
|
|
}
|
|
|
|
|
|
private void processProportionalRefund(ElderlyAskLeaveDO elderlyAskLeaveDO, OutboundRefundItemDO outboundRefundItem,
|
|
|
- LocalDate startDate, LocalDate endDate, int refundDays, boolean includeEndDay, String configName, LocalDate actualRefundStartDate) {
|
|
|
+ LocalDate startDate, LocalDate endDate, int refundDays, boolean includeEndDay, String configName, LocalDate actualRefundStartDate, boolean isAutoCross) {
|
|
|
BigDecimal proportion = outboundRefundItem.getProportion();
|
|
|
|
|
|
// 获取费用项原价
|
|
|
@@ -500,8 +502,8 @@ public class ElderlyAskLeaveServiceImpl implements ElderlyAskLeaveService {
|
|
|
YearMonth startMonth = YearMonth.from(startDate);
|
|
|
YearMonth endMonth = YearMonth.from(endDate);
|
|
|
|
|
|
- if (startMonth.equals(endMonth)) {
|
|
|
- // 不跨月,按原逻辑处理
|
|
|
+ if (startMonth.equals(endMonth) || !isAutoCross) {
|
|
|
+ // 不跨月(或不允许自动跨月),按原逻辑处理(所有费用合并到一条记录)
|
|
|
DailyExpensesDO dailyExpenses = createBaseExpenseRecord(elderlyAskLeaveDO, outboundRefundItem, startDate, endDate);
|
|
|
BigDecimal totalAmount = dailyPrice.multiply(BigDecimal.valueOf(refundDays)).setScale(8, RoundingMode.DOWN);
|
|
|
|
|
|
@@ -561,8 +563,43 @@ public class ElderlyAskLeaveServiceImpl implements ElderlyAskLeaveService {
|
|
|
|
|
|
private void processMonthlyRefunds(ElderlyAskLeaveDO elderlyAskLeaveDO, OutboundRefundItemDO outboundRefundItem,
|
|
|
ExpenseItemDO expenseItemDO, LocalDate startDate, LocalDate endDate,
|
|
|
- int totalDays, boolean includeEndDay, String configName, LocalDate actualRefundStartDate) {
|
|
|
- // 按月份循环处理
|
|
|
+ int totalDays, boolean includeEndDay, String configName, LocalDate actualRefundStartDate, boolean isAutoCross) {
|
|
|
+ if (!isAutoCross) {
|
|
|
+ // 不自动跨月,所有费用生成在归属月中(一条记录)
|
|
|
+ YearMonth startYearMonth = YearMonth.from(startDate);
|
|
|
+ DailyExpensesDO dailyExpenses = createBaseExpenseRecord(elderlyAskLeaveDO, outboundRefundItem, startDate, endDate);
|
|
|
+
|
|
|
+ BigDecimal actualAmount = resolveCustomAmount(outboundRefundItem, expenseItemDO.getActualAmount());
|
|
|
+ BigDecimal calculateAmount = resolveCalculateAmount(outboundRefundItem, expenseItemDO.getActualAmount(), actualAmount);
|
|
|
+ BigDecimal dayPrice;
|
|
|
+ if (Objects.equals(expenseItemDO.getIsDayCalculate(), 1)) {
|
|
|
+ dayPrice = actualAmount;
|
|
|
+ } else {
|
|
|
+ dayPrice = calculateAmount.divide(BigDecimal.valueOf(startYearMonth.lengthOfMonth()), 5, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ BigDecimal monthAmount = dayPrice.multiply(BigDecimal.valueOf(totalDays)).setScale(2, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ dailyExpenses.setPrice(dayPrice);
|
|
|
+ dailyExpenses.setAmount(monthAmount.negate());
|
|
|
+ dailyExpenses.setCount(totalDays);
|
|
|
+
|
|
|
+ String attributionBillTime = calculateAttributionBillTime(elderlyAskLeaveDO, startYearMonth, actualRefundStartDate);
|
|
|
+ dailyExpenses.setAttributionBillTime(attributionBillTime);
|
|
|
+
|
|
|
+ String subtractMark = "";
|
|
|
+ if (Objects.equals(outboundRefundItem.getIsSubtract(), BooleanEnum.TRUE.getValue())) {
|
|
|
+ BigDecimal baseAmount = expenseItemDO.getActualAmount() == null ? BigDecimal.ZERO : expenseItemDO.getActualAmount();
|
|
|
+ subtractMark = "减底价,原始金额:" + baseAmount.setScale(2, RoundingMode.HALF_UP) + ",减底价后金额:" + calculateAmount.setScale(2, RoundingMode.HALF_UP) + ",";
|
|
|
+ }
|
|
|
+ String customMark = BooleanEnum.TRUE.getValue().equals(outboundRefundItem.getIsCustom()) ? "使用自定义金额,退费计算金额:" + actualAmount.setScale(2,RoundingMode.HALF_UP) + ",": "";
|
|
|
+ String endDayInfo = includeEndDay ? "包含最后一天" : "不包含最后一天";
|
|
|
+ dailyExpenses.setRemarks(subtractMark + customMark + configName + "退费:长者外出,退" + startDate + "到" + endDate + "的费用(共" + totalDays + "天," + endDayInfo + ")");
|
|
|
+
|
|
|
+ saveDailyExpenseAndAttachBill(elderlyAskLeaveDO, dailyExpenses);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按月份循环处理(自动跨月)
|
|
|
LocalDate currentDate = startDate;
|
|
|
while (!currentDate.isAfter(endDate)) {
|
|
|
YearMonth currentYearMonth = YearMonth.from(currentDate);
|