Compare commits
97 Commits
text-trasl
...
not-workin
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f73924572 | |||
| 8edc4af645 | |||
| e1409d218b | |||
| 0c92f8b394 | |||
| 66de93a315 | |||
| b337db03c4 | |||
| 8c6c1e10b3 | |||
| eac3006512 | |||
| b26b582baf | |||
| 875c6ffd2d | |||
| 579ac3fcb6 | |||
| efa1371ffa | |||
| ab7f263aca | |||
| 49bae8e186 | |||
| e2872c730c | |||
| 86266b31ee | |||
| 5d0fb5fe6d | |||
| 91af8f4f9c | |||
| a96c28fb39 | |||
| 9b24ca529c | |||
| 6216d9a723 | |||
| 4aa3f6adf1 | |||
| 7baad738f5 | |||
| 9feceb9b3c | |||
| 304ed942b8 | |||
| 881bd87392 | |||
| 3a5e4e3427 | |||
| 8c82470401 | |||
| ef6a5278a7 | |||
| bb276b6504 | |||
| e351f2c05f | |||
| 165e12f216 | |||
| 475bfcc6fb | |||
| becb15da73 | |||
| 4d559901eb | |||
| 06a036810a | |||
| 0b29aebfcf | |||
| 961109b04c | |||
| b5bd68ed10 | |||
| 56fb504062 | |||
| f165d191be | |||
| e1d9823b51 | |||
| f829ccef4a | |||
| 59e881c3f4 | |||
| f5aa0f298e | |||
| 2eea773ee2 | |||
| 44f9408b22 | |||
| 044fba8d5a | |||
| 257c60fa5e | |||
| 5a84fb13c0 | |||
| 89d84ed369 | |||
| 9c3d5fae12 | |||
| 96ae9bb609 | |||
| 9cbd856ab6 | |||
| bb151ae835 | |||
| 7ebaff322c | |||
| e17da96c22 | |||
| 3e9745c7cc | |||
| 3da3e6c60c | |||
| 85b823d614 | |||
| d20d12c1f4 | |||
| ab5f6a609d | |||
| 5ba203a8d1 | |||
| 3ca3f8e466 | |||
| 5620f6a8eb | |||
| 1583ff479c | |||
| b7d81040e6 | |||
| b249cf2000 | |||
| dfc27da142 | |||
| dde92af857 | |||
| 7b92e63a49 | |||
| 8fac8ac892 | |||
| e5183590c5 | |||
| 3b4ef37e58 | |||
| eb4ad8b637 | |||
| f0e0f57e7c | |||
| 05e1c224f0 | |||
| f1636d9057 | |||
| 44d99b0a68 | |||
| 83b3008234 | |||
| 78af87ac3c | |||
| b3c0413b7c | |||
| 4f301b1652 | |||
| debf153f58 | |||
| f3d271ded2 | |||
| 13790f2055 | |||
| bcdeafe119 | |||
| 7978884ca6 | |||
| cb7b44073c | |||
| 99ae6db064 | |||
| fcf439e369 | |||
| cecdfacd33 | |||
| 5bc698815c | |||
| 73ccf8f4de | |||
| 0b4daed512 | |||
| 8a7d736aa9 | |||
| ce179cac62 |
@@ -81,6 +81,9 @@ jobs:
|
|||||||
needs: build-and-push
|
needs: build-and-push
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set ENV
|
- name: Set ENV
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
@@ -92,7 +95,7 @@ jobs:
|
|||||||
echo "ENV=dev" >> "$GITHUB_ENV"
|
echo "ENV=dev" >> "$GITHUB_ENV"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Trigger deploy on Unraid (forced command key)
|
- name: Setup SSH key
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -120,9 +123,48 @@ jobs:
|
|||||||
# 5) Validazione: se fallisce qui, la chiave NON è valida/corrotta
|
# 5) Validazione: se fallisce qui, la chiave NON è valida/corrotta
|
||||||
ssh-keygen -y -f ~/.ssh/id_ed25519 >/dev/null
|
ssh-keygen -y -f ~/.ssh/id_ed25519 >/dev/null
|
||||||
|
|
||||||
# ... (resto del codice uguale)
|
|
||||||
ssh-keyscan -H "${{ secrets.SERVER_HOST }}" >> ~/.ssh/known_hosts 2>/dev/null
|
ssh-keyscan -H "${{ secrets.SERVER_HOST }}" >> ~/.ssh/known_hosts 2>/dev/null
|
||||||
|
|
||||||
|
- name: Write env to server
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
# 1. Start with the static env file content
|
||||||
|
cat "deploy/envs/${{ env.ENV }}.env" > /tmp/full_env.env
|
||||||
|
|
||||||
|
# 2. Determine DB credentials
|
||||||
|
if [[ "${{ env.ENV }}" == "prod" ]]; then
|
||||||
|
DB_URL="${{ secrets.DB_URL_PROD }}"
|
||||||
|
DB_USER="${{ secrets.DB_USERNAME_PROD }}"
|
||||||
|
DB_PASS="${{ secrets.DB_PASSWORD_PROD }}"
|
||||||
|
elif [[ "${{ env.ENV }}" == "int" ]]; then
|
||||||
|
DB_URL="${{ secrets.DB_URL_INT }}"
|
||||||
|
DB_USER="${{ secrets.DB_USERNAME_INT }}"
|
||||||
|
DB_PASS="${{ secrets.DB_PASSWORD_INT }}"
|
||||||
|
else
|
||||||
|
DB_URL="${{ secrets.DB_URL_DEV }}"
|
||||||
|
DB_USER="${{ secrets.DB_USERNAME_DEV }}"
|
||||||
|
DB_PASS="${{ secrets.DB_PASSWORD_DEV }}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 3. Append DB credentials
|
||||||
|
printf '\nDB_URL=%s\nDB_USERNAME=%s\nDB_PASSWORD=%s\n' \
|
||||||
|
"$DB_URL" "$DB_USER" "$DB_PASS" >> /tmp/full_env.env
|
||||||
|
|
||||||
|
# 4. Debug: print content (for debug purposes)
|
||||||
|
echo "Preparing to send env file with variables:"
|
||||||
|
grep -v "PASSWORD" /tmp/full_env.env || true
|
||||||
|
|
||||||
|
# 5. Send to server
|
||||||
|
ssh -i ~/.ssh/id_ed25519 -o BatchMode=yes "${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}" \
|
||||||
|
"setenv ${{ env.ENV }}" < /tmp/full_env.env
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
- name: Trigger deploy on Unraid (forced command key)
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
# Aggiungiamo le opzioni di verbosità se dovesse fallire ancora,
|
# Aggiungiamo le opzioni di verbosità se dovesse fallire ancora,
|
||||||
# e assicuriamoci che l'input sia pulito
|
# e assicuriamoci che l'input sia pulito
|
||||||
ssh -i ~/.ssh/id_ed25519 -o BatchMode=yes "${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}" "${{ env.ENV }}"
|
ssh -i ~/.ssh/id_ed25519 -o BatchMode=yes "${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}" "deploy ${{ env.ENV }}"
|
||||||
|
|||||||
49
GEMINI.md
49
GEMINI.md
@@ -4,35 +4,42 @@ Questo file serve a dare contesto all'AI (Antigravity/Gemini) sulla struttura e
|
|||||||
|
|
||||||
## Project Overview
|
## Project Overview
|
||||||
**Nome**: Print Calculator
|
**Nome**: Print Calculator
|
||||||
**Scopo**: Calcolare costi e tempi di stampa 3D da file STL.
|
**Scopo**: Calcolare costi e tempi di stampa 3D da file STL in modo preciso tramite slicing reale.
|
||||||
**Stack**:
|
**Stack**:
|
||||||
- **Backend**: Python (FastAPI), libreria `trimesh` per analisi geometrica.
|
- **Backend**: Java 21 (Spring Boot 3.4), PostgreSQL, Flyway.
|
||||||
- **Frontend**: Angular 19 (TypeScript).
|
- **Frontend**: Angular 19 (TypeScript), Angular Material, Three.js per visualizzazione 3D.
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
### Backend (`/backend`)
|
### Backend (`/backend`)
|
||||||
- **`main.py`**: Entrypoint dell'applicazione FastAPI.
|
- **`BackendApplication.java`**: Entrypoint dell'applicazione Spring Boot.
|
||||||
- Definisce l'API `POST /calculate/stl`.
|
- **`controller/`**: Espone le API REST per l'upload e il calcolo dei preventivi.
|
||||||
- Gestisce l'upload del file, invoca lo slicer e restituisce il preventivo.
|
- **`service/SlicerService.java`**: Wrappa l'eseguibile di **OrcaSlicer** per effettuare lo slicing reale del modello.
|
||||||
- Configura CORS per permettere chiamate dal frontend.
|
- Gestisce i profili di stampa (Macchina, Processo, Filamento) caricati da file JSON.
|
||||||
- **`slicer.py`**: Wrappa l'eseguibile di **OrcaSlicer** per effettuare lo slicing reale del modello.
|
- Crea configurazioni on-the-fly e invoca OrcaSlicer in modalità headless.
|
||||||
- Gestisce i profili di stampa (Macchina, Processo, Filamento).
|
- **`service/GCodeParser.java`**: Analizza il G-Code generato per estrarre tempo di stampa e peso del materiale dai metadati del file.
|
||||||
- Crea configurazioni on-the-fly per supportare mesh di grandi dimensioni.
|
- **`service/QuoteCalculator.java`**: Calcola il prezzo finale basandosi su politiche di prezzo salvate nel database.
|
||||||
- **`calculator.py`**: Analizza il G-Code generato.
|
- Gestisce costi macchina a scaglioni (tiered pricing).
|
||||||
- `GCodeParser`: Estrae tempo di stampa e materiale usato dai metadati del G-Code.
|
- Calcola costi energetici basati sulla potenza della stampante e costo del kWh.
|
||||||
- `QuoteCalculator`: Applica i costi (orari, energia, materiale) per generare il prezzo finale.
|
- Applica markup percentuali e fee fissi per job.
|
||||||
|
|
||||||
### Frontend (`/frontend`)
|
### Frontend (`/frontend`)
|
||||||
- Applicazione Angular standard.
|
- Applicazione Angular 19 con architettura modulare (core, features, shared).
|
||||||
- Usa Angular Material.
|
- **Three.js**: Utilizzato per il rendering dei file STL caricati dall'utente.
|
||||||
- Service per upload STL e visualizzazione preventivo.
|
- **Angular Material**: Per l'interfaccia utente.
|
||||||
|
- **ngx-translate**: Per il supporto multilingua.
|
||||||
|
|
||||||
## Key Concepts
|
## Key Concepts
|
||||||
- **Real Slicing**: Il backend esegue un vero slicing usando OrcaSlicer in modalità headless. Questo garantisce stime di tempo e materiale estremamente precise, identiche a quelle che si otterrebbero preparando il file per la stampa.
|
- **Real Slicing**: Il backend esegue un vero slicing usando OrcaSlicer. Questo garantisce stime di tempo e materiale estremamente precise.
|
||||||
- **G-Code Parsing**: Invece di stimare geometricamente, l'applicazione legge direttamene i commenti generati dallo slicer nel G-Code (es. `estimated printing time`, `filament used`).
|
- **Database-Driven Pricing**: A differenza di versioni precedenti, il calcolo del preventivo è ora guidato da entità DB (`PricingPolicy`, `PrinterMachine`, `FilamentVariant`).
|
||||||
|
- **G-Code Metadata**: L'applicazione legge direttamene i commenti generati dallo slicer nel G-Code (es. `; estimated printing time`, `; filament used [g]`).
|
||||||
|
|
||||||
## Development Notes
|
## Development Notes
|
||||||
- Per eseguire il backend serve `uvicorn`.
|
- **Backend**: Richiede JDK 21. Si avvia con `./gradlew bootRun`.
|
||||||
- Il frontend richiede `npm install` al primo avvio.
|
- **Database**: Richiede PostgreSQL. Le migrazioni sono gestite da Flyway.
|
||||||
- Le configurazioni di stampa (layer height, wall thickness, infill) sono attualmente hardcoded o con valori di default nel backend, ma potrebbero essere esposte come parametri API in futuro.
|
- **Frontend**: Richiede Node.js 22. Si avvia con `npm start`.
|
||||||
|
- **OrcaSlicer**: Deve essere installato sul sistema e il percorso configurato in `application.properties` o tramite variabile d'ambiente `SLICER_PATH`.
|
||||||
|
|
||||||
|
## AI Agent Rules
|
||||||
|
- **No Inline Code**: Tutti i componenti Angular DEVONO usare file separati per HTML (`templateUrl`) e SCSS (`styleUrl`). È vietato usare `template` o `styles` inline nel decoratore `@Component`.
|
||||||
|
- **Spring Boot Conventions**: Seguire i pattern standard di Spring Boot (Service-Repository-Controller).
|
||||||
|
|||||||
10
Makefile
10
Makefile
@@ -1,10 +0,0 @@
|
|||||||
.PHONY: install s
|
|
||||||
install:
|
|
||||||
@echo "Installing Backend dependencies..."
|
|
||||||
cd backend && pip install -r requirements.txt || pip install fastapi uvicorn trimesh python-multipart numpy
|
|
||||||
@echo "Installing Frontend dependencies..."
|
|
||||||
cd frontend && npm install
|
|
||||||
|
|
||||||
start:
|
|
||||||
@echo "Starting development environment..."
|
|
||||||
./start.sh
|
|
||||||
93
README.md
93
README.md
@@ -1,70 +1,67 @@
|
|||||||
# Print Calculator (OrcaSlicer Edition)
|
# Print Calculator (OrcaSlicer Edition)
|
||||||
|
|
||||||
Un'applicazione Full Stack (Angular + Python/FastAPI) per calcolare preventivi di stampa 3D precisi utilizzando **OrcaSlicer** in modalità headless.
|
Un'applicazione Full Stack (Angular + Spring Boot) per calcolare preventivi di stampa 3D precisi utilizzando **OrcaSlicer** in modalità headless.
|
||||||
|
|
||||||
## Funzionalità
|
## Funzionalità
|
||||||
|
|
||||||
* **Slicing Reale**: Usa il motore di OrcaSlicer per stimare tempo e materiale, non semplici approssimazioni geometriche.
|
* **Slicing Reale**: Usa il motore di OrcaSlicer per stimare tempo e materiale, garantendo la massima precisione.
|
||||||
* **Preventivazione Completa**: Calcola costo materiale, ammortamento macchina, energia e ricarico.
|
* **Preventivazione Database-Driven**: Calcolo basato su politiche di prezzo configurabili nel database (costo materiale, ammortamento macchina a scaglioni, energia e markup).
|
||||||
* **Configurabile**: Prezzi e parametri macchina modificabili via variabili d'ambiente.
|
* **Visualizzazione 3D**: Anteprima del file STL caricato tramite Three.js.
|
||||||
* **Docker Ready**: Tutto containerizzato per un facile deployment.
|
* **Multi-Profilo**: Supporto per diverse stampanti, materiali e profili di processo.
|
||||||
|
|
||||||
|
## Stack Tecnologico
|
||||||
|
|
||||||
|
- **Backend**: Java 21, Spring Boot 3.4, PostgreSQL, Flyway.
|
||||||
|
- **Frontend**: Angular 19, Angular Material, Three.js.
|
||||||
|
- **Slicer**: OrcaSlicer (invocato via CLI).
|
||||||
|
|
||||||
## Prerequisiti
|
## Prerequisiti
|
||||||
|
|
||||||
* Docker Desktop & Docker Compose installati.
|
* **Java 21** installato.
|
||||||
|
* **Node.js 22** e **npm** installati.
|
||||||
|
* **PostgreSQL** attivo.
|
||||||
|
* **OrcaSlicer** installato sul sistema.
|
||||||
|
|
||||||
## Avvio Rapido
|
## Avvio Rapido
|
||||||
|
|
||||||
1. Clona il repository.
|
### 1. Database
|
||||||
2. Esegui lo script di avvio o docker-compose:
|
Crea un database PostgreSQL chiamato `printcalc`. Le tabelle verranno create automaticamente al primo avvio tramite Flyway.
|
||||||
```bash
|
|
||||||
docker-compose up --build
|
|
||||||
```
|
|
||||||
*Nota: La prima build impiegherà alcuni minuti per scaricare OrcaSlicer (~200MB) e compilare il Frontend.*
|
|
||||||
|
|
||||||
3. Accedi all'applicazione:
|
### 2. Backend
|
||||||
* **Frontend**: [http://localhost](http://localhost)
|
Configura il percorso di OrcaSlicer in `backend/src/main/resources/application.properties` o tramite la variabile d'ambiente `SLICER_PATH`.
|
||||||
* **API Docs**: [http://localhost:8000/docs](http://localhost:8000/docs)
|
|
||||||
|
|
||||||
## Configurazione Prezzi
|
|
||||||
|
|
||||||
Puoi modificare i prezzi nel file `docker-compose.yml` (sezione `environment` del servizio backend):
|
|
||||||
|
|
||||||
* `FILAMENT_COST_PER_KG`: Costo filamento al kg (es. 25.0).
|
|
||||||
* `MACHINE_COST_PER_HOUR`: Costo orario macchina (ammortamento/manutenzione).
|
|
||||||
* `ENERGY_COST_PER_KWH`: Costo energia elettrica.
|
|
||||||
* `MARKUP_PERCENT`: Margine di profitto percentuale (es. 20 = +20%).
|
|
||||||
|
|
||||||
## Struttura del Progetto
|
|
||||||
|
|
||||||
* `/backend`: API Python FastAPI. Include Dockerfile che scarica OrcaSlicer AppImage.
|
|
||||||
* `/frontend`: Applicazione Angular 19+ con Material Design.
|
|
||||||
* `/backend/profiles`: Contiene i profili di slicing (.ini). Attualmente configurato per una stima generica simil-Bambu Lab A1.
|
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
### Errore Download OrcaSlicer
|
|
||||||
Se la build del backend fallisce durante il download di `OrcaSlicer.AppImage`, verifica la tua connessione internet o aggiorna l'URL nel `backend/Dockerfile`.
|
|
||||||
|
|
||||||
### Slicing Fallito (Costo 0 o Errore)
|
|
||||||
Se l'API ritorna errore o valori nulli:
|
|
||||||
1. Controlla che il file STL sia valido (manifold).
|
|
||||||
2. Controlla i log del backend: `docker logs print-calculator-backend`.
|
|
||||||
|
|
||||||
## Sviluppo Locale (Senza Docker)
|
|
||||||
|
|
||||||
**Backend**:
|
|
||||||
Richiede Linux (o WSL2) per eseguire l'AppImage di OrcaSlicer.
|
|
||||||
```bash
|
```bash
|
||||||
cd backend
|
cd backend
|
||||||
pip install -r requirements.txt
|
./gradlew bootRun
|
||||||
# Assicurati di avere OrcaSlicer installato e nel PATH o aggiorna SLICER_PATH in slicer.py
|
|
||||||
uvicorn main:app --reload
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Frontend**:
|
### 3. Frontend
|
||||||
```bash
|
```bash
|
||||||
cd frontend
|
cd frontend
|
||||||
npm install
|
npm install
|
||||||
npm start
|
npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Accedi a [http://localhost:4200](http://localhost:4200).
|
||||||
|
|
||||||
|
## Configurazione Prezzi
|
||||||
|
|
||||||
|
I prezzi non sono più gestiti tramite variabili d'ambiente fisse ma tramite tabelle nel database:
|
||||||
|
- `pricing_policy`: Definisce markup, fee fissi e costi elettrici.
|
||||||
|
- `pricing_policy_machine_hour_tier`: Definisce i costi orari delle macchine in base alla durata della stampa.
|
||||||
|
- `printer_machine`: Anagrafica stampanti e consumi energetici.
|
||||||
|
- `filament_material_type` / `filament_variant`: Listino prezzi materiali.
|
||||||
|
|
||||||
|
## Struttura del Progetto
|
||||||
|
|
||||||
|
* `/backend`: API Spring Boot.
|
||||||
|
* `/frontend`: Applicazione Angular.
|
||||||
|
* `/backend/profiles`: Contiene i file di configurazione per OrcaSlicer.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Percorso OrcaSlicer
|
||||||
|
Assicurati che `slicer.path` punti al binario corretto. Su macOS è solitamente `/Applications/OrcaSlicer.app/Contents/MacOS/OrcaSlicer`. Su Linux è il percorso all'AppImage (estratta o meno).
|
||||||
|
|
||||||
|
### Database connection
|
||||||
|
Verifica le credenziali in `application.properties`. Se usi Docker, puoi passare `DB_URL`, `DB_USERNAME` e `DB_PASSWORD` come variabili d'ambiente.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ RUN ./gradlew bootJar -x test --no-daemon
|
|||||||
# Stage 2: Runtime Environment
|
# Stage 2: Runtime Environment
|
||||||
FROM eclipse-temurin:21-jre-jammy
|
FROM eclipse-temurin:21-jre-jammy
|
||||||
|
|
||||||
# Install system dependencies for OrcaSlicer (same as before)
|
# Install system dependencies for OrcaSlicer
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
wget \
|
wget \
|
||||||
p7zip-full \
|
p7zip-full \
|
||||||
@@ -19,7 +19,15 @@ RUN apt-get update && apt-get install -y \
|
|||||||
libglib2.0-0 \
|
libglib2.0-0 \
|
||||||
libgtk-3-0 \
|
libgtk-3-0 \
|
||||||
libdbus-1-3 \
|
libdbus-1-3 \
|
||||||
libwebkit2gtk-4.1-0 \
|
libwebkit2gtk-4.0-37 \
|
||||||
|
libx11-xcb1 \
|
||||||
|
libxcb-dri3-0 \
|
||||||
|
libxtst6 \
|
||||||
|
libnss3 \
|
||||||
|
libatk-bridge2.0-0 \
|
||||||
|
libxss1 \
|
||||||
|
libasound2 \
|
||||||
|
libgbm1 \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install OrcaSlicer
|
# Install OrcaSlicer
|
||||||
@@ -41,4 +49,6 @@ COPY profiles ./profiles
|
|||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
CMD ["java", "-jar", "app.jar"]
|
COPY entrypoint.sh .
|
||||||
|
RUN chmod +x entrypoint.sh
|
||||||
|
ENTRYPOINT ["./entrypoint.sh"]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
|
id 'application'
|
||||||
id 'org.springframework.boot' version '3.4.1'
|
id 'org.springframework.boot' version '3.4.1'
|
||||||
id 'io.spring.dependency-management' version '1.1.7'
|
id 'io.spring.dependency-management' version '1.1.7'
|
||||||
}
|
}
|
||||||
@@ -13,17 +14,42 @@ java {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
mainClass = 'com.printcalculator.BackendApplication'
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
|
implementation 'xyz.capybara:clamav-client:2.1.2'
|
||||||
|
runtimeOnly 'org.postgresql:postgresql'
|
||||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
|
testRuntimeOnly 'com.h2database:h2'
|
||||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||||
|
compileOnly 'org.projectlombok:lombok'
|
||||||
|
annotationProcessor 'org.projectlombok:lombok'
|
||||||
|
implementation 'io.github.openhtmltopdf:openhtmltopdf-pdfbox:1.1.37'
|
||||||
|
implementation 'io.github.openhtmltopdf:openhtmltopdf-svg-support:1.1.37'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||||
|
implementation 'net.codecrete.qrbill:qrbill-generator:3.4.0'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named('test') {
|
tasks.named('test') {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.named('bootRun') {
|
||||||
|
args = ["--spring.profiles.active=local"]
|
||||||
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
applicationDefaultJvmArgs = ["-Dspring.profiles.active=local"]
|
||||||
|
}
|
||||||
|
|||||||
15
backend/entrypoint.sh
Normal file
15
backend/entrypoint.sh
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "----------------------------------------------------------------"
|
||||||
|
echo "Starting Backend Application"
|
||||||
|
echo "DB_URL: $DB_URL"
|
||||||
|
echo "DB_USERNAME: $DB_USERNAME"
|
||||||
|
echo "SLICER_PATH: $SLICER_PATH"
|
||||||
|
echo "--- ALL ENV VARS ---"
|
||||||
|
env
|
||||||
|
echo "----------------------------------------------------------------"
|
||||||
|
|
||||||
|
# Exec java with explicit properties from env
|
||||||
|
exec java -jar app.jar \
|
||||||
|
--spring.datasource.url="${DB_URL}" \
|
||||||
|
--spring.datasource.username="${DB_USERNAME}" \
|
||||||
|
--spring.datasource.password="${DB_PASSWORD}"
|
||||||
@@ -2,8 +2,13 @@ package com.printcalculator;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableTransactionManagement
|
||||||
|
@EnableScheduling
|
||||||
public class BackendApplication {
|
public class BackendApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
package com.printcalculator.config;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ConfigurationProperties(prefix = "pricing")
|
|
||||||
public class AppProperties {
|
|
||||||
|
|
||||||
private double filamentCostPerKg;
|
|
||||||
private double machineCostPerHour;
|
|
||||||
private double energyCostPerKwh;
|
|
||||||
private double printerPowerWatts;
|
|
||||||
private double markupPercent;
|
|
||||||
|
|
||||||
private String slicerPath;
|
|
||||||
private String profilesRoot;
|
|
||||||
|
|
||||||
// Getters and Setters needed for Spring binding
|
|
||||||
|
|
||||||
public double getFilamentCostPerKg() { return filamentCostPerKg; }
|
|
||||||
public void setFilamentCostPerKg(double filamentCostPerKg) { this.filamentCostPerKg = filamentCostPerKg; }
|
|
||||||
|
|
||||||
public double getMachineCostPerHour() { return machineCostPerHour; }
|
|
||||||
public void setMachineCostPerHour(double machineCostPerHour) { this.machineCostPerHour = machineCostPerHour; }
|
|
||||||
|
|
||||||
public double getEnergyCostPerKwh() { return energyCostPerKwh; }
|
|
||||||
public void setEnergyCostPerKwh(double energyCostPerKwh) { this.energyCostPerKwh = energyCostPerKwh; }
|
|
||||||
|
|
||||||
public double getPrinterPowerWatts() { return printerPowerWatts; }
|
|
||||||
public void setPrinterPowerWatts(double printerPowerWatts) { this.printerPowerWatts = printerPowerWatts; }
|
|
||||||
|
|
||||||
public double getMarkupPercent() { return markupPercent; }
|
|
||||||
public void setMarkupPercent(double markupPercent) { this.markupPercent = markupPercent; }
|
|
||||||
|
|
||||||
// Slicer props are not under "pricing" prefix in properties file?
|
|
||||||
// Wait, in application.properties I put them at root level/custom.
|
|
||||||
// Let's fix this class to map correctly or change prefix.
|
|
||||||
// I'll make a separate section or just bind manually.
|
|
||||||
// Actually, I'll just add @Value in services for simplicity or fix the prefix structure.
|
|
||||||
// Let's stick to standard @Value for simple paths if this is messy.
|
|
||||||
// Or better, creating a dedicated SlicerProperties.
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.printcalculator.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class CorsConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
registry.addMapping("/**")
|
||||||
|
.allowedOrigins(
|
||||||
|
"http://localhost",
|
||||||
|
"http://localhost:4200",
|
||||||
|
"http://localhost:80",
|
||||||
|
"http://127.0.0.1",
|
||||||
|
"https://dev.3d-fab.ch",
|
||||||
|
"https://int.3d-fab.ch",
|
||||||
|
"https://3d-fab.ch"
|
||||||
|
)
|
||||||
|
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH")
|
||||||
|
.allowedHeaders("*")
|
||||||
|
.allowCredentials(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.printcalculator.config;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ConfigurationProperties(prefix = "")
|
|
||||||
// Hack: standard prefix is usually required. I'll use @Value in service or correct this.
|
|
||||||
// Better: make SlicerConfig class.
|
|
||||||
public class SlicerConfig {
|
|
||||||
// Intentionally empty, will use @Value in service for simplicity
|
|
||||||
// or fix in next step.
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
package com.printcalculator.controller;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.CustomQuoteRequest;
|
||||||
|
import com.printcalculator.entity.CustomQuoteRequestAttachment;
|
||||||
|
import com.printcalculator.repository.CustomQuoteRequestAttachmentRepository;
|
||||||
|
import com.printcalculator.repository.CustomQuoteRequestRepository;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/custom-quote-requests")
|
||||||
|
public class CustomQuoteRequestController {
|
||||||
|
|
||||||
|
private final CustomQuoteRequestRepository requestRepo;
|
||||||
|
private final CustomQuoteRequestAttachmentRepository attachmentRepo;
|
||||||
|
|
||||||
|
private final com.printcalculator.service.StorageService storageService;
|
||||||
|
|
||||||
|
public CustomQuoteRequestController(CustomQuoteRequestRepository requestRepo,
|
||||||
|
CustomQuoteRequestAttachmentRepository attachmentRepo,
|
||||||
|
com.printcalculator.service.StorageService storageService) {
|
||||||
|
this.requestRepo = requestRepo;
|
||||||
|
this.attachmentRepo = attachmentRepo;
|
||||||
|
this.storageService = storageService;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Create Custom Quote Request
|
||||||
|
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<CustomQuoteRequest> createCustomQuoteRequest(
|
||||||
|
@RequestPart("request") com.printcalculator.dto.QuoteRequestDto requestDto,
|
||||||
|
@RequestPart(value = "files", required = false) List<MultipartFile> files
|
||||||
|
) throws IOException {
|
||||||
|
|
||||||
|
// 1. Create Request
|
||||||
|
CustomQuoteRequest request = new CustomQuoteRequest();
|
||||||
|
request.setRequestType(requestDto.getRequestType());
|
||||||
|
request.setCustomerType(requestDto.getCustomerType());
|
||||||
|
request.setEmail(requestDto.getEmail());
|
||||||
|
request.setPhone(requestDto.getPhone());
|
||||||
|
request.setName(requestDto.getName());
|
||||||
|
request.setCompanyName(requestDto.getCompanyName());
|
||||||
|
request.setContactPerson(requestDto.getContactPerson());
|
||||||
|
request.setMessage(requestDto.getMessage());
|
||||||
|
request.setStatus("PENDING");
|
||||||
|
request.setCreatedAt(OffsetDateTime.now());
|
||||||
|
request.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
|
||||||
|
request = requestRepo.save(request);
|
||||||
|
|
||||||
|
// 2. Handle Attachments
|
||||||
|
if (files != null && !files.isEmpty()) {
|
||||||
|
if (files.size() > 15) {
|
||||||
|
throw new IOException("Too many files. Max 15 allowed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (MultipartFile file : files) {
|
||||||
|
if (file.isEmpty()) continue;
|
||||||
|
|
||||||
|
CustomQuoteRequestAttachment attachment = new CustomQuoteRequestAttachment();
|
||||||
|
attachment.setRequest(request);
|
||||||
|
attachment.setOriginalFilename(file.getOriginalFilename());
|
||||||
|
attachment.setMimeType(file.getContentType());
|
||||||
|
attachment.setFileSizeBytes(file.getSize());
|
||||||
|
attachment.setCreatedAt(OffsetDateTime.now());
|
||||||
|
|
||||||
|
// Generate path
|
||||||
|
UUID fileUuid = UUID.randomUUID();
|
||||||
|
String ext = getExtension(file.getOriginalFilename());
|
||||||
|
String storedFilename = fileUuid.toString() + "." + ext;
|
||||||
|
|
||||||
|
// Note: We don't have attachment ID yet.
|
||||||
|
// We'll save attachment first to get ID.
|
||||||
|
attachment.setStoredFilename(storedFilename);
|
||||||
|
attachment.setStoredRelativePath("PENDING");
|
||||||
|
|
||||||
|
attachment = attachmentRepo.save(attachment);
|
||||||
|
|
||||||
|
String relativePath = "quote-requests/" + request.getId() + "/attachments/" + attachment.getId() + "/" + storedFilename;
|
||||||
|
attachment.setStoredRelativePath(relativePath);
|
||||||
|
attachmentRepo.save(attachment);
|
||||||
|
|
||||||
|
// Save file to disk via StorageService
|
||||||
|
storageService.store(file, Paths.get(relativePath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.ok(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Get Request
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<CustomQuoteRequest> getCustomQuoteRequest(@PathVariable UUID id) {
|
||||||
|
return requestRepo.findById(id)
|
||||||
|
.map(ResponseEntity::ok)
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper
|
||||||
|
private String getExtension(String filename) {
|
||||||
|
if (filename == null) return "dat";
|
||||||
|
int i = filename.lastIndexOf('.');
|
||||||
|
if (i > 0) {
|
||||||
|
return filename.substring(i + 1);
|
||||||
|
}
|
||||||
|
return "dat";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
package com.printcalculator.controller;
|
||||||
|
|
||||||
|
import com.printcalculator.dto.OptionsResponse;
|
||||||
|
import com.printcalculator.entity.FilamentMaterialType;
|
||||||
|
import com.printcalculator.entity.FilamentVariant;
|
||||||
|
import com.printcalculator.entity.*; // This line replaces specific entity imports
|
||||||
|
import com.printcalculator.repository.FilamentMaterialTypeRepository;
|
||||||
|
import com.printcalculator.repository.FilamentVariantRepository;
|
||||||
|
import com.printcalculator.repository.LayerHeightOptionRepository;
|
||||||
|
import com.printcalculator.repository.NozzleOptionRepository;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class OptionsController {
|
||||||
|
|
||||||
|
private final FilamentMaterialTypeRepository materialRepo;
|
||||||
|
private final FilamentVariantRepository variantRepo;
|
||||||
|
private final LayerHeightOptionRepository layerHeightRepo;
|
||||||
|
private final NozzleOptionRepository nozzleRepo;
|
||||||
|
|
||||||
|
public OptionsController(FilamentMaterialTypeRepository materialRepo,
|
||||||
|
FilamentVariantRepository variantRepo,
|
||||||
|
LayerHeightOptionRepository layerHeightRepo,
|
||||||
|
NozzleOptionRepository nozzleRepo) {
|
||||||
|
this.materialRepo = materialRepo;
|
||||||
|
this.variantRepo = variantRepo;
|
||||||
|
this.layerHeightRepo = layerHeightRepo;
|
||||||
|
this.nozzleRepo = nozzleRepo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/api/calculator/options")
|
||||||
|
public ResponseEntity<OptionsResponse> getOptions() {
|
||||||
|
// 1. Materials & Variants
|
||||||
|
List<FilamentMaterialType> types = materialRepo.findAll();
|
||||||
|
List<FilamentVariant> allVariants = variantRepo.findAll();
|
||||||
|
|
||||||
|
List<OptionsResponse.MaterialOption> materialOptions = types.stream()
|
||||||
|
.map(type -> {
|
||||||
|
List<OptionsResponse.VariantOption> variants = allVariants.stream()
|
||||||
|
.filter(v -> v.getFilamentMaterialType().getId().equals(type.getId()) && v.getIsActive())
|
||||||
|
.map(v -> new OptionsResponse.VariantOption(
|
||||||
|
v.getVariantDisplayName(),
|
||||||
|
v.getColorName(),
|
||||||
|
getColorHex(v.getColorName()), // Need helper or store hex in DB
|
||||||
|
v.getStockSpools().doubleValue() <= 0
|
||||||
|
))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// Only include material if it has active variants
|
||||||
|
if (variants.isEmpty()) return null;
|
||||||
|
|
||||||
|
return new OptionsResponse.MaterialOption(
|
||||||
|
type.getMaterialCode(),
|
||||||
|
type.getMaterialCode() + (type.getIsFlexible() ? " (Flexible)" : " (Standard)"),
|
||||||
|
variants
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.filter(m -> m != null)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// Sort: PLA first, then PETG, then others alphabetically
|
||||||
|
materialOptions.sort((a, b) -> {
|
||||||
|
String codeA = a.code();
|
||||||
|
String codeB = b.code();
|
||||||
|
|
||||||
|
if (codeA.equals("pla_basic")) return -1;
|
||||||
|
if (codeB.equals("pla_basic")) return 1;
|
||||||
|
|
||||||
|
if (codeA.equals("petg_basic")) return -1;
|
||||||
|
if (codeB.equals("petg_basic")) return 1;
|
||||||
|
|
||||||
|
return codeA.compareTo(codeB);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Qualities (Static as per user request)
|
||||||
|
List<OptionsResponse.QualityOption> qualities = List.of(
|
||||||
|
new OptionsResponse.QualityOption("draft", "Draft"),
|
||||||
|
new OptionsResponse.QualityOption("standard", "Standard"),
|
||||||
|
new OptionsResponse.QualityOption("extra_fine", "High Definition")
|
||||||
|
);
|
||||||
|
|
||||||
|
// 3. Infill Patterns (Static as per user request)
|
||||||
|
List<OptionsResponse.InfillPatternOption> patterns = List.of(
|
||||||
|
new OptionsResponse.InfillPatternOption("grid", "Grid"),
|
||||||
|
new OptionsResponse.InfillPatternOption("gyroid", "Gyroid"),
|
||||||
|
new OptionsResponse.InfillPatternOption("cubic", "Cubic")
|
||||||
|
);
|
||||||
|
|
||||||
|
// 4. Layer Heights
|
||||||
|
List<OptionsResponse.LayerHeightOptionDTO> layers = layerHeightRepo.findAll().stream()
|
||||||
|
.filter(l -> l.getIsActive())
|
||||||
|
.sorted(Comparator.comparing(LayerHeightOption::getLayerHeightMm))
|
||||||
|
.map(l -> new OptionsResponse.LayerHeightOptionDTO(
|
||||||
|
l.getLayerHeightMm().doubleValue(),
|
||||||
|
String.format("%.2f mm", l.getLayerHeightMm())
|
||||||
|
))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 5. Nozzles
|
||||||
|
List<OptionsResponse.NozzleOptionDTO> nozzles = nozzleRepo.findAll().stream()
|
||||||
|
.filter(n -> n.getIsActive())
|
||||||
|
.sorted(Comparator.comparing(NozzleOption::getNozzleDiameterMm))
|
||||||
|
.map(n -> new OptionsResponse.NozzleOptionDTO(
|
||||||
|
n.getNozzleDiameterMm().doubleValue(),
|
||||||
|
String.format("%.1f mm%s", n.getNozzleDiameterMm(),
|
||||||
|
n.getExtraNozzleChangeFeeChf().doubleValue() > 0
|
||||||
|
? String.format(" (+ %.2f CHF)", n.getExtraNozzleChangeFeeChf())
|
||||||
|
: " (Standard)")
|
||||||
|
))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
return ResponseEntity.ok(new OptionsResponse(materialOptions, qualities, patterns, layers, nozzles));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Temporary helper until we add hex to DB
|
||||||
|
private String getColorHex(String colorName) {
|
||||||
|
String lower = colorName.toLowerCase();
|
||||||
|
if (lower.contains("black") || lower.contains("nero")) return "#1a1a1a";
|
||||||
|
if (lower.contains("white") || lower.contains("bianco")) return "#f5f5f5";
|
||||||
|
if (lower.contains("blue") || lower.contains("blu")) return "#1976d2";
|
||||||
|
if (lower.contains("red") || lower.contains("rosso")) return "#d32f2f";
|
||||||
|
if (lower.contains("green") || lower.contains("verde")) return "#388e3c";
|
||||||
|
if (lower.contains("orange") || lower.contains("arancione")) return "#ffa726";
|
||||||
|
if (lower.contains("grey") || lower.contains("gray") || lower.contains("grigio")) {
|
||||||
|
if (lower.contains("dark") || lower.contains("scuro")) return "#424242";
|
||||||
|
return "#bdbdbd";
|
||||||
|
}
|
||||||
|
if (lower.contains("purple") || lower.contains("viola")) return "#7b1fa2";
|
||||||
|
if (lower.contains("yellow") || lower.contains("giallo")) return "#fbc02d";
|
||||||
|
return "#9e9e9e"; // Default grey
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,258 @@
|
|||||||
|
package com.printcalculator.controller;
|
||||||
|
|
||||||
|
import com.printcalculator.dto.*;
|
||||||
|
import com.printcalculator.entity.*;
|
||||||
|
import com.printcalculator.repository.*;
|
||||||
|
import com.printcalculator.service.InvoicePdfRenderingService;
|
||||||
|
import com.printcalculator.service.OrderService;
|
||||||
|
import com.printcalculator.service.QrBillService;
|
||||||
|
import com.printcalculator.service.StorageService;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/orders")
|
||||||
|
public class OrderController {
|
||||||
|
|
||||||
|
private final OrderService orderService;
|
||||||
|
private final OrderRepository orderRepo;
|
||||||
|
private final OrderItemRepository orderItemRepo;
|
||||||
|
private final QuoteSessionRepository quoteSessionRepo;
|
||||||
|
private final QuoteLineItemRepository quoteLineItemRepo;
|
||||||
|
private final CustomerRepository customerRepo;
|
||||||
|
private final StorageService storageService;
|
||||||
|
private final InvoicePdfRenderingService invoiceService;
|
||||||
|
private final QrBillService qrBillService;
|
||||||
|
|
||||||
|
|
||||||
|
public OrderController(OrderService orderService,
|
||||||
|
OrderRepository orderRepo,
|
||||||
|
OrderItemRepository orderItemRepo,
|
||||||
|
QuoteSessionRepository quoteSessionRepo,
|
||||||
|
QuoteLineItemRepository quoteLineItemRepo,
|
||||||
|
CustomerRepository customerRepo,
|
||||||
|
StorageService storageService,
|
||||||
|
InvoicePdfRenderingService invoiceService,
|
||||||
|
QrBillService qrBillService) {
|
||||||
|
this.orderService = orderService;
|
||||||
|
this.orderRepo = orderRepo;
|
||||||
|
this.orderItemRepo = orderItemRepo;
|
||||||
|
this.quoteSessionRepo = quoteSessionRepo;
|
||||||
|
this.quoteLineItemRepo = quoteLineItemRepo;
|
||||||
|
this.customerRepo = customerRepo;
|
||||||
|
this.storageService = storageService;
|
||||||
|
this.invoiceService = invoiceService;
|
||||||
|
this.qrBillService = qrBillService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 1. Create Order from Quote
|
||||||
|
@PostMapping("/from-quote/{quoteSessionId}")
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<OrderDto> createOrderFromQuote(
|
||||||
|
@PathVariable UUID quoteSessionId,
|
||||||
|
@RequestBody com.printcalculator.dto.CreateOrderRequest request
|
||||||
|
) {
|
||||||
|
Order order = orderService.createOrderFromQuote(quoteSessionId, request);
|
||||||
|
List<OrderItem> items = orderItemRepo.findByOrder_Id(order.getId());
|
||||||
|
return ResponseEntity.ok(convertToDto(order, items));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/{orderId}/items/{orderItemId}/file", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<Void> uploadOrderItemFile(
|
||||||
|
@PathVariable UUID orderId,
|
||||||
|
@PathVariable UUID orderItemId,
|
||||||
|
@RequestParam("file") MultipartFile file
|
||||||
|
) throws IOException {
|
||||||
|
|
||||||
|
OrderItem item = orderItemRepo.findById(orderItemId)
|
||||||
|
.orElseThrow(() -> new RuntimeException("OrderItem not found"));
|
||||||
|
|
||||||
|
if (!item.getOrder().getId().equals(orderId)) {
|
||||||
|
return ResponseEntity.badRequest().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
String relativePath = item.getStoredRelativePath();
|
||||||
|
if (relativePath == null || relativePath.equals("PENDING")) {
|
||||||
|
String ext = getExtension(file.getOriginalFilename());
|
||||||
|
String storedFilename = UUID.randomUUID().toString() + "." + ext;
|
||||||
|
relativePath = "orders/" + orderId + "/3d-files/" + orderItemId + "/" + storedFilename;
|
||||||
|
item.setStoredRelativePath(relativePath);
|
||||||
|
item.setStoredFilename(storedFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
storageService.store(file, Paths.get(relativePath));
|
||||||
|
item.setFileSizeBytes(file.getSize());
|
||||||
|
item.setMimeType(file.getContentType());
|
||||||
|
orderItemRepo.save(item);
|
||||||
|
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{orderId}")
|
||||||
|
public ResponseEntity<OrderDto> getOrder(@PathVariable UUID orderId) {
|
||||||
|
return orderRepo.findById(orderId)
|
||||||
|
.map(o -> {
|
||||||
|
List<OrderItem> items = orderItemRepo.findByOrder_Id(o.getId());
|
||||||
|
return ResponseEntity.ok(convertToDto(o, items));
|
||||||
|
})
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{orderId}/invoice")
|
||||||
|
public ResponseEntity<byte[]> getInvoice(@PathVariable UUID orderId) {
|
||||||
|
Order order = orderRepo.findById(orderId)
|
||||||
|
.orElseThrow(() -> new RuntimeException("Order not found"));
|
||||||
|
|
||||||
|
List<OrderItem> items = orderItemRepo.findByOrder_Id(orderId);
|
||||||
|
|
||||||
|
Map<String, Object> vars = new HashMap<>();
|
||||||
|
vars.put("sellerDisplayName", "3D Fab Switzerland");
|
||||||
|
vars.put("sellerAddressLine1", "Sede Ticino, Svizzera");
|
||||||
|
vars.put("sellerAddressLine2", "Sede Bienne, Svizzera");
|
||||||
|
vars.put("sellerEmail", "info@3dfab.ch");
|
||||||
|
|
||||||
|
vars.put("invoiceNumber", "INV-" + order.getId().toString().substring(0, 8).toUpperCase());
|
||||||
|
vars.put("invoiceDate", order.getCreatedAt().format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||||
|
vars.put("dueDate", order.getCreatedAt().plusDays(7).format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||||
|
|
||||||
|
String buyerName = order.getBillingCustomerType().equals("BUSINESS")
|
||||||
|
? order.getBillingCompanyName()
|
||||||
|
: order.getBillingFirstName() + " " + order.getBillingLastName();
|
||||||
|
vars.put("buyerDisplayName", buyerName);
|
||||||
|
vars.put("buyerAddressLine1", order.getBillingAddressLine1());
|
||||||
|
vars.put("buyerAddressLine2", order.getBillingZip() + " " + order.getBillingCity() + ", " + order.getBillingCountryCode());
|
||||||
|
|
||||||
|
List<Map<String, Object>> invoiceLineItems = items.stream().map(i -> {
|
||||||
|
Map<String, Object> line = new HashMap<>();
|
||||||
|
line.put("description", "Stampa 3D: " + i.getOriginalFilename());
|
||||||
|
line.put("quantity", i.getQuantity());
|
||||||
|
line.put("unitPriceFormatted", String.format("CHF %.2f", i.getUnitPriceChf()));
|
||||||
|
line.put("lineTotalFormatted", String.format("CHF %.2f", i.getLineTotalChf()));
|
||||||
|
return line;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
Map<String, Object> setupLine = new HashMap<>();
|
||||||
|
setupLine.put("description", "Costo Setup");
|
||||||
|
setupLine.put("quantity", 1);
|
||||||
|
setupLine.put("unitPriceFormatted", String.format("CHF %.2f", order.getSetupCostChf()));
|
||||||
|
setupLine.put("lineTotalFormatted", String.format("CHF %.2f", order.getSetupCostChf()));
|
||||||
|
invoiceLineItems.add(setupLine);
|
||||||
|
|
||||||
|
Map<String, Object> shippingLine = new HashMap<>();
|
||||||
|
shippingLine.put("description", "Spedizione");
|
||||||
|
shippingLine.put("quantity", 1);
|
||||||
|
shippingLine.put("unitPriceFormatted", String.format("CHF %.2f", order.getShippingCostChf()));
|
||||||
|
shippingLine.put("lineTotalFormatted", String.format("CHF %.2f", order.getShippingCostChf()));
|
||||||
|
invoiceLineItems.add(shippingLine);
|
||||||
|
|
||||||
|
vars.put("invoiceLineItems", invoiceLineItems);
|
||||||
|
vars.put("subtotalFormatted", String.format("CHF %.2f", order.getSubtotalChf()));
|
||||||
|
vars.put("grandTotalFormatted", String.format("CHF %.2f", order.getTotalChf()));
|
||||||
|
vars.put("paymentTermsText", "Pagamento entro 7 giorni via Bonifico o TWINT. Grazie.");
|
||||||
|
|
||||||
|
String qrBillSvg = new String(qrBillService.generateQrBillSvg(order), java.nio.charset.StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
// Strip XML declaration and DOCTYPE if present, as they validity break the embedding HTML page
|
||||||
|
if (qrBillSvg.contains("<?xml")) {
|
||||||
|
int svgStartIndex = qrBillSvg.indexOf("<svg");
|
||||||
|
if (svgStartIndex != -1) {
|
||||||
|
qrBillSvg = qrBillSvg.substring(svgStartIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] pdf = invoiceService.generateInvoicePdfBytesFromTemplate(vars, qrBillSvg);
|
||||||
|
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.header("Content-Disposition", "attachment; filename=\"invoice-" + orderId + ".pdf\"")
|
||||||
|
.contentType(MediaType.APPLICATION_PDF)
|
||||||
|
.body(pdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getExtension(String filename) {
|
||||||
|
if (filename == null) return "stl";
|
||||||
|
int i = filename.lastIndexOf('.');
|
||||||
|
if (i > 0) {
|
||||||
|
return filename.substring(i + 1);
|
||||||
|
}
|
||||||
|
return "stl";
|
||||||
|
}
|
||||||
|
|
||||||
|
private OrderDto convertToDto(Order order, List<OrderItem> items) {
|
||||||
|
OrderDto dto = new OrderDto();
|
||||||
|
dto.setId(order.getId());
|
||||||
|
dto.setStatus(order.getStatus());
|
||||||
|
dto.setCustomerEmail(order.getCustomerEmail());
|
||||||
|
dto.setCustomerPhone(order.getCustomerPhone());
|
||||||
|
dto.setBillingCustomerType(order.getBillingCustomerType());
|
||||||
|
dto.setCurrency(order.getCurrency());
|
||||||
|
dto.setSetupCostChf(order.getSetupCostChf());
|
||||||
|
dto.setShippingCostChf(order.getShippingCostChf());
|
||||||
|
dto.setDiscountChf(order.getDiscountChf());
|
||||||
|
dto.setSubtotalChf(order.getSubtotalChf());
|
||||||
|
dto.setTotalChf(order.getTotalChf());
|
||||||
|
dto.setCreatedAt(order.getCreatedAt());
|
||||||
|
dto.setShippingSameAsBilling(order.getShippingSameAsBilling());
|
||||||
|
|
||||||
|
AddressDto billing = new AddressDto();
|
||||||
|
billing.setFirstName(order.getBillingFirstName());
|
||||||
|
billing.setLastName(order.getBillingLastName());
|
||||||
|
billing.setCompanyName(order.getBillingCompanyName());
|
||||||
|
billing.setContactPerson(order.getBillingContactPerson());
|
||||||
|
billing.setAddressLine1(order.getBillingAddressLine1());
|
||||||
|
billing.setAddressLine2(order.getBillingAddressLine2());
|
||||||
|
billing.setZip(order.getBillingZip());
|
||||||
|
billing.setCity(order.getBillingCity());
|
||||||
|
billing.setCountryCode(order.getBillingCountryCode());
|
||||||
|
dto.setBillingAddress(billing);
|
||||||
|
|
||||||
|
if (!order.getShippingSameAsBilling()) {
|
||||||
|
AddressDto shipping = new AddressDto();
|
||||||
|
shipping.setFirstName(order.getShippingFirstName());
|
||||||
|
shipping.setLastName(order.getShippingLastName());
|
||||||
|
shipping.setCompanyName(order.getShippingCompanyName());
|
||||||
|
shipping.setContactPerson(order.getShippingContactPerson());
|
||||||
|
shipping.setAddressLine1(order.getShippingAddressLine1());
|
||||||
|
shipping.setAddressLine2(order.getShippingAddressLine2());
|
||||||
|
shipping.setZip(order.getShippingZip());
|
||||||
|
shipping.setCity(order.getShippingCity());
|
||||||
|
shipping.setCountryCode(order.getShippingCountryCode());
|
||||||
|
dto.setShippingAddress(shipping);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<OrderItemDto> itemDtos = items.stream().map(i -> {
|
||||||
|
OrderItemDto idto = new OrderItemDto();
|
||||||
|
idto.setId(i.getId());
|
||||||
|
idto.setOriginalFilename(i.getOriginalFilename());
|
||||||
|
idto.setMaterialCode(i.getMaterialCode());
|
||||||
|
idto.setColorCode(i.getColorCode());
|
||||||
|
idto.setQuantity(i.getQuantity());
|
||||||
|
idto.setPrintTimeSeconds(i.getPrintTimeSeconds());
|
||||||
|
idto.setMaterialGrams(i.getMaterialGrams());
|
||||||
|
idto.setUnitPriceChf(i.getUnitPriceChf());
|
||||||
|
idto.setLineTotalChf(i.getLineTotalChf());
|
||||||
|
return idto;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
dto.setItems(itemDtos);
|
||||||
|
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,43 +1,101 @@
|
|||||||
package com.printcalculator.controller;
|
package com.printcalculator.controller;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.PrinterMachine;
|
||||||
|
import com.printcalculator.exception.ModelTooLargeException;
|
||||||
import com.printcalculator.model.PrintStats;
|
import com.printcalculator.model.PrintStats;
|
||||||
import com.printcalculator.model.QuoteResult;
|
import com.printcalculator.model.QuoteResult;
|
||||||
|
import com.printcalculator.model.StlBounds;
|
||||||
|
import com.printcalculator.repository.PrinterMachineRepository;
|
||||||
import com.printcalculator.service.QuoteCalculator;
|
import com.printcalculator.service.QuoteCalculator;
|
||||||
|
import com.printcalculator.service.ProfileManager;
|
||||||
import com.printcalculator.service.SlicerService;
|
import com.printcalculator.service.SlicerService;
|
||||||
|
import com.printcalculator.service.StlService;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin(origins = "*") // Allow all for development
|
|
||||||
public class QuoteController {
|
public class QuoteController {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(QuoteController.class.getName());
|
||||||
|
|
||||||
private final SlicerService slicerService;
|
private final SlicerService slicerService;
|
||||||
|
private final StlService stlService;
|
||||||
private final QuoteCalculator quoteCalculator;
|
private final QuoteCalculator quoteCalculator;
|
||||||
|
private final PrinterMachineRepository machineRepo;
|
||||||
|
private final ProfileManager profileManager;
|
||||||
|
|
||||||
// Defaults
|
// Defaults (using aliases defined in ProfileManager)
|
||||||
private static final String DEFAULT_MACHINE = "Bambu_Lab_A1_machine";
|
private static final String DEFAULT_FILAMENT = "pla_basic";
|
||||||
private static final String DEFAULT_FILAMENT = "Bambu_PLA_Basic";
|
private static final String DEFAULT_PROCESS = "standard";
|
||||||
private static final String DEFAULT_PROCESS = "Bambu_Process_0.20_Standard";
|
|
||||||
|
|
||||||
public QuoteController(SlicerService slicerService, QuoteCalculator quoteCalculator) {
|
public QuoteController(SlicerService slicerService, StlService stlService, QuoteCalculator quoteCalculator, PrinterMachineRepository machineRepo, ProfileManager profileManager) {
|
||||||
this.slicerService = slicerService;
|
this.slicerService = slicerService;
|
||||||
|
this.stlService = stlService;
|
||||||
this.quoteCalculator = quoteCalculator;
|
this.quoteCalculator = quoteCalculator;
|
||||||
|
this.machineRepo = machineRepo;
|
||||||
|
this.profileManager = profileManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/api/quote")
|
@PostMapping("/api/quote")
|
||||||
public ResponseEntity<QuoteResult> calculateQuote(
|
public ResponseEntity<QuoteResult> calculateQuote(
|
||||||
@RequestParam("file") MultipartFile file,
|
@RequestParam("file") MultipartFile file,
|
||||||
@RequestParam(value = "machine", defaultValue = DEFAULT_MACHINE) String machine,
|
@RequestParam(value = "filament", required = false, defaultValue = DEFAULT_FILAMENT) String filament,
|
||||||
@RequestParam(value = "filament", defaultValue = DEFAULT_FILAMENT) String filament,
|
@RequestParam(value = "process", required = false) String process,
|
||||||
@RequestParam(value = "process", defaultValue = DEFAULT_PROCESS) String process
|
@RequestParam(value = "quality", required = false) String quality,
|
||||||
|
// Advanced Options
|
||||||
|
@RequestParam(value = "infill_density", required = false) Integer infillDensity,
|
||||||
|
@RequestParam(value = "infill_pattern", required = false) String infillPattern,
|
||||||
|
@RequestParam(value = "layer_height", required = false) Double layerHeight,
|
||||||
|
@RequestParam(value = "nozzle_diameter", required = false) Double nozzleDiameter,
|
||||||
|
@RequestParam(value = "support_enabled", required = false, defaultValue = "false") Boolean supportEnabled
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
|
|
||||||
return processRequest(file, machine, filament, process);
|
// ... process selection logic ...
|
||||||
|
String actualProcess = process;
|
||||||
|
if (actualProcess == null || actualProcess.isEmpty()) {
|
||||||
|
if (quality != null && !quality.isEmpty()) {
|
||||||
|
actualProcess = quality;
|
||||||
|
} else {
|
||||||
|
actualProcess = DEFAULT_PROCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare Overrides
|
||||||
|
Map<String, String> processOverrides = new HashMap<>();
|
||||||
|
Map<String, String> machineOverrides = new HashMap<>();
|
||||||
|
|
||||||
|
if (infillDensity != null) {
|
||||||
|
processOverrides.put("sparse_infill_density", infillDensity + "%");
|
||||||
|
}
|
||||||
|
if (infillPattern != null && !infillPattern.isEmpty()) {
|
||||||
|
processOverrides.put("sparse_infill_pattern", infillPattern);
|
||||||
|
}
|
||||||
|
if (layerHeight != null) {
|
||||||
|
processOverrides.put("layer_height", String.valueOf(layerHeight));
|
||||||
|
}
|
||||||
|
if (supportEnabled != null) {
|
||||||
|
processOverrides.put("enable_support", supportEnabled ? "1" : "0");
|
||||||
|
if (supportEnabled) {
|
||||||
|
processOverrides.put("support_threshold_angle", "45");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nozzleDiameter != null) {
|
||||||
|
machineOverrides.put("nozzle_diameter", String.valueOf(nozzleDiameter));
|
||||||
|
// Also need to ensure the printer profile is compatible or just override?
|
||||||
|
// Usually nozzle diameter changes require a different printer profile or deep overrides.
|
||||||
|
// For now, we trust the override key works on the base profile.
|
||||||
|
}
|
||||||
|
|
||||||
|
return processRequest(file, filament, actualProcess, machineOverrides, processOverrides, nozzleDiameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/calculate/stl")
|
@PostMapping("/calculate/stl")
|
||||||
@@ -45,32 +103,91 @@ public class QuoteController {
|
|||||||
@RequestParam("file") MultipartFile file
|
@RequestParam("file") MultipartFile file
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
// Legacy endpoint uses defaults
|
// Legacy endpoint uses defaults
|
||||||
return processRequest(file, DEFAULT_MACHINE, DEFAULT_FILAMENT, DEFAULT_PROCESS);
|
return processRequest(file, DEFAULT_FILAMENT, DEFAULT_PROCESS, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseEntity<QuoteResult> processRequest(MultipartFile file, String machine, String filament, String process) throws IOException {
|
private ResponseEntity<QuoteResult> processRequest(MultipartFile file, String filament, String process,
|
||||||
|
Map<String, String> machineOverrides,
|
||||||
|
Map<String, String> processOverrides,
|
||||||
|
Double nozzleDiameter) throws IOException {
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
return ResponseEntity.badRequest().build();
|
return ResponseEntity.badRequest().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch Default Active Machine
|
||||||
|
PrinterMachine machine = machineRepo.findFirstByIsActiveTrue()
|
||||||
|
.orElseThrow(() -> new IOException("No active printer found in database"));
|
||||||
|
|
||||||
// Save uploaded file temporarily
|
// Save uploaded file temporarily
|
||||||
Path tempInput = Files.createTempFile("upload_", "_" + file.getOriginalFilename());
|
Path tempInput = Files.createTempFile("upload_", "_" + file.getOriginalFilename());
|
||||||
|
com.printcalculator.model.StlShiftResult shift = null;
|
||||||
try {
|
try {
|
||||||
file.transferTo(tempInput.toFile());
|
file.transferTo(tempInput.toFile());
|
||||||
|
|
||||||
// Slice
|
// Use profile from machine or fallback
|
||||||
PrintStats stats = slicerService.slice(tempInput.toFile(), machine, filament, process);
|
String slicerMachineProfile = machine.getSlicerMachineProfile();
|
||||||
|
if (slicerMachineProfile == null || slicerMachineProfile.isEmpty()) {
|
||||||
|
slicerMachineProfile = "bambu_a1";
|
||||||
|
}
|
||||||
|
slicerMachineProfile = profileManager.resolveMachineProfileName(slicerMachineProfile, nozzleDiameter);
|
||||||
|
|
||||||
|
// Validate model size against machine volume
|
||||||
|
StlBounds bounds = validateModelSize(tempInput.toFile(), machine);
|
||||||
|
|
||||||
|
// Auto-center if needed
|
||||||
|
shift = stlService.shiftToFitIfNeeded(
|
||||||
|
tempInput.toFile(),
|
||||||
|
bounds,
|
||||||
|
machine.getBuildVolumeXMm(),
|
||||||
|
machine.getBuildVolumeYMm(),
|
||||||
|
machine.getBuildVolumeZMm()
|
||||||
|
);
|
||||||
|
java.io.File sliceInput = shift.shifted() ? shift.shiftedPath().toFile() : tempInput.toFile();
|
||||||
|
if (shift.shifted()) {
|
||||||
|
logger.info(String.format("Auto-centered STL by offset (mm): x=%.3f y=%.3f z=%.3f",
|
||||||
|
shift.offsetX(), shift.offsetY(), shift.offsetZ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintStats stats = slicerService.slice(sliceInput, slicerMachineProfile, filament, process, machineOverrides, processOverrides);
|
||||||
|
|
||||||
// Calculate Quote
|
// Calculate Quote (Pass machine display name for pricing lookup)
|
||||||
QuoteResult result = quoteCalculator.calculate(stats);
|
QuoteResult result = quoteCalculator.calculate(stats, machine.getPrinterDisplayName(), filament);
|
||||||
|
|
||||||
return ResponseEntity.ok(result);
|
return ResponseEntity.ok(result);
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return ResponseEntity.internalServerError().build(); // Simplify error handling for now
|
|
||||||
} finally {
|
} finally {
|
||||||
Files.deleteIfExists(tempInput);
|
Files.deleteIfExists(tempInput);
|
||||||
|
if (shift != null && shift.shifted()) {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(shift.shiftedPath());
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private StlBounds validateModelSize(java.io.File stlFile, PrinterMachine machine) throws IOException {
|
||||||
|
StlBounds bounds = stlService.readBounds(stlFile);
|
||||||
|
double x = bounds.sizeX();
|
||||||
|
double y = bounds.sizeY();
|
||||||
|
double z = bounds.sizeZ();
|
||||||
|
|
||||||
|
int bx = machine.getBuildVolumeXMm();
|
||||||
|
int by = machine.getBuildVolumeYMm();
|
||||||
|
int bz = machine.getBuildVolumeZMm();
|
||||||
|
|
||||||
|
logger.info(String.format(
|
||||||
|
"STL bounds (mm): min(%.3f,%.3f,%.3f) max(%.3f,%.3f,%.3f) size(%.3f,%.3f,%.3f) bed(%d,%d,%d)",
|
||||||
|
bounds.minX(), bounds.minY(), bounds.minZ(),
|
||||||
|
bounds.maxX(), bounds.maxY(), bounds.maxZ(),
|
||||||
|
x, y, z, bx, by, bz
|
||||||
|
));
|
||||||
|
|
||||||
|
double eps = 0.01;
|
||||||
|
boolean fits = (x <= bx + eps && y <= by + eps && z <= bz + eps)
|
||||||
|
|| (y <= bx + eps && x <= by + eps && z <= bz + eps);
|
||||||
|
|
||||||
|
if (!fits) {
|
||||||
|
throw new ModelTooLargeException(x, y, z, bx, by, bz);
|
||||||
|
}
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,468 @@
|
|||||||
|
package com.printcalculator.controller;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.PrinterMachine;
|
||||||
|
import com.printcalculator.entity.QuoteLineItem;
|
||||||
|
import com.printcalculator.entity.QuoteSession;
|
||||||
|
import com.printcalculator.exception.ModelTooLargeException;
|
||||||
|
import com.printcalculator.model.PrintStats;
|
||||||
|
import com.printcalculator.model.QuoteResult;
|
||||||
|
import com.printcalculator.model.StlBounds;
|
||||||
|
import com.printcalculator.repository.PrinterMachineRepository;
|
||||||
|
import com.printcalculator.repository.QuoteLineItemRepository;
|
||||||
|
import com.printcalculator.repository.QuoteSessionRepository;
|
||||||
|
import com.printcalculator.service.QuoteCalculator;
|
||||||
|
import com.printcalculator.service.ProfileManager;
|
||||||
|
import com.printcalculator.service.SlicerService;
|
||||||
|
import com.printcalculator.service.StlService;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.UrlResource;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/quote-sessions")
|
||||||
|
|
||||||
|
public class QuoteSessionController {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(QuoteSessionController.class.getName());
|
||||||
|
|
||||||
|
private final QuoteSessionRepository sessionRepo;
|
||||||
|
private final QuoteLineItemRepository lineItemRepo;
|
||||||
|
private final SlicerService slicerService;
|
||||||
|
private final StlService stlService;
|
||||||
|
private final QuoteCalculator quoteCalculator;
|
||||||
|
private final ProfileManager profileManager;
|
||||||
|
private final PrinterMachineRepository machineRepo;
|
||||||
|
private final com.printcalculator.repository.PricingPolicyRepository pricingRepo;
|
||||||
|
private final com.printcalculator.service.StorageService storageService;
|
||||||
|
|
||||||
|
// Defaults
|
||||||
|
private static final String DEFAULT_FILAMENT = "pla_basic";
|
||||||
|
private static final String DEFAULT_PROCESS = "standard";
|
||||||
|
|
||||||
|
public QuoteSessionController(QuoteSessionRepository sessionRepo,
|
||||||
|
QuoteLineItemRepository lineItemRepo,
|
||||||
|
SlicerService slicerService,
|
||||||
|
StlService stlService,
|
||||||
|
QuoteCalculator quoteCalculator,
|
||||||
|
ProfileManager profileManager,
|
||||||
|
PrinterMachineRepository machineRepo,
|
||||||
|
com.printcalculator.repository.PricingPolicyRepository pricingRepo,
|
||||||
|
com.printcalculator.service.StorageService storageService) {
|
||||||
|
this.sessionRepo = sessionRepo;
|
||||||
|
this.lineItemRepo = lineItemRepo;
|
||||||
|
this.slicerService = slicerService;
|
||||||
|
this.stlService = stlService;
|
||||||
|
this.quoteCalculator = quoteCalculator;
|
||||||
|
this.profileManager = profileManager;
|
||||||
|
this.machineRepo = machineRepo;
|
||||||
|
this.pricingRepo = pricingRepo;
|
||||||
|
this.storageService = storageService;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Start a new empty session
|
||||||
|
@PostMapping(value = "")
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<QuoteSession> createSession() {
|
||||||
|
QuoteSession session = new QuoteSession();
|
||||||
|
session.setStatus("ACTIVE");
|
||||||
|
session.setPricingVersion("v1");
|
||||||
|
// Default material/settings will be set when items are added or updated?
|
||||||
|
// For now set safe defaults
|
||||||
|
session.setMaterialCode("pla_basic");
|
||||||
|
session.setSupportsEnabled(false);
|
||||||
|
session.setCreatedAt(OffsetDateTime.now());
|
||||||
|
session.setExpiresAt(OffsetDateTime.now().plusDays(30));
|
||||||
|
|
||||||
|
var policy = pricingRepo.findFirstByIsActiveTrueOrderByValidFromDesc();
|
||||||
|
session.setSetupCostChf(policy != null ? policy.getFixedJobFeeChf() : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
session = sessionRepo.save(session);
|
||||||
|
return ResponseEntity.ok(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Add item to existing session
|
||||||
|
@PostMapping(value = "/{id}/line-items", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<QuoteLineItem> addItemToExistingSession(
|
||||||
|
@PathVariable UUID id,
|
||||||
|
@RequestPart("settings") com.printcalculator.dto.PrintSettingsDto settings,
|
||||||
|
@RequestPart("file") MultipartFile file
|
||||||
|
) throws IOException {
|
||||||
|
QuoteSession session = sessionRepo.findById(id)
|
||||||
|
.orElseThrow(() -> new RuntimeException("Session not found"));
|
||||||
|
|
||||||
|
QuoteLineItem item = addItemToSession(session, file, settings);
|
||||||
|
return ResponseEntity.ok(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to add item
|
||||||
|
private QuoteLineItem addItemToSession(QuoteSession session, MultipartFile file, com.printcalculator.dto.PrintSettingsDto settings) throws IOException {
|
||||||
|
if (file.isEmpty()) throw new IOException("File is empty");
|
||||||
|
|
||||||
|
// 1. Define Persistent Storage Path
|
||||||
|
// Structure: quotes/{sessionId}/{uuid}.{ext} (inside storage root)
|
||||||
|
|
||||||
|
String originalFilename = file.getOriginalFilename();
|
||||||
|
String ext = originalFilename != null && originalFilename.contains(".")
|
||||||
|
? originalFilename.substring(originalFilename.lastIndexOf("."))
|
||||||
|
: ".stl";
|
||||||
|
|
||||||
|
String storedFilename = UUID.randomUUID() + ext;
|
||||||
|
Path relativePath = Paths.get("quotes", session.getId().toString(), storedFilename);
|
||||||
|
|
||||||
|
// Save file
|
||||||
|
storageService.store(file, relativePath);
|
||||||
|
|
||||||
|
// Resolve absolute path for slicing and storage usage
|
||||||
|
Path persistentPath = storageService.loadAsResource(relativePath).getFile().toPath();
|
||||||
|
|
||||||
|
com.printcalculator.model.StlShiftResult shift = null;
|
||||||
|
try {
|
||||||
|
// Apply Basic/Advanced Logic
|
||||||
|
applyPrintSettings(settings);
|
||||||
|
|
||||||
|
// REAL SLICING
|
||||||
|
// 1. Pick Machine (default to first active or specific)
|
||||||
|
PrinterMachine machine = machineRepo.findFirstByIsActiveTrue()
|
||||||
|
.orElseThrow(() -> new RuntimeException("No active printer found"));
|
||||||
|
|
||||||
|
// 2. Validate model size against machine volume
|
||||||
|
StlBounds bounds = validateModelSize(persistentPath.toFile(), machine);
|
||||||
|
|
||||||
|
// 2b. Auto-center if needed (keeps the stored STL unchanged)
|
||||||
|
shift = stlService.shiftToFitIfNeeded(
|
||||||
|
persistentPath.toFile(),
|
||||||
|
bounds,
|
||||||
|
machine.getBuildVolumeXMm(),
|
||||||
|
machine.getBuildVolumeYMm(),
|
||||||
|
machine.getBuildVolumeZMm()
|
||||||
|
);
|
||||||
|
java.io.File sliceInput = shift.shifted() ? shift.shiftedPath().toFile() : persistentPath.toFile();
|
||||||
|
if (shift.shifted()) {
|
||||||
|
logger.info(String.format("Auto-centered STL by offset (mm): x=%.3f y=%.3f z=%.3f",
|
||||||
|
shift.offsetX(), shift.offsetY(), shift.offsetZ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Pick Profiles
|
||||||
|
String machineProfile = machine.getSlicerMachineProfile();
|
||||||
|
if (machineProfile == null || machineProfile.isBlank()) {
|
||||||
|
machineProfile = machine.getPrinterDisplayName(); // e.g. "Bambu Lab A1 0.4 nozzle"
|
||||||
|
}
|
||||||
|
if (machineProfile == null || machineProfile.isBlank()) {
|
||||||
|
machineProfile = "bambu_a1"; // final fallback (alias handled in ProfileManager)
|
||||||
|
}
|
||||||
|
machineProfile = profileManager.resolveMachineProfileName(machineProfile, settings.getNozzleDiameter());
|
||||||
|
|
||||||
|
String filamentProfile = "Generic " + (settings.getMaterial() != null ? settings.getMaterial().toUpperCase() : "PLA");
|
||||||
|
// Mapping: "pla_basic" -> "Generic PLA", "petg_basic" -> "Generic PETG"
|
||||||
|
if (settings.getMaterial() != null) {
|
||||||
|
if (settings.getMaterial().toLowerCase().contains("pla")) filamentProfile = "Generic PLA";
|
||||||
|
else if (settings.getMaterial().toLowerCase().contains("petg")) filamentProfile = "Generic PETG";
|
||||||
|
else if (settings.getMaterial().toLowerCase().contains("tpu")) filamentProfile = "Generic TPU";
|
||||||
|
else if (settings.getMaterial().toLowerCase().contains("abs")) filamentProfile = "Generic ABS";
|
||||||
|
|
||||||
|
// Update Session Material
|
||||||
|
session.setMaterialCode(settings.getMaterial());
|
||||||
|
} else {
|
||||||
|
// Fallback if null?
|
||||||
|
session.setMaterialCode("pla_basic");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update Session Settings for Persistence
|
||||||
|
if (settings.getNozzleDiameter() != null) session.setNozzleDiameterMm(BigDecimal.valueOf(settings.getNozzleDiameter()));
|
||||||
|
if (settings.getLayerHeight() != null) session.setLayerHeightMm(BigDecimal.valueOf(settings.getLayerHeight()));
|
||||||
|
if (settings.getInfillDensity() != null) session.setInfillPercent(settings.getInfillDensity().intValue());
|
||||||
|
if (settings.getInfillPattern() != null) session.setInfillPattern(settings.getInfillPattern());
|
||||||
|
if (settings.getSupportsEnabled() != null) session.setSupportsEnabled(settings.getSupportsEnabled());
|
||||||
|
if (settings.getNotes() != null) session.setNotes(settings.getNotes());
|
||||||
|
|
||||||
|
// Save session updates
|
||||||
|
sessionRepo.save(session);
|
||||||
|
|
||||||
|
String processProfile = "0.20mm Standard @BBL A1";
|
||||||
|
// Mapping quality to process
|
||||||
|
// "standard" -> "0.20mm Standard @BBL A1"
|
||||||
|
// "draft" -> "0.28mm Extra Draft @BBL A1"
|
||||||
|
// "high" -> "0.12mm Fine @BBL A1" (approx names, need to be exact for Orca)
|
||||||
|
// Let's use robust defaults or simple overrides
|
||||||
|
if (settings.getLayerHeight() != null) {
|
||||||
|
if (settings.getLayerHeight() >= 0.28) processProfile = "0.28mm Extra Draft @BBL A1";
|
||||||
|
else if (settings.getLayerHeight() <= 0.12) processProfile = "0.12mm Fine @BBL A1";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build overrides map from settings
|
||||||
|
// Build overrides map from settings
|
||||||
|
Map<String, String> processOverrides = new HashMap<>();
|
||||||
|
if (settings.getLayerHeight() != null) processOverrides.put("layer_height", String.valueOf(settings.getLayerHeight()));
|
||||||
|
if (settings.getInfillDensity() != null) processOverrides.put("sparse_infill_density", settings.getInfillDensity() + "%");
|
||||||
|
if (settings.getInfillPattern() != null) processOverrides.put("sparse_infill_pattern", settings.getInfillPattern());
|
||||||
|
if (settings.getSupportsEnabled() != null) {
|
||||||
|
processOverrides.put("enable_support", settings.getSupportsEnabled() ? "1" : "0");
|
||||||
|
// If enabled, use a more permissive threshold (45 deg) by default
|
||||||
|
// to avoid expensive supports on things that don't strictly need them
|
||||||
|
if (settings.getSupportsEnabled()) {
|
||||||
|
processOverrides.put("support_threshold_angle", "45");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> machineOverrides = new HashMap<>();
|
||||||
|
if (settings.getNozzleDiameter() != null) {
|
||||||
|
machineOverrides.put("nozzle_diameter", String.valueOf(settings.getNozzleDiameter()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Slice (Use persistent path)
|
||||||
|
PrintStats stats = slicerService.slice(
|
||||||
|
sliceInput,
|
||||||
|
machineProfile,
|
||||||
|
filamentProfile,
|
||||||
|
processProfile,
|
||||||
|
machineOverrides, // machine overrides
|
||||||
|
processOverrides
|
||||||
|
);
|
||||||
|
|
||||||
|
// 5. Calculate Quote
|
||||||
|
QuoteResult result = quoteCalculator.calculate(stats, machine.getPrinterDisplayName(), filamentProfile);
|
||||||
|
|
||||||
|
// 6. Create Line Item
|
||||||
|
QuoteLineItem item = new QuoteLineItem();
|
||||||
|
item.setQuoteSession(session);
|
||||||
|
item.setOriginalFilename(file.getOriginalFilename());
|
||||||
|
item.setStoredPath(persistentPath.toString()); // SAVE PATH
|
||||||
|
item.setQuantity(1);
|
||||||
|
item.setColorCode(settings.getColor() != null ? settings.getColor() : "#FFFFFF");
|
||||||
|
item.setStatus("READY"); // or CALCULATED
|
||||||
|
|
||||||
|
item.setPrintTimeSeconds((int) stats.getPrintTimeSeconds());
|
||||||
|
item.setMaterialGrams(BigDecimal.valueOf(stats.getFilamentWeightGrams()));
|
||||||
|
item.setUnitPriceChf(BigDecimal.valueOf(result.getTotalPrice()));
|
||||||
|
|
||||||
|
// Store breakdown
|
||||||
|
Map<String, Object> breakdown = new HashMap<>();
|
||||||
|
breakdown.put("machine_cost", result.getTotalPrice() - result.getSetupCost()); // Approximation?
|
||||||
|
// Better: QuoteResult could expose detailed breakdown. For now just storing what we have.
|
||||||
|
breakdown.put("setup_fee", result.getSetupCost());
|
||||||
|
item.setPricingBreakdown(breakdown);
|
||||||
|
|
||||||
|
// Dimensions from STL
|
||||||
|
item.setBoundingBoxXMm(BigDecimal.valueOf(bounds.sizeX()));
|
||||||
|
item.setBoundingBoxYMm(BigDecimal.valueOf(bounds.sizeY()));
|
||||||
|
item.setBoundingBoxZMm(BigDecimal.valueOf(bounds.sizeZ()));
|
||||||
|
|
||||||
|
item.setCreatedAt(OffsetDateTime.now());
|
||||||
|
item.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
|
||||||
|
return lineItemRepo.save(item);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Cleanup if failed
|
||||||
|
try {
|
||||||
|
storageService.delete(Paths.get("quotes", session.getId().toString(), storedFilename));
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (shift != null && shift.shifted()) {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(shift.shiftedPath());
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private StlBounds validateModelSize(java.io.File stlFile, PrinterMachine machine) throws IOException {
|
||||||
|
StlBounds bounds = stlService.readBounds(stlFile);
|
||||||
|
double x = bounds.sizeX();
|
||||||
|
double y = bounds.sizeY();
|
||||||
|
double z = bounds.sizeZ();
|
||||||
|
|
||||||
|
int bx = machine.getBuildVolumeXMm();
|
||||||
|
int by = machine.getBuildVolumeYMm();
|
||||||
|
int bz = machine.getBuildVolumeZMm();
|
||||||
|
|
||||||
|
logger.info(String.format(
|
||||||
|
"STL bounds (mm): min(%.3f,%.3f,%.3f) max(%.3f,%.3f,%.3f) size(%.3f,%.3f,%.3f) bed(%d,%d,%d)",
|
||||||
|
bounds.minX(), bounds.minY(), bounds.minZ(),
|
||||||
|
bounds.maxX(), bounds.maxY(), bounds.maxZ(),
|
||||||
|
x, y, z, bx, by, bz
|
||||||
|
));
|
||||||
|
|
||||||
|
double eps = 0.01;
|
||||||
|
boolean fits = (x <= bx + eps && y <= by + eps && z <= bz + eps)
|
||||||
|
|| (y <= bx + eps && x <= by + eps && z <= bz + eps);
|
||||||
|
|
||||||
|
if (!fits) {
|
||||||
|
throw new ModelTooLargeException(x, y, z, bx, by, bz);
|
||||||
|
}
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyPrintSettings(com.printcalculator.dto.PrintSettingsDto settings) {
|
||||||
|
if ("BASIC".equalsIgnoreCase(settings.getComplexityMode())) {
|
||||||
|
// Set defaults based on Quality
|
||||||
|
String quality = settings.getQuality() != null ? settings.getQuality().toLowerCase() : "standard";
|
||||||
|
|
||||||
|
switch (quality) {
|
||||||
|
case "draft":
|
||||||
|
settings.setLayerHeight(0.28);
|
||||||
|
settings.setInfillDensity(15.0);
|
||||||
|
settings.setInfillPattern("grid");
|
||||||
|
if (settings.getNozzleDiameter() == null) settings.setNozzleDiameter(0.4);
|
||||||
|
break;
|
||||||
|
case "high":
|
||||||
|
settings.setLayerHeight(0.12);
|
||||||
|
settings.setInfillDensity(20.0);
|
||||||
|
settings.setInfillPattern("gyroid");
|
||||||
|
if (settings.getNozzleDiameter() == null) settings.setNozzleDiameter(0.4);
|
||||||
|
break;
|
||||||
|
case "standard":
|
||||||
|
default:
|
||||||
|
settings.setLayerHeight(0.20);
|
||||||
|
settings.setInfillDensity(20.0);
|
||||||
|
settings.setInfillPattern("grid");
|
||||||
|
if (settings.getNozzleDiameter() == null) settings.setNozzleDiameter(0.4);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (settings.getSupportsEnabled() == null) settings.setSupportsEnabled(false);
|
||||||
|
} else {
|
||||||
|
// ADVANCED Mode: Use values from Frontend, set defaults if missing
|
||||||
|
if (settings.getLayerHeight() == null) settings.setLayerHeight(0.20);
|
||||||
|
if (settings.getInfillDensity() == null) settings.setInfillDensity(20.0);
|
||||||
|
if (settings.getInfillPattern() == null) settings.setInfillPattern("grid");
|
||||||
|
if (settings.getNozzleDiameter() == null) settings.setNozzleDiameter(0.4);
|
||||||
|
if (settings.getSupportsEnabled() == null) settings.setSupportsEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Update Line Item
|
||||||
|
@PatchMapping("/line-items/{lineItemId}")
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<QuoteLineItem> updateLineItem(
|
||||||
|
@PathVariable UUID lineItemId,
|
||||||
|
@RequestBody Map<String, Object> updates
|
||||||
|
) {
|
||||||
|
QuoteLineItem item = lineItemRepo.findById(lineItemId)
|
||||||
|
.orElseThrow(() -> new RuntimeException("Item not found"));
|
||||||
|
|
||||||
|
if (updates.containsKey("quantity")) {
|
||||||
|
item.setQuantity((Integer) updates.get("quantity"));
|
||||||
|
}
|
||||||
|
if (updates.containsKey("color_code")) {
|
||||||
|
item.setColorCode((String) updates.get("color_code"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recalculate price if needed?
|
||||||
|
// For now, unit price is fixed in mock. Total is calculated on GET.
|
||||||
|
|
||||||
|
item.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
return ResponseEntity.ok(lineItemRepo.save(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Delete Line Item
|
||||||
|
@DeleteMapping("/{sessionId}/line-items/{lineItemId}")
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<Void> deleteLineItem(
|
||||||
|
@PathVariable UUID sessionId,
|
||||||
|
@PathVariable UUID lineItemId
|
||||||
|
) {
|
||||||
|
// Verify item belongs to session?
|
||||||
|
QuoteLineItem item = lineItemRepo.findById(lineItemId)
|
||||||
|
.orElseThrow(() -> new RuntimeException("Item not found"));
|
||||||
|
|
||||||
|
if (!item.getQuoteSession().getId().equals(sessionId)) {
|
||||||
|
return ResponseEntity.badRequest().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
lineItemRepo.delete(item);
|
||||||
|
return ResponseEntity.noContent().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. Get Session (Session + Items + Total)
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<Map<String, Object>> getQuoteSession(@PathVariable UUID id) {
|
||||||
|
QuoteSession session = sessionRepo.findById(id)
|
||||||
|
.orElseThrow(() -> new RuntimeException("Session not found"));
|
||||||
|
|
||||||
|
List<QuoteLineItem> items = lineItemRepo.findByQuoteSessionId(id);
|
||||||
|
|
||||||
|
// Calculate Totals
|
||||||
|
BigDecimal itemsTotal = BigDecimal.ZERO;
|
||||||
|
for (QuoteLineItem item : items) {
|
||||||
|
BigDecimal lineTotal = item.getUnitPriceChf().multiply(BigDecimal.valueOf(item.getQuantity()));
|
||||||
|
itemsTotal = itemsTotal.add(lineTotal);
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal setupFee = session.getSetupCostChf() != null ? session.getSetupCostChf() : BigDecimal.ZERO;
|
||||||
|
BigDecimal grandTotal = itemsTotal.add(setupFee);
|
||||||
|
|
||||||
|
Map<String, Object> response = new HashMap<>();
|
||||||
|
response.put("session", session);
|
||||||
|
response.put("items", items);
|
||||||
|
response.put("itemsTotalChf", itemsTotal);
|
||||||
|
response.put("grandTotalChf", grandTotal);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. Download Line Item Content
|
||||||
|
@GetMapping(value = "/{sessionId}/line-items/{lineItemId}/content")
|
||||||
|
public ResponseEntity<org.springframework.core.io.Resource> downloadLineItemContent(
|
||||||
|
@PathVariable UUID sessionId,
|
||||||
|
@PathVariable UUID lineItemId
|
||||||
|
) throws IOException {
|
||||||
|
QuoteLineItem item = lineItemRepo.findById(lineItemId)
|
||||||
|
.orElseThrow(() -> new RuntimeException("Item not found"));
|
||||||
|
|
||||||
|
if (!item.getQuoteSession().getId().equals(sessionId)) {
|
||||||
|
return ResponseEntity.badRequest().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.getStoredPath() == null) {
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
Path path = Paths.get(item.getStoredPath());
|
||||||
|
// Since storedPath is absolute, we can't directly use loadAsResource with it unless we resolve relative.
|
||||||
|
// But loadAsResource expects relative path?
|
||||||
|
// Actually FileSystemStorageService.loadAsResource uses rootLocation.resolve(path).
|
||||||
|
// If path is absolute, resolve might fail or behave weirdly.
|
||||||
|
// But wait, we stored absolute path in DB: item.setStoredPath(persistentPath.toString());
|
||||||
|
// If we want to use storageService.loadAsResource, we need the relative path.
|
||||||
|
// Or we just access the file directly if we trust the absolute path.
|
||||||
|
// But we want to use StorageService abstraction.
|
||||||
|
|
||||||
|
// Option 1: Reconstruct relative path.
|
||||||
|
// We know structure: quotes/{sessionId}/{filename}...
|
||||||
|
// But filename is UUID+ext. We don't have storedFilename in QuoteLineItem easily?
|
||||||
|
// QuoteLineItem doesn't seem to have storedFilename field, only storedPath.
|
||||||
|
|
||||||
|
// If we trust the file is on disk, we can use UrlResource directly here as before,
|
||||||
|
// relying on the fact that storedPath is the absolute path to the file.
|
||||||
|
// But we should verify it exists.
|
||||||
|
|
||||||
|
if (!Files.exists(path)) {
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
org.springframework.core.io.Resource resource = new org.springframework.core.io.UrlResource(path.toUri());
|
||||||
|
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
|
.header(org.springframework.http.HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + item.getOriginalFilename() + "\"")
|
||||||
|
.body(resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AddressDto {
|
||||||
|
private String firstName;
|
||||||
|
private String lastName;
|
||||||
|
private String companyName;
|
||||||
|
private String contactPerson;
|
||||||
|
private String addressLine1;
|
||||||
|
private String addressLine2;
|
||||||
|
private String zip;
|
||||||
|
private String city;
|
||||||
|
private String countryCode;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CreateOrderRequest {
|
||||||
|
private CustomerDto customer;
|
||||||
|
private AddressDto billingAddress;
|
||||||
|
private AddressDto shippingAddress;
|
||||||
|
private boolean shippingSameAsBilling;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CustomerDto {
|
||||||
|
private String email;
|
||||||
|
private String phone;
|
||||||
|
private String customerType; // "PRIVATE", "BUSINESS"
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record OptionsResponse(
|
||||||
|
List<MaterialOption> materials,
|
||||||
|
List<QualityOption> qualities,
|
||||||
|
List<InfillPatternOption> infillPatterns,
|
||||||
|
List<LayerHeightOptionDTO> layerHeights,
|
||||||
|
List<NozzleOptionDTO> nozzleDiameters
|
||||||
|
) {
|
||||||
|
public record MaterialOption(String code, String label, List<VariantOption> variants) {}
|
||||||
|
public record VariantOption(String name, String colorName, String hexColor, boolean isOutOfStock) {}
|
||||||
|
public record QualityOption(String id, String label) {}
|
||||||
|
public record InfillPatternOption(String id, String label) {}
|
||||||
|
public record LayerHeightOptionDTO(double value, String label) {}
|
||||||
|
public record NozzleOptionDTO(double value, String label) {}
|
||||||
|
}
|
||||||
74
backend/src/main/java/com/printcalculator/dto/OrderDto.java
Normal file
74
backend/src/main/java/com/printcalculator/dto/OrderDto.java
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class OrderDto {
|
||||||
|
private UUID id;
|
||||||
|
private String status;
|
||||||
|
private String customerEmail;
|
||||||
|
private String customerPhone;
|
||||||
|
private String billingCustomerType;
|
||||||
|
private AddressDto billingAddress;
|
||||||
|
private AddressDto shippingAddress;
|
||||||
|
private Boolean shippingSameAsBilling;
|
||||||
|
private String currency;
|
||||||
|
private BigDecimal setupCostChf;
|
||||||
|
private BigDecimal shippingCostChf;
|
||||||
|
private BigDecimal discountChf;
|
||||||
|
private BigDecimal subtotalChf;
|
||||||
|
private BigDecimal totalChf;
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
private List<OrderItemDto> items;
|
||||||
|
|
||||||
|
// Getters and Setters
|
||||||
|
public UUID getId() { return id; }
|
||||||
|
public void setId(UUID id) { this.id = id; }
|
||||||
|
|
||||||
|
public String getStatus() { return status; }
|
||||||
|
public void setStatus(String status) { this.status = status; }
|
||||||
|
|
||||||
|
public String getCustomerEmail() { return customerEmail; }
|
||||||
|
public void setCustomerEmail(String customerEmail) { this.customerEmail = customerEmail; }
|
||||||
|
|
||||||
|
public String getCustomerPhone() { return customerPhone; }
|
||||||
|
public void setCustomerPhone(String customerPhone) { this.customerPhone = customerPhone; }
|
||||||
|
|
||||||
|
public String getBillingCustomerType() { return billingCustomerType; }
|
||||||
|
public void setBillingCustomerType(String billingCustomerType) { this.billingCustomerType = billingCustomerType; }
|
||||||
|
|
||||||
|
public AddressDto getBillingAddress() { return billingAddress; }
|
||||||
|
public void setBillingAddress(AddressDto billingAddress) { this.billingAddress = billingAddress; }
|
||||||
|
|
||||||
|
public AddressDto getShippingAddress() { return shippingAddress; }
|
||||||
|
public void setShippingAddress(AddressDto shippingAddress) { this.shippingAddress = shippingAddress; }
|
||||||
|
|
||||||
|
public Boolean getShippingSameAsBilling() { return shippingSameAsBilling; }
|
||||||
|
public void setShippingSameAsBilling(Boolean shippingSameAsBilling) { this.shippingSameAsBilling = shippingSameAsBilling; }
|
||||||
|
|
||||||
|
public String getCurrency() { return currency; }
|
||||||
|
public void setCurrency(String currency) { this.currency = currency; }
|
||||||
|
|
||||||
|
public BigDecimal getSetupCostChf() { return setupCostChf; }
|
||||||
|
public void setSetupCostChf(BigDecimal setupCostChf) { this.setupCostChf = setupCostChf; }
|
||||||
|
|
||||||
|
public BigDecimal getShippingCostChf() { return shippingCostChf; }
|
||||||
|
public void setShippingCostChf(BigDecimal shippingCostChf) { this.shippingCostChf = shippingCostChf; }
|
||||||
|
|
||||||
|
public BigDecimal getDiscountChf() { return discountChf; }
|
||||||
|
public void setDiscountChf(BigDecimal discountChf) { this.discountChf = discountChf; }
|
||||||
|
|
||||||
|
public BigDecimal getSubtotalChf() { return subtotalChf; }
|
||||||
|
public void setSubtotalChf(BigDecimal subtotalChf) { this.subtotalChf = subtotalChf; }
|
||||||
|
|
||||||
|
public BigDecimal getTotalChf() { return totalChf; }
|
||||||
|
public void setTotalChf(BigDecimal totalChf) { this.totalChf = totalChf; }
|
||||||
|
|
||||||
|
public OffsetDateTime getCreatedAt() { return createdAt; }
|
||||||
|
public void setCreatedAt(OffsetDateTime createdAt) { this.createdAt = createdAt; }
|
||||||
|
|
||||||
|
public List<OrderItemDto> getItems() { return items; }
|
||||||
|
public void setItems(List<OrderItemDto> items) { this.items = items; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class OrderItemDto {
|
||||||
|
private UUID id;
|
||||||
|
private String originalFilename;
|
||||||
|
private String materialCode;
|
||||||
|
private String colorCode;
|
||||||
|
private Integer quantity;
|
||||||
|
private Integer printTimeSeconds;
|
||||||
|
private BigDecimal materialGrams;
|
||||||
|
private BigDecimal unitPriceChf;
|
||||||
|
private BigDecimal lineTotalChf;
|
||||||
|
|
||||||
|
// Getters and Setters
|
||||||
|
public UUID getId() { return id; }
|
||||||
|
public void setId(UUID id) { this.id = id; }
|
||||||
|
|
||||||
|
public String getOriginalFilename() { return originalFilename; }
|
||||||
|
public void setOriginalFilename(String originalFilename) { this.originalFilename = originalFilename; }
|
||||||
|
|
||||||
|
public String getMaterialCode() { return materialCode; }
|
||||||
|
public void setMaterialCode(String materialCode) { this.materialCode = materialCode; }
|
||||||
|
|
||||||
|
public String getColorCode() { return colorCode; }
|
||||||
|
public void setColorCode(String colorCode) { this.colorCode = colorCode; }
|
||||||
|
|
||||||
|
public Integer getQuantity() { return quantity; }
|
||||||
|
public void setQuantity(Integer quantity) { this.quantity = quantity; }
|
||||||
|
|
||||||
|
public Integer getPrintTimeSeconds() { return printTimeSeconds; }
|
||||||
|
public void setPrintTimeSeconds(Integer printTimeSeconds) { this.printTimeSeconds = printTimeSeconds; }
|
||||||
|
|
||||||
|
public BigDecimal getMaterialGrams() { return materialGrams; }
|
||||||
|
public void setMaterialGrams(BigDecimal materialGrams) { this.materialGrams = materialGrams; }
|
||||||
|
|
||||||
|
public BigDecimal getUnitPriceChf() { return unitPriceChf; }
|
||||||
|
public void setUnitPriceChf(BigDecimal unitPriceChf) { this.unitPriceChf = unitPriceChf; }
|
||||||
|
|
||||||
|
public BigDecimal getLineTotalChf() { return lineTotalChf; }
|
||||||
|
public void setLineTotalChf(BigDecimal lineTotalChf) { this.lineTotalChf = lineTotalChf; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PrintSettingsDto {
|
||||||
|
// Mode: "BASIC" or "ADVANCED"
|
||||||
|
private String complexityMode;
|
||||||
|
|
||||||
|
// Common
|
||||||
|
private String material; // e.g. "PLA", "PETG"
|
||||||
|
private String color; // e.g. "White", "#FFFFFF"
|
||||||
|
|
||||||
|
// Basic Mode
|
||||||
|
private String quality; // "draft", "standard", "high"
|
||||||
|
|
||||||
|
// Advanced Mode (Optional in Basic)
|
||||||
|
private Double layerHeight;
|
||||||
|
private Double infillDensity;
|
||||||
|
private String infillPattern;
|
||||||
|
private Boolean supportsEnabled = true;
|
||||||
|
private Double nozzleDiameter;
|
||||||
|
private String notes;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class QuoteRequestDto {
|
||||||
|
private String requestType; // "PRINT_SERVICE" or "DESIGN_SERVICE"
|
||||||
|
private String customerType; // "PRIVATE" or "BUSINESS"
|
||||||
|
private String email;
|
||||||
|
private String phone;
|
||||||
|
private String name;
|
||||||
|
private String companyName;
|
||||||
|
private String contactPerson;
|
||||||
|
private String message;
|
||||||
|
}
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "custom_quote_requests", indexes = {@Index(name = "ix_custom_quote_requests_status",
|
||||||
|
columnList = "status")})
|
||||||
|
public class CustomQuoteRequest {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
@Column(name = "request_id", nullable = false)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@Column(name = "request_type", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String requestType;
|
||||||
|
|
||||||
|
@Column(name = "customer_type", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String customerType;
|
||||||
|
|
||||||
|
@Column(name = "email", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Column(name = "phone", length = Integer.MAX_VALUE)
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@Column(name = "name", length = Integer.MAX_VALUE)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "company_name", length = Integer.MAX_VALUE)
|
||||||
|
private String companyName;
|
||||||
|
|
||||||
|
@Column(name = "contact_person", length = Integer.MAX_VALUE)
|
||||||
|
private String contactPerson;
|
||||||
|
|
||||||
|
@Column(name = "message", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
@Column(name = "status", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "updated_at", nullable = false)
|
||||||
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRequestType() {
|
||||||
|
return requestType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequestType(String requestType) {
|
||||||
|
this.requestType = requestType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCustomerType() {
|
||||||
|
return customerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomerType(String customerType) {
|
||||||
|
this.customerType = customerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPhone() {
|
||||||
|
return phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhone(String phone) {
|
||||||
|
this.phone = phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCompanyName() {
|
||||||
|
return companyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompanyName(String companyName) {
|
||||||
|
this.companyName = companyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContactPerson() {
|
||||||
|
return contactPerson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContactPerson(String contactPerson) {
|
||||||
|
this.contactPerson = contactPerson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getUpdatedAt() {
|
||||||
|
return updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatedAt(OffsetDateTime updatedAt) {
|
||||||
|
this.updatedAt = updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
import org.hibernate.annotations.OnDelete;
|
||||||
|
import org.hibernate.annotations.OnDeleteAction;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "custom_quote_request_attachments", indexes = {@Index(name = "ix_custom_quote_attachments_request",
|
||||||
|
columnList = "request_id")})
|
||||||
|
public class CustomQuoteRequestAttachment {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
@Column(name = "attachment_id", nullable = false)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||||
|
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||||
|
@JoinColumn(name = "request_id", nullable = false)
|
||||||
|
private CustomQuoteRequest request;
|
||||||
|
|
||||||
|
@Column(name = "original_filename", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String originalFilename;
|
||||||
|
|
||||||
|
@Column(name = "stored_relative_path", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String storedRelativePath;
|
||||||
|
|
||||||
|
@Column(name = "stored_filename", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String storedFilename;
|
||||||
|
|
||||||
|
@Column(name = "file_size_bytes")
|
||||||
|
private Long fileSizeBytes;
|
||||||
|
|
||||||
|
@Column(name = "mime_type", length = Integer.MAX_VALUE)
|
||||||
|
private String mimeType;
|
||||||
|
|
||||||
|
@Column(name = "sha256_hex", length = Integer.MAX_VALUE)
|
||||||
|
private String sha256Hex;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomQuoteRequest getRequest() {
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequest(CustomQuoteRequest request) {
|
||||||
|
this.request = request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOriginalFilename() {
|
||||||
|
return originalFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalFilename(String originalFilename) {
|
||||||
|
this.originalFilename = originalFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStoredRelativePath() {
|
||||||
|
return storedRelativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoredRelativePath(String storedRelativePath) {
|
||||||
|
this.storedRelativePath = storedRelativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStoredFilename() {
|
||||||
|
return storedFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoredFilename(String storedFilename) {
|
||||||
|
this.storedFilename = storedFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getFileSizeBytes() {
|
||||||
|
return fileSizeBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileSizeBytes(Long fileSizeBytes) {
|
||||||
|
this.fileSizeBytes = fileSizeBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMimeType() {
|
||||||
|
return mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMimeType(String mimeType) {
|
||||||
|
this.mimeType = mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSha256Hex() {
|
||||||
|
return sha256Hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSha256Hex(String sha256Hex) {
|
||||||
|
this.sha256Hex = sha256Hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomQuoteRequest(CustomQuoteRequest request) {
|
||||||
|
}
|
||||||
|
}
|
||||||
126
backend/src/main/java/com/printcalculator/entity/Customer.java
Normal file
126
backend/src/main/java/com/printcalculator/entity/Customer.java
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "customers")
|
||||||
|
public class Customer {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
@Column(name = "customer_id", nullable = false)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@Column(name = "customer_type", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String customerType;
|
||||||
|
|
||||||
|
@Column(name = "email", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Column(name = "phone", length = Integer.MAX_VALUE)
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@Column(name = "first_name", length = Integer.MAX_VALUE)
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
@Column(name = "last_name", length = Integer.MAX_VALUE)
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
@Column(name = "company_name", length = Integer.MAX_VALUE)
|
||||||
|
private String companyName;
|
||||||
|
|
||||||
|
@Column(name = "contact_person", length = Integer.MAX_VALUE)
|
||||||
|
private String contactPerson;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "updated_at", nullable = false)
|
||||||
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCustomerType() {
|
||||||
|
return customerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomerType(String customerType) {
|
||||||
|
this.customerType = customerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPhone() {
|
||||||
|
return phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhone(String phone) {
|
||||||
|
this.phone = phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstName(String firstName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastName(String lastName) {
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCompanyName() {
|
||||||
|
return companyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompanyName(String companyName) {
|
||||||
|
this.companyName = companyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContactPerson() {
|
||||||
|
return contactPerson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContactPerson(String contactPerson) {
|
||||||
|
this.contactPerson = contactPerson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getUpdatedAt() {
|
||||||
|
return updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatedAt(OffsetDateTime updatedAt) {
|
||||||
|
this.updatedAt = updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "filament_material_type")
|
||||||
|
public class FilamentMaterialType {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "filament_material_type_id", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "material_code", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String materialCode;
|
||||||
|
|
||||||
|
@ColumnDefault("false")
|
||||||
|
@Column(name = "is_flexible", nullable = false)
|
||||||
|
private Boolean isFlexible;
|
||||||
|
|
||||||
|
@ColumnDefault("false")
|
||||||
|
@Column(name = "is_technical", nullable = false)
|
||||||
|
private Boolean isTechnical;
|
||||||
|
|
||||||
|
@Column(name = "technical_type_label", length = Integer.MAX_VALUE)
|
||||||
|
private String technicalTypeLabel;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMaterialCode() {
|
||||||
|
return materialCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaterialCode(String materialCode) {
|
||||||
|
this.materialCode = materialCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsFlexible() {
|
||||||
|
return isFlexible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsFlexible(Boolean isFlexible) {
|
||||||
|
this.isFlexible = isFlexible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsTechnical() {
|
||||||
|
return isTechnical;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsTechnical(Boolean isTechnical) {
|
||||||
|
this.isTechnical = isTechnical;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTechnicalTypeLabel() {
|
||||||
|
return technicalTypeLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTechnicalTypeLabel(String technicalTypeLabel) {
|
||||||
|
this.technicalTypeLabel = technicalTypeLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "filament_variant")
|
||||||
|
public class FilamentVariant {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "filament_variant_id", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||||
|
@JoinColumn(name = "filament_material_type_id", nullable = false)
|
||||||
|
private FilamentMaterialType filamentMaterialType;
|
||||||
|
|
||||||
|
@Column(name = "variant_display_name", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String variantDisplayName;
|
||||||
|
|
||||||
|
@Column(name = "color_name", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String colorName;
|
||||||
|
|
||||||
|
@ColumnDefault("false")
|
||||||
|
@Column(name = "is_matte", nullable = false)
|
||||||
|
private Boolean isMatte;
|
||||||
|
|
||||||
|
@ColumnDefault("false")
|
||||||
|
@Column(name = "is_special", nullable = false)
|
||||||
|
private Boolean isSpecial;
|
||||||
|
|
||||||
|
@Column(name = "cost_chf_per_kg", nullable = false, precision = 10, scale = 2)
|
||||||
|
private BigDecimal costChfPerKg;
|
||||||
|
|
||||||
|
@ColumnDefault("0.000")
|
||||||
|
@Column(name = "stock_spools", nullable = false, precision = 6, scale = 3)
|
||||||
|
private BigDecimal stockSpools;
|
||||||
|
|
||||||
|
@ColumnDefault("1.000")
|
||||||
|
@Column(name = "spool_net_kg", nullable = false, precision = 6, scale = 3)
|
||||||
|
private BigDecimal spoolNetKg;
|
||||||
|
|
||||||
|
@ColumnDefault("true")
|
||||||
|
@Column(name = "is_active", nullable = false)
|
||||||
|
private Boolean isActive;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FilamentMaterialType getFilamentMaterialType() {
|
||||||
|
return filamentMaterialType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFilamentMaterialType(FilamentMaterialType filamentMaterialType) {
|
||||||
|
this.filamentMaterialType = filamentMaterialType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVariantDisplayName() {
|
||||||
|
return variantDisplayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVariantDisplayName(String variantDisplayName) {
|
||||||
|
this.variantDisplayName = variantDisplayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorName() {
|
||||||
|
return colorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorName(String colorName) {
|
||||||
|
this.colorName = colorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsMatte() {
|
||||||
|
return isMatte;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsMatte(Boolean isMatte) {
|
||||||
|
this.isMatte = isMatte;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsSpecial() {
|
||||||
|
return isSpecial;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsSpecial(Boolean isSpecial) {
|
||||||
|
this.isSpecial = isSpecial;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getCostChfPerKg() {
|
||||||
|
return costChfPerKg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCostChfPerKg(BigDecimal costChfPerKg) {
|
||||||
|
this.costChfPerKg = costChfPerKg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getStockSpools() {
|
||||||
|
return stockSpools;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStockSpools(BigDecimal stockSpools) {
|
||||||
|
this.stockSpools = stockSpools;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getSpoolNetKg() {
|
||||||
|
return spoolNetKg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpoolNetKg(BigDecimal spoolNetKg) {
|
||||||
|
this.spoolNetKg = spoolNetKg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean isActive) {
|
||||||
|
this.isActive = isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import org.hibernate.annotations.Immutable;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Immutable
|
||||||
|
@Table(name = "filament_variant_stock_kg")
|
||||||
|
public class FilamentVariantStockKg {
|
||||||
|
@Id
|
||||||
|
@Column(name = "filament_variant_id")
|
||||||
|
private Long filamentVariantId;
|
||||||
|
|
||||||
|
@Column(name = "stock_spools", precision = 6, scale = 3)
|
||||||
|
private BigDecimal stockSpools;
|
||||||
|
|
||||||
|
@Column(name = "spool_net_kg", precision = 6, scale = 3)
|
||||||
|
private BigDecimal spoolNetKg;
|
||||||
|
|
||||||
|
@Column(name = "stock_kg")
|
||||||
|
private BigDecimal stockKg;
|
||||||
|
|
||||||
|
public Long getFilamentVariantId() {
|
||||||
|
return filamentVariantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getStockSpools() {
|
||||||
|
return stockSpools;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getSpoolNetKg() {
|
||||||
|
return spoolNetKg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getStockKg() {
|
||||||
|
return stockKg;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "infill_pattern")
|
||||||
|
public class InfillPattern {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "infill_pattern_id", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "pattern_code", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String patternCode;
|
||||||
|
|
||||||
|
@Column(name = "display_name", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String displayName;
|
||||||
|
|
||||||
|
@ColumnDefault("true")
|
||||||
|
@Column(name = "is_active", nullable = false)
|
||||||
|
private Boolean isActive;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPatternCode() {
|
||||||
|
return patternCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPatternCode(String patternCode) {
|
||||||
|
this.patternCode = patternCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisplayName(String displayName) {
|
||||||
|
this.displayName = displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean isActive) {
|
||||||
|
this.isActive = isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "layer_height_option")
|
||||||
|
public class LayerHeightOption {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "layer_height_option_id", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "layer_height_mm", nullable = false, precision = 5, scale = 3)
|
||||||
|
private BigDecimal layerHeightMm;
|
||||||
|
|
||||||
|
@ColumnDefault("1.000")
|
||||||
|
@Column(name = "time_multiplier", nullable = false, precision = 6, scale = 3)
|
||||||
|
private BigDecimal timeMultiplier;
|
||||||
|
|
||||||
|
@ColumnDefault("true")
|
||||||
|
@Column(name = "is_active", nullable = false)
|
||||||
|
private Boolean isActive;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getLayerHeightMm() {
|
||||||
|
return layerHeightMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLayerHeightMm(BigDecimal layerHeightMm) {
|
||||||
|
this.layerHeightMm = layerHeightMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getTimeMultiplier() {
|
||||||
|
return timeMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeMultiplier(BigDecimal timeMultiplier) {
|
||||||
|
this.timeMultiplier = timeMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean isActive) {
|
||||||
|
this.isActive = isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "layer_height_profile")
|
||||||
|
public class LayerHeightProfile {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "layer_height_profile_id", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "profile_name", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String profileName;
|
||||||
|
|
||||||
|
@Column(name = "min_layer_height_mm", nullable = false, precision = 5, scale = 3)
|
||||||
|
private BigDecimal minLayerHeightMm;
|
||||||
|
|
||||||
|
@Column(name = "max_layer_height_mm", nullable = false, precision = 5, scale = 3)
|
||||||
|
private BigDecimal maxLayerHeightMm;
|
||||||
|
|
||||||
|
@Column(name = "default_layer_height_mm", nullable = false, precision = 5, scale = 3)
|
||||||
|
private BigDecimal defaultLayerHeightMm;
|
||||||
|
|
||||||
|
@ColumnDefault("1.000")
|
||||||
|
@Column(name = "time_multiplier", nullable = false, precision = 6, scale = 3)
|
||||||
|
private BigDecimal timeMultiplier;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProfileName() {
|
||||||
|
return profileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfileName(String profileName) {
|
||||||
|
this.profileName = profileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getMinLayerHeightMm() {
|
||||||
|
return minLayerHeightMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinLayerHeightMm(BigDecimal minLayerHeightMm) {
|
||||||
|
this.minLayerHeightMm = minLayerHeightMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getMaxLayerHeightMm() {
|
||||||
|
return maxLayerHeightMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxLayerHeightMm(BigDecimal maxLayerHeightMm) {
|
||||||
|
this.maxLayerHeightMm = maxLayerHeightMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getDefaultLayerHeightMm() {
|
||||||
|
return defaultLayerHeightMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultLayerHeightMm(BigDecimal defaultLayerHeightMm) {
|
||||||
|
this.defaultLayerHeightMm = defaultLayerHeightMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getTimeMultiplier() {
|
||||||
|
return timeMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeMultiplier(BigDecimal timeMultiplier) {
|
||||||
|
this.timeMultiplier = timeMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "nozzle_option")
|
||||||
|
public class NozzleOption {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "nozzle_option_id", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "nozzle_diameter_mm", nullable = false, precision = 4, scale = 2)
|
||||||
|
private BigDecimal nozzleDiameterMm;
|
||||||
|
|
||||||
|
@ColumnDefault("0")
|
||||||
|
@Column(name = "owned_quantity", nullable = false)
|
||||||
|
private Integer ownedQuantity;
|
||||||
|
|
||||||
|
@ColumnDefault("0.00")
|
||||||
|
@Column(name = "extra_nozzle_change_fee_chf", nullable = false, precision = 10, scale = 2)
|
||||||
|
private BigDecimal extraNozzleChangeFeeChf;
|
||||||
|
|
||||||
|
@ColumnDefault("true")
|
||||||
|
@Column(name = "is_active", nullable = false)
|
||||||
|
private Boolean isActive;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getNozzleDiameterMm() {
|
||||||
|
return nozzleDiameterMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNozzleDiameterMm(BigDecimal nozzleDiameterMm) {
|
||||||
|
this.nozzleDiameterMm = nozzleDiameterMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getOwnedQuantity() {
|
||||||
|
return ownedQuantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwnedQuantity(Integer ownedQuantity) {
|
||||||
|
this.ownedQuantity = ownedQuantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getExtraNozzleChangeFeeChf() {
|
||||||
|
return extraNozzleChangeFeeChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtraNozzleChangeFeeChf(BigDecimal extraNozzleChangeFeeChf) {
|
||||||
|
this.extraNozzleChangeFeeChf = extraNozzleChangeFeeChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean isActive) {
|
||||||
|
this.isActive = isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
414
backend/src/main/java/com/printcalculator/entity/Order.java
Normal file
414
backend/src/main/java/com/printcalculator/entity/Order.java
Normal file
@@ -0,0 +1,414 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "orders", indexes = {@Index(name = "ix_orders_status",
|
||||||
|
columnList = "status")})
|
||||||
|
public class Order {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
@Column(name = "order_id", nullable = false)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "source_quote_session_id")
|
||||||
|
private QuoteSession sourceQuoteSession;
|
||||||
|
|
||||||
|
@Column(name = "status", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "customer_id")
|
||||||
|
private Customer customer;
|
||||||
|
|
||||||
|
@Column(name = "customer_email", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String customerEmail;
|
||||||
|
|
||||||
|
@Column(name = "customer_phone", length = Integer.MAX_VALUE)
|
||||||
|
private String customerPhone;
|
||||||
|
|
||||||
|
@Column(name = "billing_customer_type", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String billingCustomerType;
|
||||||
|
|
||||||
|
@Column(name = "billing_first_name", length = Integer.MAX_VALUE)
|
||||||
|
private String billingFirstName;
|
||||||
|
|
||||||
|
@Column(name = "billing_last_name", length = Integer.MAX_VALUE)
|
||||||
|
private String billingLastName;
|
||||||
|
|
||||||
|
@Column(name = "billing_company_name", length = Integer.MAX_VALUE)
|
||||||
|
private String billingCompanyName;
|
||||||
|
|
||||||
|
@Column(name = "billing_contact_person", length = Integer.MAX_VALUE)
|
||||||
|
private String billingContactPerson;
|
||||||
|
|
||||||
|
@Column(name = "billing_address_line1", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String billingAddressLine1;
|
||||||
|
|
||||||
|
@Column(name = "billing_address_line2", length = Integer.MAX_VALUE)
|
||||||
|
private String billingAddressLine2;
|
||||||
|
|
||||||
|
@Column(name = "billing_zip", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String billingZip;
|
||||||
|
|
||||||
|
@Column(name = "billing_city", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String billingCity;
|
||||||
|
|
||||||
|
@ColumnDefault("'CH'")
|
||||||
|
@Column(name = "billing_country_code", nullable = false, length = 2)
|
||||||
|
private String billingCountryCode;
|
||||||
|
|
||||||
|
@ColumnDefault("true")
|
||||||
|
@Column(name = "shipping_same_as_billing", nullable = false)
|
||||||
|
private Boolean shippingSameAsBilling;
|
||||||
|
|
||||||
|
@Column(name = "shipping_first_name", length = Integer.MAX_VALUE)
|
||||||
|
private String shippingFirstName;
|
||||||
|
|
||||||
|
@Column(name = "shipping_last_name", length = Integer.MAX_VALUE)
|
||||||
|
private String shippingLastName;
|
||||||
|
|
||||||
|
@Column(name = "shipping_company_name", length = Integer.MAX_VALUE)
|
||||||
|
private String shippingCompanyName;
|
||||||
|
|
||||||
|
@Column(name = "shipping_contact_person", length = Integer.MAX_VALUE)
|
||||||
|
private String shippingContactPerson;
|
||||||
|
|
||||||
|
@Column(name = "shipping_address_line1", length = Integer.MAX_VALUE)
|
||||||
|
private String shippingAddressLine1;
|
||||||
|
|
||||||
|
@Column(name = "shipping_address_line2", length = Integer.MAX_VALUE)
|
||||||
|
private String shippingAddressLine2;
|
||||||
|
|
||||||
|
@Column(name = "shipping_zip", length = Integer.MAX_VALUE)
|
||||||
|
private String shippingZip;
|
||||||
|
|
||||||
|
@Column(name = "shipping_city", length = Integer.MAX_VALUE)
|
||||||
|
private String shippingCity;
|
||||||
|
|
||||||
|
@Column(name = "shipping_country_code", length = 2)
|
||||||
|
private String shippingCountryCode;
|
||||||
|
|
||||||
|
@ColumnDefault("'CHF'")
|
||||||
|
@Column(name = "currency", nullable = false, length = 3)
|
||||||
|
private String currency;
|
||||||
|
|
||||||
|
@ColumnDefault("0.00")
|
||||||
|
@Column(name = "setup_cost_chf", nullable = false, precision = 12, scale = 2)
|
||||||
|
private BigDecimal setupCostChf;
|
||||||
|
|
||||||
|
@ColumnDefault("0.00")
|
||||||
|
@Column(name = "shipping_cost_chf", nullable = false, precision = 12, scale = 2)
|
||||||
|
private BigDecimal shippingCostChf;
|
||||||
|
|
||||||
|
@ColumnDefault("0.00")
|
||||||
|
@Column(name = "discount_chf", nullable = false, precision = 12, scale = 2)
|
||||||
|
private BigDecimal discountChf;
|
||||||
|
|
||||||
|
@ColumnDefault("0.00")
|
||||||
|
@Column(name = "subtotal_chf", nullable = false, precision = 12, scale = 2)
|
||||||
|
private BigDecimal subtotalChf;
|
||||||
|
|
||||||
|
@ColumnDefault("0.00")
|
||||||
|
@Column(name = "total_chf", nullable = false, precision = 12, scale = 2)
|
||||||
|
private BigDecimal totalChf;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "updated_at", nullable = false)
|
||||||
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
@Column(name = "paid_at")
|
||||||
|
private OffsetDateTime paidAt;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuoteSession getSourceQuoteSession() {
|
||||||
|
return sourceQuoteSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceQuoteSession(QuoteSession sourceQuoteSession) {
|
||||||
|
this.sourceQuoteSession = sourceQuoteSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Customer getCustomer() {
|
||||||
|
return customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomer(Customer customer) {
|
||||||
|
this.customer = customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCustomerEmail() {
|
||||||
|
return customerEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomerEmail(String customerEmail) {
|
||||||
|
this.customerEmail = customerEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCustomerPhone() {
|
||||||
|
return customerPhone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomerPhone(String customerPhone) {
|
||||||
|
this.customerPhone = customerPhone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBillingCustomerType() {
|
||||||
|
return billingCustomerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBillingCustomerType(String billingCustomerType) {
|
||||||
|
this.billingCustomerType = billingCustomerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBillingFirstName() {
|
||||||
|
return billingFirstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBillingFirstName(String billingFirstName) {
|
||||||
|
this.billingFirstName = billingFirstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBillingLastName() {
|
||||||
|
return billingLastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBillingLastName(String billingLastName) {
|
||||||
|
this.billingLastName = billingLastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBillingCompanyName() {
|
||||||
|
return billingCompanyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBillingCompanyName(String billingCompanyName) {
|
||||||
|
this.billingCompanyName = billingCompanyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBillingContactPerson() {
|
||||||
|
return billingContactPerson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBillingContactPerson(String billingContactPerson) {
|
||||||
|
this.billingContactPerson = billingContactPerson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBillingAddressLine1() {
|
||||||
|
return billingAddressLine1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBillingAddressLine1(String billingAddressLine1) {
|
||||||
|
this.billingAddressLine1 = billingAddressLine1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBillingAddressLine2() {
|
||||||
|
return billingAddressLine2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBillingAddressLine2(String billingAddressLine2) {
|
||||||
|
this.billingAddressLine2 = billingAddressLine2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBillingZip() {
|
||||||
|
return billingZip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBillingZip(String billingZip) {
|
||||||
|
this.billingZip = billingZip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBillingCity() {
|
||||||
|
return billingCity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBillingCity(String billingCity) {
|
||||||
|
this.billingCity = billingCity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBillingCountryCode() {
|
||||||
|
return billingCountryCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBillingCountryCode(String billingCountryCode) {
|
||||||
|
this.billingCountryCode = billingCountryCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getShippingSameAsBilling() {
|
||||||
|
return shippingSameAsBilling;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShippingSameAsBilling(Boolean shippingSameAsBilling) {
|
||||||
|
this.shippingSameAsBilling = shippingSameAsBilling;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShippingFirstName() {
|
||||||
|
return shippingFirstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShippingFirstName(String shippingFirstName) {
|
||||||
|
this.shippingFirstName = shippingFirstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShippingLastName() {
|
||||||
|
return shippingLastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShippingLastName(String shippingLastName) {
|
||||||
|
this.shippingLastName = shippingLastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShippingCompanyName() {
|
||||||
|
return shippingCompanyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShippingCompanyName(String shippingCompanyName) {
|
||||||
|
this.shippingCompanyName = shippingCompanyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShippingContactPerson() {
|
||||||
|
return shippingContactPerson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShippingContactPerson(String shippingContactPerson) {
|
||||||
|
this.shippingContactPerson = shippingContactPerson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShippingAddressLine1() {
|
||||||
|
return shippingAddressLine1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShippingAddressLine1(String shippingAddressLine1) {
|
||||||
|
this.shippingAddressLine1 = shippingAddressLine1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShippingAddressLine2() {
|
||||||
|
return shippingAddressLine2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShippingAddressLine2(String shippingAddressLine2) {
|
||||||
|
this.shippingAddressLine2 = shippingAddressLine2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShippingZip() {
|
||||||
|
return shippingZip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShippingZip(String shippingZip) {
|
||||||
|
this.shippingZip = shippingZip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShippingCity() {
|
||||||
|
return shippingCity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShippingCity(String shippingCity) {
|
||||||
|
this.shippingCity = shippingCity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShippingCountryCode() {
|
||||||
|
return shippingCountryCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShippingCountryCode(String shippingCountryCode) {
|
||||||
|
this.shippingCountryCode = shippingCountryCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCurrency() {
|
||||||
|
return currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrency(String currency) {
|
||||||
|
this.currency = currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getSetupCostChf() {
|
||||||
|
return setupCostChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSetupCostChf(BigDecimal setupCostChf) {
|
||||||
|
this.setupCostChf = setupCostChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getShippingCostChf() {
|
||||||
|
return shippingCostChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShippingCostChf(BigDecimal shippingCostChf) {
|
||||||
|
this.shippingCostChf = shippingCostChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getDiscountChf() {
|
||||||
|
return discountChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDiscountChf(BigDecimal discountChf) {
|
||||||
|
this.discountChf = discountChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getSubtotalChf() {
|
||||||
|
return subtotalChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubtotalChf(BigDecimal subtotalChf) {
|
||||||
|
this.subtotalChf = subtotalChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getTotalChf() {
|
||||||
|
return totalChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalChf(BigDecimal totalChf) {
|
||||||
|
this.totalChf = totalChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getUpdatedAt() {
|
||||||
|
return updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatedAt(OffsetDateTime updatedAt) {
|
||||||
|
this.updatedAt = updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getPaidAt() {
|
||||||
|
return paidAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaidAt(OffsetDateTime paidAt) {
|
||||||
|
this.paidAt = paidAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
198
backend/src/main/java/com/printcalculator/entity/OrderItem.java
Normal file
198
backend/src/main/java/com/printcalculator/entity/OrderItem.java
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
import org.hibernate.annotations.OnDelete;
|
||||||
|
import org.hibernate.annotations.OnDeleteAction;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "order_items", indexes = {@Index(name = "ix_order_items_order",
|
||||||
|
columnList = "order_id")})
|
||||||
|
public class OrderItem {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
@Column(name = "order_item_id", nullable = false)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||||
|
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||||
|
@JoinColumn(name = "order_id", nullable = false)
|
||||||
|
private Order order;
|
||||||
|
|
||||||
|
@Column(name = "original_filename", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String originalFilename;
|
||||||
|
|
||||||
|
@Column(name = "stored_relative_path", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String storedRelativePath;
|
||||||
|
|
||||||
|
@Column(name = "stored_filename", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String storedFilename;
|
||||||
|
|
||||||
|
@Column(name = "file_size_bytes")
|
||||||
|
private Long fileSizeBytes;
|
||||||
|
|
||||||
|
@Column(name = "mime_type", length = Integer.MAX_VALUE)
|
||||||
|
private String mimeType;
|
||||||
|
|
||||||
|
@Column(name = "sha256_hex", length = Integer.MAX_VALUE)
|
||||||
|
private String sha256Hex;
|
||||||
|
|
||||||
|
@Column(name = "material_code", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String materialCode;
|
||||||
|
|
||||||
|
@Column(name = "color_code", length = Integer.MAX_VALUE)
|
||||||
|
private String colorCode;
|
||||||
|
|
||||||
|
@ColumnDefault("1")
|
||||||
|
@Column(name = "quantity", nullable = false)
|
||||||
|
private Integer quantity;
|
||||||
|
|
||||||
|
@Column(name = "print_time_seconds")
|
||||||
|
private Integer printTimeSeconds;
|
||||||
|
|
||||||
|
@Column(name = "material_grams", precision = 12, scale = 2)
|
||||||
|
private BigDecimal materialGrams;
|
||||||
|
|
||||||
|
@Column(name = "unit_price_chf", nullable = false, precision = 12, scale = 2)
|
||||||
|
private BigDecimal unitPriceChf;
|
||||||
|
|
||||||
|
@Column(name = "line_total_chf", nullable = false, precision = 12, scale = 2)
|
||||||
|
private BigDecimal lineTotalChf;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Order getOrder() {
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrder(Order order) {
|
||||||
|
this.order = order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOriginalFilename() {
|
||||||
|
return originalFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalFilename(String originalFilename) {
|
||||||
|
this.originalFilename = originalFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStoredRelativePath() {
|
||||||
|
return storedRelativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoredRelativePath(String storedRelativePath) {
|
||||||
|
this.storedRelativePath = storedRelativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStoredFilename() {
|
||||||
|
return storedFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoredFilename(String storedFilename) {
|
||||||
|
this.storedFilename = storedFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getFileSizeBytes() {
|
||||||
|
return fileSizeBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileSizeBytes(Long fileSizeBytes) {
|
||||||
|
this.fileSizeBytes = fileSizeBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMimeType() {
|
||||||
|
return mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMimeType(String mimeType) {
|
||||||
|
this.mimeType = mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSha256Hex() {
|
||||||
|
return sha256Hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSha256Hex(String sha256Hex) {
|
||||||
|
this.sha256Hex = sha256Hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMaterialCode() {
|
||||||
|
return materialCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaterialCode(String materialCode) {
|
||||||
|
this.materialCode = materialCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorCode() {
|
||||||
|
return colorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorCode(String colorCode) {
|
||||||
|
this.colorCode = colorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getQuantity() {
|
||||||
|
return quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuantity(Integer quantity) {
|
||||||
|
this.quantity = quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPrintTimeSeconds() {
|
||||||
|
return printTimeSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrintTimeSeconds(Integer printTimeSeconds) {
|
||||||
|
this.printTimeSeconds = printTimeSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getMaterialGrams() {
|
||||||
|
return materialGrams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaterialGrams(BigDecimal materialGrams) {
|
||||||
|
this.materialGrams = materialGrams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getUnitPriceChf() {
|
||||||
|
return unitPriceChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUnitPriceChf(BigDecimal unitPriceChf) {
|
||||||
|
this.unitPriceChf = unitPriceChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getLineTotalChf() {
|
||||||
|
return lineTotalChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLineTotalChf(BigDecimal lineTotalChf) {
|
||||||
|
this.lineTotalChf = lineTotalChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
146
backend/src/main/java/com/printcalculator/entity/Payment.java
Normal file
146
backend/src/main/java/com/printcalculator/entity/Payment.java
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
import org.hibernate.annotations.OnDelete;
|
||||||
|
import org.hibernate.annotations.OnDeleteAction;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "payments", indexes = {
|
||||||
|
@Index(name = "ix_payments_order",
|
||||||
|
columnList = "order_id"),
|
||||||
|
@Index(name = "ix_payments_reference",
|
||||||
|
columnList = "payment_reference")})
|
||||||
|
public class Payment {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
@Column(name = "payment_id", nullable = false)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||||
|
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||||
|
@JoinColumn(name = "order_id", nullable = false)
|
||||||
|
private Order order;
|
||||||
|
|
||||||
|
@Column(name = "method", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String method;
|
||||||
|
|
||||||
|
@Column(name = "status", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
@ColumnDefault("'CHF'")
|
||||||
|
@Column(name = "currency", nullable = false, length = 3)
|
||||||
|
private String currency;
|
||||||
|
|
||||||
|
@Column(name = "amount_chf", nullable = false, precision = 12, scale = 2)
|
||||||
|
private BigDecimal amountChf;
|
||||||
|
|
||||||
|
@Column(name = "payment_reference", length = Integer.MAX_VALUE)
|
||||||
|
private String paymentReference;
|
||||||
|
|
||||||
|
@Column(name = "provider_transaction_id", length = Integer.MAX_VALUE)
|
||||||
|
private String providerTransactionId;
|
||||||
|
|
||||||
|
@Column(name = "qr_payload", length = Integer.MAX_VALUE)
|
||||||
|
private String qrPayload;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "initiated_at", nullable = false)
|
||||||
|
private OffsetDateTime initiatedAt;
|
||||||
|
|
||||||
|
@Column(name = "received_at")
|
||||||
|
private OffsetDateTime receivedAt;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Order getOrder() {
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrder(Order order) {
|
||||||
|
this.order = order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMethod() {
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMethod(String method) {
|
||||||
|
this.method = method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCurrency() {
|
||||||
|
return currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrency(String currency) {
|
||||||
|
this.currency = currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getAmountChf() {
|
||||||
|
return amountChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAmountChf(BigDecimal amountChf) {
|
||||||
|
this.amountChf = amountChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPaymentReference() {
|
||||||
|
return paymentReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaymentReference(String paymentReference) {
|
||||||
|
this.paymentReference = paymentReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProviderTransactionId() {
|
||||||
|
return providerTransactionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProviderTransactionId(String providerTransactionId) {
|
||||||
|
this.providerTransactionId = providerTransactionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQrPayload() {
|
||||||
|
return qrPayload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQrPayload(String qrPayload) {
|
||||||
|
this.qrPayload = qrPayload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getInitiatedAt() {
|
||||||
|
return initiatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInitiatedAt(OffsetDateTime initiatedAt) {
|
||||||
|
this.initiatedAt = initiatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getReceivedAt() {
|
||||||
|
return receivedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReceivedAt(OffsetDateTime receivedAt) {
|
||||||
|
this.receivedAt = receivedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "pricing_policy")
|
||||||
|
public class PricingPolicy {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "pricing_policy_id", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "policy_name", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String policyName;
|
||||||
|
|
||||||
|
@Column(name = "valid_from", nullable = false)
|
||||||
|
private OffsetDateTime validFrom;
|
||||||
|
|
||||||
|
@Column(name = "valid_to")
|
||||||
|
private OffsetDateTime validTo;
|
||||||
|
|
||||||
|
@Column(name = "electricity_cost_chf_per_kwh", nullable = false, precision = 10, scale = 6)
|
||||||
|
private BigDecimal electricityCostChfPerKwh;
|
||||||
|
|
||||||
|
@ColumnDefault("20.000")
|
||||||
|
@Column(name = "markup_percent", nullable = false, precision = 6, scale = 3)
|
||||||
|
private BigDecimal markupPercent;
|
||||||
|
|
||||||
|
@ColumnDefault("0.00")
|
||||||
|
@Column(name = "fixed_job_fee_chf", nullable = false, precision = 10, scale = 2)
|
||||||
|
private BigDecimal fixedJobFeeChf;
|
||||||
|
|
||||||
|
@ColumnDefault("0.00")
|
||||||
|
@Column(name = "nozzle_change_base_fee_chf", nullable = false, precision = 10, scale = 2)
|
||||||
|
private BigDecimal nozzleChangeBaseFeeChf;
|
||||||
|
|
||||||
|
@ColumnDefault("0.00")
|
||||||
|
@Column(name = "cad_cost_chf_per_hour", nullable = false, precision = 10, scale = 2)
|
||||||
|
private BigDecimal cadCostChfPerHour;
|
||||||
|
|
||||||
|
@ColumnDefault("true")
|
||||||
|
@Column(name = "is_active", nullable = false)
|
||||||
|
private Boolean isActive;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPolicyName() {
|
||||||
|
return policyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPolicyName(String policyName) {
|
||||||
|
this.policyName = policyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getValidFrom() {
|
||||||
|
return validFrom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValidFrom(OffsetDateTime validFrom) {
|
||||||
|
this.validFrom = validFrom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getValidTo() {
|
||||||
|
return validTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValidTo(OffsetDateTime validTo) {
|
||||||
|
this.validTo = validTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getElectricityCostChfPerKwh() {
|
||||||
|
return electricityCostChfPerKwh;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setElectricityCostChfPerKwh(BigDecimal electricityCostChfPerKwh) {
|
||||||
|
this.electricityCostChfPerKwh = electricityCostChfPerKwh;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getMarkupPercent() {
|
||||||
|
return markupPercent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMarkupPercent(BigDecimal markupPercent) {
|
||||||
|
this.markupPercent = markupPercent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getFixedJobFeeChf() {
|
||||||
|
return fixedJobFeeChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFixedJobFeeChf(BigDecimal fixedJobFeeChf) {
|
||||||
|
this.fixedJobFeeChf = fixedJobFeeChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getNozzleChangeBaseFeeChf() {
|
||||||
|
return nozzleChangeBaseFeeChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNozzleChangeBaseFeeChf(BigDecimal nozzleChangeBaseFeeChf) {
|
||||||
|
this.nozzleChangeBaseFeeChf = nozzleChangeBaseFeeChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getCadCostChfPerHour() {
|
||||||
|
return cadCostChfPerHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCadCostChfPerHour(BigDecimal cadCostChfPerHour) {
|
||||||
|
this.cadCostChfPerHour = cadCostChfPerHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean isActive) {
|
||||||
|
this.isActive = isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "pricing_policy_machine_hour_tier")
|
||||||
|
public class PricingPolicyMachineHourTier {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "pricing_policy_machine_hour_tier_id", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||||
|
@JoinColumn(name = "pricing_policy_id", nullable = false)
|
||||||
|
private PricingPolicy pricingPolicy;
|
||||||
|
|
||||||
|
@Column(name = "tier_start_hours", nullable = false, precision = 10, scale = 2)
|
||||||
|
private BigDecimal tierStartHours;
|
||||||
|
|
||||||
|
@Column(name = "tier_end_hours", precision = 10, scale = 2)
|
||||||
|
private BigDecimal tierEndHours;
|
||||||
|
|
||||||
|
@Column(name = "machine_cost_chf_per_hour", nullable = false, precision = 10, scale = 2)
|
||||||
|
private BigDecimal machineCostChfPerHour;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PricingPolicy getPricingPolicy() {
|
||||||
|
return pricingPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPricingPolicy(PricingPolicy pricingPolicy) {
|
||||||
|
this.pricingPolicy = pricingPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getTierStartHours() {
|
||||||
|
return tierStartHours;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTierStartHours(BigDecimal tierStartHours) {
|
||||||
|
this.tierStartHours = tierStartHours;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getTierEndHours() {
|
||||||
|
return tierEndHours;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTierEndHours(BigDecimal tierEndHours) {
|
||||||
|
this.tierEndHours = tierEndHours;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getMachineCostChfPerHour() {
|
||||||
|
return machineCostChfPerHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMachineCostChfPerHour(BigDecimal machineCostChfPerHour) {
|
||||||
|
this.machineCostChfPerHour = machineCostChfPerHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import org.hibernate.annotations.Immutable;
|
||||||
|
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Immutable
|
||||||
|
@Table(name = "printer_fleet_current")
|
||||||
|
public class PrinterFleetCurrent {
|
||||||
|
@Id
|
||||||
|
@Column(name = "fleet_id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "weighted_average_power_watts")
|
||||||
|
private Integer weightedAveragePowerWatts;
|
||||||
|
|
||||||
|
@Column(name = "fleet_max_build_x_mm")
|
||||||
|
private Integer fleetMaxBuildXMm;
|
||||||
|
|
||||||
|
@Column(name = "fleet_max_build_y_mm")
|
||||||
|
private Integer fleetMaxBuildYMm;
|
||||||
|
|
||||||
|
@Column(name = "fleet_max_build_z_mm")
|
||||||
|
private Integer fleetMaxBuildZMm;
|
||||||
|
|
||||||
|
public Integer getWeightedAveragePowerWatts() {
|
||||||
|
return weightedAveragePowerWatts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getFleetMaxBuildXMm() {
|
||||||
|
return fleetMaxBuildXMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getFleetMaxBuildYMm() {
|
||||||
|
return fleetMaxBuildYMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getFleetMaxBuildZMm() {
|
||||||
|
return fleetMaxBuildZMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "printer_machine")
|
||||||
|
public class PrinterMachine {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "printer_machine_id", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "printer_display_name", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String printerDisplayName;
|
||||||
|
|
||||||
|
@Column(name = "build_volume_x_mm", nullable = false)
|
||||||
|
private Integer buildVolumeXMm;
|
||||||
|
|
||||||
|
@Column(name = "build_volume_y_mm", nullable = false)
|
||||||
|
private Integer buildVolumeYMm;
|
||||||
|
|
||||||
|
@Column(name = "build_volume_z_mm", nullable = false)
|
||||||
|
private Integer buildVolumeZMm;
|
||||||
|
|
||||||
|
@Column(name = "power_watts", nullable = false)
|
||||||
|
private Integer powerWatts;
|
||||||
|
|
||||||
|
@ColumnDefault("1.000")
|
||||||
|
@Column(name = "fleet_weight", nullable = false, precision = 6, scale = 3)
|
||||||
|
private BigDecimal fleetWeight;
|
||||||
|
|
||||||
|
@ColumnDefault("true")
|
||||||
|
@Column(name = "is_active", nullable = false)
|
||||||
|
private Boolean isActive;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
@Column(name = "slicer_machine_profile")
|
||||||
|
private String slicerMachineProfile;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrinterDisplayName() {
|
||||||
|
return printerDisplayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrinterDisplayName(String printerDisplayName) {
|
||||||
|
this.printerDisplayName = printerDisplayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSlicerMachineProfile() {
|
||||||
|
return slicerMachineProfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSlicerMachineProfile(String slicerMachineProfile) {
|
||||||
|
this.slicerMachineProfile = slicerMachineProfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getBuildVolumeXMm() {
|
||||||
|
return buildVolumeXMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBuildVolumeXMm(Integer buildVolumeXMm) {
|
||||||
|
this.buildVolumeXMm = buildVolumeXMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getBuildVolumeYMm() {
|
||||||
|
return buildVolumeYMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBuildVolumeYMm(Integer buildVolumeYMm) {
|
||||||
|
this.buildVolumeYMm = buildVolumeYMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getBuildVolumeZMm() {
|
||||||
|
return buildVolumeZMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBuildVolumeZMm(Integer buildVolumeZMm) {
|
||||||
|
this.buildVolumeZMm = buildVolumeZMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPowerWatts() {
|
||||||
|
return powerWatts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPowerWatts(Integer powerWatts) {
|
||||||
|
this.powerWatts = powerWatts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getFleetWeight() {
|
||||||
|
return fleetWeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFleetWeight(BigDecimal fleetWeight) {
|
||||||
|
this.fleetWeight = fleetWeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean isActive) {
|
||||||
|
this.isActive = isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
import org.hibernate.annotations.JdbcTypeCode;
|
||||||
|
import org.hibernate.annotations.OnDelete;
|
||||||
|
import org.hibernate.annotations.OnDeleteAction;
|
||||||
|
import org.hibernate.type.SqlTypes;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "quote_line_items", indexes = {@Index(name = "ix_quote_line_items_session",
|
||||||
|
columnList = "quote_session_id")})
|
||||||
|
public class QuoteLineItem {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
@Column(name = "quote_line_item_id", nullable = false)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||||
|
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||||
|
@JoinColumn(name = "quote_session_id", nullable = false)
|
||||||
|
@com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
|
private QuoteSession quoteSession;
|
||||||
|
|
||||||
|
@Column(name = "status", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
@Column(name = "original_filename", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String originalFilename;
|
||||||
|
|
||||||
|
@ColumnDefault("1")
|
||||||
|
@Column(name = "quantity", nullable = false)
|
||||||
|
private Integer quantity;
|
||||||
|
|
||||||
|
@Column(name = "color_code", length = Integer.MAX_VALUE)
|
||||||
|
private String colorCode;
|
||||||
|
|
||||||
|
@Column(name = "bounding_box_x_mm", precision = 10, scale = 3)
|
||||||
|
private BigDecimal boundingBoxXMm;
|
||||||
|
|
||||||
|
@Column(name = "bounding_box_y_mm", precision = 10, scale = 3)
|
||||||
|
private BigDecimal boundingBoxYMm;
|
||||||
|
|
||||||
|
@Column(name = "bounding_box_z_mm", precision = 10, scale = 3)
|
||||||
|
private BigDecimal boundingBoxZMm;
|
||||||
|
|
||||||
|
@Column(name = "print_time_seconds")
|
||||||
|
private Integer printTimeSeconds;
|
||||||
|
|
||||||
|
@Column(name = "material_grams", precision = 12, scale = 2)
|
||||||
|
private BigDecimal materialGrams;
|
||||||
|
|
||||||
|
@Column(name = "unit_price_chf", precision = 12, scale = 2)
|
||||||
|
private BigDecimal unitPriceChf;
|
||||||
|
|
||||||
|
@JdbcTypeCode(SqlTypes.JSON)
|
||||||
|
@Column(name = "pricing_breakdown")
|
||||||
|
private Map<String, Object> pricingBreakdown;
|
||||||
|
|
||||||
|
@Column(name = "error_message", length = Integer.MAX_VALUE)
|
||||||
|
private String errorMessage;
|
||||||
|
|
||||||
|
@Column(name = "stored_path", length = Integer.MAX_VALUE)
|
||||||
|
private String storedPath;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "updated_at", nullable = false)
|
||||||
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuoteSession getQuoteSession() {
|
||||||
|
return quoteSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuoteSession(QuoteSession quoteSession) {
|
||||||
|
this.quoteSession = quoteSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOriginalFilename() {
|
||||||
|
return originalFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalFilename(String originalFilename) {
|
||||||
|
this.originalFilename = originalFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getQuantity() {
|
||||||
|
return quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuantity(Integer quantity) {
|
||||||
|
this.quantity = quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorCode() {
|
||||||
|
return colorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorCode(String colorCode) {
|
||||||
|
this.colorCode = colorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getBoundingBoxXMm() {
|
||||||
|
return boundingBoxXMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundingBoxXMm(BigDecimal boundingBoxXMm) {
|
||||||
|
this.boundingBoxXMm = boundingBoxXMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getBoundingBoxYMm() {
|
||||||
|
return boundingBoxYMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundingBoxYMm(BigDecimal boundingBoxYMm) {
|
||||||
|
this.boundingBoxYMm = boundingBoxYMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getBoundingBoxZMm() {
|
||||||
|
return boundingBoxZMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundingBoxZMm(BigDecimal boundingBoxZMm) {
|
||||||
|
this.boundingBoxZMm = boundingBoxZMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPrintTimeSeconds() {
|
||||||
|
return printTimeSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrintTimeSeconds(Integer printTimeSeconds) {
|
||||||
|
this.printTimeSeconds = printTimeSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getMaterialGrams() {
|
||||||
|
return materialGrams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaterialGrams(BigDecimal materialGrams) {
|
||||||
|
this.materialGrams = materialGrams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getUnitPriceChf() {
|
||||||
|
return unitPriceChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUnitPriceChf(BigDecimal unitPriceChf) {
|
||||||
|
this.unitPriceChf = unitPriceChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getPricingBreakdown() {
|
||||||
|
return pricingBreakdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPricingBreakdown(Map<String, Object> pricingBreakdown) {
|
||||||
|
this.pricingBreakdown = pricingBreakdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStoredPath() {
|
||||||
|
return storedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoredPath(String storedPath) {
|
||||||
|
this.storedPath = storedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getUpdatedAt() {
|
||||||
|
return updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatedAt(OffsetDateTime updatedAt) {
|
||||||
|
this.updatedAt = updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "quote_sessions", indexes = {
|
||||||
|
@Index(name = "ix_quote_sessions_status",
|
||||||
|
columnList = "status"),
|
||||||
|
@Index(name = "ix_quote_sessions_expires_at",
|
||||||
|
columnList = "expires_at")})
|
||||||
|
public class QuoteSession {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
@Column(name = "quote_session_id", nullable = false)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@Column(name = "status", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
@Column(name = "pricing_version", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String pricingVersion;
|
||||||
|
|
||||||
|
@Column(name = "material_code", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String materialCode;
|
||||||
|
|
||||||
|
@Column(name = "nozzle_diameter_mm", precision = 5, scale = 2)
|
||||||
|
private BigDecimal nozzleDiameterMm;
|
||||||
|
|
||||||
|
@Column(name = "layer_height_mm", precision = 6, scale = 3)
|
||||||
|
private BigDecimal layerHeightMm;
|
||||||
|
|
||||||
|
@Column(name = "infill_pattern", length = Integer.MAX_VALUE)
|
||||||
|
private String infillPattern;
|
||||||
|
|
||||||
|
@Column(name = "infill_percent")
|
||||||
|
private Integer infillPercent;
|
||||||
|
|
||||||
|
@ColumnDefault("false")
|
||||||
|
@Column(name = "supports_enabled", nullable = false)
|
||||||
|
private Boolean supportsEnabled;
|
||||||
|
|
||||||
|
@Column(name = "notes", length = Integer.MAX_VALUE)
|
||||||
|
private String notes;
|
||||||
|
|
||||||
|
@ColumnDefault("0.00")
|
||||||
|
@Column(name = "setup_cost_chf", nullable = false, precision = 12, scale = 2)
|
||||||
|
private BigDecimal setupCostChf;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
@Column(name = "expires_at", nullable = false)
|
||||||
|
private OffsetDateTime expiresAt;
|
||||||
|
|
||||||
|
@Column(name = "converted_order_id")
|
||||||
|
private UUID convertedOrderId;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPricingVersion() {
|
||||||
|
return pricingVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPricingVersion(String pricingVersion) {
|
||||||
|
this.pricingVersion = pricingVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMaterialCode() {
|
||||||
|
return materialCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaterialCode(String materialCode) {
|
||||||
|
this.materialCode = materialCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getNozzleDiameterMm() {
|
||||||
|
return nozzleDiameterMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNozzleDiameterMm(BigDecimal nozzleDiameterMm) {
|
||||||
|
this.nozzleDiameterMm = nozzleDiameterMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getLayerHeightMm() {
|
||||||
|
return layerHeightMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLayerHeightMm(BigDecimal layerHeightMm) {
|
||||||
|
this.layerHeightMm = layerHeightMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInfillPattern() {
|
||||||
|
return infillPattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInfillPattern(String infillPattern) {
|
||||||
|
this.infillPattern = infillPattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getInfillPercent() {
|
||||||
|
return infillPercent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInfillPercent(Integer infillPercent) {
|
||||||
|
this.infillPercent = infillPercent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getSupportsEnabled() {
|
||||||
|
return supportsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSupportsEnabled(Boolean supportsEnabled) {
|
||||||
|
this.supportsEnabled = supportsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNotes() {
|
||||||
|
return notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotes(String notes) {
|
||||||
|
this.notes = notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getSetupCostChf() {
|
||||||
|
return setupCostChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSetupCostChf(BigDecimal setupCostChf) {
|
||||||
|
this.setupCostChf = setupCostChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getExpiresAt() {
|
||||||
|
return expiresAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExpiresAt(OffsetDateTime expiresAt) {
|
||||||
|
this.expiresAt = expiresAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getConvertedOrderId() {
|
||||||
|
return convertedOrderId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConvertedOrderId(UUID convertedOrderId) {
|
||||||
|
this.convertedOrderId = convertedOrderId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package com.printcalculator.exception;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.multipart.MaxUploadSizeExceededException;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
|
@ControllerAdvice
|
||||||
|
@Slf4j
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
@ExceptionHandler(StorageException.class)
|
||||||
|
public ResponseEntity<?> handleStorageException(StorageException exc) {
|
||||||
|
// Log the full exception for internal debugging
|
||||||
|
log.error("Storage Exception occurred", exc);
|
||||||
|
|
||||||
|
Map<String, String> response = new HashMap<>();
|
||||||
|
|
||||||
|
// Check for specific virus case
|
||||||
|
if (exc.getMessage() != null && exc.getMessage().contains("antivirus scanner")) {
|
||||||
|
response.put("error", "Security Violation");
|
||||||
|
// Safe message for client
|
||||||
|
response.put("message", "File rejected by security policy.");
|
||||||
|
response.put("code", "VIRUS_DETECTED");
|
||||||
|
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generic fallback for other storage errors to avoid leaking internal paths/details
|
||||||
|
response.put("error", "Storage Operation Failed");
|
||||||
|
response.put("message", "Unable to process the file upload.");
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(MaxUploadSizeExceededException.class)
|
||||||
|
public ResponseEntity<?> handleMaxSizeException(MaxUploadSizeExceededException exc) {
|
||||||
|
Map<String, String> response = new HashMap<>();
|
||||||
|
response.put("error", "File too large");
|
||||||
|
response.put("message", "The uploaded file exceeds the maximum allowed size.");
|
||||||
|
return ResponseEntity.status(HttpStatus.PAYLOAD_TOO_LARGE).body(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(ModelTooLargeException.class)
|
||||||
|
public ResponseEntity<?> handleModelTooLarge(ModelTooLargeException exc) {
|
||||||
|
Map<String, String> response = new HashMap<>();
|
||||||
|
response.put("error", "Model too large");
|
||||||
|
response.put("code", "MODEL_TOO_LARGE");
|
||||||
|
response.put("message", String.format(
|
||||||
|
"Model size %.2fx%.2fx%.2f mm exceeds build volume %dx%dx%d mm.",
|
||||||
|
exc.getModelX(), exc.getModelY(), exc.getModelZ(),
|
||||||
|
exc.getBuildX(), exc.getBuildY(), exc.getBuildZ()
|
||||||
|
));
|
||||||
|
response.put("model_x_mm", formatMm(exc.getModelX()));
|
||||||
|
response.put("model_y_mm", formatMm(exc.getModelY()));
|
||||||
|
response.put("model_z_mm", formatMm(exc.getModelZ()));
|
||||||
|
response.put("build_x_mm", String.valueOf(exc.getBuildX()));
|
||||||
|
response.put("build_y_mm", String.valueOf(exc.getBuildY()));
|
||||||
|
response.put("build_z_mm", String.valueOf(exc.getBuildZ()));
|
||||||
|
return ResponseEntity.unprocessableEntity().body(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatMm(double value) {
|
||||||
|
return BigDecimal.valueOf(value).setScale(2, RoundingMode.HALF_UP).toPlainString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.printcalculator.exception;
|
||||||
|
|
||||||
|
public class ModelTooLargeException extends RuntimeException {
|
||||||
|
private final double modelX;
|
||||||
|
private final double modelY;
|
||||||
|
private final double modelZ;
|
||||||
|
private final int buildX;
|
||||||
|
private final int buildY;
|
||||||
|
private final int buildZ;
|
||||||
|
|
||||||
|
public ModelTooLargeException(double modelX, double modelY, double modelZ,
|
||||||
|
int buildX, int buildY, int buildZ) {
|
||||||
|
super("Model size exceeds build volume");
|
||||||
|
this.modelX = modelX;
|
||||||
|
this.modelY = modelY;
|
||||||
|
this.modelZ = modelZ;
|
||||||
|
this.buildX = buildX;
|
||||||
|
this.buildY = buildY;
|
||||||
|
this.buildZ = buildZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getModelX() {
|
||||||
|
return modelX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getModelY() {
|
||||||
|
return modelY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getModelZ() {
|
||||||
|
return modelZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBuildX() {
|
||||||
|
return buildX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBuildY() {
|
||||||
|
return buildY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBuildZ() {
|
||||||
|
return buildZ;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.printcalculator.exception;
|
||||||
|
|
||||||
|
public class StorageException extends RuntimeException {
|
||||||
|
|
||||||
|
public StorageException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StorageException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package com.printcalculator.model;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
public record CostBreakdown(
|
|
||||||
BigDecimal materialCost,
|
|
||||||
BigDecimal machineCost,
|
|
||||||
BigDecimal energyCost,
|
|
||||||
BigDecimal subtotal,
|
|
||||||
BigDecimal markupAmount
|
|
||||||
) {}
|
|
||||||
@@ -1,8 +1,29 @@
|
|||||||
package com.printcalculator.model;
|
package com.printcalculator.model;
|
||||||
|
|
||||||
public record PrintStats(
|
import lombok.AllArgsConstructor;
|
||||||
long printTimeSeconds,
|
import lombok.Builder;
|
||||||
String printTimeFormatted,
|
import lombok.Data;
|
||||||
double filamentWeightGrams,
|
import lombok.NoArgsConstructor;
|
||||||
double filamentLengthMm
|
|
||||||
) {}
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class PrintStats {
|
||||||
|
private long printTimeSeconds;
|
||||||
|
private String printTimeFormatted;
|
||||||
|
private double filamentWeightGrams;
|
||||||
|
private double filamentLengthMm;
|
||||||
|
|
||||||
|
// Breakdown if available
|
||||||
|
private Double modelWeightGrams;
|
||||||
|
private Double supportWeightGrams;
|
||||||
|
|
||||||
|
// Legacy constructor for compatibility
|
||||||
|
public PrintStats(long printTimeSeconds, String printTimeFormatted, double filamentWeightGrams, double filamentLengthMm) {
|
||||||
|
this.printTimeSeconds = printTimeSeconds;
|
||||||
|
this.printTimeFormatted = printTimeFormatted;
|
||||||
|
this.filamentWeightGrams = filamentWeightGrams;
|
||||||
|
this.filamentLengthMm = filamentLengthMm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,12 +1,31 @@
|
|||||||
package com.printcalculator.model;
|
package com.printcalculator.model;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
public class QuoteResult {
|
||||||
import java.util.List;
|
private double totalPrice;
|
||||||
|
private String currency;
|
||||||
|
private PrintStats stats;
|
||||||
|
private double setupCost;
|
||||||
|
|
||||||
public record QuoteResult(
|
public QuoteResult(double totalPrice, String currency, PrintStats stats, double setupCost) {
|
||||||
BigDecimal totalPrice,
|
this.totalPrice = totalPrice;
|
||||||
String currency,
|
this.currency = currency;
|
||||||
PrintStats stats,
|
this.stats = stats;
|
||||||
CostBreakdown breakdown,
|
this.setupCost = setupCost;
|
||||||
List<String> notes
|
}
|
||||||
) {}
|
|
||||||
|
public double getTotalPrice() {
|
||||||
|
return totalPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCurrency() {
|
||||||
|
return currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrintStats getStats() {
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getSetupCost() {
|
||||||
|
return setupCost;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.printcalculator.model;
|
||||||
|
|
||||||
|
public record StlBounds(double minX, double minY, double minZ,
|
||||||
|
double maxX, double maxY, double maxZ) {
|
||||||
|
public double sizeX() {
|
||||||
|
return maxX - minX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double sizeY() {
|
||||||
|
return maxY - minY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double sizeZ() {
|
||||||
|
return maxZ - minZ;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.printcalculator.model;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public record StlShiftResult(Path shiftedPath,
|
||||||
|
double offsetX,
|
||||||
|
double offsetY,
|
||||||
|
double offsetZ,
|
||||||
|
boolean shifted) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.CustomQuoteRequestAttachment;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface CustomQuoteRequestAttachmentRepository extends JpaRepository<CustomQuoteRequestAttachment, UUID> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.CustomQuoteRequest;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface CustomQuoteRequestRepository extends JpaRepository<CustomQuoteRequest, UUID> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.Customer;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface CustomerRepository extends JpaRepository<Customer, UUID> {
|
||||||
|
Optional<Customer> findByEmail(String email);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.FilamentMaterialType;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface FilamentMaterialTypeRepository extends JpaRepository<FilamentMaterialType, Long> {
|
||||||
|
Optional<FilamentMaterialType> findByMaterialCode(String materialCode);
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.FilamentVariant;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.FilamentMaterialType;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface FilamentVariantRepository extends JpaRepository<FilamentVariant, Long> {
|
||||||
|
// We try to match by color name if possible, or get first active
|
||||||
|
Optional<FilamentVariant> findByFilamentMaterialTypeAndColorName(FilamentMaterialType type, String colorName);
|
||||||
|
Optional<FilamentVariant> findFirstByFilamentMaterialTypeAndIsActiveTrue(FilamentMaterialType type);
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.FilamentVariantStockKg;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface FilamentVariantStockKgRepository extends JpaRepository<FilamentVariantStockKg, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.InfillPattern;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface InfillPatternRepository extends JpaRepository<InfillPattern, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.LayerHeightOption;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface LayerHeightOptionRepository extends JpaRepository<LayerHeightOption, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.LayerHeightProfile;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface LayerHeightProfileRepository extends JpaRepository<LayerHeightProfile, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.NozzleOption;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface NozzleOptionRepository extends JpaRepository<NozzleOption, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.OrderItem;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface OrderItemRepository extends JpaRepository<OrderItem, UUID> {
|
||||||
|
List<OrderItem> findByOrder_Id(UUID orderId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.Order;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface OrderRepository extends JpaRepository<Order, UUID> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.Payment;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface PaymentRepository extends JpaRepository<Payment, UUID> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.PricingPolicyMachineHourTier;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.PricingPolicy;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface PricingPolicyMachineHourTierRepository extends JpaRepository<PricingPolicyMachineHourTier, Long> {
|
||||||
|
List<PricingPolicyMachineHourTier> findAllByPricingPolicyOrderByTierStartHoursAsc(PricingPolicy pricingPolicy);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.PricingPolicy;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface PricingPolicyRepository extends JpaRepository<PricingPolicy, Long> {
|
||||||
|
PricingPolicy findFirstByIsActiveTrueOrderByValidFromDesc();
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.PrinterFleetCurrent;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface PrinterFleetCurrentRepository extends JpaRepository<PrinterFleetCurrent, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.PrinterMachine;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface PrinterMachineRepository extends JpaRepository<PrinterMachine, Long> {
|
||||||
|
Optional<PrinterMachine> findByPrinterDisplayName(String printerDisplayName);
|
||||||
|
Optional<PrinterMachine> findFirstByIsActiveTrue();
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.QuoteLineItem;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface QuoteLineItemRepository extends JpaRepository<QuoteLineItem, UUID> {
|
||||||
|
List<QuoteLineItem> findByQuoteSessionId(UUID quoteSessionId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.QuoteSession;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface QuoteSessionRepository extends JpaRepository<QuoteSession, UUID> {
|
||||||
|
List<QuoteSession> findByCreatedAtBefore(java.time.OffsetDateTime cutoff);
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package com.printcalculator.service;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import xyz.capybara.clamav.ClamavClient;
|
||||||
|
import xyz.capybara.clamav.commands.scan.result.ScanResult;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ClamAVService {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ClamAVService.class);
|
||||||
|
|
||||||
|
private final ClamavClient clamavClient;
|
||||||
|
private final boolean enabled;
|
||||||
|
|
||||||
|
public ClamAVService(
|
||||||
|
@Value("${clamav.host:clamav}") String host,
|
||||||
|
@Value("${clamav.port:3310}") int port,
|
||||||
|
@Value("${clamav.enabled:false}") boolean enabled
|
||||||
|
) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
if (!enabled) {
|
||||||
|
logger.info("ClamAV is DISABLED");
|
||||||
|
this.clamavClient = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger.info("Initializing ClamAV client at {}:{}", host, port);
|
||||||
|
ClamavClient client = null;
|
||||||
|
try {
|
||||||
|
client = new ClamavClient(host, port);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Failed to initialize ClamAV client: " + e.getMessage());
|
||||||
|
}
|
||||||
|
this.clamavClient = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean scan(InputStream inputStream) {
|
||||||
|
if (!enabled || clamavClient == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ScanResult result = clamavClient.scan(inputStream);
|
||||||
|
if (result instanceof ScanResult.OK) {
|
||||||
|
return true;
|
||||||
|
} else if (result instanceof ScanResult.VirusFound) {
|
||||||
|
Map<String, Collection<String>> viruses = ((ScanResult.VirusFound) result).getFoundViruses();
|
||||||
|
logger.warn("VIRUS DETECTED: {}", viruses);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
logger.warn("Unknown scan result: {}. Allowing file (FAIL-OPEN)", result);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error scanning file with ClamAV. Allowing file (FAIL-OPEN)", e);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package com.printcalculator.service;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.UrlResource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import com.printcalculator.exception.StorageException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class FileSystemStorageService implements StorageService {
|
||||||
|
|
||||||
|
private final Path rootLocation;
|
||||||
|
private final ClamAVService clamAVService;
|
||||||
|
|
||||||
|
public FileSystemStorageService(@Value("${storage.location:storage_orders}") String storageLocation, ClamAVService clamAVService) {
|
||||||
|
this.rootLocation = Paths.get(storageLocation);
|
||||||
|
this.clamAVService = clamAVService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
try {
|
||||||
|
Files.createDirectories(rootLocation);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new StorageException("Could not initialize storage", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void store(MultipartFile file, Path destinationRelativePath) throws IOException {
|
||||||
|
Path destinationFile = this.rootLocation.resolve(destinationRelativePath).normalize().toAbsolutePath();
|
||||||
|
if (!destinationFile.getParent().startsWith(this.rootLocation.toAbsolutePath())) {
|
||||||
|
throw new StorageException("Cannot store file outside current directory.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Salva prima il file su disco per evitare problemi di stream con file grandi
|
||||||
|
Files.createDirectories(destinationFile.getParent());
|
||||||
|
file.transferTo(destinationFile.toFile());
|
||||||
|
|
||||||
|
// 2. Scansiona il file appena salvato aprendo un nuovo stream
|
||||||
|
try (InputStream inputStream = new FileInputStream(destinationFile.toFile())) {
|
||||||
|
if (!clamAVService.scan(inputStream)) {
|
||||||
|
// Se infetto, cancella il file e solleva eccezione
|
||||||
|
Files.deleteIfExists(destinationFile);
|
||||||
|
throw new StorageException("File rejected by antivirus scanner.");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (e instanceof StorageException) throw e;
|
||||||
|
// Se l'antivirus fallisce per motivi tecnici, lasciamo il file (fail-open come concordato)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void store(Path source, Path destinationRelativePath) throws IOException {
|
||||||
|
Path destinationFile = this.rootLocation.resolve(destinationRelativePath).normalize().toAbsolutePath();
|
||||||
|
if (!destinationFile.getParent().startsWith(this.rootLocation.toAbsolutePath())) {
|
||||||
|
throw new StorageException("Cannot store file outside current directory.");
|
||||||
|
}
|
||||||
|
Files.createDirectories(destinationFile.getParent());
|
||||||
|
Files.copy(source, destinationFile, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Path path) throws IOException {
|
||||||
|
Path file = rootLocation.resolve(path);
|
||||||
|
Files.deleteIfExists(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource loadAsResource(Path path) throws IOException {
|
||||||
|
try {
|
||||||
|
Path file = rootLocation.resolve(path);
|
||||||
|
Resource resource = new UrlResource(file.toUri());
|
||||||
|
if (resource.exists() || resource.isReadable()) {
|
||||||
|
return resource;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Could not read file: " + path);
|
||||||
|
}
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new RuntimeException("Could not read file: " + path, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,24 +13,59 @@ import java.util.regex.Pattern;
|
|||||||
@Service
|
@Service
|
||||||
public class GCodeParser {
|
public class GCodeParser {
|
||||||
|
|
||||||
private static final Pattern TIME_PATTERN = Pattern.compile("estimated printing time = (.*)");
|
// OrcaSlicer/BambuStudio format
|
||||||
private static final Pattern FILAMENT_G_PATTERN = Pattern.compile("filament used \\[g\\] = (.*)");
|
// ; estimated printing time = 1h 2m 3s
|
||||||
private static final Pattern FILAMENT_MM_PATTERN = Pattern.compile("filament used \\[mm\\] = (.*)");
|
// ; filament used [g] = 12.34
|
||||||
|
// ; filament used [mm] = 1234.56
|
||||||
|
private static final Pattern TOTAL_ESTIMATED_TIME_PATTERN = Pattern.compile(
|
||||||
|
";\\s*.*total\\s+estimated\\s+time\\s*[:=]\\s*([^;]+)",
|
||||||
|
Pattern.CASE_INSENSITIVE);
|
||||||
|
private static final Pattern MODEL_PRINTING_TIME_PATTERN = Pattern.compile(
|
||||||
|
";\\s*.*model\\s+printing\\s+time\\s*[:=]\\s*([^;]+)",
|
||||||
|
Pattern.CASE_INSENSITIVE);
|
||||||
|
private static final Pattern TIME_PATTERN = Pattern.compile(
|
||||||
|
";\\s*(?:estimated\\s+printing\\s+time|estimated\\s+print\\s+time|print\\s+time).*?[:=]\\s*(.*)",
|
||||||
|
Pattern.CASE_INSENSITIVE);
|
||||||
|
private static final Pattern FILAMENT_G_PATTERN = Pattern.compile(";\\s*filament used \\[g\\]\\s*=\\s*([^;\\(\\n\\r]+)(?:\\s*\\(([^,]+) model,\\s*([^ ]+) support\\))?");
|
||||||
|
private static final Pattern FILAMENT_MM_PATTERN = Pattern.compile(";\\s*filament used \\[mm\\]\\s*=\\s*(.*)");
|
||||||
|
|
||||||
public PrintStats parse(File gcodeFile) throws IOException {
|
public PrintStats parse(File gcodeFile) throws IOException {
|
||||||
long seconds = 0;
|
long seconds = 0;
|
||||||
double weightG = 0;
|
double weightG = 0;
|
||||||
double lengthMm = 0;
|
double lengthMm = 0;
|
||||||
|
Double modelWeightG = null;
|
||||||
|
Double supportWeightG = null;
|
||||||
String timeFormatted = "";
|
String timeFormatted = "";
|
||||||
|
|
||||||
try (BufferedReader reader = new BufferedReader(new FileReader(gcodeFile))) {
|
try (BufferedReader reader = new BufferedReader(new FileReader(gcodeFile))) {
|
||||||
String line;
|
String line;
|
||||||
// Scan first 500 lines for efficiency
|
|
||||||
int count = 0;
|
// Scan entire file as metadata is often at the end
|
||||||
while ((line = reader.readLine()) != null && count < 500) {
|
while ((line = reader.readLine()) != null) {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
|
|
||||||
|
// OrcaSlicer comments start with ;
|
||||||
if (!line.startsWith(";")) {
|
if (!line.startsWith(";")) {
|
||||||
count++;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.toLowerCase().contains("estimated printing time")) {
|
||||||
|
System.out.println("DEBUG: Found potential time line: '" + line + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher totalTimeMatcher = TOTAL_ESTIMATED_TIME_PATTERN.matcher(line);
|
||||||
|
if (totalTimeMatcher.find()) {
|
||||||
|
timeFormatted = totalTimeMatcher.group(1).trim();
|
||||||
|
seconds = parseTimeString(timeFormatted);
|
||||||
|
System.out.println("GCodeParser: Found total estimated time: " + timeFormatted + " (" + seconds + "s)");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher modelTimeMatcher = MODEL_PRINTING_TIME_PATTERN.matcher(line);
|
||||||
|
if (modelTimeMatcher.find()) {
|
||||||
|
timeFormatted = modelTimeMatcher.group(1).trim();
|
||||||
|
seconds = parseTimeString(timeFormatted);
|
||||||
|
System.out.println("GCodeParser: Found model printing time: " + timeFormatted + " (" + seconds + "s)");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,12 +73,21 @@ public class GCodeParser {
|
|||||||
if (timeMatcher.find()) {
|
if (timeMatcher.find()) {
|
||||||
timeFormatted = timeMatcher.group(1).trim();
|
timeFormatted = timeMatcher.group(1).trim();
|
||||||
seconds = parseTimeString(timeFormatted);
|
seconds = parseTimeString(timeFormatted);
|
||||||
|
System.out.println("GCodeParser: Found time: " + timeFormatted + " (" + seconds + "s)");
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher weightMatcher = FILAMENT_G_PATTERN.matcher(line);
|
Matcher weightMatcher = FILAMENT_G_PATTERN.matcher(line);
|
||||||
if (weightMatcher.find()) {
|
if (weightMatcher.find()) {
|
||||||
try {
|
try {
|
||||||
weightG = Double.parseDouble(weightMatcher.group(1).trim());
|
weightG = Double.parseDouble(weightMatcher.group(1).trim());
|
||||||
|
System.out.println("GCodeParser: Found total weight: " + weightG + "g");
|
||||||
|
|
||||||
|
// Check if we have groups 2 and 3 for breakdown
|
||||||
|
if (weightMatcher.groupCount() >= 3 && weightMatcher.group(2) != null) {
|
||||||
|
modelWeightG = Double.parseDouble(weightMatcher.group(2).trim());
|
||||||
|
supportWeightG = Double.parseDouble(weightMatcher.group(3).trim());
|
||||||
|
System.out.println("GCodeParser: Found breakdown - Model: " + modelWeightG + "g, Support: " + supportWeightG + "g");
|
||||||
|
}
|
||||||
} catch (NumberFormatException ignored) {}
|
} catch (NumberFormatException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,31 +95,77 @@ public class GCodeParser {
|
|||||||
if (lengthMatcher.find()) {
|
if (lengthMatcher.find()) {
|
||||||
try {
|
try {
|
||||||
lengthMm = Double.parseDouble(lengthMatcher.group(1).trim());
|
lengthMm = Double.parseDouble(lengthMatcher.group(1).trim());
|
||||||
|
System.out.println("GCodeParser: Found length: " + lengthMm + "mm");
|
||||||
} catch (NumberFormatException ignored) {}
|
} catch (NumberFormatException ignored) {}
|
||||||
}
|
}
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PrintStats(seconds, timeFormatted, weightG, lengthMm);
|
return PrintStats.builder()
|
||||||
|
.printTimeSeconds(seconds)
|
||||||
|
.printTimeFormatted(timeFormatted)
|
||||||
|
.filamentWeightGrams(weightG)
|
||||||
|
.filamentLengthMm(lengthMm)
|
||||||
|
.modelWeightGrams(modelWeightG)
|
||||||
|
.supportWeightGrams(supportWeightG)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private long parseTimeString(String timeStr) {
|
private long parseTimeString(String timeStr) {
|
||||||
// Formats: "1d 2h 3m 4s" or "1h 20m 10s"
|
// Formats: "1d 2h 3m 4s", "1h 20m 10s", "01:23:45", "12:34"
|
||||||
long totalSeconds = 0;
|
String lower = timeStr.toLowerCase();
|
||||||
|
double totalSeconds = 0;
|
||||||
Matcher d = Pattern.compile("(\\d+)d").matcher(timeStr);
|
boolean matched = false;
|
||||||
if (d.find()) totalSeconds += Long.parseLong(d.group(1)) * 86400;
|
|
||||||
|
|
||||||
Matcher h = Pattern.compile("(\\d+)h").matcher(timeStr);
|
Matcher d = Pattern.compile("(\\d+(?:\\.\\d+)?)\\s*d").matcher(lower);
|
||||||
if (h.find()) totalSeconds += Long.parseLong(h.group(1)) * 3600;
|
if (d.find()) {
|
||||||
|
totalSeconds += Double.parseDouble(d.group(1)) * 86400;
|
||||||
|
matched = true;
|
||||||
|
}
|
||||||
|
|
||||||
Matcher m = Pattern.compile("(\\d+)m").matcher(timeStr);
|
Matcher h = Pattern.compile("(\\d+(?:\\.\\d+)?)\\s*h").matcher(lower);
|
||||||
if (m.find()) totalSeconds += Long.parseLong(m.group(1)) * 60;
|
if (h.find()) {
|
||||||
|
totalSeconds += Double.parseDouble(h.group(1)) * 3600;
|
||||||
|
matched = true;
|
||||||
|
}
|
||||||
|
|
||||||
Matcher s = Pattern.compile("(\\d+)s").matcher(timeStr);
|
Matcher m = Pattern.compile("(\\d+(?:\\.\\d+)?)\\s*m").matcher(lower);
|
||||||
if (s.find()) totalSeconds += Long.parseLong(s.group(1));
|
if (m.find()) {
|
||||||
|
totalSeconds += Double.parseDouble(m.group(1)) * 60;
|
||||||
|
matched = true;
|
||||||
|
}
|
||||||
|
|
||||||
return totalSeconds;
|
Matcher s = Pattern.compile("(\\d+(?:\\.\\d+)?)\\s*s").matcher(lower);
|
||||||
|
if (s.find()) {
|
||||||
|
totalSeconds += Double.parseDouble(s.group(1));
|
||||||
|
matched = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matched) {
|
||||||
|
return Math.round(totalSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
long daySeconds = 0;
|
||||||
|
Matcher dayPrefix = Pattern.compile("(\\d+)\\s*d").matcher(lower);
|
||||||
|
if (dayPrefix.find()) {
|
||||||
|
daySeconds = Long.parseLong(dayPrefix.group(1)) * 86400;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher hms = Pattern.compile("(\\d{1,2}):(\\d{2}):(\\d{2})").matcher(lower);
|
||||||
|
if (hms.find()) {
|
||||||
|
long hours = Long.parseLong(hms.group(1));
|
||||||
|
long minutes = Long.parseLong(hms.group(2));
|
||||||
|
long seconds = Long.parseLong(hms.group(3));
|
||||||
|
return daySeconds + hours * 3600 + minutes * 60 + seconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher ms = Pattern.compile("(\\d{1,2}):(\\d{2})").matcher(lower);
|
||||||
|
if (ms.find()) {
|
||||||
|
long minutes = Long.parseLong(ms.group(1));
|
||||||
|
long seconds = Long.parseLong(ms.group(2));
|
||||||
|
return daySeconds + minutes * 60 + seconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.printcalculator.service;
|
||||||
|
|
||||||
|
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
|
||||||
|
import com.openhtmltopdf.svgsupport.BatikSVGDrawer;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.thymeleaf.TemplateEngine;
|
||||||
|
import org.thymeleaf.context.Context;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class InvoicePdfRenderingService {
|
||||||
|
|
||||||
|
private final TemplateEngine thymeleafTemplateEngine;
|
||||||
|
|
||||||
|
public InvoicePdfRenderingService(TemplateEngine thymeleafTemplateEngine) {
|
||||||
|
this.thymeleafTemplateEngine = thymeleafTemplateEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] generateInvoicePdfBytesFromTemplate(Map<String, Object> invoiceTemplateVariables, String qrBillSvg) {
|
||||||
|
try {
|
||||||
|
Context thymeleafContextWithInvoiceData = new Context(Locale.ITALY);
|
||||||
|
thymeleafContextWithInvoiceData.setVariables(invoiceTemplateVariables);
|
||||||
|
thymeleafContextWithInvoiceData.setVariable("qrBillSvg", qrBillSvg);
|
||||||
|
|
||||||
|
String renderedInvoiceHtml = thymeleafTemplateEngine.process("invoice", thymeleafContextWithInvoiceData);
|
||||||
|
|
||||||
|
String classpathBaseUrlForHtmlResources = new ClassPathResource("templates/").getURL().toExternalForm();
|
||||||
|
|
||||||
|
ByteArrayOutputStream generatedPdfByteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
PdfRendererBuilder openHtmlToPdfRendererBuilder = new PdfRendererBuilder();
|
||||||
|
openHtmlToPdfRendererBuilder.useFastMode();
|
||||||
|
openHtmlToPdfRendererBuilder.useSVGDrawer(new BatikSVGDrawer());
|
||||||
|
openHtmlToPdfRendererBuilder.withHtmlContent(renderedInvoiceHtml, classpathBaseUrlForHtmlResources);
|
||||||
|
openHtmlToPdfRendererBuilder.toStream(generatedPdfByteArrayOutputStream);
|
||||||
|
openHtmlToPdfRendererBuilder.run();
|
||||||
|
|
||||||
|
return generatedPdfByteArrayOutputStream.toByteArray();
|
||||||
|
} catch (Exception pdfGenerationException) {
|
||||||
|
throw new IllegalStateException("PDF invoice generation failed", pdfGenerationException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,300 @@
|
|||||||
|
package com.printcalculator.service;
|
||||||
|
|
||||||
|
import com.printcalculator.dto.AddressDto;
|
||||||
|
import com.printcalculator.dto.CreateOrderRequest;
|
||||||
|
import com.printcalculator.entity.*;
|
||||||
|
import com.printcalculator.repository.CustomerRepository;
|
||||||
|
import com.printcalculator.repository.OrderItemRepository;
|
||||||
|
import com.printcalculator.repository.OrderRepository;
|
||||||
|
import com.printcalculator.repository.QuoteLineItemRepository;
|
||||||
|
import com.printcalculator.repository.QuoteSessionRepository;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class OrderService {
|
||||||
|
|
||||||
|
private final OrderRepository orderRepo;
|
||||||
|
private final OrderItemRepository orderItemRepo;
|
||||||
|
private final QuoteSessionRepository quoteSessionRepo;
|
||||||
|
private final QuoteLineItemRepository quoteLineItemRepo;
|
||||||
|
private final CustomerRepository customerRepo;
|
||||||
|
private final StorageService storageService;
|
||||||
|
private final InvoicePdfRenderingService invoiceService;
|
||||||
|
private final QrBillService qrBillService;
|
||||||
|
|
||||||
|
public OrderService(OrderRepository orderRepo,
|
||||||
|
OrderItemRepository orderItemRepo,
|
||||||
|
QuoteSessionRepository quoteSessionRepo,
|
||||||
|
QuoteLineItemRepository quoteLineItemRepo,
|
||||||
|
CustomerRepository customerRepo,
|
||||||
|
StorageService storageService,
|
||||||
|
InvoicePdfRenderingService invoiceService,
|
||||||
|
QrBillService qrBillService) {
|
||||||
|
this.orderRepo = orderRepo;
|
||||||
|
this.orderItemRepo = orderItemRepo;
|
||||||
|
this.quoteSessionRepo = quoteSessionRepo;
|
||||||
|
this.quoteLineItemRepo = quoteLineItemRepo;
|
||||||
|
this.customerRepo = customerRepo;
|
||||||
|
this.storageService = storageService;
|
||||||
|
this.invoiceService = invoiceService;
|
||||||
|
this.qrBillService = qrBillService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Order createOrderFromQuote(UUID quoteSessionId, CreateOrderRequest request) {
|
||||||
|
QuoteSession session = quoteSessionRepo.findById(quoteSessionId)
|
||||||
|
.orElseThrow(() -> new RuntimeException("Quote Session not found"));
|
||||||
|
|
||||||
|
if (session.getConvertedOrderId() != null) {
|
||||||
|
throw new IllegalStateException("Quote session already converted to order");
|
||||||
|
}
|
||||||
|
|
||||||
|
Customer customer = customerRepo.findByEmail(request.getCustomer().getEmail())
|
||||||
|
.orElseGet(() -> {
|
||||||
|
Customer newC = new Customer();
|
||||||
|
newC.setEmail(request.getCustomer().getEmail());
|
||||||
|
newC.setCustomerType(request.getCustomer().getCustomerType());
|
||||||
|
newC.setCreatedAt(OffsetDateTime.now());
|
||||||
|
newC.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
return customerRepo.save(newC);
|
||||||
|
});
|
||||||
|
|
||||||
|
customer.setPhone(request.getCustomer().getPhone());
|
||||||
|
customer.setCustomerType(request.getCustomer().getCustomerType());
|
||||||
|
customer.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
customerRepo.save(customer);
|
||||||
|
|
||||||
|
Order order = new Order();
|
||||||
|
order.setSourceQuoteSession(session);
|
||||||
|
order.setCustomer(customer);
|
||||||
|
order.setCustomerEmail(request.getCustomer().getEmail());
|
||||||
|
order.setCustomerPhone(request.getCustomer().getPhone());
|
||||||
|
order.setStatus("PENDING_PAYMENT");
|
||||||
|
order.setCreatedAt(OffsetDateTime.now());
|
||||||
|
order.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
order.setCurrency("CHF");
|
||||||
|
|
||||||
|
order.setBillingCustomerType(request.getCustomer().getCustomerType());
|
||||||
|
if (request.getBillingAddress() != null) {
|
||||||
|
order.setBillingFirstName(request.getBillingAddress().getFirstName());
|
||||||
|
order.setBillingLastName(request.getBillingAddress().getLastName());
|
||||||
|
order.setBillingCompanyName(request.getBillingAddress().getCompanyName());
|
||||||
|
order.setBillingContactPerson(request.getBillingAddress().getContactPerson());
|
||||||
|
order.setBillingAddressLine1(request.getBillingAddress().getAddressLine1());
|
||||||
|
order.setBillingAddressLine2(request.getBillingAddress().getAddressLine2());
|
||||||
|
order.setBillingZip(request.getBillingAddress().getZip());
|
||||||
|
order.setBillingCity(request.getBillingAddress().getCity());
|
||||||
|
order.setBillingCountryCode(request.getBillingAddress().getCountryCode() != null ? request.getBillingAddress().getCountryCode() : "CH");
|
||||||
|
}
|
||||||
|
|
||||||
|
order.setShippingSameAsBilling(request.isShippingSameAsBilling());
|
||||||
|
if (!request.isShippingSameAsBilling() && request.getShippingAddress() != null) {
|
||||||
|
order.setShippingFirstName(request.getShippingAddress().getFirstName());
|
||||||
|
order.setShippingLastName(request.getShippingAddress().getLastName());
|
||||||
|
order.setShippingCompanyName(request.getShippingAddress().getCompanyName());
|
||||||
|
order.setShippingContactPerson(request.getShippingAddress().getContactPerson());
|
||||||
|
order.setShippingAddressLine1(request.getShippingAddress().getAddressLine1());
|
||||||
|
order.setShippingAddressLine2(request.getShippingAddress().getAddressLine2());
|
||||||
|
order.setShippingZip(request.getShippingAddress().getZip());
|
||||||
|
order.setShippingCity(request.getShippingAddress().getCity());
|
||||||
|
order.setShippingCountryCode(request.getShippingAddress().getCountryCode() != null ? request.getShippingAddress().getCountryCode() : "CH");
|
||||||
|
} else {
|
||||||
|
order.setShippingFirstName(order.getBillingFirstName());
|
||||||
|
order.setShippingLastName(order.getBillingLastName());
|
||||||
|
order.setShippingCompanyName(order.getBillingCompanyName());
|
||||||
|
order.setShippingContactPerson(order.getBillingContactPerson());
|
||||||
|
order.setShippingAddressLine1(order.getBillingAddressLine1());
|
||||||
|
order.setShippingAddressLine2(order.getBillingAddressLine2());
|
||||||
|
order.setShippingZip(order.getBillingZip());
|
||||||
|
order.setShippingCity(order.getBillingCity());
|
||||||
|
order.setShippingCountryCode(order.getBillingCountryCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<QuoteLineItem> quoteItems = quoteLineItemRepo.findByQuoteSessionId(quoteSessionId);
|
||||||
|
|
||||||
|
BigDecimal subtotal = BigDecimal.ZERO;
|
||||||
|
order.setSubtotalChf(BigDecimal.ZERO);
|
||||||
|
order.setTotalChf(BigDecimal.ZERO);
|
||||||
|
order.setDiscountChf(BigDecimal.ZERO);
|
||||||
|
order.setSetupCostChf(session.getSetupCostChf() != null ? session.getSetupCostChf() : BigDecimal.ZERO);
|
||||||
|
order.setShippingCostChf(BigDecimal.valueOf(9.00));
|
||||||
|
|
||||||
|
order = orderRepo.save(order);
|
||||||
|
|
||||||
|
List<OrderItem> savedItems = new ArrayList<>();
|
||||||
|
|
||||||
|
for (QuoteLineItem qItem : quoteItems) {
|
||||||
|
OrderItem oItem = new OrderItem();
|
||||||
|
oItem.setOrder(order);
|
||||||
|
oItem.setOriginalFilename(qItem.getOriginalFilename());
|
||||||
|
oItem.setQuantity(qItem.getQuantity());
|
||||||
|
oItem.setColorCode(qItem.getColorCode());
|
||||||
|
oItem.setMaterialCode(session.getMaterialCode());
|
||||||
|
|
||||||
|
oItem.setUnitPriceChf(qItem.getUnitPriceChf());
|
||||||
|
oItem.setLineTotalChf(qItem.getUnitPriceChf().multiply(BigDecimal.valueOf(qItem.getQuantity())));
|
||||||
|
oItem.setPrintTimeSeconds(qItem.getPrintTimeSeconds());
|
||||||
|
oItem.setMaterialGrams(qItem.getMaterialGrams());
|
||||||
|
|
||||||
|
UUID fileUuid = UUID.randomUUID();
|
||||||
|
String ext = getExtension(qItem.getOriginalFilename());
|
||||||
|
String storedFilename = fileUuid.toString() + "." + ext;
|
||||||
|
|
||||||
|
oItem.setStoredFilename(storedFilename);
|
||||||
|
oItem.setStoredRelativePath("PENDING");
|
||||||
|
oItem.setMimeType("application/octet-stream");
|
||||||
|
oItem.setCreatedAt(OffsetDateTime.now());
|
||||||
|
|
||||||
|
oItem = orderItemRepo.save(oItem);
|
||||||
|
|
||||||
|
String relativePath = "orders/" + order.getId() + "/3d-files/" + oItem.getId() + "/" + storedFilename;
|
||||||
|
oItem.setStoredRelativePath(relativePath);
|
||||||
|
|
||||||
|
if (qItem.getStoredPath() != null) {
|
||||||
|
try {
|
||||||
|
Path sourcePath = Paths.get(qItem.getStoredPath());
|
||||||
|
if (Files.exists(sourcePath)) {
|
||||||
|
storageService.store(sourcePath, Paths.get(relativePath));
|
||||||
|
oItem.setFileSizeBytes(Files.size(sourcePath));
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
oItem = orderItemRepo.save(oItem);
|
||||||
|
savedItems.add(oItem);
|
||||||
|
subtotal = subtotal.add(oItem.getLineTotalChf());
|
||||||
|
}
|
||||||
|
|
||||||
|
order.setSubtotalChf(subtotal);
|
||||||
|
if (order.getShippingCostChf() == null) {
|
||||||
|
order.setShippingCostChf(BigDecimal.valueOf(9.00));
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal total = subtotal.add(order.getSetupCostChf()).add(order.getShippingCostChf()).subtract(order.getDiscountChf() != null ? order.getDiscountChf() : BigDecimal.ZERO);
|
||||||
|
order.setTotalChf(total);
|
||||||
|
|
||||||
|
session.setConvertedOrderId(order.getId());
|
||||||
|
session.setStatus("CONVERTED");
|
||||||
|
quoteSessionRepo.save(session);
|
||||||
|
|
||||||
|
// Generate Invoice and QR Bill
|
||||||
|
generateAndSaveDocuments(order, savedItems);
|
||||||
|
|
||||||
|
return orderRepo.save(order);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateAndSaveDocuments(Order order, List<OrderItem> items) {
|
||||||
|
try {
|
||||||
|
// 1. Generate QR Bill
|
||||||
|
byte[] qrBillSvgBytes = qrBillService.generateQrBillSvg(order);
|
||||||
|
String qrBillSvg = new String(qrBillSvgBytes, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
// Strip XML declaration and DOCTYPE if present, as they validity break the embedding HTML page
|
||||||
|
if (qrBillSvg.contains("<?xml")) {
|
||||||
|
int svgStartIndex = qrBillSvg.indexOf("<svg");
|
||||||
|
if (svgStartIndex != -1) {
|
||||||
|
qrBillSvg = qrBillSvg.substring(svgStartIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save QR Bill SVG
|
||||||
|
String qrRelativePath = "orders/" + order.getId() + "/documents/qr-bill.svg";
|
||||||
|
saveFileBytes(qrBillSvgBytes, qrRelativePath);
|
||||||
|
|
||||||
|
// 2. Prepare Invoice Variables
|
||||||
|
Map<String, Object> vars = new HashMap<>();
|
||||||
|
vars.put("sellerDisplayName", "3D Fab Switzerland");
|
||||||
|
vars.put("sellerAddressLine1", "Sede Ticino, Svizzera");
|
||||||
|
vars.put("sellerAddressLine2", "Sede Bienne, Svizzera");
|
||||||
|
vars.put("sellerEmail", "info@3dfab.ch");
|
||||||
|
|
||||||
|
vars.put("invoiceNumber", "INV-" + order.getId().toString().substring(0, 8).toUpperCase());
|
||||||
|
vars.put("invoiceDate", order.getCreatedAt().format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||||
|
vars.put("dueDate", order.getCreatedAt().plusDays(7).format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||||
|
|
||||||
|
String buyerName = "BUSINESS".equals(order.getBillingCustomerType())
|
||||||
|
? order.getBillingCompanyName()
|
||||||
|
: order.getBillingFirstName() + " " + order.getBillingLastName();
|
||||||
|
vars.put("buyerDisplayName", buyerName);
|
||||||
|
vars.put("buyerAddressLine1", order.getBillingAddressLine1());
|
||||||
|
vars.put("buyerAddressLine2", order.getBillingZip() + " " + order.getBillingCity() + ", " + order.getBillingCountryCode());
|
||||||
|
|
||||||
|
List<Map<String, Object>> invoiceLineItems = items.stream().map(i -> {
|
||||||
|
Map<String, Object> line = new HashMap<>();
|
||||||
|
line.put("description", "Stampa 3D: " + i.getOriginalFilename());
|
||||||
|
line.put("quantity", i.getQuantity());
|
||||||
|
line.put("unitPriceFormatted", String.format("CHF %.2f", i.getUnitPriceChf()));
|
||||||
|
line.put("lineTotalFormatted", String.format("CHF %.2f", i.getLineTotalChf()));
|
||||||
|
return line;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
Map<String, Object> setupLine = new HashMap<>();
|
||||||
|
setupLine.put("description", "Costo Setup");
|
||||||
|
setupLine.put("quantity", 1);
|
||||||
|
setupLine.put("unitPriceFormatted", String.format("CHF %.2f", order.getSetupCostChf()));
|
||||||
|
setupLine.put("lineTotalFormatted", String.format("CHF %.2f", order.getSetupCostChf()));
|
||||||
|
invoiceLineItems.add(setupLine);
|
||||||
|
|
||||||
|
Map<String, Object> shippingLine = new HashMap<>();
|
||||||
|
shippingLine.put("description", "Spedizione");
|
||||||
|
shippingLine.put("quantity", 1);
|
||||||
|
shippingLine.put("unitPriceFormatted", String.format("CHF %.2f", order.getShippingCostChf()));
|
||||||
|
shippingLine.put("lineTotalFormatted", String.format("CHF %.2f", order.getShippingCostChf()));
|
||||||
|
invoiceLineItems.add(shippingLine);
|
||||||
|
|
||||||
|
vars.put("invoiceLineItems", invoiceLineItems);
|
||||||
|
vars.put("subtotalFormatted", String.format("CHF %.2f", order.getSubtotalChf()));
|
||||||
|
vars.put("grandTotalFormatted", String.format("CHF %.2f", order.getTotalChf()));
|
||||||
|
vars.put("paymentTermsText", "Appena riceviamo il pagamento l'ordine entrerà nella coda di stampa. Grazie per la fiducia");
|
||||||
|
|
||||||
|
// 3. Generate PDF
|
||||||
|
byte[] pdfBytes = invoiceService.generateInvoicePdfBytesFromTemplate(vars, qrBillSvg);
|
||||||
|
|
||||||
|
// Save PDF
|
||||||
|
String pdfRelativePath = "orders/" + order.getId() + "/documents/invoice-" + order.getId() + ".pdf";
|
||||||
|
saveFileBytes(pdfBytes, pdfRelativePath);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
// Don't fail the order if document generation fails, but log it
|
||||||
|
// TODO: Better error handling
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveFileBytes(byte[] content, String relativePath) {
|
||||||
|
// Since StorageService takes paths, we might need to write to temp first or check if it supports bytes/streams
|
||||||
|
// Simulating via temp file for now as StorageService.store takes a Path
|
||||||
|
try {
|
||||||
|
Path tempFile = Files.createTempFile("print-calc-upload", ".tmp");
|
||||||
|
Files.write(tempFile, content);
|
||||||
|
storageService.store(tempFile, Paths.get(relativePath));
|
||||||
|
Files.delete(tempFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Failed to save file " + relativePath, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getExtension(String filename) {
|
||||||
|
if (filename == null) return "stl";
|
||||||
|
int i = filename.lastIndexOf('.');
|
||||||
|
if (i > 0) {
|
||||||
|
return filename.substring(i + 1);
|
||||||
|
}
|
||||||
|
return "stl";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,9 @@ import java.util.Iterator;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ProfileManager {
|
public class ProfileManager {
|
||||||
@@ -22,9 +25,31 @@ public class ProfileManager {
|
|||||||
private final String profilesRoot;
|
private final String profilesRoot;
|
||||||
private final ObjectMapper mapper;
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
|
private final Map<String, String> profileAliases;
|
||||||
|
|
||||||
public ProfileManager(@Value("${profiles.root:profiles}") String profilesRoot, ObjectMapper mapper) {
|
public ProfileManager(@Value("${profiles.root:profiles}") String profilesRoot, ObjectMapper mapper) {
|
||||||
this.profilesRoot = profilesRoot;
|
this.profilesRoot = profilesRoot;
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
|
this.profileAliases = new HashMap<>();
|
||||||
|
initializeAliases();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeAliases() {
|
||||||
|
// Machine Aliases
|
||||||
|
profileAliases.put("bambu_a1", "Bambu Lab A1 0.4 nozzle");
|
||||||
|
|
||||||
|
// Material Aliases
|
||||||
|
profileAliases.put("pla_basic", "Bambu PLA Basic @BBL A1");
|
||||||
|
profileAliases.put("petg_basic", "Bambu PETG Basic @BBL A1");
|
||||||
|
profileAliases.put("tpu_95a", "Bambu TPU 95A @BBL A1");
|
||||||
|
|
||||||
|
// Quality/Process Aliases
|
||||||
|
profileAliases.put("draft", "0.24mm Draft @BBL A1");
|
||||||
|
profileAliases.put("standard", "0.20mm Standard @BBL A1"); // or 0.20mm Standard @BBL A1
|
||||||
|
profileAliases.put("extra_fine", "0.08mm High Quality @BBL A1");
|
||||||
|
|
||||||
|
// Additional aliases from error logs
|
||||||
|
profileAliases.put("Bambu_Process_0.20_Standard", "0.20mm Standard @BBL A1");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectNode getMergedProfile(String profileName, String type) throws IOException {
|
public ObjectNode getMergedProfile(String profileName, String type) throws IOException {
|
||||||
@@ -35,10 +60,25 @@ public class ProfileManager {
|
|||||||
return resolveInheritance(profilePath);
|
return resolveInheritance(profilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String resolveMachineProfileName(String machineName, Double nozzleDiameter) {
|
||||||
|
String resolvedName = profileAliases.getOrDefault(machineName, machineName);
|
||||||
|
if (nozzleDiameter == null) return resolvedName;
|
||||||
|
|
||||||
|
String base = resolvedName.replaceAll("\\s*\\d+(?:\\.\\d+)?\\s*nozzle$", "").trim();
|
||||||
|
String formatted = BigDecimal.valueOf(nozzleDiameter).stripTrailingZeros().toPlainString();
|
||||||
|
String candidate = base + " " + formatted + " nozzle";
|
||||||
|
|
||||||
|
Path exists = findProfileFile(candidate, "machine");
|
||||||
|
return exists != null ? candidate : resolvedName;
|
||||||
|
}
|
||||||
|
|
||||||
private Path findProfileFile(String name, String type) {
|
private Path findProfileFile(String name, String type) {
|
||||||
|
// Check aliases first
|
||||||
|
String resolvedName = profileAliases.getOrDefault(name, name);
|
||||||
|
|
||||||
// Simple search: look for name.json in the profiles_root recursively
|
// Simple search: look for name.json in the profiles_root recursively
|
||||||
// Type could be "machine", "process", "filament" to narrow down, but for now global search
|
// Type could be "machine", "process", "filament" to narrow down, but for now global search
|
||||||
String filename = name.endsWith(".json") ? name : name + ".json";
|
String filename = resolvedName.endsWith(".json") ? resolvedName : resolvedName + ".json";
|
||||||
|
|
||||||
try (Stream<Path> stream = Files.walk(Paths.get(profilesRoot))) {
|
try (Stream<Path> stream = Files.walk(Paths.get(profilesRoot))) {
|
||||||
Optional<Path> found = stream
|
Optional<Path> found = stream
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.printcalculator.service;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.Order;
|
||||||
|
import net.codecrete.qrbill.generator.Bill;
|
||||||
|
import net.codecrete.qrbill.generator.GraphicsFormat;
|
||||||
|
import net.codecrete.qrbill.generator.QRBill;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class QrBillService {
|
||||||
|
|
||||||
|
public byte[] generateQrBillSvg(Order order) {
|
||||||
|
Bill bill = createBillFromOrder(order);
|
||||||
|
return QRBill.generate(bill);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bill createBillFromOrder(Order order) {
|
||||||
|
Bill bill = new Bill();
|
||||||
|
|
||||||
|
// Creditor (Merchant)
|
||||||
|
bill.setAccount("CH7409000000154821581"); // TODO: Configurable IBAN
|
||||||
|
bill.setCreditor(createAddress(
|
||||||
|
"Küng, Joe",
|
||||||
|
"Via G. Pioda 29a",
|
||||||
|
"6710",
|
||||||
|
"Biasca",
|
||||||
|
"CH"
|
||||||
|
));
|
||||||
|
|
||||||
|
// Debtor (Customer)
|
||||||
|
String debtorName;
|
||||||
|
if ("BUSINESS".equals(order.getBillingCustomerType())) {
|
||||||
|
debtorName = order.getBillingCompanyName();
|
||||||
|
} else {
|
||||||
|
debtorName = order.getBillingFirstName() + " " + order.getBillingLastName();
|
||||||
|
}
|
||||||
|
|
||||||
|
bill.setDebtor(createAddress(
|
||||||
|
debtorName,
|
||||||
|
order.getBillingAddressLine1(), // Assuming simple address for now. Splitting might be needed if street/house number are separate
|
||||||
|
order.getBillingZip(),
|
||||||
|
order.getBillingCity(),
|
||||||
|
order.getBillingCountryCode()
|
||||||
|
));
|
||||||
|
|
||||||
|
// Amount
|
||||||
|
bill.setAmount(order.getTotalChf());
|
||||||
|
bill.setCurrency("CHF");
|
||||||
|
|
||||||
|
// Reference
|
||||||
|
// bill.setReference(QRBill.createCreditorReference("...")); // If using QRR
|
||||||
|
bill.setUnstructuredMessage("Order " + order.getId());
|
||||||
|
|
||||||
|
return bill;
|
||||||
|
}
|
||||||
|
|
||||||
|
private net.codecrete.qrbill.generator.Address createAddress(String name, String street, String zip, String city, String country) {
|
||||||
|
net.codecrete.qrbill.generator.Address address = new net.codecrete.qrbill.generator.Address();
|
||||||
|
address.setName(name);
|
||||||
|
address.setStreet(street);
|
||||||
|
address.setPostalCode(zip);
|
||||||
|
address.setTown(city);
|
||||||
|
address.setCountryCode(country);
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,59 +1,168 @@
|
|||||||
package com.printcalculator.service;
|
package com.printcalculator.service;
|
||||||
|
|
||||||
import com.printcalculator.config.AppProperties;
|
|
||||||
import com.printcalculator.model.CostBreakdown;
|
import com.printcalculator.entity.FilamentMaterialType;
|
||||||
|
import com.printcalculator.entity.FilamentVariant;
|
||||||
|
import com.printcalculator.entity.PricingPolicy;
|
||||||
|
import com.printcalculator.entity.PricingPolicyMachineHourTier;
|
||||||
|
import com.printcalculator.entity.PrinterMachine;
|
||||||
import com.printcalculator.model.PrintStats;
|
import com.printcalculator.model.PrintStats;
|
||||||
import com.printcalculator.model.QuoteResult;
|
import com.printcalculator.model.QuoteResult;
|
||||||
|
import com.printcalculator.repository.FilamentMaterialTypeRepository;
|
||||||
|
import com.printcalculator.repository.FilamentVariantRepository;
|
||||||
|
import com.printcalculator.repository.PricingPolicyMachineHourTierRepository;
|
||||||
|
import com.printcalculator.repository.PricingPolicyRepository;
|
||||||
|
import com.printcalculator.repository.PrinterMachineRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class QuoteCalculator {
|
public class QuoteCalculator {
|
||||||
|
|
||||||
private final AppProperties props;
|
private final PricingPolicyRepository pricingRepo;
|
||||||
|
private final PricingPolicyMachineHourTierRepository tierRepo;
|
||||||
|
private final PrinterMachineRepository machineRepo;
|
||||||
|
private final FilamentMaterialTypeRepository materialRepo;
|
||||||
|
private final FilamentVariantRepository variantRepo;
|
||||||
|
|
||||||
public QuoteCalculator(AppProperties props) {
|
public QuoteCalculator(PricingPolicyRepository pricingRepo,
|
||||||
this.props = props;
|
PricingPolicyMachineHourTierRepository tierRepo,
|
||||||
|
PrinterMachineRepository machineRepo,
|
||||||
|
FilamentMaterialTypeRepository materialRepo,
|
||||||
|
FilamentVariantRepository variantRepo) {
|
||||||
|
this.pricingRepo = pricingRepo;
|
||||||
|
this.tierRepo = tierRepo;
|
||||||
|
this.machineRepo = machineRepo;
|
||||||
|
this.materialRepo = materialRepo;
|
||||||
|
this.variantRepo = variantRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QuoteResult calculate(PrintStats stats) {
|
public QuoteResult calculate(PrintStats stats, String machineName, String filamentProfileName) {
|
||||||
// Material Cost: (weight / 1000) * costPerKg
|
// 1. Fetch Active Policy
|
||||||
BigDecimal weightKg = BigDecimal.valueOf(stats.filamentWeightGrams()).divide(BigDecimal.valueOf(1000), 4, RoundingMode.HALF_UP);
|
PricingPolicy policy = pricingRepo.findFirstByIsActiveTrueOrderByValidFromDesc();
|
||||||
BigDecimal materialCost = weightKg.multiply(BigDecimal.valueOf(props.getFilamentCostPerKg()));
|
if (policy == null) {
|
||||||
|
throw new RuntimeException("No active pricing policy found");
|
||||||
|
}
|
||||||
|
|
||||||
// Machine Cost: (seconds / 3600) * costPerHour
|
// 2. Fetch Machine Info
|
||||||
BigDecimal hours = BigDecimal.valueOf(stats.printTimeSeconds()).divide(BigDecimal.valueOf(3600), 4, RoundingMode.HALF_UP);
|
// Map "bambu_a1" -> "BambuLab A1" or similar?
|
||||||
BigDecimal machineCost = hours.multiply(BigDecimal.valueOf(props.getMachineCostPerHour()));
|
// Ideally we should use the display name from DB.
|
||||||
|
// For now, if machineName is a code, we might need a mapping or just fuzzy search.
|
||||||
|
// Let's assume machineName is mapped or we search by display name.
|
||||||
|
// If not found, fallback to first active.
|
||||||
|
PrinterMachine machine = machineRepo.findByPrinterDisplayName(machineName).orElse(null);
|
||||||
|
if (machine == null) {
|
||||||
|
// Try "BambuLab A1" if code was "bambu_a1" logic or just get first active
|
||||||
|
machine = machineRepo.findFirstByIsActiveTrue()
|
||||||
|
.orElseThrow(() -> new RuntimeException("No active printer found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Fetch Filament Info
|
||||||
|
// filamentProfileName might be "bambu_pla_basic_black" or "Generic PLA"
|
||||||
|
// We try to extract material code (PLA, PETG)
|
||||||
|
String materialCode = detectMaterialCode(filamentProfileName);
|
||||||
|
FilamentMaterialType materialType = materialRepo.findByMaterialCode(materialCode)
|
||||||
|
.orElseThrow(() -> new RuntimeException("Unknown material type: " + materialCode));
|
||||||
|
|
||||||
|
// Try to find specific variant (e.g. by color if we could parse it)
|
||||||
|
// For now, get default/first active variant for this material
|
||||||
|
FilamentVariant variant = variantRepo.findFirstByFilamentMaterialTypeAndIsActiveTrue(materialType)
|
||||||
|
.orElseThrow(() -> new RuntimeException("No active variant for material: " + materialCode));
|
||||||
|
|
||||||
|
|
||||||
|
// --- CALCULATIONS ---
|
||||||
|
|
||||||
|
// Material Cost: (weight / 1000) * costPerKg
|
||||||
|
// DISCOUNTED Support material to avoid penalizing users for default supports
|
||||||
|
BigDecimal weightToCharge;
|
||||||
|
if (stats.getModelWeightGrams() != null && stats.getSupportWeightGrams() != null) {
|
||||||
|
// Charge 100% for model + 20% for support
|
||||||
|
weightToCharge = BigDecimal.valueOf(stats.getModelWeightGrams())
|
||||||
|
.add(BigDecimal.valueOf(stats.getSupportWeightGrams()).multiply(BigDecimal.valueOf(0.2)));
|
||||||
|
} else {
|
||||||
|
weightToCharge = BigDecimal.valueOf(stats.getFilamentWeightGrams());
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal weightKg = weightToCharge.divide(BigDecimal.valueOf(1000), 4, RoundingMode.HALF_UP);
|
||||||
|
BigDecimal materialCost = weightKg.multiply(variant.getCostChfPerKg());
|
||||||
|
|
||||||
|
// Machine Cost: Tiered
|
||||||
|
BigDecimal totalHours = BigDecimal.valueOf(stats.getPrintTimeSeconds()).divide(BigDecimal.valueOf(3600), 4, RoundingMode.HALF_UP);
|
||||||
|
BigDecimal machineCost = calculateMachineCost(policy, totalHours);
|
||||||
|
|
||||||
// Energy Cost: (watts / 1000) * hours * costPerKwh
|
// Energy Cost: (watts / 1000) * hours * costPerKwh
|
||||||
BigDecimal kw = BigDecimal.valueOf(props.getPrinterPowerWatts()).divide(BigDecimal.valueOf(1000), 4, RoundingMode.HALF_UP);
|
BigDecimal kw = BigDecimal.valueOf(machine.getPowerWatts()).divide(BigDecimal.valueOf(1000), 4, RoundingMode.HALF_UP);
|
||||||
BigDecimal kwh = kw.multiply(hours);
|
BigDecimal kwh = kw.multiply(totalHours);
|
||||||
BigDecimal energyCost = kwh.multiply(BigDecimal.valueOf(props.getEnergyCostPerKwh()));
|
BigDecimal energyCost = kwh.multiply(policy.getElectricityCostChfPerKwh());
|
||||||
|
|
||||||
// Subtotal
|
// Subtotal (Costs + Fixed Fees)
|
||||||
BigDecimal subtotal = materialCost.add(machineCost).add(energyCost);
|
BigDecimal fixedFee = policy.getFixedJobFeeChf();
|
||||||
|
BigDecimal subtotal = materialCost.add(machineCost).add(energyCost).add(fixedFee);
|
||||||
|
|
||||||
// Markup
|
// Markup
|
||||||
BigDecimal markupFactor = BigDecimal.valueOf(1.0 + (props.getMarkupPercent() / 100.0));
|
// Markup is percentage (e.g. 20.0)
|
||||||
|
BigDecimal markupFactor = BigDecimal.ONE.add(policy.getMarkupPercent().divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP));
|
||||||
BigDecimal totalPrice = subtotal.multiply(markupFactor).setScale(2, RoundingMode.HALF_UP);
|
BigDecimal totalPrice = subtotal.multiply(markupFactor).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
BigDecimal markupAmount = totalPrice.subtract(subtotal);
|
return new QuoteResult(totalPrice.doubleValue(), "CHF", stats, fixedFee.doubleValue());
|
||||||
|
}
|
||||||
|
|
||||||
CostBreakdown breakdown = new CostBreakdown(
|
private BigDecimal calculateMachineCost(PricingPolicy policy, BigDecimal hours) {
|
||||||
materialCost.setScale(2, RoundingMode.HALF_UP),
|
List<PricingPolicyMachineHourTier> tiers = tierRepo.findAllByPricingPolicyOrderByTierStartHoursAsc(policy);
|
||||||
machineCost.setScale(2, RoundingMode.HALF_UP),
|
if (tiers.isEmpty()) {
|
||||||
energyCost.setScale(2, RoundingMode.HALF_UP),
|
return BigDecimal.ZERO; // Should not happen if DB is correct
|
||||||
subtotal.setScale(2, RoundingMode.HALF_UP),
|
}
|
||||||
markupAmount.setScale(2, RoundingMode.HALF_UP)
|
|
||||||
);
|
BigDecimal remainingHours = hours;
|
||||||
|
BigDecimal totalCost = BigDecimal.ZERO;
|
||||||
|
BigDecimal processedHours = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
for (PricingPolicyMachineHourTier tier : tiers) {
|
||||||
|
if (remainingHours.compareTo(BigDecimal.ZERO) <= 0) break;
|
||||||
|
|
||||||
|
BigDecimal tierStart = tier.getTierStartHours();
|
||||||
|
BigDecimal tierEnd = tier.getTierEndHours(); // can be null for infinity
|
||||||
|
|
||||||
|
// Determine duration in this tier
|
||||||
|
// Valid duration in this tier = (min(tierEnd, totalHours) - tierStart)
|
||||||
|
// But logic is simpler: we consume hours sequentially?
|
||||||
|
// "0-10h @ 2CHF, 10-20h @ 1.5CHF" implies:
|
||||||
|
// 5h job -> 5 * 2
|
||||||
|
// 15h job -> 10 * 2 + 5 * 1.5
|
||||||
|
|
||||||
|
BigDecimal tierDuration;
|
||||||
|
|
||||||
|
// Max hours applicable in this tier relative to 0
|
||||||
|
BigDecimal tierLimit = (tierEnd != null) ? tierEnd : BigDecimal.valueOf(Long.MAX_VALUE);
|
||||||
|
|
||||||
|
// The amount of hours falling into this bucket
|
||||||
|
// Upper bound for this calculation is min(totalHours, tierLimit)
|
||||||
|
// Lower bound is tierStart
|
||||||
|
// So hours in this bucket = max(0, min(totalHours, tierLimit) - tierStart)
|
||||||
|
|
||||||
|
BigDecimal upper = hours.min(tierLimit);
|
||||||
|
BigDecimal lower = tierStart;
|
||||||
|
|
||||||
|
if (upper.compareTo(lower) > 0) {
|
||||||
|
BigDecimal hoursInTier = upper.subtract(lower);
|
||||||
|
totalCost = totalCost.add(hoursInTier.multiply(tier.getMachineCostChfPerHour()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<String> notes = new ArrayList<>();
|
return totalCost;
|
||||||
notes.add("Generated via Dynamic Slicer (Java Backend)");
|
}
|
||||||
|
|
||||||
return new QuoteResult(totalPrice, "EUR", stats, breakdown, notes);
|
private String detectMaterialCode(String profileName) {
|
||||||
|
String lower = profileName.toLowerCase();
|
||||||
|
if (lower.contains("petg")) return "PETG";
|
||||||
|
if (lower.contains("tpu")) return "TPU";
|
||||||
|
if (lower.contains("abs")) return "ABS";
|
||||||
|
if (lower.contains("nylon")) return "Nylon";
|
||||||
|
if (lower.contains("asa")) return "ASA";
|
||||||
|
// Default to PLA
|
||||||
|
return "PLA";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.printcalculator.service;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.QuoteSession;
|
||||||
|
import com.printcalculator.repository.QuoteSessionRepository;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SessionCleanupService {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SessionCleanupService.class);
|
||||||
|
private final QuoteSessionRepository sessionRepository;
|
||||||
|
|
||||||
|
public SessionCleanupService(QuoteSessionRepository sessionRepository) {
|
||||||
|
this.sessionRepository = sessionRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run every day at 3 AM
|
||||||
|
@Scheduled(cron = "0 0 3 * * ?")
|
||||||
|
@Transactional
|
||||||
|
public void cleanupOldSessions() {
|
||||||
|
logger.info("Starting session cleanup job...");
|
||||||
|
|
||||||
|
OffsetDateTime cutoff = OffsetDateTime.now().minusDays(15);
|
||||||
|
List<QuoteSession> oldSessions = sessionRepository.findByCreatedAtBefore(cutoff);
|
||||||
|
|
||||||
|
int deletedCount = 0;
|
||||||
|
for (QuoteSession session : oldSessions) {
|
||||||
|
// We only delete sessions that are NOT ordered?
|
||||||
|
// The user request was "delete old ones".
|
||||||
|
// Safest is to check status if we had one.
|
||||||
|
// QuoteSession entity has 'status' field.
|
||||||
|
// Let's assume we delete 'PENDING' or similar, but maybe we just delete all old inputs?
|
||||||
|
// "rimangono in memoria... cancella quelle vecchie di 7 giorni".
|
||||||
|
// Implementation plan said: status != 'ORDERED'.
|
||||||
|
|
||||||
|
// User specified statuses: ACTIVE, EXPIRED, CONVERTED.
|
||||||
|
// We should NOT delete sessions that have been converted to an order.
|
||||||
|
if ("CONVERTED".equals(session.getStatus())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Delete ACTIVE or EXPIRED sessions older than 7 days
|
||||||
|
deleteSessionFiles(session.getId().toString());
|
||||||
|
sessionRepository.delete(session);
|
||||||
|
deletedCount++;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Failed to cleanup session {}", session.getId(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Session cleanup job finished. Deleted {} sessions.", deletedCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteSessionFiles(String sessionId) {
|
||||||
|
Path sessionDir = Paths.get("storage_quotes", sessionId);
|
||||||
|
if (Files.exists(sessionDir)) {
|
||||||
|
try (Stream<Path> walk = Files.walk(sessionDir)) {
|
||||||
|
walk.sorted(java.util.Comparator.reverseOrder())
|
||||||
|
.map(Path::toFile)
|
||||||
|
.forEach(java.io.File::delete);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Failed to delete directory: {}", sessionDir, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,8 +12,11 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SlicerService {
|
public class SlicerService {
|
||||||
@@ -36,14 +39,17 @@ public class SlicerService {
|
|||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrintStats slice(File inputStl, String machineName, String filamentName, String processName) throws IOException {
|
public PrintStats slice(File inputStl, String machineName, String filamentName, String processName,
|
||||||
// 1. Prepare Profiles
|
Map<String, String> machineOverrides, Map<String, String> processOverrides) throws IOException {
|
||||||
ObjectNode machineProfile = profileManager.getMergedProfile(machineName, "machine");
|
ObjectNode machineProfile = profileManager.getMergedProfile(machineName, "machine");
|
||||||
ObjectNode filamentProfile = profileManager.getMergedProfile(filamentName, "filament");
|
ObjectNode filamentProfile = profileManager.getMergedProfile(filamentName, "filament");
|
||||||
ObjectNode processProfile = profileManager.getMergedProfile(processName, "process");
|
ObjectNode processProfile = profileManager.getMergedProfile(processName, "process");
|
||||||
|
|
||||||
// 2. Create Temp Dir
|
if (machineOverrides != null) machineOverrides.forEach(machineProfile::put);
|
||||||
|
if (processOverrides != null) processOverrides.forEach(processProfile::put);
|
||||||
|
|
||||||
Path tempDir = Files.createTempDirectory("slicer_job_");
|
Path tempDir = Files.createTempDirectory("slicer_job_");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File mFile = tempDir.resolve("machine.json").toFile();
|
File mFile = tempDir.resolve("machine.json").toFile();
|
||||||
File fFile = tempDir.resolve("filament.json").toFile();
|
File fFile = tempDir.resolve("filament.json").toFile();
|
||||||
@@ -53,80 +59,61 @@ public class SlicerService {
|
|||||||
mapper.writeValue(fFile, filamentProfile);
|
mapper.writeValue(fFile, filamentProfile);
|
||||||
mapper.writeValue(pFile, processProfile);
|
mapper.writeValue(pFile, processProfile);
|
||||||
|
|
||||||
// 3. Build Command
|
|
||||||
// --load-settings "machine.json;process.json" --load-filaments "filament.json"
|
|
||||||
String settingsArg = mFile.getAbsolutePath() + ";" + pFile.getAbsolutePath();
|
|
||||||
|
|
||||||
List<String> command = new ArrayList<>();
|
List<String> command = new ArrayList<>();
|
||||||
command.add(slicerPath);
|
command.add(slicerPath);
|
||||||
|
|
||||||
command.add("--load-settings");
|
command.add("--load-settings");
|
||||||
command.add(settingsArg);
|
command.add(mFile.getAbsolutePath());
|
||||||
|
command.add("--load-settings");
|
||||||
|
command.add(pFile.getAbsolutePath());
|
||||||
command.add("--load-filaments");
|
command.add("--load-filaments");
|
||||||
command.add(fFile.getAbsolutePath());
|
command.add(fFile.getAbsolutePath());
|
||||||
|
|
||||||
command.add("--ensure-on-bed");
|
command.add("--ensure-on-bed");
|
||||||
command.add("--arrange");
|
command.add("--arrange");
|
||||||
command.add("1"); // force arrange
|
command.add("1");
|
||||||
command.add("--slice");
|
|
||||||
command.add("0"); // slice plate 0
|
|
||||||
command.add("--outputdir");
|
command.add("--outputdir");
|
||||||
command.add(tempDir.toAbsolutePath().toString());
|
command.add(tempDir.toAbsolutePath().toString());
|
||||||
// Need to handle Mac structure for console if needed?
|
|
||||||
// Usually the binary at Contents/MacOS/OrcaSlicer works fine as console app.
|
|
||||||
|
|
||||||
|
command.add("--slice");
|
||||||
|
command.add("0");
|
||||||
|
|
||||||
command.add(inputStl.getAbsolutePath());
|
command.add(inputStl.getAbsolutePath());
|
||||||
|
|
||||||
logger.info("Executing Slicer: " + String.join(" ", command));
|
logger.info("Executing Slicer: " + String.join(" ", command));
|
||||||
|
|
||||||
// 4. Run Process
|
runSlicerCommand(command, tempDir);
|
||||||
ProcessBuilder pb = new ProcessBuilder(command);
|
|
||||||
pb.directory(tempDir.toFile());
|
|
||||||
// pb.inheritIO(); // Useful for debugging, but maybe capture instead?
|
|
||||||
|
|
||||||
Process process = pb.start();
|
|
||||||
boolean finished = process.waitFor(5, TimeUnit.MINUTES);
|
|
||||||
|
|
||||||
if (!finished) {
|
|
||||||
process.destroy();
|
|
||||||
throw new IOException("Slicer timed out");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.exitValue() != 0) {
|
|
||||||
// Read stderr
|
|
||||||
String error = new String(process.getErrorStream().readAllBytes());
|
|
||||||
throw new IOException("Slicer failed with exit code " + process.exitValue() + ": " + error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. Find Output GCode
|
try (Stream<Path> s = Files.list(tempDir)) {
|
||||||
// Usually [basename].gcode or plate_1.gcode
|
Optional<Path> found = s.filter(p -> p.toString().endsWith(".gcode")).findFirst();
|
||||||
String basename = inputStl.getName();
|
if (found.isPresent()) return gCodeParser.parse(found.get().toFile());
|
||||||
if (basename.toLowerCase().endsWith(".stl")) {
|
else throw new IOException("No GCode found in " + tempDir);
|
||||||
basename = basename.substring(0, basename.length() - 4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
File gcodeFile = tempDir.resolve(basename + ".gcode").toFile();
|
|
||||||
if (!gcodeFile.exists()) {
|
|
||||||
// Try plate_1.gcode fallback
|
|
||||||
File alt = tempDir.resolve("plate_1.gcode").toFile();
|
|
||||||
if (alt.exists()) {
|
|
||||||
gcodeFile = alt;
|
|
||||||
} else {
|
|
||||||
throw new IOException("GCode output not found in " + tempDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. Parse Results
|
|
||||||
return gCodeParser.parse(gcodeFile);
|
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
throw new IOException("Interrupted during slicing", e);
|
throw new IOException(e);
|
||||||
} finally {
|
}
|
||||||
// Cleanup temp dir
|
}
|
||||||
// In production we should delete, for debugging we might want to keep?
|
|
||||||
// Let's delete for now on success.
|
protected void runSlicerCommand(List<String> command, Path tempDir) throws IOException, InterruptedException {
|
||||||
// recursiveDelete(tempDir);
|
ProcessBuilder pb = new ProcessBuilder(command);
|
||||||
// Leaving it effectively "leaks" temp, but safer for persistent debugging?
|
pb.directory(tempDir.toFile());
|
||||||
// Implementation detail: Use a utility to clean up.
|
|
||||||
|
Map<String, String> env = pb.environment();
|
||||||
|
env.put("HOME", "/tmp");
|
||||||
|
env.put("QT_QPA_PLATFORM", "offscreen");
|
||||||
|
|
||||||
|
Process process = pb.start();
|
||||||
|
if (!process.waitFor(5, TimeUnit.MINUTES)) {
|
||||||
|
process.destroy();
|
||||||
|
throw new IOException("Slicer timeout");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.exitValue() != 0) {
|
||||||
|
String out = new String(process.getInputStream().readAllBytes());
|
||||||
|
String err = new String(process.getErrorStream().readAllBytes());
|
||||||
|
throw new IOException("Slicer failed with exit code " + process.exitValue() + "\nERR: " + err + "\nOUT: " + out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,255 @@
|
|||||||
|
package com.printcalculator.service;
|
||||||
|
|
||||||
|
import com.printcalculator.model.StlBounds;
|
||||||
|
import com.printcalculator.model.StlShiftResult;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class StlService {
|
||||||
|
|
||||||
|
public StlBounds readBounds(File stlFile) throws IOException {
|
||||||
|
long size = stlFile.length();
|
||||||
|
if (size >= 84 && isBinaryStl(stlFile, size)) {
|
||||||
|
return readBinaryBounds(stlFile);
|
||||||
|
}
|
||||||
|
return readAsciiBounds(stlFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StlShiftResult shiftToFitIfNeeded(File stlFile, StlBounds bounds,
|
||||||
|
int bedX, int bedY, int bedZ) throws IOException {
|
||||||
|
double sizeX = bounds.sizeX();
|
||||||
|
double sizeY = bounds.sizeY();
|
||||||
|
double sizeZ = bounds.sizeZ();
|
||||||
|
|
||||||
|
double targetMinX = (bedX - sizeX) / 2.0;
|
||||||
|
double targetMinY = (bedY - sizeY) / 2.0;
|
||||||
|
double targetMinZ = 0.0;
|
||||||
|
|
||||||
|
double offsetX = targetMinX - bounds.minX();
|
||||||
|
double offsetY = targetMinY - bounds.minY();
|
||||||
|
double offsetZ = targetMinZ - bounds.minZ();
|
||||||
|
|
||||||
|
boolean needsShift = Math.abs(offsetX) > 1e-6 || Math.abs(offsetY) > 1e-6 || Math.abs(offsetZ) > 1e-6;
|
||||||
|
if (!needsShift) {
|
||||||
|
return new StlShiftResult(null, offsetX, offsetY, offsetZ, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Path shiftedPath = Files.createTempFile("stl_shifted_", ".stl");
|
||||||
|
writeShifted(stlFile, shiftedPath.toFile(), offsetX, offsetY, offsetZ);
|
||||||
|
return new StlShiftResult(shiftedPath, offsetX, offsetY, offsetZ, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBinaryStl(File stlFile, long size) throws IOException {
|
||||||
|
try (RandomAccessFile raf = new RandomAccessFile(stlFile, "r")) {
|
||||||
|
raf.seek(80);
|
||||||
|
long triangleCount = readLEUInt32(raf);
|
||||||
|
long expected = 84L + triangleCount * 50L;
|
||||||
|
return expected == size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private StlBounds readBinaryBounds(File stlFile) throws IOException {
|
||||||
|
try (RandomAccessFile raf = new RandomAccessFile(stlFile, "r")) {
|
||||||
|
raf.seek(80);
|
||||||
|
long triangleCount = readLEUInt32(raf);
|
||||||
|
raf.seek(84);
|
||||||
|
|
||||||
|
BoundsAccumulator acc = new BoundsAccumulator();
|
||||||
|
for (long i = 0; i < triangleCount; i++) {
|
||||||
|
// skip normal
|
||||||
|
readLEFloat(raf);
|
||||||
|
readLEFloat(raf);
|
||||||
|
readLEFloat(raf);
|
||||||
|
// 3 vertices
|
||||||
|
acc.accept(readLEFloat(raf), readLEFloat(raf), readLEFloat(raf));
|
||||||
|
acc.accept(readLEFloat(raf), readLEFloat(raf), readLEFloat(raf));
|
||||||
|
acc.accept(readLEFloat(raf), readLEFloat(raf), readLEFloat(raf));
|
||||||
|
// skip attribute byte count
|
||||||
|
raf.skipBytes(2);
|
||||||
|
}
|
||||||
|
return acc.toBounds();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private StlBounds readAsciiBounds(File stlFile) throws IOException {
|
||||||
|
BoundsAccumulator acc = new BoundsAccumulator();
|
||||||
|
try (BufferedReader reader = Files.newBufferedReader(stlFile.toPath(), StandardCharsets.US_ASCII)) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
line = line.trim();
|
||||||
|
if (!line.startsWith("vertex")) continue;
|
||||||
|
String[] parts = line.split("\\s+");
|
||||||
|
if (parts.length < 4) continue;
|
||||||
|
double x = Double.parseDouble(parts[1]);
|
||||||
|
double y = Double.parseDouble(parts[2]);
|
||||||
|
double z = Double.parseDouble(parts[3]);
|
||||||
|
acc.accept(x, y, z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return acc.toBounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeShifted(File input, File output, double offsetX, double offsetY, double offsetZ) throws IOException {
|
||||||
|
long size = input.length();
|
||||||
|
if (size >= 84 && isBinaryStl(input, size)) {
|
||||||
|
writeShiftedBinary(input, output, offsetX, offsetY, offsetZ);
|
||||||
|
} else {
|
||||||
|
writeShiftedAscii(input, output, offsetX, offsetY, offsetZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeShiftedAscii(File input, File output, double offsetX, double offsetY, double offsetZ) throws IOException {
|
||||||
|
try (BufferedReader reader = Files.newBufferedReader(input.toPath(), StandardCharsets.US_ASCII);
|
||||||
|
BufferedWriter writer = Files.newBufferedWriter(output.toPath(), StandardCharsets.US_ASCII)) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
String trimmed = line.trim();
|
||||||
|
if (!trimmed.startsWith("vertex")) {
|
||||||
|
writer.write(line);
|
||||||
|
writer.newLine();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String[] parts = trimmed.split("\\s+");
|
||||||
|
if (parts.length < 4) {
|
||||||
|
writer.write(line);
|
||||||
|
writer.newLine();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
double x = Double.parseDouble(parts[1]) + offsetX;
|
||||||
|
double y = Double.parseDouble(parts[2]) + offsetY;
|
||||||
|
double z = Double.parseDouble(parts[3]) + offsetZ;
|
||||||
|
int idx = line.indexOf("vertex");
|
||||||
|
String indent = idx > 0 ? line.substring(0, idx) : "";
|
||||||
|
writer.write(indent + String.format(Locale.US, "vertex %.6f %.6f %.6f", x, y, z));
|
||||||
|
writer.newLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeShiftedBinary(File input, File output, double offsetX, double offsetY, double offsetZ) throws IOException {
|
||||||
|
try (RandomAccessFile raf = new RandomAccessFile(input, "r");
|
||||||
|
OutputStream out = new FileOutputStream(output)) {
|
||||||
|
byte[] header = new byte[80];
|
||||||
|
raf.readFully(header);
|
||||||
|
out.write(header);
|
||||||
|
|
||||||
|
long triangleCount = readLEUInt32(raf);
|
||||||
|
writeLEUInt32(out, triangleCount);
|
||||||
|
|
||||||
|
for (long i = 0; i < triangleCount; i++) {
|
||||||
|
// normal
|
||||||
|
writeLEFloat(out, readLEFloat(raf));
|
||||||
|
writeLEFloat(out, readLEFloat(raf));
|
||||||
|
writeLEFloat(out, readLEFloat(raf));
|
||||||
|
|
||||||
|
// vertices
|
||||||
|
writeLEFloat(out, (float) (readLEFloat(raf) + offsetX));
|
||||||
|
writeLEFloat(out, (float) (readLEFloat(raf) + offsetY));
|
||||||
|
writeLEFloat(out, (float) (readLEFloat(raf) + offsetZ));
|
||||||
|
|
||||||
|
writeLEFloat(out, (float) (readLEFloat(raf) + offsetX));
|
||||||
|
writeLEFloat(out, (float) (readLEFloat(raf) + offsetY));
|
||||||
|
writeLEFloat(out, (float) (readLEFloat(raf) + offsetZ));
|
||||||
|
|
||||||
|
writeLEFloat(out, (float) (readLEFloat(raf) + offsetX));
|
||||||
|
writeLEFloat(out, (float) (readLEFloat(raf) + offsetY));
|
||||||
|
writeLEFloat(out, (float) (readLEFloat(raf) + offsetZ));
|
||||||
|
|
||||||
|
// attribute byte count
|
||||||
|
int b1 = raf.read();
|
||||||
|
int b2 = raf.read();
|
||||||
|
if ((b1 | b2) < 0) throw new IOException("Unexpected EOF while reading STL");
|
||||||
|
out.write(b1);
|
||||||
|
out.write(b2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private long readLEUInt32(RandomAccessFile raf) throws IOException {
|
||||||
|
int b1 = raf.read();
|
||||||
|
int b2 = raf.read();
|
||||||
|
int b3 = raf.read();
|
||||||
|
int b4 = raf.read();
|
||||||
|
if ((b1 | b2 | b3 | b4) < 0) throw new IOException("Unexpected EOF while reading STL");
|
||||||
|
return ((long) b1 & 0xFF)
|
||||||
|
| (((long) b2 & 0xFF) << 8)
|
||||||
|
| (((long) b3 & 0xFF) << 16)
|
||||||
|
| (((long) b4 & 0xFF) << 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int readLEInt(RandomAccessFile raf) throws IOException {
|
||||||
|
int b1 = raf.read();
|
||||||
|
int b2 = raf.read();
|
||||||
|
int b3 = raf.read();
|
||||||
|
int b4 = raf.read();
|
||||||
|
if ((b1 | b2 | b3 | b4) < 0) throw new IOException("Unexpected EOF while reading STL");
|
||||||
|
return (b1 & 0xFF)
|
||||||
|
| ((b2 & 0xFF) << 8)
|
||||||
|
| ((b3 & 0xFF) << 16)
|
||||||
|
| ((b4 & 0xFF) << 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
private float readLEFloat(RandomAccessFile raf) throws IOException {
|
||||||
|
return Float.intBitsToFloat(readLEInt(raf));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeLEUInt32(OutputStream out, long value) throws IOException {
|
||||||
|
out.write((int) (value & 0xFF));
|
||||||
|
out.write((int) ((value >> 8) & 0xFF));
|
||||||
|
out.write((int) ((value >> 16) & 0xFF));
|
||||||
|
out.write((int) ((value >> 24) & 0xFF));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeLEFloat(OutputStream out, float value) throws IOException {
|
||||||
|
int bits = Float.floatToIntBits(value);
|
||||||
|
out.write(bits & 0xFF);
|
||||||
|
out.write((bits >> 8) & 0xFF);
|
||||||
|
out.write((bits >> 16) & 0xFF);
|
||||||
|
out.write((bits >> 24) & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class BoundsAccumulator {
|
||||||
|
private boolean hasPoint = false;
|
||||||
|
private double minX;
|
||||||
|
private double minY;
|
||||||
|
private double minZ;
|
||||||
|
private double maxX;
|
||||||
|
private double maxY;
|
||||||
|
private double maxZ;
|
||||||
|
|
||||||
|
void accept(double x, double y, double z) {
|
||||||
|
if (!hasPoint) {
|
||||||
|
minX = maxX = x;
|
||||||
|
minY = maxY = y;
|
||||||
|
minZ = maxZ = z;
|
||||||
|
hasPoint = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (x < minX) minX = x;
|
||||||
|
if (y < minY) minY = y;
|
||||||
|
if (z < minZ) minZ = z;
|
||||||
|
if (x > maxX) maxX = x;
|
||||||
|
if (y > maxY) maxY = y;
|
||||||
|
if (z > maxZ) maxZ = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
StlBounds toBounds() throws IOException {
|
||||||
|
if (!hasPoint) {
|
||||||
|
throw new IOException("STL appears to contain no vertices");
|
||||||
|
}
|
||||||
|
return new StlBounds(minX, minY, minZ, maxX, maxY, maxZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.printcalculator.service;
|
||||||
|
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public interface StorageService {
|
||||||
|
void init();
|
||||||
|
void store(MultipartFile file, Path destination) throws IOException;
|
||||||
|
void store(Path source, Path destination) throws IOException;
|
||||||
|
void delete(Path path) throws IOException;
|
||||||
|
Resource loadAsResource(Path path) throws IOException;
|
||||||
|
}
|
||||||
@@ -1,19 +1,26 @@
|
|||||||
spring.application.name=backend
|
spring.application.name=backend
|
||||||
server.port=8000
|
server.port=8000
|
||||||
|
|
||||||
|
# Database Configuration
|
||||||
|
spring.datasource.url=${DB_URL:jdbc:postgresql://localhost:5432/printcalc}
|
||||||
|
spring.datasource.username=${DB_USERNAME:printcalc}
|
||||||
|
spring.datasource.password=${DB_PASSWORD:printcalc_secret}
|
||||||
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
|
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||||
|
|
||||||
|
|
||||||
# Slicer Configuration
|
# Slicer Configuration
|
||||||
# Map SLICER_PATH env var if present (default to /opt/orcaslicer/AppRun or Mac path)
|
# Map SLICER_PATH env var if present (default to /opt/orcaslicer/AppRun or Mac path)
|
||||||
slicer.path=${SLICER_PATH:/Applications/OrcaSlicer.app/Contents/MacOS/OrcaSlicer}
|
slicer.path=${SLICER_PATH:/Applications/OrcaSlicer.app/Contents/MacOS/OrcaSlicer}
|
||||||
profiles.root=${PROFILES_DIR:profiles}
|
profiles.root=${PROFILES_DIR:profiles}
|
||||||
|
|
||||||
# Pricing Configuration
|
|
||||||
# Mapped to legacy environment variables for Docker compatibility
|
|
||||||
pricing.filament-cost-per-kg=${FILAMENT_COST_PER_KG:25.0}
|
|
||||||
pricing.machine-cost-per-hour=${MACHINE_COST_PER_HOUR:2.0}
|
|
||||||
pricing.energy-cost-per-kwh=${ENERGY_COST_PER_KWH:0.30}
|
|
||||||
pricing.printer-power-watts=${PRINTER_POWER_WATTS:150.0}
|
|
||||||
pricing.markup-percent=${MARKUP_PERCENT:20.0}
|
|
||||||
|
|
||||||
# File Upload Limits
|
# File Upload Limits
|
||||||
spring.servlet.multipart.max-file-size=200MB
|
spring.servlet.multipart.max-file-size=200MB
|
||||||
spring.servlet.multipart.max-request-size=200MB
|
spring.servlet.multipart.max-request-size=200MB
|
||||||
|
|
||||||
|
# ClamAV Configuration
|
||||||
|
clamav.host=${CLAMAV_HOST:clamav}
|
||||||
|
clamav.port=${CLAMAV_PORT:3310}
|
||||||
|
clamav.enabled=${CLAMAV_ENABLED:false}
|
||||||
|
|
||||||
|
|||||||
84
backend/src/main/resources/templates/invoice.html
Normal file
84
backend/src/main/resources/templates/invoice.html
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="it" xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<style>
|
||||||
|
@page { size: A4; margin: 18mm 15mm; }
|
||||||
|
body { font-family: sans-serif; font-size: 10.5pt; }
|
||||||
|
.header { display: flex; justify-content: space-between; }
|
||||||
|
.addresses { margin-top: 10mm; display: flex; justify-content: space-between; }
|
||||||
|
table { width: 100%; border-collapse: collapse; margin-top: 8mm; }
|
||||||
|
th, td { padding: 6px; border-bottom: 1px solid #ccc; }
|
||||||
|
th { text-align: left; }
|
||||||
|
.totals { margin-top: 6mm; width: 40%; margin-left: auto; }
|
||||||
|
.totals td { border: none; }
|
||||||
|
.page-break { page-break-before: always; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="header">
|
||||||
|
<div>
|
||||||
|
<div><strong th:text="${sellerDisplayName}">Nome Cognome</strong></div>
|
||||||
|
<div th:text="${sellerAddressLine1}">Via Esempio 12</div>
|
||||||
|
<div th:text="${sellerAddressLine2}">6500 Bellinzona, CH</div>
|
||||||
|
<div th:text="${sellerEmail}">email@example.com</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div><strong>Fattura</strong></div>
|
||||||
|
<div>Numero: <span th:text="${invoiceNumber}">2026-000123</span></div>
|
||||||
|
<div>Data: <span th:text="${invoiceDate}">2026-02-13</span></div>
|
||||||
|
<div>Scadenza: <span th:text="${dueDate}">2026-02-20</span></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="addresses">
|
||||||
|
<div>
|
||||||
|
<div><strong>Fatturare a</strong></div>
|
||||||
|
<div th:text="${buyerDisplayName}">Cliente SA</div>
|
||||||
|
<div th:text="${buyerAddressLine1}">Via Cliente 7</div>
|
||||||
|
<div th:text="${buyerAddressLine2}">8000 Zürich, CH</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Descrizione</th>
|
||||||
|
<th style="text-align:right;">Qtà</th>
|
||||||
|
<th style="text-align:right;">Prezzo</th>
|
||||||
|
<th style="text-align:right;">Totale</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr th:each="lineItem : ${invoiceLineItems}">
|
||||||
|
<td th:text="${lineItem.description}">Stampa 3D pezzo X</td>
|
||||||
|
<td style="text-align:right;" th:text="${lineItem.quantity}">1</td>
|
||||||
|
<td style="text-align:right;" th:text="${lineItem.unitPriceFormatted}">CHF 10.00</td>
|
||||||
|
<td style="text-align:right;" th:text="${lineItem.lineTotalFormatted}">CHF 10.00</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<table class="totals">
|
||||||
|
<tr>
|
||||||
|
<td>Subtotale</td>
|
||||||
|
<td style="text-align:right;" th:text="${subtotalFormatted}">CHF 10.00</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Totale</strong></td>
|
||||||
|
<td style="text-align:right;"><strong th:text="${grandTotalFormatted}">CHF 10.00</strong></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div style="margin-top:6mm;" th:text="${paymentTermsText}">
|
||||||
|
Pagamento entro 7 giorni. Grazie.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="page-break-before: always;"></div>
|
||||||
|
<div style="position: absolute; bottom: 0; left: 0; width: 210mm; height: 105mm;" th:utext="${qrBillSvg}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
package com.printcalculator;
|
||||||
|
|
||||||
|
import com.printcalculator.controller.QuoteSessionController;
|
||||||
|
import com.printcalculator.dto.PrintSettingsDto;
|
||||||
|
import com.printcalculator.entity.QuoteSession;
|
||||||
|
import com.printcalculator.entity.QuoteLineItem;
|
||||||
|
import com.printcalculator.repository.QuoteSessionRepository;
|
||||||
|
import com.printcalculator.repository.QuoteLineItemRepository;
|
||||||
|
import com.printcalculator.repository.PrinterMachineRepository;
|
||||||
|
import com.printcalculator.service.SlicerService;
|
||||||
|
import com.printcalculator.service.QuoteCalculator;
|
||||||
|
import com.printcalculator.service.StorageService;
|
||||||
|
import com.printcalculator.service.StlService;
|
||||||
|
import com.printcalculator.service.ProfileManager;
|
||||||
|
import com.printcalculator.model.PrintStats;
|
||||||
|
import com.printcalculator.model.QuoteResult;
|
||||||
|
import com.printcalculator.entity.PrinterMachine;
|
||||||
|
import com.printcalculator.model.StlBounds;
|
||||||
|
import com.printcalculator.model.StlShiftResult;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||||
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
|
||||||
|
@WebMvcTest(QuoteSessionController.class)
|
||||||
|
public class ManualSessionPersistenceTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private QuoteSessionController controller;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private QuoteSessionRepository sessionRepo;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private QuoteLineItemRepository lineItemRepo; // Mock this too
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private SlicerService slicerService;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private StorageService storageService;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private StlService stlService;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private ProfileManager profileManager;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private QuoteCalculator quoteCalculator;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private PrinterMachineRepository machineRepo;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private com.printcalculator.repository.PricingPolicyRepository pricingRepo; // Add this if needed by controller
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSettingsPersistence() throws Exception {
|
||||||
|
// Prepare
|
||||||
|
UUID sessionId = UUID.randomUUID();
|
||||||
|
QuoteSession session = new QuoteSession();
|
||||||
|
session.setId(sessionId);
|
||||||
|
session.setMaterialCode("pla_basic"); // Initial state
|
||||||
|
|
||||||
|
when(sessionRepo.findById(sessionId)).thenReturn(Optional.of(session));
|
||||||
|
when(sessionRepo.save(any(QuoteSession.class))).thenAnswer(i -> i.getArguments()[0]);
|
||||||
|
when(lineItemRepo.save(any(QuoteLineItem.class))).thenAnswer(i -> i.getArguments()[0]);
|
||||||
|
|
||||||
|
// 2. Add Item with Custom Settings
|
||||||
|
PrintSettingsDto settings = new PrintSettingsDto();
|
||||||
|
settings.setComplexityMode("ADVANCED");
|
||||||
|
settings.setMaterial("petg_basic");
|
||||||
|
settings.setLayerHeight(0.12);
|
||||||
|
settings.setInfillDensity(50.0);
|
||||||
|
settings.setInfillPattern("gyroid");
|
||||||
|
settings.setSupportsEnabled(true);
|
||||||
|
settings.setNozzleDiameter(0.6);
|
||||||
|
settings.setNotes("Test Notes");
|
||||||
|
|
||||||
|
MockMultipartFile file = new MockMultipartFile("file", "test.stl", "application/octet-stream", "dummy content".getBytes());
|
||||||
|
|
||||||
|
// Mock dependencies
|
||||||
|
when(machineRepo.findFirstByIsActiveTrue()).thenReturn(Optional.of(new PrinterMachine(){{
|
||||||
|
setPrinterDisplayName("TestPrinter");
|
||||||
|
setSlicerMachineProfile("TestProfile");
|
||||||
|
setBuildVolumeXMm(256);
|
||||||
|
setBuildVolumeYMm(256);
|
||||||
|
setBuildVolumeZMm(256);
|
||||||
|
}}));
|
||||||
|
when(slicerService.slice(any(), any(), any(), any(), any(), any())).thenReturn(new PrintStats(100, "1m", 10.0, 100));
|
||||||
|
when(quoteCalculator.calculate(any(), any(), any())).thenReturn(
|
||||||
|
new QuoteResult(10.0, "CHF", new PrintStats(100, "1m", 10.0, 100), 0.0)
|
||||||
|
);
|
||||||
|
when(stlService.readBounds(any())).thenReturn(new StlBounds(0, 0, 0, 10, 10, 10));
|
||||||
|
when(stlService.shiftToFitIfNeeded(any(), any(), anyInt(), anyInt(), anyInt()))
|
||||||
|
.thenReturn(new StlShiftResult(null, 0, 0, 0, false));
|
||||||
|
when(profileManager.resolveMachineProfileName(any(), any())).thenAnswer(i -> i.getArguments()[0]);
|
||||||
|
when(storageService.loadAsResource(any())).thenReturn(new org.springframework.core.io.ByteArrayResource("dummy".getBytes()){
|
||||||
|
@Override
|
||||||
|
public File getFile() { return new File("dummy"); }
|
||||||
|
});
|
||||||
|
|
||||||
|
controller.addItemToExistingSession(sessionId, settings, file);
|
||||||
|
|
||||||
|
// 3. Verify Session Updated via Save Call capture
|
||||||
|
ArgumentCaptor<QuoteSession> captor = ArgumentCaptor.forClass(QuoteSession.class);
|
||||||
|
verify(sessionRepo).save(captor.capture());
|
||||||
|
|
||||||
|
QuoteSession updatedSession = captor.getValue();
|
||||||
|
|
||||||
|
assertEquals("petg_basic", updatedSession.getMaterialCode());
|
||||||
|
assertEquals(0, BigDecimal.valueOf(0.12).compareTo(updatedSession.getLayerHeightMm()));
|
||||||
|
assertEquals(50, updatedSession.getInfillPercent());
|
||||||
|
assertEquals("gyroid", updatedSession.getInfillPattern());
|
||||||
|
assertTrue(updatedSession.getSupportsEnabled());
|
||||||
|
assertEquals(0, BigDecimal.valueOf(0.6).compareTo(updatedSession.getNozzleDiameterMm()));
|
||||||
|
assertEquals("Test Notes", updatedSession.getNotes());
|
||||||
|
|
||||||
|
System.out.println("Verification Passed: Settings were persisted to Session.");
|
||||||
|
}
|
||||||
|
@org.springframework.boot.test.context.TestConfiguration
|
||||||
|
static class TestConfig {
|
||||||
|
@org.springframework.context.annotation.Bean
|
||||||
|
public org.springframework.transaction.PlatformTransactionManager transactionManager() {
|
||||||
|
return org.mockito.Mockito.mock(org.springframework.transaction.PlatformTransactionManager.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.printcalculator.config;
|
||||||
|
|
||||||
|
import com.printcalculator.service.ClamAVService;
|
||||||
|
import org.springframework.boot.test.context.TestConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
@TestConfiguration
|
||||||
|
public class TestConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public ClamAVService mockClamAVService() {
|
||||||
|
return new ClamAVService("localhost", 3310, true) {
|
||||||
|
@Override
|
||||||
|
public boolean scan(InputStream inputStream) {
|
||||||
|
return true; // Always clean for tests
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
package com.printcalculator.controller;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.printcalculator.dto.CreateOrderRequest;
|
||||||
|
import com.printcalculator.dto.CustomerDto;
|
||||||
|
import com.printcalculator.dto.AddressDto;
|
||||||
|
import com.printcalculator.entity.QuoteLineItem;
|
||||||
|
import com.printcalculator.entity.QuoteSession;
|
||||||
|
import com.printcalculator.repository.OrderRepository;
|
||||||
|
import com.printcalculator.repository.QuoteLineItemRepository;
|
||||||
|
import com.printcalculator.repository.QuoteSessionRepository;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.util.FileSystemUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||||
|
import com.printcalculator.service.ClamAVService;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@AutoConfigureMockMvc
|
||||||
|
@org.springframework.test.context.TestPropertySource(properties = {
|
||||||
|
"spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=PostgreSQL",
|
||||||
|
"spring.datasource.driverClassName=org.h2.Driver",
|
||||||
|
"spring.datasource.username=sa",
|
||||||
|
"spring.datasource.password=",
|
||||||
|
"spring.jpa.database-platform=org.hibernate.dialect.H2Dialect",
|
||||||
|
"spring.jpa.hibernate.ddl-auto=create-drop"
|
||||||
|
})
|
||||||
|
class OrderIntegrationTest {
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private ClamAVService clamAVService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private QuoteSessionRepository sessionRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private QuoteLineItemRepository lineItemRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OrderRepository orderRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
private UUID sessionId;
|
||||||
|
private UUID lineItemId;
|
||||||
|
private final String TEST_FILENAME = "test_model.stl";
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setup() throws Exception {
|
||||||
|
// Mock ClamAV to always return true (safe)
|
||||||
|
when(clamAVService.scan(any())).thenReturn(true);
|
||||||
|
|
||||||
|
// 1. Create Quote Session
|
||||||
|
QuoteSession session = new QuoteSession();
|
||||||
|
session.setStatus("ACTIVE");
|
||||||
|
session.setMaterialCode("PLA");
|
||||||
|
session.setPricingVersion("v1");
|
||||||
|
session.setCreatedAt(OffsetDateTime.now());
|
||||||
|
session.setExpiresAt(OffsetDateTime.now().plusDays(7));
|
||||||
|
session.setSetupCostChf(BigDecimal.valueOf(5.00));
|
||||||
|
session.setSupportsEnabled(false);
|
||||||
|
session = sessionRepository.save(session);
|
||||||
|
this.sessionId = session.getId();
|
||||||
|
|
||||||
|
// 2. Create Dummy File on Disk (storage_quotes)
|
||||||
|
Path sessionDir = Paths.get("storage_quotes", sessionId.toString());
|
||||||
|
Files.createDirectories(sessionDir);
|
||||||
|
Path filePath = sessionDir.resolve(UUID.randomUUID() + ".stl");
|
||||||
|
Files.writeString(filePath, "dummy content");
|
||||||
|
|
||||||
|
// 3. Create Quote Line Item
|
||||||
|
QuoteLineItem item = new QuoteLineItem();
|
||||||
|
item.setQuoteSession(session);
|
||||||
|
item.setStatus("READY");
|
||||||
|
item.setOriginalFilename(TEST_FILENAME);
|
||||||
|
item.setStoredPath(filePath.toString());
|
||||||
|
item.setQuantity(2);
|
||||||
|
item.setPrintTimeSeconds(120);
|
||||||
|
item.setMaterialGrams(BigDecimal.valueOf(10.5));
|
||||||
|
item.setUnitPriceChf(BigDecimal.valueOf(10.00));
|
||||||
|
item.setCreatedAt(OffsetDateTime.now());
|
||||||
|
item.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
item = lineItemRepository.save(item);
|
||||||
|
this.lineItemId = item.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void cleanup() throws Exception {
|
||||||
|
// Cleanup generated files
|
||||||
|
FileSystemUtils.deleteRecursively(Paths.get("storage_quotes"));
|
||||||
|
FileSystemUtils.deleteRecursively(Paths.get("storage_orders"));
|
||||||
|
|
||||||
|
// Clean DB
|
||||||
|
orderRepository.deleteAll();
|
||||||
|
lineItemRepository.deleteAll();
|
||||||
|
sessionRepository.deleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testCreateOrderFromQuote_ShouldCopyFilesAndUpdateStatus() throws Exception {
|
||||||
|
// Prepare Request
|
||||||
|
CreateOrderRequest request = new CreateOrderRequest();
|
||||||
|
|
||||||
|
CustomerDto customer = new CustomerDto();
|
||||||
|
customer.setEmail("integration@test.com");
|
||||||
|
customer.setCustomerType("PRIVATE");
|
||||||
|
request.setCustomer(customer);
|
||||||
|
|
||||||
|
AddressDto billing = new AddressDto();
|
||||||
|
billing.setFirstName("John");
|
||||||
|
billing.setLastName("Doe");
|
||||||
|
billing.setAddressLine1("Street 1");
|
||||||
|
billing.setCity("City");
|
||||||
|
billing.setZip("1000");
|
||||||
|
billing.setCountryCode("CH");
|
||||||
|
request.setBillingAddress(billing);
|
||||||
|
|
||||||
|
request.setShippingSameAsBilling(true);
|
||||||
|
|
||||||
|
// Execute Request
|
||||||
|
mockMvc.perform(post("/api/orders/from-quote/" + sessionId)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content(objectMapper.writeValueAsString(request)))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
|
||||||
|
// Verify Session Status
|
||||||
|
QuoteSession updatedSession = sessionRepository.findById(sessionId).orElseThrow();
|
||||||
|
assertEquals("CONVERTED", updatedSession.getStatus(), "Session status should be CONVERTED");
|
||||||
|
assertNotNull(updatedSession.getConvertedOrderId(), "Converted Order ID should be set");
|
||||||
|
|
||||||
|
UUID orderId = updatedSession.getConvertedOrderId();
|
||||||
|
|
||||||
|
// Verify File Copy
|
||||||
|
Path orderStorageDir = Paths.get("storage_orders");
|
||||||
|
// We need to find the specific file. Structure: storage_orders/orderId/3d-files/orderItemId/filename
|
||||||
|
// Since we don't know OrderItemId easily without querying DB, let's walk the dir.
|
||||||
|
|
||||||
|
try (var stream = Files.walk(orderStorageDir)) {
|
||||||
|
boolean fileFound = stream
|
||||||
|
.filter(Files::isRegularFile)
|
||||||
|
.anyMatch(path -> {
|
||||||
|
try {
|
||||||
|
return Files.readString(path).equals("dummy content");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assertTrue(fileFound, "The file should have been copied to storage_orders with correct content");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,10 +27,10 @@ class GCodeParserTest {
|
|||||||
PrintStats stats = parser.parse(tempFile);
|
PrintStats stats = parser.parse(tempFile);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assertEquals(3723, stats.printTimeSeconds()); // 3600 + 120 + 3
|
assertEquals(3723L, stats.getPrintTimeSeconds()); // 3600 + 120 + 3
|
||||||
assertEquals("1h 2m 3s", stats.printTimeFormatted());
|
assertEquals("1h 2m 3s", stats.getPrintTimeFormatted());
|
||||||
assertEquals(10.5, stats.filamentWeightGrams(), 0.001);
|
assertEquals(10.5, stats.getFilamentWeightGrams(), 0.001);
|
||||||
assertEquals(3000.0, stats.filamentLengthMm(), 0.001);
|
assertEquals(3000.0, stats.getFilamentLengthMm(), 0.001);
|
||||||
|
|
||||||
tempFile.delete();
|
tempFile.delete();
|
||||||
}
|
}
|
||||||
@@ -49,8 +49,64 @@ class GCodeParserTest {
|
|||||||
GCodeParser parser = new GCodeParser();
|
GCodeParser parser = new GCodeParser();
|
||||||
PrintStats stats = parser.parse(tempFile);
|
PrintStats stats = parser.parse(tempFile);
|
||||||
|
|
||||||
assertEquals(750, stats.printTimeSeconds()); // 12*60 + 30
|
assertEquals(750L, stats.getPrintTimeSeconds()); // 12*60 + 30
|
||||||
assertEquals(5.0, stats.filamentWeightGrams(), 0.001);
|
assertEquals(5.0, stats.getFilamentWeightGrams(), 0.001);
|
||||||
|
|
||||||
|
tempFile.delete();
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void parse_withExtraTextInTimeLine_returnsCorrectStats() throws IOException {
|
||||||
|
// Arrange
|
||||||
|
File tempFile = File.createTempFile("test_extra", ".gcode");
|
||||||
|
try (FileWriter writer = new FileWriter(tempFile)) {
|
||||||
|
writer.write("; generated by OrcaSlicer\n");
|
||||||
|
// Simulate the variation that was causing issues
|
||||||
|
writer.write("; estimated printing time (normal mode) = 1h 2m 3s\n");
|
||||||
|
writer.write("; filament used [g] = 10.5\n");
|
||||||
|
writer.write("; filament used [mm] = 3000.0\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
GCodeParser parser = new GCodeParser();
|
||||||
|
PrintStats stats = parser.parse(tempFile);
|
||||||
|
|
||||||
|
assertEquals(3723L, stats.getPrintTimeSeconds());
|
||||||
|
assertEquals("1h 2m 3s", stats.getPrintTimeFormatted());
|
||||||
|
|
||||||
|
tempFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void parse_colonFormattedTime_returnsCorrectStats() throws IOException {
|
||||||
|
File tempFile = File.createTempFile("test_colon", ".gcode");
|
||||||
|
try (FileWriter writer = new FileWriter(tempFile)) {
|
||||||
|
writer.write("; generated by OrcaSlicer\n");
|
||||||
|
writer.write("; print time: 01:02:03\n");
|
||||||
|
writer.write("; filament used [g] = 7.5\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
GCodeParser parser = new GCodeParser();
|
||||||
|
PrintStats stats = parser.parse(tempFile);
|
||||||
|
|
||||||
|
assertEquals(3723L, stats.getPrintTimeSeconds());
|
||||||
|
assertEquals("01:02:03", stats.getPrintTimeFormatted());
|
||||||
|
|
||||||
|
tempFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void parse_totalEstimatedTimeInline_returnsCorrectStats() throws IOException {
|
||||||
|
File tempFile = File.createTempFile("test_total", ".gcode");
|
||||||
|
try (FileWriter writer = new FileWriter(tempFile)) {
|
||||||
|
writer.write("; generated by OrcaSlicer\n");
|
||||||
|
writer.write("; model printing time: 5m 17s; total estimated time: 5m 21s\n");
|
||||||
|
writer.write("; filament used [g] = 2.0\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
GCodeParser parser = new GCodeParser();
|
||||||
|
PrintStats stats = parser.parse(tempFile);
|
||||||
|
|
||||||
|
assertEquals(321L, stats.getPrintTimeSeconds());
|
||||||
|
assertEquals("5m 21s", stats.getPrintTimeFormatted());
|
||||||
|
|
||||||
tempFile.delete();
|
tempFile.delete();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package com.printcalculator.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.printcalculator.model.PrintStats;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
|
||||||
|
class SlicerServiceTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ProfileManager profileManager;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private GCodeParser gCodeParser;
|
||||||
|
|
||||||
|
private ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
private SlicerService slicerService;
|
||||||
|
|
||||||
|
@TempDir
|
||||||
|
Path tempDir;
|
||||||
|
|
||||||
|
// Captured execution details
|
||||||
|
private List<String> lastCommand;
|
||||||
|
private Path lastTempDir;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() throws IOException {
|
||||||
|
MockitoAnnotations.openMocks(this);
|
||||||
|
|
||||||
|
// Subclass to override runSlicerCommand
|
||||||
|
slicerService = new SlicerService("orca-slicer", profileManager, gCodeParser, mapper) {
|
||||||
|
@Override
|
||||||
|
protected void runSlicerCommand(List<String> command, Path tempDir) throws IOException, InterruptedException {
|
||||||
|
lastCommand = command;
|
||||||
|
lastTempDir = tempDir;
|
||||||
|
// Don't run actual process.
|
||||||
|
// Simulate GCode output creation for the parser to find?
|
||||||
|
// Or just let it fail at parser step since we only care about JSON generation here?
|
||||||
|
// For a full test, we should create a dummy GCode file.
|
||||||
|
|
||||||
|
File stl = new File(command.get(command.size() - 1));
|
||||||
|
String basename = stl.getName().replace(".stl", "");
|
||||||
|
Files.createFile(tempDir.resolve(basename + ".gcode"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mock Profile Responses
|
||||||
|
ObjectNode emptyNode = mapper.createObjectNode();
|
||||||
|
when(profileManager.getMergedProfile(anyString(), eq("machine"))).thenReturn(emptyNode.deepCopy());
|
||||||
|
when(profileManager.getMergedProfile(anyString(), eq("filament"))).thenReturn(emptyNode.deepCopy());
|
||||||
|
when(profileManager.getMergedProfile(anyString(), eq("process"))).thenReturn(emptyNode.deepCopy());
|
||||||
|
|
||||||
|
// Mock Parser
|
||||||
|
when(gCodeParser.parse(any(File.class))).thenReturn(new PrintStats(100, "1m 40s", 10.5, 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSlice_WithDefaults_ShouldGenerateConfig() throws IOException {
|
||||||
|
File dummyStl = tempDir.resolve("test.stl").toFile();
|
||||||
|
Files.createFile(dummyStl.toPath());
|
||||||
|
|
||||||
|
slicerService.slice(dummyStl, "Bambu A1", "PLA", "Standard", null, null);
|
||||||
|
|
||||||
|
assertNotNull(lastTempDir);
|
||||||
|
assertTrue(Files.exists(lastTempDir.resolve("process.json")));
|
||||||
|
assertTrue(Files.exists(lastTempDir.resolve("machine.json")));
|
||||||
|
assertTrue(Files.exists(lastTempDir.resolve("filament.json")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSlice_WithLayerHeightOverride_ShouldUpdateProcessJson() throws IOException {
|
||||||
|
File dummyStl = tempDir.resolve("test.stl").toFile();
|
||||||
|
Files.createFile(dummyStl.toPath());
|
||||||
|
|
||||||
|
Map<String, String> processOverrides = new HashMap<>();
|
||||||
|
processOverrides.put("layer_height", "0.12");
|
||||||
|
|
||||||
|
slicerService.slice(dummyStl, "Bambu A1", "PLA", "Standard", null, processOverrides);
|
||||||
|
|
||||||
|
File processJsonFile = lastTempDir.resolve("process.json").toFile();
|
||||||
|
ObjectNode processJson = (ObjectNode) mapper.readTree(processJsonFile);
|
||||||
|
|
||||||
|
assertTrue(processJson.has("layer_height"));
|
||||||
|
assertEquals("0.12", processJson.get("layer_height").asText());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSlice_WithInfillAndSupportOverrides_ShouldUpdateProcessJson() throws IOException {
|
||||||
|
File dummyStl = tempDir.resolve("test.stl").toFile();
|
||||||
|
Files.createFile(dummyStl.toPath());
|
||||||
|
|
||||||
|
Map<String, String> processOverrides = new HashMap<>();
|
||||||
|
processOverrides.put("sparse_infill_density", "25%");
|
||||||
|
processOverrides.put("enable_support", "1");
|
||||||
|
|
||||||
|
slicerService.slice(dummyStl, "Bambu A1", "PLA", "Standard", null, processOverrides);
|
||||||
|
|
||||||
|
File processJsonFile = lastTempDir.resolve("process.json").toFile();
|
||||||
|
ObjectNode processJson = (ObjectNode) mapper.readTree(processJsonFile);
|
||||||
|
|
||||||
|
assertEquals("25%", processJson.get("sparse_infill_density").asText());
|
||||||
|
assertEquals("1", processJson.get("enable_support").asText());
|
||||||
|
}
|
||||||
|
}
|
||||||
627
db.sql
Normal file
627
db.sql
Normal file
@@ -0,0 +1,627 @@
|
|||||||
|
create table printer_machine
|
||||||
|
(
|
||||||
|
printer_machine_id bigserial primary key,
|
||||||
|
printer_display_name text not null unique,
|
||||||
|
|
||||||
|
build_volume_x_mm integer not null check (build_volume_x_mm > 0),
|
||||||
|
build_volume_y_mm integer not null check (build_volume_y_mm > 0),
|
||||||
|
build_volume_z_mm integer not null check (build_volume_z_mm > 0),
|
||||||
|
|
||||||
|
power_watts integer not null check (power_watts > 0),
|
||||||
|
|
||||||
|
fleet_weight numeric(6, 3) not null default 1.000,
|
||||||
|
|
||||||
|
is_active boolean not null default true,
|
||||||
|
slicer_machine_profile varchar(255),
|
||||||
|
created_at timestamptz not null default now()
|
||||||
|
);
|
||||||
|
|
||||||
|
create view printer_fleet_current as
|
||||||
|
select case
|
||||||
|
when sum(fleet_weight) = 0 then null
|
||||||
|
else round(sum(power_watts * fleet_weight) / sum(fleet_weight))::integer
|
||||||
|
end as weighted_average_power_watts,
|
||||||
|
max(build_volume_x_mm) as fleet_max_build_x_mm,
|
||||||
|
max(build_volume_y_mm) as fleet_max_build_y_mm,
|
||||||
|
max(build_volume_z_mm) as fleet_max_build_z_mm
|
||||||
|
from printer_machine
|
||||||
|
where is_active = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
create table filament_material_type
|
||||||
|
(
|
||||||
|
filament_material_type_id bigserial primary key,
|
||||||
|
material_code text not null unique, -- PLA, PETG, TPU, ASA...
|
||||||
|
is_flexible boolean not null default false, -- sì/no
|
||||||
|
is_technical boolean not null default false, -- sì/no
|
||||||
|
technical_type_label text -- es: "alta temperatura", "rinforzato", ecc.
|
||||||
|
);
|
||||||
|
|
||||||
|
create table filament_variant
|
||||||
|
(
|
||||||
|
filament_variant_id bigserial primary key,
|
||||||
|
filament_material_type_id bigint not null references filament_material_type (filament_material_type_id),
|
||||||
|
|
||||||
|
variant_display_name text not null, -- es: "PLA Nero Opaco BrandX"
|
||||||
|
color_name text not null, -- Nero, Bianco, ecc.
|
||||||
|
is_matte boolean not null default false,
|
||||||
|
is_special boolean not null default false,
|
||||||
|
|
||||||
|
cost_chf_per_kg numeric(10, 2) not null,
|
||||||
|
|
||||||
|
-- Stock espresso in rotoli anche frazionati
|
||||||
|
stock_spools numeric(6, 3) not null default 0.000,
|
||||||
|
spool_net_kg numeric(6, 3) not null default 1.000,
|
||||||
|
|
||||||
|
is_active boolean not null default true,
|
||||||
|
created_at timestamptz not null default now(),
|
||||||
|
|
||||||
|
unique (filament_material_type_id, variant_display_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- (opzionale) kg disponibili calcolati
|
||||||
|
create view filament_variant_stock_kg as
|
||||||
|
select filament_variant_id,
|
||||||
|
stock_spools,
|
||||||
|
spool_net_kg,
|
||||||
|
(stock_spools * spool_net_kg) as stock_kg
|
||||||
|
from filament_variant;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
create table pricing_policy
|
||||||
|
(
|
||||||
|
pricing_policy_id bigserial primary key,
|
||||||
|
|
||||||
|
policy_name text not null, -- es: "2026 Q1", "Default", ecc.
|
||||||
|
|
||||||
|
-- validità temporale (consiglio: valid_to esclusiva)
|
||||||
|
valid_from timestamptz not null,
|
||||||
|
valid_to timestamptz,
|
||||||
|
|
||||||
|
electricity_cost_chf_per_kwh numeric(10, 6) not null,
|
||||||
|
markup_percent numeric(6, 3) not null default 20.000,
|
||||||
|
|
||||||
|
fixed_job_fee_chf numeric(10, 2) not null default 0.00, -- "costo fisso"
|
||||||
|
nozzle_change_base_fee_chf numeric(10, 2) not null default 0.00, -- base cambio ugello, se vuoi
|
||||||
|
cad_cost_chf_per_hour numeric(10, 2) not null default 0.00,
|
||||||
|
|
||||||
|
is_active boolean not null default true,
|
||||||
|
created_at timestamptz not null default now()
|
||||||
|
);
|
||||||
|
|
||||||
|
create table pricing_policy_machine_hour_tier
|
||||||
|
(
|
||||||
|
pricing_policy_machine_hour_tier_id bigserial primary key,
|
||||||
|
pricing_policy_id bigint not null references pricing_policy (pricing_policy_id),
|
||||||
|
|
||||||
|
tier_start_hours numeric(10, 2) not null,
|
||||||
|
tier_end_hours numeric(10, 2), -- null = infinito
|
||||||
|
machine_cost_chf_per_hour numeric(10, 2) not null,
|
||||||
|
|
||||||
|
constraint chk_tier_start_non_negative check (tier_start_hours >= 0),
|
||||||
|
constraint chk_tier_end_gt_start check (tier_end_hours is null or tier_end_hours > tier_start_hours)
|
||||||
|
);
|
||||||
|
|
||||||
|
create index idx_pricing_policy_validity
|
||||||
|
on pricing_policy (valid_from, valid_to);
|
||||||
|
|
||||||
|
create index idx_pricing_tier_lookup
|
||||||
|
on pricing_policy_machine_hour_tier (pricing_policy_id, tier_start_hours);
|
||||||
|
|
||||||
|
|
||||||
|
create table nozzle_option
|
||||||
|
(
|
||||||
|
nozzle_option_id bigserial primary key,
|
||||||
|
nozzle_diameter_mm numeric(4, 2) not null unique, -- 0.4, 0.6, 0.8...
|
||||||
|
|
||||||
|
owned_quantity integer not null default 0 check (owned_quantity >= 0),
|
||||||
|
|
||||||
|
-- extra costo specifico oltre ad eventuale base fee della pricing_policy
|
||||||
|
extra_nozzle_change_fee_chf numeric(10, 2) not null default 0.00,
|
||||||
|
|
||||||
|
is_active boolean not null default true,
|
||||||
|
created_at timestamptz not null default now()
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
create table layer_height_option
|
||||||
|
(
|
||||||
|
layer_height_option_id bigserial primary key,
|
||||||
|
layer_height_mm numeric(5, 3) not null unique, -- 0.12, 0.20, 0.28...
|
||||||
|
|
||||||
|
-- opzionale: moltiplicatore costo/tempo (es: 0.12 costa di più)
|
||||||
|
time_multiplier numeric(6, 3) not null default 1.000,
|
||||||
|
|
||||||
|
is_active boolean not null default true
|
||||||
|
);
|
||||||
|
|
||||||
|
create table layer_height_profile
|
||||||
|
(
|
||||||
|
layer_height_profile_id bigserial primary key,
|
||||||
|
profile_name text not null unique, -- "Standard", "Fine", ecc.
|
||||||
|
|
||||||
|
min_layer_height_mm numeric(5, 3) not null,
|
||||||
|
max_layer_height_mm numeric(5, 3) not null,
|
||||||
|
default_layer_height_mm numeric(5, 3) not null,
|
||||||
|
|
||||||
|
time_multiplier numeric(6, 3) not null default 1.000,
|
||||||
|
|
||||||
|
constraint chk_layer_range check (max_layer_height_mm >= min_layer_height_mm)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
begin;
|
||||||
|
|
||||||
|
set timezone = 'Europe/Zurich';
|
||||||
|
|
||||||
|
-- =========================================================
|
||||||
|
-- 0) (Solo se non esiste) tabella infill_pattern + seed
|
||||||
|
-- =========================================================
|
||||||
|
-- Se la tabella esiste già, commenta questo blocco.
|
||||||
|
create table if not exists infill_pattern
|
||||||
|
(
|
||||||
|
infill_pattern_id bigserial primary key,
|
||||||
|
pattern_code text not null unique, -- es: grid, gyroid
|
||||||
|
display_name text not null,
|
||||||
|
is_active boolean not null default true
|
||||||
|
);
|
||||||
|
|
||||||
|
insert into infill_pattern (pattern_code, display_name, is_active)
|
||||||
|
values ('grid', 'Grid', true),
|
||||||
|
('gyroid', 'Gyroid', true)
|
||||||
|
on conflict (pattern_code) do update
|
||||||
|
set display_name = excluded.display_name,
|
||||||
|
is_active = excluded.is_active;
|
||||||
|
|
||||||
|
|
||||||
|
-- =========================================================
|
||||||
|
-- 1) Pricing policy (valori ESATTI da Excel)
|
||||||
|
-- Valid from: 2026-01-01, valid_to: NULL
|
||||||
|
-- =========================================================
|
||||||
|
insert into pricing_policy (policy_name,
|
||||||
|
valid_from,
|
||||||
|
valid_to,
|
||||||
|
electricity_cost_chf_per_kwh,
|
||||||
|
markup_percent,
|
||||||
|
fixed_job_fee_chf,
|
||||||
|
nozzle_change_base_fee_chf,
|
||||||
|
cad_cost_chf_per_hour,
|
||||||
|
is_active)
|
||||||
|
values ('Excel Tariffe 2026-01-01',
|
||||||
|
'2026-01-01 00:00:00+01'::timestamptz,
|
||||||
|
null,
|
||||||
|
0.156, -- Costo elettricità CHF/kWh (Excel)
|
||||||
|
0.000, -- Markup non specificato -> 0 (puoi cambiarlo dopo)
|
||||||
|
1.00, -- Costo fisso macchina CHF (Excel)
|
||||||
|
0.00, -- Base cambio ugello: non specificato -> 0
|
||||||
|
25.00, -- Tariffa CAD CHF/h (Excel)
|
||||||
|
true)
|
||||||
|
on conflict do nothing;
|
||||||
|
|
||||||
|
-- scaglioni tariffa stampa (Excel)
|
||||||
|
insert into pricing_policy_machine_hour_tier (pricing_policy_id,
|
||||||
|
tier_start_hours,
|
||||||
|
tier_end_hours,
|
||||||
|
machine_cost_chf_per_hour)
|
||||||
|
select p.pricing_policy_id,
|
||||||
|
tiers.tier_start_hours,
|
||||||
|
tiers.tier_end_hours,
|
||||||
|
tiers.machine_cost_chf_per_hour
|
||||||
|
from pricing_policy p
|
||||||
|
cross join (values (0.00::numeric, 10.00::numeric, 2.00::numeric), -- 0–10 h
|
||||||
|
(10.00::numeric, 20.00::numeric, 1.40::numeric), -- 10–20 h
|
||||||
|
(20.00::numeric, null::numeric, 0.50::numeric) -- >20 h
|
||||||
|
) as tiers(tier_start_hours, tier_end_hours, machine_cost_chf_per_hour)
|
||||||
|
where p.policy_name = 'Excel Tariffe 2026-01-01'
|
||||||
|
on conflict do nothing;
|
||||||
|
|
||||||
|
|
||||||
|
-- =========================================================
|
||||||
|
-- 2) Stampante: BambuLab A1
|
||||||
|
-- =========================================================
|
||||||
|
insert into printer_machine (printer_display_name,
|
||||||
|
build_volume_x_mm,
|
||||||
|
build_volume_y_mm,
|
||||||
|
build_volume_z_mm,
|
||||||
|
power_watts,
|
||||||
|
fleet_weight,
|
||||||
|
is_active)
|
||||||
|
values ('BambuLab A1',
|
||||||
|
256,
|
||||||
|
256,
|
||||||
|
256,
|
||||||
|
150, -- hai detto "150, 140": qui ho messo 150
|
||||||
|
1.000,
|
||||||
|
true)
|
||||||
|
on conflict (printer_display_name) do update
|
||||||
|
set build_volume_x_mm = excluded.build_volume_x_mm,
|
||||||
|
build_volume_y_mm = excluded.build_volume_y_mm,
|
||||||
|
build_volume_z_mm = excluded.build_volume_z_mm,
|
||||||
|
power_watts = excluded.power_watts,
|
||||||
|
fleet_weight = excluded.fleet_weight,
|
||||||
|
is_active = excluded.is_active;
|
||||||
|
|
||||||
|
|
||||||
|
-- =========================================================
|
||||||
|
-- 3) Material types (da Excel) - per ora niente technical
|
||||||
|
-- =========================================================
|
||||||
|
insert into filament_material_type (material_code,
|
||||||
|
is_flexible,
|
||||||
|
is_technical,
|
||||||
|
technical_type_label)
|
||||||
|
values ('PLA', false, false, null),
|
||||||
|
('PETG', false, false, null),
|
||||||
|
('TPU', true, false, null),
|
||||||
|
('ABS', false, false, null),
|
||||||
|
('Nylon', false, false, null),
|
||||||
|
('Carbon PLA', false, false, null)
|
||||||
|
on conflict (material_code) do update
|
||||||
|
set is_flexible = excluded.is_flexible,
|
||||||
|
is_technical = excluded.is_technical,
|
||||||
|
technical_type_label = excluded.technical_type_label;
|
||||||
|
|
||||||
|
|
||||||
|
-- =========================================================
|
||||||
|
-- 4) Filament variants (PLA colori) - costi da Excel
|
||||||
|
-- Excel: PLA = 18 CHF/kg, TPU = 42 CHF/kg (non inserito perché quantità non chiara)
|
||||||
|
-- Stock in "rotoli" (3 = 3 kg se spool_net_kg=1)
|
||||||
|
-- =========================================================
|
||||||
|
|
||||||
|
-- helper: ID PLA
|
||||||
|
with pla as (select filament_material_type_id
|
||||||
|
from filament_material_type
|
||||||
|
where material_code = 'PLA')
|
||||||
|
insert
|
||||||
|
into filament_variant (filament_material_type_id,
|
||||||
|
variant_display_name,
|
||||||
|
color_name,
|
||||||
|
is_matte,
|
||||||
|
is_special,
|
||||||
|
cost_chf_per_kg,
|
||||||
|
stock_spools,
|
||||||
|
spool_net_kg,
|
||||||
|
is_active)
|
||||||
|
select pla.filament_material_type_id,
|
||||||
|
v.variant_display_name,
|
||||||
|
v.color_name,
|
||||||
|
v.is_matte,
|
||||||
|
v.is_special,
|
||||||
|
18.00, -- PLA da Excel
|
||||||
|
v.stock_spools,
|
||||||
|
1.000,
|
||||||
|
true
|
||||||
|
from pla
|
||||||
|
cross join (values ('PLA Bianco', 'Bianco', false, false, 3.000::numeric),
|
||||||
|
('PLA Nero', 'Nero', false, false, 3.000::numeric),
|
||||||
|
('PLA Blu', 'Blu', false, false, 1.000::numeric),
|
||||||
|
('PLA Arancione', 'Arancione', false, false, 1.000::numeric),
|
||||||
|
('PLA Grigio', 'Grigio', false, false, 1.000::numeric),
|
||||||
|
('PLA Grigio Scuro', 'Grigio scuro', false, false, 1.000::numeric),
|
||||||
|
('PLA Grigio Chiaro', 'Grigio chiaro', false, false, 1.000::numeric),
|
||||||
|
('PLA Viola', 'Viola', false, false,
|
||||||
|
1.000::numeric)) as v(variant_display_name, color_name, is_matte, is_special, stock_spools)
|
||||||
|
on conflict (filament_material_type_id, variant_display_name) do update
|
||||||
|
set color_name = excluded.color_name,
|
||||||
|
is_matte = excluded.is_matte,
|
||||||
|
is_special = excluded.is_special,
|
||||||
|
cost_chf_per_kg = excluded.cost_chf_per_kg,
|
||||||
|
stock_spools = excluded.stock_spools,
|
||||||
|
spool_net_kg = excluded.spool_net_kg,
|
||||||
|
is_active = excluded.is_active;
|
||||||
|
|
||||||
|
|
||||||
|
-- =========================================================
|
||||||
|
-- 5) Ugelli
|
||||||
|
-- 0.4 standard (0 extra), 0.6 con attivazione 50 CHF
|
||||||
|
-- =========================================================
|
||||||
|
insert into nozzle_option (nozzle_diameter_mm,
|
||||||
|
owned_quantity,
|
||||||
|
extra_nozzle_change_fee_chf,
|
||||||
|
is_active)
|
||||||
|
values (0.40, 1, 0.00, true),
|
||||||
|
(0.60, 1, 50.00, true)
|
||||||
|
on conflict (nozzle_diameter_mm) do update
|
||||||
|
set owned_quantity = excluded.owned_quantity,
|
||||||
|
extra_nozzle_change_fee_chf = excluded.extra_nozzle_change_fee_chf,
|
||||||
|
is_active = excluded.is_active;
|
||||||
|
|
||||||
|
|
||||||
|
-- =========================================================
|
||||||
|
-- 6) Layer heights (opzioni)
|
||||||
|
-- =========================================================
|
||||||
|
insert into layer_height_option (layer_height_mm,
|
||||||
|
time_multiplier,
|
||||||
|
is_active)
|
||||||
|
values (0.080, 1.000, true),
|
||||||
|
(0.120, 1.000, true),
|
||||||
|
(0.160, 1.000, true),
|
||||||
|
(0.200, 1.000, true),
|
||||||
|
(0.240, 1.000, true),
|
||||||
|
(0.280, 1.000, true)
|
||||||
|
on conflict (layer_height_mm) do update
|
||||||
|
set time_multiplier = excluded.time_multiplier,
|
||||||
|
is_active = excluded.is_active;
|
||||||
|
|
||||||
|
commit;
|
||||||
|
|
||||||
|
|
||||||
|
-- Sostituisci __MULTIPLIER__ con il tuo valore (es. 1.10)
|
||||||
|
update layer_height_option
|
||||||
|
set time_multiplier = 0.1
|
||||||
|
where layer_height_mm = 0.080;
|
||||||
|
|
||||||
|
|
||||||
|
-- =========================
|
||||||
|
-- CUSTOMERS (minimo indispensabile)
|
||||||
|
-- =========================
|
||||||
|
CREATE TABLE IF NOT EXISTS customers
|
||||||
|
(
|
||||||
|
customer_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
customer_type text NOT NULL CHECK (customer_type IN ('PRIVATE', 'COMPANY')),
|
||||||
|
email text NOT NULL,
|
||||||
|
phone text,
|
||||||
|
|
||||||
|
-- per PRIVATE
|
||||||
|
first_name text,
|
||||||
|
last_name text,
|
||||||
|
|
||||||
|
-- per COMPANY
|
||||||
|
company_name text,
|
||||||
|
contact_person text,
|
||||||
|
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
updated_at timestamptz NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS ux_customers_email
|
||||||
|
ON customers (lower(email));
|
||||||
|
|
||||||
|
-- =========================
|
||||||
|
-- QUOTE SESSIONS (carrello preventivo)
|
||||||
|
-- =========================
|
||||||
|
CREATE TABLE IF NOT EXISTS quote_sessions
|
||||||
|
(
|
||||||
|
quote_session_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
status text NOT NULL CHECK (status IN ('ACTIVE', 'EXPIRED', 'CONVERTED')),
|
||||||
|
pricing_version text NOT NULL,
|
||||||
|
|
||||||
|
-- Parametri "globali" (dalla tua UI avanzata)
|
||||||
|
material_code text NOT NULL, -- es: PLA, PETG...
|
||||||
|
nozzle_diameter_mm numeric(5, 2), -- es: 0.40
|
||||||
|
layer_height_mm numeric(6, 3), -- es: 0.20
|
||||||
|
infill_pattern text, -- es: grid
|
||||||
|
infill_percent integer CHECK (infill_percent BETWEEN 0 AND 100),
|
||||||
|
supports_enabled boolean NOT NULL DEFAULT false,
|
||||||
|
notes text,
|
||||||
|
|
||||||
|
setup_cost_chf numeric(12, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
expires_at timestamptz NOT NULL,
|
||||||
|
converted_order_id uuid
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_quote_sessions_status
|
||||||
|
ON quote_sessions (status);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_quote_sessions_expires_at
|
||||||
|
ON quote_sessions (expires_at);
|
||||||
|
|
||||||
|
-- =========================
|
||||||
|
-- QUOTE LINE ITEMS (1 file = 1 riga)
|
||||||
|
-- =========================
|
||||||
|
CREATE TABLE IF NOT EXISTS quote_line_items
|
||||||
|
(
|
||||||
|
quote_line_item_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
quote_session_id uuid NOT NULL REFERENCES quote_sessions (quote_session_id) ON DELETE CASCADE,
|
||||||
|
|
||||||
|
status text NOT NULL CHECK (status IN ('CALCULATING', 'READY', 'FAILED')),
|
||||||
|
|
||||||
|
original_filename text NOT NULL,
|
||||||
|
quantity integer NOT NULL DEFAULT 1 CHECK (quantity >= 1),
|
||||||
|
color_code text, -- es: white/black o codice interno
|
||||||
|
|
||||||
|
-- Output slicing / calcolo
|
||||||
|
bounding_box_x_mm numeric(10, 3),
|
||||||
|
bounding_box_y_mm numeric(10, 3),
|
||||||
|
bounding_box_z_mm numeric(10, 3),
|
||||||
|
print_time_seconds integer CHECK (print_time_seconds >= 0),
|
||||||
|
material_grams numeric(12, 2) CHECK (material_grams >= 0),
|
||||||
|
|
||||||
|
unit_price_chf numeric(12, 2) CHECK (unit_price_chf >= 0),
|
||||||
|
pricing_breakdown jsonb, -- opzionale: costi dettagliati senza creare tabelle
|
||||||
|
|
||||||
|
error_message text,
|
||||||
|
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
updated_at timestamptz NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_quote_line_items_session
|
||||||
|
ON quote_line_items (quote_session_id);
|
||||||
|
|
||||||
|
-- Vista utile per totale quote
|
||||||
|
CREATE OR REPLACE VIEW quote_session_totals AS
|
||||||
|
SELECT qs.quote_session_id,
|
||||||
|
qs.setup_cost_chf +
|
||||||
|
COALESCE(SUM(qli.unit_price_chf * qli.quantity), 0.00) AS total_chf
|
||||||
|
FROM quote_sessions qs
|
||||||
|
LEFT JOIN quote_line_items qli
|
||||||
|
ON qli.quote_session_id = qs.quote_session_id
|
||||||
|
AND qli.status = 'READY'
|
||||||
|
GROUP BY qs.quote_session_id;
|
||||||
|
|
||||||
|
-- =========================
|
||||||
|
-- ORDERS
|
||||||
|
-- =========================
|
||||||
|
CREATE TABLE IF NOT EXISTS orders
|
||||||
|
(
|
||||||
|
order_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
source_quote_session_id uuid REFERENCES quote_sessions (quote_session_id),
|
||||||
|
|
||||||
|
status text NOT NULL CHECK (status IN (
|
||||||
|
'PENDING_PAYMENT', 'PAID', 'IN_PRODUCTION',
|
||||||
|
'SHIPPED', 'COMPLETED', 'CANCELLED'
|
||||||
|
)),
|
||||||
|
|
||||||
|
customer_id uuid REFERENCES customers (customer_id),
|
||||||
|
customer_email text NOT NULL,
|
||||||
|
customer_phone text,
|
||||||
|
|
||||||
|
-- Snapshot indirizzo/fatturazione (evita tabella addresses e mantiene storico)
|
||||||
|
billing_customer_type text NOT NULL CHECK (billing_customer_type IN ('PRIVATE', 'COMPANY')),
|
||||||
|
billing_first_name text,
|
||||||
|
billing_last_name text,
|
||||||
|
billing_company_name text,
|
||||||
|
billing_contact_person text,
|
||||||
|
|
||||||
|
billing_address_line1 text NOT NULL,
|
||||||
|
billing_address_line2 text,
|
||||||
|
billing_zip text NOT NULL,
|
||||||
|
billing_city text NOT NULL,
|
||||||
|
billing_country_code char(2) NOT NULL DEFAULT 'CH',
|
||||||
|
|
||||||
|
shipping_same_as_billing boolean NOT NULL DEFAULT true,
|
||||||
|
shipping_first_name text,
|
||||||
|
shipping_last_name text,
|
||||||
|
shipping_company_name text,
|
||||||
|
shipping_contact_person text,
|
||||||
|
shipping_address_line1 text,
|
||||||
|
shipping_address_line2 text,
|
||||||
|
shipping_zip text,
|
||||||
|
shipping_city text,
|
||||||
|
shipping_country_code char(2),
|
||||||
|
|
||||||
|
currency char(3) NOT NULL DEFAULT 'CHF',
|
||||||
|
setup_cost_chf numeric(12, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
shipping_cost_chf numeric(12, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
discount_chf numeric(12, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
|
||||||
|
subtotal_chf numeric(12, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
total_chf numeric(12, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
paid_at timestamptz
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_orders_status
|
||||||
|
ON orders (status);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_orders_customer_email
|
||||||
|
ON orders (lower(customer_email));
|
||||||
|
|
||||||
|
-- =========================
|
||||||
|
-- ORDER ITEMS (1 file 3D = 1 riga, file salvato su disco)
|
||||||
|
-- =========================
|
||||||
|
CREATE TABLE IF NOT EXISTS order_items
|
||||||
|
(
|
||||||
|
order_item_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
order_id uuid NOT NULL REFERENCES orders (order_id) ON DELETE CASCADE,
|
||||||
|
|
||||||
|
original_filename text NOT NULL,
|
||||||
|
stored_relative_path text NOT NULL, -- es: orders/<orderId>/3d-files/<orderItemId>/<uuid>.stl
|
||||||
|
stored_filename text NOT NULL, -- es: <uuid>.stl
|
||||||
|
|
||||||
|
file_size_bytes bigint CHECK (file_size_bytes >= 0),
|
||||||
|
mime_type text,
|
||||||
|
sha256_hex text, -- opzionale, utile anche per dedup interno
|
||||||
|
|
||||||
|
material_code text NOT NULL,
|
||||||
|
color_code text,
|
||||||
|
quantity integer NOT NULL DEFAULT 1 CHECK (quantity >= 1),
|
||||||
|
|
||||||
|
-- Snapshot output
|
||||||
|
print_time_seconds integer CHECK (print_time_seconds >= 0),
|
||||||
|
material_grams numeric(12, 2) CHECK (material_grams >= 0),
|
||||||
|
unit_price_chf numeric(12, 2) NOT NULL CHECK (unit_price_chf >= 0),
|
||||||
|
line_total_chf numeric(12, 2) NOT NULL CHECK (line_total_chf >= 0),
|
||||||
|
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_order_items_order
|
||||||
|
ON order_items (order_id);
|
||||||
|
|
||||||
|
-- =========================
|
||||||
|
-- PAYMENTS (supporta più tentativi / metodi)
|
||||||
|
-- =========================
|
||||||
|
CREATE TABLE IF NOT EXISTS payments
|
||||||
|
(
|
||||||
|
payment_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
order_id uuid NOT NULL REFERENCES orders (order_id) ON DELETE CASCADE,
|
||||||
|
|
||||||
|
method text NOT NULL CHECK (method IN ('QR_BILL', 'BANK_TRANSFER', 'TWINT', 'CARD', 'OTHER')),
|
||||||
|
status text NOT NULL CHECK (status IN ('PENDING', 'RECEIVED', 'FAILED', 'CANCELLED', 'REFUNDED')),
|
||||||
|
|
||||||
|
currency char(3) NOT NULL DEFAULT 'CHF',
|
||||||
|
amount_chf numeric(12, 2) NOT NULL CHECK (amount_chf >= 0),
|
||||||
|
|
||||||
|
-- riferimento pagamento (molto utile per QR bill / riconciliazione)
|
||||||
|
payment_reference text,
|
||||||
|
provider_transaction_id text,
|
||||||
|
|
||||||
|
qr_payload text, -- se vuoi salvare contenuto QR/Swiss QR bill
|
||||||
|
initiated_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
received_at timestamptz
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_payments_order
|
||||||
|
ON payments (order_id);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_payments_reference
|
||||||
|
ON payments (payment_reference);
|
||||||
|
|
||||||
|
-- =========================
|
||||||
|
-- CUSTOM QUOTE REQUESTS (preventivo personalizzato, form che hai mostrato)
|
||||||
|
-- =========================
|
||||||
|
CREATE TABLE IF NOT EXISTS custom_quote_requests
|
||||||
|
(
|
||||||
|
request_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
request_type text NOT NULL, -- es: "PREVENTIVO_PERSONALIZZATO" o come preferisci
|
||||||
|
|
||||||
|
customer_type text NOT NULL CHECK (customer_type IN ('PRIVATE', 'COMPANY')),
|
||||||
|
email text NOT NULL,
|
||||||
|
phone text,
|
||||||
|
|
||||||
|
-- PRIVATE
|
||||||
|
name text,
|
||||||
|
|
||||||
|
-- COMPANY
|
||||||
|
company_name text,
|
||||||
|
contact_person text,
|
||||||
|
|
||||||
|
message text NOT NULL,
|
||||||
|
status text NOT NULL CHECK (status IN ('NEW', 'PENDING', 'IN_PROGRESS', 'DONE', 'CLOSED')),
|
||||||
|
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
updated_at timestamptz NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_custom_quote_requests_status
|
||||||
|
ON custom_quote_requests (status);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_custom_quote_requests_email
|
||||||
|
ON custom_quote_requests (lower(email));
|
||||||
|
|
||||||
|
-- Allegati della richiesta (max 15 come UI)
|
||||||
|
CREATE TABLE IF NOT EXISTS custom_quote_request_attachments
|
||||||
|
(
|
||||||
|
attachment_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
request_id uuid NOT NULL REFERENCES custom_quote_requests (request_id) ON DELETE CASCADE,
|
||||||
|
|
||||||
|
original_filename text NOT NULL,
|
||||||
|
stored_relative_path text NOT NULL, -- es: quote-requests/<requestId>/attachments/<attachmentId>/<uuid>.stl
|
||||||
|
stored_filename text NOT NULL,
|
||||||
|
|
||||||
|
file_size_bytes bigint CHECK (file_size_bytes >= 0),
|
||||||
|
mime_type text,
|
||||||
|
sha256_hex text,
|
||||||
|
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS ix_custom_quote_attachments_request
|
||||||
|
ON custom_quote_request_attachments (request_id);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
REGISTRY_URL=git.joekung.ch
|
REGISTRY_URL=git.joekung.ch
|
||||||
REPO_OWNER=JoeKung
|
REPO_OWNER=joekung
|
||||||
ENV=dev
|
ENV=dev
|
||||||
TAG=dev
|
TAG=dev
|
||||||
|
|
||||||
@@ -7,9 +7,4 @@ TAG=dev
|
|||||||
BACKEND_PORT=18002
|
BACKEND_PORT=18002
|
||||||
FRONTEND_PORT=18082
|
FRONTEND_PORT=18082
|
||||||
|
|
||||||
# Application Config
|
|
||||||
FILAMENT_COST_PER_KG=22.0
|
|
||||||
MACHINE_COST_PER_HOUR=2.50
|
|
||||||
ENERGY_COST_PER_KWH=0.30
|
|
||||||
PRINTER_POWER_WATTS=150
|
|
||||||
MARKUP_PERCENT=20
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
REGISTRY_URL=git.joekung.ch
|
REGISTRY_URL=git.joekung.ch
|
||||||
REPO_OWNER=JoeKung
|
REPO_OWNER=joekung
|
||||||
ENV=int
|
ENV=int
|
||||||
TAG=int
|
TAG=int
|
||||||
|
|
||||||
@@ -7,9 +7,4 @@ TAG=int
|
|||||||
BACKEND_PORT=18001
|
BACKEND_PORT=18001
|
||||||
FRONTEND_PORT=18081
|
FRONTEND_PORT=18081
|
||||||
|
|
||||||
# Application Config
|
|
||||||
FILAMENT_COST_PER_KG=22.0
|
|
||||||
MACHINE_COST_PER_HOUR=2.50
|
|
||||||
ENERGY_COST_PER_KWH=0.30
|
|
||||||
PRINTER_POWER_WATTS=150
|
|
||||||
MARKUP_PERCENT=20
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
REGISTRY_URL=git.joekung.ch
|
REGISTRY_URL=git.joekung.ch
|
||||||
REPO_OWNER=JoeKung
|
REPO_OWNER=joekung
|
||||||
ENV=prod
|
ENV=prod
|
||||||
TAG=prod
|
TAG=prod
|
||||||
|
|
||||||
@@ -7,9 +7,4 @@ TAG=prod
|
|||||||
BACKEND_PORT=8000
|
BACKEND_PORT=8000
|
||||||
FRONTEND_PORT=80
|
FRONTEND_PORT=80
|
||||||
|
|
||||||
# Application Config
|
|
||||||
FILAMENT_COST_PER_KG=22.0
|
|
||||||
MACHINE_COST_PER_HOUR=2.50
|
|
||||||
ENERGY_COST_PER_KWH=0.30
|
|
||||||
PRINTER_POWER_WATTS=150
|
|
||||||
MARKUP_PERCENT=20
|
|
||||||
|
|||||||
@@ -7,28 +7,36 @@ services:
|
|||||||
container_name: print-calculator-backend-${ENV}
|
container_name: print-calculator-backend-${ENV}
|
||||||
ports:
|
ports:
|
||||||
- "${BACKEND_PORT}:8000"
|
- "${BACKEND_PORT}:8000"
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
environment:
|
environment:
|
||||||
- FILAMENT_COST_PER_KG=${FILAMENT_COST_PER_KG}
|
- DB_URL=${DB_URL}
|
||||||
- MACHINE_COST_PER_HOUR=${MACHINE_COST_PER_HOUR}
|
- DB_USERNAME=${DB_USERNAME}
|
||||||
- ENERGY_COST_PER_KWH=${ENERGY_COST_PER_KWH}
|
- DB_PASSWORD=${DB_PASSWORD}
|
||||||
- PRINTER_POWER_WATTS=${PRINTER_POWER_WATTS}
|
|
||||||
- MARKUP_PERCENT=${MARKUP_PERCENT}
|
|
||||||
- TEMP_DIR=/app/temp
|
- TEMP_DIR=/app/temp
|
||||||
- PROFILES_DIR=/app/profiles
|
- PROFILES_DIR=/app/profiles
|
||||||
restart: unless-stopped
|
- CLAMAV_HOST=host.docker.internal
|
||||||
|
- CLAMAV_PORT=3310
|
||||||
|
- STORAGE_LOCATION=/app/storage
|
||||||
|
restart: always
|
||||||
volumes:
|
volumes:
|
||||||
- backend_profiles_${ENV}:/app/profiles
|
- backend_profiles_${ENV}:/app/profiles
|
||||||
|
- /mnt/cache/appdata/print-calculator/${ENV}/storage_quotes:/app/storage/quotes
|
||||||
|
- /mnt/cache/appdata/print-calculator/${ENV}/storage_orders:/app/storage/orders
|
||||||
|
extra_hosts:
|
||||||
|
- "host.docker.internal:host-gateway"
|
||||||
|
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
image: ${REGISTRY_URL}/${REPO_OWNER}/print-calculator-frontend:${TAG}
|
image: ${REGISTRY_URL}/${REPO_OWNER}/print-calculator-frontend:${TAG}
|
||||||
container_name: print-calculator-frontend-${ENV}
|
container_name: print-calculator-frontend-${ENV}
|
||||||
ports:
|
ports:
|
||||||
- "${FRONTEND_PORT}:8008"
|
- "${FRONTEND_PORT}:80"
|
||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
- backend
|
||||||
restart: unless-stopped
|
restart: always
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
backend_profiles_prod:
|
backend_profiles_prod:
|
||||||
backend_profiles_int:
|
backend_profiles_int:
|
||||||
backend_profiles_dev:
|
backend_profiles_dev:
|
||||||
|
|||||||
@@ -9,20 +9,52 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
environment:
|
environment:
|
||||||
- FILAMENT_COST_PER_KG=22.0
|
- DB_URL=jdbc:postgresql://db:5432/printcalc
|
||||||
- MACHINE_COST_PER_HOUR=2.50
|
- DB_USERNAME=printcalc
|
||||||
- ENERGY_COST_PER_KWH=0.30
|
- DB_PASSWORD=printcalc_secret
|
||||||
- PRINTER_POWER_WATTS=150
|
- SPRING_PROFILES_ACTIVE=local
|
||||||
- MARKUP_PERCENT=20
|
|
||||||
- TEMP_DIR=/app/temp
|
- TEMP_DIR=/app/temp
|
||||||
- PROFILES_DIR=/app/profiles
|
- PROFILES_DIR=/app/profiles
|
||||||
|
- CLAMAV_HOST=clamav
|
||||||
|
- CLAMAV_PORT=3310
|
||||||
|
- STORAGE_LOCATION=/app/storage
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
- clamav
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
clamav:
|
||||||
|
platform: linux/amd64
|
||||||
|
image: clamav/clamav:latest
|
||||||
|
container_name: print-calculator-clamav
|
||||||
|
ports:
|
||||||
|
- "3310:3310"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
build: ./frontend
|
build:
|
||||||
|
context: ./frontend
|
||||||
|
dockerfile: Dockerfile.dev
|
||||||
container_name: print-calculator-frontend
|
container_name: print-calculator-frontend
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "80:80"
|
||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
- backend
|
||||||
|
- db
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:15-alpine
|
||||||
|
container_name: print-calculator-db
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER=printcalc
|
||||||
|
- POSTGRES_PASSWORD=printcalc_secret
|
||||||
|
- POSTGRES_DB=printcalc
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
volumes:
|
||||||
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
|
|||||||
15
frontend/Dockerfile.dev
Normal file
15
frontend/Dockerfile.dev
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Stage 1: Build
|
||||||
|
FROM node:20 as build
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install
|
||||||
|
COPY . .
|
||||||
|
# Use development configuration to pick up environment.ts (localhost)
|
||||||
|
RUN npm run build -- --configuration=development
|
||||||
|
|
||||||
|
# Stage 2: Serve
|
||||||
|
FROM nginx:alpine
|
||||||
|
COPY --from=build /app/dist/frontend/browser /usr/share/nginx/html
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
EXPOSE 80
|
||||||
@@ -70,6 +70,17 @@
|
|||||||
"optimization": false,
|
"optimization": false,
|
||||||
"extractLicenses": false,
|
"extractLicenses": false,
|
||||||
"sourceMap": true
|
"sourceMap": true
|
||||||
|
},
|
||||||
|
"local": {
|
||||||
|
"fileReplacements": [
|
||||||
|
{
|
||||||
|
"replace": "src/environments/environment.ts",
|
||||||
|
"with": "src/environments/environment.local.ts"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"optimization": false,
|
||||||
|
"extractLicenses": false,
|
||||||
|
"sourceMap": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -83,6 +94,9 @@
|
|||||||
},
|
},
|
||||||
"development": {
|
"development": {
|
||||||
"buildTarget": "frontend:build:development"
|
"buildTarget": "frontend:build:development"
|
||||||
|
},
|
||||||
|
"local": {
|
||||||
|
"buildTarget": "frontend:build:local"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"defaultConfiguration": "development"
|
"defaultConfiguration": "development"
|
||||||
@@ -114,8 +128,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"cli": {
|
|
||||||
"analytics": false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
frontend/package-lock.json
generated
30
frontend/package-lock.json
generated
@@ -406,7 +406,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-19.2.19.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-19.2.19.tgz",
|
||||||
"integrity": "sha512-PCpJagurPBqciqcq4Z8+3OtKLb7rSl4w/qBJoIMua8CgnrjvA1i+SWawhdtfI1zlY8FSwhzLwXV0CmWWfFzQPg==",
|
"integrity": "sha512-PCpJagurPBqciqcq4Z8+3OtKLb7rSl4w/qBJoIMua8CgnrjvA1i+SWawhdtfI1zlY8FSwhzLwXV0CmWWfFzQPg==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"parse5": "^7.1.2",
|
"parse5": "^7.1.2",
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
@@ -456,7 +455,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@angular/common/-/common-19.2.18.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/common/-/common-19.2.18.tgz",
|
||||||
"integrity": "sha512-CrV02Omzw/QtfjlEVXVPJVXipdx83NuA+qSASZYrxrhKFusUZyK3P/Zznqg+wiAeNDbedQwMUVqoAARHf0xQrw==",
|
"integrity": "sha512-CrV02Omzw/QtfjlEVXVPJVXipdx83NuA+qSASZYrxrhKFusUZyK3P/Zznqg+wiAeNDbedQwMUVqoAARHf0xQrw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
@@ -473,7 +471,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-19.2.18.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/compiler/-/compiler-19.2.18.tgz",
|
||||||
"integrity": "sha512-3MscvODxRVxc3Cs0ZlHI5Pk5rEvE80otfvxZTMksOZuPlv1B+S8MjWfc3X3jk9SbyUEzODBEH55iCaBHD48V3g==",
|
"integrity": "sha512-3MscvODxRVxc3Cs0ZlHI5Pk5rEvE80otfvxZTMksOZuPlv1B+S8MjWfc3X3jk9SbyUEzODBEH55iCaBHD48V3g==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
@@ -487,7 +484,6 @@
|
|||||||
"integrity": "sha512-N4TMtLfImJIoMaRL6mx7885UBeQidywptHH6ACZj71Ar6++DBc1mMlcwuvbeJCd3r3y8MQ5nLv5PZSN/tHr13w==",
|
"integrity": "sha512-N4TMtLfImJIoMaRL6mx7885UBeQidywptHH6ACZj71Ar6++DBc1mMlcwuvbeJCd3r3y8MQ5nLv5PZSN/tHr13w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "7.26.9",
|
"@babel/core": "7.26.9",
|
||||||
"@jridgewell/sourcemap-codec": "^1.4.14",
|
"@jridgewell/sourcemap-codec": "^1.4.14",
|
||||||
@@ -564,7 +560,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@angular/core/-/core-19.2.18.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/core/-/core-19.2.18.tgz",
|
||||||
"integrity": "sha512-+QRrf0Igt8ccUWXHA+7doK5W6ODyhHdqVyblSlcQ8OciwkzIIGGEYNZom5OZyWMh+oI54lcSeyV2O3xaDepSrQ==",
|
"integrity": "sha512-+QRrf0Igt8ccUWXHA+7doK5W6ODyhHdqVyblSlcQ8OciwkzIIGGEYNZom5OZyWMh+oI54lcSeyV2O3xaDepSrQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
@@ -581,7 +576,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@angular/forms/-/forms-19.2.18.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/forms/-/forms-19.2.18.tgz",
|
||||||
"integrity": "sha512-pe40934jWhoS7DyGl7jyZdoj1gvBgur2t1zrJD+csEkTitYnW14+La2Pv6SW1pNX5nIzFsgsS9Nex1KcH5S6Tw==",
|
"integrity": "sha512-pe40934jWhoS7DyGl7jyZdoj1gvBgur2t1zrJD+csEkTitYnW14+La2Pv6SW1pNX5nIzFsgsS9Nex1KcH5S6Tw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
@@ -617,7 +611,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-19.2.18.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-19.2.18.tgz",
|
||||||
"integrity": "sha512-eahtsHPyXTYLARs9YOlXhnXGgzw0wcyOcDkBvNWK/3lA0NHIgIHmQgXAmBo+cJ+g9skiEQTD2OmSrrwbFKWJkw==",
|
"integrity": "sha512-eahtsHPyXTYLARs9YOlXhnXGgzw0wcyOcDkBvNWK/3lA0NHIgIHmQgXAmBo+cJ+g9skiEQTD2OmSrrwbFKWJkw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
@@ -702,7 +695,6 @@
|
|||||||
"integrity": "sha512-vMqyb7XCDMPvJFFOaT9kxtiRh42GwlZEg1/uIgtZshS5a/8OaduUfCi7kynKgc3Tw/6Uo2D+db9qBttghhmxwQ==",
|
"integrity": "sha512-vMqyb7XCDMPvJFFOaT9kxtiRh42GwlZEg1/uIgtZshS5a/8OaduUfCi7kynKgc3Tw/6Uo2D+db9qBttghhmxwQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ampproject/remapping": "^2.2.0",
|
"@ampproject/remapping": "^2.2.0",
|
||||||
"@babel/code-frame": "^7.26.2",
|
"@babel/code-frame": "^7.26.2",
|
||||||
@@ -3056,7 +3048,6 @@
|
|||||||
"integrity": "sha512-G1ytyOoHh5BphmEBxSwALin3n1KGNYB6yImbICcRQdzXfOGbuJ9Jske/Of5Sebk339NSGGNfUshnzK8YWkTPsQ==",
|
"integrity": "sha512-G1ytyOoHh5BphmEBxSwALin3n1KGNYB6yImbICcRQdzXfOGbuJ9Jske/Of5Sebk339NSGGNfUshnzK8YWkTPsQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@inquirer/checkbox": "^4.1.2",
|
"@inquirer/checkbox": "^4.1.2",
|
||||||
"@inquirer/confirm": "^5.1.6",
|
"@inquirer/confirm": "^5.1.6",
|
||||||
@@ -5701,7 +5692,6 @@
|
|||||||
"integrity": "sha512-3vMNr4TzNQyjHcRZadojpRaD9Ofr6LsonZAoQ+HMUa/9ORTPoxVIw0e0mpqWpdjj8xybyCM+oKOUH2vwFu/oEw==",
|
"integrity": "sha512-3vMNr4TzNQyjHcRZadojpRaD9Ofr6LsonZAoQ+HMUa/9ORTPoxVIw0e0mpqWpdjj8xybyCM+oKOUH2vwFu/oEw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "~6.21.0"
|
"undici-types": "~6.21.0"
|
||||||
}
|
}
|
||||||
@@ -6120,7 +6110,6 @@
|
|||||||
"integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
|
"integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
"fast-uri": "^3.0.1",
|
"fast-uri": "^3.0.1",
|
||||||
@@ -6584,7 +6573,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"caniuse-lite": "^1.0.30001716",
|
"caniuse-lite": "^1.0.30001716",
|
||||||
"electron-to-chromium": "^1.5.149",
|
"electron-to-chromium": "^1.5.149",
|
||||||
@@ -9580,8 +9568,7 @@
|
|||||||
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-5.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-5.6.0.tgz",
|
||||||
"integrity": "sha512-niVlkeYVRwKFpmfWg6suo6H9CrNnydfBLEqefM5UjibYS+UoTjZdmvPJSiuyrRLGnFj1eYRhFd/ch+5hSlsFVA==",
|
"integrity": "sha512-niVlkeYVRwKFpmfWg6suo6H9CrNnydfBLEqefM5UjibYS+UoTjZdmvPJSiuyrRLGnFj1eYRhFd/ch+5hSlsFVA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT"
|
||||||
"peer": true
|
|
||||||
},
|
},
|
||||||
"node_modules/jest-worker": {
|
"node_modules/jest-worker": {
|
||||||
"version": "27.5.1",
|
"version": "27.5.1",
|
||||||
@@ -9620,7 +9607,6 @@
|
|||||||
"integrity": "sha512-/imKNG4EbWNrVjoNC/1H5/9GFy+tqjGBHCaSsN+P2RnPqjsLmv6UD3Ej+Kj8nBWaRAwyk7kK5ZUc+OEatnTR3A==",
|
"integrity": "sha512-/imKNG4EbWNrVjoNC/1H5/9GFy+tqjGBHCaSsN+P2RnPqjsLmv6UD3Ej+Kj8nBWaRAwyk7kK5ZUc+OEatnTR3A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"jiti": "bin/jiti.js"
|
"jiti": "bin/jiti.js"
|
||||||
}
|
}
|
||||||
@@ -9728,7 +9714,6 @@
|
|||||||
"integrity": "sha512-LrtUxbdvt1gOpo3gxG+VAJlJAEMhbWlM4YrFQgql98FwF7+K8K12LYO4hnDdUkNjeztYrOXEMqgTajSWgmtI/w==",
|
"integrity": "sha512-LrtUxbdvt1gOpo3gxG+VAJlJAEMhbWlM4YrFQgql98FwF7+K8K12LYO4hnDdUkNjeztYrOXEMqgTajSWgmtI/w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@colors/colors": "1.5.0",
|
"@colors/colors": "1.5.0",
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
@@ -10077,7 +10062,6 @@
|
|||||||
"integrity": "sha512-tkuLHQlvWUTeQ3doAqnHbNn8T6WX1KA8yvbKG9x4VtKtIjHsVKQZCH11zRgAfbDAXC2UNIg/K9BYAAcEzUIrNg==",
|
"integrity": "sha512-tkuLHQlvWUTeQ3doAqnHbNn8T6WX1KA8yvbKG9x4VtKtIjHsVKQZCH11zRgAfbDAXC2UNIg/K9BYAAcEzUIrNg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"copy-anything": "^2.0.1",
|
"copy-anything": "^2.0.1",
|
||||||
"parse-node-version": "^1.0.1",
|
"parse-node-version": "^1.0.1",
|
||||||
@@ -11893,7 +11877,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nanoid": "^3.3.8",
|
"nanoid": "^3.3.8",
|
||||||
"picocolors": "^1.1.1",
|
"picocolors": "^1.1.1",
|
||||||
@@ -12543,7 +12526,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz",
|
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz",
|
||||||
"integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==",
|
"integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.1.0"
|
"tslib": "^2.1.0"
|
||||||
}
|
}
|
||||||
@@ -13662,7 +13644,6 @@
|
|||||||
"integrity": "sha512-LBAhFyLho16harJoWMg/nZsQYgTrg5jXOn2nCYjRUcZZEdE3qa2zb8QEDRUGVZBW4rlazf2fxkg8tztybTaqWw==",
|
"integrity": "sha512-LBAhFyLho16harJoWMg/nZsQYgTrg5jXOn2nCYjRUcZZEdE3qa2zb8QEDRUGVZBW4rlazf2fxkg8tztybTaqWw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@jridgewell/source-map": "^0.3.3",
|
"@jridgewell/source-map": "^0.3.3",
|
||||||
"acorn": "^8.8.2",
|
"acorn": "^8.8.2",
|
||||||
@@ -13822,8 +13803,7 @@
|
|||||||
"version": "2.8.1",
|
"version": "2.8.1",
|
||||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
||||||
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
|
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
|
||||||
"license": "0BSD",
|
"license": "0BSD"
|
||||||
"peer": true
|
|
||||||
},
|
},
|
||||||
"node_modules/tuf-js": {
|
"node_modules/tuf-js": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
@@ -13880,7 +13860,6 @@
|
|||||||
"integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==",
|
"integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"peer": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
"tsserver": "bin/tsserver"
|
"tsserver": "bin/tsserver"
|
||||||
@@ -14567,7 +14546,6 @@
|
|||||||
"integrity": "sha512-UFynvx+gM44Gv9qFgj0acCQK2VE1CtdfwFdimkapco3hlPCJ/zeq73n2yVKimVbtm+TnApIugGhLJnkU6gjYXA==",
|
"integrity": "sha512-UFynvx+gM44Gv9qFgj0acCQK2VE1CtdfwFdimkapco3hlPCJ/zeq73n2yVKimVbtm+TnApIugGhLJnkU6gjYXA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/eslint-scope": "^3.7.7",
|
"@types/eslint-scope": "^3.7.7",
|
||||||
"@types/estree": "^1.0.6",
|
"@types/estree": "^1.0.6",
|
||||||
@@ -14645,7 +14623,6 @@
|
|||||||
"integrity": "sha512-QcQ72gh8a+7JO63TAx/6XZf/CWhgMzu5m0QirvPfGvptOusAxG12w2+aua1Jkjr7hzaWDnJ2n6JFeexMHI+Zjg==",
|
"integrity": "sha512-QcQ72gh8a+7JO63TAx/6XZf/CWhgMzu5m0QirvPfGvptOusAxG12w2+aua1Jkjr7hzaWDnJ2n6JFeexMHI+Zjg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/bonjour": "^3.5.13",
|
"@types/bonjour": "^3.5.13",
|
||||||
"@types/connect-history-api-fallback": "^1.5.4",
|
"@types/connect-history-api-fallback": "^1.5.4",
|
||||||
@@ -15212,8 +15189,7 @@
|
|||||||
"version": "0.15.0",
|
"version": "0.15.0",
|
||||||
"resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.15.0.tgz",
|
"resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.15.0.tgz",
|
||||||
"integrity": "sha512-9oxn0IIjbCZkJ67L+LkhYWRyAy7axphb3VgE2MBDlOqnmHMPWGYMxJxBYFueFq/JGY2GMwS0rU+UCLunEmy5UA==",
|
"integrity": "sha512-9oxn0IIjbCZkJ67L+LkhYWRyAy7axphb3VgE2MBDlOqnmHMPWGYMxJxBYFueFq/JGY2GMwS0rU+UCLunEmy5UA==",
|
||||||
"license": "MIT",
|
"license": "MIT"
|
||||||
"peer": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
0
frontend/src/app/app.component.scss
Normal file
0
frontend/src/app/app.component.scss
Normal file
@@ -5,6 +5,7 @@ import { RouterOutlet } from '@angular/router';
|
|||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [RouterOutlet],
|
imports: [RouterOutlet],
|
||||||
template: `<router-outlet></router-outlet>`
|
templateUrl: './app.component.html',
|
||||||
|
styleUrl: './app.component.scss'
|
||||||
})
|
})
|
||||||
export class AppComponent {}
|
export class AppComponent {}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user