refactor: 미사용 의존성 제거 + deprecated API 수정 + 정리

- SSO/System2: 미사용 redis, bcrypt, multer 의존성 제거
- System2: dbPool.js shim 삭제, workIssueModel을 config/database 직접 참조로 변경
- System3: deprecated datetime.utcnow() → datetime.now(timezone.utc)
- System3: deprecated @app.on_event("startup") → lifespan 패턴
- System3: 중복 /users 라우트 제거, 불필요 파일 삭제
- health-check.sh: tkuser API/Web 체크 추가
- tkuser nginx: upstream 이름 수정 (tk-system2-api → system2-api)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-02-25 08:35:11 +09:00
parent faf365e0c6
commit 64e3c1227d
11 changed files with 20 additions and 815 deletions

View File

@@ -46,6 +46,8 @@ check_service "System 2 API" "http://localhost:30105/api/health" 30105
check_service "System 2 Web" "http://localhost:30180/" 30180
check_service "System 3 API" "http://localhost:30200/api/health" 30200
check_service "System 3 Web" "http://localhost:30280/" 30280
check_service "tkuser API" "http://localhost:30300/api/health" 30300
check_service "tkuser Web" "http://localhost:30380/" 30380
check_service "phpMyAdmin" "http://localhost:30880/" 30880
echo ""

View File

@@ -12,7 +12,6 @@
"cors": "^2.8.5",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.0",
"mysql2": "^3.14.1",
"redis": "^5.9.0"
"mysql2": "^3.14.1"
}
}

View File

@@ -1,11 +0,0 @@
/**
* 데이터베이스 풀 (호환성 레거시 파일)
*
* @deprecated 이 파일은 하위 호환성을 위해 유지됩니다.
* 새로운 코드에서는 './config/database'를 직접 import하세요.
*
* @author TK-FB-Project
* @since 2025-12-11
*/
module.exports = require('./config/database');

View File

@@ -3,7 +3,7 @@
* 부적합/안전 신고 관련 DB 쿼리
*/
const { getDb } = require('../dbPool');
const { getDb } = require('../config/database');
// ==================== 신고 카테고리 관리 ====================

View File

@@ -9,14 +9,11 @@
},
"dependencies": {
"async-retry": "^1.3.3",
"bcrypt": "^6.0.0",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.18.2",
"express-rate-limit": "^7.5.1",
"jsonwebtoken": "^9.0.0",
"multer": "^1.4.5-lts.1",
"mysql2": "^3.14.1",
"redis": "^5.9.0"
"mysql2": "^3.14.1"
}
}

View File

@@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
@@ -15,11 +16,20 @@ tables_to_create = [
]
Base.metadata.create_all(bind=engine, tables=tables_to_create)
# 앱 시작/종료 lifecycle
@asynccontextmanager
async def lifespan(app: FastAPI):
db = next(get_db())
create_admin_user(db)
db.close()
yield
# FastAPI 앱 생성
app = FastAPI(
title="M-Project API",
description="작업보고서 시스템 API",
version="1.0.0"
version="1.0.0",
lifespan=lifespan
)
# CORS 설정 (완전 개방 - CORS 문제 해결)
@@ -41,13 +51,6 @@ app.include_router(projects.router)
app.include_router(page_permissions.router)
app.include_router(management.router) # 관리함 라우터 추가
# 시작 시 관리자 계정 생성
@app.on_event("startup")
async def startup_event():
db = next(get_db())
create_admin_user(db)
db.close()
# 루트 엔드포인트
@app.get("/")
async def root():

View File

