refactor(backend): 작업 보고서 통계/요약 API 구조 개선
- dailyWorkReportController의 통계/요약 함수를 C-S-M 아키텍처에 맞게 리팩토링 - Model 계층의 콜백 기반 함수를 Promise 기반으로 전환 - API의 일관성 및 유지보수성 향상
This commit is contained in:
@@ -745,33 +745,26 @@ const removeByDateAndWorker = async (date, worker_id, deletedBy, callback) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* 20. 통계 조회
|
||||
* 20. 통계 조회 (Promise 기반)
|
||||
*/
|
||||
const getStatistics = async (start_date, end_date, callback) => {
|
||||
const getStatistics = async (start_date, end_date) => {
|
||||
try {
|
||||
const db = await getDb();
|
||||
|
||||
const sql = `
|
||||
const overallSql = `
|
||||
SELECT
|
||||
COUNT(*) as total_reports,
|
||||
SUM(work_hours) as total_hours,
|
||||
COUNT(DISTINCT worker_id) as unique_workers,
|
||||
COUNT(DISTINCT project_id) as unique_projects,
|
||||
SUM(CASE WHEN work_status_id = 2 THEN 1 ELSE 0 END) as error_count,
|
||||
AVG(work_hours) as avg_hours_per_entry,
|
||||
MIN(work_hours) as min_hours,
|
||||
MAX(work_hours) as max_hours
|
||||
COUNT(DISTINCT project_id) as unique_projects
|
||||
FROM daily_work_reports
|
||||
WHERE report_date BETWEEN ? AND ?
|
||||
`;
|
||||
|
||||
const [rows] = await db.query(sql, [start_date, end_date]);
|
||||
|
||||
// 추가 통계 - 날짜별 집계
|
||||
const [overallRows] = await db.query(overallSql, [start_date, end_date]);
|
||||
|
||||
const dailyStatsSql = `
|
||||
SELECT
|
||||
report_date,
|
||||
COUNT(*) as daily_reports,
|
||||
SUM(work_hours) as daily_hours,
|
||||
COUNT(DISTINCT worker_id) as daily_workers
|
||||
FROM daily_work_reports
|
||||
@@ -779,18 +772,15 @@ const getStatistics = async (start_date, end_date, callback) => {
|
||||
GROUP BY report_date
|
||||
ORDER BY report_date DESC
|
||||
`;
|
||||
|
||||
const [dailyStats] = await db.query(dailyStatsSql, [start_date, end_date]);
|
||||
|
||||
const result = {
|
||||
overall: rows[0],
|
||||
return {
|
||||
overall: overallRows[0],
|
||||
daily_breakdown: dailyStats
|
||||
};
|
||||
|
||||
callback(null, result);
|
||||
} catch (err) {
|
||||
console.error('통계 조회 오류:', err);
|
||||
callback(err);
|
||||
throw new Error('데이터베이스에서 통계 정보를 조회하는 중 오류가 발생했습니다.');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1002,43 +992,38 @@ const removeReportById = async (reportId, deletedByUserId) => {
|
||||
};
|
||||
|
||||
|
||||
// 모든 함수 내보내기 (기존 기능 + 누적 기능)
|
||||
// 모든 함수 내보내기 (Promise 기반 함수 위주로 재구성)
|
||||
module.exports = {
|
||||
// 📋 마스터 데이터
|
||||
// 새로 추가된 V2 함수 (Promise 기반)
|
||||
createReportEntries,
|
||||
getReportsWithOptions,
|
||||
updateReportById,
|
||||
removeReportById,
|
||||
|
||||
// Promise 기반으로 리팩토링된 함수
|
||||
getStatistics,
|
||||
getSummaryByDate,
|
||||
getSummaryByWorker,
|
||||
|
||||
// 아직 리팩토링되지 않았지만 필요한 기존 함수들...
|
||||
// (점진적으로 아래 함수들도 Promise 기반으로 전환해야 함)
|
||||
getAllWorkTypes,
|
||||
getAllWorkStatusTypes,
|
||||
getAllErrorTypes,
|
||||
|
||||
// 🔄 핵심 생성 함수 (누적 방식)
|
||||
createDailyReport, // 누적 추가 (덮어쓰기 없음)
|
||||
|
||||
// 📊 누적 관련 새로운 함수들
|
||||
getMyAccumulatedHours, // 개인 누적 현황
|
||||
getAccumulatedReportsByDate, // 날짜별 누적 현황
|
||||
getContributorsByDate, // 기여자별 요약
|
||||
removeSpecificEntry, // 개별 항목 삭제
|
||||
|
||||
// 📊 기존 조회 함수들 (모두 유지)
|
||||
createDailyReport,
|
||||
getMyAccumulatedHours,
|
||||
getAccumulatedReportsByDate,
|
||||
getContributorsByDate,
|
||||
removeSpecificEntry,
|
||||
getById,
|
||||
getByDate,
|
||||
getByDateAndCreator, // 날짜+작성자별 조회
|
||||
getByDateAndCreator,
|
||||
getByWorker,
|
||||
getByDateAndWorker,
|
||||
getByRange,
|
||||
searchWithDetails,
|
||||
getSummaryByDate,
|
||||
getSummaryByWorker,
|
||||
getMonthlySummary,
|
||||
|
||||
// ✏️ 수정/삭제 함수들 (기존 유지)
|
||||
updateById,
|
||||
removeById,
|
||||
removeByDateAndWorker,
|
||||
getStatistics,
|
||||
|
||||
// 새로 추가된 V2 함수
|
||||
createReportEntries,
|
||||
getReportsWithOptions,
|
||||
updateReportById,
|
||||
removeReportById
|
||||
};
|
||||
Reference in New Issue
Block a user