feat(tkfb): 연차 데이터 정본 전환 — vacation_balance_details → sp_vacation_balances

대시보드 + 연간 연차 현황 페이지의 읽기를 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) <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-03-31 07:33:18 +09:00
parent 4dd39ceab7
commit 2357744b02
3 changed files with 41 additions and 36 deletions

View File

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

View File

@@ -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;
},

View File

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