1ㅊㅏ완료
This commit is contained in:
112
backend/api/dashboard/stats.get.ts
Normal file
112
backend/api/dashboard/stats.get.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
import { query } from '../../utils/db'
|
||||
|
||||
/**
|
||||
* 대시보드 통계 API
|
||||
* GET /api/dashboard/stats
|
||||
*
|
||||
* - 인원별 이번 주 실적/차주 계획 시간
|
||||
* - 프로젝트별 투입 인원/시간
|
||||
* - 제출 현황
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const userId = getCookie(event, 'user_id')
|
||||
if (!userId) {
|
||||
throw createError({ statusCode: 401, message: '로그인이 필요합니다.' })
|
||||
}
|
||||
|
||||
const q = getQuery(event)
|
||||
const year = parseInt(q.year as string) || new Date().getFullYear()
|
||||
const week = parseInt(q.week as string) || getISOWeek(new Date())
|
||||
|
||||
// 1. 인원별 실적/계획 현황
|
||||
const employeeStats = await query<any>(`
|
||||
SELECT
|
||||
e.employee_id,
|
||||
e.employee_name,
|
||||
e.company,
|
||||
r.report_id,
|
||||
r.report_status,
|
||||
COALESCE(SUM(CASE WHEN t.task_type = 'WORK' THEN t.task_hours ELSE 0 END), 0) as work_hours,
|
||||
COALESCE(SUM(CASE WHEN t.task_type = 'PLAN' THEN t.task_hours ELSE 0 END), 0) as plan_hours,
|
||||
COUNT(DISTINCT CASE WHEN t.task_type = 'WORK' THEN t.project_id END) as work_project_count,
|
||||
COUNT(DISTINCT CASE WHEN t.task_type = 'PLAN' THEN t.project_id END) as plan_project_count
|
||||
FROM wr_employee_info e
|
||||
LEFT JOIN wr_weekly_report r ON e.employee_id = r.author_id
|
||||
AND r.report_year = $1 AND r.report_week = $2
|
||||
LEFT JOIN wr_weekly_report_task t ON r.report_id = t.report_id
|
||||
WHERE e.is_active = true
|
||||
GROUP BY e.employee_id, e.employee_name, e.company, r.report_id, r.report_status
|
||||
ORDER BY work_hours DESC, e.employee_name
|
||||
`, [year, week])
|
||||
|
||||
// 2. 프로젝트별 투입 현황
|
||||
const projectStats = await query<any>(`
|
||||
SELECT
|
||||
p.project_id,
|
||||
p.project_code,
|
||||
p.project_name,
|
||||
COUNT(DISTINCT r.author_id) as member_count,
|
||||
COALESCE(SUM(CASE WHEN t.task_type = 'WORK' THEN t.task_hours ELSE 0 END), 0) as work_hours,
|
||||
COALESCE(SUM(CASE WHEN t.task_type = 'PLAN' THEN t.task_hours ELSE 0 END), 0) as plan_hours,
|
||||
ARRAY_AGG(DISTINCT e.employee_name) as members
|
||||
FROM wr_project_info p
|
||||
JOIN wr_weekly_report_task t ON p.project_id = t.project_id
|
||||
JOIN wr_weekly_report r ON t.report_id = r.report_id
|
||||
AND r.report_year = $1 AND r.report_week = $2
|
||||
JOIN wr_employee_info e ON r.author_id = e.employee_id
|
||||
WHERE p.project_status = 'IN_PROGRESS'
|
||||
GROUP BY p.project_id, p.project_code, p.project_name
|
||||
ORDER BY work_hours DESC
|
||||
`, [year, week])
|
||||
|
||||
// 3. 전체 요약
|
||||
const activeEmployees = employeeStats.length
|
||||
const submittedCount = employeeStats.filter((e: any) => e.report_id).length
|
||||
const totalWorkHours = employeeStats.reduce((sum: number, e: any) => sum + parseFloat(e.work_hours || 0), 0)
|
||||
const totalPlanHours = employeeStats.reduce((sum: number, e: any) => sum + parseFloat(e.plan_hours || 0), 0)
|
||||
|
||||
return {
|
||||
year,
|
||||
week,
|
||||
summary: {
|
||||
activeEmployees,
|
||||
submittedCount,
|
||||
notSubmittedCount: activeEmployees - submittedCount,
|
||||
totalWorkHours,
|
||||
totalPlanHours,
|
||||
projectCount: projectStats.length
|
||||
},
|
||||
employees: employeeStats.map((e: any) => ({
|
||||
employeeId: e.employee_id,
|
||||
employeeName: e.employee_name,
|
||||
company: e.company,
|
||||
reportId: e.report_id,
|
||||
reportStatus: e.report_status,
|
||||
workHours: parseFloat(e.work_hours) || 0,
|
||||
planHours: parseFloat(e.plan_hours) || 0,
|
||||
workProjectCount: parseInt(e.work_project_count) || 0,
|
||||
planProjectCount: parseInt(e.plan_project_count) || 0,
|
||||
isSubmitted: !!e.report_id
|
||||
})),
|
||||
projects: projectStats.map((p: any) => ({
|
||||
projectId: p.project_id,
|
||||
projectCode: p.project_code,
|
||||
projectName: p.project_name,
|
||||
memberCount: parseInt(p.member_count) || 0,
|
||||
workHours: parseFloat(p.work_hours) || 0,
|
||||
planHours: parseFloat(p.plan_hours) || 0,
|
||||
members: p.members || []
|
||||
}))
|
||||
}
|
||||
})
|
||||
|
||||
function getISOWeek(date: Date): number {
|
||||
const target = new Date(date)
|
||||
target.setHours(0, 0, 0, 0)
|
||||
const thursday = new Date(target)
|
||||
thursday.setDate(target.getDate() - ((target.getDay() + 6) % 7) + 3)
|
||||
const year = thursday.getFullYear()
|
||||
const firstThursday = new Date(year, 0, 4)
|
||||
firstThursday.setDate(firstThursday.getDate() - ((firstThursday.getDay() + 6) % 7) + 3)
|
||||
return Math.ceil((thursday.getTime() - firstThursday.getTime()) / (7 * 24 * 60 * 60 * 1000)) + 1
|
||||
}
|
||||
74
backend/api/employee/[id]/delete.delete.ts
Normal file
74
backend/api/employee/[id]/delete.delete.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { query, execute } from '../../../utils/db'
|
||||
|
||||
const ADMIN_EMAIL = 'coziny@gmail.com'
|
||||
|
||||
/**
|
||||
* 직원 삭제
|
||||
* DELETE /api/employee/[id]
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const userId = getCookie(event, 'user_id')
|
||||
if (!userId) {
|
||||
throw createError({ statusCode: 401, message: '로그인이 필요합니다.' })
|
||||
}
|
||||
|
||||
// 관리자 권한 체크
|
||||
const currentUser = await query<any>(`
|
||||
SELECT employee_email FROM wr_employee_info WHERE employee_id = $1
|
||||
`, [userId])
|
||||
|
||||
if (!currentUser[0] || currentUser[0].employee_email !== ADMIN_EMAIL) {
|
||||
throw createError({ statusCode: 403, message: '관리자만 삭제할 수 있습니다.' })
|
||||
}
|
||||
|
||||
const employeeId = getRouterParam(event, 'id')
|
||||
if (!employeeId) {
|
||||
throw createError({ statusCode: 400, message: '직원 ID가 필요합니다.' })
|
||||
}
|
||||
|
||||
// 본인 삭제 방지
|
||||
if (employeeId === userId) {
|
||||
throw createError({ statusCode: 400, message: '본인은 삭제할 수 없습니다.' })
|
||||
}
|
||||
|
||||
// 직원 존재 여부 확인
|
||||
const employee = await query<any>(`
|
||||
SELECT employee_id, employee_name FROM wr_employee_info WHERE employee_id = $1
|
||||
`, [employeeId])
|
||||
|
||||
if (!employee[0]) {
|
||||
throw createError({ statusCode: 404, message: '직원을 찾을 수 없습니다.' })
|
||||
}
|
||||
|
||||
// 주간보고 존재 여부 확인
|
||||
const reports = await query<any>(`
|
||||
SELECT COUNT(*) as cnt FROM wr_weekly_report WHERE author_id = $1
|
||||
`, [employeeId])
|
||||
|
||||
const reportCount = parseInt(reports[0].cnt)
|
||||
|
||||
if (reportCount > 0) {
|
||||
// 주간보고가 있으면 비활성화만
|
||||
await execute(`
|
||||
UPDATE wr_employee_info
|
||||
SET is_active = false, updated_at = NOW()
|
||||
WHERE employee_id = $1
|
||||
`, [employeeId])
|
||||
|
||||
return {
|
||||
success: true,
|
||||
action: 'deactivated',
|
||||
message: `${employee[0].employee_name}님이 비활성화되었습니다. (주간보고 ${reportCount}건 보존)`
|
||||
}
|
||||
} else {
|
||||
// 주간보고가 없으면 완전 삭제 (로그인 이력 포함)
|
||||
await execute(`DELETE FROM wr_login_history WHERE employee_id = $1`, [employeeId])
|
||||
await execute(`DELETE FROM wr_employee_info WHERE employee_id = $1`, [employeeId])
|
||||
|
||||
return {
|
||||
success: true,
|
||||
action: 'deleted',
|
||||
message: `${employee[0].employee_name}님이 삭제되었습니다.`
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -14,8 +14,6 @@ export default defineEventHandler(async (event) => {
|
||||
SELECT
|
||||
s.report_year,
|
||||
s.report_week,
|
||||
MIN(s.week_start_date) as week_start_date,
|
||||
MAX(s.week_end_date) as week_end_date,
|
||||
COUNT(DISTINCT s.project_id) as project_count,
|
||||
SUM(s.member_count) as total_members,
|
||||
SUM(COALESCE(s.total_work_hours, 0)) as total_work_hours,
|
||||
@@ -29,16 +27,50 @@ export default defineEventHandler(async (event) => {
|
||||
`, [year])
|
||||
|
||||
return {
|
||||
weeks: rows.map((r: any) => ({
|
||||
reportYear: r.report_year,
|
||||
reportWeek: r.report_week,
|
||||
weekStartDate: r.week_start_date,
|
||||
weekEndDate: r.week_end_date,
|
||||
projectCount: parseInt(r.project_count),
|
||||
totalMembers: parseInt(r.total_members),
|
||||
totalWorkHours: parseFloat(r.total_work_hours) || 0,
|
||||
latestAggregatedAt: r.latest_aggregated_at,
|
||||
projects: r.project_names || []
|
||||
}))
|
||||
weeks: rows.map((r: any) => {
|
||||
const { monday, sunday } = getWeekDates(r.report_year, r.report_week)
|
||||
return {
|
||||
reportYear: r.report_year,
|
||||
reportWeek: r.report_week,
|
||||
weekStartDate: monday,
|
||||
weekEndDate: sunday,
|
||||
projectCount: parseInt(r.project_count),
|
||||
totalMembers: parseInt(r.total_members),
|
||||
totalWorkHours: parseFloat(r.total_work_hours) || 0,
|
||||
latestAggregatedAt: r.latest_aggregated_at,
|
||||
projects: r.project_names || []
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// ISO 8601 주차 기준 월요일~일요일 계산
|
||||
function getWeekDates(year: number, week: number): { monday: string, sunday: string } {
|
||||
// 해당 연도의 1월 4일이 속한 주가 1주차 (ISO 8601)
|
||||
const jan4 = new Date(year, 0, 4)
|
||||
const jan4DayOfWeek = jan4.getDay() || 7 // 일요일=7
|
||||
|
||||
// 1주차의 월요일
|
||||
const week1Monday = new Date(jan4)
|
||||
week1Monday.setDate(jan4.getDate() - jan4DayOfWeek + 1)
|
||||
|
||||
// 요청된 주차의 월요일
|
||||
const monday = new Date(week1Monday)
|
||||
monday.setDate(week1Monday.getDate() + (week - 1) * 7)
|
||||
|
||||
// 일요일
|
||||
const sunday = new Date(monday)
|
||||
sunday.setDate(monday.getDate() + 6)
|
||||
|
||||
return {
|
||||
monday: formatDate(monday),
|
||||
sunday: formatDate(sunday)
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(date: Date): string {
|
||||
const y = date.getFullYear()
|
||||
const m = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const d = String(date.getDate()).padStart(2, '0')
|
||||
return `${y}-${m}-${d}`
|
||||
}
|
||||
|
||||
@@ -71,6 +71,12 @@ export default defineEventHandler(async (event) => {
|
||||
params.push(q.year)
|
||||
}
|
||||
|
||||
// 주차 필터 (단일)
|
||||
if (q.week) {
|
||||
conditions.push(`r.report_week = $${paramIndex++}`)
|
||||
params.push(q.week)
|
||||
}
|
||||
|
||||
// 주차 범위 필터
|
||||
if (q.weekFrom) {
|
||||
conditions.push(`r.report_week >= $${paramIndex++}`)
|
||||
|
||||
@@ -50,9 +50,29 @@ export function useWeekCalc() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 이번 주 정보
|
||||
* 이번 주 정보 (보고서 기준)
|
||||
* - 금~일: 현재 주차
|
||||
* - 월~목: 이전 주차
|
||||
*/
|
||||
function getCurrentWeekInfo(): WeekInfo {
|
||||
const today = new Date()
|
||||
const dayOfWeek = today.getDay() // 0=일, 1=월, ..., 5=금, 6=토
|
||||
|
||||
// 월~목 (1~4)이면 이전 주차 기준
|
||||
if (dayOfWeek >= 1 && dayOfWeek <= 4) {
|
||||
const lastWeek = new Date(today)
|
||||
lastWeek.setDate(today.getDate() - 7)
|
||||
return getWeekInfo(lastWeek)
|
||||
}
|
||||
|
||||
// 금~일 (5, 6, 0)이면 현재 주차 기준
|
||||
return getWeekInfo(today)
|
||||
}
|
||||
|
||||
/**
|
||||
* 실제 이번 주 정보 (달력 기준, 항상 현재 주차)
|
||||
*/
|
||||
function getActualCurrentWeekInfo(): WeekInfo {
|
||||
return getWeekInfo(new Date())
|
||||
}
|
||||
|
||||
@@ -110,6 +130,7 @@ export function useWeekCalc() {
|
||||
return {
|
||||
getWeekInfo,
|
||||
getCurrentWeekInfo,
|
||||
getActualCurrentWeekInfo,
|
||||
getLastWeekInfo,
|
||||
formatDate,
|
||||
parseWeekString,
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<th style="width: 150px">소속사</th>
|
||||
<th style="width: 120px">직급</th>
|
||||
<th style="width: 100px">상태</th>
|
||||
<th style="width: 80px">상세</th>
|
||||
<th style="width: 120px">관리</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -69,10 +69,18 @@
|
||||
<td>
|
||||
<NuxtLink
|
||||
:to="`/employee/${emp.employeeId}`"
|
||||
class="btn btn-sm btn-outline-primary"
|
||||
class="btn btn-sm btn-outline-primary me-1"
|
||||
title="상세보기"
|
||||
>
|
||||
<i class="bi bi-eye"></i>
|
||||
</NuxtLink>
|
||||
<button
|
||||
class="btn btn-sm btn-outline-danger"
|
||||
@click.stop="confirmDelete(emp)"
|
||||
title="삭제"
|
||||
>
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!isLoading && filteredEmployees.length === 0">
|
||||
@@ -153,6 +161,37 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-backdrop fade show" v-if="showCreateModal"></div>
|
||||
|
||||
<!-- 삭제 확인 모달 -->
|
||||
<div class="modal fade" :class="{ show: showDeleteModal }" :style="{ display: showDeleteModal ? 'block' : 'none' }">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title text-danger">
|
||||
<i class="bi bi-exclamation-triangle me-2"></i>직원 삭제
|
||||
</h5>
|
||||
<button type="button" class="btn-close" @click="showDeleteModal = false"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>
|
||||
<strong>{{ deleteTarget?.employeeName }}</strong> ({{ deleteTarget?.employeeEmail }}) 님을 삭제하시겠습니까?
|
||||
</p>
|
||||
<div class="alert alert-warning small">
|
||||
<i class="bi bi-info-circle me-1"></i>
|
||||
주간보고가 있는 경우 비활성화 처리됩니다.
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" @click="showDeleteModal = false">취소</button>
|
||||
<button type="button" class="btn btn-danger" @click="deleteEmployee" :disabled="isDeleting">
|
||||
<span v-if="isDeleting" class="spinner-border spinner-border-sm me-1"></span>
|
||||
<i v-else class="bi bi-trash me-1"></i>삭제
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-backdrop fade show" v-if="showDeleteModal"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -164,7 +203,10 @@ const employees = ref<any[]>([])
|
||||
const searchKeyword = ref('')
|
||||
const filterStatus = ref('')
|
||||
const showCreateModal = ref(false)
|
||||
const showDeleteModal = ref(false)
|
||||
const deleteTarget = ref<any>(null)
|
||||
const isLoading = ref(true)
|
||||
const isDeleting = ref(false)
|
||||
|
||||
const newEmployee = ref({
|
||||
employeeName: '',
|
||||
@@ -243,6 +285,32 @@ async function createEmployee() {
|
||||
alert(e.data?.message || e.message || '등록에 실패했습니다.')
|
||||
}
|
||||
}
|
||||
|
||||
function confirmDelete(emp: any) {
|
||||
deleteTarget.value = emp
|
||||
showDeleteModal.value = true
|
||||
}
|
||||
|
||||
async function deleteEmployee() {
|
||||
if (!deleteTarget.value) return
|
||||
|
||||
isDeleting.value = true
|
||||
try {
|
||||
const res = await $fetch<{ success: boolean; action: string; message: string }>(
|
||||
`/api/employee/${deleteTarget.value.employeeId}/delete`,
|
||||
{ method: 'DELETE' }
|
||||
)
|
||||
|
||||
alert(res.message)
|
||||
showDeleteModal.value = false
|
||||
deleteTarget.value = null
|
||||
await loadEmployees()
|
||||
} catch (e: any) {
|
||||
alert(e.data?.message || e.message || '삭제에 실패했습니다.')
|
||||
} finally {
|
||||
isDeleting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -3,77 +3,90 @@
|
||||
<AppHeader />
|
||||
|
||||
<div class="container-fluid py-4">
|
||||
<!-- 헤더 -->
|
||||
<div class="row mb-4">
|
||||
<div class="col">
|
||||
<h4>
|
||||
<i class="bi bi-speedometer2 me-2"></i>대시보드
|
||||
</h4>
|
||||
<p class="text-muted mb-0">
|
||||
{{ currentWeek.weekString }} ({{ currentWeek.startDateStr }} ~ {{ currentWeek.endDateStr }})
|
||||
</p>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h4 class="mb-1">
|
||||
<i class="bi bi-speedometer2 me-2"></i>리소스 현황
|
||||
</h4>
|
||||
<p class="text-muted mb-0">
|
||||
{{ currentWeek.year }}년 {{ currentWeek.week }}주차
|
||||
({{ currentWeek.startDateStr }} ~ {{ currentWeek.endDateStr }})
|
||||
</p>
|
||||
</div>
|
||||
<div class="d-flex gap-2">
|
||||
<select class="form-select form-select-sm" style="width: 100px;" v-model="selectedYear" @change="loadStats">
|
||||
<option v-for="y in yearOptions" :key="y" :value="y">{{ y }}년</option>
|
||||
</select>
|
||||
<select class="form-select form-select-sm" style="width: 90px;" v-model="selectedWeek" @change="loadStats">
|
||||
<option v-for="w in weekOptions" :key="w" :value="w">{{ w }}주</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 요약 카드 -->
|
||||
<div class="row g-4 mb-4">
|
||||
<div class="col-md-3">
|
||||
<div class="card border-primary h-100">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>
|
||||
<h6 class="text-muted">이번 주 내 보고서</h6>
|
||||
<h2 class="mb-0">{{ stats.myReportsThisWeek }}</h2>
|
||||
</div>
|
||||
<div class="text-primary">
|
||||
<i class="bi bi-journal-text display-4"></i>
|
||||
</div>
|
||||
<div class="row g-3 mb-4">
|
||||
<div class="col-md-2">
|
||||
<div class="card h-100 border-primary">
|
||||
<div class="card-body text-center">
|
||||
<div class="text-muted small">제출현황</div>
|
||||
<h3 class="mb-0">
|
||||
<span class="text-primary">{{ stats.summary.submittedCount }}</span>
|
||||
<span class="text-muted">/{{ stats.summary.activeEmployees }}</span>
|
||||
</h3>
|
||||
<div class="small" :class="stats.summary.notSubmittedCount > 0 ? 'text-danger' : 'text-success'">
|
||||
{{ stats.summary.notSubmittedCount > 0 ? `${stats.summary.notSubmittedCount}명 미제출` : '전원 제출' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="card border-success h-100">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>
|
||||
<h6 class="text-muted">참여 프로젝트</h6>
|
||||
<h2 class="mb-0">{{ stats.myProjects }}</h2>
|
||||
</div>
|
||||
<div class="text-success">
|
||||
<i class="bi bi-folder-check display-4"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="card h-100 border-success">
|
||||
<div class="card-body text-center">
|
||||
<div class="text-muted small">금주 실적</div>
|
||||
<h3 class="mb-0 text-success">{{ formatHours(stats.summary.totalWorkHours) }}</h3>
|
||||
<div class="small text-muted">{{ stats.summary.projectCount }}개 프로젝트</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="card border-info h-100">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>
|
||||
<h6 class="text-muted">이번 주 취합</h6>
|
||||
<h2 class="mb-0">{{ stats.summariesThisWeek }}</h2>
|
||||
</div>
|
||||
<div class="text-info">
|
||||
<i class="bi bi-collection display-4"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="card h-100 border-info">
|
||||
<div class="card-body text-center">
|
||||
<div class="text-muted small">차주 계획</div>
|
||||
<h3 class="mb-0 text-info">{{ formatHours(stats.summary.totalPlanHours) }}</h3>
|
||||
<div class="small text-muted">예정 업무량</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="card border-warning h-100">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="card h-100">
|
||||
<div class="card-body text-center">
|
||||
<div class="text-muted small">평균 업무시간</div>
|
||||
<h3 class="mb-0">{{ formatHours(avgWorkHours) }}</h3>
|
||||
<div class="small text-muted">인당 (40h 기준)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="card h-100">
|
||||
<div class="card-body text-center">
|
||||
<div class="text-muted small">리소스 현황</div>
|
||||
<div class="d-flex justify-content-around mt-1">
|
||||
<div>
|
||||
<h6 class="text-muted">전체 프로젝트</h6>
|
||||
<h2 class="mb-0">{{ stats.totalProjects }}</h2>
|
||||
<span class="badge bg-success">{{ resourceStatus.available }}</span>
|
||||
<div class="small text-muted">여유</div>
|
||||
</div>
|
||||
<div class="text-warning">
|
||||
<i class="bi bi-briefcase display-4"></i>
|
||||
<div>
|
||||
<span class="badge bg-primary">{{ resourceStatus.normal }}</span>
|
||||
<div class="small text-muted">정상</div>
|
||||
</div>
|
||||
<div>
|
||||
<span class="badge bg-danger">{{ resourceStatus.overload }}</span>
|
||||
<div class="small text-muted">과부하</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -82,85 +95,142 @@
|
||||
</div>
|
||||
|
||||
<div class="row g-4">
|
||||
<!-- 내 주간보고 -->
|
||||
<!-- 인원별 현황 -->
|
||||
<div class="col-lg-6">
|
||||
<div class="card h-100">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span><i class="bi bi-journal-text me-2"></i>내 주간보고</span>
|
||||
<NuxtLink to="/report/weekly/write" class="btn btn-primary btn-sm">
|
||||
<i class="bi bi-plus"></i> 작성
|
||||
</NuxtLink>
|
||||
<span><i class="bi bi-people me-2"></i>인원별 업무 현황</span>
|
||||
<div class="small text-muted">
|
||||
<span class="badge bg-success me-1">~32h</span>
|
||||
<span class="badge bg-primary me-1">32~48h</span>
|
||||
<span class="badge bg-danger">48h~</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<div class="list-group list-group-flush" v-if="myReports.length > 0">
|
||||
<NuxtLink
|
||||
v-for="report in myReports"
|
||||
:key="report.reportId"
|
||||
:to="`/report/weekly/${report.reportId}`"
|
||||
class="list-group-item list-group-item-action"
|
||||
>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<strong>{{ report.projectName }}</strong>
|
||||
<br />
|
||||
<small class="text-muted">
|
||||
{{ report.reportYear }}-W{{ String(report.reportWeek).padStart(2, '0') }}
|
||||
</small>
|
||||
</div>
|
||||
<span :class="getStatusBadgeClass(report.reportStatus)">
|
||||
{{ getStatusText(report.reportStatus) }}
|
||||
</span>
|
||||
</div>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
<div class="p-4 text-center text-muted" v-else>
|
||||
<i class="bi bi-inbox display-4"></i>
|
||||
<p class="mt-2 mb-0">작성한 보고서가 없습니다.</p>
|
||||
</div>
|
||||
<div class="card-body p-0" style="max-height: 500px; overflow-y: auto;">
|
||||
<table class="table table-sm table-hover mb-0">
|
||||
<thead class="table-light sticky-top">
|
||||
<tr>
|
||||
<th>이름</th>
|
||||
<th class="text-center" style="width: 80px;">금주실적</th>
|
||||
<th class="text-center" style="width: 80px;">차주계획</th>
|
||||
<th class="text-center" style="width: 60px;">상태</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="emp in stats.employees" :key="emp.employeeId"
|
||||
:class="{ 'table-light text-muted': !emp.isSubmitted }">
|
||||
<td>
|
||||
<div class="d-flex align-items-center">
|
||||
<span :class="getWorkloadBadge(emp.workHours)" class="me-2" style="width: 8px; height: 8px; border-radius: 50%; display: inline-block;"></span>
|
||||
<div>
|
||||
<div>{{ emp.employeeName }}</div>
|
||||
<div class="small text-muted">{{ emp.company || '' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<span v-if="emp.isSubmitted" :class="getWorkloadClass(emp.workHours)">
|
||||
{{ emp.workHours }}h
|
||||
</span>
|
||||
<span v-else class="text-muted">-</span>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<span v-if="emp.isSubmitted" :class="getWorkloadClass(emp.planHours)">
|
||||
{{ emp.planHours }}h
|
||||
</span>
|
||||
<span v-else class="text-muted">-</span>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<span v-if="emp.isSubmitted" class="badge bg-success">제출</span>
|
||||
<span v-else class="badge bg-secondary">미제출</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="stats.employees.length === 0">
|
||||
<td colspan="4" class="text-center py-4 text-muted">데이터가 없습니다.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 최근 취합 보고서 -->
|
||||
<!-- 프로젝트별 현황 -->
|
||||
<div class="col-lg-6">
|
||||
<div class="card h-100">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span><i class="bi bi-collection me-2"></i>최근 취합 보고서</span>
|
||||
<NuxtLink to="/report/summary" class="btn btn-outline-secondary btn-sm">
|
||||
전체보기
|
||||
</NuxtLink>
|
||||
<div class="card-header">
|
||||
<i class="bi bi-briefcase me-2"></i>프로젝트별 투입 현황
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<div class="list-group list-group-flush" v-if="summaries.length > 0">
|
||||
<NuxtLink
|
||||
v-for="summary in summaries"
|
||||
:key="summary.summaryId"
|
||||
:to="`/report/summary/${summary.summaryId}`"
|
||||
class="list-group-item list-group-item-action"
|
||||
>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<strong>{{ summary.projectName }}</strong>
|
||||
<br />
|
||||
<small class="text-muted">
|
||||
{{ summary.reportYear }}-W{{ String(summary.reportWeek).padStart(2, '0') }}
|
||||
· {{ summary.memberCount }}명 참여
|
||||
</small>
|
||||
</div>
|
||||
<span :class="getSummaryBadgeClass(summary.summaryStatus)">
|
||||
{{ getSummaryStatusText(summary.summaryStatus) }}
|
||||
</span>
|
||||
</div>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
<div class="p-4 text-center text-muted" v-else>
|
||||
<i class="bi bi-inbox display-4"></i>
|
||||
<p class="mt-2 mb-0">취합된 보고서가 없습니다.</p>
|
||||
</div>
|
||||
<div class="card-body p-0" style="max-height: 500px; overflow-y: auto;">
|
||||
<table class="table table-sm table-hover mb-0">
|
||||
<thead class="table-light sticky-top">
|
||||
<tr>
|
||||
<th>프로젝트</th>
|
||||
<th class="text-center" style="width: 60px;">인원</th>
|
||||
<th class="text-center" style="width: 80px;">금주실적</th>
|
||||
<th class="text-center" style="width: 80px;">차주계획</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="proj in stats.projects" :key="proj.projectId">
|
||||
<td>
|
||||
<div>{{ proj.projectName }}</div>
|
||||
<div class="small text-muted">{{ proj.members.slice(0, 3).join(', ') }}{{ proj.members.length > 3 ? ` 외 ${proj.members.length - 3}명` : '' }}</div>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<span class="badge bg-primary">{{ proj.memberCount }}명</span>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<strong>{{ proj.workHours }}h</strong>
|
||||
</td>
|
||||
<td class="text-center text-info">
|
||||
{{ proj.planHours }}h
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="stats.projects.length === 0">
|
||||
<td colspan="4" class="text-center py-4 text-muted">데이터가 없습니다.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 하단: 빠른 링크 -->
|
||||
<div class="row g-3 mt-3">
|
||||
<div class="col-md-3">
|
||||
<NuxtLink to="/report/weekly/write" class="card text-decoration-none h-100">
|
||||
<div class="card-body text-center py-3">
|
||||
<i class="bi bi-plus-circle display-6 text-primary"></i>
|
||||
<div class="mt-2">주간보고 작성</div>
|
||||
</div>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<NuxtLink to="/report/weekly" class="card text-decoration-none h-100">
|
||||
<div class="card-body text-center py-3">
|
||||
<i class="bi bi-journal-text display-6 text-success"></i>
|
||||
<div class="mt-2">주간보고 목록</div>
|
||||
</div>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
<div class="col-md-3" v-if="isAdmin">
|
||||
<NuxtLink to="/report/summary" class="card text-decoration-none h-100">
|
||||
<div class="card-body text-center py-3">
|
||||
<i class="bi bi-collection display-6 text-info"></i>
|
||||
<div class="mt-2">취합 보고서</div>
|
||||
</div>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<NuxtLink to="/project" class="card text-decoration-none h-100">
|
||||
<div class="card-body text-center py-3">
|
||||
<i class="bi bi-briefcase display-6 text-warning"></i>
|
||||
<div class="mt-2">프로젝트 관리</div>
|
||||
</div>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -171,18 +241,46 @@ const { getCurrentWeekInfo } = useWeekCalc()
|
||||
const router = useRouter()
|
||||
|
||||
const currentWeek = getCurrentWeekInfo()
|
||||
const isAdmin = ref(false)
|
||||
|
||||
const stats = ref({
|
||||
myReportsThisWeek: 0,
|
||||
myProjects: 0,
|
||||
summariesThisWeek: 0,
|
||||
totalProjects: 0
|
||||
const currentYear = new Date().getFullYear()
|
||||
const yearOptions = [currentYear, currentYear - 1]
|
||||
const weekOptions = Array.from({ length: 53 }, (_, i) => i + 1)
|
||||
|
||||
const selectedYear = ref(currentWeek.year)
|
||||
const selectedWeek = ref(currentWeek.week)
|
||||
|
||||
const stats = ref<any>({
|
||||
summary: {
|
||||
activeEmployees: 0,
|
||||
submittedCount: 0,
|
||||
notSubmittedCount: 0,
|
||||
totalWorkHours: 0,
|
||||
totalPlanHours: 0,
|
||||
projectCount: 0
|
||||
},
|
||||
employees: [],
|
||||
projects: []
|
||||
})
|
||||
|
||||
const myReports = ref<any[]>([])
|
||||
const summaries = ref<any[]>([])
|
||||
// 평균 업무시간 (제출자 기준)
|
||||
const avgWorkHours = computed(() => {
|
||||
const submitted = stats.value.employees.filter((e: any) => e.isSubmitted)
|
||||
if (submitted.length === 0) return 0
|
||||
const total = submitted.reduce((sum: number, e: any) => sum + e.workHours, 0)
|
||||
return Math.round(total / submitted.length)
|
||||
})
|
||||
|
||||
// 리소스 현황 (여유/정상/과부하)
|
||||
const resourceStatus = computed(() => {
|
||||
const submitted = stats.value.employees.filter((e: any) => e.isSubmitted)
|
||||
return {
|
||||
available: submitted.filter((e: any) => e.workHours < 32).length,
|
||||
normal: submitted.filter((e: any) => e.workHours >= 32 && e.workHours <= 48).length,
|
||||
overload: submitted.filter((e: any) => e.workHours > 48).length
|
||||
}
|
||||
})
|
||||
|
||||
// 로그인 체크 및 데이터 로드
|
||||
onMounted(async () => {
|
||||
const user = await fetchCurrentUser()
|
||||
if (!user) {
|
||||
@@ -190,77 +288,40 @@ onMounted(async () => {
|
||||
return
|
||||
}
|
||||
|
||||
await loadDashboardData()
|
||||
isAdmin.value = user.employeeEmail === 'coziny@gmail.com'
|
||||
await loadStats()
|
||||
})
|
||||
|
||||
async function loadDashboardData() {
|
||||
async function loadStats() {
|
||||
try {
|
||||
// 내 주간보고 목록
|
||||
const reportsRes = await $fetch<{ reports: any[] }>('/api/report/weekly/list', {
|
||||
query: { limit: 5 }
|
||||
const res = await $fetch<any>('/api/dashboard/stats', {
|
||||
query: { year: selectedYear.value, week: selectedWeek.value }
|
||||
})
|
||||
myReports.value = reportsRes.reports || []
|
||||
|
||||
// 취합 보고서 목록
|
||||
const summariesRes = await $fetch<{ summaries: any[] }>('/api/report/summary/list', {
|
||||
query: { limit: 5 }
|
||||
})
|
||||
summaries.value = summariesRes.summaries || []
|
||||
|
||||
// 내 프로젝트
|
||||
const projectsRes = await $fetch<{ projects: any[] }>('/api/project/my-projects')
|
||||
|
||||
// 전체 프로젝트
|
||||
const allProjectsRes = await $fetch<{ projects: any[] }>('/api/project/list')
|
||||
|
||||
// 통계 계산
|
||||
stats.value = {
|
||||
myReportsThisWeek: myReports.value.filter(r =>
|
||||
r.reportYear === currentWeek.year && r.reportWeek === currentWeek.week
|
||||
).length,
|
||||
myProjects: projectsRes.projects?.length || 0,
|
||||
summariesThisWeek: summaries.value.filter(s =>
|
||||
s.reportYear === currentWeek.year && s.reportWeek === currentWeek.week
|
||||
).length,
|
||||
totalProjects: allProjectsRes.projects?.length || 0
|
||||
}
|
||||
stats.value = res
|
||||
} catch (e) {
|
||||
console.error('Dashboard data load error:', e)
|
||||
console.error('Dashboard stats error:', e)
|
||||
}
|
||||
}
|
||||
|
||||
function getStatusBadgeClass(status: string) {
|
||||
const classes: Record<string, string> = {
|
||||
'DRAFT': 'badge bg-secondary',
|
||||
'SUBMITTED': 'badge bg-success',
|
||||
'AGGREGATED': 'badge bg-info'
|
||||
}
|
||||
return classes[status] || 'badge bg-secondary'
|
||||
function formatHours(hours: number): string {
|
||||
if (!hours || hours <= 0) return '0h'
|
||||
const days = Math.floor(hours / 8)
|
||||
const remain = hours % 8
|
||||
if (days === 0) return `${hours}h`
|
||||
if (remain === 0) return `${days}일`
|
||||
return `${days}일 ${remain}h`
|
||||
}
|
||||
|
||||
function getStatusText(status: string) {
|
||||
const texts: Record<string, string> = {
|
||||
'DRAFT': '작성중',
|
||||
'SUBMITTED': '제출완료',
|
||||
'AGGREGATED': '취합완료'
|
||||
}
|
||||
return texts[status] || status
|
||||
function getWorkloadBadge(hours: number): string {
|
||||
if (hours < 32) return 'bg-success'
|
||||
if (hours <= 48) return 'bg-primary'
|
||||
return 'bg-danger'
|
||||
}
|
||||
|
||||
function getSummaryBadgeClass(status: string) {
|
||||
const classes: Record<string, string> = {
|
||||
'AGGREGATED': 'badge bg-info',
|
||||
'REVIEWED': 'badge bg-success'
|
||||
}
|
||||
return classes[status] || 'badge bg-secondary'
|
||||
}
|
||||
|
||||
function getSummaryStatusText(status: string) {
|
||||
const texts: Record<string, string> = {
|
||||
'AGGREGATED': '취합완료',
|
||||
'REVIEWED': '검토완료'
|
||||
}
|
||||
return texts[status] || status
|
||||
function getWorkloadClass(hours: number): string {
|
||||
if (hours < 32) return 'text-success'
|
||||
if (hours <= 48) return ''
|
||||
return 'text-danger fw-bold'
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -272,4 +333,12 @@ function getSummaryStatusText(status: string) {
|
||||
background-color: #f8f9fa;
|
||||
font-weight: 500;
|
||||
}
|
||||
.sticky-top {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
}
|
||||
a.card:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -45,10 +45,10 @@
|
||||
<tbody>
|
||||
<tr v-for="week in weeklyList" :key="week.reportWeek">
|
||||
<td>
|
||||
<strong class="text-primary">{{ week.reportWeek }}주차</strong>
|
||||
<strong>{{ week.reportYear }}년 {{ week.reportWeek }}주</strong>
|
||||
</td>
|
||||
<td>
|
||||
<small>{{ formatDateRange(week.weekStartDate, week.weekEndDate) }}</small>
|
||||
<td class="small">
|
||||
{{ formatDate(week.weekStartDate) }} ~ {{ formatDate(week.weekEndDate) }}
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge bg-secondary me-1" v-for="p in week.projects.slice(0, 3)" :key="p">
|
||||
@@ -311,6 +311,11 @@ function getWeekDateRange(year: number, week: number): string {
|
||||
return `${fmt(monday)}~${fmt(sunday)}`
|
||||
}
|
||||
|
||||
function formatDate(dateStr: string) {
|
||||
if (!dateStr) return ''
|
||||
return dateStr.split('T')[0].replace(/-/g, '.')
|
||||
}
|
||||
|
||||
function formatDateRange(start: string, end: string) {
|
||||
if (!start || !end) return '-'
|
||||
const s = new Date(start)
|
||||
|
||||
@@ -40,44 +40,20 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- 프로젝트 -->
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small text-muted">프로젝트</label>
|
||||
<select class="form-select form-select-sm" v-model="filters.projectId" @change="loadReports">
|
||||
<option value="">전체</option>
|
||||
<option v-for="proj in projects" :key="proj.projectId" :value="proj.projectId">
|
||||
{{ proj.projectName }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- 연도 -->
|
||||
<div class="col-md-1">
|
||||
<label class="form-label small text-muted">연도</label>
|
||||
<select class="form-select form-select-sm" v-model="filters.year" @change="loadReports">
|
||||
<option value="">전체</option>
|
||||
<option v-for="y in yearOptions" :key="y" :value="y">{{ y }}년</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- 기간 -->
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small text-muted">시작일</label>
|
||||
<input type="date" class="form-control form-control-sm" v-model="filters.startDate" @change="loadReports">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small text-muted">종료일</label>
|
||||
<input type="date" class="form-control form-control-sm" v-model="filters.endDate" @change="loadReports">
|
||||
</div>
|
||||
|
||||
<!-- 상태 -->
|
||||
<!-- 주차 -->
|
||||
<div class="col-md-1">
|
||||
<label class="form-label small text-muted">상태</label>
|
||||
<select class="form-select form-select-sm" v-model="filters.status" @change="loadReports">
|
||||
<label class="form-label small text-muted">주차</label>
|
||||
<select class="form-select form-select-sm" v-model="filters.week" @change="loadReports">
|
||||
<option value="">전체</option>
|
||||
<option value="DRAFT">작성중</option>
|
||||
<option value="SUBMITTED">제출완료</option>
|
||||
<option value="AGGREGATED">취합완료</option>
|
||||
<option v-for="w in weekOptions" :key="w" :value="w">{{ w }}주</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -161,21 +137,18 @@ const router = useRouter()
|
||||
|
||||
const reports = ref<any[]>([])
|
||||
const employees = ref<any[]>([])
|
||||
const projects = ref<any[]>([])
|
||||
const isLoading = ref(true)
|
||||
const isAdmin = ref(false)
|
||||
|
||||
const currentYear = new Date().getFullYear()
|
||||
const yearOptions = [currentYear, currentYear - 1, currentYear - 2]
|
||||
const weekOptions = Array.from({ length: 53 }, (_, i) => i + 1)
|
||||
|
||||
const filters = ref({
|
||||
viewAll: false,
|
||||
authorId: '',
|
||||
projectId: '',
|
||||
year: '',
|
||||
startDate: '',
|
||||
endDate: '',
|
||||
status: ''
|
||||
year: currentYear,
|
||||
week: ''
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -216,20 +189,11 @@ async function loadReports() {
|
||||
|
||||
if (filters.value.viewAll) params.append('viewAll', 'true')
|
||||
if (filters.value.authorId) params.append('authorId', filters.value.authorId)
|
||||
if (filters.value.projectId) params.append('projectId', filters.value.projectId)
|
||||
if (filters.value.year) params.append('year', filters.value.year)
|
||||
if (filters.value.startDate) params.append('startDate', filters.value.startDate)
|
||||
if (filters.value.endDate) params.append('endDate', filters.value.endDate)
|
||||
if (filters.value.status) params.append('status', filters.value.status)
|
||||
if (filters.value.year) params.append('year', String(filters.value.year))
|
||||
if (filters.value.week) params.append('week', String(filters.value.week))
|
||||
|
||||
const res = await $fetch<any>(`/api/report/weekly/list?${params.toString()}`)
|
||||
reports.value = res.reports || []
|
||||
|
||||
// 일반 사용자도 프로젝트 필터 사용할 수 있도록
|
||||
if (!isAdmin.value && projects.value.length === 0) {
|
||||
const projRes = await $fetch<any>('/api/project/list')
|
||||
projects.value = projRes.projects || []
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
@@ -241,11 +205,8 @@ function resetFilters() {
|
||||
filters.value = {
|
||||
viewAll: false,
|
||||
authorId: '',
|
||||
projectId: '',
|
||||
year: '',
|
||||
startDate: '',
|
||||
endDate: '',
|
||||
status: ''
|
||||
year: currentYear,
|
||||
week: ''
|
||||
}
|
||||
loadReports()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user