Subversion Repositories SmartDukaan

Rev

Rev 37071 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
33772 amit.gupta 1
package com.spice.profitmandi.dao.entity.catalog;
2
 
3
import javax.persistence.*;
4
import java.time.LocalDateTime;
5
import java.util.Objects;
6
 
35343 ranu 7
 
8
@NamedQueries({
9
        @NamedQuery(name = "Catalog.findOtherORNullCategoryAndInStock", query = "select i.catalogItemId "
10
                + " from WarehouseInventoryItem wi "
11
                + " join Item i on i.id = wi.itemId"
12
                + " left join CategorisedCatalog cc on cc.catalogId = i.catalogItemId and cc.endDate is null "
35356 ranu 13
                + " where ((cc.status is null OR cc.status = 'OTHER' OR cc.status = 'SLOWMOVING')) and i.categoryId in (10006,10009,10010) and i.brand= :brand group by i.catalogItemId having sum(wi.currentQuantity) > 0"),
35343 ranu 14
 
15
        @NamedQuery(name = "Catalog.findOtherORNullCategoryAndPartnerInStock", query = "select i.catalogItemId "
16
                + " from CurrentInventorySnapshot cis "
17
                + " join Item i on i.id = cis.itemId"
18
                + " left join CategorisedCatalog cc on cc.catalogId = i.catalogItemId and cc.endDate is null "
35356 ranu 19
                + " where  ((cc.status is null OR cc.status = 'OTHER' OR cc.status = 'SLOWMOVING')) and i.categoryId in (10006,10009,10010) and i.brand= :brand and cis.fofoId = :fofoId group by i.catalogItemId having sum(cis.availability) > 0"),
35357 ranu 20
 
35365 ranu 21
        @NamedQuery(name = "Catalog.findAllWithEOLWithOutStock", query = "select i.catalogItemId "
35359 ranu 22
                + " from Item i "
23
                + " left join  WarehouseInventoryItem wi on i.id = wi.itemId"
35357 ranu 24
                + " left join CategorisedCatalog cc on cc.catalogId = i.catalogItemId and cc.endDate is null "
35426 ranu 25
                + " where ((cc.status is null OR cc.status = 'OTHER' OR cc.status = 'SLOWMOVING')) and i.categoryId in (10006,10009,10010) group by i.catalogItemId having (sum(wi.currentQuantity) = 0 OR sum(wi.currentQuantity) IS NULL)"),
35357 ranu 26
 
35487 ranu 27
        @NamedQuery(name = "Catalog.selectAllStatusAndBrandWise", query = "select c.id" +
28
                " from Catalog c " +
29
                " join CategorisedCatalog cc on c.id = cc.catalogId and cc.endDate is null" +
30
                " where cc.status in  (:statuses) and c.brand in :brands"),
35426 ranu 31
 
35501 ranu 32
        @NamedQuery(name = "Catalog.selectAllGoodStockBrandWise", query = "SELECT DISTINCT c " +
33
                "FROM Catalog c " +
34
                "         JOIN Item i ON i.catalogItemId = c.id " +
35
                "         JOIN CategorisedCatalog cc ON c.id = cc.catalogId and cc.endDate is null " +
36
                "         JOIN WarehouseInventoryItem wi ON wi.itemId = i.id " +
37
                " WHERE " +
38
                "        i.categoryId IN (10006) " +
39
                "  AND (wi.lastScanType NOT IN (:scanTypes) OR wi.lastScanType IS NULL) " +
40
                " " +
41
                "  AND ( " +
42
                "        (cc.status NOT IN (:movingStatus) AND cc.status IS NOT NULL) " +
43
                "        OR " +
44
                "        wi.currentQuantity > 0 " +
45
                "    ) " +
46
                " and c.brand = :brand " +
47
                " GROUP BY c.id"),
35487 ranu 48
 
35501 ranu 49
 
35426 ranu 50
        @NamedQuery(
51
                name = "Catalog.findAllWithNoGoodStock",
52
                query = "select i.catalogItemId "
53
                        + " from Item i "
54
                        + " left join WarehouseInventoryItem wi on i.id = wi.itemId "
55
                        + " left join CategorisedCatalog cc on cc.catalogId = i.catalogItemId and cc.endDate is null "
56
                        + " where (cc.status is null OR cc.status = 'OTHER' OR cc.status = 'SLOWMOVING') "
57
                        + " and i.categoryId in (10006, 10009, 10010) "
58
                        + " group by i.catalogItemId "
59
                        + " having "
60
                        + "   sum(case when (wi.lastScanType is null OR wi.lastScanType NOT IN (:scanTypes)) "
61
                        + "            then wi.currentQuantity else 0 end) = 0 "
62
                        + "   OR sum(wi.currentQuantity) IS NULL"
63
        )
64
 
35343 ranu 65
})
66
 
