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_0003.pgc
forge-bot 93c3cb74af 다양화 Wave2: dbio 289 + common 120 고유화 + 프로그램 206개 EXEC SQL 심화
- 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>
2026-07-19 04:54:59 +00:00

153 lines
5.4 KiB
Text

/* @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 "txcore_dbio.h"
#include "acq_util.h"
#include "rc_core.h"
EXEC SQL INCLUDE sqlca;
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);
/* 매입-입금 대사 결과를 입금대사이력(rc_deposit_log)에 임베디드 SQL 로 적재 */
{
EXEC SQL BEGIN DECLARE SECTION;
char h_dl_key[16];
long h_dl_net;
long h_dl_dep;
long h_dl_gap;
char h_dl_result[12];
EXEC SQL END DECLARE SECTION;
strncpy(h_dl_key, key, sizeof(h_dl_key) - 1);
h_dl_key[sizeof(h_dl_key) - 1] = '\0';
h_dl_net = net;
h_dl_dep = dep_amt;
h_dl_gap = gap;
strncpy(h_dl_result, result, sizeof(h_dl_result) - 1);
h_dl_result[sizeof(h_dl_result) - 1] = '\0';
if (tx_begin() == TX_OK) {
EXEC SQL INSERT INTO rc_deposit_log
(rec_key, net_amt, dep_amt, gap_amt, match_result)
VALUES (:h_dl_key, :h_dl_net, :h_dl_dep, :h_dl_gap, :h_dl_result);
if (sqlca.sqlcode != TX_SQL_OK) {
TX_DBIO_LOG_ERR("INSERT rc_deposit_log");
tx_abort();
} else {
tx_commit();
}
}
}
tx_return(ctx, TX_OK, ctx->out);
}