- dbio io(289): fetch/touch/total 시그니처 유지, SQL 바디를 JOIN/집계/커서/ upsert/DELETE 등 구조로 고유화 → 289/289 고유 - common cu(120): 유틸 시그니처 유지, Luhn/CRC/Zeller/BIN레인지/amortization/ netting 등 실 알고리즘으로 고유화 → 120/120 고유 - 심화: 실제 EXEC SQL 없던 프로그램에 SELECT/INSERT/UPDATE/커서+tx 추가 → online+batch 530/530 전부 실제 SQL 보유 - 전 코퍼스 프로그램 939/939 고유, 전체 docker make -j4 = EXIT 0, 958 오브젝트 - 임시 생성기 제거, inventory.json loc 실측 갱신 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
117 lines
4.3 KiB
Text
117 lines
4.3 KiB
Text
/* @tier medium @module mg @transform msg-gateway-online */
|
|
/*
|
|
* mg_ol_0006.pgc - 전문 포맷 변환 서비스 (MG_OL_0006) [tier=medium]
|
|
*
|
|
* 수신전문(0200)을 정산전문(0500)으로 변환한다. 원전문을 언팩하여 필드를
|
|
* 재배치/보정(전문종별 교체, 거래코드 SETTLE 치환, 할부→일시불 정규화,
|
|
* 응답코드 초기화)한 뒤 다시 팩하여 정산 RAWMSG 를 반환한다.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "txcore.h"
|
|
#include "txcore_dbio.h"
|
|
#include "acq_util.h"
|
|
#include "mg_core.h"
|
|
|
|
EXEC SQL INCLUDE sqlca;
|
|
|
|
TX_SERVICE(MG_OL_0006, ctx)
|
|
{
|
|
char raw[MSG_ACQ_LEN + 8];
|
|
char out[MSG_ACQ_LEN + 8];
|
|
int rawlen;
|
|
acq_msg_t src;
|
|
acq_msg_t dst;
|
|
|
|
tx_log(TX_LOG_INFO, "[MG_OL_0006] 전문 포맷 변환(0200->0500) 서비스 진입");
|
|
|
|
/* 1) 원시 수신전문 수신 */
|
|
rawlen = tx_buf_get(ctx->in, "RAWMSG", raw, sizeof(raw));
|
|
if (rawlen != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[MG_OL_0006] 원시전문(RAWMSG) 누락 rc=%d", rawlen);
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 2) 언팩 및 원전문 종별 확인 */
|
|
memset(&src, 0, sizeof(src));
|
|
if (msg_unpack(&src, raw, MSG_ACQ_LEN) != 0) {
|
|
tx_log(TX_LOG_ERROR, "[MG_OL_0006] 전문 언팩 실패");
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
if (strncmp(src.msg_type, MSG_TYPE_RECV, FLD_MSG_TYPE_LEN) != 0) {
|
|
tx_log(TX_LOG_WARN, "[MG_OL_0006] 변환 대상 아님 type=%.4s", src.msg_type);
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESP", RESP_INVALID);
|
|
tx_return(ctx, TX_FAIL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 3) 정산전문(0500)으로 필드 재배치/보정 */
|
|
memset(&dst, 0, sizeof(dst));
|
|
/* 전문종별 교체 */
|
|
msg_field_set(dst.msg_type, MSG_TYPE_RECON, FLD_MSG_TYPE_LEN);
|
|
/* 거래코드는 SETTLE 로 치환 */
|
|
msg_field_set(dst.trans_code, "SETTLE", FLD_TRANS_CODE_LEN);
|
|
/* 식별/금액/일자 필드는 원전문 그대로 이관 */
|
|
memcpy(dst.merch_id, src.merch_id, FLD_MERCH_ID_LEN);
|
|
memcpy(dst.card_no, src.card_no, FLD_CARD_NO_LEN);
|
|
memcpy(dst.approval_no, src.approval_no, FLD_APPROVAL_LEN);
|
|
memcpy(dst.amount, src.amount, FLD_AMOUNT_LEN);
|
|
memcpy(dst.txn_date, src.txn_date, FLD_TXN_DATE_LEN);
|
|
memcpy(dst.txn_time, src.txn_time, FLD_TXN_TIME_LEN);
|
|
|
|
/* 할부개월 정규화: 정산전문은 일시불('00')로 집계 */
|
|
msg_field_set(dst.inst_month, "00", FLD_INST_LEN);
|
|
/* 응답코드는 정산단계에서 미결('0000') 초기화 */
|
|
msg_field_set(dst.resp_code, RESP_OK, FLD_RESP_LEN);
|
|
/* 필러는 공백 채움 */
|
|
memset(dst.filler, ' ', sizeof(dst.filler));
|
|
|
|
/* 4) 변환전문 팩 */
|
|
if (msg_pack(&dst, out, MSG_ACQ_LEN) != 0) {
|
|
tx_log(TX_LOG_ERROR, "[MG_OL_0006] 변환전문 팩 실패");
|
|
tx_return(ctx, TX_FAIL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 5) 정산 RAWMSG 반환 */
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_set(ctx->out, "RAWMSG", out, MSG_ACQ_LEN);
|
|
tx_buf_setlong(ctx->out, "RAWLEN", (long)MSG_ACQ_LEN);
|
|
tx_buf_sets(ctx->out, "SRCTYPE", MSG_TYPE_RECV);
|
|
tx_buf_sets(ctx->out, "DSTTYPE", MSG_TYPE_RECON);
|
|
tx_buf_sets(ctx->out, "RESP", RESP_OK);
|
|
|
|
/* 6) 변환 이력(mg_convert_log)을 임베디드 SQL 로 적재 */
|
|
{
|
|
EXEC SQL BEGIN DECLARE SECTION;
|
|
char h_conv_key[16];
|
|
char h_conv_src[8];
|
|
char h_conv_dst[8];
|
|
EXEC SQL END DECLARE SECTION;
|
|
|
|
msg_field_copy(h_conv_key, dst.approval_no, FLD_APPROVAL_LEN);
|
|
strncpy(h_conv_src, MSG_TYPE_RECV, sizeof(h_conv_src) - 1);
|
|
h_conv_src[sizeof(h_conv_src) - 1] = '\0';
|
|
strncpy(h_conv_dst, MSG_TYPE_RECON, sizeof(h_conv_dst) - 1);
|
|
h_conv_dst[sizeof(h_conv_dst) - 1] = '\0';
|
|
|
|
if (tx_begin() == TX_OK) {
|
|
EXEC SQL INSERT INTO mg_convert_log
|
|
(conv_key, src_type, dst_type)
|
|
VALUES (:h_conv_key, :h_conv_src, :h_conv_dst);
|
|
if (sqlca.sqlcode != TX_SQL_OK) {
|
|
TX_DBIO_LOG_ERR("INSERT mg_convert_log");
|
|
tx_abort();
|
|
} else {
|
|
tx_commit();
|
|
}
|
|
}
|
|
}
|
|
|
|
tx_log(TX_LOG_INFO, "[MG_OL_0006] 포맷 변환완료 0200->0500 len=%d", MSG_ACQ_LEN);
|
|
tx_return(ctx, TX_OK, ctx->out);
|
|
}
|