/*
 * RC_ALERT.pgc - rc 모듈 서비스 RC_ALERT (one service = one file).
 * Moved verbatim from the former inline rc_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by rc_svr at tpsvrinit.
 */
#include "RC_ALERT.h"

/* 26. RC_ALERT - 대사 경보 등록. */
void RC_ALERT(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char bizdate[16], msg[128], lvl[16];
    EXEC SQL BEGIN DECLARE SECTION;
    long h_id, h_pid;
    char h_bizdate[16], h_msg[128], h_lvl[16];
    EXEC SQL END DECLARE SECTION;
    h_pid = getl(b, T_PURCHASE_ID);
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    gets_(b, T_MSG, msg, sizeof(msg)); if (msg[0] == 0) strcpy(msg, "대사 지연 경보");
    gets_(b, T_STR1, lvl, sizeof(lvl)); if (lvl[0] == 0) strcpy(lvl, "WARN");
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    strncpy(h_msg, msg, sizeof(h_msg)-1); h_msg[sizeof(h_msg)-1] = 0;
    strncpy(h_lvl, lvl, sizeof(h_lvl)-1); h_lvl[sizeof(h_lvl)-1] = 0;
    EXEC SQL SELECT nextval('rc_alert_seq') INTO :h_id;
    if (sqlca.sqlcode < 0) FAIL(b);
    EXEC SQL INSERT INTO rc_alert (alert_id, purchase_id, lvl, message, biz_date)
        VALUES (:h_id, :h_pid, :h_lvl, :h_msg, :h_bizdate);
    if (sqlca.sqlcode < 0) { userlog("RC_ALERT INSERT FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); FAIL(b); }
    setl(b, T_ID1, h_id);
    OK(b);
}

/* vim: set ts=4 sw=4 et smartindent: */
