Subversion Repositories SmartDukaan

Rev

Rev 26685 | Rev 30121 | 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.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Convert;
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.Table;
import javax.persistence.Transient;

import com.spice.profitmandi.dao.convertor.LocalDateTimeAttributeConverter;
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;

/**
 * This class basically contains scheme details
 * 
 * @author ashikali
 *
 */
@Entity
@Table(name = "catalog.scheme", schema = "catalog")
public class Scheme implements Serializable {

        public PartnerType getPartnerType() {
                return partnerType;
        }

        public void setPartnerType(PartnerType partnerType) {
                this.partnerType = partnerType;
        }

        private static final long serialVersionUID = 1L;

        public Scheme() {
        }

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

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

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

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

        @Column(name = "amount_type")
        @Enumerated(EnumType.STRING)
        private AmountType amountType;

        @Column(name = "amount")
        private float amount;

        @Convert(converter = LocalDateTimeAttributeConverter.class)
        @Column(name = "start_date_time")
        private LocalDateTime startDateTime = LocalDateTime.now();

        @Convert(converter = LocalDateTimeAttributeConverter.class)
        @Column(name = "end_date_time")
        private LocalDateTime endDateTime = LocalDateTime.now();

        @Convert(converter = LocalDateTimeAttributeConverter.class)
        @Column(name = "create_timestamp")
        private LocalDateTime createTimestamp = LocalDateTime.now();

        @Convert(converter = LocalDateTimeAttributeConverter.class)
        @Column(name = "active_timestamp")
        private LocalDateTime activeTimestamp = null;

        @Convert(converter = LocalDateTimeAttributeConverter.class)
        @Column(name = "expire_timestamp")
        private LocalDateTime expireTimestamp = null;

        @Column(name = "created_by")
        private int createdBy;

        @Column
        private boolean cashback;

        @Transient
        private Set<Integer> retailerIds = new HashSet<>();
        
        @Transient
        private String amountModel;

        @Column(name="partner_type")
        @Enumerated(EnumType.STRING)
        private PartnerType partnerType;

        @Transient
        private Map<Integer, String> itemStringMap = new HashMap<>();

        public int getId() {
                return id;
        }

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

        public String getAmountModel() {
                return amountModel;
        }

        public void setAmountModel(String amountModel) {
                this.amountModel = amountModel;
        }

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        public String getDescription() {
                return description;
        }

        public void setDescription(String description) {
                this.description = description;
        }

        public boolean isCashback() {
                return cashback;
        }

        public void setCashback(boolean cashback) {
                this.cashback = cashback;
        }

        public SchemeType getType() {
                return type;
        }

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

        @Override
        public String toString() {
                return "Scheme [id=" + id + ", name=" + name + ", description=" + description + ", type=" + type
                                + ", amountType=" + amountType + ", amount=" + amount + ", startDateTime=" + startDateTime
                                + ", endDateTime=" + endDateTime + ", createTimestamp=" + createTimestamp + ", activeTimestamp="
                                + activeTimestamp + ", expireTimestamp=" + expireTimestamp + ", createdBy=" + createdBy + ", cashBack="
                                + cashback + ", retailerIds=" + retailerIds + ", partnerType=" + partnerType + ", itemStringMap="
                                + itemStringMap + "]";
        }

        public AmountType getAmountType() {
                return amountType;
        }

        public void setAmountType(AmountType amountType) {
                this.amountType = amountType;
        }

        public float getAmount() {
                return amount;
        }

        public void setAmount(float amount) {
                this.amount = amount;
        }

        public LocalDateTime getStartDateTime() {
                return startDateTime;
        }

        public void setStartDateTime(LocalDateTime startDateTime) {
                this.startDateTime = startDateTime;
        }

        public LocalDateTime getEndDateTime() {
                return endDateTime;
        }

        public void setEndDateTime(LocalDateTime endDateTime) {
                this.endDateTime = endDateTime;
        }

        public LocalDateTime getCreateTimestamp() {
                return createTimestamp;
        }

        public void setCreateTimestamp(LocalDateTime createTimestamp) {
                this.createTimestamp = createTimestamp;
        }

        public int getCreatedBy() {
                return createdBy;
        }

        public void setCreatedBy(int createdBy) {
                this.createdBy = createdBy;
        }

        public LocalDateTime getActiveTimestamp() {
                return activeTimestamp;
        }

        public void setActiveTimestamp(LocalDateTime activeTimestamp) {
                this.activeTimestamp = activeTimestamp;
        }

        public LocalDateTime getExpireTimestamp() {
                return expireTimestamp;
        }

        public void setExpireTimestamp(LocalDateTime expireTimestamp) {
                this.expireTimestamp = expireTimestamp;
        }

        public String getFormattedStartDateTime() {
                if (startDateTime == null) {
                        return null;
                }
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
                return startDateTime.format(formatter);
        }

