feat: v9.1 업그레이드 — CS 기록 메뉴 + 반품 목록 검색 + 구글 연동 안정화
원본(CS 통합 프로그램 v9.1, 2026.09.03)을 서버판에 병합. 서버용 개조는 유지: SSO(AuthGuard·SessionMiddleware), /corm 서브경로(root_path·APP_BASE_PATH), X-Service-Token, /health/db, 환경변수 DB 설정, cafe24/naver 키 환경변수. - CS 기록 메뉴(routers/cs_records.py, cs_records.js/css): 달력별 기록·완료·복사· 다음 업무일 이월, 상시 메모(폴더·색), 일정, 엑셀 내려받기/업로드. 표는 itemcode_db 에 자동 생성(CREATE TABLE IF NOT EXISTS). DB 설정은 원본의 하드코딩 대신 CS_RECORD_DB_* → POSTGRES_*/ITEMCODE_DB 환경변수. - New CS 누락·파손·불량·오배송 발주 → CS 기록 자동 저장. - 반품 신청/입고 목록: 최근 3개월 기본, 전체 보기, 원송장번호 전체 검색. - google_runtime.py: 구글 호출 시간 제한·전용 작업 슬롯, 설정 시트 스냅샷 캐시 (예전 10분 인메모리 캐시와 /api/config/refresh 대체), 설정 저장 한 번에 원자적으로. - 밀크런: 탭을 열 때만 구글 시트 조회. - 자동발주 메뉴는 원본처럼 막지 않고 그대로 둠, 엑셀 내려받기 링크도 /corm 경로. - requirements: holidays 추가. tests/test_google_resilience.py(서비스 토큰으로 SSO 통과). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,7 @@ import requests
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import StreamingResponse
|
||||
from pydantic import BaseModel
|
||||
from google_runtime import GOOGLE_READ_TIMEOUT, GOOGLE_TIMEOUT, create_google_client, create_google_session, google_worker
|
||||
|
||||
router = APIRouter(prefix="/api/coupang-milkrun", tags=["Coupang Milkrun"])
|
||||
|
||||
@@ -315,7 +316,7 @@ _sheet_tabs_cache = {} # file_id -> (저장시각, 시트 목록 응답)
|
||||
|
||||
# 구글이 응답을 안 주면 무한정 매달리지 않도록 (연결 대기, 응답 대기) 초
|
||||
_HTTP_TIMEOUT = (10, 120)
|
||||
_HTTP_READ_TIMEOUT = 120
|
||||
_HTTP_READ_TIMEOUT = GOOGLE_READ_TIMEOUT
|
||||
|
||||
# 밀크런 출고리스트 구글 시트 (화면에서 주소를 입력하지 않아도 되도록 기본값으로 둔다)
|
||||
MILKRUN_SHEET_URL = os.getenv(
|
||||
@@ -419,7 +420,7 @@ def _drive_get(session, file_id, params):
|
||||
return session.get(
|
||||
f"https://www.googleapis.com/drive/v3/files/{file_id}",
|
||||
params={**params, "supportsAllDrives": "true"},
|
||||
timeout=60,
|
||||
timeout=GOOGLE_TIMEOUT,
|
||||
)
|
||||
|
||||
|
||||
@@ -463,7 +464,7 @@ def _fetch_drive_workbook_authenticated(file_id):
|
||||
except ImportError:
|
||||
raise HTTPException(status_code=500, detail="google-auth 라이브러리가 설치되어 있지 않습니다.")
|
||||
|
||||
session = AuthorizedSession(_load_credentials([DRIVE_SCOPE]))
|
||||
session = create_google_session(_load_credentials([DRIVE_SCOPE]))
|
||||
response = _drive_get(session, file_id, {"alt": "media"})
|
||||
if response.status_code != 200:
|
||||
raise HTTPException(status_code=400, detail=_drive_error_detail(response))
|
||||
@@ -493,7 +494,7 @@ def fetch_drive_file_name(file_id):
|
||||
try:
|
||||
from google.auth.transport.requests import AuthorizedSession
|
||||
|
||||
session = AuthorizedSession(_load_credentials([DRIVE_SCOPE]))
|
||||
session = create_google_session(_load_credentials([DRIVE_SCOPE]))
|
||||
response = _drive_get(session, file_id, {"fields": "name"})
|
||||
if response.status_code == 200:
|
||||
return response.json().get("name", "")
|
||||
@@ -548,7 +549,7 @@ def _read_sheet_tabs(file_id):
|
||||
raise HTTPException(status_code=500, detail="gspread 라이브러리가 설치되어 있지 않습니다.")
|
||||
|
||||
try:
|
||||
client = gspread.authorize(_load_credentials([SHEETS_SCOPE]))
|
||||
client = create_google_client(_load_credentials([SHEETS_SCOPE]))
|
||||
spreadsheet = client.open_by_key(file_id)
|
||||
return {
|
||||
"source": "google_sheet",
|
||||
@@ -672,7 +673,8 @@ def _read_milkrun_sheet(content, sheet_name):
|
||||
|
||||
|
||||
@router.post("/sheet-rows")
|
||||
async def get_sheet_rows(payload: SheetRowsRequest):
|
||||
@google_worker
|
||||
def get_sheet_rows(payload: SheetRowsRequest):
|
||||
"""선택한 시트의 제품코드/제품명/수량을 읽어 분석용 텍스트로 돌려준다."""
|
||||
file_id = extract_file_id(payload.url or MILKRUN_SHEET_URL)
|
||||
if not payload.sheet:
|
||||
@@ -687,7 +689,8 @@ async def get_sheet_rows(payload: SheetRowsRequest):
|
||||
|
||||
|
||||
@router.post("/sheet-tabs")
|
||||
async def get_sheet_tabs(payload: SheetTabsRequest):
|
||||
@google_worker
|
||||
def get_sheet_tabs(payload: SheetTabsRequest):
|
||||
"""구글 드라이브 파일의 시트(탭) 이름 목록을 돌려준다."""
|
||||
file_id = extract_file_id(payload.url or MILKRUN_SHEET_URL)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user