Subversion Repositories SmartDukaan

Rev

Rev 22702 | Rev 23019 | 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;
6
import java.util.HashSet;
7
import java.util.Set;
22600 ashik.ali 8
 
9
import javax.persistence.Column;
10
import javax.persistence.Convert;
11
import javax.persistence.Entity;
12
import javax.persistence.GeneratedValue;
13
import javax.persistence.GenerationType;
14
import javax.persistence.Id;
15
import javax.persistence.Table;
22859 ashik.ali 16
import javax.persistence.Transient;
22600 ashik.ali 17
 
18
import com.spice.profitmandi.dao.convertor.LocalDateTimeAttributeConverter;
19
import com.spice.profitmandi.dao.enumuration.catalog.SchemeAmountType;
22653 ashik.ali 20
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
22600 ashik.ali 21
 
22
/**
23
 * This class basically contains scheme details
24
 * 
25
 * @author ashikali
26
 *
27
 */
28
@Entity
22653 ashik.ali 29
@Table(name="catalog.scheme", schema = "catalog")
22600 ashik.ali 30
public class Scheme implements Serializable{
31
 
32
	private static final long serialVersionUID = 1L;
33
 
34
	public Scheme() {
35
	}
36
 
37
	@Id
38
	@Column(name="id")
39
	@GeneratedValue(strategy = GenerationType.IDENTITY)
40
	private int id;
41
 
22653 ashik.ali 42
	@Column(name = "name")
43
	private String name;
22600 ashik.ali 44
 
22653 ashik.ali 45
	@Column(name = "description")
46
	private String description;
22600 ashik.ali 47
 
22653 ashik.ali 48
	@Column(name = "type")
49
	private SchemeType type;
50
 
22600 ashik.ali 51
	@Column(name = "amount_type")
52
	private SchemeAmountType amountType;
53
 
54
	@Column(name = "amount")
55
	private float amount;
56
 
57
	@Convert(converter = LocalDateTimeAttributeConverter.class)
58
	@Column(name = "start_date")
59
	private LocalDateTime startDate = LocalDateTime.now();
60
 
61
	@Convert(converter = LocalDateTimeAttributeConverter.class)
22608 ashik.ali 62
	@Column(name = "end_date")
63
	private LocalDateTime endDate = LocalDateTime.now();
64
 
65
	@Convert(converter = LocalDateTimeAttributeConverter.class)
22600 ashik.ali 66
	@Column(name = "create_timestamp")
22859 ashik.ali 67
	private LocalDateTime createTimestamp = LocalDateTime.now();
22600 ashik.ali 68
 
22653 ashik.ali 69
	@Convert(converter = LocalDateTimeAttributeConverter.class)
70
	@Column(name = "active_timestamp")
71
	private LocalDateTime activeTimestamp = null;
72
 
73
	@Convert(converter = LocalDateTimeAttributeConverter.class)
22702 ashik.ali 74
	@Column(name = "expire_timestamp")
22653 ashik.ali 75
	private LocalDateTime expireTimestamp = null;
76
 
22600 ashik.ali 77
	@Column(name = "created_by")
78
	private int createdBy;
79
 
22859 ashik.ali 80
	@Column(name = "retailer_all")
81
	private boolean retailerAll;
22600 ashik.ali 82
 
22859 ashik.ali 83
	@Transient
84
	private Set<Integer> retailerIds = new HashSet<>();
85
 
86
	@Transient
87
	private Set<Integer> itemIds = new HashSet<>();
88
 
22600 ashik.ali 89
	public int getId() {
90
		return id;
91
	}
92
	public void setId(int id) {
93
		this.id = id;
94
	}
95
 
22653 ashik.ali 96
	public String getName() {
97
		return name;
22600 ashik.ali 98
	}
22653 ashik.ali 99
	public void setName(String name) {
100
		this.name = name;
22600 ashik.ali 101
	}
102
 
22653 ashik.ali 103
	public String getDescription() {
104
		return description;
22600 ashik.ali 105
	}
22653 ashik.ali 106
 
107
	public void setDescription(String description) {
108
		this.description = description;
22600 ashik.ali 109
	}
110
 
22653 ashik.ali 111
	public SchemeType getType() {
112
		return type;
113
	}
114
 
115
	public void setType(SchemeType type) {
116
		this.type = type;
117
	}
118
 
119
 
22600 ashik.ali 120
	public SchemeAmountType getAmountType() {
121
		return amountType;
122
	}
123
 
124
	public void setAmountType(SchemeAmountType amountType) {
125
		this.amountType = amountType;
126
	}
127
 
128
	public float getAmount() {
129
		return amount;
130
	}
131
	public void setAmount(float amount) {
132
		this.amount = amount;
133
	}
134
 
135
	public LocalDateTime getStartDate() {
136
		return startDate;
137
	}
138
	public void setStartDate(LocalDateTime startDate) {
139
		this.startDate = startDate;
140
	}
22653 ashik.ali 141
 
142
	public LocalDateTime getEndDate() {
143
		return endDate;
144
	}
145
	public void setEndDate(LocalDateTime endDate) {
146
		this.endDate = endDate;
147
	}
148
 
22859 ashik.ali 149
	public LocalDateTime getCreateTimestamp() {
150
		return createTimestamp;
22600 ashik.ali 151
	}
22859 ashik.ali 152
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
153
		this.createTimestamp = createTimestamp;
22600 ashik.ali 154
	}
