🔄 Duplicate Tracking System: - 중복 신고 시 원본 이슈에 신고자 정보 자동 추가 - 신고 인지도 및 대응 속도 분석을 위한 데이터 수집 - 뒷북치는 신고자 파악 및 집계 기능 📊 Database Schema Updates: - duplicate_of_issue_id: 중복 대상 이슈 ID (FK) - duplicate_reporters: 중복 신고자 목록 (JSONB 배열) - 015_add_duplicate_tracking.sql 마이그레이션 실행 - GIN 인덱스로 JSONB 검색 성능 최적화 🔧 Backend Enhancements: - 중복 폐기 시 대상 이슈에 신고자 정보 자동 추가 - 신고자 중복 체크 로직 (동일 사용자 재추가 방지) - /api/inbox/management-issues API 추가 (중복 선택용) - 프로젝트별 관리함 이슈 목록 조회 지원 🎨 Frontend UI Improvements: - 중복 선택 시 관리함 이슈 목록 표시 - 프로젝트별 필터링된 이슈 목록 제공 - 간단한 이슈 정보 표시 (제목, 카테고리, 신고자, 중복 건수) - 직관적인 선택 UI (클릭으로 선택, 시각적 피드백) 📋 Duplicate Selection Process: 1. 폐기 사유로 '중복' 선택 2. 동일 프로젝트의 관리함 이슈 목록 자동 로드 3. 중복 대상 이슈 선택 (필수) 4. 확인 시 신고자 정보가 원본 이슈에 추가 💾 Data Structure: - duplicate_reporters: [ { user_id: 123, username: 'reporter1', full_name: '신고자1', report_date: '2024-10-25T14:30:00', added_at: '2024-10-25T15:00:00' } ] 🔍 Analytics Features: - 중복 신고 건수 표시 - 신고자별 신고 시점 추적 - 원본 이슈 대비 지연 신고 분석 가능 - 부서별/사용자별 인지도 분석 데이터 제공 🚀 User Experience: - 중복 처리 시 명확한 안내 메시지 - 관리함 이슈 목록 실시간 로드 - 선택 필수 검증 (중복 대상 미선택 시 경고) - 처리 완료 후 자동 목록 새로고침 Expected Result: ✅ 중복 신고 시 신고자 정보 자동 추적 ✅ 신고 인지도 및 대응 속도 분석 데이터 수집 ✅ 직관적인 중복 대상 선택 UI ✅ 부서별/개인별 신고 패턴 분석 기반 마련
172 lines
7.0 KiB
Python
172 lines
7.0 KiB
Python
from sqlalchemy import Column, Integer, BigInteger, String, DateTime, Float, Boolean, Text, ForeignKey, Enum, Index
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime, timezone, timedelta
|
|
import enum
|
|
|
|
# 한국 시간대 설정
|
|
KST = timezone(timedelta(hours=9))
|
|
|
|
def get_kst_now():
|
|
"""현재 한국 시간 반환"""
|
|
return datetime.now(KST)
|
|
|
|
Base = declarative_base()
|
|
|
|
class UserRole(str, enum.Enum):
|
|
admin = "admin" # 관리자
|
|
user = "user" # 일반 사용자
|
|
|
|
class IssueStatus(str, enum.Enum):
|
|
new = "new"
|
|
progress = "progress"
|
|
complete = "complete"
|
|
|
|
class IssueCategory(str, enum.Enum):
|
|
material_missing = "material_missing"
|
|
design_error = "design_error" # 설계미스 (기존 dimension_defect 대체)
|
|
incoming_defect = "incoming_defect"
|
|
inspection_miss = "inspection_miss" # 검사미스 (신규 추가)
|
|
etc = "etc" # 기타
|
|
|
|
class ReviewStatus(str, enum.Enum):
|
|
pending_review = "pending_review" # 수신함 (검토 대기)
|
|
in_progress = "in_progress" # 관리함 (진행 중)
|
|
completed = "completed" # 관리함 (완료됨)
|
|
disposed = "disposed" # 폐기함 (폐기됨)
|
|
|
|
class DisposalReasonType(str, enum.Enum):
|
|
duplicate = "duplicate" # 중복 (기본값)
|
|
invalid_report = "invalid_report" # 잘못된 신고
|
|
not_applicable = "not_applicable" # 해당 없음
|
|
spam = "spam" # 스팸/오류
|
|
custom = "custom" # 직접 입력
|
|
|
|
class DepartmentType(str, enum.Enum):
|
|
production = "production" # 생산
|
|
quality = "quality" # 품질
|
|
purchasing = "purchasing" # 구매
|
|
design = "design" # 설계
|
|
sales = "sales" # 영업
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
username = Column(String, unique=True, index=True, nullable=False)
|
|
hashed_password = Column(String, nullable=False)
|
|
full_name = Column(String)
|
|
role = Column(Enum(UserRole), default=UserRole.user)
|
|
department = Column(Enum(DepartmentType)) # 부서 정보 추가
|
|
is_active = Column(Boolean, default=True)
|
|
created_at = Column(DateTime, default=get_kst_now)
|
|
|
|
# Relationships
|
|
issues = relationship("Issue", back_populates="reporter", foreign_keys="Issue.reporter_id")
|
|
reviewed_issues = relationship("Issue", foreign_keys="Issue.reviewed_by_id")
|
|
daily_works = relationship("DailyWork", back_populates="created_by")
|
|
projects = relationship("Project", back_populates="created_by")
|
|
page_permissions = relationship("UserPagePermission", back_populates="user", foreign_keys="UserPagePermission.user_id")
|
|
|
|
class UserPagePermission(Base):
|
|
__tablename__ = "user_page_permissions"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
|
page_name = Column(String(50), nullable=False)
|
|
can_access = Column(Boolean, default=False)
|
|
granted_by_id = Column(Integer, ForeignKey("users.id"))
|
|
granted_at = Column(DateTime, default=get_kst_now)
|
|
notes = Column(Text)
|
|
|
|
# Relationships
|
|
user = relationship("User", back_populates="page_permissions", foreign_keys=[user_id])
|
|
granted_by = relationship("User", foreign_keys=[granted_by_id], post_update=True)
|
|
|
|
# Unique constraint
|
|
__table_args__ = (
|
|
Index('idx_user_page_permissions_user_id', 'user_id'),
|
|
Index('idx_user_page_permissions_page_name', 'page_name'),
|
|
)
|
|
|
|
class Issue(Base):
|
|
__tablename__ = "issues"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
photo_path = Column(String)
|
|
photo_path2 = Column(String) # 두 번째 사진 경로
|
|
category = Column(Enum(IssueCategory), nullable=False)
|
|
description = Column(Text, nullable=False)
|
|
status = Column(Enum(IssueStatus), default=IssueStatus.new)
|
|
reporter_id = Column(Integer, ForeignKey("users.id"))
|
|
project_id = Column(BigInteger, ForeignKey("projects.id"))
|
|
report_date = Column(DateTime, default=get_kst_now)
|
|
work_hours = Column(Float, default=0)
|
|
detail_notes = Column(Text)
|
|
|
|
# 수신함 워크플로우 관련 컬럼들
|
|
review_status = Column(Enum(ReviewStatus), default=ReviewStatus.pending_review)
|
|
disposal_reason = Column(Enum(DisposalReasonType))
|
|
custom_disposal_reason = Column(Text)
|
|
disposed_at = Column(DateTime)
|
|
reviewed_by_id = Column(Integer, ForeignKey("users.id"))
|
|
reviewed_at = Column(DateTime)
|
|
original_data = Column(JSONB) # 원본 데이터 보존
|
|
modification_log = Column(JSONB, default=lambda: []) # 수정 이력
|
|
|
|
# 중복 신고 추적 시스템
|
|
duplicate_of_issue_id = Column(Integer, ForeignKey("issues.id")) # 중복 대상 이슈 ID
|
|
duplicate_reporters = Column(JSONB, default=lambda: []) # 중복 신고자 목록
|
|
|
|
# Relationships
|
|
reporter = relationship("User", back_populates="issues", foreign_keys=[reporter_id])
|
|
reviewer = relationship("User", foreign_keys=[reviewed_by_id], overlaps="reviewed_issues")
|
|
project = relationship("Project", back_populates="issues")
|
|
duplicate_of = relationship("Issue", remote_side=[id], foreign_keys=[duplicate_of_issue_id])
|
|
|
|
class Project(Base):
|
|
__tablename__ = "projects"
|
|
|
|
id = Column(BigInteger, primary_key=True, index=True)
|
|
job_no = Column(String, unique=True, nullable=False, index=True)
|
|
project_name = Column(String, nullable=False)
|
|
created_by_id = Column(Integer, ForeignKey("users.id"))
|
|
created_at = Column(DateTime, default=get_kst_now)
|
|
is_active = Column(Boolean, default=True)
|
|
|
|
# Relationships
|
|
created_by = relationship("User", back_populates="projects")
|
|
issues = relationship("Issue", back_populates="project")
|
|
|
|
class DailyWork(Base):
|
|
__tablename__ = "daily_works"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
date = Column(DateTime, nullable=False, index=True)
|
|
worker_count = Column(Integer, nullable=False)
|
|
regular_hours = Column(Float, nullable=False)
|
|
overtime_workers = Column(Integer, default=0)
|
|
overtime_hours = Column(Float, default=0)
|
|
overtime_total = Column(Float, default=0)
|
|
total_hours = Column(Float, nullable=False)
|
|
created_by_id = Column(Integer, ForeignKey("users.id"))
|
|
created_at = Column(DateTime, default=get_kst_now)
|
|
|
|
# Relationships
|
|
created_by = relationship("User", back_populates="daily_works")
|
|
|
|
class ProjectDailyWork(Base):
|
|
__tablename__ = "project_daily_works"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
date = Column(DateTime, nullable=False, index=True)
|
|
project_id = Column(BigInteger, ForeignKey("projects.id"), nullable=False)
|
|
hours = Column(Float, nullable=False)
|
|
created_by_id = Column(Integer, ForeignKey("users.id"))
|
|
created_at = Column(DateTime, default=get_kst_now)
|
|
|
|
# Relationships
|
|
project = relationship("Project")
|
|
created_by = relationship("User")
|