260623_02_ENH: 엑셀 다운로드를 포함한 1차 개발 완료

This commit is contained in:
2026-06-23 11:38:46 +09:00
parent 08ea4d5420
commit d3592ad81b
9 changed files with 141 additions and 9 deletions

View File

@@ -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 <LoadingOverlay force={true} />
return (
@@ -402,17 +417,23 @@ const PerformancePage = () => {
</PagePanel>
<PagePanel>
{canEdit && (
{!isWrittenReviewer && (
<div className="mb-3 flex justify-end gap-2">
<Button type="button" onClick={() => showDialog("performanceExcelRegisterDialog")}>
<Upload className="h-4 w-4" />
사업 등록
</Button>
<Button type="button" variant="outline" onClick={() => showDialog("assignWrittenExcelDialog")}>
서면 평가 배정
</Button>
{canEdit && (
<>
<Button type="button" onClick={() => showDialog("performanceExcelRegisterDialog")}>
<Upload className="h-4 w-4" />
사업 등록
</Button>
<Button type="button" variant="outline" onClick={() => showDialog("assignWrittenExcelDialog")}>
서면 평가 배정
</Button>
</>
)}
<ExcelDownloadButton requestExcelExport={downloadPerformance} />
</div>
)}
<DataTable
columns={columns}
data={filteredData}

View File

@@ -16,6 +16,7 @@ import {useAssignUserCountsQuery} from "@/query/assign";
import {
useDeleteUserMutation,
useDownloadUserExcelTemplateMutation,
useExportUserMutation,
useUpdateUserMutation,
useUploadUsersExcelMutation,
useUsersQuery,
@@ -27,6 +28,7 @@ import {useDialog} from "@/hooks/useDialog";
import {useMounted} from "@/hooks/useMounted";
import {LoadingOverlay} from "@/components/common/LoadingOverlay";
import {downloadExcelBuffer} from "@/lib/gwcf/file";
import ExcelDownloadButton from "@/components/common/ExcelDownloadButton";
type UserTab = "monitoring" | "written";
type UserFilters = {area: string[]; gender: string[]; genre: string[]; keyword: string};
@@ -64,6 +66,7 @@ const UserPage = () => {
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 = () => {
<Upload className="h-4 w-4" />
계정 등록
</Button>
<ExcelDownloadButton requestExcelExport={downloadUsers} />
</div>
<DataTable
columns={columns}

View File

@@ -72,6 +72,28 @@ export const POST = async (
return new NextResponse(result, { status: 200 });
}
if (action === "excel-download" && slug.length === 1) {
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<ArrayBuffer>(
"/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);

View File

@@ -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<ArrayBuffer>(
`/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);

View File

@@ -0,0 +1,29 @@
"use client";
import Image from "next/image";
export type ExcelDownloadButtonProps = {
requestExcelExport: () => void;
}
const ExcelDownloadButton = ({
requestExcelExport
}: ExcelDownloadButtonProps) => {
return (
<div className={"mr-3 mt-1.5 cursor-pointer"}>
<Image
src="/icon-excel.png"
alt="excel export"
width={27}
height={27}
className="object-contain"
onClick={requestExcelExport}
priority
/>
</div>
);
};
export default ExcelDownloadButton;

View File

@@ -95,7 +95,7 @@ const getMonitoringTimeline = (visits: PerformanceMonitoringVisit[]): Monitoring
export const getMonitoringSlots = (performance: Partial<PerformanceFull>): [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 ?? {};

View File

@@ -88,6 +88,17 @@ export function useDownloadPerformanceExcelTemplateMutation() {
});
}
export function useExportPerformanceMutation() {
return useMutation({
mutationFn: ({performanceIds}: {performanceIds: number[]}) =>
nextApi.post<ArrayBuffer>(
"/performance/excel-download",
performanceIds.map(String),
{ expectBinary: true }
),
});
}
export function useDownloadAssignExcelTemplateMutation() {
return useMutation({
mutationFn: () =>

View File

@@ -38,6 +38,17 @@ export function useUpdateUserMutation() {
});
}
export function useExportUserMutation() {
return useMutation({
mutationFn: ({userRole, userIds}: {userRole: number; userIds: string[]}) =>
nextApi.post<ArrayBuffer>(
`/user/excel-download/${userRole}`,
userIds,
{ expectBinary: true }
),
});
}
export function useDeleteUserMutation() {
const qc = useQueryClient();