Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
21713 ashik.ali 1
package com.spice.profitmandi.dao.entity.catalog;
21552 ashik.ali 2
 
32230 amit.gupta 3
import com.spice.profitmandi.common.enumuration.ItemType;
4
import in.shop2020.model.v1.catalog.status;
5
 
6
import javax.persistence.*;
31065 tejbeer 7
import java.io.Serializable;
31846 tejbeer 8
import java.time.LocalDateTime;
31065 tejbeer 9
import java.util.Arrays;
10
import java.util.List;
11
 
21552 ashik.ali 12
/**
13
 * This class basically contains item details
30121 amit.gupta 14
 *
21552 ashik.ali 15
 * @author ashikali
16
 */
29707 tejbeer 17
 
31846 tejbeer 18
@NamedQueries({@NamedQuery(name = "Item.selectItemByLikes", query = "select new com.spice.profitmandi.common.model.CustomItemModel(" + "	i.id, i.brand, i.modelName, i.modelNumber, i.color" + "	) from Item  i join CurrentInventorySnapshot cis on i.id = cis.itemId " + " where cis.fofoId = :fofoId and cis.availability > 0 and REPLACE(CONCAT(i.brand,' ', ifnull(i.modelName, ' '), ' ', ifnull(i.modelNumber, ' ')), '  ', ' ')  like CONCAT('%',:query,'%')"),
30121 amit.gupta 19
 
31846 tejbeer 20
        @NamedQuery(name = "Item.selectCatalogIdByMopRange", query = "select i.catalogItemId" + " from Item i join TagListing tl on tl.itemId = i.id " + " where tl.mop between :startPrice and :endPrice and  i.categoryId=10006 group by i.catalogItemId"),
30492 amit.gupta 21
 
31846 tejbeer 22
        @NamedQuery(name = "Item.selectAllBrands", query = "select distinct" + "  i.brand from Item i join TagListing tl on tl.itemId = i.id " + " where i.categoryId=:categoryId"), @NamedQuery(name = "Item.selectAllCategories", query = "select distinct" + "  i.categoryId from Item i join TagListing tl on tl.itemId = i.id "), @NamedQuery(name = "Item.selectAllModels", query = "select " + "  i from Item i join TagListing tl on tl.itemId = i.id where i.brand in :brands and i.categoryId = :categoryId")})
