|
| 1 | +package com.loopers.batch.domain.ranking; |
| 2 | + |
| 3 | +import com.loopers.infrastructure.converter.YearMonthAttributeConverter; |
| 4 | +import jakarta.persistence.*; |
| 5 | +import lombok.Getter; |
| 6 | +import lombok.NoArgsConstructor; |
| 7 | + |
| 8 | +import java.time.YearMonth; |
| 9 | + |
| 10 | +@Entity |
| 11 | +@Getter |
| 12 | +@Table( |
| 13 | + name = "mv_product_rank_monthly", |
| 14 | + indexes = { |
| 15 | + @Index(name = "idx_monthPeriod", columnList = "month_period"), |
| 16 | + @Index(name = "idx_score", columnList = "score") |
| 17 | + }, |
| 18 | + uniqueConstraints = { |
| 19 | + @UniqueConstraint(name = "uq_monthly_rank", columnNames = {"product_id", "month_period"}) |
| 20 | + } |
| 21 | +) |
| 22 | +@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED) |
| 23 | +public class MonthlyRanking { |
| 24 | + |
| 25 | + @Id |
| 26 | + @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 27 | + private Long id; |
| 28 | + |
| 29 | + @Column(name = "monthly_rank") |
| 30 | + private int rank; |
| 31 | + |
| 32 | + private Long productId; |
| 33 | + |
| 34 | + private double score; |
| 35 | + |
| 36 | + @Convert(converter = YearMonthAttributeConverter.class) |
| 37 | + @Column(name = "month_period") |
| 38 | + private YearMonth monthPeriod; |
| 39 | + |
| 40 | + public static MonthlyRanking create(int rank, Long productId, double score, YearMonth yearMonth) { |
| 41 | + MonthlyRanking monthlyRanking = new MonthlyRanking(); |
| 42 | + |
| 43 | + monthlyRanking.rank = rank; |
| 44 | + monthlyRanking.productId = productId; |
| 45 | + monthlyRanking.score = score; |
| 46 | + monthlyRanking.monthPeriod = yearMonth; |
| 47 | + |
| 48 | + return monthlyRanking; |
| 49 | + } |
| 50 | +} |
0 commit comments