This commit is contained in:
2026-01-04 20:58:47 +09:00
parent a87c11597a
commit 0660ed3973
37 changed files with 1723 additions and 885 deletions

View File

@@ -21,12 +21,24 @@ export default defineEventHandler(async (event) => {
throw createError({ statusCode: 404, message: '취합 보고서를 찾을 수 없습니다.' })
}
// 개별 보고서 목록
// 개별 보고서 목록 (새 구조: 마스터 + 프로젝트별 실적 조인)
const reports = await query(`
SELECT r.*, e.employee_name as author_name, e.employee_position
FROM wr_weekly_report_detail r
SELECT
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,
rp.work_description,
rp.plan_description
FROM wr_weekly_report r
JOIN wr_weekly_report_project rp ON r.report_id = rp.report_id
JOIN wr_employee_info e ON r.author_id = e.employee_id
WHERE r.project_id = $1 AND r.report_year = $2 AND r.report_week = $3
WHERE rp.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])
@@ -41,7 +53,6 @@ export default defineEventHandler(async (event) => {
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,
@@ -56,8 +67,8 @@ export default defineEventHandler(async (event) => {
workDescription: r.work_description,
planDescription: r.plan_description,
issueDescription: r.issue_description,
vacationDescription: r.vacation_description,
remarkDescription: r.remark_description,
workHours: r.work_hours,
reportStatus: r.report_status,
submittedAt: r.submitted_at
}))

View File

@@ -0,0 +1,108 @@
import { query, queryOne, insertReturning, execute } from '../../../utils/db'
import { getClientIp } from '../../../utils/ip'
import { getCurrentUserEmail } from '../../../utils/user'
interface AggregateBody {
projectId: number
reportYear: number
reportWeek: number
}
/**
* 수동 취합 실행
* POST /api/report/summary/aggregate
*/
export default defineEventHandler(async (event) => {
const userId = getCookie(event, 'user_id')
if (!userId) {
throw createError({ statusCode: 401, message: '로그인이 필요합니다.' })
}
const body = await readBody<AggregateBody>(event)
const clientIp = getClientIp(event)
const userEmail = await getCurrentUserEmail(event)
if (!body.projectId || !body.reportYear || !body.reportWeek) {
throw createError({ statusCode: 400, message: '프로젝트, 연도, 주차를 선택해주세요.' })
}
// 해당 프로젝트/주차의 제출된 보고서 조회 (새 구조)
const reports = await query<any>(`
SELECT
r.report_id,
r.author_id,
r.week_start_date,
r.week_end_date,
rp.detail_id
FROM wr_weekly_report r
JOIN wr_weekly_report_project rp ON r.report_id = rp.report_id
WHERE rp.project_id = $1
AND r.report_year = $2
AND r.report_week = $3
AND r.report_status IN ('SUBMITTED', 'AGGREGATED')
ORDER BY r.report_id
`, [body.projectId, body.reportYear, body.reportWeek])
if (reports.length === 0) {
throw createError({ statusCode: 400, message: '취합할 보고서가 없습니다.' })
}
const reportIds = [...new Set(reports.map(r => r.report_id))]
const weekStartDate = reports[0].week_start_date
const weekEndDate = reports[0].week_end_date
// 기존 취합 보고서 확인
const existing = await queryOne<any>(`
SELECT summary_id FROM wr_aggregated_report_summary
WHERE project_id = $1 AND report_year = $2 AND report_week = $3
`, [body.projectId, body.reportYear, body.reportWeek])
let summaryId: number
if (existing) {
// 기존 취합 업데이트
await execute(`
UPDATE wr_aggregated_report_summary
SET report_ids = $1,
member_count = $2,
aggregated_at = NOW(),
updated_at = NOW(),
updated_ip = $3,
updated_email = $4
WHERE summary_id = $5
`, [reportIds, reportIds.length, clientIp, userEmail, existing.summary_id])
summaryId = existing.summary_id
} else {
// 새 취합 생성
const newSummary = await insertReturning<any>(`
INSERT INTO wr_aggregated_report_summary (
project_id, report_year, report_week, week_start_date, week_end_date,
report_ids, member_count,
created_ip, created_email, updated_ip, updated_email
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $8, $9)
RETURNING summary_id
`, [
body.projectId, body.reportYear, body.reportWeek,
weekStartDate, weekEndDate,
reportIds, reportIds.length,
clientIp, userEmail
])
summaryId = newSummary.summary_id
}
// 개별 보고서 상태 업데이트
await execute(`
UPDATE wr_weekly_report
SET report_status = 'AGGREGATED',
updated_at = NOW(),
updated_ip = $1,
updated_email = $2
WHERE report_id = ANY($3)
`, [clientIp, userEmail, reportIds])
return {
success: true,
summaryId,
memberCount: reportIds.length
}
})

View File

@@ -1,4 +1,4 @@
import { queryOne } from '../../../../utils/db'
import { query, queryOne } from '../../../../utils/db'
/**
* 주간보고 상세 조회
@@ -12,10 +12,13 @@ export default defineEventHandler(async (event) => {
const reportId = getRouterParam(event, 'id')
// 마스터 조회
const report = await queryOne<any>(`
SELECT r.*, p.project_name, p.project_code, e.employee_name as author_name
FROM wr_weekly_report_detail r
JOIN wr_project_info p ON r.project_id = p.project_id
SELECT
r.*,
e.employee_name as author_name,
e.employee_email as author_email
FROM wr_weekly_report r
JOIN wr_employee_info e ON r.author_id = e.employee_id
WHERE r.report_id = $1
`, [reportId])
@@ -24,25 +27,46 @@ export default defineEventHandler(async (event) => {
throw createError({ statusCode: 404, message: '보고서를 찾을 수 없습니다.' })
}
// 프로젝트별 실적 조회
const projects = await query<any>(`
SELECT
rp.detail_id,
rp.project_id,
p.project_code,
p.project_name,
rp.work_description,
rp.plan_description
FROM wr_weekly_report_project rp
JOIN wr_project_info p ON rp.project_id = p.project_id
WHERE rp.report_id = $1
ORDER BY rp.detail_id
`, [reportId])
return {
reportId: report.report_id,
projectId: report.project_id,
projectName: report.project_name,
projectCode: report.project_code,
authorId: report.author_id,
authorName: report.author_name,
reportYear: report.report_year,
reportWeek: report.report_week,
weekStartDate: report.week_start_date,
weekEndDate: report.week_end_date,
workDescription: report.work_description,
planDescription: report.plan_description,
issueDescription: report.issue_description,
remarkDescription: report.remark_description,
workHours: report.work_hours,
reportStatus: report.report_status,
submittedAt: report.submitted_at,
createdAt: report.created_at,
updatedAt: report.updated_at
report: {
reportId: report.report_id,
authorId: report.author_id,
authorName: report.author_name,
authorEmail: report.author_email,
reportYear: report.report_year,
reportWeek: report.report_week,
weekStartDate: report.week_start_date,
weekEndDate: report.week_end_date,
issueDescription: report.issue_description,
vacationDescription: report.vacation_description,
remarkDescription: report.remark_description,
reportStatus: report.report_status,
submittedAt: report.submitted_at,
createdAt: report.created_at,
updatedAt: report.updated_at
},
projects: projects.map((p: any) => ({
detailId: p.detail_id,
projectId: p.project_id,
projectCode: p.project_code,
projectName: p.project_name,
workDescription: p.work_description,
planDescription: p.plan_description
}))
}
})

View File

@@ -1,4 +1,6 @@
import { execute, queryOne } from '../../../../utils/db'
import { getClientIp } from '../../../../utils/ip'
import { getCurrentUserEmail } from '../../../../utils/user'
/**
* 주간보고 제출
@@ -11,10 +13,12 @@ export default defineEventHandler(async (event) => {
}
const reportId = getRouterParam(event, 'id')
const clientIp = getClientIp(event)
const userEmail = await getCurrentUserEmail(event)
// 보고서 조회 및 권한 확인
const report = await queryOne<any>(`
SELECT * FROM wr_weekly_report_detail WHERE report_id = $1
SELECT * FROM wr_weekly_report WHERE report_id = $1
`, [reportId])
if (!report) {
@@ -25,13 +29,19 @@ export default defineEventHandler(async (event) => {
throw createError({ statusCode: 403, message: '본인의 보고서만 제출할 수 있습니다.' })
}
if (report.report_status !== 'DRAFT') {
throw createError({ statusCode: 400, message: '이미 제출된 보고서입니다.' })
}
await execute(`
UPDATE wr_weekly_report_detail SET
UPDATE wr_weekly_report SET
report_status = 'SUBMITTED',
submitted_at = NOW(),
updated_at = NOW()
WHERE report_id = $1
`, [reportId])
updated_at = NOW(),
updated_ip = $1,
updated_email = $2
WHERE report_id = $3
`, [clientIp, userEmail, reportId])
return { success: true }
})

