처리 과정에 대한 로그를 콘솔에 출력하기 위한 부분 추가

This commit is contained in:
2025-07-29 14:29:54 +09:00
parent 9abc760d7b
commit bf44f13a51

View File

@ -38,37 +38,43 @@ def load_excel_data(filepath: str):
df = df.dropna(subset=required_cols)
return df
def process_file(filepath: str, engine, session, table):
batch_size = 1000
inserted, updated, errors = 0, 0, 0
count = 0
try:
# sale_date는 엑셀 내부 각 행별로 존재하므로, 파일명 기준 추출는 제외
df = load_excel_data(filepath)
logger.info(f"[LOAD] {os.path.basename(filepath)} - {len(df)}")
inserted, updated, errors = 0, 0, 0
for _, row in df.iterrows():
try:
def safe_int(val, default=0):
try:
return int(val)
except Exception:
return default
data = {
"sale_date": pd.to_datetime(row["매출일시"]),
"shop_name": str(row.get("매장명", "")).strip(),
"pos_no": int(row.get("포스번호", 0)),
"bill_no": int(row.get("영수증 번호", 0)),
"pos_no": safe_int(row.get("포스번호")),
"bill_no": safe_int(row.get("영수증 번호")),
"product_cd": str(row.get("품목", "")).strip(),
"ca01": nan_to_none(row.get("대분류")),
"ca02": nan_to_none(row.get("중분류")),
"ca03": nan_to_none(row.get("소분류")),
"product_name": str(row.get("품목명", "")).strip(),
"barcode": nan_to_none(row.get("바코드")),
"amt": int(row.get("단가", 0)),
"qty": int(row.get("수량", 0)),
"tot_sale_amt": int(row.get("주문 금액", 0)),
"dc_amt": int(row.get("할인 금액", 0)),
"dcm_sale_amt": int(row.get("공급가액", 0)),
"net_amt": int(row.get("세금", 0)),
"vat_amt": int(row.get("부가세", 0)),
"cash_receipt": int(row.get("현금영수증", 0)),
"card": int(row.get("카드", 0)),
"amt": safe_int(row.get("단가")),
"qty": safe_int(row.get("수량")),
"tot_sale_amt": safe_int(row.get("주문 금액")),
"dc_amt": safe_int(row.get("할인 금액")),
"dcm_sale_amt": safe_int(row.get("공급가액")),
"net_amt": safe_int(row.get("세금")),
"vat_amt": safe_int(row.get("부가세")),
"cash_receipt": safe_int(row.get("현금영수증")),
"card": safe_int(row.get("카드")),
}
stmt = mysql_insert(table).values(**data)
@ -79,12 +85,16 @@ def process_file(filepath: str, engine, session, table):
})
result = session.execute(update_stmt)
# rowcount 1이면 insert, 2면 update (MySQL 특성상)
if result.rowcount == 1:
inserted += 1
elif result.rowcount == 2:
updated += 1
count += 1
if count % batch_size == 0:
session.commit()
logger.info(f"[COMMIT] {count}건 처리 완료")
except Exception as e:
logger.warning(f"[ERROR:ROW] {e}")
errors += 1