From 2357744b023639093f379e6ab798db9bb5fef4c5 Mon Sep 17 00:00:00 2001 From: Hyungi Ahn Date: Tue, 31 Mar 2026 07:33:18 +0900 Subject: [PATCH] =?UTF-8?q?feat(tkfb):=20=EC=97=B0=EC=B0=A8=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=A0=95=EB=B3=B8=20=EC=A0=84=ED=99=98=20?= =?UTF-8?q?=E2=80=94=20vacation=5Fbalance=5Fdetails=20=E2=86=92=20sp=5Fvac?= =?UTF-8?q?ation=5Fbalances?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 대시보드 + 연간 연차 현황 페이지의 읽기를 tksupport 정본 테이블로 전환. - dashboardModel: getVacationBalance worker_id → user_id, sp_vacation_balances - dashboardController: worker_id 전달 제거, user_id 직접 사용 - vacationBalanceModel: 읽기 함수 3개 sp_vacation_balances로 전환 (쓰기 함수 deductByPriority 등은 vacation_balance_details 유지) - remaining_days: STORED GENERATED 대신 (total_days - used_days) AS 계산 Co-Authored-By: Claude Opus 4.6 (1M context) --- .../api/controllers/dashboardController.js | 5 +- system1-factory/api/models/dashboardModel.js | 16 +++--- .../api/models/vacationBalanceModel.js | 56 ++++++++++--------- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/system1-factory/api/controllers/dashboardController.js b/system1-factory/api/controllers/dashboardController.js index 67c7624..822b14c 100644 --- a/system1-factory/api/controllers/dashboardController.js +++ b/system1-factory/api/controllers/dashboardController.js @@ -23,13 +23,12 @@ const DashboardController = { return res.status(404).json({ success: false, message: '사용자 정보를 찾을 수 없습니다.' }); } - const workerId = userInfo.worker_id; const departmentId = userInfo.department_id; const role = userInfo.role; - // 2단계: 나머지 3개 병렬 조회 + // 2단계: 나머지 3개 병렬 조회 (연차: sp_vacation_balances from user_id) const [vacationRows, overtime, quickAccess] = await Promise.all([ - DashboardModel.getVacationBalance(workerId, year), + DashboardModel.getVacationBalance(userId, year), DashboardModel.getMonthlyOvertime(userId, year, month), DashboardModel.getQuickAccess(userId, departmentId, role) ]); diff --git a/system1-factory/api/models/dashboardModel.js b/system1-factory/api/models/dashboardModel.js index 039ed2e..fa4bc60 100644 --- a/system1-factory/api/models/dashboardModel.js +++ b/system1-factory/api/models/dashboardModel.js @@ -27,17 +27,19 @@ const DashboardModel = { /** * 연차 현황 조회 (쿼리 2) */ - getVacationBalance: async (workerId, year) => { - if (!workerId) return []; + getVacationBalance: async (userId, year) => { + if (!userId) return []; const db = await getDb(); const [rows] = await db.execute(` - SELECT vbd.vacation_type_id, vbd.total_days, vbd.used_days, vbd.remaining_days, + SELECT svb.vacation_type_id, svb.total_days, svb.used_days, + (svb.total_days - svb.used_days) AS remaining_days, + svb.balance_type, svb.expires_at, vt.type_name, vt.type_code - FROM vacation_balance_details vbd - JOIN vacation_types vt ON vbd.vacation_type_id = vt.id - WHERE vbd.worker_id = ? AND vbd.year = ? + FROM sp_vacation_balances svb + JOIN vacation_types vt ON svb.vacation_type_id = vt.id + WHERE svb.user_id = ? AND svb.year = ? ORDER BY vt.priority - `, [workerId, year]); + `, [userId, year]); return rows; }, diff --git a/system1-factory/api/models/vacationBalanceModel.js b/system1-factory/api/models/vacationBalanceModel.js index 87b9c21..78c0f4f 100644 --- a/system1-factory/api/models/vacationBalanceModel.js +++ b/system1-factory/api/models/vacationBalanceModel.js @@ -13,14 +13,15 @@ const vacationBalanceModel = { const db = await getDb(); const [rows] = await db.query(` SELECT - vbd.*, - vt.type_name, - vt.type_code, - vt.priority, - vt.is_special - FROM vacation_balance_details vbd - INNER JOIN vacation_types vt ON vbd.vacation_type_id = vt.id - WHERE vbd.user_id = ? AND vbd.year = ? + svb.id, svb.user_id, svb.vacation_type_id, svb.year, + svb.total_days, svb.used_days, + (svb.total_days - svb.used_days) AS remaining_days, + svb.balance_type, svb.expires_at, svb.notes, + svb.created_by, svb.created_at, svb.updated_at, + vt.type_name, vt.type_code, vt.priority, vt.is_special + FROM sp_vacation_balances svb + INNER JOIN vacation_types vt ON svb.vacation_type_id = vt.id + WHERE svb.user_id = ? AND svb.year = ? ORDER BY vt.priority ASC, vt.type_name ASC `, [userId, year]); return rows; @@ -33,14 +34,16 @@ const vacationBalanceModel = { const db = await getDb(); const [rows] = await db.query(` SELECT - vbd.*, - vt.type_name, - vt.type_code - FROM vacation_balance_details vbd - INNER JOIN vacation_types vt ON vbd.vacation_type_id = vt.id - WHERE vbd.user_id = ? - AND vbd.vacation_type_id = ? - AND vbd.year = ? + svb.id, svb.user_id, svb.vacation_type_id, svb.year, + svb.total_days, svb.used_days, + (svb.total_days - svb.used_days) AS remaining_days, + svb.balance_type, svb.expires_at, + vt.type_name, vt.type_code + FROM sp_vacation_balances svb + INNER JOIN vacation_types vt ON svb.vacation_type_id = vt.id + WHERE svb.user_id = ? + AND svb.vacation_type_id = ? + AND svb.year = ? `, [userId, vacationTypeId, year]); return rows; }, @@ -52,16 +55,17 @@ const vacationBalanceModel = { const db = await getDb(); const [rows] = await db.query(` SELECT - vbd.*, - w.worker_name, - w.employment_status, - vt.type_name, - vt.type_code, - vt.priority - FROM vacation_balance_details vbd - INNER JOIN workers w ON vbd.user_id = w.user_id - INNER JOIN vacation_types vt ON vbd.vacation_type_id = vt.id - WHERE vbd.year = ? + svb.id, svb.user_id, svb.vacation_type_id, svb.year, + svb.total_days, svb.used_days, + (svb.total_days - svb.used_days) AS remaining_days, + svb.balance_type, svb.expires_at, svb.notes, + svb.created_by, svb.created_at, svb.updated_at, + w.worker_name, w.employment_status, + vt.type_name, vt.type_code, vt.priority + FROM sp_vacation_balances svb + INNER JOIN workers w ON svb.user_id = w.user_id + INNER JOIN vacation_types vt ON svb.vacation_type_id = vt.id + WHERE svb.year = ? AND w.employment_status = 'employed' ORDER BY w.worker_name ASC, vt.priority ASC `, [year]);