Subversion Repositories SmartDukaan

Rev

Rev 37149 | Rev 37563 | 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
 
37204 amit 58
    @Column(name = "brand_identifier", length = 100)
59
    private String brandIdentifier;
60
 
31846 tejbeer 61
    @Column(name = "catalog_item_id")
62
    private int catalogItemId;
29707 tejbeer 63
 
31846 tejbeer 64
    @Column(name = "weight")
65
    private Double weight;
29707 tejbeer 66
 
31846 tejbeer 67
    @Column(name = "category")
68
    private int categoryId;
29707 tejbeer 69
 
32417 amit.gupta 70
 
31846 tejbeer 71
    @Column(name = "startDate")
72
    private LocalDateTime startDate;
29707 tejbeer 73
 
32417 amit.gupta 74
    @Column(name = "addedOn")
75
    private LocalDateTime addedOn;
76
 
77
    @Column(name = "updatedOn")
78
    private LocalDateTime updatedOn;
79
 
37149 amit 80
    // maintained by MySQL (ON UPDATE CURRENT_TIMESTAMP); never written by Hibernate
81
    @Column(name = "update_timestamp", insertable = false, updatable = false)
82
    private LocalDateTime updateTimestamp;
83
 
33183 shampa 84
    private Boolean risky;
32417 amit.gupta 85
 
33183 shampa 86
    private Integer expectedDelay;
32417 amit.gupta 87
 
88
    @Column(name = "warranty_period")
89
    private Integer warrantyPeriod;
90
 
91
    private Integer preferredVendor;
92
 
31846 tejbeer 93
    public int getCategoryId() {
94
        return categoryId;
95
    }
23426 amit.gupta 96
 
31846 tejbeer 97
    public void setCategoryId(int categoryId) {
98
        this.categoryId = categoryId;
99
    }
29707 tejbeer 100
 
37204 amit 101
    public String getBrandIdentifier() {
102
        return brandIdentifier;
103
    }
104
 
105
    public void setBrandIdentifier(String brandIdentifier) {
106
        this.brandIdentifier = brandIdentifier;
107
    }
108
 
32417 amit.gupta 109
    public LocalDateTime getAddedOn() {
110
        return addedOn;
111
    }
112
 
113
    public void setAddedOn(LocalDateTime addedOn) {
114
        this.addedOn = addedOn;
115
    }
116
 
37149 amit 117
    public LocalDateTime getUpdateTimestamp() {
118
        return updateTimestamp;
119
    }
120
 
32417 amit.gupta 121
    public LocalDateTime getUpdatedOn() {
122
        return updatedOn;
123
    }
124
 
125
    public void setUpdatedOn(LocalDateTime updatedOn) {
126
        this.updatedOn = updatedOn;
127
    }
128
 
129
    public boolean isRisky() {
130
        return risky;
131
    }
132
 
133
    public void setRisky(boolean risky) {
134
        this.risky = risky;
135
    }
136
 
35169 aman 137
    public Integer getExpectedDelay() {
32417 amit.gupta 138
        return expectedDelay;
139
    }
140
 
141
    public void setExpectedDelay(int expectedDelay) {
142
        this.expectedDelay = expectedDelay;
143
    }
144
 
145
    public Integer getWarrantyPeriod() {
146
        return warrantyPeriod;
147
    }
148
 
149
    public void setWarrantyPeriod(Integer warrantyPeriod) {
150
        this.warrantyPeriod = warrantyPeriod;
151
    }
152
 
153
    public Integer getPreferredVendor() {
154
        return preferredVendor;
155
    }
156
 
157
    public void setPreferredVendor(Integer preferredVendor) {
158
        this.preferredVendor = preferredVendor;
159
    }
160
 
31846 tejbeer 161
    @Enumerated(EnumType.STRING)
162
    @Column(name = "type")
163
    private ItemType type;
29707 tejbeer 164
 
31846 tejbeer 165
    @Column(name = "hsnCode")
166
    private String hsnCode;
29707 tejbeer 167
 
31846 tejbeer 168
    @Column(name = "sellingPrice")
169
    private Float sellingPrice;
31821 amit.gupta 170
 
