From 28f361dcc4e38a6b8d45961f6841a4765f2345d2 Mon Sep 17 00:00:00 2001 From: Aurince AKAKPO Date: Tue, 28 Jul 2026 14:25:54 +0100 Subject: [PATCH] reajustement secteur decoupage perimetre --- .../audit/HistoriqueConnexionController.java | 63 ++++ .../controllers/user/UserController.java | 36 +- .../entities/audit/HistoriqueConnexion.java | 35 ++ .../java/io/gmss/fiscad/enums/UserRole.java | 6 +- .../audit/HistoriqueConnexionServiceImpl.java | 23 ++ .../DonneesImpositionTfuServiceImpl.java | 53 ++- .../implementations/user/UserServiceImpl.java | 15 +- .../audit/HistoriqueConnexionService.java | 16 + .../metier/DonneesImpositionTfuService.java | 2 + .../HistoriqueConnexionPaylaodWeb.java | 37 ++ .../generer_donnees_imposition_irf_batie.sql | 286 --------------- ...es_imposition_irf_batie_unite_logement.sql | 344 ------------------ .../audit/HistoriqueConnexionRepository.java | 71 ++++ .../decoupage/ArrondissementRepository.java | 19 + .../DonneesImpositionTfuRepository.java | 15 + .../parametre/BaremRfuNonBatiRepository.java | 20 + .../rfu/parametre/BaremRfuRepository.java | 24 ++ 17 files changed, 420 insertions(+), 645 deletions(-) create mode 100644 src/main/java/io/gmss/fiscad/controllers/audit/HistoriqueConnexionController.java create mode 100644 src/main/java/io/gmss/fiscad/entities/audit/HistoriqueConnexion.java create mode 100644 src/main/java/io/gmss/fiscad/implementations/audit/HistoriqueConnexionServiceImpl.java create mode 100755 src/main/java/io/gmss/fiscad/interfaces/audit/HistoriqueConnexionService.java create mode 100644 src/main/java/io/gmss/fiscad/paylaods/request/crudweb/HistoriqueConnexionPaylaodWeb.java create mode 100755 src/main/java/io/gmss/fiscad/persistence/repositories/audit/HistoriqueConnexionRepository.java diff --git a/src/main/java/io/gmss/fiscad/controllers/audit/HistoriqueConnexionController.java b/src/main/java/io/gmss/fiscad/controllers/audit/HistoriqueConnexionController.java new file mode 100644 index 0000000..8d46cc7 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/controllers/audit/HistoriqueConnexionController.java @@ -0,0 +1,63 @@ +package io.gmss.fiscad.controllers.audit; + + +import io.gmss.fiscad.exceptions.*; +import io.gmss.fiscad.interfaces.audit.HistoriqueConnexionService; +import io.gmss.fiscad.paylaods.ApiResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; + + +@RestController +@RequestMapping(value = "api/historique-connexion", produces = MediaType.APPLICATION_JSON_VALUE) +@SecurityRequirement(name = "bearer") +@Tag(name = "Historique des connexion") +@CrossOrigin(origins = "*") +public class HistoriqueConnexionController { + + private final HistoriqueConnexionService historiqueConnexionService; + private static final Logger logger = LoggerFactory.getLogger(HistoriqueConnexionController.class); + + public HistoriqueConnexionController(HistoriqueConnexionService historiqueConnexionService) { + this.historiqueConnexionService = historiqueConnexionService; + } + + + @GetMapping("/user/{userId}") + @PreAuthorize("hasAuthority('READ_HISTORIQUECONNEXION')") + public ResponseEntity getHistoriqueConnexionByUserId(@PathVariable Long userId) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, historiqueConnexionService.gethistoriqueConnexionListByUserIdPage(userId), "Liste des historiqueConnexions par commune 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); + } + } + +} diff --git a/src/main/java/io/gmss/fiscad/controllers/user/UserController.java b/src/main/java/io/gmss/fiscad/controllers/user/UserController.java index 608a895..f0604ac 100755 --- a/src/main/java/io/gmss/fiscad/controllers/user/UserController.java +++ b/src/main/java/io/gmss/fiscad/controllers/user/UserController.java @@ -72,7 +72,7 @@ public class UserController { @PostMapping("/change-password") @PreAuthorize("hasAuthority('UPDATE_USER')") - public ResponseEntity changeUserPassword(@RequestBody @Valid @Validated Login login) { + public ResponseEntity changeUserPassword(@RequestBody Login login) { try { userService.updatePassword(login.getUsername(), login.getPassword()); return new ResponseEntity<>( @@ -95,6 +95,40 @@ public class UserController { } } + + @PostMapping("/change-my-password") + @PreAuthorize("hasAuthority('UPDATE_USER')") + public ResponseEntity changeMyPassword(@CurrentUser UserPrincipal currentUser, @RequestBody Login login) { + try { + User user = currentUser.getUser() ; + if(!user.getUsername().equals(login.getUsername())){ + return new ResponseEntity<>( + new ApiResponse<>(false, "Echec de changement de mot de passe : Utilisateur non identifié"), + HttpStatus.OK + ); + + } + userService.updatePassword(login.getUsername(), login.getPassword()); + return new ResponseEntity<>( + new ApiResponse<>(true, "Votre mot de passe à été modifié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("/request-reset-password") //@PreAuthorize("hasAuthority('UPDATE_USER')") public ResponseEntity resetUserPassword(@RequestParam String login) { diff --git a/src/main/java/io/gmss/fiscad/entities/audit/HistoriqueConnexion.java b/src/main/java/io/gmss/fiscad/entities/audit/HistoriqueConnexion.java new file mode 100644 index 0000000..44f4f51 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/entities/audit/HistoriqueConnexion.java @@ -0,0 +1,35 @@ +package io.gmss.fiscad.entities.audit; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.gmss.fiscad.deserializer.LocalDateDeserializer; +import io.gmss.fiscad.entities.BaseEntity; +import io.gmss.fiscad.entities.user.User; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Where; + +import java.io.Serializable; +import java.time.LocalDateTime; + +@EqualsAndHashCode(callSuper = true) +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +@Where(clause = " deleted = false") +public class HistoriqueConnexion extends BaseEntity implements Serializable { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @JsonFormat(pattern = "dd-MM-yyyy HH:mm:ss") + @JsonDeserialize(using = LocalDateDeserializer.class) + private LocalDateTime dateConnexion; + @JsonIgnore + @ManyToOne + private User user; +} diff --git a/src/main/java/io/gmss/fiscad/enums/UserRole.java b/src/main/java/io/gmss/fiscad/enums/UserRole.java index 4c8e8ca..f58168f 100644 --- a/src/main/java/io/gmss/fiscad/enums/UserRole.java +++ b/src/main/java/io/gmss/fiscad/enums/UserRole.java @@ -278,6 +278,10 @@ public enum UserRole { CREATE_PROFILEMODULEFONCTIONNALITE, READ_PROFILEMODULEFONCTIONNALITE, UPDATE_PROFILEMODULEFONCTIONNALITE, - DELETE_PROFILEMODULEFONCTIONNALITE + DELETE_PROFILEMODULEFONCTIONNALITE, + CREATE_HISTORIQUECONNEXION, + READ_HISTORIQUECONNEXION, + UPDATE_HISTORIQUECONNEXION, + DELETE_HISTORIQUECONNEXION } diff --git a/src/main/java/io/gmss/fiscad/implementations/audit/HistoriqueConnexionServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/audit/HistoriqueConnexionServiceImpl.java new file mode 100644 index 0000000..ad3699f --- /dev/null +++ b/src/main/java/io/gmss/fiscad/implementations/audit/HistoriqueConnexionServiceImpl.java @@ -0,0 +1,23 @@ +package io.gmss.fiscad.implementations.audit; + +import io.gmss.fiscad.interfaces.audit.HistoriqueConnexionService; +import io.gmss.fiscad.paylaods.request.crudweb.HistoriqueConnexionPaylaodWeb; +import io.gmss.fiscad.persistence.repositories.audit.HistoriqueConnexionRepository; +import lombok.AllArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.List; + +@AllArgsConstructor +@Service +public class HistoriqueConnexionServiceImpl implements HistoriqueConnexionService { + private final HistoriqueConnexionRepository historiqueConnexionRepository ; + + @Override + public List gethistoriqueConnexionListByUserIdPage(Long userId) { + return historiqueConnexionRepository.findTop5HistoriqueConnexionByUserId(userId, PageRequest.of(0, 5)); + } +} diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/DonneesImpositionTfuServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/DonneesImpositionTfuServiceImpl.java index 69d20c9..fca7c01 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/DonneesImpositionTfuServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/DonneesImpositionTfuServiceImpl.java @@ -1,6 +1,7 @@ package io.gmss.fiscad.implementations.rfu.metier; import io.gmss.fiscad.entities.decoupage.Arrondissement; +import io.gmss.fiscad.entities.infocad.metier.Parcelle; import io.gmss.fiscad.entities.rfu.metier.DonneesImpositionTfu; import io.gmss.fiscad.entities.rfu.metier.ImpositionsTfu; import io.gmss.fiscad.entities.rfu.parametre.BaremRfuNonBati; @@ -8,6 +9,7 @@ import io.gmss.fiscad.enums.StatusAvis; import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.interfaces.rfu.metier.DonneesImpositionTfuService; +import io.gmss.fiscad.paylaods.request.crudweb.ArrondissementPaylaodWeb; import io.gmss.fiscad.paylaods.request.crudweb.DonneesImpositionPaylaodWeb; import io.gmss.fiscad.paylaods.request.crudweb.ImpositionsTfuPaylaodWeb; import io.gmss.fiscad.paylaods.response.DonneesImpositionTfuResponse; @@ -17,6 +19,7 @@ import io.gmss.fiscad.persistence.repositories.infocad.metier.ParcelleRepository import io.gmss.fiscad.persistence.repositories.rfu.metier.DonneesImpositionTfuRepository; import io.gmss.fiscad.persistence.repositories.rfu.metier.ImpositionsTfuRepository; import io.gmss.fiscad.persistence.repositories.rfu.parametre.BaremRfuNonBatiRepository; +import io.gmss.fiscad.persistence.repositories.rfu.parametre.BaremRfuRepository; import io.gmss.fiscad.persistence.repositories.rfu.parametre.ExerciceRepository; import io.gmss.fiscad.service.EntityFromPayLoadService; import jakarta.transaction.Transactional; @@ -40,6 +43,7 @@ public class DonneesImpositionTfuServiceImpl implements DonneesImpositionTfuServ private final BaremRfuNonBatiRepository baremRfuNonBatiRepository; private final ExerciceRepository exerciceRepository; private final ArrondissementRepository arrondissementRepository; + private final BaremRfuRepository baremRfuRepository; private final EntityFromPayLoadService entityFromPayLoadService; @@ -112,18 +116,24 @@ public class DonneesImpositionTfuServiceImpl implements DonneesImpositionTfuServ @Override @Transactional public ImpositionsTfuPaylaodWeb genererDonneesFiscalesParcelleNonBatieUneParcelle(ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb, Long userId,Long parcelleId) { -// System.out.println("User : " +userId); -// System.out.println("Parcelle : " +parcelleId); -// System.out.println("Imposition : " +impositionsTfuPaylaodWeb.getId()); + boolean existsBareme = baremRfuNonBatiRepository.existsBaremForParcelleNonBati(parcelleId); + Optional optionalParcelle= parcelleRepository.findById(parcelleId); + String nomQuartier=""; + String nomArrondissement=""; + String nomCommune=""; + if(optionalParcelle.isPresent()){ + nomQuartier= optionalParcelle.get().getQuartier().getNom(); + nomArrondissement= optionalParcelle.get().getQuartier().getArrondissement().getNom(); + nomCommune= optionalParcelle.get().getQuartier().getArrondissement().getCommune().getNom(); + } + if(!existsBareme){ + throw new BadRequestException("Impossible de continuer la liquidation : Il n'existe pas de barème configuré pour la zone de cette parcelle : "+nomCommune+" : "+nomArrondissement+" : "+nomQuartier); + } Integer nb= donneesImpositionTfuRepository.genererDonneesTfuNonBatie(impositionsTfuPaylaodWeb.getId(),userId,parcelleId); -// System.out.println(nb); ImpositionsTfu impositionsTfu = entityFromPayLoadService.getImpositionsTfuFromPayLoadWeb(impositionsTfuPaylaodWeb); impositionsTfu.setStatusAvis(StatusAvis.TFU_FNB_GENERE); - impositionsTfu.setNombreAvisFnb(nb); - impositionsTfuRepository.save(impositionsTfu); - return impositionsTfuRepository.findByIdToDto(impositionsTfu.getId()).orElse(null); } @@ -162,6 +172,29 @@ public class DonneesImpositionTfuServiceImpl implements DonneesImpositionTfuServ @Transactional public ImpositionsTfuPaylaodWeb genererDonneesFiscalesParcelleBatieUneParcelle(ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb, Long userId, Long parcelleId) { + Optional imp=impositionsTfuRepository.findByIdToDto(impositionsTfuPaylaodWeb.getId()); + if(imp.isPresent()){ + boolean dejaLiquide = donneesImpositionTfuRepository.existsByImpositionAnneeAndParcelle(Long.valueOf(imp.get().getExerciceAnnee()),parcelleId); + if(dejaLiquide){ + return imp.orElse(null); + } + } + + + boolean existsBareme = baremRfuRepository.existsBaremForParcelle(parcelleId); + Optional optionalParcelle= parcelleRepository.findById(parcelleId); + String nomQuartier=""; + String nomArrondissement=""; + String nomCommune=""; + if(optionalParcelle.isPresent()){ + nomQuartier= optionalParcelle.get().getQuartier().getNom(); + nomArrondissement= optionalParcelle.get().getQuartier().getArrondissement().getNom(); + nomCommune= optionalParcelle.get().getQuartier().getArrondissement().getCommune().getNom(); + } + if(!existsBareme){ + throw new BadRequestException("Impossible de continuer la liquidation : Il n'existe pas de barème configuré pour la zone de cette parcelle : "+nomCommune+" : "+nomArrondissement+" : "+nomQuartier); + } + Integer nbb= donneesImpositionTfuRepository.genererDonneesTfuBatie(impositionsTfuPaylaodWeb.getId(),userId,parcelleId); Integer nbirfbtPlusieursBati = donneesImpositionTfuRepository.majDonneesTfuBatiePlusieursBatiment(impositionsTfuPaylaodWeb.getId(),parcelleId); @@ -181,9 +214,9 @@ public class DonneesImpositionTfuServiceImpl implements DonneesImpositionTfuServ impositionsTfu.setStatusAvis(StatusAvis.GENERE); - impositionsTfu.setNombreAvis(nbb+nbulo+ (impositionsTfu.getNombreAvisFnb()==null?0:impositionsTfu.getNombreAvisFnb())); - impositionsTfu.setNombreAvisBatiment(nbb); - impositionsTfu.setNombreAvisUniteLog(nbulo); + impositionsTfu.setNombreAvis(impositionsTfu.getNombreAvis()+1); + impositionsTfu.setNombreAvisBatiment(impositionsTfu.getNombreAvisFnb()+1); + impositionsTfu.setNombreAvisUniteLog(impositionsTfu.getNombreAvisUniteLog()+1); impositionsTfuRepository.save(impositionsTfu); diff --git a/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java index 7f3ab71..e1c9c80 100644 --- a/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java @@ -1,5 +1,6 @@ package io.gmss.fiscad.implementations.user; +import io.gmss.fiscad.entities.audit.HistoriqueConnexion; import io.gmss.fiscad.entities.infocad.parametre.Structure; import io.gmss.fiscad.entities.user.User; import io.gmss.fiscad.enums.UserRole; @@ -14,6 +15,7 @@ import io.gmss.fiscad.paylaods.Login; import io.gmss.fiscad.paylaods.UserListByStructureResponse; import io.gmss.fiscad.paylaods.UserResponse; import io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb; +import io.gmss.fiscad.persistence.repositories.audit.HistoriqueConnexionRepository; import io.gmss.fiscad.persistence.repositories.user.UserRepository; import io.gmss.fiscad.security.TokenAuthentificationProvider; import io.gmss.fiscad.service.EntityFromPayLoadService; @@ -49,6 +51,7 @@ public class UserServiceImpl implements UserService { private final EntityFromPayLoadService entityFromPayLoadService; private final StringService stringService ; private final MailService mailService ; + private final HistoriqueConnexionRepository historiqueConnexionRepository ; @Value("${dgi.sigibe-foncier.reset-pw.url}") private String reseturl ; @@ -56,9 +59,7 @@ public class UserServiceImpl implements UserService { @Value("${dgi.sigibe-foncier.reset-pw.token-delay}") private String tokenDelay ; - - - public UserServiceImpl(UserRepository userRepository, PasswordEncoder passwordEncoder, RoleService roleService, AuthenticationManager authenticationManager, TokenAuthentificationProvider tokenAuthentificationProvider, StructureService structureService, EntityFromPayLoadService entityFromPayLoadService, StringService stringService, MailService mailService) { + public UserServiceImpl(UserRepository userRepository, PasswordEncoder passwordEncoder, RoleService roleService, AuthenticationManager authenticationManager, TokenAuthentificationProvider tokenAuthentificationProvider, StructureService structureService, EntityFromPayLoadService entityFromPayLoadService, StringService stringService, MailService mailService, HistoriqueConnexionRepository historiqueConnexionRepository) { this.userRepository = userRepository; this.passwordEncoder = passwordEncoder; this.roleService = roleService; @@ -68,6 +69,7 @@ public class UserServiceImpl implements UserService { this.entityFromPayLoadService = entityFromPayLoadService; this.stringService = stringService; this.mailService = mailService; + this.historiqueConnexionRepository = historiqueConnexionRepository; } @@ -121,6 +123,13 @@ public class UserServiceImpl implements UserService { ); SecurityContextHolder.getContext().setAuthentication(authentication); + + HistoriqueConnexion historiqueConnexion = new HistoriqueConnexion(); + + historiqueConnexion.setDateConnexion(LocalDateTime.now()); + historiqueConnexion.setUser(user); + historiqueConnexionRepository.save(historiqueConnexion); + return tokenAuthentificationProvider.generateToken(authentication); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/audit/HistoriqueConnexionService.java b/src/main/java/io/gmss/fiscad/interfaces/audit/HistoriqueConnexionService.java new file mode 100755 index 0000000..42952fe --- /dev/null +++ b/src/main/java/io/gmss/fiscad/interfaces/audit/HistoriqueConnexionService.java @@ -0,0 +1,16 @@ +package io.gmss.fiscad.interfaces.audit; + +import io.gmss.fiscad.entities.decoupage.Arrondissement; +import io.gmss.fiscad.exceptions.BadRequestException; +import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.paylaods.request.crudweb.ArrondissementPaylaodWeb; +import io.gmss.fiscad.paylaods.request.crudweb.HistoriqueConnexionPaylaodWeb; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.List; +import java.util.Optional; + +public interface HistoriqueConnexionService { + List gethistoriqueConnexionListByUserIdPage(Long UserId); +} diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/DonneesImpositionTfuService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/DonneesImpositionTfuService.java index 9ca00af..537a183 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/DonneesImpositionTfuService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/DonneesImpositionTfuService.java @@ -51,4 +51,6 @@ public interface DonneesImpositionTfuService { public ImpositionsTfuPaylaodWeb genererDonneesFiscalesParcelleBatieUneParcelle(ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb, Long userId, Long parcelleId); + //List getDonneesFiscalesByParcelleIdAndExercice(Long parcelleId, Long exerciceId); + } diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/HistoriqueConnexionPaylaodWeb.java b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/HistoriqueConnexionPaylaodWeb.java new file mode 100644 index 0000000..f0b1f32 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/HistoriqueConnexionPaylaodWeb.java @@ -0,0 +1,37 @@ +package io.gmss.fiscad.paylaods.request.crudweb; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.gmss.fiscad.deserializer.LocalDateDeserializer; +import io.gmss.fiscad.entities.user.User; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@NoArgsConstructor +@Data +public class HistoriqueConnexionPaylaodWeb { + private Long id; + @JsonFormat(pattern = "dd-MM-yyyy HH:mm:ss") + @JsonDeserialize(using = LocalDateDeserializer.class) + private LocalDateTime dateConnexion; + private Long userId; + private String userLogin; + private String userNom; + private String userPrenom; + + public HistoriqueConnexionPaylaodWeb(Long id, LocalDateTime dateConnexion, Long userId, String userLogin, String userNom, String userPrenom) { + this.id = id; + this.dateConnexion = dateConnexion; + this.userId = userId; + this.userLogin = userLogin; + this.userNom = userNom; + this.userPrenom = userPrenom; + } +} diff --git a/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/generer_donnees_imposition_irf_batie.sql b/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/generer_donnees_imposition_irf_batie.sql index 5369e0a..fac01f6 100644 --- a/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/generer_donnees_imposition_irf_batie.sql +++ b/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/generer_donnees_imposition_irf_batie.sql @@ -1,289 +1,3 @@ -/*CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie( - p_impositions_tfu_id BIGINT, - p_user_id BIGINT -) -RETURNS INTEGER -LANGUAGE plpgsql -AS -$$ -DECLARE -v_rows_inserted INTEGER; - v_annee BIGINT; - v_structure_id BIGINT; - v_taux_defaut_sup_sol NUMERIC; - v_taux_valeur_locat_prof NUMERIC; - v_tfu_piscine_unitaire NUMERIC; - v_taux_irf NUMERIC; -BEGIN - --- récupération de l'année -SELECT ex.annee, it.structure_id -INTO STRICT v_annee, v_structure_id -FROM impositions_tfu it - join exercice ex on ex.id =it.exercice_id -WHERE it.id = p_impositions_tfu_id; - - -select value -into strict v_taux_defaut_sup_sol -from parameters -where name ='TAUX_DEFAUT_SUPERFICIE_AU_SOL'; - -select value -into STRICT v_taux_irf -from parameters -where name ='TAUX_IRF'; - - -select value -into STRICT v_taux_valeur_locat_prof -from parameters -where name ='TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE'; - -select value -into STRICT v_tfu_piscine_unitaire -from parameters -where name ='TFU_PAR_PISCINE'; - -INSERT INTO donnees_imposition_tfu( - annee, - code_departement, - nom_departement, - code_commune, - nom_commune, - code_arrondissement, - nom_arrondissement, - code_quartier_village, - nom_quartier_village, - q, - ilot, - parcelle, - nup, - titre_foncier, - num_batiment, - ifu, - npi, - tel_prop, - email_prop, - nom_prop, - prenom_prop, - raison_sociale, - adresse_prop, - tel_sc, - nom_sc, - prenom_sc, - longitude, - latitude, - batie, - exonere, - batiment_exonere, - standing_bat, - categorie_bat, - nombre_piscine, - date_enquete, - structure_id, - zone_rfu_id, - nature_impot, - superficie_parc, - superficie_au_sol_bat, - valeur_batiment, - valeur_locative_adm_metre_carre, - montant_loyer_annuel, - tfu_metre_carre, - tfu_minimum, - impositions_tfu_id, - deleted, - created_at , - created_by , - "source", - updated_at , - updated_by, - categorie_usage, - superficie_au_sol_taux_prop_parc, ---70% de la surperficie au sol de la parcelle - valeur_locative_adm_taux_prop_parc, - tfu_calcule_taux_prop_parc, ----tfu correspondant au 70% - valeur_locative_adm_sup_reel, - valeur_locative_adm, ----------valeur locative administrative - tfu_superficie_au_sol_reel, ----tfu correspondant à la superficie au sol reelle - tfu_piscine, - montant_taxe, ----tfu finale - taux_tfu, ----taux tfu batie - parcelle_id, - batiment_id, - unite_logement_id, - superficie_au_sol_loue -) -SELECT - v_annee, - d.code, - d.nom, - c.code, - c.nom, - a.code, - a.nom, - q.code, - q.nom, - p.q, - p.i, - p.p, - p.nup, - ep.numero_titre_foncier, - b.nub, - pers.ifu, - pers.npi, - pers.tel1, - pers.email, - pers.nom, - pers.prenom, - pers.raison_sociale, - pers.adresse, - ep.representant_tel, - ep.representant_nom, - ep.representant_prenom, - p.longitude, - p.latitude, - TRUE, - ( - CURRENT_DATE >= ep.date_debut_exemption - AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE) - ), - ( - CURRENT_DATE >= eb.date_debut_excemption - AND CURRENT_DATE <= COALESCE(eb.date_fin_excemption, CURRENT_DATE) - ), - cb.standing, - cb.nom, - eb.nombre_piscine, - eb.date_enquete, - st.id, - ep.zone_rfu_id, - 'IRF', - p.superficie, - eb.superficie_au_sol, - case -------valeur_batiment - WHEN eb.valeur_batiment_reel IS NOT NULL AND eb.valeur_batiment_reel <> 0 THEN eb.valeur_batiment_reel - WHEN eb.valeur_batiment_calcule IS NOT NULL AND eb.valeur_batiment_calcule <> 0 THEN eb.valeur_batiment_calcule - WHEN eb.valeur_batiment_estime IS NOT NULL AND eb.valeur_batiment_estime <> 0 THEN eb.valeur_batiment_estime - ELSE 0 - END, - brb.valeur_locative, - case ----- montant_loyer_annuel - WHEN eb.montant_locatif_annuel_declare IS NOT NULL AND eb.montant_locatif_annuel_declare <> 0 THEN eb.montant_locatif_annuel_declare - WHEN eb.montant_locatif_annuel_calcule IS NOT NULL AND eb.montant_locatif_annuel_calcule <> 0 THEN eb.montant_locatif_annuel_calcule - WHEN eb.montant_locatif_annuel_estime IS NOT NULL AND eb.montant_locatif_annuel_estime <> 0 THEN eb.montant_locatif_annuel_estime - ELSE 0 - END, - brb.tfu_metre_carre, - brb.tfu_minimum, - p_impositions_tfu_id, - false, - current_date , - p_user_id , - 'FISCAD', - current_date , - p_user_id, - eb.categorie_usage, - p.superficie*v_taux_defaut_sup_sol/100,---superficie_au_sol_70pour100 - (p.superficie * v_taux_defaut_sup_sol/100) * brb.valeur_locative, - 0, - eb.superficie_au_sol * brb.valeur_locative, - 0, ------ valeur_locative_adm : en attente de update - 0, - 0, - 0, - v_taux_irf, - p.id, - b.id, - null, - eb.superficie_louee -FROM parcelle p - LEFT JOIN ( - SELECT DISTINCT ON (parcelle_id) - parcelle_id, - superficie, - personne_id, - numero_titre_foncier, - date_enquete, - representant_tel, - representant_nom, - representant_prenom, - representant_npi, - date_debut_exemption, - date_fin_exemption, - zone_rfu_id - FROM enquete - ORDER BY parcelle_id, date_enquete DESC, id DESC -) ep ON ep.parcelle_id = p.id - LEFT JOIN personne pers - ON pers.id = ep.personne_id - JOIN quartier q ON q.id = p.quartier_id - JOIN arrondissement a ON a.id = q.arrondissement_id - JOIN commune c ON c.id = a.commune_id - JOIN departement d ON d.id = c.departement_id - JOIN secteur_decoupage sd ON sd.quartier_id = q.id - JOIN secteur sect ON sect.id = sd.secteur_id - JOIN section ses ON ses.id = sect.section_id - JOIN "structure" st ON st.id = ses.structure_id - JOIN batiment b ON b.parcelle_id = p.id - JOIN ( - SELECT DISTINCT ON (batiment_id) - batiment_id, - superficie_au_sol, - nombre_piscine, - categorie_batiment_id, - date_enquete, - montant_locatif_annuel_declare, - montant_locatif_annuel_calcule, - montant_locatif_annuel_estime, - date_debut_excemption, - date_fin_excemption, - valeur_batiment_reel, - valeur_batiment_calcule, - valeur_batiment_estime, - u.categorie_usage, - superficie_louee - FROM enquete_batiment eb - join usage u on u.id=eb.usage_id - where superficie_louee*montant_locatif_annuel_declare>0 - ORDER BY batiment_id, date_enquete DESC, eb.id DESC -) eb ON eb.batiment_id = b.id - JOIN categorie_batiment cb - ON cb.id = eb.categorie_batiment_id - JOIN LATERAL ( - SELECT * - FROM barem_rfu_bati br - WHERE br.categorie_batiment_id = cb.id - AND br.arrondissement_id = a.id - AND (br.quartier_id = q.id OR br.quartier_id IS NULL) - ORDER BY br.quartier_id DESC NULLS LAST - LIMIT 1 -) brb ON TRUE -WHERE p.batie = TRUE - AND NOT EXISTS ( - SELECT 1 - FROM unite_logement ul - WHERE ul.batiment_id = b.id - ) - AND st.id = v_structure_id -ON CONFLICT DO NOTHING; - -GET DIAGNOSTICS v_rows_inserted = ROW_COUNT; - -UPDATE donnees_imposition_tfu dtfu -SET - valeur_locative_adm=montant_loyer_annuel, - montant_taxe = montant_loyer_annuel * v_taux_irf/100 -WHERE impositions_tfu_id = p_impositions_tfu_id - AND batie = TRUE - AND NOT EXISTS ( - SELECT 1 - FROM unite_logement ul - WHERE ul.batiment_id = dtfu.batiment_id -); -RETURN v_rows_inserted; -END; -$$;*/ - CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie( p_impositions_tfu_id BIGINT, p_user_id BIGINT diff --git a/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/generer_donnees_imposition_irf_batie_unite_logement.sql b/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/generer_donnees_imposition_irf_batie_unite_logement.sql index 28d4fa7..b6c5553 100644 --- a/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/generer_donnees_imposition_irf_batie_unite_logement.sql +++ b/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/generer_donnees_imposition_irf_batie_unite_logement.sql @@ -1,347 +1,3 @@ -/*CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie_unite_logement( - p_impositions_tfu_id BIGINT, - p_user_id BIGINT -) -RETURNS INTEGER -LANGUAGE plpgsql -AS -$$ -DECLARE -v_rows_inserted INTEGER; - v_annee BIGINT; - v_structure_id BIGINT; - v_taux_defaut_sup_sol NUMERIC; - v_taux_irf NUMERIC; - v_taux_valeur_locat_prof NUMERIC; - v_tfu_piscine_unitaire NUMERIC; -BEGIN - --- récupération de l'année -SELECT ex.annee, it.structure_id -INTO STRICT v_annee, v_structure_id -FROM impositions_tfu it - join exercice ex on ex.id =it.exercice_id -WHERE it.id = p_impositions_tfu_id; - - -select value -into strict v_taux_defaut_sup_sol -from parameters -where name ='TAUX_DEFAUT_SUPERFICIE_AU_SOL'; - -select value -into STRICT v_taux_irf -from parameters -where name ='TAUX_IRF'; - -select value -into STRICT v_taux_valeur_locat_prof -from parameters -where name ='TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE'; - -select value -into STRICT v_tfu_piscine_unitaire -from parameters -where name ='TFU_PAR_PISCINE'; - -INSERT INTO donnees_imposition_tfu( - annee, - code_departement, - nom_departement, - code_commune, - nom_commune, - code_arrondissement, - nom_arrondissement, - code_quartier_village, - nom_quartier_village, - q, - ilot, - parcelle, - nup, - titre_foncier, - num_batiment, - num_unite_logement, - ifu, - npi, - tel_prop, - email_prop, - nom_prop, - prenom_prop, - raison_sociale, - adresse_prop, - tel_sc, - nom_sc, - prenom_sc, - longitude, - latitude, - batie, - exonere, - batiment_exonere, - unite_logement_exonere, - standing_bat, - categorie_bat, - nombre_piscine, - date_enquete, - structure_id, - zone_rfu_id, - nature_impot, - superficie_parc, - superficie_au_sol_bat, - superficie_au_sol_ulog, - valeur_batiment, - valeur_locative_adm_metre_carre, - montant_loyer_annuel, - tfu_metre_carre, - tfu_minimum, - impositions_tfu_id, - deleted, - created_at , - created_by , - "source", - updated_at , - updated_by, - categorie_usage, - superficie_au_sol_taux_prop_parc, ---70% de la surperficie au sol de la parcelle - valeur_locative_adm_taux_prop_parc, - tfu_calcule_taux_prop_parc, ----tfu correspondant au 70% - valeur_locative_adm_sup_reel, - valeur_locative_adm, ----------valeur locative administrative - tfu_superficie_au_sol_reel, ----tfu correspondant à la superficie au sol reelle - tfu_piscine, - montant_taxe, ----tfu finale - taux_tfu, ----taux tfu batie - parcelle_id, - batiment_id, - unite_logement_id, - superficie_au_sol_loue -) -SELECT - v_annee, - d.code, - d.nom, - c.code, - c.nom, - a.code, - a.nom, - q.code, - q.nom, - p.q, - p.i, - p.p, - p.nup, - ep.numero_titre_foncier, - b.nub, - ul.nul, - eul.ifu, - eul.npi, - eul.tel1, - eul.email, - eul.nom, - eul.prenom, - eul.raison_sociale, - eul.adresse, - eul.representant_tel, - eul.representant_nom, - eul.representant_prenom, - p.longitude, - p.latitude, - TRUE, - ( - CURRENT_DATE >= ep.date_debut_exemption - AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE) - ), - ( - CURRENT_DATE >= eb.date_debut_excemption - AND CURRENT_DATE <= COALESCE(eb.date_fin_excemption, CURRENT_DATE) - ), - ( - CURRENT_DATE >= eul.date_debut_exemption - AND CURRENT_DATE <= COALESCE(eul.date_fin_exemption, CURRENT_DATE) - ), - cb.standing, - cb.nom, - CASE - WHEN eul.nombre_piscine is null then 0 - else eul.nombre_piscine - END, - eul.date_enquete, - st.id, - ep.zone_rfu_id, - 'IRF', - p.superficie, - eb.superficie_au_sol, - eul.superficie_au_sol, - CASE -------valeur_batiment - WHEN eul.valeur_unite_logement_reel IS NOT NULL AND eul.valeur_unite_logement_reel <> 0 THEN eul.valeur_unite_logement_reel - WHEN eul.valeur_unite_logement_calcule IS NOT NULL AND eul.valeur_unite_logement_calcule <> 0 THEN eul.valeur_unite_logement_calcule - WHEN eul.valeur_unite_logement_estime IS NOT NULL AND eul.valeur_unite_logement_estime <> 0 THEN eul.valeur_unite_logement_estime - ELSE 0 - END, - brb.valeur_locative, - CASE ----- montant_loyer_annuel - WHEN eul.montant_locatif_annuel_declare IS NOT NULL AND eul.montant_locatif_annuel_declare <> 0 THEN eul.montant_locatif_annuel_declare - WHEN eul.montant_locatif_annuel_calcule IS NOT NULL AND eul.montant_locatif_annuel_calcule <> 0 THEN eul.montant_locatif_annuel_calcule - WHEN eul.montant_locatif_annuel_estime IS NOT NULL AND eul.montant_locatif_annuel_estime <> 0 THEN eul.montant_locatif_annuel_estime - ELSE 0 - END, - brb.tfu_metre_carre, - brb.tfu_minimum, - p_impositions_tfu_id, - false, - current_date, - p_user_id, - 'FISCAD', - current_date, - p_user_id, - eul.categorie_usage, - p.superficie * v_taux_defaut_sup_sol/100,---superficie_au_sol_70pour100 - case ----valeur_locative_adm70pour100 - when eul.categorie_usage = 'HABITATION' then (p.superficie * v_taux_defaut_sup_sol/100) * brb.valeur_locative - else 0 - end, - 0, - eul.superficie_au_sol * brb.valeur_locative, - 0, ------ valeur_locative_adm : en attente de update - 0, - 0, - 0, - v_taux_irf, - p.id, - b.id, - ul.id, - eul.superficie_louee -FROM parcelle p - LEFT JOIN ( - SELECT DISTINCT ON (parcelle_id) - parcelle_id, - superficie, - personne_id, - numero_titre_foncier, - date_enquete, - representant_tel, - representant_nom, - representant_prenom, - representant_npi, - date_debut_exemption, - date_fin_exemption, - zone_rfu_id - FROM enquete - ORDER BY parcelle_id, date_enquete DESC, id DESC -) ep ON ep.parcelle_id = p.id - LEFT JOIN personne pers - ON pers.id = ep.personne_id - JOIN quartier q ON q.id = p.quartier_id - JOIN arrondissement a ON a.id = q.arrondissement_id - JOIN commune c ON c.id = a.commune_id - JOIN departement d ON d.id = c.departement_id - --JOIN secteur_decoupage sd ON sd.quartier_id = q.id - JOIN ( - SELECT DISTINCT ON (quartier_id) - quartier_id, - secteur_id - FROM secteur_decoupage - ORDER BY quartier_id - ) sd ON sd.quartier_id = q.id - JOIN secteur sect ON sect.id = sd.secteur_id - JOIN section ses ON ses.id = sect.section_id - JOIN "structure" st ON st.id = ses.structure_id - JOIN batiment b ON b.parcelle_id = p.id - JOIN ( - SELECT DISTINCT ON (batiment_id) - batiment_id, - superficie_au_sol, - nombre_piscine, - categorie_batiment_id, - date_enquete, - montant_locatif_annuel_declare, - montant_locatif_annuel_calcule, - montant_locatif_annuel_estime, - date_debut_excemption, - date_fin_excemption, - valeur_batiment_reel, - valeur_batiment_calcule, - valeur_batiment_estime, - u.categorie_usage - FROM enquete_batiment eb - join usage u on u.id=eb.usage_id - ORDER BY batiment_id, date_enquete DESC, eb.id DESC -) eb ON eb.batiment_id = b.id - JOIN unite_logement ul on ul.batiment_id = b.id - JOIN ( - SELECT DISTINCT ON (eult.unite_logement_id) - eult.unite_logement_id, - pers1.id, - pers1.ifu, - pers1.npi, - pers1.tel1, - pers1.email, - pers1.nom, - pers1.prenom, - pers1.raison_sociale, - pers1.adresse, - eult.nombre_piscine, - eult.categorie_batiment_id, - eult.superficie_au_sol, - eult.superficie_louee, - eult.nbre_piece, - eult.date_enquete, - eult.montant_locatif_annuel_calcule, - eult.montant_locatif_annuel_declare, - eult.montant_locatif_annuel_estime, - eult.date_debut_exemption, - eult.date_fin_exemption, - eult.representant_nom, - eult.representant_prenom, - eult.representant_tel, - eult.valeur_unite_logement_reel, - eult.valeur_unite_logement_calcule, - eult.valeur_unite_logement_estime, - u.categorie_usage - FROM enquete_unite_logement eult - join usage u on u.id=eult.usage_id - left join personne pers1 on pers1.id = eult.personne_id - where superficie_louee*montant_locatif_annuel_declare>0 - ORDER BY unite_logement_id, date_enquete DESC, eult.id DESC -) eul ON eul.unite_logement_id = ul.id - JOIN categorie_batiment cb - ON cb.id = eul.categorie_batiment_id - JOIN LATERAL ( - SELECT * - FROM barem_rfu_bati br - WHERE br.categorie_batiment_id = cb.id - AND br.arrondissement_id = a.id - AND (br.quartier_id = q.id OR br.quartier_id IS NULL) - ORDER BY br.quartier_id DESC NULLS LAST - LIMIT 1 -) brb ON TRUE -WHERE p.batie = TRUE - AND EXISTS ( - SELECT 1 - FROM unite_logement ul - WHERE ul.batiment_id = b.id - ) - AND st.id = v_structure_id -ON CONFLICT DO NOTHING; - -GET DIAGNOSTICS v_rows_inserted = ROW_COUNT; - -UPDATE donnees_imposition_tfu dtfu -SET - valeur_locative_adm=montant_loyer_annuel, - montant_taxe = montant_loyer_annuel * v_taux_irf/100 -WHERE impositions_tfu_id = p_impositions_tfu_id - AND batie = TRUE - AND EXISTS ( - SELECT 1 - FROM unite_logement ul - WHERE ul.batiment_id = dtfu.batiment_id -); -RETURN v_rows_inserted; -END; -$$; - - */ - CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie_unite_logement( p_impositions_tfu_id BIGINT, p_user_id BIGINT diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/audit/HistoriqueConnexionRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/audit/HistoriqueConnexionRepository.java new file mode 100755 index 0000000..d232002 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/audit/HistoriqueConnexionRepository.java @@ -0,0 +1,71 @@ +package io.gmss.fiscad.persistence.repositories.audit; + +import io.gmss.fiscad.entities.audit.HistoriqueConnexion; +import io.gmss.fiscad.entities.decoupage.Arrondissement; +import io.gmss.fiscad.entities.decoupage.Commune; +import io.gmss.fiscad.paylaods.request.crudweb.ArrondissementPaylaodWeb; +import io.gmss.fiscad.paylaods.request.crudweb.HistoriqueConnexionPaylaodWeb; +import io.gmss.fiscad.paylaods.response.ArrondissementEnqResponse; +import io.gmss.fiscad.paylaods.response.synchronisation.ArrondissementSyncResponse; +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; + +public interface HistoriqueConnexionRepository extends JpaRepository { + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.HistoriqueConnexionPaylaodWeb( + h.id, + h.dateConnexion, + h.user.id, + h.user.username, + h.user.nom, + h.user.prenom + ) + FROM HistoriqueConnexion h + ORDER BY h.dateConnexion DESC + """) + List findHistoriqueConnexion(); + + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.HistoriqueConnexionPaylaodWeb( + h.id, + h.dateConnexion, + h.user.id, + h.user.username, + h.user.nom, + h.user.prenom + ) + FROM HistoriqueConnexion h + WHERE h.user.id = :userId + ORDER BY h.dateConnexion DESC + """) + List findHistoriqueConnexionByUserId( + @Param("userId") Long userId + ); + + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.HistoriqueConnexionPaylaodWeb( + h.id, + h.dateConnexion, + h.user.id, + h.user.username, + h.user.nom, + h.user.prenom + ) + FROM HistoriqueConnexion h + WHERE h.user.id = :userId + ORDER BY h.dateConnexion DESC + """) + List findTop5HistoriqueConnexionByUserId( + @Param("userId") Long userId, + Pageable pageable + ); +} diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/ArrondissementRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/ArrondissementRepository.java index 1e1e6d1..a96b422 100755 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/ArrondissementRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/ArrondissementRepository.java @@ -70,6 +70,25 @@ public interface ArrondissementRepository extends JpaRepository findArrondissementToDtoById(@Param("arrondissementId") Long arrondissementId); + + +// @Query(""" +// SELECT new io.gmss.fiscad.paylaods.request.crudweb.ArrondissementPaylaodWeb( +// arr.id, +// arr.code, +// arr.nom, +// com.id, +// com.code, +// com.nom +// ) +// FROM Parcelle p +// INNER JOIN p.quartier q +// INNER JOIN q.arrondissement arr +// INNER JOIN arr.commune com +// WHERE p.id = :parcelleId +// """) +// Optional findArrondissementToDtoByQuartierId(@Param("quartierId") Long quartierId); + @Query( value = """ SELECT new io.gmss.fiscad.paylaods.request.crudweb.ArrondissementPaylaodWeb( diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/metier/DonneesImpositionTfuRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/metier/DonneesImpositionTfuRepository.java index ae27a9a..170e274 100755 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/metier/DonneesImpositionTfuRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/metier/DonneesImpositionTfuRepository.java @@ -201,6 +201,9 @@ SELECT new io.gmss.fiscad.paylaods.request.crudweb.DonneesImpositionPaylaodWeb( ); + + + @Query(""" SELECT new io.gmss.fiscad.paylaods.request.crudweb.DonneesImpositionPaylaodWeb( d.id, @@ -876,4 +879,16 @@ SELECT new io.gmss.fiscad.paylaods.request.crudweb.DonneesImpositionPaylaodWeb( List findAllByPersonneId( @Param("personneId") Long personneId ); + + + @Query(""" + SELECT COUNT(d) > 0 + FROM DonneesImpositionTfu d + WHERE d.annee = :annee + AND d.parcelleImposee.id = :parcelleId +""") + boolean existsByImpositionAnneeAndParcelle( + @Param("annee") Long annee, + @Param("parcelleId") Long parcelleId + ); } diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/parametre/BaremRfuNonBatiRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/parametre/BaremRfuNonBatiRepository.java index 1858c5a..50f00ce 100644 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/parametre/BaremRfuNonBatiRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/parametre/BaremRfuNonBatiRepository.java @@ -143,5 +143,25 @@ Optional findAllByCommune_IdAndZoneRfu_Id(Long communeId,Long z @Param("communeId") Long communeId, @Param("zoneId") Long zoneId ); + + + @Query(""" + SELECT COUNT(barem) > 0 + FROM Parcelle p + JOIN p.quartier q + JOIN q.arrondissement a + JOIN Enquete ep + ON ep.parcelle=p + JOIN BaremRfuNonBati barem + ON (barem.commune = a.commune) + WHERE p.id = :parcelleId + AND ep.dateEnquete = ( + SELECT MAX(ep2.dateEnquete) + FROM Enquete ep2 + WHERE ep2.parcelle = p + ) + AND barem.zoneRfu = ep.zoneRfu +""") + boolean existsBaremForParcelleNonBati(@Param("parcelleId") Long parcelleId); } diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/parametre/BaremRfuRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/parametre/BaremRfuRepository.java index 36ff193..73647eb 100644 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/parametre/BaremRfuRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/parametre/BaremRfuRepository.java @@ -252,5 +252,29 @@ public interface BaremRfuRepository extends JpaRepository { @Param("quartierId") Long quartierId, @Param("categorieBatimentId") Long categorieBatimentId ); + + + + @Query(""" + SELECT COUNT(barem) > 0 + FROM Parcelle p + JOIN p.quartier q + JOIN q.arrondissement a + JOIN Batiment b + ON b.parcelle = p + JOIN EnqueteBatiment eb + ON eb.batiment=b + JOIN BaremRfuBati barem + ON (barem.quartier = q OR barem.arrondissement = a) + WHERE p.id = :parcelleId + AND eb.dateEnquete = ( + SELECT MAX(eb2.dateEnquete) + FROM EnqueteBatiment eb2 + WHERE eb2.batiment = b + ) + AND barem.categorieBatiment = eb.categorieBatiment +""") + boolean existsBaremForParcelle(@Param("parcelleId") Long parcelleId); + }