- 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>
160 lines
6.2 KiB
Text
160 lines
6.2 KiB
Text
/* @tier easy @module cl @transform closing-online */
|
|
/*
|
|
* cl_ol_0017.pgc - 마감 온라인 서비스 (CL_OL_0017) [tier=easy]
|
|
*
|
|
* 일마감 검증
|
|
* ----------------------------------------------------------------------
|
|
* 요청 영업일(BIZDATE)에 대해 아직 마감되지 않은 미마감(R) 건이 하나도
|
|
* 없는지 확인하여 일마감 가능 여부를 판정한다. 미마감 건수가 0 이면
|
|
* 해당 영업일은 일마감 유효(VALID=Y), 1건이라도 남아 있으면 미마감
|
|
* 잔량이 존재하므로 일마감 불가(VALID=N)로 응답한다.
|
|
*
|
|
* 검증의 판단 근거를 함께 제공하기 위해 상태별 건수(R/M/U/S)를 모두
|
|
* 수집하여 응답하고, 마감 확정 시 정산이 이루어질 예정영업일(다음
|
|
* 영업일)을 계산하여 참고 필드로 반환한다. 요청 감사추적을 위해
|
|
* 선택 입력 REQID/OPER 를 로그와 응답에 반영한다.
|
|
*/
|
|
#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_0017, ctx)
|
|
{
|
|
EXEC SQL BEGIN DECLARE SECTION;
|
|
char h_biz_date[9];
|
|
long h_db_total;
|
|
long h_db_amt;
|
|
EXEC SQL END DECLARE SECTION;
|
|
|
|
char bizdate[16];
|
|
char reqid[32];
|
|
char oper[32];
|
|
char nextbiz[9];
|
|
char summary[TX_VAL_LEN];
|
|
long recv_cnt, done_cnt, fail_cnt, settled_cnt;
|
|
long total_cnt, processed_cnt, complete_rate;
|
|
long db_diff;
|
|
int valid;
|
|
|
|
tx_log(TX_LOG_INFO, "[CL_OL_0017] 일마감 검증 서비스 진입");
|
|
|
|
/* 1) 필수 입력 수신 */
|
|
if (tx_buf_get(ctx->in, "BIZDATE", bizdate, sizeof(bizdate)) != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[CL_OL_0017] 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, "OPER", oper, sizeof(oper)) != TX_OK)
|
|
strncpy(oper, "BATCH", sizeof(oper) - 1);
|
|
|
|
/* 2) 영업일 형식 검증 */
|
|
if (!date_is_valid(bizdate)) {
|
|
tx_log(TX_LOG_WARN, "[CL_OL_0017] 영업일 형식 오류 date=%s reqid=%s",
|
|
bizdate, reqid);
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESPCODE", RESP_INVALID);
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 3) 상태별 건수 수집 - 표준 DBIO 채널 이용 (read-only) */
|
|
recv_cnt = cl_rec_count(bizdate, CL_ST_RECV);
|
|
done_cnt = cl_rec_count(bizdate, CL_ST_DONE);
|
|
fail_cnt = cl_rec_count(bizdate, CL_ST_FAIL);
|
|
settled_cnt = cl_rec_count(bizdate, CL_ST_SETTLED);
|
|
|
|
if (recv_cnt < 0 || done_cnt < 0 || fail_cnt < 0 || settled_cnt < 0) {
|
|
tx_log(TX_LOG_ERROR, "[CL_OL_0017] 상태별 건수 조회 실패 date=%s", bizdate);
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESPCODE", RESP_SYSERR);
|
|
tx_return(ctx, TX_EDB, ctx->out);
|
|
return;
|
|
}
|
|
total_cnt = recv_cnt + done_cnt + fail_cnt + settled_cnt;
|
|
|
|
/*
|
|
* 3-1) 원장 직접 집계로 상태별 DBIO 합계를 교차검증한다.
|
|
* DBIO 채널 합계(total_cnt)와 원장 실집계(h_db_total)가
|
|
* 다르면 대사 불일치로 간주하여 감사 로그를 남긴다.
|
|
*/
|
|
strncpy(h_biz_date, bizdate, sizeof(h_biz_date) - 1);
|
|
h_biz_date[sizeof(h_biz_date) - 1] = '\0';
|
|
h_db_total = 0;
|
|
h_db_amt = 0;
|
|
|
|
EXEC SQL SELECT count(*), coalesce(sum(amount), 0)
|
|
INTO :h_db_total, :h_db_amt
|
|
FROM cl_ledger
|
|
WHERE biz_date = :h_biz_date;
|
|
|
|
if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) {
|
|
TX_DBIO_LOG_ERR("CL_OL_0017 direct total");
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESPCODE", RESP_SYSERR);
|
|
tx_return(ctx, TX_EDB, ctx->out);
|
|
return;
|
|
}
|
|
db_diff = total_cnt - h_db_total;
|
|
if (db_diff != 0)
|
|
tx_log(TX_LOG_WARN, "[CL_OL_0017] 집계 대사 불일치 dbio=%ld ledger=%ld",
|
|
total_cnt, h_db_total);
|
|
|
|
/* 4) 일마감 유효성 판정: 미마감 잔량이 0 이어야 유효 */
|
|
valid = (recv_cnt == 0) ? 1 : 0;
|
|
|
|
/* 5) 처리 진행률 = (마감 대상에서 미마감을 제외한 비율) */
|
|
processed_cnt = done_cnt + fail_cnt + settled_cnt;
|
|
complete_rate = (total_cnt > 0) ? (processed_cnt * 100 / total_cnt) : 100;
|
|
|
|
/* 6) 마감 확정 시 정산 예정영업일 = 다음 영업일 */
|
|
if (date_next_business(bizdate, nextbiz) != 0) {
|
|
memcpy(nextbiz, bizdate, 8);
|
|
nextbiz[8] = '\0';
|
|
}
|
|
|
|
/* 7) 판정 요약 문구 구성 */
|
|
snprintf(summary, sizeof(summary),
|
|
"영업일 %s 마감대상 %ld건 중 미마감 %ld건 (처리율 %ld%%)",
|
|
bizdate, total_cnt, recv_cnt, complete_rate);
|
|
|
|
/* 8) 응답 구성 */
|
|
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, "OPER", oper);
|
|
tx_buf_setlong(ctx->out, "RECVCNT", recv_cnt);
|
|
tx_buf_setlong(ctx->out, "DONECNT", done_cnt);
|
|
tx_buf_setlong(ctx->out, "FAILCNT", fail_cnt);
|
|
tx_buf_setlong(ctx->out, "SETTLEDCNT", settled_cnt);
|
|
tx_buf_setlong(ctx->out, "TOTALCNT", total_cnt);
|
|
tx_buf_setlong(ctx->out, "DBTOTAL", h_db_total);
|
|
tx_buf_setlong(ctx->out, "DBAMT", h_db_amt);
|
|
tx_buf_setlong(ctx->out, "DBDIFF", db_diff);
|
|
tx_buf_sets(ctx->out, "RECONMATCH", (db_diff == 0) ? "Y" : "N");
|
|
tx_buf_setlong(ctx->out, "PROCESSEDCNT", processed_cnt);
|
|
tx_buf_setlong(ctx->out, "COMPLETERATE", complete_rate);
|
|
tx_buf_sets(ctx->out, "NEXTBIZ", nextbiz);
|
|
tx_buf_sets(ctx->out, "SUMMARY", summary);
|
|
tx_buf_sets(ctx->out, "VALID", valid ? "Y" : "N");
|
|
tx_buf_sets(ctx->out, "MESSAGE",
|
|
valid ? "일마감 가능(미마감 없음)" : "미마감 잔량 존재로 일마감 불가");
|
|
|
|
tx_log(TX_LOG_INFO,
|
|
"[CL_OL_0017] 완료 date=%s R=%ld M=%ld U=%ld S=%ld valid=%s reqid=%s",
|
|
bizdate, recv_cnt, done_cnt, fail_cnt, settled_cnt,
|
|
valid ? "Y" : "N", reqid);
|
|
tx_return(ctx, TX_OK, ctx->out);
|
|
}
|