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/lg_ol_0019.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

133 lines
4.2 KiB
Text

/* @tier easy @module lg @transform ledger-online */
/*
* lg_ol_0019.pgc - 원장 온라인 서비스 (LG_OL_0019) [tier=easy]
*
* 정산확정 처리: 단건 key 의 처리완료(M) 전표를 정산완료(S) 로 확정한다.
* 정산액 = 거래금액 - 수수료 를 계산하여 응답한다.
*/
#include <stdio.h>
#include <string.h>
#include "txcore.h"
#include "txcore_dbio.h"
#include "acq_util.h"
#include "lg_core.h"
EXEC SQL INCLUDE sqlca;
/*
* [업무 개요]
* 처리완료(M) 상태의 승인 전표 한 건을 정산확정(S) 으로 전이한다. 정산
* 확정 시점에 가맹점에 실제 지급되는 금액(정산액) 을 산출하여 반환한다.
*
* [상태 전이]
* M(처리완료) → S(정산완료) 그 외 상태는 정산확정 불가(RESP_INVALID)
*
* [정산액 산식]
* SETTLEAMT = amount - fee (거래금액에서 수수료를 차감한 실지급액)
*
* [처리 절차]
* 1) KEY 추출/검증.
* 2) 단건 SELECT 로 amount, fee, 현재 status 확보.
* 3) 상태가 M 이 아니면 거부.
* 4) tx_begin 후 status='S' 로 UPDATE, tx_commit.
* 5) 정산액 산출 후 응답.
*
* [응답 필드]
* RESPCODE 처리결과코드 KEY 처리키(에코) AMOUNT 거래금액
* FEE 수수료 SETTLEAMT 정산액 STATUS 확정후 상태(S)
*/
TX_SERVICE(LG_OL_0019, ctx)
{
EXEC SQL BEGIN DECLARE SECTION;
char h_key[16];
char h_status_s[2];
char h_cur_status[2];
long h_amount;
long h_fee;
EXEC SQL END DECLARE SECTION;
char key[16];
long settle_amt;
tx_log(TX_LOG_INFO, "[LG_OL_0019] 정산확정 처리 진입");
if (tx_buf_get(ctx->in, "KEY", key, sizeof(key)) != TX_OK || key[0] == '\0') {
tx_log(TX_LOG_ERROR, "[LG_OL_0019] KEY 누락");
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_INVALID);
tx_return(ctx, TX_EINVAL, ctx->out);
return;
}
strncpy(h_key, key, sizeof(h_key) - 1);
h_key[sizeof(h_key) - 1] = '\0';
strncpy(h_status_s, LG_ST_SETTLED, sizeof(h_status_s) - 1);
h_status_s[sizeof(h_status_s) - 1] = '\0';
EXEC SQL SELECT amount, fee, status
INTO :h_amount, :h_fee, :h_cur_status
FROM lg_ledger
WHERE key = :h_key;
if (sqlca.sqlcode == TX_SQL_NOTFOUND) {
tx_log(TX_LOG_WARN, "[LG_OL_0019] 전표 없음 key=%s", key);
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_NOMERCH);
tx_return(ctx, TX_ENOENT, ctx->out);
return;
}
if (sqlca.sqlcode != TX_SQL_OK) {
TX_DBIO_LOG_ERR("lg_ol_0019 select");
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_SYSERR);
tx_return(ctx, TX_EDB, ctx->out);
return;
}
/* 처리완료(M) 상태만 정산확정 가능 */
if (h_cur_status[0] != LG_ST_DONE[0]) {
tx_log(TX_LOG_WARN, "[LG_OL_0019] 정산확정 불가 상태 key=%s status=%s",
key, h_cur_status);
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_INVALID);
tx_buf_sets(ctx->out, "STATUS", h_cur_status);
tx_return(ctx, TX_EINVAL, ctx->out);
return;
}
if (tx_begin() != TX_OK) {
tx_return(ctx, TX_FAIL, ctx->out);
return;
}
EXEC SQL UPDATE lg_ledger
SET status = :h_status_s, upd_ts = now()
WHERE key = :h_key;
if (sqlca.sqlcode != TX_SQL_OK) {
TX_DBIO_LOG_ERR("lg_ol_0019 update");
tx_abort();
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_SYSERR);
tx_return(ctx, TX_EDB, ctx->out);
return;
}
if (tx_commit() != TX_OK) {
tx_abort();
tx_return(ctx, TX_FAIL, ctx->out);
return;
}
settle_amt = h_amount - h_fee;
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_OK);
tx_buf_sets(ctx->out, "KEY", key);
tx_buf_setlong(ctx->out, "AMOUNT", h_amount);
tx_buf_setlong(ctx->out, "FEE", h_fee);
tx_buf_setlong(ctx->out, "SETTLEAMT", settle_amt);
tx_buf_sets(ctx->out, "STATUS", LG_ST_SETTLED);
tx_log(TX_LOG_INFO, "[LG_OL_0019] 정산확정 완료 key=%s 정산액=%ld", key, settle_amt);
tx_return(ctx, TX_OK, ctx->out);
}