- 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>
247 lines
7.6 KiB
C
247 lines
7.6 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_0007.pgc"
|
|
/* @tier medium @module rc @transform reconciliation-online */
|
|
/*
|
|
* rc_ol_0007.pgc - 대사 불일치 예외처리 온라인 서비스 (RC_OL_0007)
|
|
*
|
|
* 요청 KEY 의 원장 1건을 읽어 대사 불일치('U') 건에 대한 예외처리를
|
|
* 수행한다. 불일치 건만 재대사 대기 상태로 되돌린다.
|
|
*
|
|
* 업무규칙:
|
|
* - 원장 상태가 불일치('U') 가 아니면 예외처리 대상이 아니므로 상태를
|
|
* 변경하지 않고 RESULT=SKIP 으로 TX_OK 응답한다.
|
|
* - 불일치('U') 인 경우 예외처리 → 접수('R') 로 되돌려 재대사 대기로
|
|
* 전환한다(ACTION=REQUEUE). 사유(REASON)는 금액 부호로 결정한다:
|
|
* amount <= 0 → "금액오류"
|
|
* amount > 0 → "차액검토"
|
|
*
|
|
* 응답: KEY, OLDSTATUS, NEWSTATUS, REASON, ACTION
|
|
*
|
|
* 동작 요약:
|
|
* [원장 상태] [ACTION] [NEWSTATUS] [비고]
|
|
* U (불일치) REQUEUE R 재대사 대기로 복귀
|
|
* 그 외(R/M/S) SKIP (원상태) 변경 없음, TX_OK
|
|
*
|
|
* 사유(REASON) 결정: 불일치 건의 원장 금액 부호로 구분한다.
|
|
* amount <= 0 → "금액오류" (금액 자체가 비정상 → 원천 데이터 점검)
|
|
* amount > 0 → "차액검토" (금액은 정상, 승인/매입 차액 재확인 필요)
|
|
*
|
|
* 본 서비스는 단건 상태전이 1회만 수행하므로 커서/명시적 트랜잭션 경계가
|
|
* 필요 없다. 재대사는 후속 승인-매입 대사 서비스에서 수행된다.
|
|
*/
|
|
#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 38 "app/online/rc_ol_0007.pgc"
|
|
|
|
|
|
TX_SERVICE(RC_OL_0007, ctx)
|
|
{
|
|
rc_rec_t rec;
|
|
char key[16];
|
|
char old_status[2];
|
|
int rc;
|
|
const char *reason;
|
|
|
|
tx_log(TX_LOG_INFO, "[RC_OL_0007] 대사 불일치 예외처리 서비스 진입");
|
|
|
|
/* --- 요청 필드 추출 --- */
|
|
if (tx_buf_get(ctx->in, "KEY", key, sizeof(key)) != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[RC_OL_0007] KEY 누락");
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* --- 원장 조회 --- */
|
|
memset(&rec, 0, sizeof(rec));
|
|
rc = rc_rec_select(key, &rec);
|
|
if (rc != TX_OK) {
|
|
tx_log(TX_LOG_WARN, "[RC_OL_0007] 원장 조회 실패 key=%s rc=%d(%s)",
|
|
key, rc, tx_strerror(rc));
|
|
tx_return(ctx, rc, ctx->out);
|
|
return;
|
|
}
|
|
|
|
strncpy(old_status, rec.status, sizeof(old_status) - 1);
|
|
old_status[sizeof(old_status) - 1] = '\0';
|
|
|
|
tx_log(TX_LOG_INFO,
|
|
"[RC_OL_0007] 예외처리 검토 key=%s 가맹점=%s 금액=%ld 현상태=%s",
|
|
key, rec.merch_id, rec.amount, old_status);
|
|
|
|
/* --- 예외처리 대상 판별: 불일치('U') 만 --- */
|
|
if (strcmp(rec.status, RC_ST_FAIL) != 0) {
|
|
tx_log(TX_LOG_INFO,
|
|
"[RC_OL_0007] 예외처리 대상 아님 key=%s status=%s → SKIP",
|
|
key, rec.status);
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "KEY", rec.key);
|
|
tx_buf_sets(ctx->out, "OLDSTATUS", old_status);
|
|
tx_buf_sets(ctx->out, "NEWSTATUS", old_status);
|
|
tx_buf_sets(ctx->out, "REASON", "대상아님");
|
|
tx_buf_sets(ctx->out, "ACTION", "SKIP");
|
|
tx_return(ctx, TX_OK, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* --- 사유 결정: 금액 부호 --- */
|
|
if (rec.amount <= 0) {
|
|
reason = "금액오류";
|
|
tx_log(TX_LOG_WARN,
|
|
"[RC_OL_0007] 비정상 금액 감지 key=%s amount=%ld → 금액오류",
|
|
key, rec.amount);
|
|
} else {
|
|
reason = "차액검토";
|
|
tx_log(TX_LOG_INFO,
|
|
"[RC_OL_0007] 정상 금액, 차액 재검토 지정 key=%s amount=%ld",
|
|
key, rec.amount);
|
|
}
|
|
|
|
/* --- 재대사 대기(접수) 로 전이 --- */
|
|
rc = rc_rec_update_status(key, RC_ST_RECV);
|
|
if (rc != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[RC_OL_0007] 재대사 전이 실패 key=%s rc=%d",
|
|
key, rc);
|
|
tx_return(ctx, rc, ctx->out);
|
|
return;
|
|
}
|
|
|
|
tx_log(TX_LOG_INFO,
|
|
"[RC_OL_0007] 예외처리 완료 key=%s %s→R 사유=%s",
|
|
key, old_status, reason);
|
|
|
|
/* --- 응답 구성 --- */
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "KEY", rec.key);
|
|
tx_buf_sets(ctx->out, "OLDSTATUS", old_status);
|
|
tx_buf_sets(ctx->out, "NEWSTATUS", RC_ST_RECV);
|
|
tx_buf_sets(ctx->out, "REASON", reason);
|
|
tx_buf_sets(ctx->out, "ACTION", "REQUEUE");
|
|
|
|
/* 예외처리(재대사 요청) 이력을 rc_exception_log 에 임베디드 SQL 로 적재 */
|
|
{
|
|
/* exec sql begin declare section */
|
|
|
|
|
|
|
|
|
|
#line 126 "app/online/rc_ol_0007.pgc"
|
|
char h_ex_key [ 16 ] ;
|
|
|
|
#line 127 "app/online/rc_ol_0007.pgc"
|
|
char h_ex_old [ 2 ] ;
|
|
|
|
#line 128 "app/online/rc_ol_0007.pgc"
|
|
char h_ex_reason [ 64 ] ;
|
|
/* exec sql end declare section */
|
|
#line 129 "app/online/rc_ol_0007.pgc"
|
|
|
|
|
|
strncpy(h_ex_key, key, sizeof(h_ex_key) - 1);
|
|
h_ex_key[sizeof(h_ex_key) - 1] = '\0';
|
|
strncpy(h_ex_old, old_status, sizeof(h_ex_old) - 1);
|
|
h_ex_old[sizeof(h_ex_old) - 1] = '\0';
|
|
strncpy(h_ex_reason, reason, sizeof(h_ex_reason) - 1);
|
|
h_ex_reason[sizeof(h_ex_reason) - 1] = '\0';
|
|
|
|
if (tx_begin() == TX_OK) {
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into rc_exception_log ( rec_key , old_status , reason , action ) values ( $1 , $2 , $3 , 'REQUEUE' )",
|
|
ECPGt_char,(h_ex_key),(long)16,(long)1,(16)*sizeof(char),
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
ECPGt_char,(h_ex_old),(long)2,(long)1,(2)*sizeof(char),
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
ECPGt_char,(h_ex_reason),(long)64,(long)1,(64)*sizeof(char),
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
|
|
#line 141 "app/online/rc_ol_0007.pgc"
|
|
|
|
if (sqlca.sqlcode != TX_SQL_OK) {
|
|
TX_DBIO_LOG_ERR("INSERT rc_exception_log");
|
|
tx_abort();
|
|
} else {
|
|
tx_commit();
|
|
}
|
|
}
|
|
}
|
|
|
|
tx_return(ctx, TX_OK, ctx->out);
|
|
}
|