- 템플릿 클론(정규화 후 0줄 상이) → 전 코퍼스 530/530 고유 바디 - 11개 모듈(mg/au/ac/rc/vl/st/py/lg/mm/cm/cl) 각 파일이 distinct한 매입·대사·정산·수수료·지급·원장·마감·마스터·정합성·전문게이트웨이·공통 업무 - TxCore(ATMI 유사) + ECPG(EXEC SQL) 관용구, 프레임워크/헤더/DBIO API/파일ID·경로 유지 - 전체 docker make -j4 = EXIT 0, 958 오브젝트, 데모 바이너리 링크 - inventory.json loc 실측 갱신 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
85 lines
2.9 KiB
Text
85 lines
2.9 KiB
Text
/* @tier easy @module mg @transform msg-gateway-online */
|
|
/*
|
|
* mg_ol_0001.pgc - 전문게이트웨이 전문 수신 서비스 (MG_OL_0001) [tier=easy]
|
|
*
|
|
* 채널로부터 수신한 고정길이 원시전문(0200)을 acq_msg_t 로 언팩/검증한
|
|
* 뒤, 전문게이트웨이 원장(mg_ledger)에 접수상태('R')로 적재한다.
|
|
* (ATMI void SVC(TPSVCINFO*) 대응)
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "txcore.h"
|
|
#include "acq_util.h"
|
|
#include "mg_core.h"
|
|
|
|
EXEC SQL INCLUDE sqlca;
|
|
|
|
TX_SERVICE(MG_OL_0001, ctx)
|
|
{
|
|
char raw[256];
|
|
int rawlen;
|
|
acq_msg_t msg;
|
|
mg_rec_t rec;
|
|
long amount;
|
|
int rc;
|
|
|
|
tx_log(TX_LOG_INFO, "[MG_OL_0001] 전문 수신 서비스 진입");
|
|
|
|
/* 1) 원시전문 수신 (고정길이 프레임) */
|
|
rawlen = tx_buf_get(ctx->in, "RAWMSG", raw, sizeof(raw));
|
|
if (rawlen <= 0) {
|
|
tx_log(TX_LOG_ERROR, "[MG_OL_0001] 원시전문(RAWMSG) 누락");
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 2) 고정길이 언팩 */
|
|
memset(&msg, 0, sizeof(msg));
|
|
if (msg_unpack(&msg, raw, (int)strlen(raw)) != 0) {
|
|
tx_log(TX_LOG_ERROR, "[MG_OL_0001] 전문 언팩 실패 len=%d", (int)strlen(raw));
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 3) 전문 검증 (전문종별/필수필드) */
|
|
if (msg_validate(&msg) != 0 ||
|
|
strncmp(msg.msg_type, MSG_TYPE_RECV, FLD_MSG_TYPE_LEN) != 0) {
|
|
tx_log(TX_LOG_WARN, "[MG_OL_0001] 전문 검증 실패 type=%.4s", msg.msg_type);
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESP", RESP_INVALID);
|
|
tx_return(ctx, TX_FAIL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 4) 구조체 -> 원장 레코드 매핑 */
|
|
amount = amount_parse(msg.amount, FLD_AMOUNT_LEN);
|
|
memset(&rec, 0, sizeof(rec));
|
|
msg_field_copy(rec.key, msg.approval_no, FLD_APPROVAL_LEN);
|
|
msg_field_copy(rec.merch_id, msg.merch_id, FLD_MERCH_ID_LEN);
|
|
msg_field_copy(rec.card_no, msg.card_no, FLD_CARD_NO_LEN);
|
|
msg_field_copy(rec.biz_date, msg.txn_date, FLD_TXN_DATE_LEN);
|
|
rec.amount = amount;
|
|
rec.fee = 0;
|
|
strncpy(rec.status, MG_ST_RECV, sizeof(rec.status) - 1);
|
|
|
|
/* 5) 원장 적재 */
|
|
rc = mg_rec_insert(&rec);
|
|
if (rc != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[MG_OL_0001] 원장 적재 실패 key=%s rc=%d(%s)",
|
|
rec.key, rc, tx_strerror(rc));
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESP", RESP_SYSERR);
|
|
tx_return(ctx, rc, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 6) 수신확인 응답 구성 */
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESP", RESP_OK);
|
|
tx_buf_sets(ctx->out, "KEY", rec.key);
|
|
tx_buf_setlong(ctx->out, "AMOUNT", rec.amount);
|
|
tx_buf_sets(ctx->out, "STATUS", rec.status);
|
|
tx_log(TX_LOG_INFO, "[MG_OL_0001] 전문 수신완료 key=%s amount=%ld", rec.key, rec.amount);
|
|
tx_return(ctx, TX_OK, ctx->out);
|
|
}
|