1ㅊㅏ완료

This commit is contained in:
2026-01-05 02:00:13 +09:00
parent 1bbad6efa7
commit 185161db16
30 changed files with 4331 additions and 837 deletions

View File

@@ -3,10 +3,15 @@ import { callOpenAI, buildParseReportPrompt } from '../../utils/openai'
const ADMIN_EMAIL = 'coziny@gmail.com'
interface ParsedTask {
description: string
hours: number
}
interface ParsedProject {
projectName: string
workDescription: string | null
planDescription: string | null
workTasks: ParsedTask[]
planTasks: ParsedTask[]
}
interface ParsedReport {
@@ -62,6 +67,28 @@ export default defineEventHandler(async (event) => {
throw createError({ statusCode: 500, message: 'AI 응답 파싱 실패' })
}
// 주차 정보 기본값 설정 (AI가 파싱 못한 경우)
const now = new Date()
if (!parsed.reportYear) {
parsed.reportYear = now.getFullYear()
}
if (!parsed.reportWeek) {
// ISO 주차 계산
const startOfYear = new Date(now.getFullYear(), 0, 1)
const days = Math.floor((now.getTime() - startOfYear.getTime()) / (24 * 60 * 60 * 1000))
parsed.reportWeek = Math.ceil((days + startOfYear.getDay() + 1) / 7)
}
if (!parsed.weekStartDate || !parsed.weekEndDate) {
// 현재 주의 월요일~일요일 계산
const day = now.getDay()
const monday = new Date(now)
monday.setDate(now.getDate() - (day === 0 ? 6 : day - 1))
const sunday = new Date(monday)
sunday.setDate(monday.getDate() + 6)
parsed.weekStartDate = monday.toISOString().split('T')[0]
parsed.weekEndDate = sunday.toISOString().split('T')[0]
}
// 기존 직원 목록 조회
const employees = await query<any>(`
SELECT employee_id, employee_name, employee_email
@@ -76,7 +103,7 @@ export default defineEventHandler(async (event) => {
WHERE project_status != 'COMPLETED'
`)
// 직원 매칭
// 직원 및 프로젝트 매칭
const matchedReports = parsed.reports.map(report => {
// 이메일로 정확 매칭 시도
let matchedEmployee = null
@@ -114,6 +141,7 @@ export default defineEventHandler(async (event) => {
matchedEmployeeName: matchedEmployee?.employee_name || null,
matchedEmployeeEmail: matchedEmployee?.employee_email || null,
isEmployeeMatched: !!matchedEmployee,
isNewEmployee: !matchedEmployee && !!report.employeeEmail,
projects: matchedProjects
}
})
@@ -127,7 +155,6 @@ export default defineEventHandler(async (event) => {
weekEndDate: parsed.weekEndDate,
reports: matchedReports
},
// 선택용 목록
employees: employees.map((e: any) => ({
employeeId: e.employee_id,
employeeName: e.employee_name,