31846 tejbeer 171
    public String getProductGroup() {
172
        return productGroup;
173
    }
29707 tejbeer 174
 
31846 tejbeer 175
    public void setProductGroup(String productGroup) {
176
        this.productGroup = productGroup;
177
    }
29707 tejbeer 178
 
31846 tejbeer 179
    public int getId() {
180
        return id;
181
    }
29707 tejbeer 182
 
31846 tejbeer 183
    @Column
184
    private Float mrp;
29707 tejbeer 185
 
31846 tejbeer 186
    public void setId(int id) {
187
        this.id = id;
188
    }
29707 tejbeer 189
 
31846 tejbeer 190
    public String getBrand() {
191
        return brand;
192
    }
29707 tejbeer 193
 
31846 tejbeer 194
    public void setBrand(String brand) {
37071 amit 195
        this.brand = com.spice.profitmandi.common.util.StringUtils.normalizeWhitespace(brand);
31846 tejbeer 196
    }
29707 tejbeer 197
 
31846 tejbeer 198
    public String getModelName() {
199
        return modelName;
200
    }
29707 tejbeer 201
 
31846 tejbeer 202
    public void setModelName(String modelName) {
37071 amit 203
        this.modelName = com.spice.profitmandi.common.util.StringUtils.normalizeWhitespace(modelName);
31846 tejbeer 204
    }
29707 tejbeer 205
 
31846 tejbeer 206
    public String getModelNumber() {
207
        return modelNumber;
208
    }
29707 tejbeer 209
 
31846 tejbeer 210
    public void setModelNumber(String modelNumber) {
37071 amit 211
        this.modelNumber = com.spice.profitmandi.common.util.StringUtils.normalizeWhitespace(modelNumber);
31846 tejbeer 212
    }
29707 tejbeer 213
 
31846 tejbeer 214
    public String getColor() {
215
        if (color != null && (color.startsWith("f_") || color.startsWith("F_"))) {
216
            return color.substring(2);
217
        }
218
        return color;
219
    }
29707 tejbeer 220
 
31846 tejbeer 221
    public String getColorNatural() {
222
        return this.color;
223
    }
29707 tejbeer 224
 
31846 tejbeer 225
    public void setColor(String color) {
37071 amit 226
        this.color = com.spice.profitmandi.common.util.StringUtils.normalizeWhitespace(color);
31846 tejbeer 227
    }
29707 tejbeer 228
 
31846 tejbeer 229
    public ItemType getType() {
230
        return type;
231
    }
29707 tejbeer 232
 
31846 tejbeer 233
    public void setType(ItemType type) {
234
        this.type = type;
235
    }
29707 tejbeer 236
 
31846 tejbeer 237
    public String getHsnCode() {
238
        return hsnCode;
239
    }
29707 tejbeer 240
 
31846 tejbeer 241
    public void setHsnCode(String hsnCode) {
242
        this.hsnCode = hsnCode;
243
    }
29707 tejbeer 244
 
31846 tejbeer 245
    public int getCatalogItemId() {
246
        return catalogItemId;
247
    }
29707 tejbeer 248
 
31846 tejbeer 249
    public Double getWeight() {
250
        return weight;
251
    }
29707 tejbeer 252
 
31846 tejbeer 253
    public void setWeight(Double weight) {
254
        this.weight = weight;
255
    }
29707 tejbeer 256
 
31846 tejbeer 257
    public void setCatalogItemId(int catalogItemId) {
258
        this.catalogItemId = catalogItemId;
259
    }
29707 tejbeer 260
 
31846 tejbeer 261
    public Float getSellingPrice() {
262
        return sellingPrice;
263
    }
29707 tejbeer 264
 
31846 tejbeer 265
    public void setSellingPrice(Float sellingPrice) {
266
        this.sellingPrice = sellingPrice;
267
    }
29707 tejbeer 268
 
31065 tejbeer 269
 
31846 tejbeer 270
    public LocalDateTime getStartDate() {
271
        return startDate;
272
    }
29707 tejbeer 273
 
31846 tejbeer 274
    public void setStartDate(LocalDateTime startDate) {
275
        this.startDate = startDate;
276
    }
29707 tejbeer 277
 
