feat(tksupport): Sprint 001 Section C — 전사 휴가관리 구현
- 전사 휴가 부여/관리 (company-holidays) CRUD + 연차차감 트랜잭션 - 전체 휴가관리 대시보드 (vacation-dashboard) 부서별/직원별 현황 - 내 휴가 현황 개선 (/my-status) balance_type별 카드, 전사 휴가일 - requireSupportTeam 미들웨어, 부서명 JOIN, 마이그레이션 002 추가 - 사이드바 roles 기반 메뉴 필터링 (하위호환 유지) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
55
tksupport/api/models/vacationDashboardModel.js
Normal file
55
tksupport/api/models/vacationDashboardModel.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const { getPool } = require('../middleware/auth');
|
||||
|
||||
const vacationDashboardModel = {
|
||||
async getSummary(year) {
|
||||
const db = getPool();
|
||||
const [rows] = await db.query(`
|
||||
SELECT
|
||||
d.department_id, COALESCE(d.department_name, '미배정') as department_name,
|
||||
COUNT(DISTINCT su.user_id) as employee_count,
|
||||
AVG(vb.total_days - vb.used_days) as avg_remaining,
|
||||
SUM(CASE WHEN (vb.total_days - vb.used_days) <= 2 THEN 1 ELSE 0 END) as low_balance_count
|
||||
FROM sso_users su
|
||||
LEFT JOIN departments d ON su.department_id = d.department_id
|
||||
LEFT JOIN sp_vacation_balances vb ON su.user_id = vb.user_id
|
||||
AND vb.year = ? AND vb.balance_type = 'AUTO'
|
||||
WHERE su.is_active = 1
|
||||
GROUP BY d.department_id
|
||||
`, [year]);
|
||||
return rows;
|
||||
},
|
||||
|
||||
async getEmployeeList(year, filters = {}) {
|
||||
const db = getPool();
|
||||
let query = `
|
||||
SELECT su.user_id, su.name, su.username, su.hire_date, su.department_id,
|
||||
COALESCE(d.department_name, '미배정') as department_name,
|
||||
vb.id, vb.balance_type, vb.total_days, vb.used_days,
|
||||
(vb.total_days - vb.used_days) as remaining_days,
|
||||
vb.expires_at, vt.type_name, vt.type_code
|
||||
FROM sso_users su
|
||||
LEFT JOIN departments d ON su.department_id = d.department_id
|
||||
LEFT JOIN sp_vacation_balances vb ON su.user_id = vb.user_id
|
||||
AND (vb.year = ? OR (vb.balance_type = 'LONG_SERVICE' AND vb.expires_at IS NULL))
|
||||
LEFT JOIN vacation_types vt ON vb.vacation_type_id = vt.id
|
||||
WHERE su.is_active = 1
|
||||
`;
|
||||
const params = [year];
|
||||
|
||||
if (filters.department_id) {
|
||||
query += ' AND su.department_id = ?';
|
||||
params.push(filters.department_id);
|
||||
}
|
||||
if (filters.search_name) {
|
||||
query += ' AND su.name LIKE ?';
|
||||
params.push(`%${filters.search_name}%`);
|
||||
}
|
||||
|
||||
query += ' ORDER BY su.name ASC';
|
||||
|
||||
const [rows] = await db.query(query, params);
|
||||
return rows;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = vacationDashboardModel;
|
||||
Reference in New Issue
Block a user