@@ -1,41 +0,0 @@
"""
데이터베이스 마이그레이션: 사진 필드 추가
- 신고 사진 3, 4, 5 추가
- 완료 사진 2, 3, 4, 5 추가
"""
from sqlalchemy import create_engine, text
import os
# 데이터베이스 URL
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://postgres:postgres@db:5432/issue_tracker")
def run_migration():
engine = create_engine(DATABASE_URL)
with engine.connect() as conn:
print("마이그레이션 시작...")
try:
# 신고 사진 필드 추가
print("신고 사진 필드 추가 중...")
conn.execute(text("ALTER TABLE issues ADD COLUMN IF NOT EXISTS photo_path3 VARCHAR"))
conn.execute(text("ALTER TABLE issues ADD COLUMN IF NOT EXISTS photo_path4 VARCHAR"))
conn.execute(text("ALTER TABLE issues ADD COLUMN IF NOT EXISTS photo_path5 VARCHAR"))
# 완료 사진 필드 추가
print("완료 사진 필드 추가 중...")
conn.execute(text("ALTER TABLE issues ADD COLUMN IF NOT EXISTS completion_photo_path2 VARCHAR(500)"))
conn.execute(text("ALTER TABLE issues ADD COLUMN IF NOT EXISTS completion_photo_path3 VARCHAR(500)"))
conn.execute(text("ALTER TABLE issues ADD COLUMN IF NOT EXISTS completion_photo_path4 VARCHAR(500)"))
conn.execute(text("ALTER TABLE issues ADD COLUMN IF NOT EXISTS completion_photo_path5 VARCHAR(500)"))
conn.commit()
print("✅ 마이그레이션 완료!")
except Exception as e:
conn.rollback()
print(f"❌ 마이그레이션 실패: {e}")
raise
if __name__ == "__main__":
run_migration()

View File

