- 템플릿 클론(정규화 후 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>
200 lines
6.4 KiB
C
200 lines
6.4 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_0017.pgc"
|
|
/* @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"
|
|
|
|
|
|
#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_0017.pgc"
|
|
|
|
|
|
TX_SERVICE(CL_OL_0017, ctx)
|
|
{
|
|
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;
|
|
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;
|
|
|
|
/* 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, "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);
|
|
}
|