/* Processed by ecpg (15.18 (Debian 15.18-0+deb12u1)) */ /* These include files are added by the preprocessor */ #include #include #include /* End of automatic include section */ #line 1 "app/online/lg_ol_0023.pgc" /* @tier easy @module lg @transform ledger-online */ /* * lg_ol_0023.pgc - 원장 온라인 서비스 (LG_OL_0023) [tier=easy] * * 수수료 재계산 반영: 지정 영업일의 모든 전표에 대해 수수료를 거래금액의 * 1%(amount/100) 로 일괄 재계산하여 UPDATE 하고, 반영 건수를 응답한다. */ #include #include #include "txcore.h" #include "txcore_dbio.h" #include "acq_util.h" #include "lg_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 16 "app/online/lg_ol_0023.pgc" /* * [업무 개요] * 수수료율 정책이 변경되었거나, 접수 단계에서 수수료가 미계산/오계산된 * 경우, 특정 영업일 전체 전표의 수수료를 일괄 재계산한다. 기준율은 1% * (거래금액 절대값의 1/100) 이며, 음수 전표(취소·역분개)도 절대 크기로 * 수수료를 산정한다. * * [재계산 규칙] * fee = abs(amount) / 100 (정수 나눗셈, 원 단위 절사) * * [처리 절차] * 1) BIZDATE 추출 및 형식 검증. * 2) tx_begin 후 당일 전표 전체를 한 UPDATE 문으로 재계산. * 3) 반영 건수 = sqlca.sqlerrd[2]. * 4) 재계산 직후 당일 수수료 총액을 재집계하여 검산. * 5) tx_commit — 실패 시 tx_abort. * * [응답 필드] * RESPCODE 처리결과코드 * BIZDATE 대상 영업일(에코) * UPDCNT 수수료 재계산 반영 건수 * FEETOTAL 재계산 후 당일 수수료 총액 * * [주의] * 집합 UPDATE 이므로 대량 전표에 대해 원자적으로 처리된다. 대상이 0건이면 * UPDCNT=0 으로 정상 응답한다. * * [연계] * 수수료 재계산은 정산확정(LG_OL_0019) 이전에 선행되어야 정산액이 올바르게 * 산출된다. 이미 정산완료(S) 된 전표까지 포함해 재계산되므로, 정책 소급 * 적용이 필요한 경우에만 운영 승인 하에 호출한다. */ TX_SERVICE(LG_OL_0023, ctx) { /* exec sql begin declare section */ #line 53 "app/online/lg_ol_0023.pgc" char h_biz_date [ 9 ] ; #line 54 "app/online/lg_ol_0023.pgc" long h_updated ; #line 55 "app/online/lg_ol_0023.pgc" long h_fee_total ; /* exec sql end declare section */ #line 56 "app/online/lg_ol_0023.pgc" char bizdate[16]; tx_log(TX_LOG_INFO, "[LG_OL_0023] 수수료 재계산 반영 진입"); if (tx_buf_get(ctx->in, "BIZDATE", bizdate, sizeof(bizdate)) != TX_OK) { tx_log(TX_LOG_ERROR, "[LG_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 (!date_is_valid(bizdate)) { tx_log(TX_LOG_WARN, "[LG_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; } strncpy(h_biz_date, bizdate, sizeof(h_biz_date) - 1); h_biz_date[sizeof(h_biz_date) - 1] = '\0'; if (tx_begin() != TX_OK) { tx_return(ctx, TX_FAIL, ctx->out); return; } /* 수수료 = 거래금액의 1% (음수 전표는 절대 크기 기준) */ { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update lg_ledger set fee = abs ( amount ) / 100 , upd_ts = now ( ) where biz_date = $1 ", ECPGt_char,(h_biz_date),(long)9,(long)1,(9)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} #line 88 "app/online/lg_ol_0023.pgc" if (sqlca.sqlcode != TX_SQL_OK) { TX_DBIO_LOG_ERR("lg_ol_0023 recalc"); tx_abort(); tx_buf_reset(ctx->out); tx_buf_sets(ctx->out, "RESPCODE", RESP_SYSERR); tx_return(ctx, TX_EDB, ctx->out); return; } h_updated = (long)sqlca.sqlerrd[2]; /* 재계산 후 당일 수수료 총액 확인 */ { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select coalesce ( sum ( fee ) , 0 ) from lg_ledger where biz_date = $1 ", ECPGt_char,(h_biz_date),(long)9,(long)1,(9)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_long,&(h_fee_total),(long)1,(long)1,sizeof(long), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} #line 104 "app/online/lg_ol_0023.pgc" if (sqlca.sqlcode != TX_SQL_OK) h_fee_total = 0; if (tx_commit() != TX_OK) { tx_abort(); tx_return(ctx, TX_FAIL, ctx->out); return; } tx_buf_reset(ctx->out); tx_buf_sets(ctx->out, "RESPCODE", RESP_OK); tx_buf_sets(ctx->out, "BIZDATE", bizdate); tx_buf_setlong(ctx->out, "UPDCNT", h_updated); tx_buf_setlong(ctx->out, "FEETOTAL", h_fee_total); tx_log(TX_LOG_INFO, "[LG_OL_0023] 수수료 재계산 완료 date=%s 반영건수=%ld 수수료합=%ld", bizdate, h_updated, h_fee_total); tx_return(ctx, TX_OK, ctx->out); }