/* Processed by ecpg (15.18 (Debian 15.18-0+deb12u1)) */ /* These include files are added by the preprocessor */ #include #include #include /* 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 [db@host] */ #include #include #include #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) { long cntR, cntM, cntU, cntS; long total, processed; long proc_rate, settle_rate, fail_rate; int mismatch; /* 상태별 건수 조회 (읽기전용) */ 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"); 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 [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; }