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)} />