Subversion Repositories SmartDukaan

Rev

Rev 25503 | Rev 26685 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
22600 ashik.ali 1
package com.spice.profitmandi.dao.entity.catalog;
2
 
3
import java.io.Serializable;
4
import java.time.LocalDateTime;
22859 ashik.ali 5
import java.time.format.DateTimeFormatter;
23339 ashik.ali 6
import java.util.HashMap;
22859 ashik.ali 7
import java.util.HashSet;
23339 ashik.ali 8
import java.util.Map;
22859 ashik.ali 9
import java.util.Set;
22600 ashik.ali 10
 
11
import javax.persistence.Column;
12
import javax.persistence.Convert;
13
import javax.persistence.Entity;
23297 ashik.ali 14
import javax.persistence.EnumType;
15
import javax.persistence.Enumerated;
22600 ashik.ali 16
import javax.persistence.GeneratedValue;
17
import javax.persistence.GenerationType;
18
import javax.persistence.Id;
19
import javax.persistence.Table;
22859 ashik.ali 20
import javax.persistence.Transient;
22600 ashik.ali 21
 
22
import com.spice.profitmandi.dao.convertor.LocalDateTimeAttributeConverter;
25503 amit.gupta 23
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
23527 ashik.ali 24
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
22653 ashik.ali 25
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
22600 ashik.ali 26
 
27
/**
28
 * This class basically contains scheme details
29
 * 
30
 * @author ashikali
31
 *
32
 */