21552 ashik.ali 23
@Entity
31846 tejbeer 24
@Table(name = "catalog.item")
29707 tejbeer 25
public class Item implements Serializable {
26
 
31846 tejbeer 27
    public static final List<String> SMART_PG = Arrays.asList("85171300", "85171290");
31065 tejbeer 28
 
31846 tejbeer 29
    private static final long serialVersionUID = 1L;
29707 tejbeer 30
 
31846 tejbeer 31
    public Item() {
32
    }
29707 tejbeer 33
 
31846 tejbeer 34
    @Id
35
    @Column(name = "id", columnDefinition = "int(11)")
36
    @GeneratedValue(strategy = GenerationType.IDENTITY)
37
    private int id;
29707 tejbeer 38
 
31846 tejbeer 39
    @Column(name = "brand", length = 100)
40
    private String brand;
29707 tejbeer 41
 
31846 tejbeer 42
    @Column(name = "status")
43
    @Enumerated(EnumType.ORDINAL)
44
    private status status;
29707 tejbeer 45
 
31846 tejbeer 46
    @Column(name = "product_group", length = 100)
47
    private String productGroup;
29707 tejbeer 48
 
31846 tejbeer 49
    @Column(name = "model_name", length = 100)
50
    private String modelName;
29707 tejbeer 51
 
31846 tejbeer 52
    @Column(name = "model_number", length = 100)
53
    private String modelNumber;
29707 tejbeer 54
 
31846 tejbeer 55
    @Column(name = "color", length = 20)
56
    private String color;
29707 tejbeer 57
 
31846 tejbeer 58
    @Column(name = "catalog_item_id")
59
    private int catalogItemId;
29707 tejbeer 60
 
31846 tejbeer 61
    @Column(name = "weight")
62
    private Double weight;
29707 tejbeer 63
 
31846 tejbeer 64
    @Column(name = "category")
65
    private int categoryId;
29707 tejbeer 66
 
32417 amit.gupta 67
 
31846 tejbeer 68
    @Column(name = "startDate")
69
    private LocalDateTime startDate;
29707 tejbeer 70
 
32417 amit.gupta 71
    @Column(name = "addedOn")
72
    private LocalDateTime addedOn;
73
 
74
    @Column(name = "updatedOn")
75
    private LocalDateTime updatedOn;
76
 
37149 amit 77
    // maintained by MySQL (ON UPDATE CURRENT_TIMESTAMP); never written by Hibernate
78
    @Column(name = "update_timestamp", insertable = false, updatable = false)
79
    private LocalDateTime updateTimestamp;
80
 
33183 shampa 81
    private Boolean risky;
32417 amit.gupta 82
 
33183 shampa 83
    private Integer expectedDelay;
32417 amit.gupta 84
 
85
    @Column(name = "warranty_period")
86
    private Integer warrantyPeriod;
87
 
88
    private Integer preferredVendor;
89
 
31846 tejbeer 90
    public int getCategoryId() {
91
        return categoryId;
92
    }
23426 amit.gupta 93
 
31846 tejbeer 94
    public void setCategoryId(int categoryId) {
95
        this.categoryId = categoryId;
96
    }
29707 tejbeer 97
 
32417 amit.gupta 98
    public LocalDateTime getAddedOn() {
99
        return addedOn;
100
    }
101
 
102
    public void setAddedOn(LocalDateTime addedOn) {
103
        this.addedOn = addedOn;
104
    }
105
 
37149 amit 106
    public LocalDateTime getUpdateTimestamp() {
107
        return updateTimestamp;
108
    }
109
 
32417 amit.gupta 110
    public LocalDateTime getUpdatedOn() {
111
        return updatedOn;
112
    }
113
 
114
    public void setUpdatedOn(LocalDateTime updatedOn) {
115
        this.updatedOn = updatedOn;
116
    }
117
 
118
    public boolean isRisky() {
119
        return risky;
120
    }
121
 
122
    public void setRisky(boolean risky) {
123
        this.risky = risky;
124
    }
125
 
35169 aman 126
    public Integer getExpectedDelay() {
32417 amit.gupta 127
        return expectedDelay;
128
    }
129
 
130
    public void setExpectedDelay(int expectedDelay) {
131
        this.expectedDelay = expectedDelay;
132
    }
133
 
134
    public Integer getWarrantyPeriod() {
135
        return warrantyPeriod;
136
    }
137
 
138
    public void setWarrantyPeriod(Integer warrantyPeriod) {
139
        this.warrantyPeriod = warrantyPeriod;
140
    }
141
 
142
    public Integer getPreferredVendor() {
143
        return preferredVendor;
144
    }
145
 
146
    public void setPreferredVendor(Integer preferredVendor) {
147
        this.preferredVendor = preferredVendor;
148
    }
149
 
31846 tejbeer 150
    @Enumerated(EnumType.STRING)
151
    @Column(name = "type")
152
    private ItemType type;
29707 tejbeer 153
 
31846 tejbeer 154
    @Column(name = "hsnCode")
155
    private String hsnCode;
29707 tejbeer 156
 
31846 tejbeer 157
    @Column(name = "sellingPrice")
158
    private Float sellingPrice;
31821 amit.gupta 159
 
31846 tejbeer 160
    public String getProductGroup() {
161
        return productGroup;
162
    }
29707 tejbeer 163
 
31846 tejbeer 164
    public void setProductGroup(String productGroup) {
165
        this.productGroup = productGroup;
166
    }
29707 tejbeer 167
 
31846 tejbeer 168
    public int getId() {
169
        return id;
170
    }
29707 tejbeer 171
 
31846 tejbeer 172
    @Column
173
    private Float mrp;
29707 tejbeer 174
 
31846 tejbeer 175
    public void setId(int id) {
176
        this.id = id;
177
    }
29707 tejbeer 178
 
31846 tejbeer 179
    public String getBrand() {
180
        return brand;
181
    }
29707 tejbeer 182
 
31846 tejbeer 183
    public void setBrand(String brand) {
37071 amit 184
        this.brand = com.spice.profitmandi.common.util.StringUtils.normalizeWhitespace(brand);
31846 tejbeer 185
    }
29707 tejbeer 186
 
31846 tejbeer 187
    public String getModelName() {
188
        return modelName;
189
    }
29707 tejbeer 190
 
31846 tejbeer 191
    public void setModelName(String modelName) {
37071 amit 192
        this.modelName = com.spice.profitmandi.common.util.StringUtils.normalizeWhitespace(modelName);
31846 tejbeer 193
    }
29707 tejbeer 194
 
31846 tejbeer 195
    public String getModelNumber() {
196
        return modelNumber;
197
    }
29707 tejbeer 198
 
31846 tejbeer 199
    public void setModelNumber(String modelNumber) {
37071 amit 200
        this.modelNumber = com.spice.profitmandi.common.util.StringUtils.normalizeWhitespace(modelNumber);
31846 tejbeer 201
    }
29707 tejbeer 202
 
31846 tejbeer 203
    public String getColor() {
204
        if (color != null && (color.startsWith("f_") || color.startsWith("F_"))) {
205
            return color.substring(2);
206
        }
207
        return color;
208
    }
29707 tejbeer 209
 
31846 tejbeer 210
    public String getColorNatural() {
211
        return this.color;
212
    }
29707 tejbeer 213
 
31846 tejbeer 214
    public void setColor(String color) {
37071 amit 215
        this.color = com.spice.profitmandi.common.util.StringUtils.normalizeWhitespace(color);
31846 tejbeer 216
    }
29707 tejbeer 217
 
31846 tejbeer 218
    public ItemType getType() {
219
        return type;
220
    }
29707 tejbeer 221
 
31846 tejbeer 222
    public void setType(ItemType type) {
223
        this.type = type;
224
    }
29707 tejbeer 225
 
31846 tejbeer 226
    public String getHsnCode() {
227
        return hsnCode;
228
    }
29707 tejbeer 229
 
31846 tejbeer 230
    public void setHsnCode(String hsnCode) {
231
        this.hsnCode = hsnCode;
232
    }
29707 tejbeer 233
 
31846 tejbeer 234
    public int getCatalogItemId() {
235
        return catalogItemId;
236
    }
29707 tejbeer 237
 
31846 tejbeer 238
    public Double getWeight() {
239
        return weight;
240
    }
29707 tejbeer 241
 
31846 tejbeer 242
    public void setWeight(Double weight) {
243
        this.weight = weight;
244
    }
29707 tejbeer 245
 
31846 tejbeer 246
    public void setCatalogItemId(int catalogItemId) {
247
        this.catalogItemId = catalogItemId;
248
    }
29707 tejbeer 249
 
31846 tejbeer 250
    public Float getSellingPrice() {
251
        return sellingPrice;
252
    }
29707 tejbeer 253
 
31846 tejbeer 254
    public void setSellingPrice(Float sellingPrice) {
255
        this.sellingPrice = sellingPrice;
256
    }
29707 tejbeer 257
 
31065 tejbeer 258
 
31846 tejbeer 259
    public LocalDateTime getStartDate() {
260
        return startDate;
261
    }
29707 tejbeer 262
 
31846 tejbeer 263
    public void setStartDate(LocalDateTime startDate) {
264
        this.startDate = startDate;
265
    }
29707 tejbeer 266
 
31846 tejbeer 267
    public String getItemDescription() {
268
        StringBuilder itemString = new StringBuilder();
269
        if (this.getBrand() != null && !this.getBrand().isEmpty()) {
270
            itemString.append(this.getBrand().trim());
271
        }
272
        itemString.append(" ");
273
        if (this.getModelName() != null && !this.getModelName().isEmpty()) {
274
            itemString.append(this.getModelName().trim());
275
        }
276
        if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
277
            itemString.append(" ");
278
            itemString.append(this.getModelNumber().trim());
279
        }
280
        if (this.getColor() != null && !this.getColor().isEmpty() && !this.getColor().trim().equals("f_")) {
281
            itemString.append(" ");
282
            itemString.append(this.getColor().trim());
283
        }
284
        return itemString.toString().replaceAll("\\s+", " ").trim();
285
    }
