diff --git a/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CommuneCentreAssignationController.java b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CommuneCentreAssignationController.java new file mode 100644 index 0000000..26bd8e4 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/controllers/rfu/metier/CommuneCentreAssignationController.java @@ -0,0 +1,279 @@ +package io.gmss.fiscad.controllers.rfu.metier; + + +import io.gmss.fiscad.entities.user.User; +import io.gmss.fiscad.exceptions.*; +import io.gmss.fiscad.implementations.infocad.metier.PersonneServiceImpl; +import io.gmss.fiscad.interfaces.rfu.metier.CommuneCentreAssignationService; +import io.gmss.fiscad.paylaods.ApiResponse; +import io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb; +import io.gmss.fiscad.security.CurrentUser; +import io.gmss.fiscad.security.UserPrincipal; +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 lombok.AllArgsConstructor; +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.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; + + +@RestController +@AllArgsConstructor +@RequestMapping(value = "api/commune-centre-assignation", produces = MediaType.APPLICATION_JSON_VALUE) +@SecurityRequirement(name = "bearer") +@Tag(name = "CommuneCentreAssignation") +@CrossOrigin(origins = "*") +public class CommuneCentreAssignationController { + + private final CommuneCentreAssignationService communeCentreAssignationService; + private final PersonneServiceImpl personneService; + + private static final Logger logger = LoggerFactory.getLogger(CommuneCentreAssignationController.class); + +// public CommuneCentreAssignationController(CommuneCentreAssignationService communeCentreAssignationService) { +// this.communeCentreAssignationService = communeCentreAssignationService; +// } + + @PostMapping("/assigne-centre") + public ResponseEntity AssigneCommuneCentre(@CurrentUser UserPrincipal userPrincipal, @RequestBody CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) { + try { + if(userPrincipal==null){ + return new ResponseEntity<>( + new ApiResponse<>(false, null, "vous ne pouvez pas faire cette action."), + HttpStatus.OK + ); + } + User user = userPrincipal.getUser(); + communeCentreAssignationPaylaodWeb = communeCentreAssignationService.createCommuneCentreAssignation(user,communeCentreAssignationPaylaodWeb); + return new ResponseEntity<>( + new ApiResponse<>(true, communeCentreAssignationPaylaodWeb, "CommuneCentreAssignation créé 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); + } + } + + @PostMapping("/detache-centre") + public ResponseEntity detacheCommuneCentre(@CurrentUser UserPrincipal userPrincipal, @RequestBody CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) { + try { + if(userPrincipal==null){ + return new ResponseEntity<>( + new ApiResponse<>(false, null, "vous ne pouvez pas faire cette action."), + HttpStatus.OK + ); + } + User user = userPrincipal.getUser(); + communeCentreAssignationPaylaodWeb = communeCentreAssignationService.detacherCommuneCentreAssignation(user,communeCentreAssignationPaylaodWeb); + return new ResponseEntity<>( + new ApiResponse<>(true, communeCentreAssignationPaylaodWeb, "CommuneCentreAssignation créé 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); + } + } + + @PutMapping("/update/{id}") + public ResponseEntity updateCommuneCentreAssignation(@PathVariable Long id, @RequestBody CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, communeCentreAssignationService.updateCommuneCentreAssignation(id,communeCentreAssignationPaylaodWeb), "CommuneCentreAssignation mise à jour 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); + } + } + + @DeleteMapping("/delete/{id}") + public ResponseEntity deleteCommuneCentreAssignation(@PathVariable Long id) { + try { + communeCentreAssignationService.deleteCommuneCentreAssignation(id); + return new ResponseEntity<>( + new ApiResponse<>(true, "CommuneCentreAssignation supprimé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") + public ResponseEntity getAllCommuneCentreAssignationPaged(@RequestParam int pageNo, @RequestParam int pageSize) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, communeCentreAssignationService.getCommuneCentreAssignationList(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("/all-paged/by-commune-id/{communeId}") + public ResponseEntity getAllCommuneCentreAssignationByCommuneList(@PathVariable Long communeId,@RequestParam int pageNo, @RequestParam int pageSize ) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, communeCentreAssignationService.getCommuneCentreAssignationListByCommunePageable(communeId,pageable), "Liste des assignation de centre 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 getCommuneCentreAssignationById(@PathVariable Long id) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, communeCentreAssignationService.getCommuneCentreAssignationById(id), "CommuneCentreAssignation trouvé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); + } + } + + @Operation(summary = "Liste des contribuables ayant un centre d'assignation") + @GetMapping("/all-paged/by-structure-id/{structureId}") + public ResponseEntity getAllCommuneCentreAssignationByStrucutrePaged(@PathVariable Long structureId, @RequestParam int pageNo, @RequestParam int pageSize) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, communeCentreAssignationService.getCommuneCentreAssignationListByCentrePageable(structureId, pageable), "Liste des communeCentreAssignations 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); + } + } + + + @Operation(summary = "Liste des contribuables sans centre d'assignation") + @GetMapping("/all-paged/sans-centre-assignation") + public ResponseEntity getAllPersonneSansCentreAssignationPaged(@RequestParam int pageNo, @RequestParam int pageSize) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, personneService.getPersonneListNonAssigneePage(pageable), "Liste des contribuables sans centre d'assignation 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/entities/infocad/parametre/Personne.java b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Personne.java index fb062e0..d982129 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Personne.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Personne.java @@ -41,6 +41,7 @@ public class Personne extends BaseEntity implements Serializable { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String ifu; + private String nc; private String nom; private String prenom; private String raisonSociale; diff --git a/src/main/java/io/gmss/fiscad/entities/rfu/metier/CommuneCentreAssignation.java b/src/main/java/io/gmss/fiscad/entities/rfu/metier/CommuneCentreAssignation.java index 929c2f5..68762c3 100644 --- a/src/main/java/io/gmss/fiscad/entities/rfu/metier/CommuneCentreAssignation.java +++ b/src/main/java/io/gmss/fiscad/entities/rfu/metier/CommuneCentreAssignation.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.gmss.fiscad.deserializer.LocalDateDeserializer; import io.gmss.fiscad.entities.BaseEntity; import io.gmss.fiscad.entities.decoupage.Commune; +import io.gmss.fiscad.entities.infocad.metier.Parcelle; import io.gmss.fiscad.entities.infocad.metier.Tpe; import io.gmss.fiscad.entities.infocad.parametre.Personne; import io.gmss.fiscad.entities.infocad.parametre.Structure; @@ -19,11 +20,19 @@ import lombok.NoArgsConstructor; import java.io.Serializable; import java.time.LocalDate; -@EqualsAndHashCode(callSuper = true) @Entity +@Table( + uniqueConstraints = { + @UniqueConstraint( + name = "uk_structure_commune_personne", + columnNames = {"structure_id", "commune_id", "personne_id"} + ) + } +) @Data @NoArgsConstructor @AllArgsConstructor +@EqualsAndHashCode(callSuper = true) public class CommuneCentreAssignation extends BaseEntity implements Serializable { @Id @@ -32,14 +41,25 @@ public class CommuneCentreAssignation extends BaseEntity implements Serializable @JsonIgnore @ManyToOne + @JoinColumn(name = "structure_id", nullable = false) private Structure structure; @JsonIgnore @ManyToOne + @JoinColumn(name = "commune_id", nullable = false) private Commune commune; @JsonIgnore @ManyToOne - private Personne personne ; + @JoinColumn(name = "personne_id") + private Personne personne; -} + @JsonIgnore + @ManyToOne + @JoinColumn(name = "parcelle_id") + private Parcelle parcelle; + + private String nc; + + private String ifu; +} \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/enums/UserProfile.java b/src/main/java/io/gmss/fiscad/enums/UserProfile.java index d5db6d2..e443ef4 100644 --- a/src/main/java/io/gmss/fiscad/enums/UserProfile.java +++ b/src/main/java/io/gmss/fiscad/enums/UserProfile.java @@ -3,7 +3,11 @@ package io.gmss.fiscad.enums; public enum UserProfile { INSPECTEUR_GESTIONNAIRE, ADMIN_FONCTIONNEL, + ADMIN_TECHNIQUE, + INSPECTEUR_GESTIONNAIRE_CHEF_SERVICE, + AGENT_CONSTATATION_ASSIETTE, + CONSULTATION, + ENQUETEUR, INSPECTEUR_GESTIONNAIRE_CHEF_SECTEUR, - INSPECTEUR_GESTIONNAIRE_CHEF_SECTION, INSPECTEUR_GESTIONNAIRE_CHEF_CENTRE } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/PersonneServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/PersonneServiceImpl.java index b8f015c..75d282f 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/PersonneServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/PersonneServiceImpl.java @@ -86,6 +86,11 @@ public class PersonneServiceImpl implements PersonneService { return null; } + @Override + public Page getPersonneListNonAssigneePage(Pageable pageable) { + return personneRepository.findAllPersonneNonAssigneCentreToDto(pageable); + } + @Override public List getPersonneList() { return null; diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CommuneCentreAssignationServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CommuneCentreAssignationServiceImpl.java new file mode 100644 index 0000000..55317e2 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/CommuneCentreAssignationServiceImpl.java @@ -0,0 +1,160 @@ +package io.gmss.fiscad.implementations.rfu.metier; + +import io.gmss.fiscad.entities.rfu.metier.CommuneCentreAssignation; +import io.gmss.fiscad.entities.user.User; +import io.gmss.fiscad.exceptions.BadRequestException; +import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.interfaces.rfu.metier.CommuneCentreAssignationService; +import io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb; +import io.gmss.fiscad.persistence.repositories.decoupage.CommuneRepository; +import io.gmss.fiscad.persistence.repositories.infocad.metier.ParcelleRepository; +import io.gmss.fiscad.persistence.repositories.infocad.parametre.PersonneRepository; +import io.gmss.fiscad.persistence.repositories.infocad.parametre.StructureRepository; +import io.gmss.fiscad.persistence.repositories.rfu.metier.CommuneCentreAssignationRepository; +import io.gmss.fiscad.service.EntityFromPayLoadService; +import lombok.AllArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@AllArgsConstructor +@Service +public class CommuneCentreAssignationServiceImpl implements CommuneCentreAssignationService { + + + private final EntityFromPayLoadService entityFromPayLoadService; + private final CommuneRepository communeRepository; + private final StructureRepository structureRepository ; + private final PersonneRepository personneRepository ; + private final ParcelleRepository parcelleRepository ; + private final CommuneCentreAssignationRepository communeCentreAssignationRepository; + + + @Override + public CommuneCentreAssignationPaylaodWeb createCommuneCentreAssignation(User user, CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) throws BadRequestException { + + if (user.getStructure() == null) { + throw new BadRequestException("Impossible de créer l'assignation: Votre centre doit être précisé."); + } + + if (user.getStructure().getCommune() == null) { + throw new BadRequestException("Impossible de créer un nouveau communeCentreAssignation: votre commune doit être précisée."); + } + + if (communeCentreAssignationPaylaodWeb.getPersonneId() == null) { + throw new BadRequestException("Impossible de créer un nouveau communeCentreAssignation: Le contribuable doit être précisée."); + }else { + if(!personneRepository.existsById(communeCentreAssignationPaylaodWeb.getPersonneId())) + throw new BadRequestException("Impossible de créer un nouveau communeCentreAssignation: Le contribuable doit être précisée."); + } + + if (communeCentreAssignationPaylaodWeb.getParcelleContactId() == null) { + throw new BadRequestException("Impossible de créer une nouvelle assignation de centre : La parcelle de contact doit être précisée."); + }else { + if(!parcelleRepository.existsById(communeCentreAssignationPaylaodWeb.getParcelleContactId())) + throw new BadRequestException("Impossible de créer une nouvelle assignation de centre: La parcelle précisée n'existe pas."); + } + + Optional communeCentreAssignationPaylaodWebOptional=communeCentreAssignationRepository.findbyCommuneAndPersonne(user.getStructure().getCommune().getId(),communeCentreAssignationPaylaodWeb.getPersonneId()); + if(communeCentreAssignationPaylaodWeb.getId()==null && communeCentreAssignationPaylaodWebOptional.isPresent()){ + throw new BadRequestException("Impossible de créer une nouvelle assignation de centre: Le contribuable est déjà assigné au centre : "+communeCentreAssignationPaylaodWebOptional.get().getStructureNom()); + } + + + CommuneCentreAssignation communeCentreAssignation= entityFromPayLoadService.getCommuneCentreAssignationFromPayLoadWeb(communeCentreAssignationPaylaodWeb); + communeCentreAssignation.setStructure(user.getStructure()); + communeCentreAssignation.setCommune(user.getStructure().getCommune()); + communeCentreAssignation= communeCentreAssignationRepository.save(communeCentreAssignation); + return communeCentreAssignationRepository.findUnique(communeCentreAssignation.getId()).orElse(null); + } + + @Override + public CommuneCentreAssignationPaylaodWeb updateCommuneCentreAssignation(Long id,CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) throws NotFoundException { + if (communeCentreAssignationPaylaodWeb.getId() == null) { + throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation ayant un id null."); + } + if (communeCentreAssignationPaylaodWeb.getCommuneId() == null) { + throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation: La commune doit être précisée."); + }else { + if(!communeRepository.existsById(communeCentreAssignationPaylaodWeb.getCommuneId())) + throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation: La commune doit être précisée."); + } + + if (communeCentreAssignationPaylaodWeb.getStructureId() == null) { + throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation: Le centre doit être précisée."); + }else { + if(!structureRepository.existsById(communeCentreAssignationPaylaodWeb.getStructureId())) + throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation: Le centre doit être précisée."); + } + + if (communeCentreAssignationPaylaodWeb.getPersonneId() == null) { + throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation: Le contribuable doit être précisée."); + }else { + if(!personneRepository.existsById(communeCentreAssignationPaylaodWeb.getPersonneId())) + throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation: Le contribuable doit être précisée."); + } + CommuneCentreAssignation communeCentreAssignation= entityFromPayLoadService.getCommuneCentreAssignationFromPayLoadWeb(communeCentreAssignationPaylaodWeb); + communeCentreAssignation= communeCentreAssignationRepository.save(communeCentreAssignation); + + return communeCentreAssignationRepository.findUnique(communeCentreAssignation.getId()).orElse(null); + } + + @Override + public CommuneCentreAssignationPaylaodWeb detacherCommuneCentreAssignation(User user, CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) throws NotFoundException { + if (communeCentreAssignationPaylaodWeb.getId() != null) { + throw new BadRequestException("Impossible de fait de detachement. L'assignation n'est pas précisée"); + } + Optional communeCentreAssignationOptional= communeCentreAssignationRepository.findById(communeCentreAssignationPaylaodWeb.getId()); + if (communeCentreAssignationOptional.isEmpty()) { + throw new BadRequestException("Impossible de fait de detachement. L'assignation n'est pas précisée"); + } + + if(communeCentreAssignationOptional.get().getStructure() != user.getStructure()){ + throw new BadRequestException("Impossible de fait de detachement. Le contribuable n'est pas rattaché à votre centre. Veuillez contracter : "+user.getStructure().getNom()); + } + communeCentreAssignationOptional.get().setStructure(null); + + CommuneCentreAssignation communeCentreAssignation = communeCentreAssignationRepository.save(communeCentreAssignationOptional.get()); + + return communeCentreAssignationRepository.findUnique(communeCentreAssignation.getId()).orElse(null); + + } + + @Override + public void deleteCommuneCentreAssignation(Long id) throws NotFoundException { + Optional communeCentreAssignationOptional = communeCentreAssignationRepository.findById(id); + if (communeCentreAssignationOptional.isPresent()) { + communeCentreAssignationRepository.deleteById(communeCentreAssignationOptional.get().getId()); + } else { + throw new NotFoundException("Impossible de trouver le communeCentreAssignation spécifié dans notre base de données."); + } + } + + @Override + public Page getCommuneCentreAssignationList(Pageable pageable) { + return communeCentreAssignationRepository.findAllPayload(pageable); + } + + @Override + public Page getCommuneCentreAssignationListByCommunePageable(Long communeId, Pageable pageable) { + return communeCentreAssignationRepository.findByCommuneId(communeId,pageable); + } + + @Override + public Optional getCommuneCentreAssignationById(Long id) { + if (communeCentreAssignationRepository.existsById(id)) { + return communeCentreAssignationRepository.findUnique(id); + } else { + throw new NotFoundException("Impossible de trouver le centre d'assignation spécifiée dans la base de données."); + } + } + + @Override + public Page getCommuneCentreAssignationListByCentrePageable(Long centreId, Pageable pageable) { + return communeCentreAssignationRepository.findByStructureId(centreId,pageable); + } + +} diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/PersonneService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/PersonneService.java index 7eff463..88e82f6 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/PersonneService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/PersonneService.java @@ -21,6 +21,7 @@ public interface PersonneService { void deletePersonne(Long id) throws NotFoundException; Page getPersonneList(Pageable pageable); + Page getPersonneListNonAssigneePage(Pageable pageable); List getPersonneList(); diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CommuneCentreAssignationService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CommuneCentreAssignationService.java new file mode 100755 index 0000000..ec579ad --- /dev/null +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/CommuneCentreAssignationService.java @@ -0,0 +1,34 @@ +package io.gmss.fiscad.interfaces.rfu.metier; + +import io.gmss.fiscad.entities.user.User; +import io.gmss.fiscad.exceptions.BadRequestException; +import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.List; +import java.util.Optional; + +public interface CommuneCentreAssignationService { + + CommuneCentreAssignationPaylaodWeb createCommuneCentreAssignation(User user, CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) throws BadRequestException; + + CommuneCentreAssignationPaylaodWeb updateCommuneCentreAssignation(Long id,CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) throws NotFoundException; + CommuneCentreAssignationPaylaodWeb detacherCommuneCentreAssignation(User user,CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) throws NotFoundException; + + void deleteCommuneCentreAssignation(Long id) throws NotFoundException; + + Page getCommuneCentreAssignationList(Pageable pageable); + + + Page getCommuneCentreAssignationListByCommunePageable(Long communeId, Pageable pageable); + + + + Optional getCommuneCentreAssignationById(Long id); + + + Page getCommuneCentreAssignationListByCentrePageable(Long centreId, Pageable pageable); + +} diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/CommuneCentreAssignationPaylaodWeb.java b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/CommuneCentreAssignationPaylaodWeb.java new file mode 100644 index 0000000..1528edb --- /dev/null +++ b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/CommuneCentreAssignationPaylaodWeb.java @@ -0,0 +1,54 @@ +package io.gmss.fiscad.paylaods.request.crudweb; + +import lombok.Data; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@Data +public class CommuneCentreAssignationPaylaodWeb { + private Long id; + private String code; + private String nom; + private Long communeId; + private String communeCode; + private String communeNom; + private Long structureId; + private String structureCode; + private String structureNom; + private Long personneId; + private String personneNom; + private String personnePrenom; + private String personneRaisonSociale; + private String personneIfu; + private String personneNc; + private String personneNpi; + private Long parcelleContactId; + private String parcelleContactQuartierCode; + private String parcelleContactQ; + private String parcelleContactI; + private String parcelleContactP; + + public CommuneCentreAssignationPaylaodWeb(Long id, String code, String nom, Long communeId, String communeCode, String communeNom, Long structureId, String structureCode, String structureNom, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale, String personneIfu, String personneNc, String personneNpi, Long parcelleContactId, String parcelleContactQuartierCode, String parcelleContactQ, String parcelleContactI, String parcelleContactP) { + this.id = id; + this.code = code; + this.nom = nom; + this.communeId = communeId; + this.communeCode = communeCode; + this.communeNom = communeNom; + this.structureId = structureId; + this.structureCode = structureCode; + this.structureNom = structureNom; + this.personneId = personneId; + this.personneNom = personneNom; + this.personnePrenom = personnePrenom; + this.personneRaisonSociale = personneRaisonSociale; + this.personneIfu = personneIfu; + this.personneNc = personneNc; + this.personneNpi = personneNpi; + this.parcelleContactId = parcelleContactId; + this.parcelleContactQuartierCode = parcelleContactQuartierCode; + this.parcelleContactQ = parcelleContactQ; + this.parcelleContactI = parcelleContactI; + this.parcelleContactP = parcelleContactP; + } +} diff --git a/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/export_donnee_imposition_vers_sigibe.sql b/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/export_donnee_imposition_vers_sigibe.sql new file mode 100644 index 0000000..0ad54d8 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/export_donnee_imposition_vers_sigibe.sql @@ -0,0 +1,119 @@ +----------------- + +create or replace view e_avis_view as +WITH first_parcelle_imposition AS ( + SELECT DISTINCT ON (personne_id) + personne_id, + parcelle_id + FROM donnees_imposition_tfu + ORDER BY personne_id, annee,parcelle_id +), + cca_unique AS ( + SELECT DISTINCT ON (cc.commune_id, cc.personne_id) + cc.structure_id, + cc.personne_id, + cc.commune_id, + COALESCE(qu.code, qu_imp.code) AS r_quartier_contact, + COALESCE(parc.q, parc_imp.q) AS q_contact, + COALESCE(parc.i, parc_imp.i) AS i_contact, + COALESCE(parc.p, parc_imp.p) AS p_contact + + FROM commune_centre_assignation cc + + LEFT JOIN parcelle parc + ON parc.id = cc.parcelle_id + + LEFT JOIN quartier qu + ON qu.id = parc.quartier_id + + LEFT JOIN first_parcelle_imposition dpi + ON dpi.personne_id = cc.personne_id + + LEFT JOIN parcelle parc_imp + ON parc_imp.id = dpi.parcelle_id + + LEFT JOIN quartier qu_imp + ON qu_imp.id = parc_imp.quartier_id + ORDER BY cc.commune_id, cc.personne_id, cc.structure_id +) +SELECT distinct + null as id_avis, + concat(c.code,'-',dimp.ifu,'-',exo.annee) as r_avis, + exo.annee as exercice, + c.code as r_commune, + st.code as r_centre_impot, + dimp.personne_id as id_contribuable_foncier, + dimp.ifu as ifu, + dimp.npi as npi, + dimp.ifu as nc, + dimp.raison_sociale as raison_sociale, + dimp.nom_prop as nom , + dimp.prenom_prop as prenom, + imp.date_generation as date_liquidation, + current_date as date_information, + cca.r_quartier_contact, + cca.q_contact, + cca.i_contact, + cca.p_contact +FROM impositions_tfu imp + INNER JOIN donnees_imposition_tfu dimp + ON dimp.impositions_tfu_id = imp.id + LEFT JOIN exercice exo + ON exo.id = imp.exercice_id + LEFT JOIN commune c + ON c.id = imp.commune_id + LEFT JOIN cca_unique cca + ON cca.personne_id = dimp.personne_id + AND cca.commune_id = imp.commune_id + LEFT JOIN structure st + ON st.id = cca.structure_id +order by c.code,st.code,r_quartier_contact,i_contact,p_contact; + + +select * from e_avis_view; + +--left join structure st2 on st2.id=imp.structure_id; + +create or replace view e_avis_detail_view as +WITH cca_unique AS ( + SELECT DISTINCT ON (personne_id, commune_id) + structure_id, + personne_id, + commune_id + FROM commune_centre_assignation + ORDER BY commune_id,personne_id,structure_id +) +SELECT + null as id_avis_detail, + null as id_avis, + dimp.id as id_externe_ligne_imposition, + concat(c.code,'-',dimp.ifu,'-',exo.annee) as r_avis, + dimp.nature_impot as id_impot_nature, + dimp.parcelle_id as id_unite_foncier, + dimp.nup as nup, + dimp.code_quartier_village as r_quartier, + dimp.q as qip_quartier, + dimp.ilot as qip_ilot, + dimp.parcelle as qip_parcelle, + dimp.num_batiment as batiment, + dimp.num_unite_logement as unite_logement, + case + when dimp.batie = false then dimp.valeur_admin_parcelle_nb + else dimp.valeur_locative_adm + end as montant_base_imposition, + dimp.valeur_locative_adm as montant_valeur_locative, + dimp.taux_tfu as taux, + dimp.montant_taxe as montant_du +FROM impositions_tfu imp + INNER JOIN donnees_imposition_tfu dimp + ON dimp.impositions_tfu_id = imp.id + LEFT JOIN exercice exo + ON exo.id = imp.exercice_id + LEFT JOIN commune c + ON c.id = imp.commune_id + LEFT JOIN cca_unique cca + ON cca.personne_id = dimp.personne_id + AND cca.commune_id = imp.commune_id + LEFT JOIN structure st + ON st.id = cca.structure_id + where dimp.personne_id is not null ; diff --git a/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/export_parcelles_vers_sigibe.sql b/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/export_parcelles_vers_sigibe.sql new file mode 100644 index 0000000..8f052f4 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/export_parcelles_vers_sigibe.sql @@ -0,0 +1,5 @@ +----------------- + +create or replace view parcelle_view as +select distinct q.code as r_quartier,q.nom,p.nup, p.q,p.i,p.p from parcelle p +inner join quartier q on q.id=p.quartier_id \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/import_assignation_personne_cotonou.sql b/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/import_assignation_personne_cotonou.sql index 04fa7e9..0a6fa9f 100644 --- a/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/import_assignation_personne_cotonou.sql +++ b/src/main/java/io/gmss/fiscad/persistence/procedure_fonction_stocke/import_assignation_personne_cotonou.sql @@ -7,7 +7,7 @@ SELECT dblink_connect( --SELECT dblink_disconnect('connexion_rfu'); --SELECT pg_size_pretty(pg_database_size('rfu')); -CREATE OR REPLACE PROCEDURE public.import_personne_from_rfu() +CREATE OR REPLACE PROCEDURE public.import_assignation_centre_personne_from_rfu_cotonou() LANGUAGE plpgsql AS $procedure$ BEGIN @@ -16,7 +16,8 @@ INSERT INTO public.commune_centre_assignation ( ifu, commune_id, structure_id, - + personne_id, + parcelle_id, created_at, created_by, deleted, @@ -25,16 +26,18 @@ INSERT INTO public.commune_centre_assignation ( source ) SELECT - n0_contrib, - ifu, - 77, - case centre - when 'A' then c.nom_c - when 'B' then c.nom - when 'C' then c.nom_c - when 'D' then c.nom - else null + c.n0_contrib, + c.ifu, + 70, + case rcdi + when 'A' then 61 + when 'B' then 62 + when 'C' then 63 + when 'D' then 64 + else null end, + pers.id, + parc.id, now(), NULL::bigint, false, @@ -44,35 +47,49 @@ SELECT FROM dblink( 'connexion_rfu', $db$ - SELECT - ifu, - n0_contrib, - centre, - profession + SELECT distinct on (ifu,rcdi) + trim(ifu), + trim(n0_contrib), + trim(rcdi), + trim(quartier_c), + trim(ilot_c), + trim(parcel_c) FROM stemichel.contrib - -- WHERE ifu IS NOT NULL - $db$ + order by ifu,rcdi + $db$ ) AS c ( - date_nais varchar, ifu varchar, - lieu_nais varchar, - nom varchar, - prenoms varchar, - nom_c varchar, - prenoms_c varchar, - autradr1 varchar, - autradr2 varchar, + n0_contrib varchar, + rcdi varchar, quartier_c varchar, ilot_c varchar, - parcel_c varchar, - n0_contrib varchar, - sexe varchar, - profession varchar + parcel_c varchar ) +LEFT JOIN personne pers on trim(pers.ifu)=trim(c.ifu) +LEFT JOIN parcelle parc on (trim(parc.q) = trim(c.quartier_c) + and trim(parc.i) = trim(c.ilot_c) + and trim(parc.p) = trim(c.parcel_c)) WHERE NOT EXISTS ( SELECT 1 - FROM public.personne p - WHERE p.nc = c.n0_contrib -); + FROM public.commune_centre_assignation cca + WHERE cca.personne_id = pers.id + and cca.structure_id = case trim(c.rcdi) + when 'A' then 61 + when 'B' then 62 + when 'C' then 63 + when 'D' then 64 + else null + end + and cca.commune_id = 70 +) +ON CONFLICT (structure_id, commune_id, personne_id) DO NOTHING; + END; -$procedure$; \ No newline at end of file +$procedure$; + +call import_assignation_centre_personne_from_rfu_cotonou(); + +--delete from commune_centre_assignation; + + +--select * from commune_centre_assignation; diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/infocad/parametre/PersonneRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/infocad/parametre/PersonneRepository.java index b554e82..4d60c94 100755 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/infocad/parametre/PersonneRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/infocad/parametre/PersonneRepository.java @@ -263,4 +263,36 @@ public interface PersonneRepository extends JpaRepository { List findAllPersonneByNpiToDto( @Param("npi") String npi ); + + + @Query(value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.PersonnePayLoadWeb( + p.id, + p.ifu, + p.nom, + p.prenom, + p.raisonSociale, + p.numRavip, + p.npi, + p.dateNaissanceOuConsti, + p.lieuNaissance, + p.tel1, + p.nomJeuneFille, + p.nomMere, + p.etatIdentificationPersonne + ) + FROM Personne p + where not exists ( + select 1 from CommuneCentreAssignation cca + where cca.personne.id=p.id) + """, + countQuery = """ + SELECT COUNT(p) + FROM Personne p + where not exists ( + select 1 from CommuneCentreAssignation cca + where cca.personne.id=p.id) + """ + ) + Page findAllPersonneNonAssigneCentreToDto(Pageable pageable); } diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/metier/CommuneCentreAssignationRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/metier/CommuneCentreAssignationRepository.java new file mode 100755 index 0000000..bba87b2 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/rfu/metier/CommuneCentreAssignationRepository.java @@ -0,0 +1,311 @@ +package io.gmss.fiscad.persistence.repositories.rfu.metier; + +import io.gmss.fiscad.entities.rfu.metier.Batiment; +import io.gmss.fiscad.entities.rfu.metier.CommuneCentreAssignation; +import io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb; +import io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb; +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; + + +public interface CommuneCentreAssignationRepository extends JpaRepository { + @Query( + value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb( + cca.id, + cca.nc, + cca.ifu, + c.id, + c.code, + c.nom, + s.id, + s.code, + s.nom, + p.id, + p.nom, + p.prenom, + p.raisonSociale, + p.ifu, + p.nc, + p.npi, + parc.id, + q.code, + parc.q, + parc.i, + parc.p + ) + FROM CommuneCentreAssignation cca + LEFT JOIN cca.commune c + LEFT JOIN cca.structure s + LEFT JOIN cca.personne p + LEFT JOIN cca.parcelle parc + LEFT JOIN parc.quartier q + """, + countQuery = """ + SELECT COUNT(cca.id) + FROM CommuneCentreAssignation cca + """ + ) + Page findAllPayload(Pageable pageable); + + @Query( + value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb( + cca.id, + cca.nc, + cca.ifu, + c.id, + c.code, + c.nom, + s.id, + s.code, + s.nom, + p.id, + p.nom, + p.prenom, + p.raisonSociale, + p.ifu, + p.nc, + p.npi, + parc.id, + q.code, + parc.q, + parc.i, + parc.p + ) + FROM CommuneCentreAssignation cca + JOIN cca.structure s + LEFT JOIN cca.commune c + LEFT JOIN cca.personne p + LEFT JOIN cca.parcelle parc + LEFT JOIN parc.quartier q + WHERE s.id = :structureId + """, + countQuery = """ + SELECT COUNT(cca.id) + FROM CommuneCentreAssignation cca + WHERE cca.structure.id = :structureId + """ + ) + Page findByStructureId( + Long structureId, + Pageable pageable + ); + + + @Query( + value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb( + cca.id, + cca.nc, + cca.ifu, + c.id, + c.code, + c.nom, + s.id, + s.code, + s.nom, + p.id, + p.nom, + p.prenom, + p.raisonSociale, + p.ifu, + p.nc, + p.npi, + parc.id, + q.code, + parc.q, + parc.i, + parc.p + ) + FROM CommuneCentreAssignation cca + JOIN cca.commune c + LEFT JOIN cca.structure s + LEFT JOIN cca.personne p + LEFT JOIN cca.parcelle parc + LEFT JOIN parc.quartier q + WHERE c.id = :communeId + """, + countQuery = """ + SELECT COUNT(cca.id) + FROM CommuneCentreAssignation cca + WHERE cca.commune.id = :communeId + """ + ) + Page findByCommuneId( + Long communeId, + Pageable pageable + ); + + @Query( + value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb( + cca.id, + cca.nc, + cca.ifu, + c.id, + c.code, + c.nom, + s.id, + s.code, + s.nom, + p.id, + p.nom, + p.prenom, + p.raisonSociale, + p.ifu, + p.nc, + p.npi, + parc.id, + q.code, + parc.q, + parc.i, + parc.p + ) + FROM CommuneCentreAssignation cca + JOIN cca.structure s + JOIN cca.commune c + LEFT JOIN cca.personne p + LEFT JOIN cca.parcelle parc + LEFT JOIN parc.quartier q + WHERE s.id = :structureId + AND c.id = :communeId + """, + countQuery = """ + SELECT COUNT(cca.id) + FROM CommuneCentreAssignation cca + WHERE cca.structure.id = :structureId + AND cca.commune.id = :communeId + """ + ) + Page findByStructureAndCommune( + Long structureId, + Long communeId, + Pageable pageable + ); + + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb( + cca.id, + cca.nc, + cca.ifu, + c.id, + c.code, + c.nom, + s.id, + s.code, + s.nom, + p.id, + p.nom, + p.prenom, + p.raisonSociale, + p.ifu, + p.nc, + p.npi, + parc.id, + q.code, + parc.q, + parc.i, + parc.p + ) + FROM CommuneCentreAssignation cca + JOIN cca.structure s + JOIN cca.commune c + JOIN cca.personne p + LEFT JOIN cca.parcelle parc + LEFT JOIN parc.quartier q + WHERE s.id = :structureId + AND c.id = :communeId + AND p.id = :personneId + """) + Optional findUnique( + Long structureId, + Long communeId, + Long personneId + ); + + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb( + cca.id, + cca.nc, + cca.ifu, + c.id, + c.code, + c.nom, + s.id, + s.code, + s.nom, + p.id, + p.nom, + p.prenom, + p.raisonSociale, + p.ifu, + p.nc, + p.npi, + parc.id, + q.code, + parc.q, + parc.i, + parc.p + ) + FROM CommuneCentreAssignation cca + JOIN cca.structure s + JOIN cca.commune c + JOIN cca.personne p + LEFT JOIN cca.parcelle parc + LEFT JOIN parc.quartier q + WHERE cca.id = :id + """) + Optional findUnique( + Long id + ); + + + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb( + cca.id, + cca.nc, + cca.ifu, + c.id, + c.code, + c.nom, + s.id, + s.code, + s.nom, + p.id, + p.nom, + p.prenom, + p.raisonSociale, + p.ifu, + p.nc, + p.npi, + parc.id, + q.code, + parc.q, + parc.i, + parc.p + ) + FROM CommuneCentreAssignation cca + JOIN cca.structure s + JOIN cca.commune c + JOIN cca.personne p + LEFT JOIN cca.parcelle parc + LEFT JOIN parc.quartier q + WHERE c.id = :communeId + AND p.id = :personneId + """) + Optional findbyCommuneAndPersonne( + Long communeId, + Long personneId + ); +} diff --git a/src/main/java/io/gmss/fiscad/service/EntityFromPayLoadService.java b/src/main/java/io/gmss/fiscad/service/EntityFromPayLoadService.java index 4c6390d..2efbbe0 100644 --- a/src/main/java/io/gmss/fiscad/service/EntityFromPayLoadService.java +++ b/src/main/java/io/gmss/fiscad/service/EntityFromPayLoadService.java @@ -74,6 +74,7 @@ public class EntityFromPayLoadService { private final RueRepository rueRepository ; private final NatureDomaineRepository natureDomaineRepository ; private final TypeDomaineRepository typeDomaineRepository ; + private final CommuneCentreAssignationRepository communeCentreAssignationRepository ; public CaracteristiqueParcelle getCaracteristiqueParcelleFromPayLoadWeb(CaracteristiqueParcellePayloadWeb caracteristiqueParcellePayloadWeb){ @@ -997,4 +998,36 @@ public class EntityFromPayLoadService { parcelle.setSuperficie(parcellePayLoadWeb.getSuperficie()); return parcelle; } + + public CommuneCentreAssignation getCommuneCentreAssignationFromPayLoadWeb(CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) { + CommuneCentreAssignation communeCentreAssignation = new CommuneCentreAssignation(); + if (communeCentreAssignationPaylaodWeb.getId()!=null) + communeCentreAssignation=communeCentreAssignationRepository.findById(communeCentreAssignationPaylaodWeb.getId()).orElse(new CommuneCentreAssignation()); + + if (communeCentreAssignationPaylaodWeb.getPersonneId() != null) { + Personne personne = new Personne(); + personne.setId(communeCentreAssignationPaylaodWeb.getPersonneId()); + communeCentreAssignation.setPersonne(personne); + } + +// if (communeCentreAssignationPaylaodWeb.getCommuneId() != null) { +// Commune commune = new Commune(); +// commune.setId(communeCentreAssignationPaylaodWeb.getCommuneId()); +// communeCentreAssignation.setCommune(commune); +// } + +// if (communeCentreAssignationPaylaodWeb.getStructureId() != null) { +// Structure structure = new Structure(); +// structure.setId(communeCentreAssignationPaylaodWeb.getStructureId()); +// communeCentreAssignation.setStructure(structure); +// } + + if (communeCentreAssignationPaylaodWeb.getParcelleContactId() != null) { + Parcelle parcelle = new Parcelle(); + parcelle.setId(communeCentreAssignationPaylaodWeb.getParcelleContactId()); + communeCentreAssignation.setParcelle(parcelle); + } + + return communeCentreAssignation; + } }