Skip to content

Commit 4ca7f7c

Browse files
committed
cumulative beneficiary.
1 parent f0e8e9c commit 4ca7f7c

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/controller/UserController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,7 @@ public ResponseEntity<Long> getCumulativeBeneficiaries(){
14441444

14451445

14461446
Long cumulativeJoinedSubscription = kilkariCallReportDao.getCumulativeJoinedSubscription(locationId, locationType, toDate);
1447+
LOGGER.info("cumulativecount:{},date:{},locationType:{},locationId:{}",cumulativeJoinedSubscription,toDate,locationType,locationId);
14471448
return ResponseEntity.ok(cumulativeJoinedSubscription);
14481449
// Long ashaStarted = 0L;
14491450
// Long ashaCompleted = 0L;

NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import com.beehyv.nmsreporting.dao.KilkariCallReportDao;
55
import com.beehyv.nmsreporting.model.KilkariCalls;
66
import org.hibernate.Criteria;
7+
import org.hibernate.Query;
78
import org.hibernate.criterion.Order;
89
import org.hibernate.criterion.Projections;
910
import org.hibernate.criterion.Restrictions;
1011
import org.springframework.stereotype.Repository;
1112

1213
import java.util.Date;
1314
import java.util.List;
15+
import java.util.logging.Logger;
1416

1517
/**
1618
* Created by beehyv on 11/10/17.
@@ -51,20 +53,29 @@ public KilkariCalls getKilkariCallreport(Integer locationId, String locationTyp
5153

5254
@Override
5355
public Long getCumulativeJoinedSubscription(Long locationId, String locationType, Date toDate) {
54-
Criteria criteria = createEntityCriteria();
56+
String hql;
5557

5658
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;
5867
} 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;
6177
}
62-
criteria.add(Restrictions.eq("date", toDate));
6378

64-
criteria.setProjection(Projections.sum("uniqueBeneficiaries"));
65-
66-
Long result = (Long) criteria.uniqueResult();
67-
return result != null ? result : 0L;
6879
}
6980
}
7081

0 commit comments

Comments
 (0)