/* 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/cl_ol_0011.pgc" /* @tier easy @module cl @transform closing-online */ /* * cl_ol_0011.pgc - 마감 온라인 서비스 (CL_OL_0011) [tier=easy] * * 마감 알림 발송(판정). 요청 영업일(BIZDATE)에 미마감(접수 R) 건이 남아 * 있는지 확인하여, 남아 있으면 알림 대상(ALERT=Y)으로 미마감 건수·금액을 * 함께 반환하고, 없으면 ALERT=N 으로 응답한다. 원장을 변경하지 않는 * read-only 판정 서비스이다. (실제 발송채널 연계는 상위 오케스트레이션 담당) * * ── 서비스 계약(Contract) ──────────────────────────────────────────── * 입력 필드: * BIZDATE (필수) 영업일(YYYYMMDD) * 출력 필드: * RESPCODE 0000=정상 / 9001=입력오류 / 9999=시스템오류 * BIZDATE 점검 대상 영업일 * RECVCNT 미마감(접수 R) 건수 * RECVSUM 미마감 금액합계(원) * RECVWON 미마감 금액 한글 표기 * ALERT 알림 필요여부(Y=미마감 존재 / N=없음) * MESSAGE 판정 사유 메시지 * * ── 알림 판정 규칙 ─────────────────────────────────────────────────── * · 접수(R) 상태는 아직 마감처리 흐름에 진입하지 않은 원건이다. * · R 건이 1건 이상이면 마감 담당자 알림 대상(ALERT=Y)으로 분류한다. * · R 건이 없으면 마감 준비 완료로 보고 ALERT=N 을 반환한다. * · 본 서비스는 판정만 수행하며 실제 SMS/메일 발송은 상위에서 처리. * * ── 처리 흐름 ──────────────────────────────────────────────────────── * 1) BIZDATE 추출/형식검증 * 2) status='R' 건수·금액합계 singleton SELECT * 3) 건수 기준 ALERT Y/N 판정 및 응답 구성 * * ── 후속 연계(참고) ────────────────────────────────────────────────── * · ALERT=Y 응답을 받은 상위 오케스트레이션은 마감 담당자 그룹으로 * SMS/메일/사내 메신저 알림을 발송한다. * · RECVCNT/RECVWON 은 알림 본문의 미마감 규모 안내에 사용된다. * · 본 서비스는 판정 근거만 제공하고 실제 채널 I/O 는 수행하지 않아 * DB 커넥션 외 외부 자원에 의존하지 않는 순수 조회 서비스이다. */ #include #include #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 48 "app/online/cl_ol_0011.pgc" TX_SERVICE(CL_OL_0011, ctx) { /* exec sql begin declare section */ #line 53 "app/online/cl_ol_0011.pgc" char h_biz_date [ 9 ] ; #line 54 "app/online/cl_ol_0011.pgc" int h_recv_cnt ; #line 55 "app/online/cl_ol_0011.pgc" long h_recv_sum ; /* exec sql end declare section */ #line 56 "app/online/cl_ol_0011.pgc" char bizdate[16]; char won[40]; tx_log(TX_LOG_INFO, "[CL_OL_0011] 마감 알림 판정 서비스 진입"); /* 1. 요청 검증 */ if (tx_buf_get(ctx->in, "BIZDATE", bizdate, sizeof(bizdate)) != TX_OK) { tx_log(TX_LOG_ERROR, "[CL_OL_0011] 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, "[CL_OL_0011] 영업일 형식 오류 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'; /* 2. 미마감(R) 존재여부 및 금액 집계 */ { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select count ( * ) , coalesce ( sum ( amount ) , 0 ) from cl_ledger where biz_date = $1 and status = 'R'", ECPGt_char,(h_biz_date),(long)9,(long)1,(9)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_int,&(h_recv_cnt),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_long,&(h_recv_sum),(long)1,(long)1,sizeof(long), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} #line 87 "app/online/cl_ol_0011.pgc" if (sqlca.sqlcode != TX_SQL_OK) { TX_DBIO_LOG_ERR("CL_OL_0011 recv aggregate"); tx_buf_reset(ctx->out); tx_buf_sets(ctx->out, "RESPCODE", RESP_SYSERR); tx_return(ctx, TX_EDB, ctx->out); return; } /* 3. 알림 판정 및 응답 구성 (판정 근거 상세 로깅) */ tx_log(TX_LOG_DEBUG, "[CL_OL_0011] 판정근거 date=%s 미마감R건수=%d 금액=%ld", bizdate, h_recv_cnt, h_recv_sum); amount_format_won(h_recv_sum, won, sizeof(won)); 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, "RECVCNT", (long)h_recv_cnt); tx_buf_setlong(ctx->out, "RECVSUM", h_recv_sum); tx_buf_sets(ctx->out, "RECVWON", won); /* 미마감(R) 잔존 시 알림 대상, 아니면 마감 준비완료로 판정 */ if (h_recv_cnt > 0) { tx_buf_sets(ctx->out, "ALERT", "Y"); tx_buf_setlong(ctx->out, "ALERTLEVEL", (h_recv_cnt >= 100) ? 2 : 1); tx_buf_sets(ctx->out, "MESSAGE", "미마감 접수건 존재 - 마감 알림 대상"); tx_log(TX_LOG_WARN, "[CL_OL_0011] 알림대상 date=%s 미마감=%d 금액=%ld", bizdate, h_recv_cnt, h_recv_sum); } else { tx_buf_sets(ctx->out, "ALERT", "N"); tx_buf_sets(ctx->out, "MESSAGE", "미마감 접수건 없음 - 알림 불필요"); tx_log(TX_LOG_INFO, "[CL_OL_0011] 알림불요 date=%s", bizdate); } tx_return(ctx, TX_OK, ctx->out); }