Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
26299 amit.gupta 1
package com.spice.profitmandi.dao.entity.fofo;
2
 
30213 amit.gupta 3
import javax.persistence.*;
26299 amit.gupta 4
import java.time.LocalDateTime;
5
 
6
@Entity
7
@Table(name = "fofo.activated_imei", schema = "fofo")
28825 tejbeer 8
 
9
@NamedQueries({
10
 
11
		@NamedQuery(name = "ActivatedImei.selectActivatedModelGroupByBrand", query = "select new com.spice.profitmandi.dao.model.BrandWiseActivatedModel(li.brand, "
12
				+ "sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp))= :lms then 1 else 0 end),"
13
				+ "sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp))= :lms  then CAST(li.unitPrice  AS int) else 0 end),"
14
				+ "sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp))= :mtd then 1 else 0 end),"
15
				+ "sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp))= :mtd   then CAST(li.unitPrice AS int) else 0 end), "
16
				+ "sum(case when ai.activationTimestamp between  :lmtdStartDate and :lmtdEndDate then 1 else 0 end), "
17
				+ "sum(case when ai.activationTimestamp between  :lmtdStartDate and :lmtdEndDate then  CAST(li.unitPrice  AS int) else 0 end))"
18
				+ " from ActivatedImei ai join LineItemImeiView lim on ai.serialNumber = lim.serialNumber join LineItem li on li.id = lim.lineItemId join Order o on o.id = li.orderId "
19
				+ "	join FofoStore fs on fs.id = o.retailerId where (fs.fofoType = 'FRANCHISE' or fs.fofoType = 'THIRD_PARTY') and fs.id in :fofoIds group by li.brand"),
20
 
29475 amit.gupta 21
		@NamedQuery(name = "ActivatedImei.selectActivatedModelGroupByWarehouse", query = "select new com.spice.profitmandi.dao.model.WarehouseWiseActivatedModel(o.warehouseId, "
28825 tejbeer 22
				+ "sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp))= :lms then 1 else 0 end),"
23
				+ "sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp))= :lms  then CAST(li.unitPrice  AS int) else 0 end),"
24
				+ "sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp))= :mtd then 1 else 0 end),"
25
				+ "sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp))= :mtd   then CAST(li.unitPrice AS int) else 0 end), "
26
				+ "sum(case when ai.activationTimestamp between  :lmtdStartDate and :lmtdEndDate then 1 else 0 end), "
27
				+ "sum(case when ai.activationTimestamp between  :lmtdStartDate and :lmtdEndDate then  CAST(li.unitPrice  AS int) else 0 end))"
28
				+ " from ActivatedImei ai join LineItemImeiView lim on ai.serialNumber = lim.serialNumber join LineItem li on li.id = lim.lineItemId join Order o on o.id = li.orderId "
29
				+ " join FofoStore fs on fs.id = o.retailerId where (fs.fofoType = 'FRANCHISE' or fs.fofoType = 'THIRD_PARTY') and li.brand = :brand and fs.id in :fofoIds"
29474 amit.gupta 30
				+ " group by o.warehouseId"),
28825 tejbeer 31
 
32
		@NamedQuery(name = "ActivatedImei.selectWarehouseBrandActivatedItem", query = "select new com.spice.profitmandi.dao.model.WarehouseBrandWiseItemActivatedModel(fs.warehouseId, li.itemId, li.brand,li.modelName,"
33
				+ " li.modelNumber, li.color,"
34
				+ "sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp))= :lms then 1 else 0 end),"
35
				+ "sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp))= :lms  then CAST(li.unitPrice  AS int) else 0 end),"
36
				+ "sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp))= :mtd then 1 else 0 end),"
37
				+ "sum(case when concat(year(ai.activationTimestamp), month(ai.activationTimestamp))= :mtd   then CAST(li.unitPrice AS int) else 0 end), "
38
				+ "sum(case when ai.activationTimestamp between  :lmtdStartDate and :lmtdEndDate then 1 else 0 end), "
39
				+ "sum(case when ai.activationTimestamp between  :lmtdStartDate and :lmtdEndDate then  CAST(li.unitPrice  AS int) else 0 end))"
40
				+ " from ActivatedImei ai join LineItemImeiView lim on ai.serialNumber = lim.serialNumber join LineItem li on li.id = lim.lineItemId join Order o on o.id = li.orderId "
41
				+ " join FofoStore fs on fs.id = o.retailerId where (fs.fofoType = 'FRANCHISE' or fs.fofoType = 'THIRD_PARTY') and fs.warehouseId in :warehouseId and li.brand = :brand and fs.id in :fofoIds "
42
				+ " group by li.itemId"),
43
 
44
		@NamedQuery(name = "ActivatedImei.selectActivatedUpdationDate", query = "select new com.spice.profitmandi.dao.model.ActivationImeiUpdationModel(fs.warehouseId,li.brand, "
45
				+ " Max(ai.createTimestamp))"
46
				+ " from ActivatedImei ai join LineItemImeiView lim on ai.serialNumber = lim.serialNumber join LineItem li on li.id = lim.lineItemId join Order o on o.id = li.orderId "
47
				+ "	join FofoStore fs on fs.id = o.retailerId group by li.brand,fs.warehouseId"),
48
 
30344 amit.gupta 49
		@NamedQuery(name = "ActivatedImei.selectImeiActivationByBrand", query = "select new com.spice.profitmandi.dao.model.ImeiActivationTimestampModel(limei.serialNumber, ai.activationTimestamp) "
50
				+ " from Order o join LineItem  li on o.id=li.orderId join LineItemImei  limei on li.id=limei.lineItemId join FofoStore fs on fs.id=o.retailerId left join ActivatedImei ai on limei.serialNumber = ai.serialNumber "
30349 amit.gupta 51
				+ "	where (ai.createTimestamp is null or ai.createTimestamp < :daysBeforeToday) and li.brand = :brand and ai.activationTimestamp is null and fs.active=true and fs.internal = false and fs.fofoType='FRANCHISE'"),
29452 manish 52
 
30449 amit.gupta 53
		@NamedQuery(name = "ActivatedImei.selectActivatedImeisByOrders", query = "select new com.spice.profitmandi.dao.model.ImeiActivationTimestampModel(o.id, o.lineItem.unitPrice, limei.serialNumber, ai.activationTimestamp) "
54
				+ " from Order o join LineItem  li on o.id=li.orderId join LineItemImei  limei on li.id=limei.lineItemId join FofoStore fs on fs.id=o.retailerId left join ActivatedImei ai on limei.serialNumber = ai.serialNumber "
55
				+ "	where o.id in :orderIds and ai.activationTimestamp is not null"),
56
 
28825 tejbeer 57
})
26299 amit.gupta 58
public class ActivatedImei {
26309 amit.gupta 59
	@Id
60
	@Column(name = "serial_number", unique = true)
61
	private String serialNumber;
28825 tejbeer 62
 
26309 amit.gupta 63
	@Column(name = "activation_timestamp")
64
	private LocalDateTime activationTimestamp;
26299 amit.gupta 65
 
26309 amit.gupta 66
	@Column(name = "create_timestamp")
67
	private LocalDateTime createTimestamp;
28825 tejbeer 68
 
26299 amit.gupta 69
	public ActivatedImei() {
70
		super();
71
	}
28825 tejbeer 72
 
26299 amit.gupta 73
	public ActivatedImei(String serialNumber, LocalDateTime activationTimestamp) {
74
		this.activationTimestamp = activationTimestamp;
75
		this.serialNumber = serialNumber;
76
	}
77
 
78
	@Override
79
	public String toString() {
26309 amit.gupta 80
		return "ActivatedImei [serialNumber=" + serialNumber + ", activationTimestamp=" + activationTimestamp
81
				+ ", createTimestamp=" + createTimestamp + "]";
26299 amit.gupta 82
	}
83
 
84
	public String getSerialNumber() {
85
		return serialNumber;
86
	}
87
 
88
	public void setSerialNumber(String serialNumber) {
89
		this.serialNumber = serialNumber;
90
	}
91
 
92
	public LocalDateTime getActivationTimestamp() {
93
		return activationTimestamp;
94
	}
95
 
96
	public void setActivationTimestamp(LocalDateTime activationTimestamp) {
97
		this.activationTimestamp = activationTimestamp;
98
	}
99
 
26309 amit.gupta 100
	public LocalDateTime getCreateTimestamp() {
101
		return createTimestamp;
102
	}
103
 
104
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
105
		this.createTimestamp = createTimestamp;
106
	}
