260623_02_ENH: 엑셀 다운로드를 포함한 1차 개발 완료
This commit is contained in:
BIN
public/icon-excel.png
Normal file
BIN
public/icon-excel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
@@ -16,6 +16,7 @@ import {useCodesQuery} from "@/query/code";
|
|||||||
import {
|
import {
|
||||||
useDownloadAssignExcelTemplateMutation,
|
useDownloadAssignExcelTemplateMutation,
|
||||||
useDownloadPerformanceExcelTemplateMutation,
|
useDownloadPerformanceExcelTemplateMutation,
|
||||||
|
useExportPerformanceMutation,
|
||||||
usePerformanceDetailQuery,
|
usePerformanceDetailQuery,
|
||||||
usePerformanceListQuery,
|
usePerformanceListQuery,
|
||||||
useUpdatePerformanceMutation,
|
useUpdatePerformanceMutation,
|
||||||
@@ -50,6 +51,7 @@ import {
|
|||||||
getReviewPdfDownloadName,
|
getReviewPdfDownloadName,
|
||||||
openWrittenReviewWindow,
|
openWrittenReviewWindow,
|
||||||
} from "@/lib/gwcf/file";
|
} from "@/lib/gwcf/file";
|
||||||
|
import ExcelDownloadButton from "@/components/common/ExcelDownloadButton";
|
||||||
|
|
||||||
type PerformanceFilters = {
|
type PerformanceFilters = {
|
||||||
businessType: string[];
|
businessType: string[];
|
||||||
@@ -88,6 +90,7 @@ const PerformancePage = () => {
|
|||||||
const writtenAssignUploadMutation = useUploadWrittenAssignExcelMutation();
|
const writtenAssignUploadMutation = useUploadWrittenAssignExcelMutation();
|
||||||
const performanceTemplateMutation = useDownloadPerformanceExcelTemplateMutation();
|
const performanceTemplateMutation = useDownloadPerformanceExcelTemplateMutation();
|
||||||
const writtenAssignTemplateMutation = useDownloadAssignExcelTemplateMutation();
|
const writtenAssignTemplateMutation = useDownloadAssignExcelTemplateMutation();
|
||||||
|
const exportMutation = useExportPerformanceMutation();
|
||||||
const reviewPdfMutation = useDownloadReviewPdfMutation();
|
const reviewPdfMutation = useDownloadReviewPdfMutation();
|
||||||
const reviewOriginalMutation = useDownloadReviewOriginalMutation();
|
const reviewOriginalMutation = useDownloadReviewOriginalMutation();
|
||||||
|
|
||||||
@@ -372,6 +375,18 @@ const PerformancePage = () => {
|
|||||||
downloadExcelBuffer(buffer, "서면 평가 배정 template.xlsx");
|
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} />
|
if(!mounted) return <LoadingOverlay force={true} />
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -402,8 +417,10 @@ const PerformancePage = () => {
|
|||||||
</PagePanel>
|
</PagePanel>
|
||||||
|
|
||||||
<PagePanel>
|
<PagePanel>
|
||||||
{canEdit && (
|
{!isWrittenReviewer && (
|
||||||
<div className="mb-3 flex justify-end gap-2">
|
<div className="mb-3 flex justify-end gap-2">
|
||||||
|
{canEdit && (
|
||||||
|
<>
|
||||||
<Button type="button" onClick={() => showDialog("performanceExcelRegisterDialog")}>
|
<Button type="button" onClick={() => showDialog("performanceExcelRegisterDialog")}>
|
||||||
<Upload className="h-4 w-4" />
|
<Upload className="h-4 w-4" />
|
||||||
사업 등록
|
사업 등록
|
||||||
@@ -411,8 +428,12 @@ const PerformancePage = () => {
|
|||||||
<Button type="button" variant="outline" onClick={() => showDialog("assignWrittenExcelDialog")}>
|
<Button type="button" variant="outline" onClick={() => showDialog("assignWrittenExcelDialog")}>
|
||||||
서면 평가 배정
|
서면 평가 배정
|
||||||
</Button>
|
</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<ExcelDownloadButton requestExcelExport={downloadPerformance} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<DataTable
|
<DataTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={filteredData}
|
data={filteredData}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {useAssignUserCountsQuery} from "@/query/assign";
|
|||||||
import {
|
import {
|
||||||
useDeleteUserMutation,
|
useDeleteUserMutation,
|
||||||
useDownloadUserExcelTemplateMutation,
|
useDownloadUserExcelTemplateMutation,
|
||||||
|
useExportUserMutation,
|
||||||
useUpdateUserMutation,
|
useUpdateUserMutation,
|
||||||
useUploadUsersExcelMutation,
|
useUploadUsersExcelMutation,
|
||||||
useUsersQuery,
|
useUsersQuery,
|
||||||
@@ -27,6 +28,7 @@ import {useDialog} from "@/hooks/useDialog";
|
|||||||
import {useMounted} from "@/hooks/useMounted";
|
import {useMounted} from "@/hooks/useMounted";
|
||||||
import {LoadingOverlay} from "@/components/common/LoadingOverlay";
|
import {LoadingOverlay} from "@/components/common/LoadingOverlay";
|
||||||
import {downloadExcelBuffer} from "@/lib/gwcf/file";
|
import {downloadExcelBuffer} from "@/lib/gwcf/file";
|
||||||
|
import ExcelDownloadButton from "@/components/common/ExcelDownloadButton";
|
||||||
|
|
||||||
type UserTab = "monitoring" | "written";
|
type UserTab = "monitoring" | "written";
|
||||||
type UserFilters = {area: string[]; gender: string[]; genre: string[]; keyword: string};
|
type UserFilters = {area: string[]; gender: string[]; genre: string[]; keyword: string};
|
||||||
@@ -64,6 +66,7 @@ const UserPage = () => {
|
|||||||
const deleteMutation = useDeleteUserMutation();
|
const deleteMutation = useDeleteUserMutation();
|
||||||
const uploadMutation = useUploadUsersExcelMutation(userRole);
|
const uploadMutation = useUploadUsersExcelMutation(userRole);
|
||||||
const templateMutation = useDownloadUserExcelTemplateMutation(userRole);
|
const templateMutation = useDownloadUserExcelTemplateMutation(userRole);
|
||||||
|
const exportMutation = useExportUserMutation();
|
||||||
|
|
||||||
const assignCountMap = useMemo(() => new Map(assignCounts.map((item) => [item.assignUser, item.assignCount])), [assignCounts]);
|
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");
|
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 renderEditableCell = (user: UserFull, key: string, fallbackKeys: string[], type: "text" | "select" = "text", options: Code[] = []) => {
|
||||||
const draft = draftRef.current;
|
const draft = draftRef.current;
|
||||||
const isEditing = editingId === user.userId && draft;
|
const isEditing = editingId === user.userId && draft;
|
||||||
@@ -255,6 +270,7 @@ const UserPage = () => {
|
|||||||
<Upload className="h-4 w-4" />
|
<Upload className="h-4 w-4" />
|
||||||
계정 등록
|
계정 등록
|
||||||
</Button>
|
</Button>
|
||||||
|
<ExcelDownloadButton requestExcelExport={downloadUsers} />
|
||||||
</div>
|
</div>
|
||||||
<DataTable
|
<DataTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
|
|||||||
@@ -72,6 +72,28 @@ export const POST = async (
|
|||||||
return new NextResponse(result, { status: 200 });
|
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 });
|
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
return errorToResponse(error);
|
return errorToResponse(error);
|
||||||
|
|||||||
@@ -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 });
|
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
return errorToResponse(error);
|
return errorToResponse(error);
|
||||||
|
|||||||
29
src/components/common/ExcelDownloadButton.tsx
Normal file
29
src/components/common/ExcelDownloadButton.tsx
Normal 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;
|
||||||
@@ -95,7 +95,7 @@ const getMonitoringTimeline = (visits: PerformanceMonitoringVisit[]): Monitoring
|
|||||||
export const getMonitoringSlots = (performance: Partial<PerformanceFull>): [MonitoringSlot, MonitoringSlot] => {
|
export const getMonitoringSlots = (performance: Partial<PerformanceFull>): [MonitoringSlot, MonitoringSlot] => {
|
||||||
const confirmedAssigns = (performance.performanceAssignList ?? [])
|
const confirmedAssigns = (performance.performanceAssignList ?? [])
|
||||||
.filter((assign) => assign.assignType === MONITORING_ASSIGN_TYPE && assign.assignConfirm)
|
.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 ?? {};
|
const visits = performance.performanceMonitoringVisitMap ?? {};
|
||||||
|
|
||||||
|
|||||||
@@ -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() {
|
export function useDownloadAssignExcelTemplateMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: () =>
|
mutationFn: () =>
|
||||||
|
|||||||
@@ -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() {
|
export function useDeleteUserMutation() {
|
||||||
const qc = useQueryClient();
|
const qc = useQueryClient();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user