View File

@@ -1,11 +1,18 @@
import { execute, queryOne } from '../../../../utils/db'
import { execute, query, queryOne } from '../../../../utils/db'
import { getClientIp } from '../../../../utils/ip'
import { getCurrentUserEmail } from '../../../../utils/user'
interface UpdateReportBody {
interface ProjectItem {
projectId: number
workDescription?: string
planDescription?: string
}
interface UpdateReportBody {
projects?: ProjectItem[]
issueDescription?: string
vacationDescription?: string
remarkDescription?: string
workHours?: number
}
/**
@@ -20,10 +27,12 @@ export default defineEventHandler(async (event) => {
const reportId = getRouterParam(event, 'id')
const body = await readBody<UpdateReportBody>(event)
const clientIp = getClientIp(event)
const userEmail = await getCurrentUserEmail(event)
// 보고서 조회 및 권한 확인
const report = await queryOne<any>(`
SELECT * FROM wr_weekly_report_detail WHERE report_id = $1
SELECT * FROM wr_weekly_report WHERE report_id = $1
`, [reportId])
if (!report) {
@@ -34,23 +43,50 @@ export default defineEventHandler(async (event) => {
throw createError({ statusCode: 403, message: '본인의 보고서만 수정할 수 있습니다.' })
}
if (report.report_status === 'SUBMITTED' || report.report_status === 'AGGREGATED') {
throw createError({ statusCode: 400, message: '제출된 보고서는 수정할 수 없습니다.' })
}
// 마스터 업데이트
await execute(`
UPDATE wr_weekly_report_detail SET
work_description = $1,
plan_description = $2,
issue_description = $3,
remark_description = $4,
work_hours = $5,
updated_at = NOW()
UPDATE wr_weekly_report SET
issue_description = $1,
vacation_description = $2,
remark_description = $3,
updated_at = NOW(),
updated_ip = $4,
updated_email = $5
WHERE report_id = $6
`, [
body.workDescription ?? report.work_description,
body.planDescription ?? report.plan_description,
body.issueDescription ?? report.issue_description,
body.vacationDescription ?? report.vacation_description,
body.remarkDescription ?? report.remark_description,
body.workHours ?? report.work_hours,
clientIp,
userEmail,
reportId
])
// 프로젝트별 실적 업데이트
if (body.projects && body.projects.length > 0) {
// 기존 삭제 후 재등록
await execute(`DELETE FROM wr_weekly_report_project WHERE report_id = $1`, [reportId])
for (const proj of body.projects) {
await execute(`
INSERT INTO wr_weekly_report_project (
report_id, project_id, work_description, plan_description,
created_ip, created_email, updated_ip, updated_email
) VALUES ($1, $2, $3, $4, $5, $6, $5, $6)
`, [
reportId,
proj.projectId,
proj.workDescription || null,
proj.planDescription || null,
clientIp,
userEmail
])
}
}
return { success: true }
})

View File

@@ -1,15 +1,21 @@
import { insertReturning, queryOne } from '../../../utils/db'
import { query, insertReturning, execute } from '../../../utils/db'
import { getWeekInfo } from '../../../utils/week-calc'
import { getClientIp } from '../../../utils/ip'
import { getCurrentUserEmail } from '../../../utils/user'
interface CreateReportBody {
interface ProjectItem {
projectId: number
reportYear?: number
reportWeek?: number
workDescription?: string
planDescription?: string
}
interface CreateReportBody {
reportYear?: number
reportWeek?: number
projects: ProjectItem[]
issueDescription?: string
vacationDescription?: string
remarkDescription?: string
workHours?: number
}
/**
@@ -23,9 +29,11 @@ export default defineEventHandler(async (event) => {
}
const body = await readBody<CreateReportBody>(event)
const clientIp = getClientIp(event)
const userEmail = await getCurrentUserEmail(event)
if (!body.projectId) {
throw createError({ statusCode: 400, message: '프로젝트를 선택해주세요.' })
if (!body.projects || body.projects.length === 0) {
throw createError({ statusCode: 400, message: '최소 1개 이상의 프로젝트를 추가해주세요.' })
}
// 주차 정보 (기본값: 이번 주)
@@ -34,40 +42,57 @@ export default defineEventHandler(async (event) => {
const week = body.reportWeek || weekInfo.week
// 중복 체크
const existing = await queryOne(`
SELECT report_id FROM wr_weekly_report_detail
WHERE project_id = $1 AND author_id = $2 AND report_year = $3 AND report_week = $4
`, [body.projectId, parseInt(userId), year, week])
const existing = await query(`
SELECT report_id FROM wr_weekly_report
WHERE author_id = $1 AND report_year = $2 AND report_week = $3
`, [parseInt(userId), year, week])
if (existing) {
if (existing.length > 0) {
throw createError({ statusCode: 409, message: '이미 해당 주차 보고서가 존재합니다.' })
}
// 주차 날짜 계산
const dates = getWeekInfo(new Date(year, 0, 4 + (week - 1) * 7))
// 마스터 생성
const report = await insertReturning(`
INSERT INTO wr_weekly_report_detail (
project_id, author_id, report_year, report_week,
INSERT INTO wr_weekly_report (
author_id, report_year, report_week,
week_start_date, week_end_date,
work_description, plan_description, issue_description, remark_description,
work_hours, report_status
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, 'DRAFT')
issue_description, vacation_description, remark_description,
report_status, created_ip, created_email, updated_ip, updated_email
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 'DRAFT', $9, $10, $9, $10)
RETURNING *
`, [
body.projectId,
parseInt(userId),
year,
week,
dates.startDateStr,
dates.endDateStr,
body.workDescription || null,
body.planDescription || null,
body.issueDescription || null,
body.vacationDescription || null,
body.remarkDescription || null,
body.workHours || null
clientIp,
userEmail
])
// 프로젝트별 실적 저장
for (const proj of body.projects) {
await execute(`
INSERT INTO wr_weekly_report_project (
report_id, project_id, work_description, plan_description,
created_ip, created_email, updated_ip, updated_email
) VALUES ($1, $2, $3, $4, $5, $6, $5, $6)
`, [
report.report_id,
proj.projectId,
proj.workDescription || null,
proj.planDescription || null,
clientIp,
userEmail
])
}
return {
success: true,
reportId: report.report_id

View File

@@ -1,7 +1,7 @@
import { query } from '../../../utils/db'
/**
* 주간보고 목록
* 주간보고 목록 조회
* GET /api/report/weekly/list
*/
export default defineEventHandler(async (event) => {
@@ -11,50 +11,45 @@ export default defineEventHandler(async (event) => {
}
const queryParams = getQuery(event)
const year = queryParams.year ? parseInt(queryParams.year as string) : null
const projectId = queryParams.projectId ? parseInt(queryParams.projectId as string) : null
const limit = parseInt(queryParams.limit as string) || 20
let sql = `
SELECT r.*, p.project_name, p.project_code
FROM wr_weekly_report_detail r
JOIN wr_project_info p ON r.project_id = p.project_id
const reports = await query<any>(`
SELECT
r.report_id,
r.author_id,
e.employee_name as author_name,
r.report_year,
r.report_week,
r.week_start_date,
r.week_end_date,
r.issue_description,
r.vacation_description,
r.report_status,
r.submitted_at,
r.created_at,
(SELECT COUNT(*) FROM wr_weekly_report_project WHERE report_id = r.report_id) as project_count
FROM wr_weekly_report r
JOIN wr_employee_info e ON r.author_id = e.employee_id
WHERE r.author_id = $1
`
const params: any[] = [parseInt(userId)]
let paramIndex = 2
if (year) {
sql += ` AND r.report_year = $${paramIndex++}`
params.push(year)
}
if (projectId) {
sql += ` AND r.project_id = $${paramIndex++}`
params.push(projectId)
}
sql += ' ORDER BY r.report_year DESC, r.report_week DESC'
const reports = await query(sql, params)
ORDER BY r.report_year DESC, r.report_week DESC
LIMIT $2
`, [userId, limit])
return {
reports: reports.map((r: any) => ({
reportId: r.report_id,
projectId: r.project_id,
projectName: r.project_name,
projectCode: r.project_code,
authorId: r.author_id,
authorName: r.author_name,
reportYear: r.report_year,
reportWeek: r.report_week,
weekStartDate: r.week_start_date,
weekEndDate: r.week_end_date,
workDescription: r.work_description,
planDescription: r.plan_description,
issueDescription: r.issue_description,
remarkDescription: r.remark_description,
workHours: r.work_hours,
vacationDescription: r.vacation_description,
reportStatus: r.report_status,
submittedAt: r.submitted_at,
createdAt: r.created_at,
updatedAt: r.updated_at
projectCount: parseInt(r.project_count)
}))
}
})