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/cl_ol_0031.pgc
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

122 lines
4.6 KiB
Text

/* @tier easy @module cl @transform closing-online */
/*
* cl_ol_0031.pgc - 마감 온라인 서비스 (CL_OL_0031) [tier=easy]
*
* 마감 스냅샷 비교
* ----------------------------------------------------------------------
* 두 스냅샷 처리키(SS1, SS2)를 표준 DBIO(cl_rec_select) 로 각각 조회
* 하여, 두 스냅샷의 합계금액(amount) 차이와 일치 여부(MATCH=Y/N) 를
* diff 응답으로 반환한다. 어느 한쪽 스냅샷이 없으면 비교 불가로
* ENOENT 를 응답한다.
*
* 금액 차이에 더해 건수(fee 필드에 적재) 차이와 변동 방향(DIRECTION:
* UP/DOWN/FLAT), 기준(SS1) 대비 변동률(%)을 산출하여 제공한다.
* 감사추적을 위해 선택 입력 REQID 를 반영한다.
*/
#include <stdio.h>
#include <string.h>
#include "txcore.h"
#include "txcore_dbio.h"
#include "acq_util.h"
#include "cl_core.h"
EXEC SQL INCLUDE sqlca;
TX_SERVICE(CL_OL_0031, ctx)
{
cl_rec_t rec1, rec2;
char ss1[16], ss2[16];
char reqid[32];
char diff_won[32];
char summary[TX_VAL_LEN];
const char *direction;
long diff, cnt_diff, abs_diff;
long rate;
int rc1, rc2;
tx_log(TX_LOG_INFO, "[CL_OL_0031] 마감 스냅샷 비교 서비스 진입");
/* 1) 입력 수신 */
if (tx_buf_get(ctx->in, "SS1", ss1, sizeof(ss1)) != TX_OK ||
tx_buf_get(ctx->in, "SS2", ss2, sizeof(ss2)) != TX_OK) {
tx_log(TX_LOG_ERROR, "[CL_OL_0031] SS1/SS2 누락");
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_INVALID);
tx_return(ctx, TX_EINVAL, ctx->out);
return;
}
if (tx_buf_get(ctx->in, "REQID", reqid, sizeof(reqid)) != TX_OK)
strncpy(reqid, "-", sizeof(reqid) - 1);
/* 2) 두 스냅샷 각각 조회 */
memset(&rec1, 0, sizeof(rec1));
memset(&rec2, 0, sizeof(rec2));
rc1 = cl_rec_select(ss1, &rec1);
rc2 = cl_rec_select(ss2, &rec2);
if (rc1 == TX_ENOENT || rc2 == TX_ENOENT) {
tx_log(TX_LOG_WARN, "[CL_OL_0031] 스냅샷 없음 ss1=%s(rc=%d) ss2=%s(rc=%d)",
ss1, rc1, ss2, rc2);
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_INVALID);
tx_buf_sets(ctx->out, "FOUND1", rc1 == TX_OK ? "Y" : "N");
tx_buf_sets(ctx->out, "FOUND2", rc2 == TX_OK ? "Y" : "N");
tx_buf_sets(ctx->out, "MESSAGE", "비교 대상 스냅샷 누락");
tx_return(ctx, TX_ENOENT, ctx->out);
return;
}
if (rc1 != TX_OK || rc2 != TX_OK) {
tx_log(TX_LOG_ERROR, "[CL_OL_0031] 스냅샷 조회 실패 rc1=%d rc2=%d", rc1, rc2);
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_SYSERR);
tx_return(ctx, TX_EDB, ctx->out);
return;
}
/* 3) 금액/건수 차이, 방향, 변동률(기준 SS1) 산출 */
diff = rec2.amount - rec1.amount; /* SS1 -> SS2 변동 */
cnt_diff = rec2.fee - rec1.fee;
if (diff > 0)
direction = "UP";
else if (diff < 0)
direction = "DOWN";
else
direction = "FLAT";
rate = (rec1.amount != 0)
? (diff * 100 / (rec1.amount < 0 ? -rec1.amount : rec1.amount))
: 0;
abs_diff = (diff < 0) ? -diff : diff;
amount_format_won(diff, diff_won, sizeof(diff_won));
/* 4) 비교 결과 요약 문구 구성 */
snprintf(summary, sizeof(summary),
"스냅샷 %s(%ld) -> %s(%ld) 변동 %ld원 (%s %ld%%)",
ss1, rec1.amount, ss2, rec2.amount, diff, direction, rate);
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_OK);
tx_buf_sets(ctx->out, "SS1", ss1);
tx_buf_sets(ctx->out, "SS2", ss2);
tx_buf_sets(ctx->out, "REQID", reqid);
tx_buf_setlong(ctx->out, "AMT1", rec1.amount);
tx_buf_setlong(ctx->out, "AMT2", rec2.amount);
tx_buf_setlong(ctx->out, "CNT1", rec1.fee);
tx_buf_setlong(ctx->out, "CNT2", rec2.fee);
tx_buf_setlong(ctx->out, "DIFF", diff);
tx_buf_sets(ctx->out, "DIFFWON", diff_won);
tx_buf_setlong(ctx->out, "ABSDIFF", abs_diff);
tx_buf_setlong(ctx->out, "CNTDIFF", cnt_diff);
tx_buf_setlong(ctx->out, "RATE", rate);
tx_buf_sets(ctx->out, "DIRECTION", direction);
tx_buf_sets(ctx->out, "SUMMARY", summary);
tx_buf_sets(ctx->out, "MATCH", (diff == 0) ? "Y" : "N");
/* 유의미 변동 여부(절대변동이 기준의 1% 초과) */
tx_buf_sets(ctx->out, "MATERIAL",
(rate > 1 || rate < -1) ? "Y" : "N");
tx_log(TX_LOG_INFO,
"[CL_OL_0031] 완료 ss1=%s(%ld) ss2=%s(%ld) 차이=%ld 방향=%s",
ss1, rec1.amount, ss2, rec2.amount, diff, direction);
tx_return(ctx, TX_OK, ctx->out);
}