diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/[lng]/evcp/(evcp)/basic-contract-template/[id]/not-found.tsx | 25 | ||||
| -rw-r--r-- | app/[lng]/evcp/(evcp)/basic-contract-template/[id]/page.tsx | 150 | ||||
| -rw-r--r-- | app/[lng]/evcp/(evcp)/tech-vendor-candidates/page.tsx | 81 | ||||
| -rw-r--r-- | app/[lng]/evcp/(evcp)/tech-vendors/[id]/info/layout.tsx | 2 | ||||
| -rw-r--r-- | app/[lng]/evcp/(evcp)/tech-vendors/[id]/info/page.tsx | 2 | ||||
| -rw-r--r-- | app/[lng]/sales/(sales)/tech-vendor-candidates/page.tsx | 78 | ||||
| -rw-r--r-- | app/api/files/[...path]/route.ts | 2 | ||||
| -rw-r--r-- | app/api/sync/import/status/route.ts | 208 |
8 files changed, 195 insertions, 353 deletions
diff --git a/app/[lng]/evcp/(evcp)/basic-contract-template/[id]/not-found.tsx b/app/[lng]/evcp/(evcp)/basic-contract-template/[id]/not-found.tsx new file mode 100644 index 00000000..6b09f772 --- /dev/null +++ b/app/[lng]/evcp/(evcp)/basic-contract-template/[id]/not-found.tsx @@ -0,0 +1,25 @@ +// app/evcp/basic-contract-template/[id]/not-found.tsx + +import { Button } from "@/components/ui/button"; +import { ArrowLeft } from "lucide-react"; +import Link from "next/link"; + +export default function NotFound() { + return ( + <div className="container mx-auto py-12"> + <div className="text-center"> + <h1 className="text-2xl font-bold mb-4">템플릿을 찾을 수 없습니다</h1> + <p className="text-muted-foreground mb-6"> + 요청하신 기본계약서 템플릿이 존재하지 않거나 삭제되었습니다. + </p> + <Link href="/evcp/basic-contract-template"> + <Button> + <ArrowLeft className="mr-2 h-4 w-4" /> + 목록으로 돌아가기 + </Button> + </Link> + </div> + </div> + ); + } +
\ No newline at end of file diff --git a/app/[lng]/evcp/(evcp)/basic-contract-template/[id]/page.tsx b/app/[lng]/evcp/(evcp)/basic-contract-template/[id]/page.tsx new file mode 100644 index 00000000..bcf3e1f4 --- /dev/null +++ b/app/[lng]/evcp/(evcp)/basic-contract-template/[id]/page.tsx @@ -0,0 +1,150 @@ +// app/evcp/basic-contract-template/[id]/page.tsx +import * as React from "react" +import { notFound } from "next/navigation" +import { ArrowLeft, FileText, Download, Edit } from "lucide-react" +import Link from "next/link" +import { Metadata } from "next" + +import { Button } from "@/components/ui/button" +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" +import { Badge } from "@/components/ui/badge" +import { formatDateTime } from "@/lib/utils" +import { getBasicContractTemplateByIdService, refreshTemplatePage } from "@/lib/basic-contract/service" +import { TemplateEditorWrapper } from "@/lib/basic-contract/template/template-editor-wrapper" + +interface BasicContractTemplateDetailPageProps { + params: { + id: string + } +} + +// 메타데이터 생성 +export async function generateMetadata({ + params +}: BasicContractTemplateDetailPageProps): Promise<Metadata> { + const template = await getBasicContractTemplateByIdService(params.id); + + if (!template) { + return { + title: "템플릿을 찾을 수 없음", + description: "요청한 기본계약서 템플릿을 찾을 수 없습니다." + }; + } + + return { + title: `${template.templateName} (v${template.revision}) - 기본계약서 템플릿`, + description: `${template.templateName} 템플릿의 상세 정보 및 편집 페이지입니다.` + }; +} + +export default async function BasicContractTemplateDetailPage({ + params +}: BasicContractTemplateDetailPageProps) { + const template = await getBasicContractTemplateByIdService(params.id); + + if (!template) { + notFound(); + } + + // 페이지 새로고침 서버 액션 + const handleRefresh = async () => { + "use server" + await refreshTemplatePage(params.id); + }; + + return ( + <div className="container mx-auto py-6 space-y-6"> + {/* Header */} + <div className="flex items-center justify-between"> + <div className="flex items-center space-x-4"> + <Link href="/evcp/basic-contract-template"> + <Button variant="outline" size="sm"> + <ArrowLeft className="mr-2 h-4 w-4" /> + 목록으로 + </Button> + </Link> + <div> + <h1 className="text-2xl font-bold flex items-center"> + <FileText className="mr-2 h-6 w-6 text-blue-500" /> + {template.templateName} + <Badge variant="outline" className="ml-2"> + v{template.revision} + </Badge> + </h1> + <p className="text-muted-foreground"> + 기본계약서 템플릿 상세 정보 및 편집 + </p> + </div> + </div> + + <div className="flex items-center space-x-2"> + {/* <DownloadButton + filePath={template.filePath} + fileName={template.fileName} + /> */} + </div> + </div> + + <div className="space-y-4"> + {/* 상단 - 기본 정보만 (최대한 압축) */} + <Card> + <CardHeader className="pb-2"> + <CardTitle className="text-sm">기본 정보</CardTitle> + </CardHeader> + <CardContent className="py-2"> + <div className="flex items-center space-x-6"> + <div className="flex items-center space-x-2"> + <label className="text-xs font-medium text-muted-foreground">상태:</label> + <Badge variant={template.status === "ACTIVE" ? "default" : "secondary"} className="text-xs h-5"> + {template.status === "ACTIVE" ? "활성" : "폐기"} + </Badge> + </div> + + <div className="flex items-center space-x-2"> + <label className="text-xs font-medium text-muted-foreground">버전:</label> + <span className="text-xs font-medium">v{template.revision}</span> + </div> + + <div className="flex items-center space-x-2"> + <label className="text-xs font-medium text-muted-foreground">법무검토:</label> + <Badge variant={template.legalReviewRequired ? "destructive" : "secondary"} className="text-xs h-5"> + {template.legalReviewRequired ? "필요" : "불필요"} + </Badge> + </div> + + <div className="flex items-center space-x-2"> + <label className="text-xs font-medium text-muted-foreground">파일:</label> + <span className="text-xs">{template.fileName}</span> + </div> + </div> + </CardContent> + </Card> + + {/* 하단 - 파일 뷰어 (전체 너비, 높이 증가) */} + <Card className="h-[950px]"> + <CardHeader className="pb-2"> + <div className="flex items-center justify-between"> + <div> + <CardTitle className="text-lg flex items-center"> + <Edit className="mr-2 h-5 w-5 text-blue-500" /> + 템플릿 편집기 + </CardTitle> + <CardDescription className="text-sm"> + Word 문서를 편집하고 {'{{변수}}'} 를 설정할 수 있습니다. + </CardDescription> + </div> + </div> + </CardHeader> + <CardContent className="h-[calc(100%-80px)] p-0"> + <TemplateEditorWrapper + templateId={template.id} + filePath={template.filePath} + fileName={template.fileName} + refreshAction={handleRefresh} + /> + </CardContent> + </Card> + </div> + </div> + ); +}
\ No newline at end of file diff --git a/app/[lng]/evcp/(evcp)/tech-vendor-candidates/page.tsx b/app/[lng]/evcp/(evcp)/tech-vendor-candidates/page.tsx deleted file mode 100644 index 2e45ebd8..00000000 --- a/app/[lng]/evcp/(evcp)/tech-vendor-candidates/page.tsx +++ /dev/null @@ -1,81 +0,0 @@ -import * as React from "react" -import { type SearchParams } from "@/types/table" - -import { getValidFilters } from "@/lib/data-table" -import { Skeleton } from "@/components/ui/skeleton" -import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton" -import { Shell } from "@/components/shell" - -import { getVendorCandidateCounts, getVendorCandidates } from "@/lib/tech-vendor-candidates/service" -import { searchParamsTechCandidateCache } from "@/lib/tech-vendor-candidates/validations" -import { VendorCandidateTable as TechVendorCandidateTable } from "@/lib/tech-vendor-candidates/table/candidates-table" -import { DateRangePicker } from "@/components/date-range-picker" -import { InformationButton } from "@/components/information/information-button" -interface IndexPageProps { - searchParams: Promise<SearchParams> -} - -export default async function IndexPage(props: IndexPageProps) { - const searchParams = await props.searchParams - const search = searchParamsTechCandidateCache.parse(searchParams) - - const validFilters = getValidFilters(search.filters) - - const promises = Promise.all([ - getVendorCandidates({ - ...search, - filters: validFilters, - }), - getVendorCandidateCounts() - ]) - - return ( - <Shell className="gap-2"> - - <div className="flex items-center justify-between space-y-2"> - <div className="flex items-center justify-between space-y-2"> - <div> - <div className="flex items-center gap-2"> - <h2 className="text-2xl font-bold tracking-tight"> - 협력업체 후보 관리 - </h2> - <InformationButton pagePath="evcp/tech-vendor-candidates" /> - </div> - {/* <p className="text-muted-foreground"> - 수집한 협력업체 후보를 등록하고 초대 메일을 송부할 수 있습니다. - </p> */} - </div> - </div> - </div> - - {/* 수집일 라벨과 DateRangePicker를 함께 배치 */} - <div className="flex items-center justify-start gap-2"> - {/* <span className="text-sm font-medium">수집일 기간 설정: </span> */} - <React.Suspense fallback={<Skeleton className="h-7 w-52" />}> - <DateRangePicker - triggerSize="sm" - triggerClassName="w-56 sm:w-60" - align="end" - shallow={false} - showClearButton={true} - placeholder="수집일 날짜 범위를 고르세요" - /> - </React.Suspense> - </div> - - <React.Suspense - fallback={ - <DataTableSkeleton - columnCount={6} - searchableColumnCount={1} - filterableColumnCount={2} - cellWidths={["10rem", "40rem", "12rem", "12rem", "8rem", "8rem"]} - shrinkZero - /> - } - > - <TechVendorCandidateTable promises={promises}/> - </React.Suspense> - </Shell> - ) -}
\ No newline at end of file diff --git a/app/[lng]/evcp/(evcp)/tech-vendors/[id]/info/layout.tsx b/app/[lng]/evcp/(evcp)/tech-vendors/[id]/info/layout.tsx index 291cd630..42fba934 100644 --- a/app/[lng]/evcp/(evcp)/tech-vendors/[id]/info/layout.tsx +++ b/app/[lng]/evcp/(evcp)/tech-vendors/[id]/info/layout.tsx @@ -31,7 +31,7 @@ export default async function SettingsLayout({ // 3) 사이드바 메뉴
const sidebarNavItems = [
{
- title: "연락처",
+ title: "담당자",
href: `/${lng}/evcp/tech-vendors/${id}/info`,
},
{
diff --git a/app/[lng]/evcp/(evcp)/tech-vendors/[id]/info/page.tsx b/app/[lng]/evcp/(evcp)/tech-vendors/[id]/info/page.tsx index 9969a801..f8847981 100644 --- a/app/[lng]/evcp/(evcp)/tech-vendors/[id]/info/page.tsx +++ b/app/[lng]/evcp/(evcp)/tech-vendors/[id]/info/page.tsx @@ -40,7 +40,7 @@ export default async function SettingsAccountPage(props: IndexPageProps) { <div className="space-y-6">
<div>
<h3 className="text-lg font-medium">
- Contacts
+ 담당자
</h3>
<p className="text-sm text-muted-foreground">
업무별 담당자 정보를 확인하세요.
diff --git a/app/[lng]/sales/(sales)/tech-vendor-candidates/page.tsx b/app/[lng]/sales/(sales)/tech-vendor-candidates/page.tsx deleted file mode 100644 index 5a9f150f..00000000 --- a/app/[lng]/sales/(sales)/tech-vendor-candidates/page.tsx +++ /dev/null @@ -1,78 +0,0 @@ -import * as React from "react" -import { type SearchParams } from "@/types/table" - -import { getValidFilters } from "@/lib/data-table" -import { Skeleton } from "@/components/ui/skeleton" -import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton" -import { Shell } from "@/components/shell" - -import { getVendorCandidateCounts, getVendorCandidates } from "@/lib/tech-vendor-candidates/service" -import { searchParamsTechCandidateCache } from "@/lib/tech-vendor-candidates/validations" -import { VendorCandidateTable as TechVendorCandidateTable } from "@/lib/tech-vendor-candidates/table/candidates-table" -import { DateRangePicker } from "@/components/date-range-picker" - -interface IndexPageProps { - searchParams: Promise<SearchParams> -} - -export default async function IndexPage(props: IndexPageProps) { - const searchParams = await props.searchParams - const search = searchParamsTechCandidateCache.parse(searchParams) - - const validFilters = getValidFilters(search.filters) - - const promises = Promise.all([ - getVendorCandidates({ - ...search, - filters: validFilters, - }), - getVendorCandidateCounts() - ]) - - return ( - <Shell className="gap-2"> - - <div className="flex items-center justify-between space-y-2"> - <div className="flex items-center justify-between space-y-2"> - <div> - <h2 className="text-2xl font-bold tracking-tight"> - 발굴업체 등록 관리 - </h2> - {/* <p className="text-muted-foreground"> - 수집한 협력업체 후보를 등록하고 초대 메일을 송부할 수 있습니다. - </p> */} - </div> - </div> - </div> - - {/* 수집일 라벨과 DateRangePicker를 함께 배치 */} - <div className="flex items-center justify-start gap-2"> - {/* <span className="text-sm font-medium">수집일 기간 설정: </span> */} - <React.Suspense fallback={<Skeleton className="h-7 w-52" />}> - <DateRangePicker - triggerSize="sm" - triggerClassName="w-56 sm:w-60" - align="end" - shallow={false} - showClearButton={true} - placeholder="수집일 날짜 범위를 고르세요" - /> - </React.Suspense> - </div> - - <React.Suspense - fallback={ - <DataTableSkeleton - columnCount={6} - searchableColumnCount={1} - filterableColumnCount={2} - cellWidths={["10rem", "40rem", "12rem", "12rem", "8rem", "8rem"]} - shrinkZero - /> - } - > - <TechVendorCandidateTable promises={promises}/> - </React.Suspense> - </Shell> - ) -}
\ No newline at end of file diff --git a/app/api/files/[...path]/route.ts b/app/api/files/[...path]/route.ts index e03187e3..a3bd67af 100644 --- a/app/api/files/[...path]/route.ts +++ b/app/api/files/[...path]/route.ts @@ -35,6 +35,8 @@ const isAllowedPath = (requestedPath: string): boolean => { 'basicContract/signed', 'vendorFormReportSample', 'vendorFormData', + 'uploads', + 'tech-sales' ]; return allowedPaths.some(allowed => diff --git a/app/api/sync/import/status/route.ts b/app/api/sync/import/status/route.ts index 8b6144d6..c5b4b0bd 100644 --- a/app/api/sync/import/status/route.ts +++ b/app/api/sync/import/status/route.ts @@ -1,19 +1,8 @@ -// app/api/sync/status/route.ts +// app/api/sync/import/status/route.ts import { NextRequest, NextResponse } from "next/server" +import { importService } from "@/lib/vendor-document-list/import-service" import { getServerSession } from "next-auth" import { authOptions } from "@/app/api/auth/[...nextauth]/route" -import db from "@/db/db" -import { documents, revisions, documentAttachments, contracts, projects, vendors } from "@/db/schema" -import { eq, and, sql, desc } from "drizzle-orm" - -interface SyncStatus { - syncEnabled: boolean - pendingChanges: number - syncedChanges: number - failedChanges: number - lastSyncAt?: string - error?: string -} export async function GET(request: NextRequest) { try { @@ -24,7 +13,7 @@ export async function GET(request: NextRequest) { const { searchParams } = new URL(request.url) const contractId = searchParams.get('contractId') - const targetSystem = searchParams.get('targetSystem') || 'SHI' + const sourceSystem = searchParams.get('sourceSystem') || 'DOLCE' if (!contractId) { return NextResponse.json( @@ -33,185 +22,20 @@ export async function GET(request: NextRequest) { ) } - // 🔥 안전하게 동기화 상태 조회 - const syncStatus = await getSyncStatusSafely(Number(contractId), targetSystem) - - return NextResponse.json(syncStatus) - - } catch (error) { - console.error('Unexpected error in sync status API:', error) - - // 🔥 에러 시에도 200으로 응답하고 error 필드 포함 - return NextResponse.json({ - syncEnabled: false, - pendingChanges: 0, - syncedChanges: 0, - failedChanges: 0, - lastSyncAt: undefined, - error: '시스템 오류가 발생했습니다. 잠시 후 다시 시도해주세요.' - }, { status: 200 }) - } -} - -async function getSyncStatusSafely(contractId: number, targetSystem: string): Promise<SyncStatus> { - try { - // 1. 계약 정보 확인 - const contractInfo = await db - .select({ - projectCode: projects.code, - vendorCode: vendors.vendorCode, - contractStatus: contracts.status - }) - .from(contracts) - .innerJoin(projects, eq(contracts.projectId, projects.id)) - .innerJoin(vendors, eq(contracts.vendorId, vendors.id)) - .where(eq(contracts.id, contractId)) - .limit(1) - - // 계약 정보가 없는 경우 - if (!contractInfo || contractInfo.length === 0) { - return { - syncEnabled: false, - pendingChanges: 0, - syncedChanges: 0, - failedChanges: 0, - error: `계약 ${contractId}를 찾을 수 없습니다.` - } - } - - const contract = contractInfo[0] - - // 프로젝트 코드나 벤더 코드가 없는 경우 - if (!contract.projectCode || !contract.vendorCode) { - return { - syncEnabled: false, - pendingChanges: 0, - syncedChanges: 0, - failedChanges: 0, - error: `계약 ${contractId}에 프로젝트 코드 또는 벤더 코드가 설정되지 않았습니다.` - } - } - - // 2. 마지막 동기화 시간 조회 - const [lastSync] = await db - .select({ - lastSyncAt: sql<string>`MAX(${documents.externalSyncedAt})` - }) - .from(documents) - .where(and( - eq(documents.contractId, contractId), - eq(documents.externalSystemType, targetSystem) - )) - - // 3. 문서별 변경사항 분석 - const documentStats = await db - .select({ - id: documents.id, - docNumber: documents.docNumber, - updatedAt: documents.updatedAt, - externalSyncedAt: documents.externalSyncedAt, - syncStatus: documents.syncStatus - }) - .from(documents) - .where(eq(documents.contractId, contractId)) - - let pendingChanges = 0 - let syncedChanges = 0 - let failedChanges = 0 - - // 각 문서의 동기화 상태 분석 - for (const doc of documentStats) { - // 문서 자체가 변경되었는지 확인 - const docNeedsSync = !doc.externalSyncedAt || - (doc.updatedAt && doc.externalSyncedAt && doc.updatedAt > doc.externalSyncedAt) - - if (docNeedsSync) { - if (doc.syncStatus === 'FAILED') { - failedChanges++ - } else if (doc.syncStatus === 'SYNCED') { - syncedChanges++ - } else { - pendingChanges++ - } - } - - // 해당 문서의 리비전 변경사항 확인 - const revisionStats = await db - .select({ - updatedAt: revisions.updatedAt, - externalSyncedAt: revisions.externalSyncedAt, - syncStatus: revisions.syncStatus - }) - .from(revisions) - .innerJoin(documents, eq(revisions.documentId, documents.id)) - .where(eq(documents.id, doc.id)) - - for (const revision of revisionStats) { - const revisionNeedsSync = !revision.externalSyncedAt || - (revision.updatedAt && revision.externalSyncedAt && revision.updatedAt > revision.externalSyncedAt) - - if (revisionNeedsSync) { - if (revision.syncStatus === 'FAILED') { - failedChanges++ - } else if (revision.syncStatus === 'SYNCED') { - syncedChanges++ - } else { - pendingChanges++ - } - } - } - - // 첨부파일 변경사항 확인 - const attachmentStats = await db - .select({ - updatedAt: documentAttachments.updatedAt, - externalSyncedAt: documentAttachments.externalSyncedAt, - syncStatus: documentAttachments.syncStatus - }) - .from(documentAttachments) - .innerJoin(revisions, eq(documentAttachments.revisionId, revisions.id)) - .innerJoin(documents, eq(revisions.documentId, documents.id)) - .where(eq(documents.id, doc.id)) - - for (const attachment of attachmentStats) { - const attachmentNeedsSync = !attachment.externalSyncedAt || - (attachment.updatedAt && attachment.externalSyncedAt && attachment.updatedAt > attachment.externalSyncedAt) - - if (attachmentNeedsSync) { - if (attachment.syncStatus === 'FAILED') { - failedChanges++ - } else if (attachment.syncStatus === 'SYNCED') { - syncedChanges++ - } else { - pendingChanges++ - } - } - } - } - - // 4. 동기화 활성화 여부 확인 - const syncEnabled = contract.contractStatus === 'ACTIVE' && - Boolean(contract.projectCode) && - Boolean(contract.vendorCode) && - process.env[`SYNC_${targetSystem.toUpperCase()}_ENABLED`] === 'true' - - return { - syncEnabled, - pendingChanges, - syncedChanges, - failedChanges, - lastSyncAt: lastSync?.lastSyncAt ? new Date(lastSync.lastSyncAt).toISOString() : undefined - } + const status = await importService.getImportStatus( + Number(contractId), + sourceSystem + ) + return NextResponse.json(status) } catch (error) { - console.error(`Failed to get sync status for contract ${contractId}:`, error) - - return { - syncEnabled: false, - pendingChanges: 0, - syncedChanges: 0, - failedChanges: 0, - error: error instanceof Error ? error.message : '동기화 상태를 확인할 수 없습니다.' - } + console.error('Failed to get import status:', error) + return NextResponse.json( + { + error: 'Failed to get import status', + message: error instanceof Error ? error.message : 'Unknown error' + }, + { status: 500 } + ) } }
\ No newline at end of file |
