diff --git a/docs/evidence/rev004-accounting/late-fee-start-and-daily-recalculation-2026-06-30.md b/docs/evidence/rev004-accounting/late-fee-start-and-daily-recalculation-2026-06-30.md index 41f244c..fd01087 100644 --- a/docs/evidence/rev004-accounting/late-fee-start-and-daily-recalculation-2026-06-30.md +++ b/docs/evidence/rev004-accounting/late-fee-start-and-daily-recalculation-2026-06-30.md @@ -17,6 +17,7 @@ - `f7207fe61 feat: add daily late fee recalculation job` - `af05601f1 fix: harden late fee recalculation batch` - `3722c54fa fix: paginate late fee recalculation batches` +- `d551dba84 fix: handle late fee reversal and batch transactions` ## Implemented Files @@ -26,6 +27,7 @@ - `sw-business/sw-business-server/src/main/java/cn/com/emsoft/sw/business/service/charge/latefee/LateFeeBeginDateCalculator.java` - `sw-business/sw-business-server/src/main/java/cn/com/emsoft/sw/business/service/charge/latefee/LateFeeBeginDateApplyService.java` - `sw-business/sw-business-server/src/main/java/cn/com/emsoft/sw/business/service/charge/latefee/LateFeeDailyCalculator.java` +- `sw-business/sw-business-server/src/main/java/cn/com/emsoft/sw/business/service/charge/latefee/LateFeeRecalculationBatchService.java` - `sw-business/sw-business-server/src/main/java/cn/com/emsoft/sw/business/service/charge/latefee/LateFeeRecalculationService.java` - `sw-business/sw-business-server/src/main/java/cn/com/emsoft/sw/business/job/charge/LateFeeRecalculationJob.java` - `sw-business/sw-business-server/src/main/java/cn/com/emsoft/sw/business/config/ClockConfig.java` @@ -36,16 +38,19 @@ - `script/xxl-job-init.sql` - Unit tests under `sw-business/sw-business-server/src/test/java/cn/com/emsoft/sw/business/service/charge/latefee/` - `sw-business/sw-business-server/src/test/java/cn/com/emsoft/sw/business/service/charge/ChargeLateFeeBeginDateWiringTest.java` +- `sw-business/sw-business-server/src/test/java/cn/com/emsoft/sw/business/service/accountingadjust/pricediff/PriceDiffWriteBackServiceTest.java` ## Review Fixes -- Paid late-fee deduction now counts only `PaymentAllocationStatusEnum.APPLIED` late-fee payment details, so reversed positive details are not deducted again. +- Paid late-fee deduction excludes original `APPLIED` late-fee details that have a `REVERSED` detail referencing them through `relatedDetailId`. - The daily recalculation batch now selects unpaid charges with non-null `lateFeeBeginDate`, avoiding repeated starvation behind historical rows that cannot be recalculated. - `script/xxl-job-init.sql` registers handler `lateFeeDailyRecalculation` for business-server with cron `0 30 3 * * ?`. - `LateFeeRecalculationServiceTest` includes a defensive scenario where a reversed late-fee detail is returned by the mapper and ignored by aggregation. - The daily recalculation job now uses keyset pagination (`id > lastId`) until no eligible rows remain, so rows after the first page are recalculated in the same run instead of waiting forever behind unchanged earlier rows. - `LateFeeBeginDateApplyService` centralizes `lateFeeBeginDate` persistence and is reused by normal billing, manual charge creation, counter add-reading formalization, and special billing formalization before `chargeMapper.insert`. - Focused tests now cover the shared begin-date apply service, keyset pagination across batches, and direct insert path wiring for counter add-reading and special billing. +- Price-diff write-back now applies missing `lateFeeBeginDate` before inserting the replacement unpaid charge. +- Daily recalculation now keeps the outer pagination loop non-transactional and executes each page through `LateFeeRecalculationBatchService.recalculateBatch(...)` with its own transaction boundary. ## Verification @@ -54,20 +59,21 @@ Command: ```bash -mvn -pl sw-business/sw-business-server -am -Dtest=LateFeeBeginDateCalculatorTest,LateFeeBeginDateApplyServiceTest,LateFeeConfigResolverTest,LateFeeDailyCalculatorTest,LateFeeRecalculationServiceTest,ChargeLateFeeBeginDateWiringTest,CounterAddReadingApplicationServiceImplTest,SpecialBillingServiceImplTest -Dsurefire.failIfNoSpecifiedTests=false test +mvn -pl sw-business/sw-business-server -am -Dtest=LateFeeBeginDateCalculatorTest,LateFeeBeginDateApplyServiceTest,LateFeeConfigResolverTest,LateFeeDailyCalculatorTest,LateFeeRecalculationServiceTest,ChargeLateFeeBeginDateWiringTest,CounterAddReadingApplicationServiceImplTest,SpecialBillingServiceImplTest,PriceDiffWriteBackServiceTest -Dsurefire.failIfNoSpecifiedTests=false test ``` Result: PASS - `LateFeeBeginDateApplyServiceTest`: 2 tests, 0 failures, 0 errors, 0 skipped -- `LateFeeRecalculationServiceTest`: 5 tests, 0 failures, 0 errors, 0 skipped +- `LateFeeRecalculationServiceTest`: 7 tests, 0 failures, 0 errors, 0 skipped - `LateFeeConfigResolverTest`: 3 tests, 0 failures, 0 errors, 0 skipped - `LateFeeBeginDateCalculatorTest`: 7 tests, 0 failures, 0 errors, 0 skipped - `LateFeeDailyCalculatorTest`: 8 tests, 0 failures, 0 errors, 0 skipped - `ChargeLateFeeBeginDateWiringTest`: 5 tests, 0 failures, 0 errors, 0 skipped +- `PriceDiffWriteBackServiceTest`: 1 test, 0 failures, 0 errors, 0 skipped - `CounterAddReadingApplicationServiceImplTest`: 24 tests, 0 failures, 0 errors, 0 skipped - `SpecialBillingServiceImplTest`: 4 tests, 0 failures, 0 errors, 0 skipped -- Total: 58 tests, 0 failures, 0 errors, 0 skipped +- Total: 61 tests, 0 failures, 0 errors, 0 skipped ### Existing Accounting Regression Tests