Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
37651 vikas 1
package com.spice.profitmandi.dao.entity.user;
2
 
3
import com.spice.profitmandi.dao.enumuration.dtr.MetaLeadOutcome;
4
 
5
import javax.persistence.Column;
6
import javax.persistence.Entity;
7
import javax.persistence.EnumType;
8
import javax.persistence.Enumerated;
9
import javax.persistence.GeneratedValue;
10
import javax.persistence.GenerationType;
11
import javax.persistence.Id;
12
import javax.persistence.Lob;
13
import javax.persistence.Table;
14
import javax.persistence.UniqueConstraint;
15
import java.time.LocalDateTime;
16
 
17
/**
18
 * One row of a Meta lead-ads export, and what the import did with it.
19
 *
20
 * <p>Serves three jobs at once:
21
 *
22
 * <ul>
23
 *   <li><b>Idempotency.</b> {@code meta_lead_id} is Meta's own id — unique and stable — so
24
 *       re-uploading the same file, or an overlapping export, creates nothing twice. The existing
25
 *       lead CSV import ({@code /csvFileAndSetLead}) has no dedupe at all and silently doubles every
26
 *       lead on a second upload; this is the fix for that class of mistake.</li>
27
 *   <li><b>Accounting.</b> Every row gets a row here whatever happened to it, so a 60-row file
28
 *       always adds up to 60 and "where did that lead go?" has an answer.</li>
29
 *   <li><b>Attribution.</b> Campaign, form and placement are kept so lead quality can later be
30
 *       compared across campaigns — the reason for running the ads in the first place.</li>
31
 * </ul>
32
 *
33
 * <p>{@code raw_row} holds the original row verbatim as JSON. Mapping is lossy by nature (a business
34
 * -value band becomes a number, a name gets split), and the source file will not be around in six
35
 * months; keeping the original means a mapping bug can be replayed rather than merely regretted.
36
 */
37
@Entity
38
@Table(name = "user.meta_lead",
39
        uniqueConstraints = {@UniqueConstraint(columnNames = "meta_lead_id")})
40
public class MetaLead {
41
 
42
    @Id
43
    @Column(name = "id", unique = true, updatable = false)
44
    @GeneratedValue(strategy = GenerationType.IDENTITY)
45
    private int id;
46
 
47
    /** Meta's own lead id. The idempotency key — unique, and stable across exports. */
48
    @Column(name = "meta_lead_id")
49
    private String metaLeadId;
50
 
51
    @Column(name = "import_batch_id")
52
    private Integer importBatchId;
53
 
54
    /** The lead this became. Null for every outcome except CREATED. */
55
    @Column(name = "lead_id")
56
    private Integer leadId;
57
 
58
    @Column(name = "outcome")
59
    @Enumerated(EnumType.STRING)
60
    private MetaLeadOutcome outcome;
61
 
62
    /** Why it was skipped or rejected. Null on CREATED. */
63
    @Column(name = "reason")
64
    private String reason;
65
 
66
    @Column(name = "campaign_name")
67
    private String campaignName;
68
 
69
    @Column(name = "form_name")
70
    private String formName;
71
 
72
    /** {@code fb} or {@code ig} — which placement produced the lead. */
73
    @Column(name = "platform")
74
    private String platform;
75
 
76
    /** When Meta captured the lead, as opposed to when we imported it. */
77
    @Column(name = "meta_created_time")
78
    private LocalDateTime metaCreatedTime;
79
 
80
    /** The original row as JSON, so a mapping bug can be replayed rather than guessed at. */
81
    @Lob
82
    @Column(name = "raw_row")
83
    private String rawRow;
84
 
85
    @Column(name = "created_timestamp")
86
    private LocalDateTime createdTimestamp;
87
 
88
    public int getId() {
89
        return id;
90
    }
91
 
92
    public void setId(int id) {
93
        this.id = id;
94
    }
95
 
96
    public String getMetaLeadId() {
97
        return metaLeadId;
98
    }
99
 
100
    public void setMetaLeadId(String metaLeadId) {
101
        this.metaLeadId = metaLeadId;
102
    }
103
 
104
    public Integer getImportBatchId() {
105
        return importBatchId;
106
    }
107
 
108
    public void setImportBatchId(Integer importBatchId) {
109
        this.importBatchId = importBatchId;
110
    }
111
 
112
    public Integer getLeadId() {
113
        return leadId;
114
    }
115
 
116
    public void setLeadId(Integer leadId) {
117
        this.leadId = leadId;
118
    }
119
 
120
    public MetaLeadOutcome getOutcome() {
121
        return outcome;
122
    }
123
 
124
    public void setOutcome(MetaLeadOutcome outcome) {
125
        this.outcome = outcome;
126
    }
127
 
128
    public String getReason() {
129
        return reason;
130
    }
131
 
132
    public void setReason(String reason) {
133
        this.reason = reason;
134
    }
135
 
136
    public String getCampaignName() {
137
        return campaignName;
138
    }
139
 
140
    public void setCampaignName(String campaignName) {
141
        this.campaignName = campaignName;
142
    }
143
 
144
    public String getFormName() {
145
        return formName;
146
    }
147
 
148
    public void setFormName(String formName) {
149
        this.formName = formName;
150
    }
151
 
152
    public String getPlatform() {
153
        return platform;
154
    }
155
 
156
    public void setPlatform(String platform) {
157
        this.platform = platform;
158
    }
159
 
160
    public LocalDateTime getMetaCreatedTime() {
161
        return metaCreatedTime;
162
    }
163
 
164
    public void setMetaCreatedTime(LocalDateTime metaCreatedTime) {
165
        this.metaCreatedTime = metaCreatedTime;
166
    }
167
 
168
    public String getRawRow() {
169
        return rawRow;
170
    }
171
 
172
    public void setRawRow(String rawRow) {
173
        this.rawRow = rawRow;
174
    }
175
 
176
    public LocalDateTime getCreatedTimestamp() {
177
        return createdTimestamp;
178
    }
179
 
180
    public void setCreatedTimestamp(LocalDateTime createdTimestamp) {
181
        this.createdTimestamp = createdTimestamp;
182
    }
183
 
184
    @Override
185
    public String toString() {
186
        return "MetaLead [metaLeadId=" + metaLeadId + ", outcome=" + outcome + ", leadId=" + leadId + "]";
187
    }
188
}