29707 tejbeer 286
 
31846 tejbeer 287
    public boolean isSmartPhone() {
288
        return SMART_PG.contains(this.getHsnCode());
289
    }
29707 tejbeer 290
 
32230 amit.gupta 291
    public String getModel() {
292
        StringBuilder itemString = new StringBuilder();
293
        if (this.getModelName() != null && !this.getModelName().isEmpty()) {
294
            itemString.append(this.getModelName().trim());
295
        }
296
        if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
297
            itemString.append(" ");
298
            itemString.append(this.getModelNumber().trim());
299
        }
300
 
301
        return itemString.toString().replaceAll("\\s+", " ").trim();
302
 
303
    }
304
 
31846 tejbeer 305
    public String getItemDescriptionNoColor() {
306
        StringBuilder itemString = new StringBuilder();
307
        if (this.getBrand() != null && !this.getBrand().isEmpty()) {
308
            itemString.append(this.getBrand().trim());
309
        }
310
        itemString.append(" ");
311
        if (this.getModelName() != null && !this.getModelName().isEmpty()) {
312
            itemString.append(this.getModelName().trim());
313
        }
314
        if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
315
            itemString.append(" ");
316
            itemString.append(this.getModelNumber().trim());
317
        }
29707 tejbeer 318
 
31846 tejbeer 319
        return itemString.toString().replaceAll("\\s+", " ").trim();