33
@Entity
25503 amit.gupta 34
@Table(name = "catalog.scheme", schema = "catalog")
35
public class Scheme implements Serializable {
36
 
37
	public PartnerType getPartnerType() {
38
		return partnerType;
39
	}
40
 
41
	public void setPartnerType(PartnerType partnerType) {
42
		this.partnerType = partnerType;
43
	}
44
 
22600 ashik.ali 45
	private static final long serialVersionUID = 1L;
25503 amit.gupta 46
 
22600 ashik.ali 47
	public Scheme() {
48
	}
25503 amit.gupta 49
 
22600 ashik.ali 50
	@Id
25503 amit.gupta 51
	@Column(name = "id")
22600 ashik.ali 52
	@GeneratedValue(strategy = GenerationType.IDENTITY)
53
	private int id;
25503 amit.gupta 54
 
22653 ashik.ali 55
	@Column(name = "name")
56
	private String name;
25503 amit.gupta 57
 
22653 ashik.ali 58
	@Column(name = "description")
59
	private String description;
25503 amit.gupta 60
 
22653 ashik.ali 61
	@Column(name = "type")
23297 ashik.ali 62
	@Enumerated(EnumType.STRING)
22653 ashik.ali 63
	private SchemeType type;
25503 amit.gupta 64
 
22600 ashik.ali 65
	@Column(name = "amount_type")
23297 ashik.ali 66
	@Enumerated(EnumType.STRING)
23527 ashik.ali 67
	private AmountType amountType;
25503 amit.gupta 68
 
22600 ashik.ali 69
	@Column(name = "amount")
70
	private float amount;
25503 amit.gupta 71
 
22600 ashik.ali 72
	@Convert(converter = LocalDateTimeAttributeConverter.class)
23019 ashik.ali 73
	@Column(name = "start_date_time")
74
	private LocalDateTime startDateTime = LocalDateTime.now();
25503 amit.gupta 75
 
22600 ashik.ali 76
	@Convert(converter = LocalDateTimeAttributeConverter.class)
23019 ashik.ali 77
	@Column(name = "end_date_time")
78
	private LocalDateTime endDateTime = LocalDateTime.now();
25503 amit.gupta 79
 
22608 ashik.ali 80
	@Convert(converter = LocalDateTimeAttributeConverter.class)
22600 ashik.ali 81
	@Column(name = "create_timestamp")
22859 ashik.ali 82
	private LocalDateTime createTimestamp = LocalDateTime.now();
25503 amit.gupta 83
 
22653 ashik.ali 84
	@Convert(converter = LocalDateTimeAttributeConverter.class)
85
	@Column(name = "active_timestamp")
86
	private LocalDateTime activeTimestamp = null;
25503 amit.gupta 87
 
22653 ashik.ali 88
	@Convert(converter = LocalDateTimeAttributeConverter.class)
22702 ashik.ali 89
	@Column(name = "expire_timestamp")
22653 ashik.ali 90
	private LocalDateTime expireTimestamp = null;
25503 amit.gupta 91
 
22600 ashik.ali 92
	@Column(name = "created_by")
93
	private int createdBy;
25503 amit.gupta 94
 
26679 amit.gupta 95
	@Column
96
	private boolean cashBack;
97
 
22859 ashik.ali 98
	@Transient
99
	private Set<Integer> retailerIds = new HashSet<>();
25503 amit.gupta 100
 
101
	@Column(name="partner_type")
102
	@Enumerated(EnumType.STRING)
103
	private PartnerType partnerType;
104
 
22859 ashik.ali 105
	@Transient
23339 ashik.ali 106
	private Map<Integer, String> itemStringMap = new HashMap<>();
25503 amit.gupta 107
 
22600 ashik.ali 108
	public int getId() {
109
		return id;
110
	}
25503 amit.gupta 111
 
22600 ashik.ali 112
	public void setId(int id) {
113
		this.id = id;
114
	}
25503 amit.gupta 115
 
22653 ashik.ali 116
	public String getName() {
117
		return name;
22600 ashik.ali 118
	}
25503 amit.gupta 119
 
22653 ashik.ali 120
	public void setName(String name) {
121
		this.name = name;
22600 ashik.ali 122
	}
25503 amit.gupta 123
 
22653 ashik.ali 124
	public String getDescription() {
125
		return description;
22600 ashik.ali 126
	}
25503 amit.gupta 127
 
22653 ashik.ali 128
	public void setDescription(String description) {
129
		this.description = description;
22600 ashik.ali 130
	}
25503 amit.gupta 131
 
26679 amit.gupta 132
	public boolean isCashBack() {
133
		return cashBack;
134
	}
135
 
136
	public void setCashBack(boolean cashBack) {
137
		this.cashBack = cashBack;
138
	}
139
 
22653 ashik.ali 140
	public SchemeType getType() {
141
		return type;
142
	}
25503 amit.gupta 143
 
22653 ashik.ali 144
	public void setType(SchemeType type) {
145
		this.type = type;
146
	}
25503 amit.gupta 147
 
148
	@Override
149
	public String toString() {
150
		return "Scheme [id=" + id + ", name=" + name + ", description=" + description + ", type=" + type
151
				+ ", amountType=" + amountType + ", amount=" + amount + ", startDateTime=" + startDateTime
152
				+ ", endDateTime=" + endDateTime + ", createTimestamp=" + createTimestamp + ", activeTimestamp="
26679 amit.gupta 153
				+ activeTimestamp + ", expireTimestamp=" + expireTimestamp + ", createdBy=" + createdBy + ", cashBack="
154
				+ cashBack + ", retailerIds=" + retailerIds + ", partnerType=" + partnerType + ", itemStringMap="
155
				+ itemStringMap + "]";
25503 amit.gupta 156
	}
157
 
23527 ashik.ali 158
	public AmountType getAmountType() {
22600 ashik.ali 159
		return amountType;
160
	}
25503 amit.gupta 161
 
23527 ashik.ali 162
	public void setAmountType(AmountType amountType) {
22600 ashik.ali 163
		this.amountType = amountType;
164
	}
25503 amit.gupta 165
 
22600 ashik.ali 166
	public float getAmount() {
167
		return amount;
168
	}
25503 amit.gupta 169
 
22600 ashik.ali 170
	public void setAmount(float amount) {
171
		this.amount = amount;
172
	}
25503 amit.gupta 173
 
23019 ashik.ali 174
	public LocalDateTime getStartDateTime() {
175
		return startDateTime;
22600 ashik.ali 176
	}
25503 amit.gupta 177
 
23019 ashik.ali 178
	public void setStartDateTime(LocalDateTime startDateTime) {
179
		this.startDateTime = startDateTime;
22600 ashik.ali 180
	}
25503 amit.gupta 181
 
23019 ashik.ali 182
	public LocalDateTime getEndDateTime() {
183
		return endDateTime;
22653 ashik.ali 184
	}
25503 amit.gupta 185
 
23019 ashik.ali 186
	public void setEndDateTime(LocalDateTime endDateTime) {
187
		this.endDateTime = endDateTime;
22653 ashik.ali 188
	}
25503 amit.gupta 189
 
22859 ashik.ali 190
	public LocalDateTime getCreateTimestamp() {
191
		return createTimestamp;
22600 ashik.ali 192
	}
25503 amit.gupta 193
 
22859 ashik.ali 194
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
195
		this.createTimestamp = createTimestamp;
22600 ashik.ali 196
	}
