package com.snp.batch.global.model; import jakarta.persistence.*; import lombok.*; import java.time.LocalDate; import java.time.LocalDateTime; /** * Bypass API 계정 정보를 저장하는 엔티티 * 외부 사용자에게 Bypass API 접근 권한을 부여하기 위한 계정 정보 관리 * * JPA를 사용하므로 @PrePersist, @PreUpdate로 감사 필드 자동 설정 */ @Entity @Table(name = "bypass_api_account", indexes = { @Index(name = "idx_bypass_account_username", columnList = "username"), @Index(name = "idx_bypass_account_status", columnList = "status") } ) @Getter @Setter @Builder @NoArgsConstructor @AllArgsConstructor public class BypassApiAccount { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; /** * 로그인 아이디 (고유값) */ @Column(name = "username", nullable = false, unique = true, length = 50) private String username; /** * 해시된 비밀번호 */ @Column(name = "password_hash", nullable = false, length = 255) private String passwordHash; /** * 표시명 */ @Column(name = "display_name", nullable = false, length = 100) private String displayName; /** * 소속 기관 */ @Column(name = "organization", length = 200) private String organization; /** * 이메일 */ @Column(name = "email", length = 200) private String email; /** * 연락처 */ @Column(name = "phone", length = 50) private String phone; /** * 계정 상태 (ACTIVE, SUSPENDED, EXPIRED) */ @Enumerated(EnumType.STRING) @Column(name = "status", nullable = false, length = 20) @Builder.Default private AccountStatus status = AccountStatus.ACTIVE; /** * 접근 허용 시작일 */ @Column(name = "access_start_date") private LocalDate accessStartDate; /** * 접근 허용 종료일 */ @Column(name = "access_end_date") private LocalDate accessEndDate; /** * 생성 일시 (감사 필드) */ @Column(name = "created_at", nullable = false, updatable = false) private LocalDateTime createdAt; /** * 수정 일시 (감사 필드) */ @Column(name = "updated_at", nullable = false) private LocalDateTime updatedAt; /** * 엔티티 저장 전 자동 호출 (INSERT 시) */ @PrePersist protected void onCreate() { LocalDateTime now = LocalDateTime.now(); this.createdAt = now; this.updatedAt = now; } /** * 엔티티 업데이트 전 자동 호출 (UPDATE 시) */ @PreUpdate protected void onUpdate() { this.updatedAt = LocalDateTime.now(); } }