Subversion Repositories SmartDukaan

Rev

Rev 30634 | Rev 30896 | 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 "
30823 amit.gupta 51
				+ "	where (ai.createTimestamp is null or ai.createTimestamp < :daysBeforeToday) and li.brand = :brand and ai.activationTimestamp is null and fs.internal = false and date(o.billingTimestamp)>'2021-01-01'"),
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
 
30505 amit.gupta 57
		@NamedQuery(name = "ActivatedImei.selectActivatedGrnPendingAmount", query = "select cast(sum(o.lineItem.unitPrice) as float )"
30479 amit.gupta 58
				+ " from Order o join LineItemImei  limei on o.lineItem.id=limei.lineItemId join FofoStore fs on fs.id=o.retailerId left join ActivatedImei ai on limei.serialNumber = ai.serialNumber "
30484 amit.gupta 59
				+ "	where o.status in (12, 9) and ai.activationTimestamp is not null and o.partnerGrnTimestamp is null and o.retailerId=:fofoId group by o.retailerId"),
30479 amit.gupta 60
 
28825 tejbeer 61
})
26299 amit.gupta 62
public class ActivatedImei {
26309 amit.gupta 63
	@Id
64
	@Column(name = "serial_number", unique = true)
65
	private String serialNumber;
28825 tejbeer 66
 
26309 amit.gupta 67
	@Column(name = "activation_timestamp")
68
	private LocalDateTime activationTimestamp;
26299 amit.gupta 69
 
26309 amit.gupta 70
	@Column(name = "create_timestamp")
71
	private LocalDateTime createTimestamp;
28825 tejbeer 72
 
26299 amit.gupta 73
	public ActivatedImei() {
74
		super();
75
	}
28825 tejbeer 76
 
26299 amit.gupta 77
	public ActivatedImei(String serialNumber, LocalDateTime activationTimestamp) {
78
		this.activationTimestamp = activationTimestamp;
79
		this.serialNumber = serialNumber;
80
	}
81
 
82
	@Override
83
	public String toString() {
26309 amit.gupta 84
		return "ActivatedImei [serialNumber=" + serialNumber + ", activationTimestamp=" + activationTimestamp
85
				+ ", createTimestamp=" + createTimestamp + "]";
26299 amit.gupta 86
	}
87
 
88
	public String getSerialNumber() {
89
		return serialNumber;
90
	}
91
 
92
	public void setSerialNumber(String serialNumber) {
93
		this.serialNumber = serialNumber;
94
	}
95
 
96
	public LocalDateTime getActivationTimestamp() {
97
		return activationTimestamp;
98
	}
99
 
100
	public void setActivationTimestamp(LocalDateTime activationTimestamp) {
101
		this.activationTimestamp = activationTimestamp;
102
	}
103
 
26309 amit.gupta 104
	public LocalDateTime getCreateTimestamp() {
105
		return createTimestamp;
106
	}
107
 
108
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
109
		this.createTimestamp = createTimestamp;
110
	}
111
 
26299 amit.gupta 112
	@Override
113
	public int hashCode() {
114
		final int prime = 31;
115
		int result = 1;
26309 amit.gupta 116
		result = prime * result + ((activationTimestamp == null) ? 0 : activationTimestamp.hashCode());
117
		result = prime * result + ((createTimestamp == null) ? 0 : createTimestamp.hashCode());
26299 amit.gupta 118
		result = prime * result + ((serialNumber == null) ? 0 : serialNumber.hashCode());
119
		return result;
120
	}
121
 
122
	@Override
123
	public boolean equals(Object obj) {
124
		if (this == obj)
125
			return true;
126
		if (obj == null)
127
			return false;
128
		if (getClass() != obj.getClass())
129
			return false;
130
		ActivatedImei other = (ActivatedImei) obj;
26309 amit.gupta 131
		if (activationTimestamp == null) {
132
			if (other.activationTimestamp != null)
133
				return false;
134
		} else if (!activationTimestamp.equals(other.activationTimestamp))
135
			return false;
136
		if (createTimestamp == null) {
137
			if (other.createTimestamp != null)
138
				return false;
139
		} else if (!createTimestamp.equals(other.createTimestamp))
140
			return false;
26299 amit.gupta 141
		if (serialNumber == null) {
142
			if (other.serialNumber != null)
143
				return false;
144
		} else if (!serialNumber.equals(other.serialNumber))
145
			return false;
146
		return true;
147
	}
148
 
149
}