        public String getFormattedEndDateTime() {
                if (endDateTime == null) {
                        return null;
                }
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
                return endDateTime.format(formatter);
        }

        public String getFormattedCreateTimestamp() {
                if (createTimestamp == null) {
                        return null;
                }
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
                return createTimestamp.format(formatter);
        }

        public String getFormattedActiveTimestamp() {
                if (activeTimestamp == null) {
                        return null;
                }
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
                return activeTimestamp.format(formatter);
        }

        public String getFormattedExpireTimestamp() {
                if (expireTimestamp == null) {
                        return null;
                }
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
                return expireTimestamp.format(formatter);
        }

        public Set<Integer> getRetailerIds() {
                return retailerIds;
        }

        public void setRetailerIds(Set<Integer> retailerIds) {
                this.retailerIds = retailerIds;
        }

        public String getRetailerIdsString() {
                Set<String> stringRetailerIds = new HashSet<>();
                if (!retailerIds.isEmpty()) {
                        for (int retailerId : retailerIds) {
                                stringRetailerIds.add(String.valueOf(retailerId));
                        }
                }
                return String.join(", ", stringRetailerIds);
        }

        public Map<Integer, String> getItemStringMap() {
                return itemStringMap;
        }

        public void setItemStringMap(Map<Integer, String> itemStringMap) {
                this.itemStringMap = itemStringMap;
        }

        /*
         * public String getItemIdsString(){ Set<String> stringItemIds = new
         * HashSet<>(); if(!itemIds.isEmpty()){ for(int itemId : itemIds){
         * stringItemIds.add(String.valueOf(itemId)); } } return String.join(", ",
         * stringItemIds); }
         */

        @Override
        public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result + ((activeTimestamp == null) ? 0 : activeTimestamp.hashCode());
                result = prime * result + Float.floatToIntBits(amount);
                result = prime * result + ((amountType == null) ? 0 : amountType.hashCode());
                result = prime * result + (cashback ? 1231 : 1237);
                result = prime * result + ((createTimestamp == null) ? 0 : createTimestamp.hashCode());
                result = prime * result + createdBy;
                result = prime * result + ((description == null) ? 0 : description.hashCode());
                result = prime * result + ((endDateTime == null) ? 0 : endDateTime.hashCode());
                result = prime * result + ((expireTimestamp == null) ? 0 : expireTimestamp.hashCode());
                result = prime * result + id;
                result = prime * result + ((itemStringMap == null) ? 0 : itemStringMap.hashCode());
                result = prime * result + ((name == null) ? 0 : name.hashCode());
                result = prime * result + ((partnerType == null) ? 0 : partnerType.hashCode());
                result = prime * result + ((retailerIds == null) ? 0 : retailerIds.hashCode());
                result = prime * result + ((startDateTime == null) ? 0 : startDateTime.hashCode());
                result = prime * result + ((type == null) ? 0 : type.hashCode());
                return result;
        }

        @Override
        public boolean equals(Object obj) {
                if (this == obj)
                        return true;
                if (obj == null)
                        return false;
                if (getClass() != obj.getClass())
                        return false;
                Scheme other = (Scheme) obj;
                if (activeTimestamp == null) {
                        if (other.activeTimestamp != null)
                                return false;
                } else if (!activeTimestamp.equals(other.activeTimestamp))
                        return false;
                if (Float.floatToIntBits(amount) != Float.floatToIntBits(other.amount))
                        return false;
                if (amountType != other.amountType)
                        return false;
                if (cashback != other.cashback)
                        return false;
                if (createTimestamp == null) {
                        if (other.createTimestamp != null)
                                return false;
                } else if (!createTimestamp.equals(other.createTimestamp))
                        return false;
                if (createdBy != other.createdBy)
                        return false;
                if (description == null) {
                        if (other.description != null)
                                return false;
                } else if (!description.equals(other.description))
                        return false;
                if (endDateTime == null) {
                        if (other.endDateTime != null)
                                return false;
                } else if (!endDateTime.equals(other.endDateTime))
                        return false;
                if (expireTimestamp == null) {
                        if (other.expireTimestamp != null)
                                return false;
                } else if (!expireTimestamp.equals(other.expireTimestamp))
                        return false;
                if (id != other.id)
                        return false;
                if (itemStringMap == null) {
                        if (other.itemStringMap != null)
                                return false;
                } else if (!itemStringMap.equals(other.itemStringMap))
                        return false;
                if (name == null) {
                        if (other.name != null)
                                return false;
                } else if (!name.equals(other.name))
                        return false;
                if (partnerType != other.partnerType)
                        return false;
                if (retailerIds == null) {
                        if (other.retailerIds != null)
                                return false;
                } else if (!retailerIds.equals(other.retailerIds))
                        return false;
                if (startDateTime == null) {
                        if (other.startDateTime != null)
                                return false;
                } else if (!startDateTime.equals(other.startDateTime))
                        return false;
                if (type != other.type)
                        return false;
                return true;
        }

}