25503 amit.gupta 197
 
22600 ashik.ali 198
	public int getCreatedBy() {
199
		return createdBy;
200
	}
25503 amit.gupta 201
 
22600 ashik.ali 202
	public void setCreatedBy(int createdBy) {
203
		this.createdBy = createdBy;
204
	}
25503 amit.gupta 205
 
22653 ashik.ali 206
	public LocalDateTime getActiveTimestamp() {
207
		return activeTimestamp;
22600 ashik.ali 208
	}
25503 amit.gupta 209
 
22653 ashik.ali 210
	public void setActiveTimestamp(LocalDateTime activeTimestamp) {
211
		this.activeTimestamp = activeTimestamp;
22600 ashik.ali 212
	}
25503 amit.gupta 213
 
22653 ashik.ali 214
	public LocalDateTime getExpireTimestamp() {
215
		return expireTimestamp;
216
	}
25503 amit.gupta 217
 
22653 ashik.ali 218
	public void setExpireTimestamp(LocalDateTime expireTimestamp) {
219
		this.expireTimestamp = expireTimestamp;
220
	}
25503 amit.gupta 221
 
222
	public String getFormattedStartDateTime() {
223
		if (startDateTime == null) {
22859 ashik.ali 224
			return null;
225
		}
24402 amit.gupta 226
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
23019 ashik.ali 227
		return startDateTime.format(formatter);
25503 amit.gupta 228
	}
229
 
230
	public String getFormattedEndDateTime() {
231
		if (endDateTime == null) {
22859 ashik.ali 232
			return null;
233
		}
24402 amit.gupta 234
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
23019 ashik.ali 235
		return endDateTime.format(formatter);
25503 amit.gupta 236
	}
237
 
238
	public String getFormattedCreateTimestamp() {
239
		if (createTimestamp == null) {
22859 ashik.ali 240
			return null;
241
		}
24402 amit.gupta 242
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
22859 ashik.ali 243
		return createTimestamp.format(formatter);
25503 amit.gupta 244
	}
245
 
246
	public String getFormattedActiveTimestamp() {
247
		if (activeTimestamp == null) {
22859 ashik.ali 248
			return null;
249
		}
24402 amit.gupta 250
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
22859 ashik.ali 251
		return activeTimestamp.format(formatter);
25503 amit.gupta 252
	}
253
 
254
	public String getFormattedExpireTimestamp() {
255
		if (expireTimestamp == null) {
22859 ashik.ali 256
			return null;
257
		}
24402 amit.gupta 258
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
22859 ashik.ali 259
		return expireTimestamp.format(formatter);
25503 amit.gupta 260
	}
261
 
22859 ashik.ali 262
	public Set<Integer> getRetailerIds() {
263
		return retailerIds;
264
	}
25503 amit.gupta 265
 
22859 ashik.ali 266
	public void setRetailerIds(Set<Integer> retailerIds) {
267
		this.retailerIds = retailerIds;
268
	}
25503 amit.gupta 269
 
270
	public String getRetailerIdsString() {
22859 ashik.ali 271
		Set<String> stringRetailerIds = new HashSet<>();
25503 amit.gupta 272
		if (!retailerIds.isEmpty()) {
273
			for (int retailerId : retailerIds) {
22859 ashik.ali 274
				stringRetailerIds.add(String.valueOf(retailerId));
275
			}
276
		}
277
		return String.join(", ", stringRetailerIds);
278
	}
25503 amit.gupta 279
 
23339 ashik.ali 280
	public Map<Integer, String> getItemStringMap() {
281
		return itemStringMap;
22859 ashik.ali 282
	}
25503 amit.gupta 283
 
23339 ashik.ali 284
	public void setItemStringMap(Map<Integer, String> itemStringMap) {
285
		this.itemStringMap = itemStringMap;
22859 ashik.ali 286
	}
25503 amit.gupta 287
 