320
    }
29707 tejbeer 321
 
31846 tejbeer 322
    @Override
323
    public int hashCode() {
324
        final int prime = 31;
325
        int result = 1;
326
        result = prime * result + ((brand == null) ? 0 : brand.hashCode());
327
        result = prime * result + catalogItemId;
328
        result = prime * result + categoryId;
329
        result = prime * result + ((color == null) ? 0 : color.hashCode());
330
        result = prime * result + ((hsnCode == null) ? 0 : hsnCode.hashCode());
331
        result = prime * result + id;
332
        result = prime * result + ((modelName == null) ? 0 : modelName.hashCode());
333
        result = prime * result + ((modelNumber == null) ? 0 : modelNumber.hashCode());
334
        result = prime * result + ((productGroup == null) ? 0 : productGroup.hashCode());
335
        result = prime * result + ((sellingPrice == null) ? 0 : sellingPrice.hashCode());
336
        result = prime * result + ((startDate == null) ? 0 : startDate.hashCode());
337
        result = prime * result + ((status == null) ? 0 : status.hashCode());
338
        result = prime * result + ((type == null) ? 0 : type.hashCode());
339
        result = prime * result + ((weight == null) ? 0 : weight.hashCode());
340
        return result;
341
    }
29707 tejbeer 342
 
31846 tejbeer 343
    @Override
