feat: 다수 기능 개선 - 순찰, 출근, 작업분석, 모바일 UI 등
- 순찰/점검 기능 개선 (zone-detail 페이지 추가) - 출근/근태 시스템 개선 (연차 조회, 근무현황) - 작업분석 대분류 그룹화 및 마이그레이션 스크립트 - 모바일 네비게이션 UI 추가 - NAS 배포 도구 및 문서 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* 프로젝트 분석 서비스
|
||||
*
|
||||
* 기간별 프로젝트, 작업자, 작업 유형 분석 데이터 처리
|
||||
*
|
||||
* @author TK-FB-Project
|
||||
* @since 2025-12-11
|
||||
*/
|
||||
|
||||
const analysisModel = require('../models/analysisModel');
|
||||
const { ValidationError, DatabaseError } = require('../utils/errors');
|
||||
const logger = require('../utils/logger');
|
||||
|
||||
/**
|
||||
* 기간별 프로젝트 분석 데이터 조회
|
||||
*
|
||||
* @param {string} startDate - 시작일 (YYYY-MM-DD)
|
||||
* @param {string} endDate - 종료일 (YYYY-MM-DD)
|
||||
* @returns {Promise<object>} 가공된 분석 데이터
|
||||
*/
|
||||
const getAnalysisService = async (startDate, endDate) => {
|
||||
// 필수 필드 검증
|
||||
if (!startDate || !endDate) {
|
||||
throw new ValidationError('시작일과 종료일이 필요합니다', {
|
||||
required: ['startDate', 'endDate'],
|
||||
received: { startDate, endDate }
|
||||
});
|
||||
}
|
||||
|
||||
logger.info('분석 데이터 조회 요청', { startDate, endDate });
|
||||
|
||||
try {
|
||||
const analysisData = await analysisModel.getAnalysis(startDate, endDate);
|
||||
|
||||
const { summary, byProject, byWorker, byTask, details } = analysisData;
|
||||
const totalHours = summary.totalHours || 0;
|
||||
|
||||
// 비율(percentage) 계산 헬퍼 함수
|
||||
const addPercentage = (item) => ({
|
||||
...item,
|
||||
hours: parseFloat(item.hours.toFixed(1)),
|
||||
percentage: totalHours > 0 ? parseFloat((item.hours / totalHours * 100).toFixed(1)) : 0
|
||||
});
|
||||
|
||||
const result = {
|
||||
summary: {
|
||||
...summary,
|
||||
totalHours: parseFloat(totalHours.toFixed(1))
|
||||
},
|
||||
byProject: byProject.map(addPercentage),
|
||||
byWorker: byWorker.map(addPercentage),
|
||||
byTask: byTask.map(addPercentage),
|
||||
details: details.map(d => ({
|
||||
...d,
|
||||
work_hours: parseFloat(d.work_hours.toFixed(1))
|
||||
}))
|
||||
};
|
||||
|
||||
logger.info('분석 데이터 조회 성공', {
|
||||
startDate,
|
||||
endDate,
|
||||
totalHours: result.summary.totalHours,
|
||||
projectCount: result.byProject.length,
|
||||
workerCount: result.byWorker.length,
|
||||
detailCount: result.details.length
|
||||
});
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
logger.error('분석 데이터 조회 실패', {
|
||||
startDate,
|
||||
endDate,
|
||||
error: error.message
|
||||
});
|
||||
throw new DatabaseError('분석 데이터 조회 중 오류가 발생했습니다');
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getAnalysisService
|
||||
};
|
||||
Reference in New Issue
Block a user