- 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>
253 lines
8.1 KiB
C
253 lines
8.1 KiB
C
/* Processed by ecpg (15.18 (Debian 15.18-0+deb12u1)) */
|
|
/* These include files are added by the preprocessor */
|
|
#include <ecpglib.h>
|
|
#include <ecpgerrno.h>
|
|
#include <sqlca.h>
|
|
/* End of automatic include section */
|
|
|
|
#line 1 "app/online/cl_ol_0023.pgc"
|
|
/* @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"
|
|
|
|
|
|
#line 1 "/usr/include/postgresql/sqlca.h"
|
|
#ifndef POSTGRES_SQLCA_H
|
|
#define POSTGRES_SQLCA_H
|
|
|
|
#ifndef PGDLLIMPORT
|
|
#if defined(WIN32) || defined(__CYGWIN__)
|
|
#define PGDLLIMPORT __declspec (dllimport)
|
|
#else
|
|
#define PGDLLIMPORT
|
|
#endif /* __CYGWIN__ */
|
|
#endif /* PGDLLIMPORT */
|
|
|
|
#define SQLERRMC_LEN 150
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
struct sqlca_t
|
|
{
|
|
char sqlcaid[8];
|
|
long sqlabc;
|
|
long sqlcode;
|
|
struct
|
|
{
|
|
int sqlerrml;
|
|
char sqlerrmc[SQLERRMC_LEN];
|
|
} sqlerrm;
|
|
char sqlerrp[8];
|
|
long sqlerrd[6];
|
|
/* Element 0: empty */
|
|
/* 1: OID of processed tuple if applicable */
|
|
/* 2: number of rows processed */
|
|
/* after an INSERT, UPDATE or */
|
|
/* DELETE statement */
|
|
/* 3: empty */
|
|
/* 4: empty */
|
|
/* 5: empty */
|
|
char sqlwarn[8];
|
|
/* Element 0: set to 'W' if at least one other is 'W' */
|
|
/* 1: if 'W' at least one character string */
|
|
/* value was truncated when it was */
|
|
/* stored into a host variable. */
|
|
|
|
/*
|
|
* 2: if 'W' a (hopefully) non-fatal notice occurred
|
|
*/ /* 3: empty */
|
|
/* 4: empty */
|
|
/* 5: empty */
|
|
/* 6: empty */
|
|
/* 7: empty */
|
|
|
|
char sqlstate[5];
|
|
};
|
|
|
|
struct sqlca_t *ECPGget_sqlca(void);
|
|
|
|
#ifndef POSTGRES_ECPG_INTERNAL
|
|
#define sqlca (*ECPGget_sqlca())
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#line 25 "app/online/cl_ol_0023.pgc"
|
|
|
|
|
|
#define CL_OL_0023_DEFAULT_CAP 1000000L
|
|
|
|
TX_SERVICE(CL_OL_0023, ctx)
|
|
{
|
|
/* exec sql begin declare section */
|
|
|
|
|
|
|
|
|
|
|
|
#line 32 "app/online/cl_ol_0023.pgc"
|
|
char h_biz_date [ 9 ] ;
|
|
|
|
#line 33 "app/online/cl_ol_0023.pgc"
|
|
char h_st_done [ 2 ] ;
|
|
|
|
#line 34 "app/online/cl_ol_0023.pgc"
|
|
long h_db_used ;
|
|
|
|
#line 35 "app/online/cl_ol_0023.pgc"
|
|
char h_max_key [ 16 ] ;
|
|
/* exec sql end declare section */
|
|
#line 36 "app/online/cl_ol_0023.pgc"
|
|
|
|
|
|
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';
|
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select count ( * ) , coalesce ( max ( key ) , '' ) from cl_ledger where biz_date = $1 and status = $2 ",
|
|
ECPGt_char,(h_biz_date),(long)9,(long)1,(9)*sizeof(char),
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
ECPGt_char,(h_st_done),(long)2,(long)1,(2)*sizeof(char),
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
|
|
ECPGt_long,&(h_db_used),(long)1,(long)1,sizeof(long),
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
ECPGt_char,(h_max_key),(long)16,(long)1,(16)*sizeof(char),
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
|
|
#line 110 "app/online/cl_ol_0023.pgc"
|
|
|
|
|
|
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);
|
|
}
|