diff --git a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/controller/UserController.java b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/controller/UserController.java index 1780a750..146bc909 100644 --- a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/controller/UserController.java +++ b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/controller/UserController.java @@ -1436,6 +1436,7 @@ public ResponseEntity getCumulativeBeneficiaries(){ Long cumulativeJoinedSubscription = kilkariCallReportDao.getCumulativeJoinedSubscription(locationId, locationType, toDate); + LOGGER.info("cumulativecount:{},date:{},locationType:{},locationId:{}",cumulativeJoinedSubscription,toDate,locationType,locationId); return ResponseEntity.ok(cumulativeJoinedSubscription); // Long ashaStarted = 0L; // Long ashaCompleted = 0L; diff --git a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateBlockDaoImpl.java b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateBlockDaoImpl.java index 11d0712a..b09aab83 100644 --- a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateBlockDaoImpl.java +++ b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateBlockDaoImpl.java @@ -54,7 +54,7 @@ public List allCountOffReports(Integer dis "COUNT(Case when s.subscription_status = 'COMPLETED' THEN s.subscription_id END) AS subscriptions_completed, " + "0 AS subscriptions_rejected , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) BETWEEN -90 AND 168 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_PW , "+ - "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) BETWEEN 169 AND 504 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child , "+ + "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) >= 169 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) < -90 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Ineligible "+ "FROM Beneficiary b " + " INNER JOIN subscriptions s ON b.id = s.beneficiary_id AND s.subscription_id = (SELECT MAX(subscription_id) FROM subscriptions WHERE beneficiary_id = b.id) " + diff --git a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateDistrictDaoImpl.java b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateDistrictDaoImpl.java index 3f7fc0ad..e7491167 100644 --- a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateDistrictDaoImpl.java +++ b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateDistrictDaoImpl.java @@ -56,7 +56,7 @@ public List allCountOffReports(Integer sta "COUNT(CASE WHEN s.subscription_status = 'COMPLETED' THEN s.subscription_id END) AS subscriptions_completed , " + "0 AS subscriptions_rejected , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) BETWEEN -90 AND 168 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_PW , "+ - "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) BETWEEN 169 AND 504 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child , "+ + "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) >= 169 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) < -90 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Ineligible "+ "FROM Beneficiary b " + " INNER JOIN subscriptions s ON b.id = s.beneficiary_id AND s.subscription_id = (SELECT MAX(subscription_id) FROM subscriptions WHERE beneficiary_id = b.id) " + diff --git a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateStateDaoImpl.java b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateStateDaoImpl.java index 2cac0044..c7434a75 100644 --- a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateStateDaoImpl.java +++ b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateStateDaoImpl.java @@ -54,7 +54,7 @@ public List allCountOffReports(Date fromDa "COUNT(CASE WHEN s.subscription_status = 'COMPLETED' THEN s.subscription_id END) AS subscriptions_completed ," + "0 AS subscriptions_rejected , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) BETWEEN -90 AND 168 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_PW , "+ - "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) BETWEEN 169 AND 504 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child, "+ + "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) >= 169 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child, "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) < -90 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Ineligible "+ "FROM Beneficiary b " + " INNER JOIN subscriptions s ON b.id = s.beneficiary_id AND s.subscription_id = (SELECT MAX(subscription_id) FROM subscriptions WHERE beneficiary_id = b.id) " + diff --git a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateSubCentreDaoImpl.java b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateSubCentreDaoImpl.java index 24dd52cf..a1fa999a 100644 --- a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateSubCentreDaoImpl.java +++ b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/BeneficiaryWithRegistrationDateSubCentreDaoImpl.java @@ -56,7 +56,7 @@ public List allCountOffReports(Integer blo "COUNT(CASE WHEN s.subscription_status = 'COMPLETED' THEN s.subscription_id END) AS subscriptions_completed , " + "0 AS subscriptions_rejected , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) BETWEEN -90 AND 168 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_PW , "+ - "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) BETWEEN 169 AND 504 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child , "+ + "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 2 OR DATEDIFF(registrationDate, s.start_date) >= 169 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Received_for_Child , "+ "COUNT(DISTINCT CASE WHEN s.subscriptionPack_id = 1 AND DATEDIFF(registrationDate, s.start_date) < -90 THEN s.subscription_id ELSE NULL END) AS Subscriptions_Ineligible "+ "FROM Beneficiary b " + " INNER JOIN subscriptions s ON b.id = s.beneficiary_id AND s.subscription_id = (SELECT MAX(subscription_id) FROM subscriptions WHERE beneficiary_id = b.id) "+ diff --git a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java index 6ee3b713..ae3ffb67 100644 --- a/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java +++ b/NMSReportingSuite/src/main/java/com/beehyv/nmsreporting/dao/impl/KilkariCallReportDaoImpl.java @@ -4,8 +4,8 @@ import com.beehyv.nmsreporting.dao.KilkariCallReportDao; import com.beehyv.nmsreporting.model.KilkariCalls; import org.hibernate.Criteria; +import org.hibernate.Query; import org.hibernate.criterion.Order; -import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.springframework.stereotype.Repository; @@ -51,20 +51,29 @@ public KilkariCalls getKilkariCallreport(Integer locationId, String locationTyp @Override public Long getCumulativeJoinedSubscription(Long locationId, String locationType, Date toDate) { - Criteria criteria = createEntityCriteria(); + String hql; if (locationId == 0 && "State".equalsIgnoreCase(locationType)) { - criteria.add(Restrictions.eq("locationType", locationType)); + String sql = "SELECT COALESCE(SUM(CAST(total_beneficiaries AS SIGNED)), 0) " + + "FROM agg_kilkari_call_report " + + "WHERE location_type = :locationType AND date = (SELECT date FROM agg_kilkari_call_report ORDER BY date DESC LIMIT 1)"; + Query query = getSession().createSQLQuery(sql); + query.setParameter("locationType", locationType); +// query.setParameter("toDate", toDate); + Long result = ((Number) query.uniqueResult()).longValue(); + return result != null ? result : 0L; } else { - criteria.add(Restrictions.eq("locationId", locationId)); - criteria.add(Restrictions.eq("locationType", locationType)); + String sql = "SELECT COALESCE(SUM(CAST(total_beneficiaries AS SIGNED)), 0) " + + "FROM agg_kilkari_call_report " + + "WHERE location_id = :locationId AND location_type = :locationType AND date = (SELECT date FROM agg_kilkari_call_report ORDER BY date DESC LIMIT 1)"; + Query query = getSession().createSQLQuery(sql); + query.setParameter("locationId", locationId); + query.setParameter("locationType", locationType); +// query.setParameter("toDate", toDate); + Long result = ((Number) query.uniqueResult()).longValue(); + return result != null ? result : 0L; } - criteria.add(Restrictions.eq("date", toDate)); - criteria.setProjection(Projections.sum("uniqueBeneficiaries")); - - Long result = (Long) criteria.uniqueResult(); - return result != null ? result : 0L; } }