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
@@ -0,0 +1,19 @@
-- V87: 회계분개(contract_accounting_entry) 정산월 멱등성 확보
-- AccountingEntryGenerateStep(Step8b)이 동일 정산월 재실행 시 분개를 중복 INSERT 하던 버그 수정.
-- payment_id 가 항상 NULL(원장 기반)이라 기존 주석의 existsByPaymentId 중복방어는 불가능했음.
-- recruit/maintain ledger 와 동일하게 settle_month 키로 "미전기분 삭제 후 재생성" 패턴 적용.
-- (journal_no 채번된 마감 분개는 보존 — 미전기분만 재생성 대상)
ALTER TABLE contract_accounting_entry ADD COLUMN IF NOT EXISTS settle_month CHAR(6);
COMMENT ON COLUMN contract_accounting_entry.settle_month IS '정산월 (YYYYMM). 배치 재생성 시 미전기분 멱등 삭제 키';
-- 기존 데이터 백필: description 의 6자리 정산월(예: "모집수수료 202604") 추출
UPDATE contract_accounting_entry
SET settle_month = substring(description from '(\d{6})')
WHERE settle_month IS NULL
AND description ~ '\d{6}';
-- 미전기분 재생성 조회/삭제용 부분 인덱스
CREATE INDEX IF NOT EXISTS idx_cae_settle_unposted
ON contract_accounting_entry(settle_month)
WHERE journal_no IS NULL;