/* @tier medium @module au @transform authorization-batch */ /* * au_bt_0007.pgc - 가맹점별 승인금액 집계 배치 (매출 리포트) [tier=medium] * * 배치 main 엔트리 포함. 실행: au_bt_0007 [db@host] */ #include #include #include #include "txcore.h" #include "txcore_dbio.h" #include "acq_util.h" #include "au_core.h" EXEC SQL INCLUDE sqlca; static int run_au_bt_0007(const char *biz_date) { EXEC SQL BEGIN DECLARE SECTION; char h_biz_date[9], h_merch[16]; int h_cnt; long h_sum, h_fee; EXEC SQL END DECLARE SECTION; long merchants = 0, grand = 0; strncpy(h_biz_date, biz_date, 8); h_biz_date[8] = '\0'; EXEC SQL DECLARE cur_msum CURSOR FOR SELECT merch_id, count(*), sum(amount), sum(fee) FROM au_ledger WHERE biz_date = :h_biz_date AND status IN ('M','S') GROUP BY merch_id ORDER BY sum(amount) DESC; EXEC SQL OPEN cur_msum; if (sqlca.sqlcode != TX_SQL_OK) { TX_DBIO_LOG_ERR("OPEN cur_msum"); return TX_EDB; } printf("===== 가맹점별 승인집계 [au_bt_0007] date=%s =====\n", biz_date); printf(" %-15s %8s %15s %12s\n", "가맹점", "건수", "승인액", "수수료"); for (;;) { EXEC SQL FETCH cur_msum INTO :h_merch, :h_cnt, :h_sum, :h_fee; if (sqlca.sqlcode == TX_SQL_NOTFOUND) break; if (sqlca.sqlcode != TX_SQL_OK) break; merchants++; grand += h_sum; printf(" %-15s %8d %15ld %12ld\n", h_merch, h_cnt, h_sum, h_fee); } EXEC SQL CLOSE cur_msum; printf(" 가맹점수=%ld 총승인액=%ld\n", merchants, grand); tx_log(TX_LOG_INFO, "[au_bt_0007] 가맹점집계 date=%s merch=%ld", biz_date, merchants); return TX_OK; } int main(int argc, char **argv) { const char *biz_date; const char *target; int rc; tx_set_loglevel(TX_LOG_INFO); if (argc < 2) { fprintf(stderr, "사용법: %s [db@host]\n", argv[0]); return 2; } biz_date = argv[1]; target = (argc >= 3) ? argv[2] : NULL; if (!date_is_valid(biz_date)) { fprintf(stderr, "오류: 유효하지 않은 영업일 '%s'\n", biz_date); return 2; } tx_log(TX_LOG_INFO, "[au_bt_0007] 배치 시작 date=%s", biz_date); rc = au_dbio_connect(target); if (rc != TX_OK) { tx_log(TX_LOG_ERROR, "[au_bt_0007] DB 접속 실패 rc=%d", rc); return 1; } rc = run_au_bt_0007(biz_date); au_dbio_disconnect(); tx_log(TX_LOG_INFO, "[au_bt_0007] 배치 종료 rc=%d(%s)", rc, tx_strerror(rc)); return (rc == TX_OK) ? 0 : 1; }