1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
'use server';
import { oracleKnex, getOracleConnection } from "@/lib/oracle-db/db";
import { readFileSync } from "fs";
import { join } from "path";
import creditServiceMapping from "./creditServiceMapping.json";
import { getTaxIdByVendorId } from "@/lib/vendors/repository";
// SQL 파일 읽기
const getCreditQuerySQL = () => {
const sqlPath = join(process.cwd(), "lib/oracle-db/nonsap/services/creditServiceQuery.sql");
return readFileSync(sqlPath, "utf8");
};
// 신용평가사 코드 변환 함수
const convertCreditGbToCode = (creditGb: string): string => {
// 이미 1글자 코드인 경우 그대로 반환
if (creditGb.length === 1 && creditServiceMapping.hasOwnProperty(creditGb)) {
return creditGb;
}
// 한글 이름인 경우 코드로 변환
const code = creditServiceMapping[creditGb as keyof typeof creditServiceMapping];
if (code && typeof code === "string" && code.length === 1) {
return code;
}
throw new Error(`유효하지 않은 신용평가사 코드: ${creditGb}`);
};
// 방법 1: knex.raw() 사용 (네임드 바인드 변수)
// reno: 사업자번호, credit_gb: 신용평가사 코드
export const getCreditInfo = async (id: string, credit_gb: string) => {
const query = getCreditQuerySQL();
const bindParameters = {
reno: await getTaxIdByVendorId(id),
credit_gb: convertCreditGbToCode(credit_gb)
}
const result = await oracleKnex.raw(query, bindParameters);
// Oracle knex raw 결과에서 실제 rows 추출
const rows = Array.isArray(result) ? result : result.rows || [];
return rows;
};
// 방법 2: oracledb 직접 사용 (네임드 바인드 변수)
// reno: 사업자번호, credit_gb: 신용평가사 코드
export const getCreditInfoWithOracleDb = async (reno: string, credit_gb: string) => {
const connection = await getOracleConnection();
try {
const query = getCreditQuerySQL();
const creditGbCode = convertCreditGbToCode(credit_gb);
const result = await connection.execute(query, {
reno: reno,
credit_gb: creditGbCode
});
return result.rows || [];
} finally {
await connection.close();
}
// UI 테스트용 목업 데이터 (필요시 주석 해제)
// const mockData = getMockCreditData(reno, credit_gb);
// return [mockData];
};
// 편의 함수: 신용평가사 코드 목록 조회
export const getCreditServiceCodes = async () => {
const codes = Object.keys(creditServiceMapping).filter(key => key.length === 1);
return codes.map(code => ({
code: code,
name: creditServiceMapping[code as keyof typeof creditServiceMapping]
}));
};
// 편의 함수: 신용평가사 이름 목록 조회
export const getCreditServiceNames = async () => {
const names = Object.keys(creditServiceMapping).filter(key => key.length > 1);
return names.map(name => ({
name: name,
code: creditServiceMapping[name as keyof typeof creditServiceMapping]
}));
};
// 임시 테스트 데이터
const getMockCreditData = (reno: string, credit_gb: string) => {
return {
RESNO: reno,
EENTNM: "SAMPLE COMPANY LTD",
OPEDT: "2005.03.15",
REPR_NM: "홍길동",
TYSCALE: "중소기업",
RELCMP: "독립회사",
ADR: "서울특별시 강남구 테헤란로 123",
LISTYN: "비상장",
GOODSNM: "전자부품제조",
TELNO: "02-1234-5678",
FAXNO: "02-1234-5679",
FSTRDRT: "15.2",
// 매출순위
MO_1: "현대중공업",
MO_4: "27",
MO_2: "대우조선해양",
MO_5: "25",
MO_3: "삼성물산",
MO_6: "21",
// 매입순위
MI_1: "안전세관",
MI_4: "152",
MI_2: "부산세관",
MI_5: "84",
MI_3: "포디어션푸드(주)",
MI_6: "4",
// 지분관계
GIBUN_RL_1: "Kongsberg Maritime",
LSH_STK_RATE1: "100",
GIBUN_RL_2: "",
LSH_STK_RATE2: "0",
GIBUN_RL_3: "",
LSH_STK_RATE3: "0",
// 기타 정보
HAPGYE: "228",
NOTICE: "",
NOTICE_DT: "",
HPGBNCR_TY: "정상",
FCLOSDT: "",
LASTGRD: "BBB+",
DECISION: "A",
FRISKRV: "R-2",
EXPIRE_GB: "",
FWATCHD: "정상",
SUVDT: "2021.04.26",
ESETDTT: "2020.12.31",
// 재무년월
bs_dt0: "20.12.31",
bs_dt1: "19.12.31",
bs_dt2: "18.12.31",
// 재무현황 - 총자산
bs59_0: "63,307",
bs59_1: "63,307",
bs59_2: "62,216",
// 재무현황 - 부채총계
bs91_0: "27,660",
bs91_1: "36,196",
bs91_2: "23,205",
// 재무현황 - 자본총계
bs113_0: "125,474",
bs113_1: "142,804",
bs113_2: "89,251",
// 재무현황 - 매출액
pl01_0: "36,247",
pl01_1: "34,866",
pl01_2: "39,011",
// 재무현황 - 영업이익
pl27_0: "6,425",
pl27_1: "7,140",
pl27_2: "5,389",
// 재무현황 - 당기순이익
pl71_0: "5,286",
pl71_1: "5,761",
pl71_2: "4,325",
// 재무비율 - 부채비율
TR0053: "55.3",
TR0052: "0",
TR0051: "59.5",
// 재무비율 - 차입금의존도
TR0513: "0",
TR0512: "0",
TR0511: "0",
// 재무비율 - 영업이익율
TR0523: "5.1",
TR0522: "5",
TR0521: "6",
// 재무비율 - 순이익율
TR0103: "4.2",
TR0102: "4",
TR0101: "4.8",
// 재무비율 - 매출액증가율
TR0223: "-19.1",
TR0222: "59.3",
TR0221: "-13.9",
// 재무비율 - 유동비율
TR0013: "194.4",
TR0012: "172.7",
TR0011: "230.8"
};
};
|