Subversion Repositories SmartDukaan

Rev

Rev 30499 | Rev 31767 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.dao.entity.catalog;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import com.spice.profitmandi.common.enumuration.ItemType;

import in.shop2020.model.v1.catalog.status;

/**
 * This class basically contains item details
 *
 * @author ashikali
 */

@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,'%')"),

                @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"),

                @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") })
@Entity
@Table(name = "catalog.item", schema = "catalog")
public class Item implements Serializable {

        public static final List<String> SMART_PG = Arrays.asList("85171300", "85171290");

        private static final long serialVersionUID = 1L;

        public Item() {
        }

        @Id
        @Column(name = "id", columnDefinition = "int(11)")
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private int id;

        @Column(name = "brand", length = 100)
        private String brand;

        @Column(name = "status")
        @Enumerated(EnumType.ORDINAL)
        private status status;

        @Column(name = "product_group", length = 100)
        private String productGroup;

        @Column(name = "model_name", length = 100)
        private String modelName;

        @Column(name = "model_number", length = 100)
        private String modelNumber;

        @Column(name = "color", length = 20)
        private String color;

        @Column(name = "catalog_item_id")
        private int catalogItemId;

        @Column(name = "weight")
        private Double weight;

        @Column(name = "category")
        private int categoryId;

        public int getCategoryId() {
                return categoryId;
        }

        public void setCategoryId(int categoryId) {
                this.categoryId = categoryId;
        }

        @Enumerated(EnumType.STRING)
        @Column(name = "type")
        private ItemType type;

        @Column(name = "hsnCode")
        private String hsnCode;

        @Column(name = "sellingPrice")
        private Float sellingPrice;

        public String getProductGroup() {
                return productGroup;
        }

        public void setProductGroup(String productGroup) {
                this.productGroup = productGroup;
        }

        public int getId() {
                return id;
        }

        public void setId(int id) {
                this.id = id;
        }

        public String getBrand() {
                return brand;
        }

        public void setBrand(String brand) {
                this.brand = brand;
        }

        public String getModelName() {
                return modelName;
        }

        public void setModelName(String modelName) {
                this.modelName = modelName;
        }

        public String getModelNumber() {
                return modelNumber;
        }

        public void setModelNumber(String modelNumber) {
                this.modelNumber = modelNumber;
        }

        public String getColor() {
                if (color != null && (color.startsWith("f_") || color.startsWith("F_"))) {
                        return color.substring(2);
                }
                return color;
        }

        public String getColorNatural() {
                return this.color;
        }

        public void setColor(String color) {
                this.color = color;
        }

        public ItemType getType() {
                return type;
        }

        public void setType(ItemType type) {
                this.type = type;
        }

        public String getHsnCode() {
                return hsnCode;
        }

        public void setHsnCode(String hsnCode) {
                this.hsnCode = hsnCode;
        }

        public int getCatalogItemId() {
                return catalogItemId;
        }

        public Double getWeight() {
                return weight;
        }

        public void setWeight(Double weight) {
                this.weight = weight;
        }

        public void setCatalogItemId(int catalogItemId) {
                this.catalogItemId = catalogItemId;
        }

        public Float getSellingPrice() {
                return sellingPrice;
        }

        public void setSellingPrice(Float sellingPrice) {
                this.sellingPrice = sellingPrice;
        }

        public String getItemDescription() {
                StringBuilder itemString = new StringBuilder();
                if (this.getBrand() != null && !this.getBrand().isEmpty()) {
                        itemString.append(this.getBrand().trim());
                }
                itemString.append(" ");
                if (this.getModelName() != null && !this.getModelName().isEmpty()) {
                        itemString.append(this.getModelName().trim());
                }
                if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
                        itemString.append(" ");
                        itemString.append(this.getModelNumber().trim());
                }
                if (this.getColor() != null && !this.getColor().isEmpty() && !this.getColor().trim().equals("f_")) {
                        itemString.append(" ");
                        itemString.append(this.getColor().trim());
                }
                return itemString.toString().replaceAll("\\s+", " ").trim();
        }

        public boolean isSmartPhone() {
                return SMART_PG.contains(this.getHsnCode());
        }

        public String getItemDescriptionNoColor() {
                StringBuilder itemString = new StringBuilder();
                if (this.getBrand() != null && !this.getBrand().isEmpty()) {
                        itemString.append(this.getBrand().trim());
                }
                itemString.append(" ");
                if (this.getModelName() != null && !this.getModelName().isEmpty()) {
                        itemString.append(this.getModelName().trim());
                }
                if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
                        itemString.append(" ");
                        itemString.append(this.getModelNumber().trim());
                }

                return itemString.toString().replaceAll("\\s+", " ").trim();
        }

        @Override
        public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result + id;
                return result;
        }

        @Override
        public boolean equals(Object obj) {
                if (this == obj)
                        return true;
                if (obj == null)
                        return false;
                if (getClass() != obj.getClass())
                        return false;
                Item other = (Item) obj;
                if (id != other.id)
                        return false;
                return true;
        }

        @Override
        public String toString() {
                return "Item [id=" + id + ", brand=" + brand + ", status=" + status + ", productGroup=" + productGroup
                                + ", modelName=" + modelName + ", modelNumber=" + modelNumber + ", color=" + color + ", catalogItemId="
                                + catalogItemId + ", weight=" + weight + ", categoryId=" + categoryId + ", type=" + type + ", hsnCode="
                                + hsnCode + ", sellingPrice=" + sellingPrice + "]";
        }

        public status getStatus() {
                return status;
        }

        public void setStatus(status status) {
                this.status = status;
        }

}