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

@@ -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 }
})