gestion revu de code en utilisant uniquement les DTO
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 27s

This commit is contained in:
2026-02-14 15:07:50 +01:00
parent 8031289509
commit 8efe46fea8
8 changed files with 254 additions and 26 deletions

View File

@@ -6,6 +6,7 @@ import io.gmss.fiscad.exceptions.*;
import io.gmss.fiscad.interfaces.infocad.metier.EnqueteService; import io.gmss.fiscad.interfaces.infocad.metier.EnqueteService;
import io.gmss.fiscad.interfaces.infocad.metier.ParcelleService; import io.gmss.fiscad.interfaces.infocad.metier.ParcelleService;
import io.gmss.fiscad.paylaods.ApiResponse; import io.gmss.fiscad.paylaods.ApiResponse;
import io.gmss.fiscad.paylaods.FiltreParcelle;
import io.gmss.fiscad.paylaods.request.EnqueteTraitementPayLoad; import io.gmss.fiscad.paylaods.request.EnqueteTraitementPayLoad;
import io.gmss.fiscad.paylaods.request.FiltreEnquetePayLoad; import io.gmss.fiscad.paylaods.request.FiltreEnquetePayLoad;
import io.gmss.fiscad.paylaods.request.crudweb.EnquetePayLoadWeb; import io.gmss.fiscad.paylaods.request.crudweb.EnquetePayLoadWeb;
@@ -30,7 +31,7 @@ import java.util.List;
@RestController @RestController
@RequestMapping(value = "api/parcelle", produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "api/parcelle", produces = MediaType.APPLICATION_JSON_VALUE)
@SecurityRequirement(name = "bearer") //@SecurityRequirement(name = "bearer")
@Tag(name = "Parcelle") @Tag(name = "Parcelle")
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
//@PreAuthorize("hasRole('ADMIN') or hasRole('SUPERVISEUR') or hasRole('ENQUETEUR')") //@PreAuthorize("hasRole('ADMIN') or hasRole('SUPERVISEUR') or hasRole('ENQUETEUR')")
@@ -90,6 +91,7 @@ public class ParcelleController {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
} }
@@ -230,6 +232,39 @@ public class ParcelleController {
} }
} }
@PostMapping("/all-paged/multi-criteres")
public ResponseEntity<?> getAllParcelleFiltrePaged(@CurrentUser UserPrincipal currentUser, @RequestParam int pageNo, @RequestParam int pageSize, @RequestBody FiltreParcelle filtreParcelle) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
if(currentUser==null)
return new ResponseEntity<>(
new ApiResponse<>(true,null, "Vous ne pouvez pas accéder à cette ressource"),
HttpStatus.OK
);
Long userId = currentUser.getUser().getId();
return new ResponseEntity<>(
new ApiResponse<>(true, parcelleService.getParcelleByMultiFiltre(userId,filtreParcelle,pageable), "Liste des enquetes 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) {
e.printStackTrace();
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/by-quartier-id/{quartierId}") @GetMapping("/all/by-quartier-id/{quartierId}")
public ResponseEntity<?> getAllParcelleByQuartier(@CurrentUser UserPrincipal currentUser,@PathVariable Long quartierId) { public ResponseEntity<?> getAllParcelleByQuartier(@CurrentUser UserPrincipal currentUser,@PathVariable Long quartierId) {
try { try {

View File

@@ -10,6 +10,7 @@ import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.decoupage.SecteurService; import io.gmss.fiscad.interfaces.decoupage.SecteurService;
import io.gmss.fiscad.interfaces.infocad.metier.ParcelleService; import io.gmss.fiscad.interfaces.infocad.metier.ParcelleService;
import io.gmss.fiscad.paylaods.FiltreParcelle;
import io.gmss.fiscad.paylaods.request.FiltreParcellePayLoad; import io.gmss.fiscad.paylaods.request.FiltreParcellePayLoad;
import io.gmss.fiscad.paylaods.request.crudweb.ParcellePayLoadWeb; import io.gmss.fiscad.paylaods.request.crudweb.ParcellePayLoadWeb;
import io.gmss.fiscad.paylaods.response.dataTableResponse.ParcelleDataTableResponse; import io.gmss.fiscad.paylaods.response.dataTableResponse.ParcelleDataTableResponse;
@@ -174,12 +175,20 @@ public class ParcelleServiceImpl implements ParcelleService {
} }
} }
@Override
public Page<ParcelleDataTableResponse> getParcelleDataTableListByUserId(Long userId, Pageable pageable) {
List<Long> secteurIds = getSecteurIdListForUser(userId);
Page<ParcelleDataTableResponse> parcelleDataTableResponses=parcelleRepository.getParcelleDataTableResponse(secteurIds,pageable);
return parcelleDataTableResponses ; @Override
public Page<ParcellePayLoadWeb> getParcelleByMultiFiltre(Long userId, FiltreParcelle filtreParcelle, Pageable pageable) {
List<Long> secteurIds = getSecteurIdListForUser(userId);
System.out.println(secteurIds.size());
if (secteurIds == null || secteurIds.isEmpty()) {
throw new IllegalArgumentException("Vous n'êtes pas autorisés à consulter ces parcelles");
}
return parcelleRepository.filtrerParcellesNative(
filtreParcelle,
secteurIds,
pageable
);
} }
private List<Long> getSecteurIdListForUser(Long userId) { private List<Long> getSecteurIdListForUser(Long userId) {
@@ -190,22 +199,8 @@ public class ParcelleServiceImpl implements ParcelleService {
return secteurIds; return secteurIds;
} }
@Override
public Page<ParcelleDataTableResponse> getParcelleDataTableListByMultiFiltre(Long userId, FiltreParcellePayLoad filtreParcellePayLoad, Pageable pageable) {
List<Long> secteurIds = getSecteurIdListForUser(userId);
//
// return parcelleRepository.findAll(
// ParcelleSpecification.filtre(filtreParcellePayLoad, secteurIds),
// pageable
// );
Page<ParcelleDataTableResponse> parcelleDataTableResponses=parcelleRepository.getParcelleDataTableResponse(secteurIds,pageable);
return parcelleDataTableResponses ;
}
private Parcelle getParcelleFromPayload(Parcelle parcelle, ParcellePayLoadWeb parcellePayLoadWeb) { private Parcelle getParcelleFromPayload(Parcelle parcelle, ParcellePayLoadWeb parcellePayLoadWeb) {
if(parcellePayLoadWeb.getRueId()!=null) { if(parcellePayLoadWeb.getRueId()!=null) {
Optional<Rue> optionalRue = rueRepository.findById(parcellePayLoadWeb.getRueId()); Optional<Rue> optionalRue = rueRepository.findById(parcellePayLoadWeb.getRueId());

View File

@@ -3,6 +3,7 @@ package io.gmss.fiscad.interfaces.infocad.metier;
import io.gmss.fiscad.entities.infocad.metier.Parcelle; import io.gmss.fiscad.entities.infocad.metier.Parcelle;
import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.paylaods.FiltreParcelle;
import io.gmss.fiscad.paylaods.request.FiltreParcellePayLoad; import io.gmss.fiscad.paylaods.request.FiltreParcellePayLoad;
import io.gmss.fiscad.paylaods.request.crudweb.ParcellePayLoadWeb; import io.gmss.fiscad.paylaods.request.crudweb.ParcellePayLoadWeb;
import io.gmss.fiscad.paylaods.response.dataTableResponse.ParcelleDataTableResponse; import io.gmss.fiscad.paylaods.response.dataTableResponse.ParcelleDataTableResponse;
@@ -33,9 +34,5 @@ public interface ParcelleService {
List<ParcellePayLoadWeb> getParcelleListByRueToDto(Long userId,Long rueId); List<ParcellePayLoadWeb> getParcelleListByRueToDto(Long userId,Long rueId);
Page<ParcellePayLoadWeb> getParcelleListByRuePageableToDto(Long userId,Long rueId,Pageable pageable); Page<ParcellePayLoadWeb> getParcelleListByRuePageableToDto(Long userId,Long rueId,Pageable pageable);
Page<ParcellePayLoadWeb> getParcelleByMultiFiltre(Long userId, FiltreParcelle filtreParcelle, Pageable pageable);
Page<ParcelleDataTableResponse> getParcelleDataTableListByUserId(Long userId, Pageable pageable);
Page<ParcelleDataTableResponse> getParcelleDataTableListByMultiFiltre(Long userId, FiltreParcellePayLoad filtreParcellePayLoad, Pageable pageable);
} }

View File

@@ -14,6 +14,7 @@ import java.util.Date;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class FiltreParcelle { public class FiltreParcelle {
private Long quartierId;
private String nup; private String nup;
private String nupProvisoir; private String nupProvisoir;
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
@@ -24,4 +25,6 @@ public class FiltreParcelle {
private String nc; private String nc;
private Long structureId; private Long structureId;
private String numeroTitreFoncier; private String numeroTitreFoncier;
private String ifu;
private String npi;
} }

View File

@@ -1,7 +1,9 @@
package io.gmss.fiscad.paylaods.request.crudweb; package io.gmss.fiscad.paylaods.request.crudweb;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@Data @Data
public class ParcellePayLoadWeb { public class ParcellePayLoadWeb {
private Long id; private Long id;

View File

@@ -0,0 +1,16 @@
package io.gmss.fiscad.persistence.customrepository;
import io.gmss.fiscad.paylaods.FiltreParcelle;
import io.gmss.fiscad.paylaods.request.crudweb.ParcellePayLoadWeb;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
public interface ParcelleRepositoryCustom {
Page<ParcellePayLoadWeb> filtrerParcellesNative(
FiltreParcelle filtre,
List<Long> secteurIds,
Pageable pageable
);
}

View File

@@ -0,0 +1,179 @@
package io.gmss.fiscad.persistence.customrepository;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.paylaods.FiltreParcelle;
import io.gmss.fiscad.paylaods.request.crudweb.ParcellePayLoadWeb;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Query;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
@RequiredArgsConstructor
public class ParcelleRepositoryCustomImpl implements ParcelleRepositoryCustom {
private final EntityManager em;
@Autowired
private NamedParameterJdbcTemplate jdbcTemplate;
@Override
public Page<ParcellePayLoadWeb> filtrerParcellesNative(
FiltreParcelle filtre,
List<Long> secteurIds,
Pageable pageable) {
String baseSql = """
WITH derniere_enquete AS (
SELECT DISTINCT ON (e.parcelle_id)
e.id,
e.parcelle_id,
e.date_enquete,
e.statut_enquete,
e.personne_id
FROM enquete e
ORDER BY e.parcelle_id, e.date_enquete DESC
)
SELECT
p.id as id,
p.q as q,
p.i as i,
p.p as p,
p.nup as nup,
p.nup_provisoire as nupProvisoire,
p.numero_titre_foncier as numeroTitreFoncier,
p.longitude as longitude,
p.latitude as latitude,
p.altitude as altitude,
p.superficie as superficie,
p.observation as observation,
p.situation_geographique as situationGeographique,
p.num_entree_parcelle as numEntreeParcelle,
q.id as quartierId,
q.code as quartierCode,
q.nom as quartierNom,
nd.id as natureId,
nd.libelle as natureLibelle,
td.id as typeId,
td.libelle as typeLibelle,
r.id as rueId,
r.numero as rueNumero,
r.nom as rueNom,
pers.id as personneId,
pers.ifu as ifu,
pers.npi as npi,
pers.nom as nom,
pers.prenom as prenom,
pers.raison_sociale as raisonSociale,
de.id as enqueteId
FROM parcelle p
LEFT JOIN quartier q ON q.id = p.quartier_id
LEFT JOIN nature_domaine nd ON nd.id = p.nature_domaine_id
LEFT JOIN type_domaine td ON td.id = p.type_domaine_id
LEFT JOIN rue r ON r.id = p.rue_id
LEFT JOIN derniere_enquete de ON de.parcelle_id = p.id
LEFT JOIN personne pers ON pers.id = de.personne_id
INNER JOIN secteur_decoupage sd ON sd.quartier_id = p.quartier_id
WHERE sd.secteur_id IN (:secteurIds)
""";
StringBuilder where = new StringBuilder();
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("secteurIds", secteurIds);
if (filtre.getNup() != null && !filtre.getNup().isBlank()) {
where.append(" AND LOWER(p.nup) LIKE LOWER(:nup)");
params.addValue("nup", "%" + filtre.getNup() + "%");
}
if (filtre.getNup() != null && !filtre.getNup().isBlank()) {
where.append(" AND LOWER(p.nup_provisoir) LIKE LOWER(:nupProvisoir)");
params.addValue("nupProvisoir", "%" + filtre.getNup() + "%");
}
if (filtre.getNumeroTitreFoncier() != null) {
where.append(" AND p.numero_titre_foncier = :numeroTitreFoncier");
params.addValue("numeroTitreFoncier", filtre.getNumeroTitreFoncier());
}
if (filtre.getStatus() != null) {
where.append(" AND de.statut_enquete = :status");
params.addValue("status", filtre.getStatus().name());
}
// if (filtre.getStructureId() != null) {
// where.append(" AND de.structure_id = :structureId");
// params.addValue("structureId", filtre.getStructureId());
// }
if (filtre.getQuartierId() != null) {
where.append(" AND p.quartier_id = :quartierId");
params.addValue("quartierId", filtre.getQuartierId());
}
if (filtre.getQ() != null) {
where.append(" AND TRIM(p.q) = :q");
params.addValue("q", filtre.getQ().trim());
}
if (filtre.getI() != null) {
where.append(" AND TRIM(p.i) = :i");
params.addValue("i", filtre.getI().trim());
}
if (filtre.getP() != null) {
where.append(" AND TRIM(p.p) = :p");
params.addValue("p", filtre.getP().trim());
}
if (filtre.getNc() != null) {
where.append(" AND TRIM(pers.nc) = :nc");
params.addValue("nc", filtre.getNc().trim());
}
if (filtre.getIfu() != null) {
where.append(" AND pers.ifu = :ifu");
params.addValue("ifu", filtre.getIfu());
}
if (filtre.getNpi() != null) {
where.append(" AND pers.npi = :npi");
params.addValue("npi", filtre.getNpi());
}
String pagination = " ORDER BY p.id LIMIT :limit OFFSET :offset";
params.addValue("limit", pageable.getPageSize());
params.addValue("offset", pageable.getOffset());
List<ParcellePayLoadWeb> content = jdbcTemplate.query(
baseSql + where + pagination,
params,
new BeanPropertyRowMapper<>(ParcellePayLoadWeb.class)
);
// Count query
Long total = jdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM (" + baseSql + where + ") as count_query",
params,
Long.class
);
return new PageImpl<>(content, pageable, total);
}
}

View File

@@ -6,6 +6,7 @@ import io.gmss.fiscad.paylaods.response.dataTableResponse.ParcelleDataTableRespo
import io.gmss.fiscad.paylaods.response.statistique.StatistiqueTypeNombreResponse; import io.gmss.fiscad.paylaods.response.statistique.StatistiqueTypeNombreResponse;
import io.gmss.fiscad.paylaods.response.restoration.ParcellePayLoadRestor; import io.gmss.fiscad.paylaods.response.restoration.ParcellePayLoadRestor;
import io.gmss.fiscad.paylaods.response.restoration.ParcelleStatsProjectionUnSecteur; import io.gmss.fiscad.paylaods.response.restoration.ParcelleStatsProjectionUnSecteur;
import io.gmss.fiscad.persistence.customrepository.ParcelleRepositoryCustom;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
@@ -16,7 +17,7 @@ import org.springframework.data.repository.query.Param;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
public interface ParcelleRepository extends JpaRepository<Parcelle, Long>, JpaSpecificationExecutor<Parcelle> { public interface ParcelleRepository extends JpaRepository<Parcelle, Long>, JpaSpecificationExecutor<Parcelle>, ParcelleRepositoryCustom {
Optional<Parcelle> findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long TerminalId); Optional<Parcelle> findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long TerminalId);
Optional<Parcelle> findByMobileDataId(Long id); Optional<Parcelle> findByMobileDataId(Long id);
@Query(value = "Select " + @Query(value = "Select " +