- 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>
238 lines
7.5 KiB
C
238 lines
7.5 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/online/rc_ol_0006.pgc"
|
|
/* @tier medium @module rc @transform reconciliation-online */
|
|
/*
|
|
* rc_ol_0006.pgc - 건수 불일치 검출 온라인 서비스 (RC_OL_0006)
|
|
*
|
|
* 요청 영업일(BIZDATE)에 대해 상태별 원장 건수를 집계하여 대사 진행
|
|
* 상황을 점검한다. 상태별로 rc_rec_count 를 호출한다:
|
|
* 접수('R'), 매입확정('M'), 불일치('U'), 정산완료('S').
|
|
*
|
|
* 업무규칙:
|
|
* - total = 접수 + 매입확정 + 불일치 + 정산완료
|
|
* - 접수('R') 건이 하나라도 남아 있으면 아직 처리되지 않은 미처리
|
|
* 잔존이 있으므로 MISMATCH=Y, 없으면 MISMATCH=N.
|
|
*
|
|
* 응답: BIZDATE, CNTR, CNTM, CNTU, CNTS, TOTAL, MISMATCH
|
|
*
|
|
* 상태 코드 대응:
|
|
* CNTR 접수/승인('R') - 아직 대사되지 않은 미처리 건
|
|
* CNTM 매입확정('M') - 승인-매입 대사 완료 건
|
|
* CNTU 불일치/보류('U') - 예외처리 대기 건
|
|
* CNTS 정산완료('S') - 입금대사까지 종료된 건
|
|
*
|
|
* 판정 원칙: 하루의 대사가 완결되면 접수('R') 잔량이 0 이어야 한다.
|
|
* CNTR > 0 이면 미처리 잔존으로 보아 MISMATCH=Y 를 통지한다.
|
|
* (CNTU 는 예외처리 트랙으로 별도 관리하므로 여기서는 접수
|
|
* 잔량만을 완결 지표로 삼는다.) 상태별 단순 COUNT 집계만
|
|
* 수행하므로 커서/트랜잭션 경계가 필요 없다.
|
|
*/
|
|
#include <stdio.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 36 "app/online/rc_ol_0006.pgc"
|
|
|
|
|
|
TX_SERVICE(RC_OL_0006, ctx)
|
|
{
|
|
char bizdate[16];
|
|
long cnt_r, cnt_m, cnt_u, cnt_s;
|
|
long total;
|
|
const char *mismatch;
|
|
|
|
tx_log(TX_LOG_INFO, "[RC_OL_0006] 건수 불일치 검출 서비스 진입");
|
|
|
|
/* --- 요청 필드 추출 및 검증 --- */
|
|
if (tx_buf_get(ctx->in, "BIZDATE", bizdate, sizeof(bizdate)) != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[RC_OL_0006] BIZDATE 누락");
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
if (!date_is_valid(bizdate)) {
|
|
tx_log(TX_LOG_WARN, "[RC_OL_0006] 영업일 형식 오류 date=%s", bizdate);
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* --- 상태별 건수 집계 (음수 리턴은 조회오류) --- */
|
|
cnt_r = rc_rec_count(bizdate, RC_ST_RECV);
|
|
cnt_m = rc_rec_count(bizdate, RC_ST_DONE);
|
|
cnt_u = rc_rec_count(bizdate, RC_ST_FAIL);
|
|
cnt_s = rc_rec_count(bizdate, RC_ST_SETTLED);
|
|
|
|
if (cnt_r < 0 || cnt_m < 0 || cnt_u < 0 || cnt_s < 0) {
|
|
tx_log(TX_LOG_ERROR,
|
|
"[RC_OL_0006] 건수 집계 실패 date=%s R=%ld M=%ld U=%ld S=%ld",
|
|
bizdate, cnt_r, cnt_m, cnt_u, cnt_s);
|
|
tx_return(ctx, TX_EDB, ctx->out);
|
|
return;
|
|
}
|
|
|
|
total = cnt_r + cnt_m + cnt_u + cnt_s;
|
|
|
|
tx_log(TX_LOG_INFO,
|
|
"[RC_OL_0006] 집계 date=%s R=%ld M=%ld U=%ld S=%ld 총=%ld",
|
|
bizdate, cnt_r, cnt_m, cnt_u, cnt_s, total);
|
|
|
|
/* 총건수 0 이면 해당 영업일 대사 대상 자체가 없음 (참고 로그) */
|
|
if (total == 0)
|
|
tx_log(TX_LOG_WARN,
|
|
"[RC_OL_0006] 대사 대상 없음 date=%s (원장 무건)", bizdate);
|
|
|
|
/* 불일치('U') 누적 경고 (완결 지표와 별개로 예외 트랙 가시화) */
|
|
if (cnt_u > 0)
|
|
tx_log(TX_LOG_WARN,
|
|
"[RC_OL_0006] 예외처리 대기 date=%s 불일치=%ld", bizdate, cnt_u);
|
|
|
|
/* --- 미처리(접수) 잔존 여부로 불일치 플래그 결정 --- */
|
|
if (cnt_r > 0) {
|
|
mismatch = "Y";
|
|
tx_log(TX_LOG_WARN,
|
|
"[RC_OL_0006] 미처리 잔존 date=%s 접수=%ld → MISMATCH",
|
|
bizdate, cnt_r);
|
|
} else {
|
|
mismatch = "N";
|
|
tx_log(TX_LOG_INFO,
|
|
"[RC_OL_0006] 미처리 없음 date=%s 총=%ld → 정상",
|
|
bizdate, total);
|
|
}
|
|
|
|
/* --- 응답 구성 --- */
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "BIZDATE", bizdate);
|
|
tx_buf_setlong(ctx->out, "CNTR", cnt_r);
|
|
tx_buf_setlong(ctx->out, "CNTM", cnt_m);
|
|
tx_buf_setlong(ctx->out, "CNTU", cnt_u);
|
|
tx_buf_setlong(ctx->out, "CNTS", cnt_s);
|
|
tx_buf_setlong(ctx->out, "TOTAL", total);
|
|
tx_buf_sets(ctx->out, "MISMATCH", mismatch);
|
|
|
|
/* 원장에서 직접 총건수를 임베디드 SQL 로 재집계하여 교차검증(DBTOTAL) */
|
|
{
|
|
/* exec sql begin declare section */
|
|
|
|
|
|
|
|
#line 115 "app/online/rc_ol_0006.pgc"
|
|
char h_c6_bd [ 9 ] ;
|
|
|
|
#line 116 "app/online/rc_ol_0006.pgc"
|
|
long h_c6_total ;
|
|
/* exec sql end declare section */
|
|
#line 117 "app/online/rc_ol_0006.pgc"
|
|
|
|
|
|
strncpy(h_c6_bd, bizdate, sizeof(h_c6_bd) - 1);
|
|
h_c6_bd[sizeof(h_c6_bd) - 1] = '\0';
|
|
h_c6_total = 0;
|
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select count ( * ) from rc_ledger where biz_date = $1 ",
|
|
ECPGt_char,(h_c6_bd),(long)9,(long)1,(9)*sizeof(char),
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
|
|
ECPGt_long,&(h_c6_total),(long)1,(long)1,sizeof(long),
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
|
|
#line 126 "app/online/rc_ol_0006.pgc"
|
|
|
|
if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) {
|
|
TX_DBIO_LOG_ERR("SELECT rc_ledger dbtotal");
|
|
h_c6_total = total;
|
|
}
|
|
tx_buf_setlong(ctx->out, "DBTOTAL", h_c6_total);
|
|
if (h_c6_total != total)
|
|
tx_log(TX_LOG_WARN, "[RC_OL_0006] 집계 교차검증 상이 wrap=%ld db=%ld",
|
|
total, h_c6_total);
|
|
}
|
|
|
|
/* 진행률 참고 로그: (매입확정+정산완료) / 총건수 */
|
|
if (total > 0) {
|
|
long done_cnt = cnt_m + cnt_s;
|
|
tx_log(TX_LOG_INFO,
|
|
"[RC_OL_0006] 검출완료 date=%s 완료=%ld/%ld MISMATCH=%s",
|
|
bizdate, done_cnt, total, mismatch);
|
|
} else {
|
|
tx_log(TX_LOG_INFO,
|
|
"[RC_OL_0006] 검출완료 date=%s 대상없음 MISMATCH=%s",
|
|
bizdate, mismatch);
|
|
}
|
|
tx_return(ctx, TX_OK, ctx->out);
|
|
}
|