253 lines
14 KiB
Java
253 lines
14 KiB
Java
package io.gmss.fiscad.controllers.statistique;
|
|
|
|
import io.gmss.fiscad.enums.NiveauDecoupage;
|
|
import io.gmss.fiscad.enums.StatutEnquete;
|
|
import io.gmss.fiscad.exceptions.*;
|
|
import io.gmss.fiscad.interfaces.statistique.StatistiquesService;
|
|
import io.gmss.fiscad.paylaods.ApiResponse;
|
|
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 org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.client.HttpClientErrorException;
|
|
|
|
@RestController
|
|
@RequestMapping(value = "api/statistique", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
@SecurityRequirement(name = "bearer")
|
|
@Tag(name = "Statistique")
|
|
@CrossOrigin(origins = "*")
|
|
public class StatistiqueController {
|
|
private final StatistiquesService statistiquesService;
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(StatistiqueController.class);
|
|
|
|
public StatistiqueController(StatistiquesService statistiquesService) {
|
|
this.statistiquesService = statistiquesService;
|
|
}
|
|
|
|
@GetMapping(path = "/user/enquete-par-statut")
|
|
public ResponseEntity<?> getStatistiquesParStatut() {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, statistiquesService.getStatEnqueteParStatut(), "Statistique des enquêtes par statut."),
|
|
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(path = "/enquete-par-arrondissement/{commune_id}")
|
|
public ResponseEntity<?> getStatistiquesParArrondissement(@PathVariable Long commune_id) {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, statistiquesService.getStatEnqueteAdminDecoupage(commune_id), "Statistique des enquêtes par arrondissement."),
|
|
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(path = "/user/enquete-par-structure")
|
|
public ResponseEntity<?> getStatistiquesParStructure() {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, statistiquesService.getStatEnqueteAdminStructure(), "Statistique des enquêtes par structure."),
|
|
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(path = "/user/enquete-par-bloc")
|
|
public ResponseEntity<?> getStatistiquesParBloc() {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, statistiquesService.getStatBloc(), "Statistique des enquêtes par bloc."),
|
|
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 = "Statistique des immeubles",
|
|
description = "Donnes le nombre parcelle baties, parcelles non baties, batiments et unité de logement"
|
|
)
|
|
@GetMapping(path = "/immeubles/nombre-total/{codeDecoupage}")
|
|
public ResponseEntity<?> getStatistiquesObjets(@PathVariable String codeDecoupage) {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, statistiquesService.getStatNombreTotalObjet(codeDecoupage), "Statistique des immeubles par découpage admin."),
|
|
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 = "Statistique des personnes",
|
|
description = "Donnes le nombre de personne par type"
|
|
)
|
|
@GetMapping(path = "/personnes/nombre-par-type")
|
|
public ResponseEntity<?> getStatistiquesPeronnesParType() {
|
|
try {
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, statistiquesService.getStatNombrePersonneParCategorie(), "Statistique des personne par type."),
|
|
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 = "Statistique des enquetes en cours par object ",
|
|
description = "Donnes le nombre d'enquetes en coures par objet"
|
|
)
|
|
@GetMapping(path = "/nombre-enquete/par-objet/en-cours")
|
|
public ResponseEntity<?> getStatistiquesEnqueteEnCoursParObjet(@CurrentUser UserPrincipal currentUser) {
|
|
try {
|
|
if(currentUser==null)
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true,null, "Vous ne pouvez pas accéder à cette ressource"),
|
|
HttpStatus.OK
|
|
);
|
|
Long userId = currentUser.getUser().getId();
|
|
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, statistiquesService.getStatNombreEnqueteParObjetUserConnect(userId,StatutEnquete.EN_COURS.toString()), "Statistique des personne par type."),
|
|
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 = "Statistique des enquetes en cours par object ",
|
|
description = "Donnes le nombre d'enquetes en coures par objet"
|
|
)
|
|
@GetMapping(path = "/nombre-enquete/par-objet/cloture")
|
|
public ResponseEntity<?> getStatistiquesEnqueteClotureParObjet(@CurrentUser UserPrincipal currentUser) {
|
|
try {
|
|
if(currentUser==null)
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true,null, "Vous ne pouvez pas accéder à cette ressource"),
|
|
HttpStatus.OK
|
|
);
|
|
Long userId = currentUser.getUser().getId();
|
|
|
|
return new ResponseEntity<>(
|
|
new ApiResponse<>(true, statistiquesService.getStatNombreEnqueteParObjetUserConnect(userId, StatutEnquete.CLOTURE.toString()), "Statistique des personne par type."),
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
} |