Sync: code local unifié
Synchronisation du code source local (fait foi). Signed-off-by: lions dev Team
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
package dev.lions.unionflow.server.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import dev.lions.unionflow.server.api.enums.membre.StatutMembre;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* Lien entre un utilisateur et une organisation.
|
||||
*
|
||||
* <p>Un utilisateur peut adhérer à plusieurs organisations simultanément.
|
||||
* Chaque adhésion a son propre statut, date et unité d'affectation.
|
||||
*
|
||||
* <p>Table : {@code membres_organisations}
|
||||
*/
|
||||
@Entity
|
||||
@Table(
|
||||
name = "membres_organisations",
|
||||
indexes = {
|
||||
@Index(name = "idx_mo_utilisateur", columnList = "utilisateur_id"),
|
||||
@Index(name = "idx_mo_organisation", columnList = "organisation_id"),
|
||||
@Index(name = "idx_mo_statut", columnList = "statut_membre"),
|
||||
@Index(name = "idx_mo_unite", columnList = "unite_id")
|
||||
},
|
||||
uniqueConstraints = {
|
||||
@UniqueConstraint(
|
||||
name = "uk_mo_utilisateur_organisation",
|
||||
columnNames = {"utilisateur_id", "organisation_id"})
|
||||
})
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MembreOrganisation extends BaseEntity {
|
||||
|
||||
/** L'utilisateur (identité globale) */
|
||||
@NotNull
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "utilisateur_id", nullable = false)
|
||||
private Membre membre;
|
||||
|
||||
/** L'organisation racine à laquelle appartient ce membre */
|
||||
@NotNull
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "organisation_id", nullable = false)
|
||||
private Organisation organisation;
|
||||
|
||||
/**
|
||||
* Unité d'affectation (agence/bureau).
|
||||
* NULL = affecté au siège.
|
||||
*/
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "unite_id")
|
||||
private Organisation unite;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Builder.Default
|
||||
@Column(name = "statut_membre", nullable = false, length = 30)
|
||||
private StatutMembre statutMembre = StatutMembre.EN_ATTENTE_VALIDATION;
|
||||
|
||||
@Column(name = "date_adhesion")
|
||||
private LocalDate dateAdhesion;
|
||||
|
||||
@Column(name = "date_changement_statut")
|
||||
private LocalDate dateChangementStatut;
|
||||
|
||||
@Column(name = "motif_statut", length = 500)
|
||||
private String motifStatut;
|
||||
|
||||
/** Utilisateur qui a approuvé ou traité ce changement de statut */
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "approuve_par_id")
|
||||
private Membre approuvePar;
|
||||
|
||||
// ── Relations ─────────────────────────────────────────────────────────────
|
||||
|
||||
/** Rôles de ce membre dans cette organisation */
|
||||
@JsonIgnore
|
||||
@OneToMany(mappedBy = "membreOrganisation", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@Builder.Default
|
||||
private List<MembreRole> roles = new ArrayList<>();
|
||||
|
||||
/** Ayants droit (mutuelles de santé uniquement) */
|
||||
@JsonIgnore
|
||||
@OneToMany(mappedBy = "membreOrganisation", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@Builder.Default
|
||||
private List<AyantDroit> ayantsDroit = new ArrayList<>();
|
||||
|
||||
// ── Méthodes métier ────────────────────────────────────────────────────────
|
||||
|
||||
public boolean isActif() {
|
||||
return StatutMembre.ACTIF.equals(statutMembre) && Boolean.TRUE.equals(getActif());
|
||||
}
|
||||
|
||||
public boolean peutDemanderAide() {
|
||||
return StatutMembre.ACTIF.equals(statutMembre);
|
||||
}
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
super.onCreate();
|
||||
if (statutMembre == null) {
|
||||
statutMembre = StatutMembre.EN_ATTENTE_VALIDATION;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user