Notification.java
2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.ecommerce.notification.model;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import java.time.LocalDateTime;
@Data
@NoArgsConstructor
@Entity
@Table(name = "notifications")
public class Notification {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(name = "notification_id", unique = true, nullable = false)
    private String notificationId;
    
    @Column(name = "user_id")
    private Long userId;
    
    @Column(name = "email")
    private String email;
    
    @Column(name = "phone")
    private String phone;
    
    @Column(name = "device_token")
    private String deviceToken;
    
    @Column(name = "type", nullable = false)
    private String type; // EMAIL, SMS, PUSH, IN_APP
    
    @Column(name = "channel", nullable = false)
    private String channel; // ORDER, PAYMENT, SHIPPING, PROMOTION, SYSTEM
    
    @Column(name = "template_name")
    private String templateName;
    
    @Column(name = "subject")
    private String subject;
    
    @Column(name = "content", columnDefinition = "TEXT")
    private String content;
    
    @Column(name = "status", nullable = false)
    private String status = "PENDING"; // PENDING, SENT, FAILED, DELIVERED, READ
    
    @Column(name = "priority")
    private String priority = "MEDIUM"; // LOW, MEDIUM, HIGH, URGENT
    
    @Column(name = "reference_type")
    private String referenceType; // ORDER, PAYMENT, USER
    
    @Column(name = "reference_id")
    private String referenceId;
    
    @Column(name = "metadata", columnDefinition = "TEXT")
    private String metadata;
    
    @Column(name = "failure_reason")
    private String failureReason;
    
    @Column(name = "retry_count")
    private Integer retryCount = 0;
    
    @Column(name = "max_retries")
    private Integer maxRetries = 3;
    
    @CreationTimestamp
    @Column(name = "created_at")
    private LocalDateTime createdAt;
    
    @Column(name = "sent_at")
    private LocalDateTime sentAt;
    
    @Column(name = "delivered_at")
    private LocalDateTime deliveredAt;
    
    @Column(name = "read_at")
    private LocalDateTime readAt;
    
    @PrePersist
    protected void onCreate() {
        if (notificationId == null) {
            notificationId = generateNotificationId();
        }
    }
    
    private String generateNotificationId() {
        return "NOTIF" + System.currentTimeMillis() + (int)(Math.random() * 1000);
    }
}