From f85191b47caf75970ecbe82387c7f9211db4c4bd Mon Sep 17 00:00:00 2001 From: Aurince AKAKPO Date: Tue, 10 Feb 2026 00:26:14 +0100 Subject: [PATCH] gestion revu de code en utilisant uniquement les DTO --- .../rfu/metier/BatimentController.java | 47 +++++ .../entities/rfu/metier/EnqueteBatiment.java | 4 + .../infocad/metier/ParcelleServiceImpl.java | 4 + .../rfu/metier/BatimentServiceImpl.java | 22 ++- .../rfu/metier/BatimentService.java | 10 +- .../request/crudweb/BatimentPaylaodWeb.java | 25 ++- .../rfu/metier/BatimentRepository.java | 175 ++++++++++++++++++ src/main/resources/application.properties | 13 +- 8 files changed, 288 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/BatimentController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/BatimentController.java index 32ccc47..b6da166 100644 --- a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/BatimentController.java +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/BatimentController.java @@ -154,6 +154,53 @@ public class BatimentController { } } + @GetMapping("/all/by-parcelle-id/{parcelleId}") + public ResponseEntity getAllBatimentByParcelleList(@PathVariable Long parcelleId) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, batimentService.getBatimentListByParcelle(parcelleId), "Liste des caractéristiques chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } + + @GetMapping("/all-paged/by-parcelle-id/{parcelleId}") + public ResponseEntity getAllBatimentByParcellePaged(@PathVariable Long parcelleId, @RequestParam int pageNo, @RequestParam int pageSize) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, batimentService.getBatimentListByParcellePageable(parcelleId,pageable), "Liste des caractéristiques chargée avec succès."), + HttpStatus.OK + ); + } catch (HttpClientErrorException.MethodNotAllowed e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); + } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | + FileStorageException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); + } catch (NullPointerException e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); + } + } + @GetMapping("/id/{id}") public ResponseEntity getBatimentById(@PathVariable Long id) { try { diff --git a/src/main/java/io/gmss/fiscad/entities/rfu/metier/EnqueteBatiment.java b/src/main/java/io/gmss/fiscad/entities/rfu/metier/EnqueteBatiment.java index 23a0128..9f0815f 100644 --- a/src/main/java/io/gmss/fiscad/entities/rfu/metier/EnqueteBatiment.java +++ b/src/main/java/io/gmss/fiscad/entities/rfu/metier/EnqueteBatiment.java @@ -67,6 +67,10 @@ public class EnqueteBatiment extends BaseEntity implements Serializable { @JsonDeserialize(using = LocalDateDeserializer.class) private LocalDate dateFinExcemption; + @JsonFormat(pattern = "dd-MM-yyyy") + @JsonDeserialize(using = LocalDateDeserializer.class) + private LocalDate dateEnquete; + //@JsonIgnore @ManyToOne private Personne personne; diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ParcelleServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ParcelleServiceImpl.java index 6efa000..833aa7f 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ParcelleServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ParcelleServiceImpl.java @@ -156,7 +156,11 @@ public class ParcelleServiceImpl implements ParcelleService { @Override public Page getParcelleListByRuePageableToDto(Long userId, Long rueId, Pageable pageable) { List secteurIds = getSecteurIdListForUser(userId); + System.out.println(rueId); + secteurIds.forEach(aLong -> { + System.out.println(aLong); + }); return parcelleRepository.findAllParcelleByRueToDtoPageable(rueId,secteurIds,pageable); } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/BatimentServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/BatimentServiceImpl.java index 36b8ae4..21b58cd 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/BatimentServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/BatimentServiceImpl.java @@ -56,20 +56,30 @@ public class BatimentServiceImpl implements BatimentService { } @Override - public Page getBatimentList(Pageable pageable) { - return batimentRepository.findAll(pageable); + public Page getBatimentList(Pageable pageable) { + return batimentRepository.findAllBatimentsAvecOccupantCourantToDtoPageble(pageable); } @Override - public List getBatimentList() { - return batimentRepository.findAll(); + public List getBatimentList() { + return batimentRepository.findAllBatimentsAvecOccupantCourantToDto(); + } + + @Override + public Page getBatimentListByParcellePageable(Long parcelleId, Pageable pageable) { + return batimentRepository.findAllBatimentsAvecOccupantCourantByParcelleToDtoPageble(parcelleId,pageable); + } + + @Override + public List getBatimentListByParcelle(Long parcelleId) { + return batimentRepository.findAllBatimentsAvecOccupantCourantByParcelleToDto(parcelleId); } @Override - public Optional getBatimentById(Long id) { + public Optional getBatimentById(Long id) { if (batimentRepository.existsById(id)) { - return batimentRepository.findById(id); + return batimentRepository.findBatimentAvecOccupantCourantToDto(id); } else { throw new NotFoundException("Impossible de trouver la caractéristique spécifiée dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/BatimentService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/BatimentService.java index 422528f..db0a93b 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/BatimentService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/BatimentService.java @@ -18,9 +18,13 @@ public interface BatimentService { void deleteBatiment(Long id) throws NotFoundException; - Page getBatimentList(Pageable pageable); + Page getBatimentList(Pageable pageable); - List getBatimentList(); + List getBatimentList(); - Optional getBatimentById(Long id); + Page getBatimentListByParcellePageable(Long parcelleId, Pageable pageable); + + List getBatimentListByParcelle(Long parcelleId); + + Optional getBatimentById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/BatimentPaylaodWeb.java b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/BatimentPaylaodWeb.java index ab9f71d..79e3a9e 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/BatimentPaylaodWeb.java +++ b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/BatimentPaylaodWeb.java @@ -11,5 +11,28 @@ public class BatimentPaylaodWeb { private String code; private LocalDate dateConstruction; private Long parcelleId; - private String observation; + private String parcelleNup; + private String parcelleQ; + private String parcelleI; + private String parcelleP; + private Long personneId; + private String personneNom; + private String personnePrenom; + private String personneRaisonSociale; + + public BatimentPaylaodWeb(Long id, String nub, String code, LocalDate dateConstruction, Long parcelleId, String parcelleNup, String parcelleQ, String parcelleI, String parcelleP, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale) { + this.id = id; + this.nub = nub; + this.code = code; + this.dateConstruction = dateConstruction; + this.parcelleId = parcelleId; + this.parcelleNup = parcelleNup; + this.parcelleQ = parcelleQ; + this.parcelleI = parcelleI; + this.parcelleP = parcelleP; + this.personneId = personneId; + this.personneNom = personneNom; + this.personnePrenom = personnePrenom; + this.personneRaisonSociale = personneRaisonSociale; + } } diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/metier/BatimentRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/metier/BatimentRepository.java index a32bf1e..edb2f78 100755 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/metier/BatimentRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/metier/BatimentRepository.java @@ -1,9 +1,13 @@ package io.gmss.fiscad.persistence.repositories.rfu.metier; import io.gmss.fiscad.entities.rfu.metier.Batiment; +import io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb; import io.gmss.fiscad.paylaods.response.restoration.BatimentPayloadRestor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import java.util.List; import java.util.Optional; @@ -29,4 +33,175 @@ public interface BatimentRepository extends JpaRepository { Long countByParcelle_Quartier_CodeLike(String codeQuartier); + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb( + b.id, + b.nub, + b.code, + b.dateConstruction, + p.id, + p.nup, + p.q, + p.i, + p.p, + per.id, + per.nom, + per.prenom, + per.raisonSociale + ) + FROM Batiment b + JOIN b.parcelle p + LEFT JOIN EnqueteBatiment eb + ON eb.batiment = b + AND eb.dateEnquete = ( + SELECT MAX(eb2.dateEnquete) + FROM EnqueteBatiment eb2 + WHERE eb2.batiment = b + ) + LEFT JOIN eb.personne per + WHERE b.id = :batimentId + """) + Optional findBatimentAvecOccupantCourantToDto(@Param("batimentId") Long batimentId); + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb( + b.id, + b.nub, + b.code, + b.dateConstruction, + p.id, + p.nup, + p.q, + p.i, + p.p, + per.id, + per.nom, + per.prenom, + per.raisonSociale + ) + FROM Batiment b + JOIN b.parcelle p + LEFT JOIN EnqueteBatiment eb + ON eb.batiment = b + AND eb.dateEnquete = ( + SELECT MAX(eb2.dateEnquete) + FROM EnqueteBatiment eb2 + WHERE eb2.batiment = b + ) + LEFT JOIN eb.personne per + """) + List findAllBatimentsAvecOccupantCourantToDto(); + + + @Query( + value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb( + b.id, + b.nub, + b.code, + b.dateConstruction, + p.id, + p.nup, + p.q, + p.i, + p.p, + per.id, + per.nom, + per.prenom, + per.raisonSociale + ) + FROM Batiment b + JOIN b.parcelle p + LEFT JOIN EnqueteBatiment eb + ON eb.batiment = b + AND eb.dateEnquete = ( + SELECT MAX(eb2.dateEnquete) + FROM EnqueteBatiment eb2 + WHERE eb2.batiment = b + ) + LEFT JOIN eb.personne per + """, + countQuery = """ + SELECT COUNT(b) + FROM Batiment b + """ + ) + Page findAllBatimentsAvecOccupantCourantToDtoPageble(Pageable pageable); + + + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb( + b.id, + b.nub, + b.code, + b.dateConstruction, + p.id, + p.nup, + p.q, + p.i, + p.p, + per.id, + per.nom, + per.prenom, + per.raisonSociale + ) + FROM Batiment b + JOIN b.parcelle p + LEFT JOIN EnqueteBatiment eb + ON eb.batiment = b + AND eb.dateEnquete = ( + SELECT MAX(eb2.dateEnquete) + FROM EnqueteBatiment eb2 + WHERE eb2.batiment = b + ) + LEFT JOIN eb.personne per + WHERE p.id = :parcelleId + """) + List findAllBatimentsAvecOccupantCourantByParcelleToDto( + @Param("parcelleId") Long parcelleId + ); + + + + @Query( + value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb( + b.id, + b.nub, + b.code, + b.dateConstruction, + p.id, + p.nup, + p.q, + p.i, + p.p, + per.id, + per.nom, + per.prenom, + per.raisonSociale + ) + FROM Batiment b + JOIN b.parcelle p + LEFT JOIN EnqueteBatiment eb + ON eb.batiment = b + AND eb.dateEnquete = ( + SELECT MAX(eb2.dateEnquete) + FROM EnqueteBatiment eb2 + WHERE eb2.batiment = b + ) + LEFT JOIN eb.personne per + WHERE p.id = :parcelleId + """, + countQuery = """ + SELECT COUNT(b) + FROM Batiment b + WHERE b.parcelle.id = :parcelleId + """ + ) + Page findAllBatimentsAvecOccupantCourantByParcelleToDtoPageble( + @Param("parcelleId") Long parcelleId, + Pageable pageable + ); + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e9d673d..85dff60 100755 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,7 +4,6 @@ spring.profiles.active=${SPRING_PROFILES_ACTIVE} spring.jpa.properties.hibernate.id.new_generator_mappings=false spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true spring.jpa.open-in-view=false -spring.jpa.show-sql=true spring.jpa.hibernate.ddl-auto=update jwt.jwtSecret=ImThEVeryB@dS@lt@302839_ jwt.jwtExpirationInMs=7776000000 @@ -63,4 +62,14 @@ server.tomcat.max-http-form-post-size=200MB # ?? Réduire le bruit des logs 'client aborted' (optionnel) logging.level.org.springframework.web.servlet.mvc.method.annotation=INFO -logging.level.org.apache.catalina.connector.ClientAbortException=ERROR \ No newline at end of file +logging.level.org.apache.catalina.connector.ClientAbortException=ERROR + + +# Affiche les requêtes SQL +#spring.jpa.show-sql=true +# Formate le SQL pour la lisibilité +#spring.jpa.properties.hibernate.format_sql=true + +# Affiche les valeurs des paramètres bindés (Hibernate 5.4+) +#logging.level.org.hibernate.SQL=DEBUG +#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE \ No newline at end of file -- 2.49.1