기능구현중
This commit is contained in:
116
server/api/report/summary/[id]/detail.get.ts
Normal file
116
server/api/report/summary/[id]/detail.get.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import { queryOne, query } from '../../../../utils/db'
|
||||
|
||||
/**
|
||||
* 취합 보고서 상세 (개별 보고서 포함)
|
||||
* GET /api/report/summary/[id]/detail
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const summaryId = getRouterParam(event, 'id')
|
||||
|
||||
// 취합 보고서 조회
|
||||
const summary = await queryOne<any>(`
|
||||
SELECT s.*, p.project_name, p.project_code,
|
||||
e.employee_name as reviewer_name
|
||||
FROM wr_aggregated_report_summary s
|
||||
JOIN wr_project_info p ON s.project_id = p.project_id
|
||||
LEFT JOIN wr_employee_info e ON s.reviewer_id = e.employee_id
|
||||
WHERE s.summary_id = $1
|
||||
`, [summaryId])
|
||||
|
||||
if (!summary) {
|
||||
throw createError({ statusCode: 404, message: '취합 보고서를 찾을 수 없습니다.' })
|
||||
}
|
||||
|
||||
// 개별 보고서 목록 (Task 기반)
|
||||
const reports = await query(`
|
||||
SELECT DISTINCT
|
||||
r.report_id,
|
||||
r.author_id,
|
||||
e.employee_name as author_name,
|
||||
e.employee_position,
|
||||
r.issue_description,
|
||||
r.vacation_description,
|
||||
r.remark_description,
|
||||
r.report_status,
|
||||
r.submitted_at
|
||||
FROM wr_weekly_report r
|
||||
JOIN wr_weekly_report_task t ON r.report_id = t.report_id
|
||||
JOIN wr_employee_info e ON r.author_id = e.employee_id
|
||||
WHERE t.project_id = $1 AND r.report_year = $2 AND r.report_week = $3
|
||||
ORDER BY e.employee_name
|
||||
`, [summary.project_id, summary.report_year, summary.report_week])
|
||||
|
||||
// 각 보고서의 Task 조회
|
||||
const reportIds = reports.map((r: any) => r.report_id)
|
||||
const tasks = reportIds.length > 0 ? await query(`
|
||||
SELECT
|
||||
t.report_id,
|
||||
t.task_type,
|
||||
t.task_description,
|
||||
t.task_hours,
|
||||
t.is_completed
|
||||
FROM wr_weekly_report_task t
|
||||
WHERE t.report_id = ANY($1) AND t.project_id = $2
|
||||
ORDER BY t.report_id, t.task_type
|
||||
`, [reportIds, summary.project_id]) : []
|
||||
|
||||
// Task를 보고서별로 그룹핑
|
||||
const tasksByReport = new Map<number, { work: any[], plan: any[] }>()
|
||||
for (const task of tasks) {
|
||||
if (!tasksByReport.has(task.report_id)) {
|
||||
tasksByReport.set(task.report_id, { work: [], plan: [] })
|
||||
}
|
||||
const group = tasksByReport.get(task.report_id)!
|
||||
if (task.task_type === 'WORK') {
|
||||
group.work.push({
|
||||
description: task.task_description,
|
||||
hours: parseFloat(task.task_hours) || 0,
|
||||
isCompleted: task.is_completed
|
||||
})
|
||||
} else {
|
||||
group.plan.push({
|
||||
description: task.task_description,
|
||||
hours: parseFloat(task.task_hours) || 0
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
summary: {
|
||||
summaryId: summary.summary_id,
|
||||
projectId: summary.project_id,
|
||||
projectName: summary.project_name,
|
||||
projectCode: summary.project_code,
|
||||
reportYear: summary.report_year,
|
||||
reportWeek: summary.report_week,
|
||||
weekStartDate: summary.week_start_date,
|
||||
weekEndDate: summary.week_end_date,
|
||||
memberCount: summary.member_count,
|
||||
totalWorkHours: summary.total_work_hours,
|
||||
reviewerId: summary.reviewer_id,
|
||||
reviewerName: summary.reviewer_name,
|
||||
reviewerComment: summary.reviewer_comment,
|
||||
reviewedAt: summary.reviewed_at,
|
||||
summaryStatus: summary.summary_status,
|
||||
aggregatedAt: summary.aggregated_at,
|
||||
aiSummary: summary.ai_summary,
|
||||
aiSummaryAt: summary.ai_summary_at
|
||||
},
|
||||
reports: reports.map((r: any) => {
|
||||
const taskGroup = tasksByReport.get(r.report_id) || { work: [], plan: [] }
|
||||
return {
|
||||
reportId: r.report_id,
|
||||
authorId: r.author_id,
|
||||
authorName: r.author_name,
|
||||
authorPosition: r.employee_position,
|
||||
workTasks: taskGroup.work,
|
||||
planTasks: taskGroup.plan,
|
||||
issueDescription: r.issue_description,
|
||||
vacationDescription: r.vacation_description,
|
||||
remarkDescription: r.remark_description,
|
||||
reportStatus: r.report_status,
|
||||
submittedAt: r.submitted_at
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
37
server/api/report/summary/[id]/review.put.ts
Normal file
37
server/api/report/summary/[id]/review.put.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { execute, queryOne } from '../../../../utils/db'
|
||||
import { requireAuth } from '../../../../utils/session'
|
||||
|
||||
interface ReviewBody {
|
||||
reviewerComment?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* PM 검토/코멘트 작성
|
||||
* PUT /api/report/summary/[id]/review
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const userId = await requireAuth(event)
|
||||
|
||||
const summaryId = getRouterParam(event, 'id')
|
||||
const body = await readBody<ReviewBody>(event)
|
||||
|
||||
const summary = await queryOne<any>(`
|
||||
SELECT * FROM wr_aggregated_report_summary WHERE summary_id = $1
|
||||
`, [summaryId])
|
||||
|
||||
if (!summary) {
|
||||
throw createError({ statusCode: 404, message: '취합 보고서를 찾을 수 없습니다.' })
|
||||
}
|
||||
|
||||
await execute(`
|
||||
UPDATE wr_aggregated_report_summary SET
|
||||
reviewer_id = $1,
|
||||
reviewer_comment = $2,
|
||||
reviewed_at = NOW(),
|
||||
summary_status = 'REVIEWED',
|
||||
updated_at = NOW()
|
||||
WHERE summary_id = $3
|
||||
`, [userId, body.reviewerComment || null, summaryId])
|
||||
|
||||
return { success: true }
|
||||
})
|
||||
Reference in New Issue
Block a user