- 템플릿 클론(정규화 후 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>
122 lines
4.8 KiB
Text
122 lines
4.8 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)
|
|
{
|
|
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 하한으로 보정한다.
|
|
*/
|
|
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, "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);
|
|
}
|