155
	public int getCreatedBy() {
156
		return createdBy;
157
	}
158
	public void setCreatedBy(int createdBy) {
159
		this.createdBy = createdBy;
160
	}
22653 ashik.ali 161
 
162
	public LocalDateTime getActiveTimestamp() {
163
		return activeTimestamp;
22600 ashik.ali 164
	}
22653 ashik.ali 165
 
166
	public void setActiveTimestamp(LocalDateTime activeTimestamp) {
167
		this.activeTimestamp = activeTimestamp;
22600 ashik.ali 168
	}
169
 
22653 ashik.ali 170
	public LocalDateTime getExpireTimestamp() {
171
		return expireTimestamp;
172
	}
173
 
174
	public void setExpireTimestamp(LocalDateTime expireTimestamp) {
175
		this.expireTimestamp = expireTimestamp;
176
	}
177
 
22859 ashik.ali 178
	public boolean isRetailerAll() {
179
		return retailerAll;
22653 ashik.ali 180
	}
181
 
22859 ashik.ali 182
	public void setRetailerAll(boolean retailerAll) {
183
		this.retailerAll = retailerAll;
22653 ashik.ali 184
	}
22859 ashik.ali 185
 
186
	public String getFormattedStartDate(){
187
		if(startDate == null){
188
			return null;
189
		}
190
    	DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-YYYY HH:mm");
191
		return startDate.format(formatter);
192
    }
193
 
194
	public String getFormattedEndDate(){
195
		if(endDate == null){
196
			return null;
197
		}
198
    	DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-YYYY HH:mm");
199
		return endDate.format(formatter);
200
    }
201
 
202
	public String getFormattedCreateTimestamp(){
203
		if(createTimestamp == null){
204
			return null;
205
		}
206
    	DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-YYYY HH:mm");
207
		return createTimestamp.format(formatter);
208
    }
209
 
210
	public String getFormattedActiveTimestamp(){
211
		if(activeTimestamp == null){
212
			return null;
213
		}
214
    	DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-YYYY HH:mm");
215
		return activeTimestamp.format(formatter);
216
    }
217
 
218
	public String getFormattedExpireTimestamp(){
219
		if(expireTimestamp == null){
220
			return null;
221
		}
222
    	DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-YYYY HH:mm");
223
		return expireTimestamp.format(formatter);
224
    }
225
 
226
	public Set<Integer> getRetailerIds() {
227
		return retailerIds;
228
	}
229
 
230
	public void setRetailerIds(Set<Integer> retailerIds) {
231
		this.retailerIds = retailerIds;
232
	}
233
 
234
	public String getRetailerIdsString(){
235
		Set<String> stringRetailerIds = new HashSet<>();
236
		if(!retailerIds.isEmpty()){
237
			for(int retailerId : retailerIds){
238
				stringRetailerIds.add(String.valueOf(retailerId));
239
			}
240
		}
241
		return String.join(", ", stringRetailerIds);
242
	}
243
 
244
	public Set<Integer> getItemIds() {
245
		return itemIds;
246
	}
247
 
248
	public void setItemIds(Set<Integer> itemIds) {
249
		this.itemIds = itemIds;
250
	}
251
 
252
	public String getItemIdsString(){
253
		Set<String> stringItemIds = new HashSet<>();
254
		if(!itemIds.isEmpty()){
255
			for(int itemId : itemIds){
256
				stringItemIds.add(String.valueOf(itemId));
257
			}
258
		}
259
		return String.join(", ", stringItemIds);
260
	}
261
 
22600 ashik.ali 262
	@Override
263
	public int hashCode() {
264
		final int prime = 31;
265
		int result = 1;
266
		result = prime * result + id;
267
		return result;
268
	}
269
	@Override
270
	public boolean equals(Object obj) {
271
		if (this == obj)
272
			return true;
273
		if (obj == null)
274
			return false;
275
		if (getClass() != obj.getClass())
276
			return false;
277
		Scheme other = (Scheme) obj;
278
		if (id != other.id)
279
			return false;
280
		return true;
281
	}
282
	@Override
283
	public String toString() {
22653 ashik.ali 284
		return "Scheme [id=" + id + ", name=" + name + ", description=" + description + ", type=" + type
285
				+ ", amountType=" + amountType + ", amount=" + amount + ", startDate=" + startDate + ", endDate="
22859 ashik.ali 286
				+ endDate + ", createTimestamp=" + createTimestamp + ", activeTimestamp=" + activeTimestamp
287
				+ ", expireTimestamp=" + expireTimestamp + ", createdBy=" + createdBy + ", retailerAll=" + retailerAll + ", retailerIds=" + retailerIds + "]";
22600 ashik.ali 288
	}
22653 ashik.ali 289
 
22600 ashik.ali 290
}