Sync: code local unifié
Synchronisation du code source local (fait foi). Signed-off-by: lions dev Team
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
package dev.lions.unionflow.server.service;
|
||||
|
||||
import dev.lions.unionflow.server.api.dto.finance.AdhesionDTO;
|
||||
import dev.lions.unionflow.server.entity.Adhesion;
|
||||
import dev.lions.unionflow.server.api.dto.finance.request.CreateAdhesionRequest;
|
||||
import dev.lions.unionflow.server.api.dto.finance.request.UpdateAdhesionRequest;
|
||||
import dev.lions.unionflow.server.api.dto.finance.response.AdhesionResponse;
|
||||
|
||||
import dev.lions.unionflow.server.entity.DemandeAdhesion;
|
||||
import dev.lions.unionflow.server.entity.Membre;
|
||||
import dev.lions.unionflow.server.entity.Organisation;
|
||||
import dev.lions.unionflow.server.repository.AdhesionRepository;
|
||||
import dev.lions.unionflow.server.repository.MembreRepository;
|
||||
import dev.lions.unionflow.server.repository.OrganisationRepository;
|
||||
import io.quarkus.panache.common.Page;
|
||||
import io.quarkus.panache.common.Sort;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.transaction.Transactional;
|
||||
@@ -16,7 +17,7 @@ import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.ws.rs.NotFoundException;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -24,140 +25,80 @@ import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Service métier pour la gestion des adhésions
|
||||
* Contient la logique métier et les règles de validation
|
||||
* Service métier pour la gestion des demandes d'adhésion.
|
||||
*
|
||||
* @author UnionFlow Team
|
||||
* @version 1.0
|
||||
* @since 2025-01-17
|
||||
* @version 2.0
|
||||
* @since 2025-02-18
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@Slf4j
|
||||
public class AdhesionService {
|
||||
|
||||
@Inject AdhesionRepository adhesionRepository;
|
||||
@Inject
|
||||
AdhesionRepository adhesionRepository;
|
||||
@Inject
|
||||
MembreRepository membreRepository;
|
||||
@Inject
|
||||
OrganisationRepository organisationRepository;
|
||||
@Inject
|
||||
MembreKeycloakSyncService keycloakSyncService;
|
||||
@Inject
|
||||
DefaultsService defaultsService;
|
||||
|
||||
@Inject MembreRepository membreRepository;
|
||||
|
||||
@Inject OrganisationRepository organisationRepository;
|
||||
|
||||
/**
|
||||
* Récupère toutes les adhésions avec pagination
|
||||
*
|
||||
* @param page numéro de page (0-based)
|
||||
* @param size taille de la page
|
||||
* @return liste des adhésions converties en DTO
|
||||
*/
|
||||
public List<AdhesionDTO> getAllAdhesions(int page, int size) {
|
||||
public List<AdhesionResponse> getAllAdhesions(int page, int size) {
|
||||
log.debug("Récupération des adhésions - page: {}, size: {}", page, size);
|
||||
|
||||
jakarta.persistence.TypedQuery<Adhesion> query =
|
||||
adhesionRepository
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
"SELECT a FROM Adhesion a ORDER BY a.dateDemande DESC", Adhesion.class);
|
||||
jakarta.persistence.TypedQuery<DemandeAdhesion> query = adhesionRepository
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
"SELECT a FROM DemandeAdhesion a ORDER BY a.dateDemande DESC",
|
||||
DemandeAdhesion.class);
|
||||
query.setFirstResult(page * size);
|
||||
query.setMaxResults(size);
|
||||
List<Adhesion> adhesions = query.getResultList();
|
||||
|
||||
return adhesions.stream().map(this::convertToDTO).collect(Collectors.toList());
|
||||
return query.getResultList().stream().map(this::convertToDTO).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère une adhésion par son ID
|
||||
*
|
||||
* @param id identifiant UUID de l'adhésion
|
||||
* @return DTO de l'adhésion
|
||||
* @throws NotFoundException si l'adhésion n'existe pas
|
||||
*/
|
||||
public AdhesionDTO getAdhesionById(@NotNull UUID id) {
|
||||
public AdhesionResponse getAdhesionById(@NotNull UUID id) {
|
||||
log.debug("Récupération de l'adhésion avec ID: {}", id);
|
||||
|
||||
Adhesion adhesion =
|
||||
adhesionRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Adhésion non trouvée avec l'ID: " + id));
|
||||
|
||||
DemandeAdhesion adhesion = adhesionRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Adhésion non trouvée avec l'ID: " + id));
|
||||
return convertToDTO(adhesion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère une adhésion par son numéro de référence
|
||||
*
|
||||
* @param numeroReference numéro de référence unique
|
||||
* @return DTO de l'adhésion
|
||||
* @throws NotFoundException si l'adhésion n'existe pas
|
||||
*/
|
||||
public AdhesionDTO getAdhesionByReference(@NotNull String numeroReference) {
|
||||
public AdhesionResponse getAdhesionByReference(@NotNull String numeroReference) {
|
||||
log.debug("Récupération de l'adhésion avec référence: {}", numeroReference);
|
||||
|
||||
Adhesion adhesion =
|
||||
adhesionRepository
|
||||
.findByNumeroReference(numeroReference)
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new NotFoundException(
|
||||
"Adhésion non trouvée avec la référence: " + numeroReference));
|
||||
|
||||
DemandeAdhesion adhesion = adhesionRepository
|
||||
.findByNumeroReference(numeroReference)
|
||||
.orElseThrow(
|
||||
() -> new NotFoundException(
|
||||
"Adhésion non trouvée avec la référence: " + numeroReference));
|
||||
return convertToDTO(adhesion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée une nouvelle adhésion
|
||||
*
|
||||
* @param adhesionDTO données de l'adhésion à créer
|
||||
* @return DTO de l'adhésion créée
|
||||
*/
|
||||
@Transactional
|
||||
public AdhesionDTO createAdhesion(@Valid AdhesionDTO adhesionDTO) {
|
||||
public AdhesionResponse createAdhesion(@Valid CreateAdhesionRequest request) {
|
||||
log.info(
|
||||
"Création d'une nouvelle adhésion pour le membre: {} et l'organisation: {}",
|
||||
adhesionDTO.getMembreId(),
|
||||
adhesionDTO.getOrganisationId());
|
||||
request.membreId(),
|
||||
request.organisationId());
|
||||
|
||||
// Validation du membre
|
||||
Membre membre =
|
||||
membreRepository
|
||||
.findByIdOptional(adhesionDTO.getMembreId())
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new NotFoundException(
|
||||
"Membre non trouvé avec l'ID: " + adhesionDTO.getMembreId()));
|
||||
Membre membre = membreRepository
|
||||
.findByIdOptional(request.membreId())
|
||||
.orElseThrow(
|
||||
() -> new NotFoundException(
|
||||
"Membre non trouvé avec l'ID: " + request.membreId()));
|
||||
|
||||
// Validation de l'organisation
|
||||
Organisation organisation =
|
||||
organisationRepository
|
||||
.findByIdOptional(adhesionDTO.getOrganisationId())
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new NotFoundException(
|
||||
"Organisation non trouvée avec l'ID: " + adhesionDTO.getOrganisationId()));
|
||||
Organisation organisation = organisationRepository
|
||||
.findByIdOptional(request.organisationId())
|
||||
.orElseThrow(
|
||||
() -> new NotFoundException(
|
||||
"Organisation non trouvée avec l'ID: " + request.organisationId()));
|
||||
|
||||
// Conversion DTO vers entité
|
||||
Adhesion adhesion = convertToEntity(adhesionDTO);
|
||||
adhesion.setMembre(membre);
|
||||
DemandeAdhesion adhesion = convertToEntity(request);
|
||||
adhesion.setUtilisateur(membre);
|
||||
adhesion.setOrganisation(organisation);
|
||||
|
||||
// Génération automatique du numéro de référence si absent
|
||||
if (adhesion.getNumeroReference() == null || adhesion.getNumeroReference().isEmpty()) {
|
||||
adhesion.setNumeroReference(genererNumeroReference());
|
||||
}
|
||||
|
||||
// Initialisation par défaut
|
||||
if (adhesion.getDateDemande() == null) {
|
||||
adhesion.setDateDemande(LocalDate.now());
|
||||
}
|
||||
if (adhesion.getStatut() == null || adhesion.getStatut().isEmpty()) {
|
||||
adhesion.setStatut("EN_ATTENTE");
|
||||
}
|
||||
if (adhesion.getMontantPaye() == null) {
|
||||
adhesion.setMontantPaye(BigDecimal.ZERO);
|
||||
}
|
||||
if (adhesion.getCodeDevise() == null || adhesion.getCodeDevise().isEmpty()) {
|
||||
adhesion.setCodeDevise("XOF");
|
||||
}
|
||||
|
||||
// Persistance
|
||||
adhesionRepository.persist(adhesion);
|
||||
|
||||
log.info(
|
||||
@@ -168,392 +109,259 @@ public class AdhesionService {
|
||||
return convertToDTO(adhesion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour une adhésion existante
|
||||
*
|
||||
* @param id identifiant UUID de l'adhésion
|
||||
* @param adhesionDTO nouvelles données
|
||||
* @return DTO de l'adhésion mise à jour
|
||||
*/
|
||||
@Transactional
|
||||
public AdhesionDTO updateAdhesion(@NotNull UUID id, @Valid AdhesionDTO adhesionDTO) {
|
||||
public AdhesionResponse updateAdhesion(@NotNull UUID id, @Valid UpdateAdhesionRequest request) {
|
||||
log.info("Mise à jour de l'adhésion avec ID: {}", id);
|
||||
|
||||
Adhesion adhesionExistante =
|
||||
adhesionRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Adhésion non trouvée avec l'ID: " + id));
|
||||
|
||||
// Mise à jour des champs modifiables
|
||||
updateAdhesionFields(adhesionExistante, adhesionDTO);
|
||||
|
||||
DemandeAdhesion adhesionExistante = adhesionRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Adhésion non trouvée avec l'ID: " + id));
|
||||
updateAdhesionFields(adhesionExistante, request);
|
||||
log.info("Adhésion mise à jour avec succès - ID: {}", id);
|
||||
|
||||
return convertToDTO(adhesionExistante);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime (désactive) une adhésion
|
||||
*
|
||||
* @param id identifiant UUID de l'adhésion
|
||||
*/
|
||||
@Transactional
|
||||
public void deleteAdhesion(@NotNull UUID id) {
|
||||
log.info("Suppression de l'adhésion avec ID: {}", id);
|
||||
DemandeAdhesion adhesion = adhesionRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Adhésion non trouvée avec l'ID: " + id));
|
||||
|
||||
Adhesion adhesion =
|
||||
adhesionRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Adhésion non trouvée avec l'ID: " + id));
|
||||
|
||||
// Vérification si l'adhésion peut être supprimée
|
||||
if ("PAYEE".equals(adhesion.getStatut())) {
|
||||
throw new IllegalStateException("Impossible de supprimer une adhésion déjà payée");
|
||||
if ("APPROUVEE".equals(adhesion.getStatut()) && adhesion.isPayeeIntegralement()) {
|
||||
throw new IllegalStateException("Impossible de supprimer une adhésion déjà payée intégralement");
|
||||
}
|
||||
|
||||
adhesion.setStatut("ANNULEE");
|
||||
|
||||
log.info("Adhésion supprimée avec succès - ID: {}", id);
|
||||
log.info("Adhésion annulée avec succès - ID: {}", id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Approuve une adhésion
|
||||
*
|
||||
* @param id identifiant UUID de l'adhésion
|
||||
* @param approuvePar nom de l'utilisateur qui approuve
|
||||
* @return DTO de l'adhésion approuvée
|
||||
*/
|
||||
@Transactional
|
||||
public AdhesionDTO approuverAdhesion(@NotNull UUID id, String approuvePar) {
|
||||
public AdhesionResponse approuverAdhesion(@NotNull UUID id, String approuvePar) {
|
||||
log.info("Approbation de l'adhésion avec ID: {}", id);
|
||||
DemandeAdhesion adhesion = adhesionRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Adhésion non trouvée avec l'ID: " + id));
|
||||
|
||||
Adhesion adhesion =
|
||||
adhesionRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Adhésion non trouvée avec l'ID: " + id));
|
||||
|
||||
if (!"EN_ATTENTE".equals(adhesion.getStatut())) {
|
||||
throw new IllegalStateException(
|
||||
"Seules les adhésions en attente peuvent être approuvées");
|
||||
if (!adhesion.isEnAttente()) {
|
||||
throw new IllegalStateException("Seules les adhésions en attente peuvent être approuvées");
|
||||
}
|
||||
|
||||
adhesion.setStatut("APPROUVEE");
|
||||
adhesion.setDateApprobation(LocalDate.now());
|
||||
adhesion.setApprouvePar(approuvePar);
|
||||
adhesion.setDateValidation(LocalDate.now());
|
||||
adhesion.setDateTraitement(LocalDateTime.now());
|
||||
adhesion.setObservations(
|
||||
approuvePar != null ? "Approuvée par : " + approuvePar : adhesion.getObservations());
|
||||
|
||||
// Activer le compte membre et provisionner son accès Keycloak
|
||||
Membre membre = adhesion.getUtilisateur();
|
||||
if (membre != null) {
|
||||
membre.setStatutCompte("ACTIF");
|
||||
membre.setActif(true);
|
||||
try {
|
||||
keycloakSyncService.provisionKeycloakUser(membre.getId());
|
||||
log.info("Compte Keycloak provisionné pour le membre: {}", membre.getEmail());
|
||||
} catch (Exception e) {
|
||||
log.warn("Provisionnement Keycloak non bloquant pour {} : {}", membre.getEmail(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Adhésion approuvée avec succès - ID: {}", id);
|
||||
|
||||
return convertToDTO(adhesion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rejette une adhésion
|
||||
*
|
||||
* @param id identifiant UUID de l'adhésion
|
||||
* @param motifRejet motif du rejet
|
||||
* @return DTO de l'adhésion rejetée
|
||||
*/
|
||||
@Transactional
|
||||
public AdhesionDTO rejeterAdhesion(@NotNull UUID id, String motifRejet) {
|
||||
public AdhesionResponse rejeterAdhesion(@NotNull UUID id, String motifRejet) {
|
||||
log.info("Rejet de l'adhésion avec ID: {}", id);
|
||||
DemandeAdhesion adhesion = adhesionRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Adhésion non trouvée avec l'ID: " + id));
|
||||
|
||||
Adhesion adhesion =
|
||||
adhesionRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Adhésion non trouvée avec l'ID: " + id));
|
||||
|
||||
if (!"EN_ATTENTE".equals(adhesion.getStatut())) {
|
||||
if (!adhesion.isEnAttente()) {
|
||||
throw new IllegalStateException("Seules les adhésions en attente peuvent être rejetées");
|
||||
}
|
||||
|
||||
adhesion.setStatut("REJETEE");
|
||||
adhesion.setMotifRejet(motifRejet);
|
||||
adhesion.setDateTraitement(LocalDateTime.now());
|
||||
|
||||
// Désactiver le compte membre
|
||||
Membre membre = adhesion.getUtilisateur();
|
||||
if (membre != null) {
|
||||
membre.setStatutCompte("DESACTIVE");
|
||||
membre.setActif(false);
|
||||
}
|
||||
|
||||
log.info("Adhésion rejetée avec succès - ID: {}", id);
|
||||
|
||||
return convertToDTO(adhesion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enregistre un paiement pour une adhésion
|
||||
*
|
||||
* @param id identifiant UUID de l'adhésion
|
||||
* @param montantPaye montant payé
|
||||
* @param methodePaiement méthode de paiement
|
||||
* @param referencePaiement référence du paiement
|
||||
* @return DTO de l'adhésion mise à jour
|
||||
*/
|
||||
@Transactional
|
||||
public AdhesionDTO enregistrerPaiement(
|
||||
public AdhesionResponse enregistrerPaiement(
|
||||
@NotNull UUID id,
|
||||
BigDecimal montantPaye,
|
||||
String methodePaiement,
|
||||
String referencePaiement) {
|
||||
log.info("Enregistrement du paiement pour l'adhésion avec ID: {}", id);
|
||||
|
||||
Adhesion adhesion =
|
||||
adhesionRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Adhésion non trouvée avec l'ID: " + id));
|
||||
DemandeAdhesion adhesion = adhesionRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Adhésion non trouvée avec l'ID: " + id));
|
||||
|
||||
if (!"APPROUVEE".equals(adhesion.getStatut()) && !"EN_PAIEMENT".equals(adhesion.getStatut())) {
|
||||
throw new IllegalStateException(
|
||||
"Seules les adhésions approuvées peuvent recevoir un paiement");
|
||||
"Seules les adhésions approuvées peuvent receive un paiement");
|
||||
}
|
||||
|
||||
BigDecimal nouveauMontantPaye =
|
||||
adhesion.getMontantPaye() != null
|
||||
? adhesion.getMontantPaye().add(montantPaye)
|
||||
: montantPaye;
|
||||
BigDecimal nouveauMontant = adhesion.getMontantPaye() != null
|
||||
? adhesion.getMontantPaye().add(montantPaye)
|
||||
: montantPaye;
|
||||
adhesion.setMontantPaye(nouveauMontant);
|
||||
|
||||
adhesion.setMontantPaye(nouveauMontantPaye);
|
||||
adhesion.setMethodePaiement(methodePaiement);
|
||||
adhesion.setReferencePaiement(referencePaiement);
|
||||
adhesion.setDatePaiement(java.time.LocalDateTime.now());
|
||||
|
||||
// Mise à jour du statut si payée intégralement
|
||||
if (adhesion.isPayeeIntegralement()) {
|
||||
adhesion.setStatut("PAYEE");
|
||||
} else {
|
||||
adhesion.setStatut("EN_PAIEMENT");
|
||||
adhesion.setStatut("APPROUVEE");
|
||||
}
|
||||
|
||||
log.info("Paiement enregistré avec succès pour l'adhésion - ID: {}", id);
|
||||
|
||||
return convertToDTO(adhesion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les adhésions d'un membre
|
||||
*
|
||||
* @param membreId identifiant UUID du membre
|
||||
* @param page numéro de page
|
||||
* @param size taille de la page
|
||||
* @return liste des adhésions du membre
|
||||
*/
|
||||
public List<AdhesionDTO> getAdhesionsByMembre(@NotNull UUID membreId, int page, int size) {
|
||||
public List<AdhesionResponse> getAdhesionsByMembre(@NotNull UUID membreId, int page, int size) {
|
||||
log.debug("Récupération des adhésions du membre: {}", membreId);
|
||||
|
||||
if (!membreRepository.findByIdOptional(membreId).isPresent()) {
|
||||
throw new NotFoundException("Membre non trouvé avec l'ID: " + membreId);
|
||||
}
|
||||
|
||||
List<Adhesion> adhesions =
|
||||
adhesionRepository.findByMembreId(membreId).stream()
|
||||
.skip(page * size)
|
||||
.limit(size)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return adhesions.stream().map(this::convertToDTO).collect(Collectors.toList());
|
||||
return adhesionRepository.findByMembreId(membreId).stream()
|
||||
.skip((long) page * size)
|
||||
.limit(size)
|
||||
.map(this::convertToDTO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les adhésions d'une organisation
|
||||
*
|
||||
* @param organisationId identifiant UUID de l'organisation
|
||||
* @param page numéro de page
|
||||
* @param size taille de la page
|
||||
* @return liste des adhésions de l'organisation
|
||||
*/
|
||||
public List<AdhesionDTO> getAdhesionsByOrganisation(
|
||||
public List<AdhesionResponse> getAdhesionsByOrganisation(
|
||||
@NotNull UUID organisationId, int page, int size) {
|
||||
log.debug("Récupération des adhésions de l'organisation: {}", organisationId);
|
||||
|
||||
if (!organisationRepository.findByIdOptional(organisationId).isPresent()) {
|
||||
throw new NotFoundException("Organisation non trouvée avec l'ID: " + organisationId);
|
||||
}
|
||||
|
||||
List<Adhesion> adhesions =
|
||||
adhesionRepository.findByOrganisationId(organisationId).stream()
|
||||
.skip(page * size)
|
||||
.limit(size)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return adhesions.stream().map(this::convertToDTO).collect(Collectors.toList());
|
||||
return adhesionRepository.findByOrganisationId(organisationId).stream()
|
||||
.skip((long) page * size)
|
||||
.limit(size)
|
||||
.map(this::convertToDTO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les adhésions par statut
|
||||
*
|
||||
* @param statut statut recherché
|
||||
* @param page numéro de page
|
||||
* @param size taille de la page
|
||||
* @return liste des adhésions avec le statut spécifié
|
||||
*/
|
||||
public List<AdhesionDTO> getAdhesionsByStatut(@NotNull String statut, int page, int size) {
|
||||
public List<AdhesionResponse> getAdhesionsByStatut(@NotNull String statut, int page, int size) {
|
||||
log.debug("Récupération des adhésions avec statut: {}", statut);
|
||||
|
||||
List<Adhesion> adhesions =
|
||||
adhesionRepository.findByStatut(statut).stream()
|
||||
.skip(page * size)
|
||||
.limit(size)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return adhesions.stream().map(this::convertToDTO).collect(Collectors.toList());
|
||||
return adhesionRepository.findByStatut(statut).stream()
|
||||
.skip((long) page * size)
|
||||
.limit(size)
|
||||
.map(this::convertToDTO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les adhésions en attente
|
||||
*
|
||||
* @param page numéro de page
|
||||
* @param size taille de la page
|
||||
* @return liste des adhésions en attente
|
||||
*/
|
||||
public List<AdhesionDTO> getAdhesionsEnAttente(int page, int size) {
|
||||
public List<AdhesionResponse> getAdhesionsEnAttente(int page, int size) {
|
||||
log.debug("Récupération des adhésions en attente");
|
||||
|
||||
List<Adhesion> adhesions =
|
||||
adhesionRepository.findEnAttente().stream()
|
||||
.skip(page * size)
|
||||
.limit(size)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return adhesions.stream().map(this::convertToDTO).collect(Collectors.toList());
|
||||
return adhesionRepository.findEnAttente().stream()
|
||||
.skip((long) page * size)
|
||||
.limit(size)
|
||||
.map(this::convertToDTO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les statistiques des adhésions
|
||||
*
|
||||
* @return map contenant les statistiques
|
||||
*/
|
||||
public Map<String, Object> getStatistiquesAdhesions() {
|
||||
log.debug("Calcul des statistiques des adhésions");
|
||||
|
||||
long totalAdhesions = adhesionRepository.count();
|
||||
long adhesionsApprouvees = adhesionRepository.findByStatut("APPROUVEE").size();
|
||||
long adhesionsEnAttente = adhesionRepository.findEnAttente().size();
|
||||
long adhesionsPayees = adhesionRepository.findByStatut("PAYEE").size();
|
||||
long total = adhesionRepository.count();
|
||||
long approuvees = adhesionRepository.findByStatut("APPROUVEE").size();
|
||||
long enAttente = adhesionRepository.findEnAttente().size();
|
||||
long rejetees = adhesionRepository.findByStatut("REJETEE").size();
|
||||
|
||||
return Map.of(
|
||||
"totalAdhesions", totalAdhesions,
|
||||
"adhesionsApprouvees", adhesionsApprouvees,
|
||||
"adhesionsEnAttente", adhesionsEnAttente,
|
||||
"adhesionsPayees", adhesionsPayees,
|
||||
"tauxApprobation",
|
||||
totalAdhesions > 0 ? (adhesionsApprouvees * 100.0 / totalAdhesions) : 0.0,
|
||||
"tauxPaiement",
|
||||
adhesionsApprouvees > 0
|
||||
? (adhesionsPayees * 100.0 / adhesionsApprouvees)
|
||||
: 0.0);
|
||||
"totalAdhesions", total,
|
||||
"adhesionsApprouvees", approuvees,
|
||||
"adhesionsEnAttente", enAttente,
|
||||
"adhesionsRejetees", rejetees,
|
||||
"tauxApprobation", total > 0 ? (approuvees * 100.0 / total) : 0.0,
|
||||
"tauxRejet", total > 0 ? (rejetees * 100.0 / total) : 0.0);
|
||||
}
|
||||
|
||||
/** Génère un numéro de référence unique pour une adhésion */
|
||||
private String genererNumeroReference() {
|
||||
return "ADH-" + System.currentTimeMillis() + "-" + UUID.randomUUID().toString().substring(0, 8).toUpperCase();
|
||||
}
|
||||
|
||||
/** Convertit une entité Adhesion en DTO */
|
||||
private AdhesionDTO convertToDTO(Adhesion adhesion) {
|
||||
if (adhesion == null) {
|
||||
private AdhesionResponse convertToDTO(DemandeAdhesion adhesion) {
|
||||
if (adhesion == null)
|
||||
return null;
|
||||
|
||||
AdhesionResponse response = new AdhesionResponse();
|
||||
response.setId(adhesion.getId());
|
||||
response.setNumeroReference(adhesion.getNumeroReference());
|
||||
|
||||
if (adhesion.getUtilisateur() != null) {
|
||||
response.setMembreId(adhesion.getUtilisateur().getId());
|
||||
response.setNomMembre(adhesion.getUtilisateur().getNomComplet());
|
||||
response.setNumeroMembre(adhesion.getUtilisateur().getNumeroMembre());
|
||||
response.setEmailMembre(adhesion.getUtilisateur().getEmail());
|
||||
}
|
||||
|
||||
AdhesionDTO dto = new AdhesionDTO();
|
||||
|
||||
dto.setId(adhesion.getId());
|
||||
dto.setNumeroReference(adhesion.getNumeroReference());
|
||||
|
||||
// Conversion du membre associé
|
||||
if (adhesion.getMembre() != null) {
|
||||
dto.setMembreId(adhesion.getMembre().getId());
|
||||
dto.setNomMembre(adhesion.getMembre().getNomComplet());
|
||||
dto.setNumeroMembre(adhesion.getMembre().getNumeroMembre());
|
||||
dto.setEmailMembre(adhesion.getMembre().getEmail());
|
||||
}
|
||||
|
||||
// Conversion de l'organisation
|
||||
if (adhesion.getOrganisation() != null) {
|
||||
dto.setOrganisationId(adhesion.getOrganisation().getId());
|
||||
dto.setNomOrganisation(adhesion.getOrganisation().getNom());
|
||||
response.setOrganisationId(adhesion.getOrganisation().getId());
|
||||
response.setNomOrganisation(adhesion.getOrganisation().getNom());
|
||||
}
|
||||
|
||||
// Propriétés de l'adhésion
|
||||
dto.setDateDemande(adhesion.getDateDemande());
|
||||
dto.setFraisAdhesion(adhesion.getFraisAdhesion());
|
||||
dto.setMontantPaye(adhesion.getMontantPaye());
|
||||
dto.setCodeDevise(adhesion.getCodeDevise());
|
||||
dto.setStatut(adhesion.getStatut());
|
||||
dto.setDateApprobation(adhesion.getDateApprobation());
|
||||
dto.setDatePaiement(adhesion.getDatePaiement());
|
||||
dto.setMethodePaiement(adhesion.getMethodePaiement());
|
||||
dto.setReferencePaiement(adhesion.getReferencePaiement());
|
||||
dto.setMotifRejet(adhesion.getMotifRejet());
|
||||
dto.setObservations(adhesion.getObservations());
|
||||
dto.setApprouvePar(adhesion.getApprouvePar());
|
||||
dto.setDateValidation(adhesion.getDateValidation());
|
||||
response.setDateDemande(
|
||||
adhesion.getDateDemande() != null ? adhesion.getDateDemande().toLocalDate() : null);
|
||||
response.setFraisAdhesion(adhesion.getFraisAdhesion());
|
||||
response.setMontantPaye(adhesion.getMontantPaye());
|
||||
response.setCodeDevise(adhesion.getCodeDevise());
|
||||
response.setStatut(adhesion.getStatut());
|
||||
response.setMotifRejet(adhesion.getMotifRejet());
|
||||
response.setObservations(adhesion.getObservations());
|
||||
|
||||
// Métadonnées de BaseEntity
|
||||
dto.setDateCreation(adhesion.getDateCreation());
|
||||
dto.setDateModification(adhesion.getDateModification());
|
||||
dto.setCreePar(adhesion.getCreePar());
|
||||
dto.setModifiePar(adhesion.getModifiePar());
|
||||
dto.setActif(adhesion.getActif());
|
||||
if (adhesion.getDateTraitement() != null) {
|
||||
response.setDateApprobation(adhesion.getDateTraitement().toLocalDate());
|
||||
}
|
||||
if (adhesion.getTraitePar() != null) {
|
||||
response.setApprouvePar(adhesion.getTraitePar().getNomComplet());
|
||||
}
|
||||
|
||||
return dto;
|
||||
response.setDateCreation(adhesion.getDateCreation());
|
||||
response.setDateModification(adhesion.getDateModification());
|
||||
response.setCreePar(adhesion.getCreePar());
|
||||
response.setModifiePar(adhesion.getModifiePar());
|
||||
response.setActif(adhesion.getActif());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/** Convertit un DTO en entité Adhesion */
|
||||
private Adhesion convertToEntity(AdhesionDTO dto) {
|
||||
if (dto == null) {
|
||||
private DemandeAdhesion convertToEntity(CreateAdhesionRequest request) {
|
||||
if (request == null)
|
||||
return null;
|
||||
}
|
||||
|
||||
Adhesion adhesion = new Adhesion();
|
||||
|
||||
adhesion.setNumeroReference(dto.getNumeroReference());
|
||||
adhesion.setDateDemande(dto.getDateDemande());
|
||||
adhesion.setFraisAdhesion(dto.getFraisAdhesion());
|
||||
adhesion.setMontantPaye(dto.getMontantPaye() != null ? dto.getMontantPaye() : BigDecimal.ZERO);
|
||||
adhesion.setCodeDevise(dto.getCodeDevise());
|
||||
adhesion.setStatut(dto.getStatut());
|
||||
adhesion.setDateApprobation(dto.getDateApprobation());
|
||||
adhesion.setDatePaiement(dto.getDatePaiement());
|
||||
adhesion.setMethodePaiement(dto.getMethodePaiement());
|
||||
adhesion.setReferencePaiement(dto.getReferencePaiement());
|
||||
adhesion.setMotifRejet(dto.getMotifRejet());
|
||||
adhesion.setObservations(dto.getObservations());
|
||||
adhesion.setApprouvePar(dto.getApprouvePar());
|
||||
adhesion.setDateValidation(dto.getDateValidation());
|
||||
|
||||
return adhesion;
|
||||
return DemandeAdhesion.builder()
|
||||
.numeroReference(
|
||||
request.numeroReference() != null
|
||||
? request.numeroReference()
|
||||
: DemandeAdhesion.genererNumeroReference())
|
||||
.dateDemande(
|
||||
request.dateDemande() != null
|
||||
? request.dateDemande().atStartOfDay()
|
||||
: LocalDateTime.now())
|
||||
.fraisAdhesion(request.fraisAdhesion() != null ? request.fraisAdhesion() : BigDecimal.ZERO)
|
||||
.montantPaye(BigDecimal.ZERO)
|
||||
.codeDevise(request.codeDevise() != null ? request.codeDevise() : defaultsService.getDevise())
|
||||
.statut("EN_ATTENTE")
|
||||
.observations(request.observations())
|
||||
.build();
|
||||
}
|
||||
|
||||
/** Met à jour les champs modifiables d'une adhésion existante */
|
||||
private void updateAdhesionFields(Adhesion adhesion, AdhesionDTO dto) {
|
||||
if (dto.getFraisAdhesion() != null) {
|
||||
adhesion.setFraisAdhesion(dto.getFraisAdhesion());
|
||||
private void updateAdhesionFields(DemandeAdhesion adhesion, UpdateAdhesionRequest request) {
|
||||
if (request.statut() != null)
|
||||
adhesion.setStatut(request.statut());
|
||||
if (request.montantPaye() != null)
|
||||
adhesion.setMontantPaye(request.montantPaye());
|
||||
if (request.motifRejet() != null)
|
||||
adhesion.setMotifRejet(request.motifRejet());
|
||||
if (request.observations() != null)
|
||||
adhesion.setObservations(request.observations());
|
||||
if (request.dateApprobation() != null) {
|
||||
adhesion.setDateTraitement(request.dateApprobation().atStartOfDay());
|
||||
}
|
||||
if (dto.getMontantPaye() != null) {
|
||||
adhesion.setMontantPaye(dto.getMontantPaye());
|
||||
}
|
||||
if (dto.getStatut() != null) {
|
||||
adhesion.setStatut(dto.getStatut());
|
||||
}
|
||||
if (dto.getDateApprobation() != null) {
|
||||
adhesion.setDateApprobation(dto.getDateApprobation());
|
||||
}
|
||||
if (dto.getDatePaiement() != null) {
|
||||
adhesion.setDatePaiement(dto.getDatePaiement());
|
||||
}
|
||||
if (dto.getMethodePaiement() != null) {
|
||||
adhesion.setMethodePaiement(dto.getMethodePaiement());
|
||||
}
|
||||
if (dto.getReferencePaiement() != null) {
|
||||
adhesion.setReferencePaiement(dto.getReferencePaiement());
|
||||
}
|
||||
if (dto.getMotifRejet() != null) {
|
||||
adhesion.setMotifRejet(dto.getMotifRejet());
|
||||
}
|
||||
if (dto.getObservations() != null) {
|
||||
adhesion.setObservations(dto.getObservations());
|
||||
}
|
||||
if (dto.getApprouvePar() != null) {
|
||||
adhesion.setApprouvePar(dto.getApprouvePar());
|
||||
}
|
||||
if (dto.getDateValidation() != null) {
|
||||
adhesion.setDateValidation(dto.getDateValidation());
|
||||
if (request.dateValidation() != null) {
|
||||
// Logic for validation date if needed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user