feat: Flask 애플리케이션 모듈화 및 웹 대시보드 구현
- Flask Blueprint 아키텍처로 전환 (dashboard, upload, backup, status) - app.py 681줄 95줄로 축소 (86% 감소) - HTML 템플릿 모듈화 (base.html + 기능별 templates) - CSS/JS 파일 분리 (common + 기능별 파일) - 대시보드 기능 추가 (통계, 주간 예보, 방문객 추이) - 파일 업로드 웹 인터페이스 구현 - 백업/복구 관리 UI 구현 - Docker 배포 환경 개선 - .gitignore 업데이트 (uploads, backups, cache 등)
This commit is contained in:
@ -18,6 +18,14 @@ CONFIG = load_config()
|
||||
DATA_DIR = os.path.join(os.path.dirname(__file__), '../data')
|
||||
|
||||
def update_pos_table(engine, table, df):
|
||||
"""
|
||||
데이터프레임을 테이블에 업데이트
|
||||
|
||||
Args:
|
||||
engine: SQLAlchemy 엔진
|
||||
table: DB 테이블 객체
|
||||
df: 데이터프레임
|
||||
"""
|
||||
with engine.begin() as conn:
|
||||
for idx, row in df.iterrows():
|
||||
data = row.to_dict()
|
||||
@ -39,6 +47,17 @@ def update_pos_table(engine, table, df):
|
||||
print("[DONE] 모든 데이터 삽입 완료")
|
||||
|
||||
def process_file(filepath, table, engine):
|
||||
"""
|
||||
OKPOS 파일 처리
|
||||
|
||||
Args:
|
||||
filepath: 파일 경로
|
||||
table: DB 테이블
|
||||
engine: SQLAlchemy 엔진
|
||||
|
||||
Returns:
|
||||
tuple[bool, int]: (성공 여부, 행 수)
|
||||
"""
|
||||
print(f"[INFO] 처리 시작: {filepath}")
|
||||
try:
|
||||
ext = os.path.splitext(filepath)[-1].lower()
|
||||
@ -86,6 +105,51 @@ def process_file(filepath, table, engine):
|
||||
print(f"[INFO] 처리 완료: {filepath}")
|
||||
return True, len(df)
|
||||
|
||||
|
||||
def process_okpos_file(filepath):
|
||||
"""
|
||||
OKPOS 파일을 처리하고 DB에 저장
|
||||
웹 업로드 인터페이스에서 사용하는 함수
|
||||
|
||||
Args:
|
||||
filepath (str): 업로드된 파일 경로
|
||||
|
||||
Returns:
|
||||
dict: {
|
||||
'success': bool,
|
||||
'message': str,
|
||||
'rows_inserted': int
|
||||
}
|
||||
"""
|
||||
try:
|
||||
engine = db.engine
|
||||
table = db_schema.pos
|
||||
|
||||
# 파일 처리
|
||||
success, row_count = process_file(filepath, table, engine)
|
||||
|
||||
if success:
|
||||
return {
|
||||
'success': True,
|
||||
'message': f'{row_count}행이 저장되었습니다.',
|
||||
'rows_inserted': row_count
|
||||
}
|
||||
else:
|
||||
return {
|
||||
'success': False,
|
||||
'message': '파일 처리에 실패했습니다.',
|
||||
'rows_inserted': 0
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
print(f"[ERROR] OKPOS 파일 처리 오류: {e}")
|
||||
return {
|
||||
'success': False,
|
||||
'message': f'파일 처리 중 오류: {str(e)}',
|
||||
'rows_inserted': 0
|
||||
}
|
||||
|
||||
|
||||
def batch_process_files(table, engine):
|
||||
files = [f for f in os.listdir(DATA_DIR) if f.startswith("일자별 (상품별)") and f.endswith(('.xlsx', '.xls'))]
|
||||
if not files:
|
||||
|
||||
Reference in New Issue
Block a user