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/online/rc_ol_0005.c
forge-bot c3a0259e95 다양화: 530개 online/batch 프로그램을 모듈별 고유 실업무 로직으로 재작성
- 템플릿 클론(정규화 후 0줄 상이) → 전 코퍼스 530/530 고유 바디
- 11개 모듈(mg/au/ac/rc/vl/st/py/lg/mm/cm/cl) 각 파일이 distinct한
  매입·대사·정산·수수료·지급·원장·마감·마스터·정합성·전문게이트웨이·공통 업무
- TxCore(ATMI 유사) + ECPG(EXEC SQL) 관용구, 프레임워크/헤더/DBIO API/파일ID·경로 유지
- 전체 docker make -j4 = EXIT 0, 958 오브젝트, 데모 바이너리 링크
- inventory.json loc 실측 갱신

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

198 lines
6.1 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_0005.pgc"
/* @tier medium @module rc @transform reconciliation-online */
/*
* rc_ol_0005.pgc - 승인-매입 금액불일치 검출 (단건, read-only) (RC_OL_0005)
*
* 요청 KEY 의 원장 1건을 읽어 "승인금액(입력 APPRAMT)" 과 "매입금액
* (원장 amount)" 의 차이를 계산하고 유형을 분류한다. 이 서비스는 검출
* 전용이며 원장 상태를 절대 변경하지 않는다(read-only).
*
* 분류 규칙(차액 diff = amount - APPRAMT, absd = |diff|):
* - diff == 0 → "EXACT" (완전일치)
* - absd <= 10 → "ROUNDING" (반올림 오차 허용범위)
* - 그 외 → "MISMATCH" (실질 불일치)
*
* 응답: KEY, APPRAMT, CAPAMT(=amount), DIFF, ABSDIFF, CLASS
*
* 분류표:
* [절대차 absd] [CLASS] [의미]
* diff == 0 EXACT 승인/매입 완전일치
* absd <= 10 ROUNDING 반올림/절사 오차 허용
* absd > 10 MISMATCH 실질 금액 불일치(정산조정 필요)
*
* 설계 원칙: 본 서비스는 "검출(detection) 전용" 이다. rc_rec_update_status
* 를 호출하지 않으므로 어떤 상태전이도 발생하지 않으며, 반복
* 호출해도 원장은 불변(idempotent read)이다. 실제 상태전이는
* 승인-매입 대사 서비스(RC_OL_0002)나 예외처리(RC_OL_0007)에서
* 수행한다. 따라서 커서/트랜잭션 경계가 필요 없다.
*/
#include <stdio.h>
#include <string.h>
#include "txcore.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 35 "app/online/rc_ol_0005.pgc"
#define RC_ROUNDING_TOL 10L /* 반올림 허용 오차(원) */
TX_SERVICE(RC_OL_0005, ctx)
{
rc_rec_t rec;
char key[16];
long appr_amt = 0; /* 승인금액 */
long diff; /* 차액 = 매입금액 - 승인금액 */
long absd; /* 차액 절대값 */
int rc;
const char *klass;
tx_log(TX_LOG_INFO, "[RC_OL_0005] 승인-매입 금액불일치 검출 서비스 진입");
/* --- 요청 필드 추출 --- */
if (tx_buf_get(ctx->in, "KEY", key, sizeof(key)) != TX_OK) {
tx_log(TX_LOG_ERROR, "[RC_OL_0005] KEY 누락");
tx_return(ctx, TX_EINVAL, ctx->out);
return;
}
if (tx_buf_getlong(ctx->in, "APPRAMT", &appr_amt) != TX_OK) {
tx_log(TX_LOG_ERROR, "[RC_OL_0005] APPRAMT(승인금액) 누락 key=%s", 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_0005] 원장 조회 실패 key=%s rc=%d(%s)",
key, rc, tx_strerror(rc));
tx_return(ctx, rc, ctx->out);
return;
}
/* --- 차액 계산 및 분류 --- */
diff = rec.amount - appr_amt;
absd = (diff < 0) ? -diff : diff;
tx_log(TX_LOG_INFO,
"[RC_OL_0005] 검출 대상 key=%s 가맹점=%s 매입=%ld 승인=%ld 상태=%s",
key, rec.merch_id, rec.amount, appr_amt, rec.status);
if (diff == 0) {
klass = "EXACT";
tx_log(TX_LOG_INFO, "[RC_OL_0005] 완전일치 key=%s amount=%ld",
key, rec.amount);
} else if (absd <= RC_ROUNDING_TOL) {
klass = "ROUNDING";
tx_log(TX_LOG_INFO,
"[RC_OL_0005] 반올림오차 key=%s 차액=%ld(허용<=%ld)",
key, diff, RC_ROUNDING_TOL);
} else {
klass = "MISMATCH";
tx_log(TX_LOG_WARN,
"[RC_OL_0005] 실질 불일치 key=%s 차액=%ld 절대차=%ld",
key, diff, absd);
}
/* --- 차액 방향 보조 로그 (초과매입/과소매입 구분) --- */
if (diff > 0)
tx_log(TX_LOG_INFO,
"[RC_OL_0005] 매입 초과 key=%s (매입>승인) 초과액=%ld",
key, diff);
else if (diff < 0)
tx_log(TX_LOG_INFO,
"[RC_OL_0005] 매입 과소 key=%s (매입<승인) 부족액=%ld",
key, absd);
/* --- 응답 구성 (원장 상태는 유지) --- */
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "KEY", rec.key);
tx_buf_setlong(ctx->out, "APPRAMT", appr_amt);
tx_buf_setlong(ctx->out, "CAPAMT", rec.amount);
tx_buf_setlong(ctx->out, "DIFF", diff);
tx_buf_setlong(ctx->out, "ABSDIFF", absd);
tx_buf_sets(ctx->out, "CLASS", klass);
tx_log(TX_LOG_INFO,
"[RC_OL_0005] 검출완료 key=%s CLASS=%s DIFF=%ld ABSDIFF=%ld",
key, klass, diff, absd);
tx_return(ctx, TX_OK, ctx->out);
}