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]);