107
 
26299 amit.gupta 108
	@Override
109
	public int hashCode() {
110
		final int prime = 31;
111
		int result = 1;
26309 amit.gupta 112
		result = prime * result + ((activationTimestamp == null) ? 0 : activationTimestamp.hashCode());
113
		result = prime * result + ((createTimestamp == null) ? 0 : createTimestamp.hashCode());
26299 amit.gupta 114
		result = prime * result + ((serialNumber == null) ? 0 : serialNumber.hashCode());
115
		return result;
116
	}
117
 
118
	@Override
119
	public boolean equals(Object obj) {
120
		if (this == obj)
121
			return true;
122
		if (obj == null)
123
			return false;
124
		if (getClass() != obj.getClass())
125
			return false;
126
		ActivatedImei other = (ActivatedImei) obj;
26309 amit.gupta 127
		if (activationTimestamp == null) {
128
			if (other.activationTimestamp != null)
129
				return false;
130
		} else if (!activationTimestamp.equals(other.activationTimestamp))
131
			return false;
132
		if (createTimestamp == null) {
133
			if (other.createTimestamp != null)
134
				return false;
135
		} else if (!createTimestamp.equals(other.createTimestamp))
136
			return false;
26299 amit.gupta 137
		if (serialNumber == null) {
138
			if (other.serialNumber != null)
139
				return false;
140
		} else if (!serialNumber.equals(other.serialNumber))
141
			return false;
142
		return true;
143
	}
144
 
145
}