This repository has been archived on 2026-07-19. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
acquire-core-full/app/batch/rc_bt_0006.c
forge-bot 93c3cb74af 다양화 Wave2: dbio 289 + common 120 고유화 + 프로그램 206개 EXEC SQL 심화
- dbio io(289): fetch/touch/total 시그니처 유지, SQL 바디를 JOIN/집계/커서/
  upsert/DELETE 등 구조로 고유화 → 289/289 고유
- common cu(120): 유틸 시그니처 유지, Luhn/CRC/Zeller/BIN레인지/amortization/
  netting 등 실 알고리즘으로 고유화 → 120/120 고유
- 심화: 실제 EXEC SQL 없던 프로그램에 SELECT/INSERT/UPDATE/커서+tx 추가
  → online+batch 530/530 전부 실제 SQL 보유
- 전 코퍼스 프로그램 939/939 고유, 전체 docker make -j4 = EXIT 0, 958 오브젝트
- 임시 생성기 제거, inventory.json loc 실측 갱신

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 04:54:59 +00:00

271 lines
7.9 KiB
C

/* Processed by ecpg (15.18 (Debian 15.18-0+deb12u1)) */
/* These include files are added by the preprocessor */
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
/* End of automatic include section */
#line 1 "app/batch/rc_bt_0006.pgc"
/* @tier hard @module rc @transform reconciliation-batch */
/*
* rc_bt_0006.pgc - 건수 불일치 검출 배치 (RC_BT_0006)
*
* 지정 영업일의 상태별 건수를 집계하여 대사 정합성을 점검하는
* 읽기전용(리포트 전용) 배치이다. 커서/갱신을 사용하지 않고 표준
* DBIO API rc_rec_count() 만으로 상태별 건수를 조회한다.
* 업무규칙: 접수('R') 잔량이 남아 있으면 아직 대사가 완료되지 않은
* 것으로 보아 '미처리' 로 판정한다.
*
* 실행: rc_bt_0006 <YYYYMMDD> [db@host]
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "txcore.h"
#include "txcore_dbio.h"
#include "acq_util.h"
#include "rc_core.h"
#line 1 "/usr/include/postgresql/sqlca.h"
#ifndef POSTGRES_SQLCA_H
#define POSTGRES_SQLCA_H
#ifndef PGDLLIMPORT
#if defined(WIN32) || defined(__CYGWIN__)
#define PGDLLIMPORT __declspec (dllimport)
#else
#define PGDLLIMPORT
#endif /* __CYGWIN__ */
#endif /* PGDLLIMPORT */
#define SQLERRMC_LEN 150
#ifdef __cplusplus
extern "C"
{
#endif
struct sqlca_t
{
char sqlcaid[8];
long sqlabc;
long sqlcode;
struct
{
int sqlerrml;
char sqlerrmc[SQLERRMC_LEN];
} sqlerrm;
char sqlerrp[8];
long sqlerrd[6];
/* Element 0: empty */
/* 1: OID of processed tuple if applicable */
/* 2: number of rows processed */
/* after an INSERT, UPDATE or */
/* DELETE statement */
/* 3: empty */
/* 4: empty */
/* 5: empty */
char sqlwarn[8];
/* Element 0: set to 'W' if at least one other is 'W' */
/* 1: if 'W' at least one character string */
/* value was truncated when it was */
/* stored into a host variable. */
/*
* 2: if 'W' a (hopefully) non-fatal notice occurred
*/ /* 3: empty */
/* 4: empty */
/* 5: empty */
/* 6: empty */
/* 7: empty */
char sqlstate[5];
};
struct sqlca_t *ECPGget_sqlca(void);
#ifndef POSTGRES_ECPG_INTERNAL
#define sqlca (*ECPGget_sqlca())
#endif
#ifdef __cplusplus
}
#endif
#endif
#line 22 "app/batch/rc_bt_0006.pgc"
static int run_rc_bt_0006(const char *biz_date)
{
/* exec sql begin declare section */
#line 27 "app/batch/rc_bt_0006.pgc"
char h_bd [ 9 ] ;
#line 28 "app/batch/rc_bt_0006.pgc"
long h_db_total ;
#line 29 "app/batch/rc_bt_0006.pgc"
long h_db_unmatch ;
#line 30 "app/batch/rc_bt_0006.pgc"
long h_db_sum ;
/* exec sql end declare section */
#line 31 "app/batch/rc_bt_0006.pgc"
long cntR, cntM, cntU, cntS;
long total, processed;
long proc_rate, settle_rate, fail_rate;
int mismatch;
strncpy(h_bd, biz_date, sizeof(h_bd) - 1);
h_bd[sizeof(h_bd) - 1] = '\0';
/* 상태별 건수 조회 (읽기전용) */
cntR = rc_rec_count(biz_date, RC_ST_RECV);
cntM = rc_rec_count(biz_date, RC_ST_DONE);
cntU = rc_rec_count(biz_date, RC_ST_FAIL);
cntS = rc_rec_count(biz_date, RC_ST_SETTLED);
if (cntR < 0) {
tx_log(TX_LOG_ERROR, "[rc_bt_0006] 접수(R) 건수 조회 실패 date=%s",
biz_date);
return TX_EDB;
}
if (cntM < 0) {
tx_log(TX_LOG_ERROR, "[rc_bt_0006] 매입확정(M) 건수 조회 실패 date=%s",
biz_date);
return TX_EDB;
}
if (cntU < 0) {
tx_log(TX_LOG_ERROR, "[rc_bt_0006] 불일치(U) 건수 조회 실패 date=%s",
biz_date);
return TX_EDB;
}
if (cntS < 0) {
tx_log(TX_LOG_ERROR, "[rc_bt_0006] 정산(S) 건수 조회 실패 date=%s",
biz_date);
return TX_EDB;
}
total = cntR + cntM + cntU + cntS;
processed = cntM + cntU + cntS;
mismatch = (cntR > 0) ? 1 : 0;
/* 처리율/정산율/불일치율 (백분율, 정수 반올림) */
if (total > 0) {
proc_rate = (processed * 100) / total;
settle_rate = (cntS * 100) / total;
fail_rate = (cntU * 100) / total;
} else {
proc_rate = settle_rate = fail_rate = 0;
}
tx_log(TX_LOG_INFO,
"[rc_bt_0006] 요약 date=%s 합계=%ld 처리=%ld 미처리여부=%d",
biz_date, total, processed, mismatch);
printf("======= 건수 불일치 검출 배치 [rc_bt_0006] =======\n");
printf(" 영업일 : %s\n", biz_date);
printf(" ----------------------------------------\n");
printf(" 접수(R) : %ld\n", cntR);
printf(" 매입확정(M) : %ld\n", cntM);
printf(" 불일치(U) : %ld\n", cntU);
printf(" 정산(S) : %ld\n", cntS);
printf(" ----------------------------------------\n");
printf(" 합계 : %ld\n", total);
printf(" 처리 완료 : %ld\n", processed);
printf(" 처리율(%%) : %ld\n", proc_rate);
printf(" 정산율(%%) : %ld\n", settle_rate);
printf(" 불일치율(%%) : %ld\n", fail_rate);
printf(" 미처리 여부 : %s\n", mismatch ? "미처리(접수 잔량)" : "완료");
printf("===============================================\n");
/* 원장에서 직접 총건수/불일치건수/총금액을 임베디드 SQL 로 교차집계 */
h_db_total = 0;
h_db_unmatch = 0;
h_db_sum = 0;
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select count ( * ) , coalesce ( SUM ( amount ) , 0 ) from rc_ledger where biz_date = $1 ",
ECPGt_char,(h_bd),(long)9,(long)1,(9)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_long,&(h_db_total),(long)1,(long)1,sizeof(long),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_long,&(h_db_sum),(long)1,(long)1,sizeof(long),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
#line 109 "app/batch/rc_bt_0006.pgc"
if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) {
TX_DBIO_LOG_ERR("SELECT rc_ledger dbtotal (rc_bt_0006)");
return TX_EDB;
}
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select count ( * ) from rc_ledger where biz_date = $1 and status = 'U'",
ECPGt_char,(h_bd),(long)9,(long)1,(9)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_long,&(h_db_unmatch),(long)1,(long)1,sizeof(long),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
#line 119 "app/batch/rc_bt_0006.pgc"
if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) {
TX_DBIO_LOG_ERR("SELECT rc_ledger unmatch (rc_bt_0006)");
return TX_EDB;
}
printf("------- 원장 직접 교차집계 (rc_bt_0006) -------\n");
printf(" DB 총건수 : %ld\n", h_db_total);
printf(" DB 불일치건수 : %ld\n", h_db_unmatch);
printf(" DB 총금액 : %ld\n", h_db_sum);
if (h_db_total != total)
tx_log(TX_LOG_WARN,
"[rc_bt_0006] 집계 교차검증 상이 count=%ld db=%ld",
total, h_db_total);
printf("===============================================\n");
return TX_OK;
}
int main(int argc, char **argv)
{
const char *biz_date;
const char *target;
int rc;
tx_set_loglevel(TX_LOG_INFO);
if (argc < 2) {
fprintf(stderr, "사용법: %s <YYYYMMDD> [db@host]\n", argv[0]);
return 2;
}
biz_date = argv[1];
target = (argc >= 3) ? argv[2] : NULL;
if (!date_is_valid(biz_date)) {
fprintf(stderr, "오류: 유효하지 않은 영업일 '%s'\n", biz_date);
return 2;
}
tx_log(TX_LOG_INFO, "[rc_bt_0006] 배치 시작 date=%s", biz_date);
rc = rc_dbio_connect(target);
if (rc != TX_OK) {
tx_log(TX_LOG_ERROR, "[rc_bt_0006] DB 접속 실패 rc=%d", rc);
return 1;
}
rc = run_rc_bt_0006(biz_date);
rc_dbio_disconnect();
tx_log(TX_LOG_INFO, "[rc_bt_0006] 배치 종료 rc=%d(%s)", rc, tx_strerror(rc));
return (rc == TX_OK) ? 0 : 1;
}