- 템플릿 클론(정규화 후 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>
198 lines
5.9 KiB
C
198 lines
5.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/online/rc_ol_0003.pgc"
|
|
/* @tier medium @module rc @transform reconciliation-online */
|
|
/*
|
|
* rc_ol_0003.pgc - 매입-입금 대사 (단건) 온라인 서비스 (RC_OL_0003)
|
|
*
|
|
* 요청 KEY 의 원장 1건을 읽어 "매입 순액(net = 매입금액 amount - 수수료
|
|
* fee)" 과 매입사로부터 통지된 "실제 입금액(입력 DEPAMT)" 을 대사한다.
|
|
*
|
|
* 업무규칙:
|
|
* - 원장 상태가 매입확정('M') 이고 net == DEPAMT 이면 대사 일치로 보고
|
|
* 정산완료('S') 로 상태를 전이한다(RESULT=MATCH).
|
|
* - 그 외에는 대사 불일치로 판정한다(RESULT=UNMATCH). 이 경우 순액과
|
|
* 입금액이 실제로 어긋난 때(net != DEPAMT)에 한해 불일치('U') 로
|
|
* 전이하여 후속 예외처리 대상으로 남기고, 금액은 맞으나 아직 매입
|
|
* 확정 상태가 아닌 경우에는 상태를 바꾸지 않는다.
|
|
*
|
|
* 응답: KEY, NET, DEPAMT, GAP(=net-DEPAMT), STATUS, RESULT
|
|
*/
|
|
#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 25 "app/online/rc_ol_0003.pgc"
|
|
|
|
|
|
TX_SERVICE(RC_OL_0003, ctx)
|
|
{
|
|
rc_rec_t rec;
|
|
char key[16];
|
|
long dep_amt = 0; /* 매입사 통지 입금액 */
|
|
long net; /* 매입 순액 = amount - fee */
|
|
long gap; /* 차액 = net - dep_amt */
|
|
int matched; /* 대사 일치 여부 */
|
|
int rc;
|
|
const char *result;
|
|
const char *final_st;
|
|
|
|
tx_log(TX_LOG_INFO, "[RC_OL_0003] 매입-입금 대사(단건) 서비스 진입");
|
|
|
|
/* --- 요청 필드 추출 --- */
|
|
if (tx_buf_get(ctx->in, "KEY", key, sizeof(key)) != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[RC_OL_0003] KEY 누락");
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
if (tx_buf_getlong(ctx->in, "DEPAMT", &dep_amt) != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[RC_OL_0003] DEPAMT(입금액) 누락 key=%s", key);
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
if (!amount_is_valid(dep_amt)) {
|
|
tx_log(TX_LOG_WARN, "[RC_OL_0003] 입금액 범위 오류 key=%s dep=%ld",
|
|
key, dep_amt);
|
|
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_0003] 원장 조회 실패 key=%s rc=%d(%s)",
|
|
key, rc, tx_strerror(rc));
|
|
tx_return(ctx, rc, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* --- 대사 계산 --- */
|
|
net = rec.amount - rec.fee;
|
|
gap = net - dep_amt;
|
|
matched = (strcmp(rec.status, RC_ST_DONE) == 0) && (gap == 0);
|
|
|
|
if (matched) {
|
|
/* 매입확정 + 순액 일치 → 정산완료 전이 */
|
|
rc = rc_rec_update_status(key, RC_ST_SETTLED);
|
|
if (rc != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[RC_OL_0003] 정산완료 전이 실패 key=%s rc=%d",
|
|
key, rc);
|
|
tx_return(ctx, rc, ctx->out);
|
|
return;
|
|
}
|
|
final_st = RC_ST_SETTLED;
|
|
result = "MATCH";
|
|
tx_log(TX_LOG_INFO,
|
|
"[RC_OL_0003] 대사 일치 key=%s net=%ld dep=%ld → 정산완료",
|
|
key, net, dep_amt);
|
|
} else if (gap != 0) {
|
|
/* 금액이 실제로 어긋남 → 불일치 상태로 보류 */
|
|
rc = rc_rec_update_status(key, RC_ST_FAIL);
|
|
if (rc != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[RC_OL_0003] 불일치 전이 실패 key=%s rc=%d",
|
|
key, rc);
|
|
tx_return(ctx, rc, ctx->out);
|
|
return;
|
|
}
|
|
final_st = RC_ST_FAIL;
|
|
result = "UNMATCH";
|
|
tx_log(TX_LOG_WARN,
|
|
"[RC_OL_0003] 대사 불일치 key=%s 차액=%ld → 보류",
|
|
key, gap);
|
|
} else {
|
|
/* 금액은 맞으나 매입확정 상태가 아님 → 전이 없이 보류 판정 */
|
|
final_st = rec.status;
|
|
result = "UNMATCH";
|
|
tx_log(TX_LOG_WARN,
|
|
"[RC_OL_0003] 매입확정 前 상태 key=%s status=%s → 전이 보류",
|
|
key, rec.status);
|
|
}
|
|
|
|
/* --- 응답 구성 --- */
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "KEY", rec.key);
|
|
tx_buf_setlong(ctx->out, "NET", net);
|
|
tx_buf_setlong(ctx->out, "DEPAMT", dep_amt);
|
|
tx_buf_setlong(ctx->out, "GAP", gap);
|
|
tx_buf_sets(ctx->out, "STATUS", final_st);
|
|
tx_buf_sets(ctx->out, "RESULT", result);
|
|
tx_return(ctx, TX_OK, ctx->out);
|
|
}
|