+
diff --git a/src/components/common/SectionTitle.tsx b/src/components/common/SectionTitle.tsx
new file mode 100644
index 0000000..e45632a
--- /dev/null
+++ b/src/components/common/SectionTitle.tsx
@@ -0,0 +1,10 @@
+const SectionTitle = ({title}:{title:string}) => {
+ return (
+
+
+ {title}
+
+ );
+}
+
+export default SectionTitle;
diff --git a/src/components/dialog/loginDialog.tsx b/src/components/dialog/loginDialog.tsx
index 3e7690b..aacf109 100644
--- a/src/components/dialog/loginDialog.tsx
+++ b/src/components/dialog/loginDialog.tsx
@@ -2,7 +2,7 @@
import {useEffect, useRef, useState} from "react";
import {apiError} from "@/lib/http-util";
-import {NONE_HTTP_ERROR} from "@/const/commonConst";
+import {NONE_HTTP_ERROR} from "../../const/common.const";
import {DialogId} from "@/store/jotai/dialog";
import {useDialog} from "@/hooks/useDialog";
import {useLoginMutation} from "@/query/auth";
diff --git a/src/components/layout/MainLayout.tsx b/src/components/layout/MainLayout.tsx
index cf0ca34..9bd0f58 100644
--- a/src/components/layout/MainLayout.tsx
+++ b/src/components/layout/MainLayout.tsx
@@ -55,7 +55,7 @@ const MainLayout = ({ children }: MainLayoutProps) => {
if(!isMounted) return null;
return (
-
+
{
onLogin={openLoginDialog}
onLogout={handleLogout}
/>
-
+
-
- {children}
-
+
+
+ {children}
+
+
diff --git a/src/components/table/BaseDataTable.tsx b/src/components/table/BaseDataTable.tsx
new file mode 100644
index 0000000..306d18c
--- /dev/null
+++ b/src/components/table/BaseDataTable.tsx
@@ -0,0 +1,162 @@
+"use client";
+
+import type React from "react";
+import { cn, parseNumber } from "@/lib/utils";
+
+import BaseTableRenderer from "./core/BaseTableRenderer";
+import {
+ appendCellMarker,
+ getColumnAlign,
+ getLeafColumns,
+ toRoundedNumber,
+ toTableCellContent,
+} from "./core/table-core.helpers";
+import {DataColumn} from "@/components/table/types";
+import {isGapRow} from "@/lib/kfpa-utill";
+
+export type MergedTableCell
= {
+ key: keyof T;
+ content: React.ReactNode;
+ startRowIndex?: number;
+ rowSpan?: number;
+ className?: string;
+};
+
+export type PreAppendTableCell =
+ | React.ReactNode
+ | {
+ content: React.ReactNode;
+ className?: string;
+ colSpan?: number;
+ rowSpan?: number;
+ };
+
+type Props> = {
+ columns: DataColumn[];
+ rows: T[];
+ title?: string;
+ wrapperClassName?: string;
+ tableClassName?: string;
+ subheadRowClassName?: string;
+ minWidth?: number | string;
+ fillGapRow?: boolean;
+ mergedCell?: MergedTableCell;
+ getCellClassName?: (row: T, column: DataColumn, rowIndex: number) => string | undefined;
+};
+
+const getPreAppendCells = (row: Record): PreAppendTableCell[] => {
+ const cells = row.preAppendCells;
+ return Array.isArray(cells) ? (cells as PreAppendTableCell[]) : [];
+};
+
+const renderPreAppendCell = (cell: PreAppendTableCell, index: number) => {
+ const isCellConfig =
+ typeof cell === "object" &&
+ cell !== null &&
+ !Array.isArray(cell) &&
+ "content" in cell;
+
+ if (!isCellConfig) {
+ return {cell} | ;
+ }
+
+ return (
+
+ {cell.content}
+ |
+ );
+};
+
+export default function BaseDataTable>({
+ columns,
+ rows,
+ title,
+ wrapperClassName,
+ tableClassName,
+ subheadRowClassName,
+ minWidth,
+ fillGapRow = false,
+ mergedCell,
+ getCellClassName,
+}: Readonly>) {
+ const mergedCellStart = mergedCell?.startRowIndex ?? 0;
+ const mergedCellSpan = mergedCell?.rowSpan ?? Math.max(0, rows.length - mergedCellStart);
+ const leafColumns = getLeafColumns(columns);
+
+ return (
+
+ {rows.map((row, rowIndex) => {
+ const rowTotal = parseNumber(row.total);
+ const isFillGapRow = fillGapRow && isGapRow((row.rowLabel as string) ?? "")
+ const fillGapClass = isFillGapRow ? "bg-gray-100" : "";
+ const preAppendCells = getPreAppendCells(row);
+
+ return (
+
+ {preAppendCells.map(renderPreAppendCell)}
+ {leafColumns.map((column) => {
+ const dynamicCellClassName = getCellClassName?.(row, column, rowIndex);
+
+ if (mergedCell && column.key === mergedCell.key && rowIndex >= mergedCellStart) {
+ if (rowIndex > mergedCellStart) {
+ return null;
+ }
+
+ return (
+ |
+ {mergedCell.content}
+ |
+ );
+ }
+
+ const rawValue = row[column.key];
+ const align = getColumnAlign(column);
+ const defaultContent = column.render ? column.render(row) : toTableCellContent(rawValue);
+ const numericValue = "numeric" in column && column.numeric ? parseNumber(rawValue ?? defaultContent) ?? 0 : 0;
+
+ if (column.rowHead) {
+ return (
+
+ {defaultContent}
+ |
+ );
+ }
+
+ return (
+
+ {defaultContent}
+ |
+ );
+ })}
+
+ );
+ })}
+
+ );
+}
diff --git a/src/components/table/DataTable.tsx b/src/components/table/DataTable.tsx
new file mode 100644
index 0000000..fea84af
--- /dev/null
+++ b/src/components/table/DataTable.tsx
@@ -0,0 +1,43 @@
+"use client";
+
+import BaseDataTable from "./BaseDataTable";
+import {DataColumn} from "@/components/table/types";
+
+type Props> = {
+ columns: DataColumn[];
+ rows: T[];
+ title?: string;
+ className?: string;
+ tableClassName?: string;
+ wrapperClassName?: string;
+ subheadRowClassName?: string;
+ minWidth?: number | string;
+ fillGapRow?: boolean;
+};
+
+const DataTable = >({
+ columns,
+ rows,
+ title,
+ className,
+ tableClassName,
+ wrapperClassName,
+ subheadRowClassName,
+ minWidth,
+ fillGapRow = false,
+ }: Props) => {
+ return (
+
+ );
+};
+
+export default DataTable;
diff --git a/src/components/table/core/BaseTableHeader.tsx b/src/components/table/core/BaseTableHeader.tsx
new file mode 100644
index 0000000..8859cc7
--- /dev/null
+++ b/src/components/table/core/BaseTableHeader.tsx
@@ -0,0 +1,18 @@
+import SectionTitle from "@/components/common/SectionTitle";
+
+
+type Props = {
+ title?: string;
+};
+
+export default function BaseTableHeader({ title }: Readonly) {
+ if (!title) {
+ return null;
+ }
+
+ return (
+
+
+
+ );
+}
diff --git a/src/components/table/core/BaseTableRenderer.tsx b/src/components/table/core/BaseTableRenderer.tsx
new file mode 100644
index 0000000..8b3e208
--- /dev/null
+++ b/src/components/table/core/BaseTableRenderer.tsx
@@ -0,0 +1,68 @@
+"use client";
+
+import type React from "react";
+import { cn } from "@/lib/utils";
+
+import BaseTableHeader from "./BaseTableHeader";
+import { buildHeaderRows } from "./table-core.helpers";
+import {DataColumn} from "@/components/table/types";
+
+type BaseColumn = DataColumn;
+
+type Props = {
+ columns: BaseColumn[];
+ title?: string;
+ wrapperClassName?: string;
+ tableClassName?: string;
+ subheadRowClassName?: string;
+ minWidth?: number | string;
+ colgroup?: React.ReactNode;
+ renderHeaderPrefix?: React.ReactNode;
+ children: React.ReactNode;
+};
+
+export default function BaseTableRenderer({
+ columns,
+ title,
+ wrapperClassName,
+ tableClassName,
+ subheadRowClassName,
+ minWidth,
+ colgroup,
+ renderHeaderPrefix,
+ children,
+}: Readonly>) {
+ const headerRows = buildHeaderRows(columns);
+ const lastHeaderRowIndex = headerRows.length - 1;
+
+ return (
+
+
+
+
+
+ {colgroup}
+
+ {renderHeaderPrefix}
+ {headerRows.map((row, rowIndex) => (
+
+ {row.map((cell) => (
+ |
+ {cell.label}
+ |
+ ))}
+
+ ))}
+
+ {children}
+
+
+
+ );
+}
diff --git a/src/components/table/core/table-core.helpers.tsx b/src/components/table/core/table-core.helpers.tsx
new file mode 100644
index 0000000..3973773
--- /dev/null
+++ b/src/components/table/core/table-core.helpers.tsx
@@ -0,0 +1,242 @@
+import type React from "react";
+import { parseNumber, roundNumber } from "@/lib/utils";
+import {
+ DataColumn,
+ DataColumnLeaf,
+ SignDisplayMode,
+ SignStyle,
+ ValueFormatter
+} from "@/components/table/types";
+
+export type TableColumnNode = DataColumn;
+export type TableColumnLeaf = DataColumnLeaf;
+
+export type GroupHeaderCell = {
+ id: string;
+ label: string;
+ colSpan: number;
+ rowSpan: number;
+ className?: string;
+ isLeaf: boolean;
+};
+
+export type ResolvedSignStyle = {
+ paint: "text" | "cell";
+ display: SignDisplayMode;
+ showPlus: boolean;
+ arrowWithNumber: boolean;
+ zeroText: string;
+ valueFormatter: ValueFormatter;
+ positiveTextClassName: string;
+ negativeTextClassName: string;
+ zeroTextClassName: string;
+ positiveCellBg: string;
+ negativeCellBg: string;
+ zeroCellBg: string;
+};
+
+const defaultValueFormatter: ValueFormatter = (value) =>
+ Number.isInteger(value) ? String(roundNumber(value)) : value.toLocaleString();
+
+function isColumnLeaf(column: TableColumnNode): column is TableColumnLeaf {
+ return !("children" in column) || !column.children?.length;
+}
+
+export function getLeafColumns(columns: TableColumnNode[]) {
+ const leaves: TableColumnLeaf[] = [];
+
+ const visit = (nodes: TableColumnNode[]) => {
+ nodes.forEach((node) => {
+ if (isColumnLeaf(node)) {
+ leaves.push(node);
+ return;
+ }
+
+ visit(node.children);
+ });
+ };
+
+ visit(columns);
+ return leaves;
+}
+
+function getHeaderDepth(columns: TableColumnNode[]) {
+ const visit = (nodes: TableColumnNode[], depth: number): number =>
+ nodes.reduce((maxDepth, node) => {
+ if (isColumnLeaf(node)) {
+ return Math.max(maxDepth, depth);
+ }
+
+ return Math.max(maxDepth, visit(node.children, depth + 1));
+ }, depth);
+
+ return columns.length ? visit(columns, 1) : 0;
+}
+
+function getLeafCount(column: TableColumnNode): number {
+ if (isColumnLeaf(column)) {
+ return 1;
+ }
+
+ return column.children.reduce((sum, child) => sum + getLeafCount(child), 0);
+}
+
+export function buildHeaderRows(columns: TableColumnNode[]) {
+ const depth = getHeaderDepth(columns);
+
+ if (!depth) {
+ return [] as GroupHeaderCell[][];
+ }
+
+ const rows = Array.from({ length: depth }, () => [] as GroupHeaderCell[]);
+
+ const visit = (nodes: TableColumnNode[], level: number, path: string[]) => {
+ nodes.forEach((node, index) => {
+ const nodeId = node.id ?? (isColumnLeaf(node) ? String(node.key) : `${path.join(".") || "root"}:${index}:${node.header}`);
+ const nextPath = [...path, nodeId];
+ const isLeaf = isColumnLeaf(node);
+
+ rows[level].push({
+ id: nextPath.join("/"),
+ label: node.header,
+ colSpan: isLeaf ? 1 : getLeafCount(node),
+ rowSpan: isLeaf ? depth - level : 1,
+ className: node.headerClassName,
+ isLeaf,
+ });
+
+ if (!isLeaf) {
+ visit(node.children, level + 1, nextPath);
+ }
+ });
+ };
+
+ visit(columns, 0, []);
+ return rows;
+}
+
+export function hasGroupedHeader(columns: TableColumnNode[]) {
+ return getHeaderDepth(columns) > 1;
+}
+
+export function getColumnAlign(column: TableColumnLeaf, fallback: "left" | "center" | "right" = "center") {
+ if (column.align) {
+ return column.align;
+ }
+
+ if ("numeric" in column && column.numeric) {
+ return "right";
+ }
+
+ if (column.rowHead) {
+ return "left";
+ }
+
+ return fallback;
+}
+
+export function toTableCellContent(raw: unknown): React.ReactNode {
+ if (raw == null) {
+ return "";
+ }
+
+ if (typeof raw === "string") {
+ const trimmed = raw.trim();
+ if (!trimmed) {
+ return raw;
+ }
+
+ const parsed = Number(trimmed);
+ return Number.isNaN(parsed) ? raw : roundNumber(parsed);
+ }
+
+ if (typeof raw === "number") {
+ return String(roundNumber(raw));
+ }
+
+ return String(raw);
+}
+
+export function toRoundedNumber(raw: unknown, decimalPoint?: number) {
+ const parsed = parseNumber(raw);
+ return parsed === null ? null : roundNumber(parsed, decimalPoint);
+}
+
+const defaultSignStyle: ResolvedSignStyle = {
+ paint: "text",
+ display: "number",
+ showPlus: true,
+ arrowWithNumber: false,
+ zeroText: "-",
+ valueFormatter: defaultValueFormatter,
+ positiveTextClassName: "text-primary font-semibold",
+ negativeTextClassName: "text-info font-semibold",
+ zeroTextClassName: "text-gray-600",
+ positiveCellBg: "hsl(var(--primary) / 0.08)",
+ negativeCellBg: "hsl(var(--info) / 0.08)",
+ zeroCellBg: "hsl(var(--lg-gray-200) / 0.6)",
+};
+
+
+export function resolveSignStyle(signStyle?: SignStyle, fallback?: Partial) {
+ return {
+ ...defaultSignStyle,
+ ...fallback,
+ ...signStyle,
+ valueFormatter: signStyle?.valueFormatter ?? fallback?.valueFormatter ?? defaultSignStyle.valueFormatter,
+ };
+}
+
+export function formatSignedValue(
+ value: number,
+ options: Pick
+) {
+ if (options.display === "arrow") {
+ if (value > 0) {
+ return options.arrowWithNumber ? `▲${options.valueFormatter(Math.abs(value))}` : "▲";
+ }
+ if (value < 0) {
+ return options.arrowWithNumber ? `▼${options.valueFormatter(Math.abs(value))}` : "▼";
+ }
+ return options.zeroText;
+ }
+
+ if (value > 0) {
+ return options.showPlus ? `+${options.valueFormatter(value)}` : options.valueFormatter(value);
+ }
+ if (value < 0) {
+ return options.valueFormatter(value);
+ }
+ return options.zeroText;
+}
+
+
+export function getSignTextClass(
+ value: number,
+ options: Pick
+) {
+ if (value > 0) {
+ return options.positiveTextClassName;
+ }
+ if (value < 0) {
+ return options.negativeTextClassName;
+ }
+ return options.zeroTextClassName;
+}
+
+export function appendCellMarker(content: React.ReactNode, marker: string) {
+ if (!marker) {
+ return content;
+ }
+
+ if (typeof content === "string" || typeof content === "number") {
+ return `${content}${marker}`;
+ }
+
+ return (
+ <>
+ {content}
+ {marker}
+ >
+ );
+}
\ No newline at end of file
diff --git a/src/components/table/table.config.ts b/src/components/table/table.config.ts
new file mode 100644
index 0000000..0f55dab
--- /dev/null
+++ b/src/components/table/table.config.ts
@@ -0,0 +1,12 @@
+export const TABLE_DIMENSIONS = {
+ CELL_HEIGHT: {
+ DEFAULT: 26,
+ COMPACT: 20,
+ EXPANDED: 32,
+ },
+ MIN_WIDTH: {
+ STANDARD: 1600,
+ COMPACT: 1200,
+ WIDE: 2000,
+ },
+} as const;
\ No newline at end of file
diff --git a/src/components/table/types.ts b/src/components/table/types.ts
new file mode 100644
index 0000000..df5ef7f
--- /dev/null
+++ b/src/components/table/types.ts
@@ -0,0 +1,64 @@
+export type ValueFormatter = (v: number) => string;
+
+export type TableColumnAlign = "left" | "center" | "right";
+
+type TableColumnShared = {
+ id?: string;
+ header: string;
+ width?: number | string;
+ align?: TableColumnAlign;
+ headerClassName?: string;
+ cellClassName?: string;
+ render?: (row: T) => React.ReactNode;
+};
+
+export type DataColumnLeaf = TableColumnShared & {
+ key: keyof T;
+ rowHead?: boolean; // 첫 컬럼 등 row header
+ numeric?: boolean; // 숫자열(정렬 기본값/색상 타겟 기본값에 사용)
+ children?: undefined;
+};
+
+export type DataColumnGroup = TableColumnShared & {
+ children: DataColumn[];
+ key?: undefined;
+ rowHead?: undefined;
+ numeric?: undefined;
+};
+
+export type DataColumn = DataColumnLeaf | DataColumnGroup;
+
+export type SignDisplayMode = "number" | "arrow";
+
+export type SignStyle = {
+ /** 어떤 row에 +/ -/ 0 색상표기를 적용할지 선택 */
+ rowSelector: (row: T, rowIndex: number) => boolean;
+
+ /** 어떤 컬럼에 적용할지(미지정 시 numeric 컬럼 전체) */
+ keys?: (keyof T)[];
+
+ /** 색상 적용 방식 */
+ paint?: "text" | "cell"; // 기본 text
+
+ /** 표기 방식 */
+ display?: SignDisplayMode; // 기본 number
+ showPlus?: boolean; // number 모드에서 + 표시(기본 true)
+
+ /** 0 값 표기(기본 "-") */
+ zeroText?: string;
+
+ /** arrow 모드 옵션 */
+ arrowWithNumber?: boolean; // ▲ 2 처럼 (기본 false)
+
+ /** 값 포맷(기본: 정수면 그대로/그 외 toLocaleString) */
+ valueFormatter?: (v: number) => string;
+
+ /** 색상 커스터마이즈(기본: + primary, - info, 0 gray) */
+ positiveTextClassName?: string; // 기본 "text-primary font-semibold"
+ negativeTextClassName?: string; // 기본 "text-info font-semibold"
+ zeroTextClassName?: string; // 기본 "text-gray-600"
+
+ positiveCellBg?: string; // ex) "hsl(var(--primary) / 0.08)"
+ negativeCellBg?: string; // ex) "hsl(var(--info) / 0.08)"
+ zeroCellBg?: string; // ex) "hsl(var(--lg-gray-200) / 0.6)"
+};
\ No newline at end of file
diff --git a/src/components/ui/dialog.tsx b/src/components/ui/dialog.tsx
index 3e0ce0e..750c52c 100644
--- a/src/components/ui/dialog.tsx
+++ b/src/components/ui/dialog.tsx
@@ -39,7 +39,7 @@ function DialogOverlay({
= {
'2601009_A': '안전점검',
- '2604005_E': 'UCIS',
- '2604005_D': 'Bridge플랫폼',
- '2604005_C': '방재컨설팅',
- '2604005_A': '보험 공동인수',
- '2604005_B': '화재조사',
+ //'2604005_E': 'UCIS',
+ //'2604005_D': 'Bridge플랫폼',
+ //'2604005_C': '방재컨설팅',
+ //'2604005_A': '보험 공동인수',
+ //'2604005_B': '화재조사',
};
export const CATEGORY_PATH_MAP: Record = {
@@ -25,22 +25,22 @@ export const CATEGORIES = Object.values(CATEGORY_KEY_MAP) as Array;
export const DIV_KEY_MAP: Record = {
'-1': '전체',
'1': '서울인천지역본부',
- '2': '경기강원지역본부',
- '3': '부산경남지역본부',
- '4': '대구경북지역본부',
- '5': '대전충청지역본부',
- '6': '광주호남지역본부',
+ '3': '경기강원지역본부',
+ '2': '부산경남지역본부',
+ '5': '대구경북지역본부',
+ '6': '대전충청지역본부',
+ '4': '광주호남지역본부',
};
-export const DIV_KEYS = Object.keys(DIV_KEY_MAP) as Array;
+export const DIV_KEYS = ["-1", "1", "3", "2", "5", "6", "4"] as const;
-export const DIVS = Object.values(DIV_KEY_MAP) as Array;
+export const DIVS = DIV_KEYS.map((key) => DIV_KEY_MAP[key]);
export const REGION_KEY_MAP: Record = {
'1': '서울',
- '2': '경기',
- '3': '부산',
- '4': '대구',
- '5': '대전',
- '6': '광주',
-};
\ No newline at end of file
+ '3': '경기',
+ '2': '부산',
+ '5': '대구',
+ '6': '대전',
+ '4': '광주',
+};
diff --git a/src/config/menu.data.ts b/src/config/menu.data.ts
index 0395816..77d1316 100644
--- a/src/config/menu.data.ts
+++ b/src/config/menu.data.ts
@@ -1,5 +1,5 @@
import {SideMenuItem, TopMenuItem} from "@/config/menu.type";
-import {CATEGORY_KEY_MAP, CATEGORY_PATH_MAP, DIV_KEY_MAP} from "./kfpaConfig";
+import {CATEGORY_KEY_MAP, CATEGORY_PATH_MAP, DIV_KEY_MAP, DIV_KEYS} from "./kfpaConfig";
import { Building } from 'lucide-react';
export const TOP_MENUS: TopMenuItem[] = Object.entries(CATEGORY_KEY_MAP).map(
@@ -15,14 +15,9 @@ export const TOP_MENUS: TopMenuItem[] = Object.entries(CATEGORY_KEY_MAP).map(
}
);
-export const SIDE_MENUS :SideMenuItem[] = Object.entries(DIV_KEY_MAP)
- .sort(([a], [b]) => {
- if (a === "-1") return -1;
- if (b === "-1") return 1;
- return Number(a) - Number(b);
- })
- .map(([key, value]) => ({
+export const SIDE_MENUS :SideMenuItem[] = DIV_KEYS
+ .map((key) => ({
id: key,
- label: value,
+ label: DIV_KEY_MAP[key],
icon: Building,
}));
diff --git a/src/const/commonConst.ts b/src/const/common.const.ts
similarity index 100%
rename from src/const/commonConst.ts
rename to src/const/common.const.ts
diff --git a/src/const/kfpa.const.ts b/src/const/kfpa.const.ts
new file mode 100644
index 0000000..694cfdb
--- /dev/null
+++ b/src/const/kfpa.const.ts
@@ -0,0 +1,2 @@
+export const VIEW_DECIMAL_POINT = 0;
+export const GAP_WORDING = "전년 대비";
\ No newline at end of file
diff --git a/src/lib/http-util.ts b/src/lib/http-util.ts
index 15a9a51..6fe5a5f 100644
--- a/src/lib/http-util.ts
+++ b/src/lib/http-util.ts
@@ -1,7 +1,7 @@
import {NextResponse} from "next/server";
import {HttpError} from "@/lib/http-client";
import {clientEnv} from "@/lib/env.client";
-import {NONE_HTTP_ERROR, UNKNOWN_HTTP_ERROR} from "@/const/commonConst";
+import {NONE_HTTP_ERROR, UNKNOWN_HTTP_ERROR} from "../const/common.const";
export type ApiError = {
status: number
diff --git a/src/lib/kfpa-utill.ts b/src/lib/kfpa-utill.ts
new file mode 100644
index 0000000..e9e9350
--- /dev/null
+++ b/src/lib/kfpa-utill.ts
@@ -0,0 +1,3 @@
+export const isGapRow = (raw: string) => raw.replace(/\s+/g, "").toUpperCase().includes("전년대비");
+
+export const isSampleRow = (raw: string) => raw.replace(/\s+/g, "").includes("사례수");
\ No newline at end of file
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index bd0c391..d71553b 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -1,6 +1,61 @@
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
+import {VIEW_DECIMAL_POINT} from "@/const/kfpa.const";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
+
+export const formatKoreanBaseDate = (date = new Date()) => {
+ const year = String(date.getFullYear()).slice(-2);
+ return `${year}년 ${date.getMonth() + 1}월 ${date.getDate()}일 기준`;
+};
+
+/**
+ * 다양한 형식의 값을 숫자로 파싱합니다.
+ * - 쉼표, 퍼센트, 유니코드 마이너스 자동 처리
+ * - null/undefined/빈문자열/"−" 등은 null 반환
+ * - 유한하지 않은 숫자는 null 반환
+ */
+export function parseNumber(
+ value: unknown,
+ options?: {
+ allowComma?: boolean; // 기본값: true
+ allowPercent?: boolean; // 기본값: true
+ allowMinus?: boolean; // 기본값: true (유니코드 마이너스 포함)
+ }
+): number | null {
+ const { allowComma = true, allowPercent = true, allowMinus = true } = options ?? {};
+
+ if (value === null || value === undefined) return null;
+
+ if (typeof value === "number") {
+ return Number.isFinite(value) ? value : null;
+ }
+
+ if (typeof value === "string") {
+ let s = value.trim();
+
+ if (s === "" || s === "-" || s === "−") return null;
+
+ s = s.replaceAll("(", "");
+ s = s.replaceAll(")", "");
+
+ if (allowComma) s = s.replaceAll(",", "");
+ if (allowPercent) s = s.replaceAll("%", "");
+ if (allowMinus) s = s.replaceAll("−", "-"); // 유니코드 마이너스 -> ASCII 마이너스
+
+ const n = Number(s);
+ return Number.isFinite(n) ? n : null;
+ }
+
+ return null;
+}
+
+export const roundNumber = (num: number|null, decimalPoint?: number) => {
+ if(num == null) return null;
+
+ decimalPoint ??= VIEW_DECIMAL_POINT;
+ const factor = 10 ** decimalPoint;
+ return Math.round(num * factor) / factor;
+};
diff --git a/src/query/admin.ts b/src/query/admin.ts
new file mode 100644
index 0000000..aee7004
--- /dev/null
+++ b/src/query/admin.ts
@@ -0,0 +1,15 @@
+import {useMutation} from "@tanstack/react-query";
+import {nextApi} from "@/lib/http-client";
+import {RequestWriteDivComment} from "@/types/kfpa";
+import {adminQueryKeys} from "@/query/key/keys";
+
+export const writeDivComment = (body: RequestWriteDivComment) => {
+ return nextApi.patch("/admin/div-comment", body);
+};
+
+export const useWriteDivCommentMutation = () => {
+ return useMutation({
+ mutationKey: adminQueryKeys.divComment(),
+ mutationFn: writeDivComment,
+ });
+};
diff --git a/src/query/key/keys.ts b/src/query/key/keys.ts
index e69de29..f9b18b2 100644
--- a/src/query/key/keys.ts
+++ b/src/query/key/keys.ts
@@ -0,0 +1,10 @@
+export const adminQueryKeys = {
+ all: ["admin"] as const,
+ divComment: () => [...adminQueryKeys.all, "div-comment"] as const,
+};
+
+export const statisticsQueryKeys = {
+ all: ["statistics"] as const,
+ csi: () => [...statisticsQueryKeys.all, "csi"] as const,
+ divDetail: (divId: string | number) => [...statisticsQueryKeys.all, "div-detail", String(divId)] as const,
+};
diff --git a/src/query/statistics.ts b/src/query/statistics.ts
new file mode 100644
index 0000000..08f8964
--- /dev/null
+++ b/src/query/statistics.ts
@@ -0,0 +1,27 @@
+import {useQuery} from "@tanstack/react-query";
+import {nextApi} from "@/lib/http-client";
+import {CsiDataMap, DivDetailDataMap} from "@/types/kfpa";
+import {statisticsQueryKeys} from "@/query/key/keys";
+
+export const getCsiData = () => {
+ return nextApi.get("/statistics/csi");
+};
+
+export const getDivDetailData = (divId: string | number) => {
+ return nextApi.get(`/statistics/div-detail/${divId}`);
+};
+
+export const useCsiDataQuery = () => {
+ return useQuery({
+ queryKey: statisticsQueryKeys.csi(),
+ queryFn: getCsiData,
+ });
+};
+
+export const useDivDetailDataQuery = (divId: string | number, enabled = true) => {
+ return useQuery({
+ queryKey: statisticsQueryKeys.divDetail(divId),
+ queryFn: () => getDivDetailData(divId),
+ enabled,
+ });
+};
diff --git a/src/types/kfpa.ts b/src/types/kfpa.ts
index 81aad02..2f977d5 100644
--- a/src/types/kfpa.ts
+++ b/src/types/kfpa.ts
@@ -2,4 +2,38 @@ import {CATEGORY_KEY_MAP, DIV_KEY_MAP} from "@/config/kfpaConfig";
export type CategoryKey = keyof typeof CATEGORY_KEY_MAP;
-export type DivKey = keyof typeof DIV_KEY_MAP;
\ No newline at end of file
+export type DivKey = keyof typeof DIV_KEY_MAP;
+
+export type CommentValue = {
+ directExperience: string;
+ indirectExperience: string;
+ capability: string;
+};
+
+export type RequestWriteDivComment = {
+ divId: number;
+ commentValues: Record;
+};
+
+export type CsiData = {
+ wave: number;
+ csi: number;
+ safeHelp: number;
+ recHelp: number;
+ staffProf: number;
+ staffAtt: number;
+};
+
+export type CsiRank = {
+ csi: number;
+ divRank: number;
+};
+
+export type DivDetailData = {
+ csiRanks: Record;
+ commentValues: Record;
+};
+
+export type CsiDataMap = Record;
+
+export type DivDetailDataMap = Record;