diff --git a/public/icon-excel.png b/public/icon-excel.png new file mode 100644 index 0000000..36a0e07 Binary files /dev/null and b/public/icon-excel.png differ diff --git a/src/app/(pages)/(main)/performance/page.tsx b/src/app/(pages)/(main)/performance/page.tsx index ec7b62f..b37b7b0 100644 --- a/src/app/(pages)/(main)/performance/page.tsx +++ b/src/app/(pages)/(main)/performance/page.tsx @@ -16,6 +16,7 @@ import {useCodesQuery} from "@/query/code"; import { useDownloadAssignExcelTemplateMutation, useDownloadPerformanceExcelTemplateMutation, + useExportPerformanceMutation, usePerformanceDetailQuery, usePerformanceListQuery, useUpdatePerformanceMutation, @@ -50,6 +51,7 @@ import { getReviewPdfDownloadName, openWrittenReviewWindow, } from "@/lib/gwcf/file"; +import ExcelDownloadButton from "@/components/common/ExcelDownloadButton"; type PerformanceFilters = { businessType: string[]; @@ -88,6 +90,7 @@ const PerformancePage = () => { const writtenAssignUploadMutation = useUploadWrittenAssignExcelMutation(); const performanceTemplateMutation = useDownloadPerformanceExcelTemplateMutation(); const writtenAssignTemplateMutation = useDownloadAssignExcelTemplateMutation(); + const exportMutation = useExportPerformanceMutation(); const reviewPdfMutation = useDownloadReviewPdfMutation(); const reviewOriginalMutation = useDownloadReviewOriginalMutation(); @@ -372,6 +375,18 @@ const PerformancePage = () => { downloadExcelBuffer(buffer, "서면 평가 배정 template.xlsx"); }; + const downloadPerformance = async () => { + const performanceIds = filteredData.map((performance) => performance.id); + + if (performanceIds.length === 0) { + alert("다운로드할 사업 정보가 없습니다."); + return; + } + + const buffer = await exportMutation.mutateAsync({performanceIds}); + downloadExcelBuffer(buffer, "사업 정보.xlsx"); + }; + if(!mounted) return return ( @@ -402,17 +417,23 @@ const PerformancePage = () => { - {canEdit && ( + {!isWrittenReviewer && (
- - + {canEdit && ( + <> + + + + )} +
)} + { const deleteMutation = useDeleteUserMutation(); const uploadMutation = useUploadUsersExcelMutation(userRole); const templateMutation = useDownloadUserExcelTemplateMutation(userRole); + const exportMutation = useExportUserMutation(); const assignCountMap = useMemo(() => new Map(assignCounts.map((item) => [item.assignUser, item.assignCount])), [assignCounts]); @@ -131,6 +134,18 @@ const UserPage = () => { downloadExcelBuffer(buffer, tab === "monitoring" ? "모니터링 요원 template.xlsx" : "서면 평가위원 template.xlsx"); }; + const downloadUsers = async () => { + const userIds = filteredData.map((user) => user.userId); + + if (userIds.length === 0) { + alert("다운로드할 사용자가 없습니다."); + return; + } + + const buffer = await exportMutation.mutateAsync({userRole, userIds}); + downloadExcelBuffer(buffer, tab === "monitoring" ? "모니터링 요원.xlsx" : "서면 평가위원.xlsx"); + }; + const renderEditableCell = (user: UserFull, key: string, fallbackKeys: string[], type: "text" | "select" = "text", options: Code[] = []) => { const draft = draftRef.current; const isEditing = editingId === user.userId && draft; @@ -255,6 +270,7 @@ const UserPage = () => { 계정 등록 + null); + + if (!Array.isArray(body)) { + return NextResponse.json({ message: "Request body must be an array." }, { status: 400 }); + } + + const result = await backApi.post( + "/performance/excel/download", + body, + { expectBinary: true } + ); + + return new NextResponse(result, { + status: 200, + headers: { + "Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "Content-Disposition": `attachment; filename="performance.xlsx"`, + }, + }); + } + return NextResponse.json({ message: "Not found" }, { status: 404 }); } catch (error: unknown) { return errorToResponse(error); diff --git a/src/app/api/user/[[...slug]]/route.ts b/src/app/api/user/[[...slug]]/route.ts index 4907652..0a10d08 100644 --- a/src/app/api/user/[[...slug]]/route.ts +++ b/src/app/api/user/[[...slug]]/route.ts @@ -73,6 +73,28 @@ export const POST = async ( }); } + if (action === "excel-download" && slug.length === 2) { + const body = await req.json().catch(() => null); + + if (!Array.isArray(body)) { + return NextResponse.json({ message: "Request body must be an array." }, { status: 400 }); + } + + const result = await backApi.post( + `/user/excel/download/${encodeURIComponent(slug[1])}`, + body, + { expectBinary: true } + ); + + return new NextResponse(result, { + status: 200, + headers: { + "Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "Content-Disposition": `attachment; filename="user_${slug[1]}.xlsx"`, + }, + }); + } + return NextResponse.json({ message: "Not found" }, { status: 404 }); } catch (error: unknown) { return errorToResponse(error); diff --git a/src/components/common/ExcelDownloadButton.tsx b/src/components/common/ExcelDownloadButton.tsx new file mode 100644 index 0000000..624b5b7 --- /dev/null +++ b/src/components/common/ExcelDownloadButton.tsx @@ -0,0 +1,29 @@ +"use client"; + +import Image from "next/image"; + +export type ExcelDownloadButtonProps = { + requestExcelExport: () => void; +} + +const ExcelDownloadButton = ({ + requestExcelExport +}: ExcelDownloadButtonProps) => { + + return ( +
+ excel export +
+ + ); +}; + +export default ExcelDownloadButton; \ No newline at end of file diff --git a/src/lib/gwcf/performance-status.ts b/src/lib/gwcf/performance-status.ts index 834308a..6fb7807 100644 --- a/src/lib/gwcf/performance-status.ts +++ b/src/lib/gwcf/performance-status.ts @@ -95,7 +95,7 @@ const getMonitoringTimeline = (visits: PerformanceMonitoringVisit[]): Monitoring export const getMonitoringSlots = (performance: Partial): [MonitoringSlot, MonitoringSlot] => { const confirmedAssigns = (performance.performanceAssignList ?? []) .filter((assign) => assign.assignType === MONITORING_ASSIGN_TYPE && assign.assignConfirm) - .sort((a, b) => a.id - b.id); + .sort((a, b) => a.assignOrder - b.assignOrder || a.id - b.id); const visits = performance.performanceMonitoringVisitMap ?? {}; diff --git a/src/query/performance.ts b/src/query/performance.ts index 1204626..c706580 100644 --- a/src/query/performance.ts +++ b/src/query/performance.ts @@ -88,6 +88,17 @@ export function useDownloadPerformanceExcelTemplateMutation() { }); } +export function useExportPerformanceMutation() { + return useMutation({ + mutationFn: ({performanceIds}: {performanceIds: number[]}) => + nextApi.post( + "/performance/excel-download", + performanceIds.map(String), + { expectBinary: true } + ), + }); +} + export function useDownloadAssignExcelTemplateMutation() { return useMutation({ mutationFn: () => diff --git a/src/query/user.ts b/src/query/user.ts index f76eb94..c8785df 100644 --- a/src/query/user.ts +++ b/src/query/user.ts @@ -38,6 +38,17 @@ export function useUpdateUserMutation() { }); } +export function useExportUserMutation() { + return useMutation({ + mutationFn: ({userRole, userIds}: {userRole: number; userIds: string[]}) => + nextApi.post( + `/user/excel-download/${userRole}`, + userIds, + { expectBinary: true } + ), + }); +} + export function useDeleteUserMutation() { const qc = useQueryClient();