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_0023.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

155 lines
5.9 KiB
Text

/* @tier medium @module cl @transform closing-online */
/*
* cl_ol_0023.pgc - 마감 온라인 서비스 (CL_OL_0023) [tier=medium]
*
* 채번 조회
* ----------------------------------------------------------------------
* 요청 영업일(BIZDATE)에 대해 현재까지 마감처리완료(M)된 건수를 채번
* 소진수로 보고, 다음 부여 순번(=소진수+1)을 산출하여 응답한다. 원장을
* 변경하지 않는 read-only 조회이며, 응답의 다음순번은 배치/온라인 채번
* 발급의 힌트로 사용된다.
*
* 소진 현황의 근거로 접수(R)/정산완료(S) 건수도 함께 조회하여 잔여
* 발급 여력(가용 채번 = 상한 - 소진)을 계산한다. 상한(CAP)은 선택 입력
* 으로 받되 미지정 시 일 100만 건을 기본 상한으로 적용한다. 감사추적을
* 위해 선택 입력 REQID/CHANNEL 을 반영한다.
*/
#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;
#define CL_OL_0023_DEFAULT_CAP 1000000L
TX_SERVICE(CL_OL_0023, ctx)
{
EXEC SQL BEGIN DECLARE SECTION;
char h_biz_date[9];
char h_st_done[2];
long h_db_used;
char h_max_key[16];
EXEC SQL END DECLARE SECTION;
char bizdate[16];
char reqid[32];
char channel[16];
char nextseq[16];
char summary[TX_VAL_LEN];
long done_cnt, recv_cnt, settled_cnt;
long next_no;
long cap = 0;
long avail, usage_rate;
tx_log(TX_LOG_INFO, "[CL_OL_0023] 채번 조회 서비스 진입");
/* 1) 입력 수신 및 검증 */
if (tx_buf_get(ctx->in, "BIZDATE", bizdate, sizeof(bizdate)) != TX_OK) {
tx_log(TX_LOG_ERROR, "[CL_OL_0023] BIZDATE 누락");
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);
if (tx_buf_get(ctx->in, "CHANNEL", channel, sizeof(channel)) != TX_OK)
strncpy(channel, "ON", sizeof(channel) - 1);
if (!date_is_valid(bizdate)) {
tx_log(TX_LOG_WARN, "[CL_OL_0023] 영업일 형식 오류 date=%s", bizdate);
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_INVALID);
tx_return(ctx, TX_EINVAL, ctx->out);
return;
}
/* 채번 상한 보정 */
tx_buf_getlong(ctx->in, "CAP", &cap);
if (cap <= 0)
cap = CL_OL_0023_DEFAULT_CAP;
/* 2) 상태별 건수 조회 (표준 DBIO, read-only) */
done_cnt = cl_rec_count(bizdate, CL_ST_DONE);
recv_cnt = cl_rec_count(bizdate, CL_ST_RECV);
settled_cnt = cl_rec_count(bizdate, CL_ST_SETTLED);
if (done_cnt < 0 || recv_cnt < 0 || settled_cnt < 0) {
tx_log(TX_LOG_ERROR, "[CL_OL_0023] 채번 소진수 조회 실패 date=%s", bizdate);
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_SYSERR);
tx_return(ctx, TX_EDB, ctx->out);
return;
}
/*
* 3) 다음 순번 산출 및 채번 키 구성(YYYYMMDD + 6자리 일련)
* - 소진수(done_cnt)는 이미 마감완료(M)로 확정된 건수이므로
* 다음 발급 순번은 소진수 + 1 이 된다.
* - 가용 여력(avail)은 일 상한(cap)에서 소진수를 뺀 값이며
* 음수가 되지 않도록 0 하한으로 보정한다.
*/
/*
* 2-1) 원장 직접 집계로 소진수(마감완료 M)를 재확인하고, 이미 발급된
* 최대 처리키를 조회하여 채번 연속성의 근거로 삼는다.
*/
strncpy(h_biz_date, bizdate, sizeof(h_biz_date) - 1);
h_biz_date[sizeof(h_biz_date) - 1] = '\0';
strncpy(h_st_done, CL_ST_DONE, sizeof(h_st_done));
h_db_used = 0;
h_max_key[0] = '\0';
EXEC SQL SELECT count(*), coalesce(max(key), '')
INTO :h_db_used, :h_max_key
FROM cl_ledger
WHERE biz_date = :h_biz_date
AND status = :h_st_done;
if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) {
TX_DBIO_LOG_ERR("CL_OL_0023 direct used");
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_SYSERR);
tx_return(ctx, TX_EDB, ctx->out);
return;
}
next_no = done_cnt + 1;
avail = (cap > done_cnt) ? (cap - done_cnt) : 0;
usage_rate = (cap > 0) ? (done_cnt * 100 / cap) : 0;
snprintf(nextseq, sizeof(nextseq), "%.8s%06ld", bizdate, next_no);
/* 4) 채번 현황 요약 문구 */
snprintf(summary, sizeof(summary),
"영업일 %s 채번 소진 %ld / 상한 %ld (소진율 %ld%%), 다음순번 %ld",
bizdate, done_cnt, cap, usage_rate, next_no);
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "RESPCODE", RESP_OK);
tx_buf_sets(ctx->out, "BIZDATE", bizdate);
tx_buf_sets(ctx->out, "REQID", reqid);
tx_buf_sets(ctx->out, "CHANNEL", channel);
tx_buf_setlong(ctx->out, "USEDCNT", done_cnt);
tx_buf_setlong(ctx->out, "DBUSED", h_db_used);
tx_buf_sets(ctx->out, "MAXKEY", h_max_key);
tx_buf_setlong(ctx->out, "RECVCNT", recv_cnt);
tx_buf_setlong(ctx->out, "SETTLEDCNT", settled_cnt);
tx_buf_setlong(ctx->out, "CAP", cap);
tx_buf_setlong(ctx->out, "AVAIL", avail);
tx_buf_setlong(ctx->out, "USAGERATE", usage_rate);
tx_buf_setlong(ctx->out, "NEXTNO", next_no);
tx_buf_sets(ctx->out, "NEXTSEQ", nextseq);
tx_buf_sets(ctx->out, "SUMMARY", summary);
tx_buf_sets(ctx->out, "EXHAUSTED", (avail == 0) ? "Y" : "N");
/* 발급 여력 임계(잔여 상한의 10% 미만) 사전 경고 플래그 */
tx_buf_sets(ctx->out, "LOWALERT",
(cap > 0 && avail * 10 < cap) ? "Y" : "N");
tx_log(TX_LOG_INFO,
"[CL_OL_0023] 완료 date=%s 소진=%ld 다음순번=%ld 가용=%ld ch=%s",
bizdate, done_cnt, next_no, avail, channel);
tx_return(ctx, TX_OK, ctx->out);
}