fix: 회계분개 멱등성 — 동일 정산월 재실행 시 분개 중복 INSERT 방지 (V87)

AccountingEntryGenerateStep(Step8b)이 selectBySettleMonth 결과를 무조건 insert 하여
동일 정산월 재정산 시 분개가 누적 중복되던 버그. payment_id 가 항상 NULL(원장 기반)이라
기존 주석의 existsByPaymentId 중복방어는 불가능했음.

- V87: contract_accounting_entry.settle_month 컬럼 추가 + 기존데이터 백필(description 6자리) + 미전기 부분 인덱스
- core: VO settleMonth 필드, Mapper deleteUnpostedBySettleMonth, insertBatch/selectBySettleMonth 에 settle_month 반영
- batch: 재생성 전 deleteUnpostedBySettleMonth 호출(마감 채번분 journal_no IS NOT NULL 보존)

검증: ga-core/ga-batch/ga-api compileJava SUCCESS, Flyway v87 적용(백필 433건 NULL 0),
  202605 정산 2회 실행 → 193건 유지(중복 0, 수정 전이라면 386). 멱등성 PASS. 테스트데이터 롤백 완료.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
GA Pro
2026-05-29 22:58:49 +09:00
parent a5ae95e34c
commit e407263370
5 changed files with 45 additions and 3 deletions
@@ -22,7 +22,7 @@ import java.util.List;
* 정산월 기준 recruit_ledger + maintain_ledger → contract_accounting_entry INSERT.
* - 차변(8350 지급수수료) / 대변(2530 미지급금) 한 쌍을 단일 행으로 저장.
* - journal_no는 NULL(미전기). 마감 UI에서 채번.
* - 이미 분개된 payment는 existsByPaymentId로 중복 방어.
* - 멱등성: 재실행 시 해당 정산월의 미전기 분개를 먼저 삭제 후 재생성(마감 채번분은 보존).
*/
@Slf4j
@Component
@@ -40,6 +40,12 @@ public class AccountingEntryGenerateStep implements Tasklet {
String settleMonth = ctx.getSettleMonth();
log.info("[AccountingEntry] settleMonth={}", settleMonth);
// 멱등성: 이번 정산월의 미전기 분개 제거 후 재생성 (마감 채번된 분개는 보존)
int deleted = accountingMapper.deleteUnpostedBySettleMonth(settleMonth);
if (deleted > 0) {
log.info("[AccountingEntry] deleted {} unposted entries before regenerate", deleted);
}
List<ContractAccountingEntryVO> source = accountingMapper.selectBySettleMonth(settleMonth);
if (source.isEmpty()) {
log.info("[AccountingEntry] no ledger records for month={}", settleMonth);