31846 tejbeer 278
    public String getItemDescription() {
279
        StringBuilder itemString = new StringBuilder();
280
        if (this.getBrand() != null && !this.getBrand().isEmpty()) {
281
            itemString.append(this.getBrand().trim());
282
        }
283
        itemString.append(" ");
284
        if (this.getModelName() != null && !this.getModelName().isEmpty()) {
285
            itemString.append(this.getModelName().trim());
286
        }
287
        if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
288
            itemString.append(" ");
289
            itemString.append(this.getModelNumber().trim());
290
        }
291
        if (this.getColor() != null && !this.getColor().isEmpty() && !this.getColor().trim().equals("f_")) {
292
            itemString.append(" ");
293
            itemString.append(this.getColor().trim());
294
        }
295
        return itemString.toString().replaceAll("\\s+", " ").trim();
296
    }
29707 tejbeer 297
 
31846 tejbeer 298
    public boolean isSmartPhone() {
299
        return SMART_PG.contains(this.getHsnCode());
300
    }
29707 tejbeer 301
 
32230 amit.gupta 302
    public String getModel() {
303
        StringBuilder itemString = new StringBuilder();
304
        if (this.getModelName() != null && !this.getModelName().isEmpty()) {
305
            itemString.append(this.getModelName().trim());
306
        }
307
        if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
308
            itemString.append(" ");
309
            itemString.append(this.getModelNumber().trim());
310
        }
311
 
312
        return itemString.toString().replaceAll("\\s+", " ").trim();
313
 
314
    }
315
 
31846 tejbeer 316
    public String getItemDescriptionNoColor() {
317
        StringBuilder itemString = new StringBuilder();
318
        if (this.getBrand() != null && !this.getBrand().isEmpty()) {
319
            itemString.append(this.getBrand().trim());
320
        }
321
        itemString.append(" ");
322
        if (this.getModelName() != null && !this.getModelName().isEmpty()) {
323
            itemString.append(this.getModelName().trim());
324
        }
325
        if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
326
            itemString.append(" ");
327
            itemString.append(this.getModelNumber().trim());
328
        }
29707 tejbeer 329
 
31846 tejbeer 330
        return itemString.toString().replaceAll("\\s+", " ").trim();
331
    }
29707 tejbeer 332
 
31846 tejbeer 333
    @Override
334
    public int hashCode() {
335
        final int prime = 31;
336
        int result = 1;
337
        result = prime * result + ((brand == null) ? 0 : brand.hashCode());
338
        result = prime * result + catalogItemId;
339
        result = prime * result + categoryId;
340
        result = prime * result + ((color == null) ? 0 : color.hashCode());
341
        result = prime * result + ((hsnCode == null) ? 0 : hsnCode.hashCode());
342
        result = prime * result + id;
343
        result = prime * result + ((modelName == null) ? 0 : modelName.hashCode());
344
        result = prime * result + ((modelNumber == null) ? 0 : modelNumber.hashCode());
345
        result = prime * result + ((productGroup == null) ? 0 : productGroup.hashCode());
346
        result = prime * result + ((sellingPrice == null) ? 0 : sellingPrice.hashCode());
347
        result = prime * result + ((startDate == null) ? 0 : startDate.hashCode());
348
        result = prime * result + ((status == null) ? 0 : status.hashCode());
349
        result = prime * result + ((type == null) ? 0 : type.hashCode());
350
        result = prime * result + ((weight == null) ? 0 : weight.hashCode());
351
        return result;
352
    }
29707 tejbeer 353
 
31846 tejbeer 354
    @Override
