Configure Maven repository for unionflow-server-api dependency
This commit is contained in:
130
src/main/java/dev/lions/unionflow/server/entity/DemandeAide.java
Normal file
130
src/main/java/dev/lions/unionflow/server/entity/DemandeAide.java
Normal file
@@ -0,0 +1,130 @@
|
||||
package dev.lions.unionflow.server.entity;
|
||||
|
||||
import dev.lions.unionflow.server.api.enums.solidarite.StatutAide;
|
||||
import dev.lions.unionflow.server.api.enums.solidarite.TypeAide;
|
||||
import jakarta.persistence.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/** Entité représentant une demande d'aide dans le système de solidarité */
|
||||
@Entity
|
||||
@Table(name = "demandes_aide")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DemandeAide extends BaseEntity {
|
||||
|
||||
@Column(name = "titre", nullable = false, length = 200)
|
||||
private String titre;
|
||||
|
||||
@Column(name = "description", nullable = false, columnDefinition = "TEXT")
|
||||
private String description;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "type_aide", nullable = false)
|
||||
private TypeAide typeAide;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "statut", nullable = false)
|
||||
private StatutAide statut;
|
||||
|
||||
@Column(name = "montant_demande", precision = 10, scale = 2)
|
||||
private BigDecimal montantDemande;
|
||||
|
||||
@Column(name = "montant_approuve", precision = 10, scale = 2)
|
||||
private BigDecimal montantApprouve;
|
||||
|
||||
@Column(name = "date_demande", nullable = false)
|
||||
private LocalDateTime dateDemande;
|
||||
|
||||
@Column(name = "date_evaluation")
|
||||
private LocalDateTime dateEvaluation;
|
||||
|
||||
@Column(name = "date_versement")
|
||||
private LocalDateTime dateVersement;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "demandeur_id", nullable = false)
|
||||
private Membre demandeur;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "evaluateur_id")
|
||||
private Membre evaluateur;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "organisation_id", nullable = false)
|
||||
private Organisation organisation;
|
||||
|
||||
@Column(name = "justification", columnDefinition = "TEXT")
|
||||
private String justification;
|
||||
|
||||
@Column(name = "commentaire_evaluation", columnDefinition = "TEXT")
|
||||
private String commentaireEvaluation;
|
||||
|
||||
@Column(name = "urgence", nullable = false)
|
||||
@Builder.Default
|
||||
private Boolean urgence = false;
|
||||
|
||||
@Column(name = "documents_fournis")
|
||||
private String documentsFournis;
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
super.onCreate(); // Appelle le onCreate de BaseEntity
|
||||
if (dateDemande == null) {
|
||||
dateDemande = LocalDateTime.now();
|
||||
}
|
||||
if (statut == null) {
|
||||
statut = StatutAide.EN_ATTENTE;
|
||||
}
|
||||
if (urgence == null) {
|
||||
urgence = false;
|
||||
}
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
protected void onUpdate() {
|
||||
// Méthode appelée avant mise à jour
|
||||
}
|
||||
|
||||
/** Vérifie si la demande est en attente */
|
||||
public boolean isEnAttente() {
|
||||
return StatutAide.EN_ATTENTE.equals(statut);
|
||||
}
|
||||
|
||||
/** Vérifie si la demande est approuvée */
|
||||
public boolean isApprouvee() {
|
||||
return StatutAide.APPROUVEE.equals(statut);
|
||||
}
|
||||
|
||||
/** Vérifie si la demande est rejetée */
|
||||
public boolean isRejetee() {
|
||||
return StatutAide.REJETEE.equals(statut);
|
||||
}
|
||||
|
||||
/** Vérifie si la demande est urgente */
|
||||
public boolean isUrgente() {
|
||||
return Boolean.TRUE.equals(urgence);
|
||||
}
|
||||
|
||||
/** Calcule le pourcentage d'approbation par rapport au montant demandé */
|
||||
public BigDecimal getPourcentageApprobation() {
|
||||
if (montantDemande == null || montantDemande.compareTo(BigDecimal.ZERO) == 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
if (montantApprouve == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return montantApprouve
|
||||
.divide(montantDemande, 4, RoundingMode.HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(100));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user