344
    public boolean equals(Object obj) {
345
        if (this == obj) return true;
346
        if (obj == null) return false;
347
        if (getClass() != obj.getClass()) return false;
348
        Item other = (Item) obj;
349
        if (brand == null) {
350
            if (other.brand != null) return false;
351
        } else if (!brand.equals(other.brand)) return false;
352
        if (catalogItemId != other.catalogItemId) return false;
353
        if (categoryId != other.categoryId) return false;
354
        if (color == null) {
355
            if (other.color != null) return false;
356
        } else if (!color.equals(other.color)) return false;
357
        if (hsnCode == null) {
358
            if (other.hsnCode != null) return false;
359
        } else if (!hsnCode.equals(other.hsnCode)) return false;
360
        if (id != other.id) return false;
361
        if (modelName == null) {
362
            if (other.modelName != null) return false;
363
        } else if (!modelName.equals(other.modelName)) return false;
364
        if (modelNumber == null) {
365
            if (other.modelNumber != null) return false;
366
        } else if (!modelNumber.equals(other.modelNumber)) return false;
367
        if (productGroup == null) {
368
            if (other.productGroup != null) return false;
369
        } else if (!productGroup.equals(other.productGroup)) return false;
370
        if (sellingPrice == null) {
371
            if (other.sellingPrice != null) return false;
372
        } else if (!sellingPrice.equals(other.sellingPrice)) return false;
373
        if (startDate == null) {
374
            if (other.startDate != null) return false;
375
        } else if (!startDate.equals(other.startDate)) return false;
376
        if (status != other.status) return false;
377
        if (type != other.type) return false;
378
        if (weight == null) {
379
            if (other.weight != null) return false;
380
        } else if (!weight.equals(other.weight)) return false;
381
        return true;
382
    }
31767 amit.gupta 383
 
31846 tejbeer 384
    public status getStatus() {
385
        return status;
386
    }
387
 
388
    public void setStatus(status status) {
389
        this.status = status;
390
    }
391
 
392
    public boolean isAnyColor() {
393
        if (this.color != null) {
394
            String lowerCaseColor = this.color.toLowerCase();
395
            return lowerCaseColor.equals("any color") || lowerCaseColor.equals("f_any color") || lowerCaseColor.equals("any colour") || lowerCaseColor.equals("f_any colour");
396
        }
397
        return false;
398
    }
399
 
32417 amit.gupta 400
    public Item clone() {
401
        Item item = new Item();
402
        item.setBrand(this.getBrand());
403
        item.setModelName(this.getModelName());
404
        item.setModelNumber(this.getModelNumber());
405
        item.setColor(this.getColor());
406
        item.setCatalogItemId(this.catalogItemId);
407
        item.setHsnCode(this.getHsnCode());
408
        item.setCategoryId(this.getCategoryId());
409
        item.setMrp(this.getMrp());
410
        item.setProductGroup(this.getProductGroup());
411
        item.setSellingPrice(this.getSellingPrice());
412
        item.setStartDate(LocalDateTime.now());
413
        item.setStatus(this.getStatus());
414
        item.setType(this.getType());
415
        item.setWeight(this.getWeight());
416
        item.setAddedOn(LocalDateTime.now());
417
        item.setUpdatedOn(LocalDateTime.now());
418
        item.setExpectedDelay(0);
419
        item.setPreferredVendor(null);
420
        item.setRisky(true);
421
        item.setWarrantyPeriod(0);
422
        return item;
423
    }
424
 
31846 tejbeer 425
    public Float getMrp() {
426
        return mrp;
427
    }
428
 
429
    public void setMrp(Float mrp) {
430
        this.mrp = mrp;
431
    }
32417 amit.gupta 432
 
433
    @Override
434
    public String toString() {
435
        return "Item{" +
436
                "id=" + id +
437
                ", brand='" + brand + '\'' +
438
                ", status=" + status +
439
                ", productGroup='" + productGroup + '\'' +
440
                ", modelName='" + modelName + '\'' +
441
                ", modelNumber='" + modelNumber + '\'' +
442
                ", color='" + color + '\'' +
443
                ", catalogItemId=" + catalogItemId +
444
                ", weight=" + weight +
445
                ", categoryId=" + categoryId +
446
                ", startDate=" + startDate +
447
                ", addedOn=" + addedOn +
448
                ", updatedOn=" + updatedOn +
449
                ", risky=" + risky +
450
                ", expectedDelay=" + expectedDelay +
451
                ", warrantyPeriod=" + warrantyPeriod +
452
                ", preferredVendor=" + preferredVendor +
453
                ", type=" + type +
454
                ", hsnCode='" + hsnCode + '\'' +
455
                ", sellingPrice=" + sellingPrice +
456
                ", mrp=" + mrp +
457
                '}';
458
    }
21552 ashik.ali 459
}