101 lines
4.9 KiB
Java
101 lines
4.9 KiB
Java
package com.erp.controller;
|
|
|
|
import com.erp.dto.ApiResponse;
|
|
import com.erp.service.NodeExternalConnectionService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* Node 플로우 전용 외부 DB 연결 컨트롤러
|
|
*
|
|
* Node.js dataflow/node-external-connections.ts 포팅.
|
|
*
|
|
* GET /api/dataflow/node-external-connections/tested — 테스트 성공 커넥션 목록
|
|
* GET /api/dataflow/node-external-connections/{id}/tables — 외부 DB 테이블 목록
|
|
* GET /api/dataflow/node-external-connections/{id}/tables/{tableName}/columns — 외부 DB 컬럼 목록
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api/dataflow/node-external-connections")
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
public class NodeExternalConnectionController {
|
|
|
|
private final NodeExternalConnectionService service;
|
|
|
|
// ─────────────────────────────────────────────────────────
|
|
// GET /tested
|
|
// Node.js: router.get("/tested", ...)
|
|
// ─────────────────────────────────────────────────────────
|
|
|
|
@GetMapping("/tested")
|
|
public ResponseEntity<ApiResponse<List<Map<String, Object>>>> getTestedConnections(
|
|
@RequestAttribute("company_code") String companyCode) {
|
|
try {
|
|
log.info("노드 플로우용 테스트 완료된 커넥션 조회 요청 - companyCode: {}", companyCode);
|
|
List<Map<String, Object>> valid = service.getTestedConnections(companyCode);
|
|
return ResponseEntity.ok(ApiResponse.success(valid,
|
|
"테스트에 성공한 " + valid.size() + "개의 커넥션을 조회했습니다."));
|
|
} catch (Exception e) {
|
|
log.error("노드 플로우용 커넥션 조회 오류", e);
|
|
return ResponseEntity.status(500)
|
|
.body(ApiResponse.error("서버 내부 오류가 발생했습니다."));
|
|
}
|
|
}
|
|
|
|
// ─────────────────────────────────────────────────────────
|
|
// GET /{id}/tables
|
|
// Node.js: router.get("/:id/tables", ...)
|
|
// ─────────────────────────────────────────────────────────
|
|
|
|
@GetMapping("/{id}/tables")
|
|
public ResponseEntity<?> getTables(
|
|
@RequestAttribute("company_code") String companyCode,
|
|
@PathVariable int id) {
|
|
try {
|
|
log.info("외부 DB 테이블 목록 조회: connectionId={}", id);
|
|
Map<String, Object> result = service.getTablesFromConnection(id);
|
|
if (Boolean.TRUE.equals(result.get("success"))) {
|
|
return ResponseEntity.ok(result);
|
|
}
|
|
return ResponseEntity.status(400).body(result);
|
|
} catch (Exception e) {
|
|
log.error("외부 DB 테이블 목록 조회 오류: id={}", id, e);
|
|
return ResponseEntity.status(500).body(Map.of(
|
|
"success", false,
|
|
"message", "서버 내부 오류가 발생했습니다.",
|
|
"error", e.getMessage()));
|
|
}
|
|
}
|
|
|
|
// ─────────────────────────────────────────────────────────
|
|
// GET /{id}/tables/{tableName}/columns
|
|
// Node.js: router.get("/:id/tables/:tableName/columns", ...)
|
|
// ─────────────────────────────────────────────────────────
|
|
|
|
@GetMapping("/{id}/tables/{tableName}/columns")
|
|
public ResponseEntity<?> getTableColumns(
|
|
@RequestAttribute("company_code") String companyCode,
|
|
@PathVariable int id,
|
|
@PathVariable String tableName) {
|
|
try {
|
|
log.info("외부 DB 컬럼 목록 조회: connectionId={}, table={}", id, tableName);
|
|
Map<String, Object> result = service.getColumnsFromConnection(id, tableName);
|
|
if (Boolean.TRUE.equals(result.get("success"))) {
|
|
return ResponseEntity.ok(result);
|
|
}
|
|
return ResponseEntity.status(400).body(result);
|
|
} catch (Exception e) {
|
|
log.error("외부 DB 컬럼 목록 조회 오류: id={}, table={}", id, tableName, e);
|
|
return ResponseEntity.status(500).body(Map.of(
|
|
"success", false,
|
|
"message", "서버 내부 오류가 발생했습니다.",
|
|
"error", e.getMessage()));
|
|
}
|
|
}
|
|
}
|