From 77d89527b831d796a792455f7fe4c8172ae7ccde Mon Sep 17 00:00:00 2001 From: chpark Date: Tue, 12 May 2026 00:39:15 +0900 Subject: [PATCH] =?UTF-8?q?fix(dept):=20=EB=B6=80=EC=84=9C=EC=BD=94?= =?UTF-8?q?=EB=93=9C/=ED=9A=8C=EC=82=AC=EB=AA=85=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EC=88=A8=EA=B9=80=20+=20=EC=9E=90=EB=8F=99=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20+=20DB=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [UI] - 부서 등록 폼: 부서코드/회사명 입력 제거 (부서명만 입력) - 부서 목록 grid: 부서코드/회사명 컬럼 제거 (부서명/활성여부/등록일만) [API] - /api/admin/dept/save: dept_code 비어있으면 'DEPT' + MAX+1 자동 생성 - company_name 기본값 '모모유통' [운영 데이터 정리] - 거래처(user_type='C') 134명 dept_code → DEPT003 일반구매자 - 전체 사용자 141명 비밀번호 → '1' (AES 암호화 저장) Co-Authored-By: Claude Opus 4.7 (1M context) --- src/app/admin-panel/page.tsx | 33 ++++++---------------------- src/app/api/admin/dept/save/route.ts | 23 ++++++++++++++----- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/app/admin-panel/page.tsx b/src/app/admin-panel/page.tsx index d4e3111..e772cf8 100644 --- a/src/app/admin-panel/page.tsx +++ b/src/app/admin-panel/page.tsx @@ -1408,18 +1408,16 @@ function DeptManagement() { }; const columns: GridColumn[] = [ - { title: "부서코드", field: "DEPT_CODE", width: 140, cellClick: (row) => openEdit(row) }, - { title: "회사명", field: "COMPANY_NAME", width: 180 }, - { title: "부서명", field: "DEPT_NAME", width: 240 }, - { title: "활성화 여부", field: "STATUS_NAME", width: 100 }, - { title: "등록일", field: "REGDATE", width: 110, hozAlign: "center" }, + { title: "부서명", field: "DEPT_NAME", width: 320, cellClick: (row) => openEdit(row) }, + { title: "활성화 여부", field: "STATUS_NAME", width: 120, hozAlign: "center" }, + { title: "등록일", field: "REGDATE", width: 130, hozAlign: "center" }, ]; const set = (k: string, v: string) => setEditForm((p) => ({ ...p, [k]: v })); const handleSave = async () => { - if (!editForm.dept_code || !editForm.dept_name) { - Swal.fire("알림", "부서코드와 부서명은 필수입니다.", "warning"); + if (!editForm.dept_name) { + Swal.fire("알림", "부서명은 필수입니다.", "warning"); return; } setSaving(true); @@ -1457,29 +1455,12 @@ function DeptManagement() {

- {editForm.actionType === "regist" ? "부서 등록" : `부서 수정 — ${editForm.dept_code}`} + {editForm.actionType === "regist" ? "부서 등록" : `부서 수정`}

- - - - - - - - - + diff --git a/src/app/api/admin/dept/save/route.ts b/src/app/api/admin/dept/save/route.ts index 2bf4f1c..bcb050d 100644 --- a/src/app/api/admin/dept/save/route.ts +++ b/src/app/api/admin/dept/save/route.ts @@ -22,14 +22,25 @@ export async function POST(request: NextRequest) { company_name, } = body as Record; - if (!dept_code || !dept_name) { - return NextResponse.json({ success: false, message: "부서코드와 부서명은 필수입니다." }, { status: 400 }); + if (!dept_name) { + return NextResponse.json({ success: false, message: "부서명은 필수입니다." }, { status: 400 }); } if (actionType === "regist") { + // 부서코드 자동 생성: DEPT### 최대값 + 1 + let code = (dept_code || "").trim(); + if (!code) { + const row = await queryOne<{ MAX_CODE: string | null }>( + `SELECT MAX(dept_code) AS "MAX_CODE" FROM dept_info WHERE dept_code ~ '^DEPT[0-9]+$'` + ); + const max = row?.MAX_CODE; + const next = max ? parseInt(max.replace(/^DEPT/, ""), 10) + 1 : 1; + code = `DEPT${String(next).padStart(3, "0")}`; + } + const dup = await queryOne<{ cnt: string }>( `SELECT COUNT(*)::text AS cnt FROM dept_info WHERE dept_code = $1`, - [dept_code] + [code] ); if (dup && Number(dup.cnt) > 0) { return NextResponse.json({ success: false, message: "이미 존재하는 부서코드입니다." }, { status: 400 }); @@ -41,7 +52,7 @@ export async function POST(request: NextRequest) { location, location_name, regdate, status, sales_yn, company_name) VALUES ($1, $2, $3, $4, $5, $6, $7, NOW(), COALESCE($8,'active'), $9, $10)`, [ - dept_code, + code, dept_name, parent_dept_code || null, master_sabun || null, @@ -50,10 +61,10 @@ export async function POST(request: NextRequest) { location_name || null, status || "active", sales_yn || "N", - company_name || null, + company_name || "모모유통", ] ); - return NextResponse.json({ success: true, message: "등록되었습니다.", dept_code }); + return NextResponse.json({ success: true, message: "등록되었습니다.", dept_code: code }); } // 수정
부서코드 * - set("dept_code", e.target.value)} - readOnly={editForm.actionType !== "regist"} - className={editForm.actionType !== "regist" ? "bg-gray-50" : ""} - /> -
회사명 - set("company_name", e.target.value)} /> -
부서명 *부서명 * set("dept_name", e.target.value)} />