355
    public boolean equals(Object obj) {
356
        if (this == obj) return true;
357
        if (obj == null) return false;
358
        if (getClass() != obj.getClass()) return false;
359
        Item other = (Item) obj;
360
        if (brand == null) {
361
            if (other.brand != null) return false;
362
        } else if (!brand.equals(other.brand)) return false;
363
        if (catalogItemId != other.catalogItemId) return false;
364
        if (categoryId != other.categoryId) return false;
365
        if (color == null) {
366
            if (other.color != null) return false;
367
        } else if (!color.equals(other.color)) return false;
368
        if (hsnCode == null) {
369
            if (other.hsnCode != null) return false;
370
        } else if (!hsnCode.equals(other.hsnCode)) return false;
371
        if (id != other.id) return false;
372
        if (modelName == null) {
373
            if (other.modelName != null) return false;
374
        } else if (!modelName.equals(other.modelName)) return false;
375
        if (modelNumber == null) {
376
            if (other.modelNumber != null) return false;
377
        } else if (!modelNumber.equals(other.modelNumber)) return false;
378
        if (productGroup == null) {
379
            if (other.productGroup != null) return false;
380
        } else if (!productGroup.equals(other.productGroup)) return false;
381
        if (sellingPrice == null) {
382
            if (other.sellingPrice != null) return false;
383
        } else if (!sellingPrice.equals(other.sellingPrice)) return false;
384
        if (startDate == null) {
385
            if (other.startDate != null) return false;
386
        } else if (!startDate.equals(other.startDate)) return false;
387
        if (status != other.status) return false;
388
        if (type != other.type) return false;
389
        if (weight == null) {
390
            if (other.weight != null) return false;
391
        } else if (!weight.equals(other.weight)) return false;
392
        return true;
393
    }
31767 amit.gupta 394
 
31846 tejbeer 395
    public status getStatus() {
396
        return status;
397
    }
398
 
399
    public void setStatus(status status) {
400
        this.status = status;
401
    }
402
 
403
    public boolean isAnyColor() {
404
        if (this.color != null) {
405
            String lowerCaseColor = this.color.toLowerCase();
406
            return lowerCaseColor.equals("any color") || lowerCaseColor.equals("f_any color") || lowerCaseColor.equals("any colour") || lowerCaseColor.equals("f_any colour");
407
        }
408
        return false;
409
    }
410
 
32417 amit.gupta 411
    public Item clone() {
412
        Item item = new Item();
413
        item.setBrand(this.getBrand());
414
        item.setModelName(this.getModelName());
415
        item.setModelNumber(this.getModelNumber());
416
        item.setColor(this.getColor());
417
        item.setCatalogItemId(this.catalogItemId);
418
        item.setHsnCode(this.getHsnCode());
419
        item.setCategoryId(this.getCategoryId());
420
        item.setMrp(this.getMrp());
421
        item.setProductGroup(this.getProductGroup());
422
        item.setSellingPrice(this.getSellingPrice());
423
        item.setStartDate(LocalDateTime.now());
424
        item.setStatus(this.getStatus());
425
        item.setType(this.getType());
426
        item.setWeight(this.getWeight());
427
        item.setAddedOn(LocalDateTime.now());
428
        item.setUpdatedOn(LocalDateTime.now());
429
        item.setExpectedDelay(0);
430
        item.setPreferredVendor(null);
431
        item.setRisky(true);
432
        item.setWarrantyPeriod(0);
433
        return item;
434
    }
435
 
31846 tejbeer 436
    public Float getMrp() {
437
        return mrp;
438
    }
439
 
440
    public void setMrp(Float mrp) {
441
        this.mrp = mrp;
442
    }
32417 amit.gupta 443
 
444
    @Override
445
    public String toString() {
446
        return "Item{" +
447
                "id=" + id +
448
                ", brand='" + brand + '\'' +
449
                ", status=" + status +
450
                ", productGroup='" + productGroup + '\'' +
451
                ", modelName='" + modelName + '\'' +
452
                ", modelNumber='" + modelNumber + '\'' +
453
                ", color='" + color + '\'' +
454
                ", catalogItemId=" + catalogItemId +
455
                ", weight=" + weight +
456
                ", categoryId=" + categoryId +
457
                ", startDate=" + startDate +
458
                ", addedOn=" + addedOn +
459
                ", updatedOn=" + updatedOn +
460
                ", risky=" + risky +
461
                ", expectedDelay=" + expectedDelay +
462
                ", warrantyPeriod=" + warrantyPeriod +
463
                ", preferredVendor=" + preferredVendor +
464
                ", type=" + type +
465
                ", hsnCode='" + hsnCode + '\'' +
466
                ", sellingPrice=" + sellingPrice +
467
                ", mrp=" + mrp +
468
                '}';
469
    }
21552 ashik.ali 470
}