diff --git a/backend/app.py b/backend/app.py index 3b26ab8..e7cf0a3 100644 --- a/backend/app.py +++ b/backend/app.py @@ -5862,20 +5862,25 @@ def api_replace_product_image(barcode): except Exception as e: return jsonify({'success': False, 'error': f'이미지 처리 실패: {str(e)}'}), 400 - # SQLite 업데이트 + # SQLite 업데이트 (기존 값 유지) db_path = os.path.join(os.path.dirname(__file__), 'db', 'product_images.db') conn = sqlite3.connect(db_path) cursor = conn.cursor() - cursor.execute(""" - UPDATE product_images - SET image_base64 = ?, thumbnail_base64 = ?, image_url = ?, - status = 'manual', error_message = NULL, updated_at = datetime('now') - WHERE barcode = ? - """, (image_base64, thumbnail_base64, image_url, barcode)) + # 기존 레코드 확인 + cursor.execute("SELECT product_name, drug_code FROM product_images WHERE barcode = ?", (barcode,)) + existing = cursor.fetchone() - if cursor.rowcount == 0: - # 레코드가 없으면 새로 생성 + if existing: + # 기존 레코드 있으면 이미지만 업데이트 (product_name, drug_code 유지) + cursor.execute(""" + UPDATE product_images + SET image_base64 = ?, thumbnail_base64 = ?, image_url = ?, + status = 'manual', error_message = NULL, updated_at = datetime('now') + WHERE barcode = ? + """, (image_base64, thumbnail_base64, image_url, barcode)) + else: + # 레코드가 없으면 새로 생성 (product_name은 barcode로 임시 저장) cursor.execute(""" INSERT INTO product_images (barcode, image_base64, thumbnail_base64, image_url, status, product_name) VALUES (?, ?, ?, ?, 'manual', ?) diff --git a/backend/templates/admin_product_images.html b/backend/templates/admin_product_images.html index efac690..e3abe8d 100644 --- a/backend/templates/admin_product_images.html +++ b/backend/templates/admin_product_images.html @@ -504,7 +504,7 @@ ${getStatusText(item.status)}
- +