Files
SmartReports/CertReports.Syncfusion/README.md

165 lines
7.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CertReports.Syncfusion
Progetto ASP.NET Core 8 per la generazione di report PDF per certificati finanziari,
basato su **Syncfusion PDF Library** (Community License).
Sostituisce il vecchio progetto WebForms con DevExpress + PdfSharp.
---
## Architettura
```
┌──────────────────────────────────────────────────────────────────────┐
│ ReportController │
│ GET /api/report?p={encrypted} | GET /api/report?alias={id} │
└──────────────────────┬───────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────────────┐
│ ReportOrchestrator │
│ │
│ 1. CertificateDataService ──→ SQL Server (stored procedures) │
│ 2. AnagraficaSectionRenderer ──→ PDF Sezione 1 │
│ 3. EventiSectionRenderer ──→ PDF Sezione 2 │
│ 4. ScenarioSectionRenderer ──→ PDF Sezione 3 (se non Protect.) │
│ 5. ChartSectionRenderer ──→ PDF Sezione 4 (ext. service) │
│ 6. PdfMergerService ──→ PDF Finale unificato │
└──────────────────────────────────────────────────────────────────────┘
```
### Struttura file
```
CertReports.Syncfusion/
├── Controllers/
│ └── ReportController.cs # API endpoint (sostituisce WebForm)
├── Helpers/
│ ├── CryptoHelper.cs # Decodifica ISIN cifrato
│ └── PdfTheme.cs # Colori, font, stili centralizzati
├── Models/
│ └── CertificateModels.cs # Modelli dati (Info, Eventi, Scenario)
├── Services/
│ ├── Interfaces/
│ │ └── IServices.cs # Contratti per tutti i servizi
│ └── Implementations/
│ ├── CertificateDataService.cs # Accesso DB via stored procedures
│ ├── AnagraficaSectionRenderer.cs # Sezione 1: dati + sottostanti
│ ├── EventiSectionRenderer.cs # Sezione 2: tabella eventi
│ ├── ScenarioSectionRenderer.cs # Sezione 3: matrice scenario
│ ├── ChartSectionRenderer.cs # Sezione 4: grafico
│ ├── PdfMergerService.cs # Merge PDF Syncfusion
│ └── ReportOrchestrator.cs # Coordinatore principale
├── GlobalUsings.cs
├── Program.cs # Entry point + DI setup
├── appsettings.json # Configurazione
└── CertReports.Syncfusion.csproj # Progetto + NuGet packages
```
---
## Mapping Vecchio → Nuovo
| Vecchio (DevExpress/WebForms) | Nuovo (Syncfusion/ASP.NET Core) |
|----------------------------------------------|-------------------------------------------|
| `ReportFSSiteCrypt.aspx` (Page_Load) | `ReportController.cs` (API REST) |
| `XtraReport` + `.repx` template | `IPdfSectionRenderer` implementations |
| `report.ExportToPdf()` per ogni sezione | Ogni renderer restituisce `PdfDocument` |
| `PdfSharp.PdfReader.Open` + `CopyPages` | `Syncfusion PdfMergerService` |
| `CommonClass.DecryptCombined()` | `CryptoHelper.DecryptIsin()` |
| `CommonClass.execSP_Scalar()` | `CertificateDataService` (async) |
| `CallWebApi()` per chart | `ChartSectionRenderer` (HttpClientFactory)|
| File temp su disco + `File.Delete` | Tutto in memoria (MemoryStream) |
| `Response.BinaryWrite()` | `return File(bytes, "application/pdf")` |
---
## Setup e Configurazione
### 1. Prerequisiti
- .NET 8 SDK
- SQL Server con le stored procedures esistenti
- Syncfusion Community License Key (gratuita per < $1M fatturato)
### 2. Configurazione `appsettings.json`
```json
{
"ConnectionStrings": {
"CertDb": "Server=...;Database=...;User Id=...;Password=...;"
},
"Syncfusion": {
"LicenseKey": "LA_TUA_CHIAVE_QUI"
},
"ChartService": {
"BaseUrl": "https://reports.smart-roots.net:4004",
"ChartEndpoint": "/ChartFSWeb.aspx?width=800&height=600&isin={0}&tipo=pdf"
}
}
```
### 3. Avvio
```bash
dotnet restore
dotnet run
```
### 4. Test
```
# Con ISIN cifrato (compatibile vecchie URL)
GET https://localhost:5001/api/report?p=0x0200000047...
# Con Alias ID
GET https://localhost:5001/api/report?alias=MY_ALIAS
# Diretto (debug/interno)
GET https://localhost:5001/api/report/by-isin/CH1277653163
# Download come file
GET https://localhost:5001/api/report/download?alias=MY_ALIAS
```
---
## Stored Procedures Utilizzate
| SP | Sezione Report | Descrizione |
|----|----------------|-------------|
| `rpt_Master_CFT_ISIN(@ISIN)` | 1 - Anagrafica | Dati certificato (1 record, campi pre-formattati) |
| `rpt_Details_UL_ISIN(@ISIN)` | 1 - Sottostanti | N sottostanti con strike, barriere, dividendi |
| `rpt_Events_CFT_ISIN(@ISIN)` | 2 - Eventi | Lista eventi con date, cedole, autocall |
| `rpt_AnalisiRischio_ISIN(@ISIN)` | 3 - Scenario | Tabella pivot 3×11 (variazioni -70%..+70%) |
| `rpt_FindIsinbyAliasID(@AliasID)` | Risoluzione | Alias ID → ISIN |
---
## TODO Rimasti
### Completato ✓
- ✓ CryptoHelper con logica `DecryptCombined` completa (v1 TripleDES, v2 AES)
- ✓ Mapping colonne SP reali (`rpt_Master_CFT_ISIN`, `rpt_Details_UL_ISIN`, ecc.)
- ✓ Modelli aggiornati per ricevere stringhe pre-formattate dalla SP
- ✓ Analisi scenario adattata al formato pivot `col0..col11`
### Da Verificare/Completare
1. **Test con DB reale** — Verificare che i nomi colonna nel `SqlDataReader` corrispondano
esattamente all'output delle SP (usa `GetStringSafe` che gestisce colonne mancanti)
2. **Layout PDF fine-tuning** — Posizioni, margini, colori per replicare il look originale
3. **Chart service** — L'endpoint ChartFSWeb.aspx funziona ancora? Altrimenti
implementare la generazione interna con SkiaSharp in `ChartSectionRenderer`
4. **SP `rpt_FindIsinbyAliasID`** — Verificare nome esatto e parametro
---
## Vantaggi rispetto al Vecchio Progetto
- **Nessun file temporaneo su disco**: tutto in MemoryStream
- **Dependency Injection**: ogni servizio è testabile e sostituibile
- **Async/await**: niente più `WebRequest` bloccanti
- **Logging strutturato**: Serilog con log rotanti
- **Sezioni modulari**: aggiungere un nuovo tipo di report = aggiungere un `IPdfSectionRenderer`
- **Tema centralizzato**: un cambio in `PdfTheme.cs` aggiorna tutti i PDF
- **API REST**: può essere consumata da qualsiasi client (non solo browser)