33772 amit.gupta 67
@Entity
68
@Table(name = "catalog.catalog")
69
public class Catalog {
70
    @Id
71
    @GeneratedValue(strategy = GenerationType.IDENTITY)
72
    @Column(name = "id", columnDefinition = "int(11)")
73
    private int id;
74
 
75
    @Column(name="brand_id")
76
    private int brandId;
77
 
78
    @Column
79
    private String brand;
80
 
81
    @Column(name="model_number")
82
    private String modelNumber;
83
 
84
    @Column(name="model_name")
85
    private String modelName;
86
 
33888 ranu 87
    @Column(name = "category_id")
88
    private int categoryId;
89
 
33772 amit.gupta 90
    @Column(name="created_by")
91
    private String createdBy;
92
 
93
    @Column
94
    private LocalDateTime created;
95
 
37149 amit 96
    // maintained by MySQL (ON UPDATE CURRENT_TIMESTAMP); never written by Hibernate
97
    @Column(name = "update_timestamp", insertable = false, updatable = false)
98
    private LocalDateTime updateTimestamp;
99
 
100
    public LocalDateTime getUpdateTimestamp() {
101
        return updateTimestamp;
102
    }
103
 
33772 amit.gupta 104
    public int getId() {
105
        return id;
106
    }
107
 
108
    public void setId(int id) {
109
        this.id = id;
110
    }
111
 
112
    public int getBrandId() {
113
        return brandId;
114
    }
115
 
116
    public void setBrandId(int brandId) {
117
        this.brandId = brandId;
118
    }
119
 
120
    public String getBrand() {
121
        return brand;
122
    }
123
 
124
    public void setBrand(String brand) {
37071 amit 125
        this.brand = com.spice.profitmandi.common.util.StringUtils.normalizeWhitespace(brand);
33772 amit.gupta 126
    }
127
 
128
    public String getModelNumber() {
129
        return modelNumber;
130
    }
131
 
132
    public void setModelNumber(String modelNumber) {
37071 amit 133
        this.modelNumber = com.spice.profitmandi.common.util.StringUtils.normalizeWhitespace(modelNumber);
33772 amit.gupta 134
    }
135
 
136
    public String getModelName() {
137
        return modelName;
138
    }
139
 
140
    public void setModelName(String modelName) {
37071 amit 141
        this.modelName = com.spice.profitmandi.common.util.StringUtils.normalizeWhitespace(modelName);
33772 amit.gupta 142
    }
143
 
144
    public String getCreatedBy() {
145
        return createdBy;
146
    }
147
 
148
    public void setCreatedBy(String createdBy) {
149
        this.createdBy = createdBy;
150
    }
151
 
152
    public LocalDateTime getCreated() {
153
        return created;
154
    }
155
 
156
    public void setCreated(LocalDateTime created) {
157
        this.created = created;
158
    }
159
 
33888 ranu 160
    public int getCategoryId() {
161
        return categoryId;
162
    }
163
 
164
    public void setCategoryId(int categoryId) {
165
        this.categoryId = categoryId;
166
    }
167
 
33772 amit.gupta 168
    @Override
169
    public boolean equals(Object o) {
170
        if (this == o) return true;
171
        if (o == null || getClass() != o.getClass()) return false;
172
        Catalog catalog = (Catalog) o;
33888 ranu 173
        return id == catalog.id && brandId == catalog.brandId && categoryId == catalog.categoryId && Objects.equals(brand, catalog.brand) && Objects.equals(modelNumber, catalog.modelNumber) && Objects.equals(modelName, catalog.modelName) && Objects.equals(createdBy, catalog.createdBy) && Objects.equals(created, catalog.created);
33772 amit.gupta 174
    }
175
 
176
    @Override
33888 ranu 177
    public int hashCode() {
178
        return Objects.hash(id, brandId, brand, modelNumber, modelName, categoryId, createdBy, created);
179
    }
180
 
33916 amit.gupta 181
    public String getDescription() {
182
        StringBuilder itemString = new StringBuilder();
183
        if (this.getBrand() != null && !this.getBrand().isEmpty()) {
184
            itemString.append(this.getBrand().trim());
185
        }
186
        itemString.append(" ");
187
        if (this.getModelName() != null && !this.getModelName().isEmpty()) {
188
            itemString.append(this.getModelName().trim());
189
        }
190
        if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
191
            itemString.append(" ");
192
            itemString.append(this.getModelNumber().trim());
193
        }
194
 
195
        return itemString.toString().replaceAll("\\s+", " ").trim();
196
    }
197
 
35188 amit 198
    public String getDescriptionNoBrand() {
199
        StringBuilder itemString = new StringBuilder();
200
        itemString.append(" ");
201
        if (this.getModelName() != null && !this.getModelName().isEmpty()) {
202
            itemString.append(this.getModelName().trim());
203
        }
204
        if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
205
            itemString.append(" ");
206
            itemString.append(this.getModelNumber().trim());
207
        }
208
 
209
        return itemString.toString().replaceAll("\\s+", " ").trim();
210
    }
211
 
33888 ranu 212
    @Override
33772 amit.gupta 213
    public String toString() {
214
        return "Catalog{" +
215
                "id=" + id +
216
                ", brandId=" + brandId +
217
                ", brand='" + brand + '\'' +
218
                ", modelNumber='" + modelNumber + '\'' +
219
                ", modelName='" + modelName + '\'' +
33888 ranu 220
                ", categoryId=" + categoryId +
33772 amit.gupta 221
                ", createdBy='" + createdBy + '\'' +
222
                ", created=" + created +
223
                '}';
224
    }
225
 
226
}
227