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/vl_ol_0011.c
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

210 lines
6 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/vl_ol_0011.pgc"
/* @tier medium @module vl @transform validation-online */
/*
* vl_ol_0011.pgc - 승인-매입 정합 검증 서비스 (VL_OL_0011)
*
* 승인번호를 기준으로 승인원장(vl_approval) 과 매입원장(vl_purchase) 을 각각
* 조회하여 금액 합계와 건수를 대사한다. 승인/매입 금액 또는 건수가 불일치하면
* 미대사(VL11xx) 로 판정한다.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "txcore.h"
#include "txcore_dbio.h"
#include "acq_util.h"
#include "vl_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 18 "app/online/vl_ol_0011.pgc"
TX_SERVICE(VL_OL_0011, ctx)
{
/* exec sql begin declare section */
#line 23 "app/online/vl_ol_0011.pgc"
char h_appr_no [ 16 ] ;
#line 24 "app/online/vl_ol_0011.pgc"
long h_appr_amt ;
#line 25 "app/online/vl_ol_0011.pgc"
long h_appr_cnt ;
#line 26 "app/online/vl_ol_0011.pgc"
long h_pur_amt ;
#line 27 "app/online/vl_ol_0011.pgc"
long h_pur_cnt ;
/* exec sql end declare section */
#line 28 "app/online/vl_ol_0011.pgc"
char approval[16];
long amt_diff, cnt_diff;
tx_log(TX_LOG_INFO, "[VL_OL_0011] 승인-매입 정합 검증 서비스 진입");
if (tx_buf_get(ctx->in, "APPRNO", approval, sizeof(approval)) != TX_OK) {
tx_log(TX_LOG_ERROR, "[VL_OL_0011] APPRNO 누락");
tx_buf_sets(ctx->out, "ERRCODE", "VL1100");
tx_return(ctx, TX_EINVAL, ctx->out);
return;
}
strncpy(h_appr_no, approval, sizeof(h_appr_no) - 1);
h_appr_no[sizeof(h_appr_no) - 1] = '\0';
h_appr_amt = 0; h_appr_cnt = 0; h_pur_amt = 0; h_pur_cnt = 0;
/* 1) 승인원장 집계 */
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select coalesce ( SUM ( appr_amount ) , 0 ) , count ( * ) from vl_approval where approval_no = $1 ",
ECPGt_char,(h_appr_no),(long)16,(long)1,(16)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_long,&(h_appr_amt),(long)1,(long)1,sizeof(long),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_long,&(h_appr_cnt),(long)1,(long)1,sizeof(long),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
#line 50 "app/online/vl_ol_0011.pgc"
if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) {
TX_DBIO_LOG_ERR("SELECT vl_approval");
tx_buf_sets(ctx->out, "ERRCODE", "VL1109");
tx_return(ctx, TX_EDB, ctx->out);
return;
}
/* 2) 매입원장 집계 */
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select coalesce ( SUM ( purchase_amount ) , 0 ) , count ( * ) from vl_purchase where approval_no = $1 ",
ECPGt_char,(h_appr_no),(long)16,(long)1,(16)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_long,&(h_pur_amt),(long)1,(long)1,sizeof(long),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_long,&(h_pur_cnt),(long)1,(long)1,sizeof(long),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
#line 63 "app/online/vl_ol_0011.pgc"
if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) {
TX_DBIO_LOG_ERR("SELECT vl_purchase");
tx_buf_sets(ctx->out, "ERRCODE", "VL1119");
tx_return(ctx, TX_EDB, ctx->out);
return;
}
/* 3) 대사 판정 */
amt_diff = h_appr_amt - h_pur_amt;
cnt_diff = h_appr_cnt - h_pur_cnt;
tx_buf_reset(ctx->out);
tx_buf_sets(ctx->out, "APPRNO", approval);
tx_buf_setlong(ctx->out, "APPRAMT", h_appr_amt);
tx_buf_setlong(ctx->out, "APPRCNT", h_appr_cnt);
tx_buf_setlong(ctx->out, "PURAMT", h_pur_amt);
tx_buf_setlong(ctx->out, "PURCNT", h_pur_cnt);
tx_buf_setlong(ctx->out, "AMTDIFF", amt_diff);
if (h_appr_cnt == 0 && h_pur_cnt == 0) {
tx_log(TX_LOG_WARN, "[VL_OL_0011] 승인/매입 원장 없음 appr=%s", approval);
tx_buf_sets(ctx->out, "RESULT", "MISMATCH");
tx_buf_sets(ctx->out, "ERRCODE", "VL1101");
tx_return(ctx, TX_ENOENT, ctx->out);
return;
}
if (amt_diff != 0 || cnt_diff != 0) {
tx_log(TX_LOG_WARN, "[VL_OL_0011] 승인-매입 불일치 appr=%s amtdiff=%ld cntdiff=%ld",
approval, amt_diff, cnt_diff);
tx_buf_sets(ctx->out, "RESULT", "MISMATCH");
tx_buf_sets(ctx->out, "ERRCODE", "VL1103");
tx_return(ctx, TX_OK, ctx->out);
return;
}
tx_buf_sets(ctx->out, "RESULT", "MATCH");
tx_buf_sets(ctx->out, "ERRCODE", RESP_OK);
tx_log(TX_LOG_INFO, "[VL_OL_0011] 승인-매입 정합 appr=%s amt=%ld cnt=%ld",
approval, h_appr_amt, h_appr_cnt);
tx_return(ctx, TX_OK, ctx->out);
}