@@ -118,16 +118,6 @@ async def create_user(
db.refresh(db_user)
return db_user
@router.get("/users", response_model=List[schemas.User])
async def read_users(
skip: int = 0,
limit: int = 100,
current_admin: User = Depends(get_current_admin),
db: Session = Depends(get_db)
):
users = db.query(User).offset(skip).limit(limit).all()
return users
@router.put("/users/{user_id}", response_model=schemas.User)
async def update_user(
user_id: int,

View File

@@ -1,734 +0,0 @@
from fastapi import APIRouter, Depends, HTTPException
from fastapi.responses import StreamingResponse
from sqlalchemy.orm import Session
from sqlalchemy import func, and_, or_
from datetime import datetime, date
from typing import List
import io
import re
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
from openpyxl.utils import get_column_letter
from openpyxl.drawing.image import Image as XLImage
import os
from database.database import get_db
from database.models import Issue, DailyWork, IssueStatus, IssueCategory, User, UserRole, Project, ReviewStatus
from database import schemas
from routers.auth import get_current_user
router = APIRouter(prefix="/api/reports", tags=["reports"])
@router.post("/summary", response_model=schemas.ReportSummary)
async def generate_report_summary(
report_request: schemas.ReportRequest,
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""보고서 요약 생성"""
start_date = report_request.start_date
end_date = report_request.end_date
# 일일 공수 합계
daily_works = db.query(DailyWork).filter(
DailyWork.date >= start_date.date(),
DailyWork.date <= end_date.date()
).all()
total_hours = sum(w.total_hours for w in daily_works)
# 이슈 통계
issues_query = db.query(Issue).filter(
Issue.report_date >= start_date,
Issue.report_date <= end_date
)
# 일반 사용자는 자신의 이슈만
if current_user.role == UserRole.user:
issues_query = issues_query.filter(Issue.reporter_id == current_user.id)
issues = issues_query.all()
# 카테고리별 통계
category_stats = schemas.CategoryStats()
completed_issues = 0
total_resolution_time = 0
resolved_count = 0
for issue in issues:
# 카테고리별 카운트
if issue.category == IssueCategory.material_missing:
category_stats.material_missing += 1
elif issue.category == IssueCategory.design_error:
category_stats.dimension_defect += 1
elif issue.category == IssueCategory.incoming_defect:
category_stats.incoming_defect += 1
# 완료된 이슈
if issue.status == IssueStatus.complete:
completed_issues += 1
if issue.work_hours > 0:
total_resolution_time += issue.work_hours
resolved_count += 1
# 평균 해결 시간
average_resolution_time = total_resolution_time / resolved_count if resolved_count > 0 else 0
return schemas.ReportSummary(
start_date=start_date,
end_date=end_date,
total_hours=total_hours,
total_issues=len(issues),
category_stats=category_stats,
completed_issues=completed_issues,
average_resolution_time=average_resolution_time
)
@router.get("/issues")
async def get_report_issues(
start_date: datetime,
end_date: datetime,
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""보고서용 이슈 상세 목록"""
query = db.query(Issue).filter(
Issue.report_date >= start_date,
Issue.report_date <= end_date
)
# 일반 사용자는 자신의 이슈만
if current_user.role == UserRole.user:
query = query.filter(Issue.reporter_id == current_user.id)
issues = query.order_by(Issue.report_date.desc()).all()
return [{
"id": issue.id,
"photo_path": issue.photo_path,
"category": issue.category,
"description": issue.description,
"status": issue.status,
"reporter_name": issue.reporter.full_name or issue.reporter.username,
"report_date": issue.report_date,
"work_hours": issue.work_hours,
"detail_notes": issue.detail_notes
} for issue in issues]
@router.get("/daily-works")
async def get_report_daily_works(
start_date: datetime,
end_date: datetime,
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""보고서용 일일 공수 목록"""
works = db.query(DailyWork).filter(
DailyWork.date >= start_date.date(),
DailyWork.date <= end_date.date()
).order_by(DailyWork.date).all()
return [{
"date": work.date,
"worker_count": work.worker_count,
"regular_hours": work.regular_hours,
"overtime_workers": work.overtime_workers,
"overtime_hours": work.overtime_hours,
"overtime_total": work.overtime_total,
"total_hours": work.total_hours
} for work in works]
@router.get("/daily-preview")
async def preview_daily_report(
project_id: int,
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""일일보고서 미리보기 - 추출될 항목 목록"""
# 권한 확인
if current_user.role != UserRole.admin:
raise HTTPException(status_code=403, detail="품질팀만 접근 가능합니다")
# 프로젝트 확인
project = db.query(Project).filter(Project.id == project_id).first()
if not project:
raise HTTPException(status_code=404, detail="프로젝트를 찾을 수 없습니다")
# 추출될 항목 조회 (진행 중 + 미추출 완료 항목)
issues_query = db.query(Issue).filter(
Issue.project_id == project_id,
or_(
Issue.review_status == ReviewStatus.in_progress,
and_(
Issue.review_status == ReviewStatus.completed,
Issue.last_exported_at == None
)
)
)
issues = issues_query.all()
# 정렬: 지연 -> 진행중 -> 완료됨 순으로, 같은 상태 내에서는 신고일 최신순
issues = sorted(issues, key=lambda x: (get_issue_priority(x), -x.report_date.timestamp() if x.report_date else 0))
# 통계 계산
stats = calculate_project_stats(issues)
# 이슈 리스트를 schema로 변환
issues_data = [schemas.Issue.from_orm(issue) for issue in issues]
return {
"project": schemas.Project.from_orm(project),
"stats": stats,
"issues": issues_data,
"total_issues": len(issues)
}
@router.post("/daily-export")
async def export_daily_report(
request: schemas.DailyReportRequest,
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""품질팀용 일일보고서 엑셀 내보내기"""
# 권한 확인 (품질팀만 접근 가능)
if current_user.role != UserRole.admin:
raise HTTPException(status_code=403, detail="품질팀만 접근 가능합니다")
# 프로젝트 확인
project = db.query(Project).filter(Project.id == request.project_id).first()
if not project:
raise HTTPException(status_code=404, detail="프로젝트를 찾을 수 없습니다")
# 관리함 데이터 조회
# 1. 진행 중인 항목 (모두 포함)
in_progress_issues = db.query(Issue).filter(
Issue.project_id == request.project_id,
Issue.review_status == ReviewStatus.in_progress
).all()
# 2. 완료된 항목 (한번도 추출 안된 항목만)
completed_issues = db.query(Issue).filter(
Issue.project_id == request.project_id,
Issue.review_status == ReviewStatus.completed,
Issue.last_exported_at == None
).all()
# 진행중 항목 정렬: 지연 -> 진행중 순으로, 같은 상태 내에서는 신고일 최신순
in_progress_issues = sorted(in_progress_issues, key=lambda x: (get_issue_priority(x), -x.report_date.timestamp() if x.report_date else 0))
# 완료 항목 정렬: 등록번호(project_sequence_no 또는 id) 순
completed_issues = sorted(completed_issues, key=lambda x: x.project_sequence_no or x.id)
# 전체 이슈 (통계 계산용)
issues = in_progress_issues + completed_issues
# 통계 계산
stats = calculate_project_stats(issues)
# 엑셀 파일 생성
wb = Workbook()
# 스타일 정의 (공통)
header_font = Font(bold=True, color="FFFFFF")
header_fill = PatternFill(start_color="4472C4", end_color="4472C4", fill_type="solid")
stats_font = Font(bold=True, size=12)
stats_fill = PatternFill(start_color="E7E6E6", end_color="E7E6E6", fill_type="solid")
border = Border(
left=Side(style='thin'),
right=Side(style='thin'),
top=Side(style='thin'),
bottom=Side(style='thin')
)
center_alignment = Alignment(horizontal='center', vertical='center')
card_header_font = Font(bold=True, color="FFFFFF", size=11)
label_font = Font(bold=True, size=10)
label_fill = PatternFill(start_color="E7E6E6", end_color="E7E6E6", fill_type="solid")
content_font = Font(size=10)
thick_border = Border(
left=Side(style='medium'),
right=Side(style='medium'),
top=Side(style='medium'),
bottom=Side(style='medium')
)
# 두 개의 시트를 생성하고 각각 데이터 입력
sheets_data = [
(wb.active, in_progress_issues, "진행 중"),
(wb.create_sheet(title="완료됨"), completed_issues, "완료됨")
]
sheets_data[0][0].title = "진행 중"
for ws, sheet_issues, sheet_title in sheets_data:
# 제목 및 기본 정보
ws.merge_cells('A1:L1')
ws['A1'] = f"{project.project_name} - {sheet_title}"
ws['A1'].font = Font(bold=True, size=16)
ws['A1'].alignment = center_alignment
ws.merge_cells('A2:L2')
ws['A2'] = f"생성일: {datetime.now().strftime('%Y년 %m월 %d일')}"
ws['A2'].alignment = center_alignment
# 프로젝트 통계 (4행부터)
ws.merge_cells('A4:L4')
ws['A4'] = "프로젝트 현황"
ws['A4'].font = stats_font
ws['A4'].fill = stats_fill
ws['A4'].alignment = center_alignment
# 통계 데이터
stats_row = 5
ws[f'A{stats_row}'] = "총 신고 수량"
ws[f'B{stats_row}'] = stats.total_count
ws[f'D{stats_row}'] = "관리처리 현황"
ws[f'E{stats_row}'] = stats.management_count
ws[f'G{stats_row}'] = "완료 현황"
ws[f'H{stats_row}'] = stats.completed_count
ws[f'J{stats_row}'] = "지연 중"
ws[f'K{stats_row}'] = stats.delayed_count
# 통계 스타일 적용
for col in ['A', 'D', 'G', 'J']:
ws[f'{col}{stats_row}'].font = Font(bold=True)
ws[f'{col}{stats_row}'].fill = PatternFill(start_color="FFF2CC", end_color="FFF2CC", fill_type="solid")
# 카드 형태로 데이터 입력 (7행부터)
current_row = 7
for idx, issue in enumerate(sheet_issues, 1):
card_start_row = current_row
# 상태별 헤더 색상 설정
header_color = get_issue_status_header_color(issue)
card_header_fill = PatternFill(start_color=header_color, end_color=header_color, fill_type="solid")
# 카드 헤더 (No, 상태, 신고일) - L열까지 확장
ws.merge_cells(f'A{current_row}:C{current_row}')
ws[f'A{current_row}'] = f"No. {issue.project_sequence_no or issue.id}"
ws[f'A{current_row}'].font = card_header_font
ws[f'A{current_row}'].fill = card_header_fill
ws[f'A{current_row}'].alignment = center_alignment
ws.merge_cells(f'D{current_row}:G{current_row}')
ws[f'D{current_row}'] = f"상태: {get_issue_status_text(issue)}"
ws[f'D{current_row}'].font = card_header_font
ws[f'D{current_row}'].fill = card_header_fill
ws[f'D{current_row}'].alignment = center_alignment
ws.merge_cells(f'H{current_row}:L{current_row}')
ws[f'H{current_row}'] = f"신고일: {issue.report_date.strftime('%Y-%m-%d') if issue.report_date else '-'}"
ws[f'H{current_row}'].font = card_header_font
ws[f'H{current_row}'].fill = card_header_fill
ws[f'H{current_row}'].alignment = center_alignment
current_row += 1
# 부적합명
ws[f'A{current_row}'] = "부적합명"
ws[f'A{current_row}'].font = label_font
ws[f'A{current_row}'].fill = label_fill
ws.merge_cells(f'B{current_row}:L{current_row}')
# final_description이 있으면 사용, 없으면 description 사용
issue_title = issue.final_description or issue.description or "내용 없음"
ws[f'B{current_row}'] = issue_title
ws[f'B{current_row}'].font = content_font
ws[f'B{current_row}'].alignment = Alignment(wrap_text=True, vertical='top')
current_row += 1
# 상세내용 (detail_notes가 실제 상세 설명)
if issue.detail_notes:
ws[f'A{current_row}'] = "상세내용"
ws[f'A{current_row}'].font = label_font
ws[f'A{current_row}'].fill = label_fill
ws.merge_cells(f'B{current_row}:L{current_row}')
ws[f'B{current_row}'] = issue.detail_notes
ws[f'B{current_row}'].font = content_font
ws[f'B{current_row}'].alignment = Alignment(wrap_text=True, vertical='top')
ws.row_dimensions[current_row].height = 50
current_row += 1
# 원인분류
ws[f'A{current_row}'] = "원인분류"
ws[f'A{current_row}'].font = label_font
ws[f'A{current_row}'].fill = label_fill
ws.merge_cells(f'B{current_row}:C{current_row}')
ws[f'B{current_row}'] = get_category_text(issue.final_category or issue.category)
ws[f'B{current_row}'].font = content_font
ws[f'D{current_row}'] = "원인부서"
ws[f'D{current_row}'].font = label_font
ws[f'D{current_row}'].fill = label_fill
ws.merge_cells(f'E{current_row}:F{current_row}')
ws[f'E{current_row}'] = get_department_text(issue.cause_department)
ws[f'E{current_row}'].font = content_font
ws[f'G{current_row}'] = "신고자"
ws[f'G{current_row}'].font = label_font
ws[f'G{current_row}'].fill = label_fill
ws.merge_cells(f'H{current_row}:L{current_row}')
ws[f'H{current_row}'] = issue.reporter.full_name or issue.reporter.username if issue.reporter else "-"
ws[f'H{current_row}'].font = content_font
current_row += 1
# 해결방안 (완료 반려 내용 및 댓글 제거)
ws[f'A{current_row}'] = "해결방안"
ws[f'A{current_row}'].font = label_font
ws[f'A{current_row}'].fill = label_fill
ws.merge_cells(f'B{current_row}:L{current_row}')
# management_comment에서 완료 반려 패턴과 댓글 제거
clean_solution = clean_management_comment_for_export(issue.management_comment)
ws[f'B{current_row}'] = clean_solution
ws[f'B{current_row}'].font = content_font
ws[f'B{current_row}'].alignment = Alignment(wrap_text=True, vertical='center') # 수직 가운데 정렬
ws.row_dimensions[current_row].height = 30
current_row += 1
# 담당정보
ws[f'A{current_row}'] = "담당부서"
ws[f'A{current_row}'].font = label_font
ws[f'A{current_row}'].fill = label_fill
ws.merge_cells(f'B{current_row}:C{current_row}')
ws[f'B{current_row}'] = get_department_text(issue.responsible_department)
ws[f'B{current_row}'].font = content_font
ws[f'D{current_row}'] = "담당자"
ws[f'D{current_row}'].font = label_font
ws[f'D{current_row}'].fill = label_fill
ws.merge_cells(f'E{current_row}:G{current_row}')
ws[f'E{current_row}'] = issue.responsible_person or ""
ws[f'E{current_row}'].font = content_font
ws[f'H{current_row}'] = "조치예상일"
ws[f'H{current_row}'].font = label_font
ws[f'H{current_row}'].fill = label_fill
ws.merge_cells(f'I{current_row}:L{current_row}')
ws[f'I{current_row}'] = issue.expected_completion_date.strftime('%Y-%m-%d') if issue.expected_completion_date else ""
ws[f'I{current_row}'].font = content_font
ws.row_dimensions[current_row].height = 20 # 기본 높이보다 20% 증가
current_row += 1
# === 신고 사진 영역 ===
has_report_photo = issue.photo_path or issue.photo_path2
if has_report_photo:
# 라벨 행 (A~L 전체 병합)
ws.merge_cells(f'A{current_row}:L{current_row}')
ws[f'A{current_row}'] = "신고 사진"
ws[f'A{current_row}'].font = label_font
ws[f'A{current_row}'].fill = PatternFill(start_color="FFF2CC", end_color="FFF2CC", fill_type="solid") # 노란색
ws[f'A{current_row}'].alignment = Alignment(horizontal='left', vertical='center')
ws.row_dimensions[current_row].height = 18
current_row += 1
# 사진 행 (별도 행으로 분리)
ws.merge_cells(f'A{current_row}:L{current_row}')
report_image_inserted = False
# 신고 사진 1
if issue.photo_path:
photo_path = issue.photo_path.replace('/uploads/', '/app/uploads/') if issue.photo_path.startswith('/uploads/') else issue.photo_path
if os.path.exists(photo_path):
try:
img = XLImage(photo_path)
img.width = min(img.width, 250)
img.height = min(img.height, 180)
ws.add_image(img, f'A{current_row}') # A열에 첫 번째 사진
report_image_inserted = True
except Exception as e:
print(f"이미지 삽입 실패 ({photo_path}): {e}")
# 신고 사진 2
if issue.photo_path2:
photo_path2 = issue.photo_path2.replace('/uploads/', '/app/uploads/') if issue.photo_path2.startswith('/uploads/') else issue.photo_path2
if os.path.exists(photo_path2):
try:
img = XLImage(photo_path2)
img.width = min(img.width, 250)
img.height = min(img.height, 180)
ws.add_image(img, f'G{current_row}') # G열에 두 번째 사진 (간격 확보)
report_image_inserted = True
except Exception as e:
print(f"이미지 삽입 실패 ({photo_path2}): {e}")
if report_image_inserted:
ws.row_dimensions[current_row].height = 150 # 사진 행 높이 조정 (200 -> 150)
else:
ws[f'A{current_row}'] = "사진 파일을 찾을 수 없음"
ws[f'A{current_row}'].font = Font(size=9, italic=True, color="999999")
ws.row_dimensions[current_row].height = 20
current_row += 1
# === 완료 관련 정보 (완료된 항목만) ===
if issue.review_status == ReviewStatus.completed:
# 완료 코멘트
if issue.completion_comment:
ws[f'A{current_row}'] = "완료 의견"
ws[f'A{current_row}'].font = label_font
ws[f'A{current_row}'].fill = PatternFill(start_color="D5F5D5", end_color="D5F5D5", fill_type="solid")
ws.merge_cells(f'B{current_row}:L{current_row}')
ws[f'B{current_row}'] = issue.completion_comment
ws[f'B{current_row}'].font = content_font
ws[f'B{current_row}'].alignment = Alignment(wrap_text=True, vertical='center') # 수직 가운데 정렬
ws.row_dimensions[current_row].height = 30
current_row += 1
# 완료 사진
if issue.completion_photo_path:
# 라벨 행 (A~L 전체 병합)
ws.merge_cells(f'A{current_row}:L{current_row}')
ws[f'A{current_row}'] = "완료 사진"
ws[f'A{current_row}'].font = label_font
ws[f'A{current_row}'].fill = PatternFill(start_color="D5F5D5", end_color="D5F5D5", fill_type="solid") # 연두색
ws[f'A{current_row}'].alignment = Alignment(horizontal='left', vertical='center')
ws.row_dimensions[current_row].height = 18
current_row += 1
# 사진 행 (별도 행으로 분리)
ws.merge_cells(f'A{current_row}:L{current_row}')
completion_path = issue.completion_photo_path.replace('/uploads/', '/app/uploads/') if issue.completion_photo_path.startswith('/uploads/') else issue.completion_photo_path
completion_image_inserted = False
if os.path.exists(completion_path):
try:
img = XLImage(completion_path)
img.width = min(img.width, 250)
img.height = min(img.height, 180)
ws.add_image(img, f'A{current_row}') # A열에 사진
completion_image_inserted = True
except Exception as e:
print(f"이미지 삽입 실패 ({completion_path}): {e}")
if completion_image_inserted:
ws.row_dimensions[current_row].height = 150 # 사진 행 높이 조정 (200 -> 150)
else:
ws[f'A{current_row}'] = "사진 파일을 찾을 수 없음"
ws[f'A{current_row}'].font = Font(size=9, italic=True, color="999999")
ws.row_dimensions[current_row].height = 20
current_row += 1
# 완료일 정보
if issue.actual_completion_date:
ws[f'A{current_row}'] = "완료일"
ws[f'A{current_row}'].font = label_font
ws[f'A{current_row}'].fill = PatternFill(start_color="D5F5D5", end_color="D5F5D5", fill_type="solid")
ws.merge_cells(f'B{current_row}:C{current_row}')
ws[f'B{current_row}'] = issue.actual_completion_date.strftime('%Y-%m-%d')
ws[f'B{current_row}'].font = content_font
current_row += 1
# 사진이 하나도 없을 경우
# 진행중: 신고 사진만 체크
# 완료됨: 신고 사진 + 완료 사진 체크
has_any_photo = has_report_photo or (issue.review_status == ReviewStatus.completed and issue.completion_photo_path)
if not has_any_photo:
ws[f'A{current_row}'] = "첨부사진"
ws[f'A{current_row}'].font = label_font
ws[f'A{current_row}'].fill = label_fill
ws.merge_cells(f'B{current_row}:L{current_row}')
ws[f'B{current_row}'] = "첨부된 사진 없음"
ws[f'B{current_row}'].font = Font(size=9, italic=True, color="999999")
current_row += 1
# 카드 전체에 테두리 적용 (A-L 열)
card_end_row = current_row - 1
for row in range(card_start_row, card_end_row + 1):
for col in range(1, 13): # A-L 열 (12열)
cell = ws.cell(row=row, column=col)
if not cell.border or cell.border.left.style != 'medium':
cell.border = border
# 카드 외곽에 굵은 테두리 (A-L 열)
for col in range(1, 13):
ws.cell(row=card_start_row, column=col).border = Border(
left=Side(style='medium' if col == 1 else 'thin'),
right=Side(style='medium' if col == 12 else 'thin'),
top=Side(style='medium'),
bottom=Side(style='thin')
)
ws.cell(row=card_end_row, column=col).border = Border(
left=Side(style='medium' if col == 1 else 'thin'),
right=Side(style='medium' if col == 12 else 'thin'),
top=Side(style='thin'),
bottom=Side(style='medium')
)
# 카드 구분 (빈 행)
current_row += 1
# 열 너비 조정
ws.column_dimensions['A'].width = 12 # 레이블 열
ws.column_dimensions['B'].width = 15 # 내용 열
ws.column_dimensions['C'].width = 15 # 내용 열
ws.column_dimensions['D'].width = 15 # 내용 열
ws.column_dimensions['E'].width = 15 # 내용 열
ws.column_dimensions['F'].width = 15 # 내용 열
ws.column_dimensions['G'].width = 15 # 내용 열
ws.column_dimensions['H'].width = 15 # 내용 열
ws.column_dimensions['I'].width = 15 # 내용 열
ws.column_dimensions['J'].width = 15 # 내용 열
ws.column_dimensions['K'].width = 15 # 내용 열
ws.column_dimensions['L'].width = 15 # 내용 열
# 엑셀 파일을 메모리에 저장
excel_buffer = io.BytesIO()
wb.save(excel_buffer)
excel_buffer.seek(0)
# 추출 이력 업데이트
export_time = datetime.now()
for issue in issues:
issue.last_exported_at = export_time
issue.export_count = (issue.export_count or 0) + 1
db.commit()
# 파일명 생성
today = date.today().strftime('%Y%m%d')
filename = f"{project.project_name}_일일보고서_{today}.xlsx"
# 한글 파일명을 위한 URL 인코딩
from urllib.parse import quote
encoded_filename = quote(filename.encode('utf-8'))
return StreamingResponse(
io.BytesIO(excel_buffer.read()),
media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
headers={
"Content-Disposition": f"attachment; filename*=UTF-8''{encoded_filename}"
}
)
def calculate_project_stats(issues: List[Issue]) -> schemas.DailyReportStats:
"""프로젝트 통계 계산"""
stats = schemas.DailyReportStats()
today = date.today()
for issue in issues:
stats.total_count += 1
if issue.review_status == ReviewStatus.in_progress:
stats.management_count += 1
# 지연 여부 확인 (expected_completion_date가 오늘보다 이전인 경우)
if issue.expected_completion_date:
expected_date = issue.expected_completion_date.date() if isinstance(issue.expected_completion_date, datetime) else issue.expected_completion_date
if expected_date < today:
stats.delayed_count += 1
elif issue.review_status == ReviewStatus.completed:
stats.completed_count += 1
return stats
def get_category_text(category: IssueCategory) -> str:
"""카테고리 한글 변환"""
category_map = {
IssueCategory.material_missing: "자재 누락",
IssueCategory.design_error: "설계 미스",
IssueCategory.incoming_defect: "입고 불량",
IssueCategory.inspection_miss: "검사 미스",
IssueCategory.etc: "기타"
}
return category_map.get(category, str(category))
def get_department_text(department) -> str:
"""부서 한글 변환"""
if not department:
return ""
department_map = {
"production": "생산",
"quality": "품질",
"purchasing": "구매",
"design": "설계",
"sales": "영업"
}
return department_map.get(department, str(department))
def get_status_text(status: ReviewStatus) -> str:
"""상태 한글 변환"""
status_map = {
ReviewStatus.pending_review: "검토 대기",
ReviewStatus.in_progress: "진행 중",
ReviewStatus.completed: "완료됨",
ReviewStatus.disposed: "폐기됨"
}
return status_map.get(status, str(status))
def clean_management_comment_for_export(text: str) -> str:
"""엑셀 내보내기용 management_comment 정리 (완료 반려, 댓글 제거)"""
if not text:
return ""
# 1. 완료 반려 패턴 제거 ([완료 반려 - 날짜시간] 내용)
text = re.sub(r'\[완료 반려[^\]]*\][^\n]*\n*', '', text)
# 2. 댓글 패턴 제거 (└, ↳로 시작하는 줄들)
lines = text.split('\n')
filtered_lines = []
for line in lines:
# └ 또는 ↳로 시작하는 줄 제외
if not re.match(r'^\s*[└↳]', line):
filtered_lines.append(line)
# 3. 빈 줄 정리
result = '\n'.join(filtered_lines).strip()
# 연속된 빈 줄을 하나로
result = re.sub(r'\n{3,}', '\n\n', result)
return result
def get_status_color(status: ReviewStatus) -> str:
"""상태별 색상 반환"""
color_map = {
ReviewStatus.in_progress: "FFF2CC", # 연한 노랑
ReviewStatus.completed: "E2EFDA", # 연한 초록
ReviewStatus.disposed: "F2F2F2" # 연한 회색
}
return color_map.get(status, None)
def get_issue_priority(issue: Issue) -> int:
"""이슈 우선순위 반환 (엑셀 정렬용)
1: 지연 (빨강)
2: 진행중 (노랑)
3: 완료됨 (초록)
"""
if issue.review_status == ReviewStatus.completed:
return 3
elif issue.review_status == ReviewStatus.in_progress:
# 조치 예상일이 지난 경우 지연
if issue.expected_completion_date:
today = date.today()
expected_date = issue.expected_completion_date.date() if isinstance(issue.expected_completion_date, datetime) else issue.expected_completion_date
if expected_date < today:
return 1 # 지연
return 2 # 진행중
return 2
def get_issue_status_text(issue: Issue) -> str:
"""이슈 상태 텍스트 반환"""
if issue.review_status == ReviewStatus.completed:
return "완료됨"
elif issue.review_status == ReviewStatus.in_progress:
if issue.expected_completion_date:
today = date.today()
expected_date = issue.expected_completion_date.date() if isinstance(issue.expected_completion_date, datetime) else issue.expected_completion_date
if expected_date < today:
return "지연중"
return "진행중"
return get_status_text(issue.review_status)
def get_issue_status_header_color(issue: Issue) -> str:
"""이슈 상태별 헤더 색상 반환"""
priority = get_issue_priority(issue)
if priority == 1: # 지연
return "E74C3C" # 빨간색
elif priority == 2: # 진행중
return "F39C12" # 주황/노란색
elif priority == 3: # 완료
return "27AE60" # 초록색
return "4472C4" # 기본 파란색

View File

@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Optional
from jose import JWTError, jwt
from passlib.context import CryptContext
@@ -48,9 +48,9 @@ def get_password_hash(password: str) -> str:
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
to_encode = data.copy()
if expires_delta:
expire = datetime.utcnow() + expires_delta
expire = datetime.now(timezone.utc) + expires_delta
else:
expire = datetime.utcnow() + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
expire = datetime.now(timezone.utc) + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt

View File

@@ -43,7 +43,7 @@ server {
# work-issues API 프록시 → system2-api
location /api/work-issues/ {
proxy_pass http://tk-system2-api:3005;
proxy_pass http://system2-api:3005;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;