288
	/*
289
	 * public String getItemIdsString(){ Set<String> stringItemIds = new
290
	 * HashSet<>(); if(!itemIds.isEmpty()){ for(int itemId : itemIds){
291
	 * stringItemIds.add(String.valueOf(itemId)); } } return String.join(", ",
292
	 * stringItemIds); }
293
	 */
294
 
22600 ashik.ali 295
	@Override
296
	public int hashCode() {
297
		final int prime = 31;
298
		int result = 1;
26679 amit.gupta 299
		result = prime * result + ((activeTimestamp == null) ? 0 : activeTimestamp.hashCode());
300
		result = prime * result + Float.floatToIntBits(amount);
301
		result = prime * result + ((amountType == null) ? 0 : amountType.hashCode());
302
		result = prime * result + (cashBack ? 1231 : 1237);
303
		result = prime * result + ((createTimestamp == null) ? 0 : createTimestamp.hashCode());
304
		result = prime * result + createdBy;
305
		result = prime * result + ((description == null) ? 0 : description.hashCode());
306
		result = prime * result + ((endDateTime == null) ? 0 : endDateTime.hashCode());
307
		result = prime * result + ((expireTimestamp == null) ? 0 : expireTimestamp.hashCode());
22600 ashik.ali 308
		result = prime * result + id;
26679 amit.gupta 309
		result = prime * result + ((itemStringMap == null) ? 0 : itemStringMap.hashCode());
310
		result = prime * result + ((name == null) ? 0 : name.hashCode());
311
		result = prime * result + ((partnerType == null) ? 0 : partnerType.hashCode());
312
		result = prime * result + ((retailerIds == null) ? 0 : retailerIds.hashCode());
313
		result = prime * result + ((startDateTime == null) ? 0 : startDateTime.hashCode());
314
		result = prime * result + ((type == null) ? 0 : type.hashCode());
22600 ashik.ali 315
		return result;
316
	}
25503 amit.gupta 317
 
22600 ashik.ali 318
	@Override
319
	public boolean equals(Object obj) {
320
		if (this == obj)
321
			return true;
322
		if (obj == null)
323
			return false;
324
		if (getClass() != obj.getClass())
325
			return false;
326
		Scheme other = (Scheme) obj;
26679 amit.gupta 327
		if (activeTimestamp == null) {
328
			if (other.activeTimestamp != null)
329
				return false;
330
		} else if (!activeTimestamp.equals(other.activeTimestamp))
331
			return false;
332
		if (Float.floatToIntBits(amount) != Float.floatToIntBits(other.amount))
333
			return false;
334
		if (amountType != other.amountType)
335
			return false;
336
		if (cashBack != other.cashBack)
337
			return false;
338
		if (createTimestamp == null) {
339
			if (other.createTimestamp != null)
340
				return false;
341
		} else if (!createTimestamp.equals(other.createTimestamp))
342
			return false;
343
		if (createdBy != other.createdBy)
344
			return false;
345
		if (description == null) {
346
			if (other.description != null)
347
				return false;
348
		} else if (!description.equals(other.description))
349
			return false;
350
		if (endDateTime == null) {
351
			if (other.endDateTime != null)
352
				return false;
353
		} else if (!endDateTime.equals(other.endDateTime))
354
			return false;
355
		if (expireTimestamp == null) {
356
			if (other.expireTimestamp != null)
357
				return false;
358
		} else if (!expireTimestamp.equals(other.expireTimestamp))
359
			return false;
22600 ashik.ali 360
		if (id != other.id)
361
			return false;
26679 amit.gupta 362
		if (itemStringMap == null) {
363
			if (other.itemStringMap != null)
364
				return false;
365
		} else if (!itemStringMap.equals(other.itemStringMap))
366
			return false;
367
		if (name == null) {
368
			if (other.name != null)
369
				return false;
370
		} else if (!name.equals(other.name))
371
			return false;
372
		if (partnerType != other.partnerType)
373
			return false;
374
		if (retailerIds == null) {
375
			if (other.retailerIds != null)
376
				return false;
377
		} else if (!retailerIds.equals(other.retailerIds))
378
			return false;
379
		if (startDateTime == null) {
380
			if (other.startDateTime != null)
381
				return false;
382
		} else if (!startDateTime.equals(other.startDateTime))
383
			return false;
384
		if (type != other.type)
385
			return false;
22600 ashik.ali 386
		return true;
387
	}
25503 amit.gupta 388
 
22600 ashik.ali 389
}