feat: Export CSV des commandes équipements (Dashboard)
- Ajout de la génération de CSV des équipements choisis et non fournis pour la saison active. - Création du DotationService et ajout de la route /admin/equipements/export-commande. - Ajout du bouton d'export sur le tableau de bord principal (index.html).
This commit is contained in:
@@ -4,6 +4,10 @@ import com.astalange.core.entity.Dotation;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import com.astalange.core.entity.Saison;
|
||||
|
||||
@Repository
|
||||
public interface DotationRepository extends JpaRepository<Dotation, Long> {
|
||||
List<Dotation> findByLicence_SaisonAndChoisiTrueAndFourniFalse(Saison saison);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.astalange.core.service;
|
||||
|
||||
import com.astalange.core.entity.Dotation;
|
||||
import com.astalange.core.entity.Saison;
|
||||
import com.astalange.core.repository.DotationRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DotationService {
|
||||
|
||||
private final DotationRepository dotationRepository;
|
||||
|
||||
public DotationService(DotationRepository dotationRepository) {
|
||||
this.dotationRepository = dotationRepository;
|
||||
}
|
||||
|
||||
public String genererCsvCommandeEquipement(Saison saisonActive) {
|
||||
List<Dotation> dotations = dotationRepository.findByLicence_SaisonAndChoisiTrueAndFourniFalse(saisonActive);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// BOM for Excel to open UTF-8 correctly
|
||||
sb.append('\ufeff');
|
||||
|
||||
// Header
|
||||
sb.append("Catégorie;Nom;Prénom;Équipement;Taille;Flocage;Numéro\n");
|
||||
|
||||
for (Dotation d : dotations) {
|
||||
String categorie = d.getLicence().getCategorie() != null ? d.getLicence().getCategorie().getNom() : "";
|
||||
String nom = d.getLicence().getAdherent().getNom();
|
||||
String prenom = d.getLicence().getAdherent().getPrenom();
|
||||
String equipement = d.getEquipement() != null ? d.getEquipement().getNom() : "";
|
||||
String taille = d.getTaille() != null ? d.getTaille() : "";
|
||||
String flocage = d.getFlocage() != null ? d.getFlocage() : "";
|
||||
String numero = d.getNumero() != null ? d.getNumero() : "";
|
||||
|
||||
sb.append(escapeCsv(categorie)).append(";")
|
||||
.append(escapeCsv(nom)).append(";")
|
||||
.append(escapeCsv(prenom)).append(";")
|
||||
.append(escapeCsv(equipement)).append(";")
|
||||
.append(escapeCsv(taille)).append(";")
|
||||
.append(escapeCsv(flocage)).append(";")
|
||||
.append(escapeCsv(numero)).append("\n");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String escapeCsv(String value) {
|
||||
if (value == null) {
|
||||
return "";
|
||||
}
|
||||
String result = value;
|
||||
if (result.contains("\"")) {
|
||||
result = result.replace("\"", "\"\"");
|
||||
}
|
||||
if (result.contains(";") || result.contains("\n") || result.contains("\"")) {
|
||||
return "\"" + result + "\"";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user