|
4 | 4 | import com.beehyv.nmsreporting.dao.KilkariCallReportDao; |
5 | 5 | import com.beehyv.nmsreporting.model.KilkariCalls; |
6 | 6 | import org.hibernate.Criteria; |
| 7 | +import org.hibernate.Query; |
7 | 8 | import org.hibernate.criterion.Order; |
8 | 9 | import org.hibernate.criterion.Projections; |
9 | 10 | import org.hibernate.criterion.Restrictions; |
10 | 11 | import org.springframework.stereotype.Repository; |
11 | 12 |
|
12 | 13 | import java.util.Date; |
13 | 14 | import java.util.List; |
| 15 | +import java.util.logging.Logger; |
14 | 16 |
|
15 | 17 | /** |
16 | 18 | * Created by beehyv on 11/10/17. |
@@ -51,20 +53,29 @@ public KilkariCalls getKilkariCallreport(Integer locationId, String locationTyp |
51 | 53 |
|
52 | 54 | @Override |
53 | 55 | public Long getCumulativeJoinedSubscription(Long locationId, String locationType, Date toDate) { |
54 | | - Criteria criteria = createEntityCriteria(); |
| 56 | + String hql; |
55 | 57 |
|
56 | 58 | if (locationId == 0 && "State".equalsIgnoreCase(locationType)) { |
57 | | - criteria.add(Restrictions.eq("locationType", locationType)); |
| 59 | + String sql = "SELECT COALESCE(SUM(CAST(total_beneficiaries AS SIGNED)), 0) " + |
| 60 | + "FROM agg_kilkari_call_report " + |
| 61 | + "WHERE location_type = :locationType AND date = (SELECT date FROM agg_kilkari_call_report ORDER BY date DESC LIMIT 1)"; |
| 62 | + Query query = getSession().createSQLQuery(sql); |
| 63 | + query.setParameter("locationType", locationType); |
| 64 | +// query.setParameter("toDate", toDate); |
| 65 | + Long result = ((Number) query.uniqueResult()).longValue(); |
| 66 | + return result != null ? result : 0L; |
58 | 67 | } else { |
59 | | - criteria.add(Restrictions.eq("locationId", locationId)); |
60 | | - criteria.add(Restrictions.eq("locationType", locationType)); |
| 68 | + String sql = "SELECT COALESCE(SUM(CAST(total_beneficiaries AS SIGNED)), 0) " + |
| 69 | + "FROM agg_kilkari_call_report " + |
| 70 | + "WHERE location_id = :locationId AND location_type = :locationType AND date = (SELECT date FROM agg_kilkari_call_report ORDER BY date DESC LIMIT 1)"; |
| 71 | + Query query = getSession().createSQLQuery(sql); |
| 72 | + query.setParameter("locationId", locationId); |
| 73 | + query.setParameter("locationType", locationType); |
| 74 | +// query.setParameter("toDate", toDate); |
| 75 | + Long result = ((Number) query.uniqueResult()).longValue(); |
| 76 | + return result != null ? result : 0L; |
61 | 77 | } |
62 | | - criteria.add(Restrictions.eq("date", toDate)); |
63 | 78 |
|
64 | | - criteria.setProjection(Projections.sum("uniqueBeneficiaries")); |
65 | | - |
66 | | - Long result = (Long) criteria.uniqueResult(); |
67 | | - return result != null ? result : 0L; |
68 | 79 | } |
69 | 80 | } |
70 | 81 |
|
0 commit comments