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
|
"use server"
import { oracleKnex } from '@/lib/oracle-db/db'
// SSLVW_PUR_INQ_REQ 테이블 데이터 타입 (실제 테이블 구조에 맞게 조정 필요)
export interface SSLVWPurInqReq {
[key: string]: string | number | Date | null | undefined
}
// 테스트 환경용 폴백 데이터
const FALLBACK_TEST_DATA: SSLVWPurInqReq[] = [
{
id: 1,
request_number: 'REQ001',
status: 'PENDING',
created_date: new Date('2025-01-01'),
description: '테스트 요청 1'
},
{
id: 2,
request_number: 'REQ002',
status: 'APPROVED',
created_date: new Date('2025-01-02'),
description: '테스트 요청 2'
}
]
/**
* SSLVW_PUR_INQ_REQ 테이블 전체 조회
* @returns 테이블 데이터 배열
*/
export async function getSSLVWPurInqReqData(): Promise<{
success: boolean
data: SSLVWPurInqReq[]
error?: string
isUsingFallback?: boolean
}> {
try {
console.log('📋 [getSSLVWPurInqReqData] SSLVW_PUR_INQ_REQ 테이블 조회 시작...')
const result = await oracleKnex.raw(`
SELECT *
FROM SSLVW_PUR_INQ_REQ
WHERE ROWNUM < 100
ORDER BY 1
`)
// Oracle raw query의 결과는 rows 배열에 들어있음
const rows = (result.rows || result) as Array<Record<string, unknown>>
console.log(`✅ [getSSLVWPurInqReqData] 조회 성공 - ${rows.length}건`)
// 데이터 타입 변환 (필요에 따라 조정)
const cleanedResult = rows.map((item) => {
const convertedItem: SSLVWPurInqReq = {}
for (const [key, value] of Object.entries(item)) {
if (value instanceof Date) {
convertedItem[key] = value
} else if (value === null) {
convertedItem[key] = null
} else {
convertedItem[key] = String(value)
}
}
return convertedItem
})
return {
success: true,
data: cleanedResult,
isUsingFallback: false
}
} catch (error) {
console.error('❌ [getSSLVWPurInqReqData] 오류:', error)
console.log('🔄 [getSSLVWPurInqReqData] 폴백 테스트 데이터 사용')
return {
success: true,
data: FALLBACK_TEST_DATA,
isUsingFallback: true
}
}
}
|