Replace Flask admin with FastAPI app (api/app/) featuring: - Dashboard with stat cards, sync control, and history - Mappings CRUD for ARTICOLE_TERTI with CSV import/export - Article autocomplete from NOM_ARTICOLE - SKU pre-validation before import - Sync orchestration: read JSONs -> validate -> import -> log to SQLite - APScheduler for periodic sync from UI - File logging to logs/sync_comenzi_YYYYMMDD_HHMMSS.log - Oracle pool None guard (503 vs 500 on unavailable) Test suite: - test_app_basic.py: 30 tests (imports + routes) without Oracle - test_integration.py: 9 integration tests with Oracle Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4.6 KiB
4.6 KiB
GoMag Vending - Import Comenzi Web → ROA Oracle
System automat de import comenzi din platforma GoMag in sistemul ERP ROA Oracle.
Arhitectura
[GoMag API] → [VFP Orchestrator] → [Oracle PL/SQL] → [FastAPI Admin]
↓ ↓ ↑ ↑
JSON Orders Process & Log Store/Update Dashboard + Config
Stack Tehnologic
- Database: Oracle PL/SQL packages (PACK_IMPORT_PARTENERI, PACK_IMPORT_COMENZI)
- Integrare: Visual FoxPro 9 (gomag-vending.prg, sync-comenzi-web.prg)
- Admin/Dashboard: FastAPI + Jinja2 + Oracle pool + SQLite
- Date: Oracle 11g/12c (schema ROA), SQLite (tracking local)
Quick Start
Prerequisite
- Python 3.10+
- Oracle Instant Client (optional - suporta si thin mode)
Instalare si pornire
cd api
pip install -r requirements.txt
# Configureaza .env (vezi api/.env.example)
uvicorn app.main:app --host 0.0.0.0 --port 5003 --reload
Deschide http://localhost:5003 in browser.
Testare
Test A - Basic (fara Oracle):
cd api
python test_app_basic.py
Verifica 17 importuri de module + 13 rute GET. Asteptat: 30/30 PASS.
Test C - Integrare Oracle:
python api/test_integration.py
Necesita Oracle activ. Verifica health, mappings CRUD, article search, validation, sync. Asteptat: 9/9 PASS.
Structura Proiect
/
├── api/ # FastAPI Admin + Database
│ ├── app/ # Aplicatia FastAPI
│ │ ├── main.py # Entry point, lifespan, logging
│ │ ├── config.py # Settings (pydantic-settings, .env)
│ │ ├── database.py # Oracle pool + SQLite init
│ │ ├── routers/ # Endpoint-uri HTTP
│ │ │ ├── health.py # /health, /api/health
│ │ │ ├── dashboard.py # / (dashboard HTML)
│ │ │ ├── mappings.py # /mappings, /api/mappings
│ │ │ ├── articles.py # /api/articles/search
│ │ │ ├── validation.py # /api/validate/*
│ │ │ └── sync.py # /api/sync/*
│ │ ├── services/ # Business logic
│ │ │ ├── mapping_service # CRUD ARTICOLE_TERTI
│ │ │ ├── article_service # Cautare NOM_ARTICOLE
│ │ │ ├── import_service # Import comanda in Oracle
│ │ │ ├── sync_service # Orchestrare: JSON→validate→import
│ │ │ ├── validation_service # Validare SKU-uri
│ │ │ ├── order_reader # Citire JSON-uri din vfp/output/
│ │ │ ├── sqlite_service # Tracking runs/orders/missing SKUs
│ │ │ └── scheduler_service # APScheduler timer
│ │ ├── templates/ # Jinja2 HTML (dashboard, mappings, etc.)
│ │ └── static/ # CSS + JS
│ ├── database-scripts/ # Oracle SQL scripts
│ ├── test_app_basic.py # Test A - fara Oracle
│ ├── test_integration.py # Test C - cu Oracle
│ └── requirements.txt # Python dependencies
├── vfp/ # VFP Integration
│ ├── gomag-vending.prg # Client GoMag API
│ ├── sync-comenzi-web.prg # Orchestrator VFP
│ └── utils.prg # Utilitare VFP
├── docs/ # Documentatie
│ ├── PRD.md # Product Requirements
│ └── stories/ # User Stories
└── logs/ # Log-uri aplicatie
Configurare (.env)
ORACLE_USER=MARIUSM_AUTO
ORACLE_PASSWORD=********
ORACLE_DSN=ROA_CENTRAL
FORCE_THIN_MODE=true # sau INSTANTCLIENTPATH=C:\oracle\instantclient
SQLITE_DB_PATH=data/import.db
APP_PORT=5003
LOG_LEVEL=INFO
JSON_OUTPUT_DIR=../vfp/output
Status Implementare
Phase 1: Database Foundation - COMPLET
- ARTICOLE_TERTI table + Docker setup
- PACK_IMPORT_PARTENERI package
- PACK_IMPORT_COMENZI package
Phase 2: VFP Integration - COMPLET
- gomag-vending.prg (GoMag API client)
- sync-comenzi-web.prg (orchestrator cu logging)
Phase 3-4: FastAPI Admin + Dashboard - COMPLET
- Mappings CRUD + CSV import/export
- Article autocomplete (NOM_ARTICOLE)
- Pre-validation SKU-uri
- Import orchestration (JSON→Oracle)
- Dashboard cu stat cards, sync control, history
- Missing SKUs management page
- File logging (logs/sync_comenzi_*.log)
Phase 5: Production - IN PROGRESS
- File logging
- Email notifications (SMTP)
- HTTP Basic Auth
- NSSM Windows service