snp-sync-batch/src/main/java/com/snp/batch/global/model/JobScheduleEntity.java
HYOJIN 744cc02f36 feat: snp-sync-batch 프로젝트 초기 설정
mda-snp-batch 기반으로 snp-sync-batch 프로젝트 생성
- 프론트엔드: Thymeleaf → React + TypeScript + Vite + Tailwind CSS 전환
- 컨텍스트: /snp-sync, 포트 8051
- 재수집(Recollection) 관련 코드 제거
- displayName → job_schedule.description 기반으로 전환
- 누락 API 추가 (statistics, jobs/detail, executions/recent)
- 실행 이력 조회 속도 개선 (JDBC 경량 쿼리)
- 스케줄 CRUD API 메서드 매핑 수정 (PUT/DELETE)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 13:33:31 +09:00

111 lines
2.7 KiB
Java

package com.snp.batch.global.model;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
/**
* 배치 작업 스케줄 정보를 저장하는 엔티티
* Quartz 스케줄러와 연동하여 DB에 영속화
*
* JPA를 사용하므로 @PrePersist, @PreUpdate로 감사 필드 자동 설정
*/
@Entity
@Table(name = "job_schedule", schema = "snp_batch", indexes = {
@Index(name = "idx_job_name", columnList = "job_name", unique = true),
@Index(name = "idx_active", columnList = "active")
})
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class JobScheduleEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
/**
* 배치 작업 이름 (BatchConfig에 등록된 Job Bean 이름)
* 예: "jsonToPostgresJob", "shipDataImportJob"
*/
@Column(name = "job_name", unique = true, nullable = false, length = 100)
private String jobName;
/**
* Cron 표현식
* 예: "0 0 2 * * ?" (매일 새벽 2시)
*/
@Column(name = "cron_expression", nullable = false, length = 100)
private String cronExpression;
/**
* 스케줄 설명
*/
@Column(name = "description", length = 500)
private String description;
/**
* 활성화 여부
* true: 스케줄 활성, false: 일시 중지
*/
@Column(name = "active", nullable = false)
@Builder.Default
private Boolean active = true;
/**
* 생성 일시 (감사 필드)
*/
@Column(name = "created_at", nullable = false, updatable = false)
private LocalDateTime createdAt;
/**
* 수정 일시 (감사 필드)
*/
@Column(name = "updated_at", nullable = false)
private LocalDateTime updatedAt;
/**
* 생성자 (감사 필드)
*/
@Column(name = "created_by", length = 100)
private String createdBy;
/**
* 수정자 (감사 필드)
*/
@Column(name = "updated_by", length = 100)
private String updatedBy;
/**
* 엔티티 저장 전 자동 호출 (INSERT 시)
*/
@PrePersist
protected void onCreate() {
LocalDateTime now = LocalDateTime.now();
this.createdAt = now;
this.updatedAt = now;
if (this.createdBy == null) {
this.createdBy = "SYSTEM";
}
if (this.updatedBy == null) {
this.updatedBy = "SYSTEM";
}
}
/**
* 엔티티 업데이트 전 자동 호출 (UPDATE 시)
*/
@PreUpdate
protected void onUpdate() {
this.updatedAt = LocalDateTime.now();
if (this.updatedBy == null) {
this.updatedBy = "SYSTEM";
}
}
}