- 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>
155 lines
6.5 KiB
Text
155 lines
6.5 KiB
Text
/* @tier easy @module cl @transform closing-online */
|
|
/*
|
|
* cl_ol_0015.pgc - 마감 온라인 서비스 (CL_OL_0015) [tier=easy]
|
|
*
|
|
* 마감 상태조회. 요청 처리키(KEY) 단건에 대해 표준 DBIO cl_rec_select 로
|
|
* 원장 레코드를 읽어, 상태코드/금액/영업일과 함께 마감여부(status='S')를
|
|
* 판정하여 응답한다. 아울러 동일 가맹점·동일 영업일의 형제 거래 건수/
|
|
* 금액합계를 cl_ledger 에서 직접 집계(SELECT)하여 맥락을 함께 제공한다.
|
|
*
|
|
* ── 서비스 계약(Contract) ────────────────────────────────────────────
|
|
* 입력 필드:
|
|
* KEY (필수) 처리키(승인/거래 번호) - 원장 PK
|
|
* 출력 필드:
|
|
* RESPCODE 0000=정상 / 9001=키누락·원장없음 / 9999=시스템오류
|
|
* KEY 조회 대상 처리키
|
|
* MERCHID 가맹점번호
|
|
* BIZDATE 영업일(YYYYMMDD)
|
|
* AMOUNT 거래금액(원, 정수)
|
|
* AMOUNTWON 거래금액 한글 표기(예: 12,300원)
|
|
* STATUS 상태코드(R/M/U/S)
|
|
* STATUSLABEL 상태 한글 라벨(접수/처리완료/불일치/정산완료)
|
|
* CLOSED 마감여부(Y=정산완료 S / N=그 외)
|
|
* SIBLINGCNT 동일 가맹점·영업일 형제 거래 건수
|
|
* SIBLINGSUM 동일 가맹점·영업일 형제 거래 금액합계
|
|
*
|
|
* ── 상태코드 정의 ────────────────────────────────────────────────────
|
|
* R(접수) → M(처리완료) → S(정산완료/마감확정)
|
|
* └ U(불일치) 는 재처리 후 M 으로 복귀 대상
|
|
* 본 서비스는 상태를 변경하지 않으며, 마감확정 여부만 판정한다.
|
|
*
|
|
* ── 처리 흐름 ────────────────────────────────────────────────────────
|
|
* 1) 요청 TXBUF 에서 KEY 추출 및 필수검증
|
|
* 2) cl_rec_select 로 단건 원장 조회 (없으면 RESP_INVALID)
|
|
* 3) status 를 CL_ST_* 상수와 비교하여 라벨/마감여부 산출
|
|
* 4) 동일 가맹점·영업일 형제 집계 SELECT
|
|
* 5) 응답 TXBUF 구성 후 tx_return
|
|
*/
|
|
#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_0015, ctx)
|
|
{
|
|
EXEC SQL BEGIN DECLARE SECTION;
|
|
char h_merch_id[16];
|
|
char h_biz_date[9];
|
|
long h_sib_cnt;
|
|
long h_sib_sum;
|
|
EXEC SQL END DECLARE SECTION;
|
|
|
|
cl_rec_t rec;
|
|
char key[16];
|
|
char won[40];
|
|
const char *st_label;
|
|
int is_settled;
|
|
int is_snap;
|
|
int rc;
|
|
|
|
tx_log(TX_LOG_INFO, "[CL_OL_0015] 마감 상태조회 서비스 진입");
|
|
|
|
/* 1. 요청 검증 : 처리키 필수 */
|
|
if (tx_buf_get(ctx->in, "KEY", key, sizeof(key)) != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[CL_OL_0015] KEY 누락");
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESPCODE", RESP_INVALID);
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 2. 단건 조회 (표준 DBIO) */
|
|
memset(&rec, 0, sizeof(rec));
|
|
rc = cl_rec_select(key, &rec);
|
|
if (rc == TX_ENOENT) {
|
|
tx_log(TX_LOG_WARN, "[CL_OL_0015] 원장 없음 key=%s", key);
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESPCODE", RESP_INVALID);
|
|
tx_buf_sets(ctx->out, "KEY", key);
|
|
tx_buf_sets(ctx->out, "MESSAGE", "해당 처리키 원장 없음");
|
|
tx_return(ctx, rc, ctx->out);
|
|
return;
|
|
}
|
|
if (rc != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[CL_OL_0015] 조회 오류 key=%s rc=%d(%s)",
|
|
key, rc, tx_strerror(rc));
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESPCODE", RESP_SYSERR);
|
|
tx_return(ctx, rc, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 3. 마감여부 판정 : status='S' 이면 마감완료 */
|
|
is_settled = (strcmp(rec.status, CL_ST_SETTLED) == 0);
|
|
if (strcmp(rec.status, CL_ST_RECV) == 0) st_label = "접수";
|
|
else if (strcmp(rec.status, CL_ST_DONE) == 0) st_label = "처리완료";
|
|
else if (strcmp(rec.status, CL_ST_FAIL) == 0) st_label = "불일치";
|
|
else if (strcmp(rec.status, CL_ST_SETTLED) == 0) st_label = "정산완료";
|
|
else st_label = "미정의";
|
|
|
|
/* 4. 스냅샷 요약행 여부 판정 (merch_id='*SNAP' 규약) */
|
|
is_snap = (strcmp(rec.merch_id, "*SNAP") == 0);
|
|
|
|
/* 5. 동일 가맹점·동일 영업일 형제 거래 집계 (read-only 맥락) */
|
|
strncpy(h_merch_id, rec.merch_id, sizeof(h_merch_id) - 1);
|
|
h_merch_id[sizeof(h_merch_id) - 1] = '\0';
|
|
strncpy(h_biz_date, rec.biz_date, sizeof(h_biz_date) - 1);
|
|
h_biz_date[sizeof(h_biz_date) - 1] = '\0';
|
|
h_sib_cnt = 0;
|
|
h_sib_sum = 0;
|
|
|
|
EXEC SQL SELECT count(*), coalesce(sum(amount), 0)
|
|
INTO :h_sib_cnt, :h_sib_sum
|
|
FROM cl_ledger
|
|
WHERE merch_id = :h_merch_id
|
|
AND biz_date = :h_biz_date;
|
|
|
|
if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) {
|
|
TX_DBIO_LOG_ERR("CL_OL_0015 sibling aggregate");
|
|
h_sib_cnt = 0;
|
|
h_sib_sum = 0;
|
|
}
|
|
|
|
/* 6. 응답 구성 */
|
|
amount_format_won(rec.amount, won, sizeof(won));
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESPCODE", RESP_OK);
|
|
tx_buf_sets(ctx->out, "KEY", rec.key);
|
|
tx_buf_sets(ctx->out, "MERCHID", rec.merch_id);
|
|
tx_buf_sets(ctx->out, "BIZDATE", rec.biz_date);
|
|
tx_buf_setlong(ctx->out, "AMOUNT", rec.amount);
|
|
tx_buf_sets(ctx->out, "AMOUNTWON", won);
|
|
tx_buf_setlong(ctx->out, "FEE", rec.fee);
|
|
tx_buf_sets(ctx->out, "STATUS", rec.status);
|
|
tx_buf_sets(ctx->out, "STATUSLABEL", st_label);
|
|
tx_buf_sets(ctx->out, "CLOSED", is_settled ? "Y" : "N");
|
|
tx_buf_sets(ctx->out, "SNAPSHOT", is_snap ? "Y" : "N");
|
|
tx_buf_setlong(ctx->out, "SIBLINGCNT", h_sib_cnt);
|
|
tx_buf_setlong(ctx->out, "SIBLINGSUM", h_sib_sum);
|
|
|
|
/* 7. 스냅샷 요약행은 집계행이므로 별도 안내 로깅 */
|
|
if (is_snap)
|
|
tx_log(TX_LOG_INFO,
|
|
"[CL_OL_0015] 스냅샷 요약행 조회 key=%s biz=%s Σ=%ld",
|
|
rec.key, rec.biz_date, rec.amount);
|
|
|
|
tx_log(TX_LOG_INFO,
|
|
"[CL_OL_0015] 상태조회 key=%s status=%s(%s) 마감여부=%s 형제=%ld건",
|
|
rec.key, rec.status, st_label, is_settled ? "Y" : "N", h_sib_cnt);
|
|
tx_return(ctx, TX_OK, ctx->out);
|
|
}
|