feat(equipements): clean equipment search, fix category regression, and sync dotations on category change

This commit is contained in:
2026-06-15 23:11:05 +02:00
parent e1cd5930fd
commit c4bb9803ed
9 changed files with 368 additions and 11 deletions
@@ -1,6 +1,7 @@
package com.astalange.core.repository;
import com.astalange.core.entity.Dotation;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@@ -8,6 +9,6 @@ import java.util.List;
import com.astalange.core.entity.Saison;
@Repository
public interface DotationRepository extends JpaRepository<Dotation, Long> {
public interface DotationRepository extends JpaRepository<Dotation, Long>, JpaSpecificationExecutor<Dotation> {
List<Dotation> findByLicence_SaisonAndChoisiTrueAndFourniFalse(Saison saison);
}
@@ -76,7 +76,13 @@ public class CategorieService {
}
}
private void updateDotationsForLicence(Licence licence, List<CategorieEquipement> categorieEquipements) {
public void syncDotationsForLicence(Licence licence) {
if (licence.getCategorie() != null) {
updateDotationsForLicence(licence, licence.getCategorie().getCategorieEquipements());
}
}
public void updateDotationsForLicence(Licence licence, List<CategorieEquipement> categorieEquipements) {
List<Dotation> currentDotations = licence.getDotations();
List<Dotation> toRemove = new ArrayList<>();
@@ -24,12 +24,14 @@ public class DotationService {
sb.append('\ufeff');
// Header
sb.append("Catégorie;Nom;Prénom;Équipement;Taille;Flocage;Numéro\n");
sb.append("Catégorie;Nom;Prénom;Poste;Sexe;É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 poste = d.getLicence().getAdherent().getTypeMaillot() != null ? d.getLicence().getAdherent().getTypeMaillot() : "";
String sexe = d.getLicence().getAdherent().getSexe() != null ? d.getLicence().getAdherent().getSexe() : "";
String equipement = d.getEquipement() != null ? d.getEquipement().getNom() : "";
String taille = d.getTaille() != null ? d.getTaille() : "";
String flocage = d.getFlocage() != null ? d.getFlocage() : "";
@@ -38,6 +40,8 @@ public class DotationService {
sb.append(escapeCsv(categorie)).append(";")
.append(escapeCsv(nom)).append(";")
.append(escapeCsv(prenom)).append(";")
.append(escapeCsv(poste)).append(";")
.append(escapeCsv(sexe)).append(";")
.append(escapeCsv(equipement)).append(";")
.append(escapeCsv(taille)).append(";")
.append(escapeCsv(flocage)).append(";")
@@ -47,6 +51,43 @@ public class DotationService {
return sb.toString();
}
public String genererCsvSearchEquipement(List<Dotation> dotations) {
StringBuilder sb = new StringBuilder();
// BOM for Excel to open UTF-8 correctly
sb.append('\ufeff');
// Header
sb.append("Saison;Catégorie;Nom;Prénom;Poste;Sexe;Équipement;Taille;Flocage;Numéro;Fourni\n");
for (Dotation d : dotations) {
String saison = d.getLicence().getSaison() != null ? d.getLicence().getSaison().getNom() : "";
String categorie = d.getLicence().getCategorie() != null ? d.getLicence().getCategorie().getNom() : "";
String nom = d.getLicence().getAdherent().getNom();
String prenom = d.getLicence().getAdherent().getPrenom();
String poste = d.getLicence().getAdherent().getTypeMaillot() != null ? d.getLicence().getAdherent().getTypeMaillot() : "";
String sexe = d.getLicence().getAdherent().getSexe() != null ? d.getLicence().getAdherent().getSexe() : "";
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() : "";
String fourni = Boolean.TRUE.equals(d.getFourni()) ? "Oui" : "Non";
sb.append(escapeCsv(saison)).append(";")
.append(escapeCsv(categorie)).append(";")
.append(escapeCsv(nom)).append(";")
.append(escapeCsv(prenom)).append(";")
.append(escapeCsv(poste)).append(";")
.append(escapeCsv(sexe)).append(";")
.append(escapeCsv(equipement)).append(";")
.append(escapeCsv(taille)).append(";")
.append(escapeCsv(flocage)).append(";")
.append(escapeCsv(numero)).append(";")
.append(escapeCsv(fourni)).append("\n");
}
return sb.toString();
}
private String escapeCsv(String value) {
if (value == null) {
return "";