diff options
| author | joonhoekim <26rote@gmail.com> | 2025-08-22 02:18:10 +0000 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-08-22 02:18:10 +0000 |
| commit | bde9151154dc9731046ac3facdc4869b7612a7af (patch) | |
| tree | a9b8337114e101cce92c97a05e2b0ded12da4809 | |
| parent | 7dd2b9fc1856306652f311d19697d9880955bfab (diff) | |
(김준회) 설계 데이터 입력 - EDP 에 클라이언트가 직접 요청 보내던 문제 수정
| -rw-r--r-- | components/form-data/form-data-table.tsx | 112 | ||||
| -rw-r--r-- | components/form-data/sedp-compare-dialog.tsx | 17 | ||||
| -rw-r--r-- | lib/forms/sedp-actions.ts | 116 |
3 files changed, 135 insertions, 110 deletions
diff --git a/components/form-data/form-data-table.tsx b/components/form-data/form-data-table.tsx index c9632c8c..a2645679 100644 --- a/components/form-data/form-data-table.tsx +++ b/components/form-data/form-data-table.tsx @@ -16,30 +16,25 @@ import { Button } from "../ui/button"; import { Download, Loader, - Save, Upload, Plus, Tag, TagsIcon, - FileText, - FileSpreadsheet, FileOutput, Clipboard, Send, GitCompareIcon, RefreshCcw, Trash2, - Eye // 새로 추가된 아이콘 + Eye } from "lucide-react"; import { toast } from "sonner"; import { getPackageCodeById, getProjectById, - getProjectCodeById, getReportTempList, sendFormDataToSEDP, syncMissingTags, - updateFormDataInDB, } from "@/lib/forms/services"; import { UpdateTagSheet } from "./update-form-sheet"; import { FormDataReportTempUploadDialog } from "./form-data-report-temp-upload-dialog"; @@ -50,101 +45,18 @@ import { DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, - DropdownMenuSeparator, } from "@/components/ui/dropdown-menu"; import { AddFormTagDialog } from "./add-formTag-dialog"; import { importExcelData } from "./import-excel-form"; import { exportExcelData } from "./export-excel-form"; import { SEDPConfirmationDialog, SEDPStatusDialog } from "./sedp-components"; import { SEDPCompareDialog } from "./sedp-compare-dialog"; -import { getSEDPToken } from "@/lib/sedp/sedp-token"; import { DeleteFormDataDialog } from "./delete-form-data-dialog"; import { TemplateViewDialog } from "./spreadJS-dialog"; - -// 기존 fetchTagDataFromSEDP 함수 -async function fetchTagDataFromSEDP(projectCode: string, formCode: string): Promise<any> { - try { - // Get the token - const apiKey = await getSEDPToken(); - - // Define the API base URL - const SEDP_API_BASE_URL = process.env.SEDP_API_BASE_URL || 'http://sedpwebapi.ship.samsung.co.kr/api'; - - // Make the API call - const response = await fetch( - `${SEDP_API_BASE_URL}/Data/GetPubData`, - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'accept': '*/*', - 'ApiKey': apiKey, - 'ProjectNo': projectCode - }, - body: JSON.stringify({ - ProjectNo: projectCode, - REG_TYPE_ID: formCode, - ContainDeleted: false - }) - } - ); - - if (!response.ok) { - const errorText = await response.text(); - throw new Error(`SEDP API request failed: ${response.status} ${response.statusText} - ${errorText}`); - } - - const data = await response.json(); - return data; - } catch (error: any) { - console.error('Error calling SEDP API:', error); - throw new Error(`Failed to fetch data from SEDP API: ${error.message || 'Unknown error'}`); - } -} - -// 새로 추가된 fetchTemplateFromSEDP 함수 -async function fetchTemplateFromSEDP(projectCode: string, formCode: string): Promise<any> { - try { - // Get the token - const apiKey = await getSEDPToken(); - - // Define the API base URL - const SEDP_API_BASE_URL = process.env.SEDP_API_BASE_URL || 'http://sedpwebapi.ship.samsung.co.kr/api'; - - // Make the API call - const response = await fetch( - `${SEDP_API_BASE_URL}/Template/GetByRegisterID`, - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'accept': '*/*', - 'ApiKey': apiKey, - 'ProjectNo': projectCode - }, - body: JSON.stringify({ - WithContent: true, - ProjectNo: projectCode, - REG_TYPE_ID: formCode - }) - } - ); - - if (!response.ok) { - const errorText = await response.text(); - throw new Error(`SEDP Template API request failed: ${response.status} ${response.statusText} - ${errorText}`); - } - - const data = await response.json(); - return data; - } catch (error: any) { - console.error('Error calling SEDP Template API:', error); - throw new Error(`Failed to fetch template from SEDP API: ${error.message || 'Unknown error'}`); - } -} +import { fetchTemplateFromSEDP } from "@/lib/forms/sedp-actions"; interface GenericData { - [key: string]: any; + [key: string]: unknown; } export interface DynamicTableProps { @@ -194,13 +106,12 @@ export default function DynamicTable({ // 폴링 상태 관리를 위한 ref const pollingRef = React.useRef<NodeJS.Timeout | null>(null); - const [syncId, setSyncId] = React.useState<string | null>(null); // Separate loading states for different operations const [isSyncingTags, setIsSyncingTags] = React.useState(false); const [isImporting, setIsImporting] = React.useState(false); const [isExporting, setIsExporting] = React.useState(false); - const [isSaving, setIsSaving] = React.useState(false); + const [isSaving] = React.useState(false); const [isSendingSEDP, setIsSendingSEDP] = React.useState(false); const [isLoadingTags, setIsLoadingTags] = React.useState(false); const [isLoadingTemplate, setIsLoadingTemplate] = React.useState(false); // 새로 추가 @@ -227,7 +138,7 @@ export default function DynamicTable({ // 새로 추가된 Template 다이얼로그 상태 const [templateDialogOpen, setTemplateDialogOpen] = React.useState(false); - const [templateData, setTemplateData] = React.useState<any>(null); + const [templateData, setTemplateData] = React.useState<unknown>(null); const [tempUpDialog, setTempUpDialog] = React.useState(false); const [reportData, setReportData] = React.useState<GenericData[]>([]); @@ -415,7 +326,6 @@ export default function DynamicTable({ // 작업 ID 저장 if (data.syncId) { - setSyncId(data.syncId); toast.info('Tag import started. This may take a while...'); // 상태 확인을 위한 폴링 시작 @@ -462,7 +372,6 @@ export default function DynamicTable({ // 상태 초기화 setIsLoadingTags(false); - setSyncId(null); // 성공 메시지 표시 toast.success( @@ -477,7 +386,6 @@ export default function DynamicTable({ } setIsLoadingTags(false); - setSyncId(null); toast.error(data.error || 'Import failed'); } else if (data.status === 'processing') { // 진행 상태 업데이트 (선택적) @@ -575,7 +483,10 @@ export default function DynamicTable({ setIsSendingSEDP(true); // Validate data - const invalidData = tableData.filter((item) => !item.TAG_NO?.trim()); + const invalidData = tableData.filter((item) => { + const tagNo = item.TAG_NO; + return !tagNo || (typeof tagNo === 'string' && !tagNo.trim()); + }); if (invalidData.length > 0) { toast.error(`태그 번호가 없는 항목이 ${invalidData.length}개 있습니다.`); setSedpConfirmOpen(false); @@ -619,13 +530,13 @@ export default function DynamicTable({ // Refresh the route to get fresh data router.refresh(); - } catch (err: any) { + } catch (err: unknown) { console.error("SEDP error:", err); // Set error status setSedpStatusData({ status: 'error', - message: err.message || "An unexpected error occurred", + message: err instanceof Error ? err.message : "An unexpected error occurred", successCount: 0, errorCount: tableData.length, totalCount: tableData.length @@ -1001,7 +912,6 @@ export default function DynamicTable({ columnsJSON={columnsJSON} projectCode={projectCode} formCode={formCode} - fetchTagDataFromSEDP={fetchTagDataFromSEDP} projectType={projectType} packageCode={packageCode} /> diff --git a/components/form-data/sedp-compare-dialog.tsx b/components/form-data/sedp-compare-dialog.tsx index 9a6c8098..9cc08657 100644 --- a/components/form-data/sedp-compare-dialog.tsx +++ b/components/form-data/sedp-compare-dialog.tsx @@ -13,15 +13,15 @@ import { Switch } from "../ui/switch"; import { Card, CardContent } from "@/components/ui/card"; import { useTranslation } from "@/i18n/client" import { useParams } from "next/navigation" +import { fetchTagDataFromSEDP } from "@/lib/forms/sedp-actions"; interface SEDPCompareDialogProps { isOpen: boolean; onClose: () => void; - tableData: any[]; + tableData: unknown[]; columnsJSON: DataTableColumnJSON[]; projectCode: string; formCode: string; - fetchTagDataFromSEDP: (projectCode: string, formCode: string) => Promise<any>; projectType:string; packageCode:string; } @@ -33,15 +33,15 @@ interface ComparisonResult { attributes: { key: string; label: string; - localValue: any; - sedpValue: any; + localValue: unknown; + sedpValue: unknown; isMatching: boolean; uom?: string; }[]; } // Component for formatting display value with UOM -const DisplayValue = ({ value, uom, isSedp = false }: { value: any; uom?: string; isSedp?: boolean }) => { +const DisplayValue = ({ value, uom, isSedp = false }: { value: unknown; uom?: string; isSedp?: boolean }) => { if (value === "" || value === null || value === undefined) { return <span className="text-muted-foreground italic">(empty)</span>; } @@ -68,7 +68,6 @@ export function SEDPCompareDialog({ columnsJSON, projectCode, formCode, - fetchTagDataFromSEDP, projectType, packageCode }: SEDPCompareDialogProps) { @@ -275,13 +274,13 @@ export function SEDPCompareDialog({ }); - tagEntries.forEach((entry: any) => { + tagEntries.forEach((entry: Record<string, unknown>) => { const tagNo = entry.TAG_NO; const attributesMap = new Map(); // Convert attributes array to map for easier access if (Array.isArray(entry.ATTRIBUTES)) { - entry.ATTRIBUTES.forEach((attr: any) => { + entry.ATTRIBUTES.forEach((attr: Record<string, unknown>) => { attributesMap.set(attr.ATT_ID, attr.VALUE); }); } @@ -385,7 +384,7 @@ export function SEDPCompareDialog({ } finally { setIsLoading(false); } - }, [projectCode, formCode, tableData, columnsJSON, fetchTagDataFromSEDP, columnLabelMap, columnUomMap]); + }, [projectCode, formCode, tableData, columnsJSON, columnLabelMap, columnUomMap]); // Fetch data when dialog opens React.useEffect(() => { diff --git a/lib/forms/sedp-actions.ts b/lib/forms/sedp-actions.ts new file mode 100644 index 00000000..24ae2e66 --- /dev/null +++ b/lib/forms/sedp-actions.ts @@ -0,0 +1,116 @@ +"use server"; + +import { getSEDPToken } from "@/lib/sedp/sedp-token"; + +interface SEDPTagData { + [tableName: string]: Array<{ + TAG_NO: string; + TAG_DESC: string; + ATTRIBUTES: Array<{ + ATT_ID: string; + VALUE: string; + }>; + }>; +} + +interface SEDPTemplateData { + templateId: string; + content: string; + projectNo: string; + regTypeId: string; + [key: string]: any; +} + +/** + * SEDP에서 태그 데이터를 가져오는 서버 액션 + */ +export async function fetchTagDataFromSEDP( + projectCode: string, + formCode: string +): Promise<SEDPTagData> { + try { + // Get the token + const apiKey = await getSEDPToken(); + + // Define the API base URL + const SEDP_API_BASE_URL = process.env.SEDP_API_BASE_URL || 'http://sedpwebapi.ship.samsung.co.kr/api'; + + // Make the API call + const response = await fetch( + `${SEDP_API_BASE_URL}/Data/GetPubData`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'accept': '*/*', + 'ApiKey': apiKey, + 'ProjectNo': projectCode + }, + body: JSON.stringify({ + ProjectNo: projectCode, + REG_TYPE_ID: formCode, + ContainDeleted: false + }) + } + ); + + if (!response.ok) { + const errorText = await response.text(); + throw new Error(`SEDP API request failed: ${response.status} ${response.statusText} - ${errorText}`); + } + + const data = await response.json(); + return data as SEDPTagData; + } catch (error: unknown) { + console.error('Error calling SEDP API:', error); + const errorMessage = error instanceof Error ? error.message : 'Unknown error'; + throw new Error(`Failed to fetch data from SEDP API: ${errorMessage}`); + } +} + +/** + * SEDP에서 템플릿 데이터를 가져오는 서버 액션 + */ +export async function fetchTemplateFromSEDP( + projectCode: string, + formCode: string +): Promise<SEDPTemplateData> { + try { + // Get the token + const apiKey = await getSEDPToken(); + + // Define the API base URL + const SEDP_API_BASE_URL = process.env.SEDP_API_BASE_URL || 'http://sedpwebapi.ship.samsung.co.kr/api'; + + // Make the API call + const response = await fetch( + `${SEDP_API_BASE_URL}/Template/GetByRegisterID`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'accept': '*/*', + 'ApiKey': apiKey, + 'ProjectNo': projectCode + }, + body: JSON.stringify({ + WithContent: true, + ProjectNo: projectCode, + REG_TYPE_ID: formCode + }) + } + ); + + if (!response.ok) { + const errorText = await response.text(); + throw new Error(`SEDP Template API request failed: ${response.status} ${response.statusText} - ${errorText}`); + } + + const data = await response.json(); + return data as SEDPTemplateData; + } catch (error: unknown) { + console.error('Error calling SEDP Template API:', error); + const errorMessage = error instanceof Error ? error.message : 'Unknown error'; + throw new Error(`Failed to fetch template from SEDP API: ${errorMessage}`); + } +} |
