From a4d1ad9ea2c8001741667ab73be522c95be9315b Mon Sep 17 00:00:00 2001 From: vanitha1822 Date: Thu, 20 Aug 2026 12:14:00 +0530 Subject: [PATCH 1/2] Revert "fix: add the range to sync" This reverts commit 92b3f200bd6ba2539ca5efa179952d14acd553bf. --- .../environment/common_example.properties | 5 - .../NHM_DashboardServiceImpl.java | 142 ++++-------------- 2 files changed, 26 insertions(+), 121 deletions(-) diff --git a/src/main/environment/common_example.properties b/src/main/environment/common_example.properties index 8e3d969d..8b23d6f5 100644 --- a/src/main/environment/common_example.properties +++ b/src/main/environment/common_example.properties @@ -95,11 +95,6 @@ cron-scheduler-everwelldatasync=0 0/5 * * * ? * start-nhmdashboard-scheduler=true cron-scheduler-nhmdashboard=0 1 0 * * ? * nhm-detailedcallreport-backfill-days=7 -# one-off recovery of older / partly imported days (yyyy-MM-dd, both inclusive, -# max 60 days per run). Leave empty during normal operation - while these are set -# the job pulls this range instead of only the missing days. -nhm-detailedcallreport-backfill-start-date= -nhm-detailedcallreport-backfill-end-date= ##----------------------------------------------------#grievance data sync----------------------------------------------------------- start-grievancedatasync-scheduler=false diff --git a/src/main/java/com/iemr/common/service/nhm_dashboard/NHM_DashboardServiceImpl.java b/src/main/java/com/iemr/common/service/nhm_dashboard/NHM_DashboardServiceImpl.java index d86c1ad9..3360cdd7 100644 --- a/src/main/java/com/iemr/common/service/nhm_dashboard/NHM_DashboardServiceImpl.java +++ b/src/main/java/com/iemr/common/service/nhm_dashboard/NHM_DashboardServiceImpl.java @@ -75,14 +75,6 @@ public class NHM_DashboardServiceImpl implements NHM_DashboardService { @Value("${nhm-detailedcallreport-backfill-days:7}") private int detailedCallReportBackfillDays; - @Value("${nhm-detailedcallreport-backfill-start-date:}") - private String backfillStartDate; - - @Value("${nhm-detailedcallreport-backfill-end-date:}") - private String backfillEndDate; - - private static final int MAX_EXPLICIT_BACKFILL_DAYS = 60; - public String pushAbandonCalls(AbandonCallSummary abandonCallSummary) throws Exception { logger.info("NHM_abandon call push API request : " + abandonCallSummary.toString()); @@ -137,6 +129,7 @@ public String getDetailedCallReport() throws Exception { return new Gson().toJson(resultSet); } + // JOB calling C-Zentrix 2 APIs => AgentSummaryReport & DetailedCallReport public String pull_NHM_Data_CTI() throws IEMRException { String response = ""; String result1 = ""; @@ -152,12 +145,14 @@ public String pull_NHM_Data_CTI() throws IEMRException { } StringBuilder detailedCallReportResult = new StringBuilder(); + // each pending day is pulled separately, so that one failing day does not stop + // the remaining days for (LocalDate callDate : getPendingDetailedCallReportDates()) { try { List detailedCallReportList = callDetailedCallReportCTI_API(callDate); if (detailedCallReportList.size() > 0) { detailedCallReportResult.append(callDate).append(" : ") - .append(saveNewDetailedCallReport(detailedCallReportList, callDate)).append("; "); + .append(saveDetailedCallReport(detailedCallReportList)).append("; "); } } catch (Exception e) { logger.error("DetailedCallReport pull failed for " + callDate + " - " + e.getLocalizedMessage()); @@ -168,45 +163,23 @@ public String pull_NHM_Data_CTI() throws IEMRException { return response.concat(result1).concat(" ").concat(result2); } - + /** + * Days (oldest first) for which detailed call report data still has to be + * pulled from CTI - yesterday plus any earlier day within the backfill window + * that has no data at all. Without this, a day missed because CTI was down or + * throttled ("Please wait for 1 hour") was never requested again and stayed + * permanently missing from the report. + */ List getPendingDetailedCallReportDates() { - LocalDate yesterday = LocalDate.now().minusDays(1); - - LocalDate explicitStart = parseBackfillDate(backfillStartDate, "start"); - LocalDate explicitEnd = parseBackfillDate(backfillEndDate, "end"); - if (explicitStart != null) { - LocalDate lastDate = explicitEnd != null ? explicitEnd : yesterday; - // today is still in progress, never pull it - if (lastDate.isAfter(yesterday)) - lastDate = yesterday; - if (lastDate.isBefore(explicitStart)) { - logger.error("Configured detailed call report backfill range is empty - start " + explicitStart - + " is after end " + lastDate + ", falling back to the missing day check"); - } else { - List explicitDates = new ArrayList<>(); - for (LocalDate date = explicitStart; !date.isAfter(lastDate); date = date.plusDays(1)) { - if (explicitDates.size() >= MAX_EXPLICIT_BACKFILL_DAYS) { - logger.warn("Configured detailed call report backfill range exceeds " - + MAX_EXPLICIT_BACKFILL_DAYS + " days - stopping at " + date.minusDays(1) - + ", move the start date forward and run again to continue"); - break; - } - explicitDates.add(date); - } - logger.info("DetailedCallReport configured backfill range " + explicitStart + " to " + lastDate - + " - pulling " + explicitDates.size() + " day(s)"); - return explicitDates; - } - } - + LocalDate lastDate = LocalDate.now().minusDays(1); int lookBackDays = detailedCallReportBackfillDays > 0 ? detailedCallReportBackfillDays : 1; - LocalDate firstDate = yesterday.minusDays(lookBackDays - 1L); + LocalDate firstDate = lastDate.minusDays(lookBackDays - 1L); Set existingDates = new HashSet<>(); try { List dates = detailedCallReportRepo.findExistingCallDates( Timestamp.valueOf(firstDate.atStartOfDay()), - Timestamp.valueOf(yesterday.atTime(LocalTime.MAX).withNano(0))); + Timestamp.valueOf(lastDate.atTime(LocalTime.MAX).withNano(0))); for (java.sql.Date date : dates) { if (date != null) existingDates.add(date.toLocalDate()); @@ -214,69 +187,18 @@ List getPendingDetailedCallReportDates() { } catch (Exception e) { // on any problem in gap detection, fall back to the previous behaviour logger.error("Error while detecting missing detailed call report dates - " + e.getLocalizedMessage()); - return Arrays.asList(yesterday); + return Arrays.asList(lastDate); } List pendingDates = new ArrayList<>(); - for (LocalDate date = firstDate; !date.isAfter(yesterday); date = date.plusDays(1)) { + for (LocalDate date = firstDate; !date.isAfter(lastDate); date = date.plusDays(1)) { if (!existingDates.contains(date)) pendingDates.add(date); } - logger.info("DetailedCallReport pending dates between " + firstDate + " and " + yesterday + " : " + pendingDates); + logger.info("DetailedCallReport pending dates between " + firstDate + " and " + lastDate + " : " + pendingDates); return pendingDates; } - private LocalDate parseBackfillDate(String value, String label) { - if (value == null || value.trim().isEmpty()) - return null; - try { - return LocalDate.parse(value.trim()); - } catch (Exception e) { - logger.error("Ignoring detailed call report backfill " + label + " date '" + value - + "' - expected format yyyy-MM-dd"); - return null; - } - } - - String saveNewDetailedCallReport(List detailedCallReportList, LocalDate callDate) - throws IEMRException { - parseDetailedCallReportTimestamps(detailedCallReportList); - - Set existingKeys = new HashSet<>(); - for (DetailedCallReport existing : detailedCallReportRepo.findByCallStartTimeBetween( - Timestamp.valueOf(callDate.atStartOfDay()), - Timestamp.valueOf(callDate.atTime(LocalTime.MAX).withNano(0)))) { - existingKeys.add(getDetailedCallReportKey(existing)); - } - - List newRecords = new ArrayList<>(); - for (DetailedCallReport detailedCallReport : detailedCallReportList) { - if (existingKeys.add(getDetailedCallReportKey(detailedCallReport))) - newRecords.add(detailedCallReport); - } - - int duplicates = detailedCallReportList.size() - newRecords.size(); - if (newRecords.isEmpty()) { - logger.info("DetailedCallReport " + callDate + " - all " + detailedCallReportList.size() - + " record(s) already present, nothing to save"); - return "0 records saved, " + duplicates + " already present"; - } - - List resultSet = (List) detailedCallReportRepo.saveAll(newRecords); - logger.info("DetailedCallReport " + callDate + " - pulled " + detailedCallReportList.size() + ", saved " - + resultSet.size() + ", already present " + duplicates); - return resultSet.size() + " records saved, " + duplicates + " already present"; - } - - /** - * Natural key of a call record. A session can hold more than one leg (transfer, - * redial), so the phone number and start time are part of the key as well. - */ - private String getDetailedCallReportKey(DetailedCallReport detailedCallReport) { - return String.valueOf(detailedCallReport.getSession_ID()) + '|' + detailedCallReport.getPHONE() + '|' - + detailedCallReport.getCallStartTime() + '|' + detailedCallReport.getAgent_ID(); - } - public String saveAgentSummaryReport(List agentSummaryReportList) throws IEMRException { List resultSet = (List) agentSummaryReportRepo @@ -288,26 +210,7 @@ public String saveAgentSummaryReport(List agentSummaryReport public String saveDetailedCallReport(List detailedCallReportList) throws IEMRException { if (detailedCallReportList != null && detailedCallReportList.size() > 0) { - parseDetailedCallReportTimestamps(detailedCallReportList); - - List resultSet = (List) detailedCallReportRepo - .saveAll(detailedCallReportList); - - return resultSet.size() + " detailedCallReport records saved successfully"; - } else - throw new IEMRException("please pass valid DetailedCallReport data in list"); - } - - /** - * CTI sends the times as strings; they are moved into the timestamp columns - * here. Has to run before the records are compared against what is already - * stored, because the comparison uses the parsed start time. - */ - private void parseDetailedCallReportTimestamps(List detailedCallReportList) { - if (detailedCallReportList == null) - return; - - for (DetailedCallReport detailedCallReport : detailedCallReportList) { + for (DetailedCallReport detailedCallReport : detailedCallReportList) { try { if (detailedCallReport.getCall_Start_Time() != null && !detailedCallReport.getCall_Start_Time().equalsIgnoreCase("0000-00-00 00:00:00")) @@ -341,7 +244,14 @@ private void parseDetailedCallReportTimestamps(List detailed } catch (Exception e) { logger.error("Call_Start_Time" + e.getLocalizedMessage()); } - } + } + + List resultSet = (List) detailedCallReportRepo + .saveAll(detailedCallReportList); + + return resultSet.size() + " detailedCallReport records saved successfully"; + } else + throw new IEMRException("please pass valid DetailedCallReport data in list"); } public List callAgentSummaryReportCTI_API() throws IEMRException { From a1b7d7f2eb7cea1092591003ed773a06084d54ac Mon Sep 17 00:00:00 2001 From: vanitha1822 Date: Thu, 20 Aug 2026 12:14:16 +0530 Subject: [PATCH 2/2] Revert "fix: call report issue for 104" This reverts commit a47b709730b9134a39fc2d99b425b832473f2b20. --- .../environment/common_example.properties | 7 +- .../NHMDetailCallReportScheduler.java | 19 +-- .../nhm_dashboard/DetailedCallReportRepo.java | 12 -- .../ctiCall/CallCentreDataSyncImpl.java | 124 ++++++++---------- .../NHM_DashboardServiceImpl.java | 86 +++--------- 5 files changed, 82 insertions(+), 166 deletions(-) diff --git a/src/main/environment/common_example.properties b/src/main/environment/common_example.properties index 8b23d6f5..ac440991 100644 --- a/src/main/environment/common_example.properties +++ b/src/main/environment/common_example.properties @@ -71,9 +71,9 @@ cron-scheduler-ctidatasync=0 30 01 * * ? * ##-------------------------------###cti data check with call detail report Scheduler------------------------------------------------------ -#Runs at everyday 3:00AM - after the NHM data pull and CTI data sync complete +#Runs at everyday 12:10AM start-ctidatacheck-scheduler=false -cron-scheduler-ctidatacheck=0 00 03 * * * +cron-scheduler-ctidatacheck=0 00 02 * * * ##---------------------------------#### Registration schedular for Avni------------------------------------------------------------------------------ @@ -93,8 +93,7 @@ cron-scheduler-everwelldatasync=0 0/5 * * * ? * ##-----------------------------------------------#NHM data dashboard schedular---------------------------------------------------------------- # run at everyday 12:01AM start-nhmdashboard-scheduler=true -cron-scheduler-nhmdashboard=0 1 0 * * ? * -nhm-detailedcallreport-backfill-days=7 +cron-scheduler-nhmdashboard=0 1 * * * ? * ##----------------------------------------------------#grievance data sync----------------------------------------------------------- start-grievancedatasync-scheduler=false diff --git a/src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java b/src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java index 31e72019..d02eb3f2 100644 --- a/src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java +++ b/src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java @@ -41,23 +41,18 @@ public class NHMDetailCallReportScheduler { @Value("${start-ctidatacheck-scheduler}") private boolean startCtiDataCheckFlag; - /** - * Number of days (ending yesterday) checked against t_bencall. Kept in sync with - * the detailed call report backfill window, so that days pulled late from CTI are - * also reconciled. The reconciliation itself is idempotent. - */ - @Value("${nhm-detailedcallreport-backfill-days:7}") - private int lookBackDays; @Scheduled(cron = "${cron-scheduler-ctidatacheck}") public void detailedCallReport() { if (startCtiDataCheckFlag) { try { - int days = lookBackDays > 0 ? lookBackDays : 1; - LocalDateTime endDay = LocalDateTime.now().minusDays(1); - LocalDateTime startDay = endDay.minusDays(days - 1L); - String endDate = endDay.toString().split("T")[0].concat(" 23:59:59"); - String fromDate = startDay.toString().split("T")[0].concat(" 00:00:00"); + String endDate = null; + String fromDate = null; + LocalDateTime date = null; + date = LocalDateTime.now().minusDays(1); + String[] dateArr = date.toString().split("T"); + endDate = dateArr[0].concat(" 23:59:59"); + fromDate = dateArr[0].concat(" 00:00:01"); Timestamp fromTime = Timestamp.valueOf(fromDate); Timestamp endTime = Timestamp.valueOf(endDate); diff --git a/src/main/java/com/iemr/common/repository/nhm_dashboard/DetailedCallReportRepo.java b/src/main/java/com/iemr/common/repository/nhm_dashboard/DetailedCallReportRepo.java index f4c5b125..bb89881b 100644 --- a/src/main/java/com/iemr/common/repository/nhm_dashboard/DetailedCallReportRepo.java +++ b/src/main/java/com/iemr/common/repository/nhm_dashboard/DetailedCallReportRepo.java @@ -21,13 +21,10 @@ */ package com.iemr.common.repository.nhm_dashboard; -import java.sql.Date; import java.sql.Timestamp; import java.util.List; -import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import com.iemr.common.data.nhm_dashboard.DetailedCallReport; @@ -35,13 +32,4 @@ @Repository public interface DetailedCallReportRepo extends CrudRepository { List findByCallStartTimeBetween(Timestamp startDate, Timestamp endDate); - - /** - * Call dates for which data has already been pulled from CTI. Used to detect - * the days that were missed by earlier scheduler runs, so that they can be - * pulled again instead of staying permanently empty. - */ - @Query(value = "select distinct date(Call_Start_Time) from t_DetailedCallReport " - + "where Call_Start_Time between :startDate and :endDate", nativeQuery = true) - List findExistingCallDates(@Param("startDate") Timestamp startDate, @Param("endDate") Timestamp endDate); } diff --git a/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java b/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java index f568fe9e..b3cfaf9c 100644 --- a/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java +++ b/src/main/java/com/iemr/common/service/ctiCall/CallCentreDataSyncImpl.java @@ -83,10 +83,10 @@ public String callUrl(String urlRequest) { @Override public void ctiDataSync() { LocalDate currentDate = LocalDate.now(); - // Look back 7 days to retry records that failed in previous runs - LocalDate startDate = currentDate.minusDays(7); - // Up to yesterday - LocalDate endDate = currentDate.minusDays(1); + // Calculate three days before the current date + LocalDate startDate = currentDate.minusDays(3); + // Calculate two days before the current date + LocalDate endDate = currentDate.minusDays(2); // Convert LocalDate to LocalDateTime to set time as 00:00:00 LocalDateTime startDateTime = startDate.atTime(0, 0, 0); LocalDateTime endDateTime = endDate.atTime(23, 59, 59); @@ -98,78 +98,64 @@ public void ctiDataSync() { List list = callReportRepo.getAllBenCallIDetails(startTimeStamp, endTimeStamp); if (!list.isEmpty()) { - logger.info("Total records to process for CTI data sync: " + list.size()); + + // List benList = new ArrayList<>(); + String callDuartion = null; + String filePath = null; + String URL = null; + String callinfoapiURL = null; + String ctiResponse = null; + String callEndTime = null; + String callStartTime = null; + String recordingPath = ""; for (BeneficiaryCall call : list) { - if (call.getCallID() == null) { - logger.warn("Skipping record with null callID, benCallID: " + call.getBenCallID()); - continue; - } - String recordingPath = null; - String callDuartion = null; - String callEndTime = null; - String callStartTime = null; - try { - JSONObject requestFile = new JSONObject(); - requestFile.put("agent_id", call.getAgentID()); - requestFile.put("session_id", call.getCallID()); - - OutputResponse response1 = ctiService.getVoiceFileNew(requestFile.toString(), "extra parameter"); - if(response1 != null && response1.getStatusCode() == 200) { - - CTIResponse ctiResponsePath = InputMapper.gson().fromJson(response1.getData(), - CTIResponse.class); - String recordingFilePath = ctiResponsePath.getResponse().toString(); - if(recordingFilePath.length() > 20) - recordingPath = recordingFilePath.substring(20); - else if (!recordingFilePath.isEmpty()) - recordingPath = recordingFilePath; - logger.info("recordingPath: " + recordingPath); - } - - String callInfoURL = this.callinfoapiURL; - String URL = callInfoURL.replace("CTI_SERVER", ctiServerIP).replace("AGENT_ID", call.getAgentID()) - .replace("SESSION_ID", call.getCallID()).replace("PHONE_NO", call.getPhoneNo()); - - logger.info("calling CTI API url: " + URL); - String ctiResponse = this.callUrl(URL); - logger.info("calling CTI_CDR_CALL_INFO API returned " + ctiResponse); - - CTIData data = InputMapper.gson().fromJson(ctiResponse, CTIData.class); - CTIResponse model = data.getResponse(); - - if (model != null && "1".equals(model.getResponse_code())) { - callDuartion = model.getCall_duration(); - callEndTime = model.getCall_end_date_time(); - callStartTime = model.getCall_start_date_time(); - } else { - logger.warn("CTI API returned non-success for sessionID: " + call.getCallID() - + ", response_code: " + (model != null ? model.getResponse_code() : "null")); - } - - // Only save if we got at least the call duration from CTI - if (callDuartion != null) { - call.setCZcallDuration(Integer.parseInt(callDuartion)); + if (call.getCallID() != null) { + recordingPath = null; + try { + JSONObject requestFile = new JSONObject(); + requestFile.put("agent_id", call.getAgentID()); + requestFile.put("session_id", call.getCallID()); + + OutputResponse response1 = ctiService.getVoiceFileNew(requestFile.toString(), "extra parameter"); + if(response1 != null && response1.getStatusCode() == 200) { + + CTIResponse ctiResponsePath = InputMapper.gson().fromJson(response1.getData(), + CTIResponse.class); + String recordingFilePath = ctiResponsePath.getResponse().toString(); + if(recordingFilePath.length() > 20) + recordingPath = recordingFilePath.substring(20); + logger.info("recordingPath: " + recordingPath); + } + + callDuartion = null; + callinfoapiURL = this.callinfoapiURL; + URL = callinfoapiURL.replace("CTI_SERVER", ctiServerIP).replace("AGENT_ID", call.getAgentID()) + .replace("SESSION_ID", call.getCallID()).replace("PHONE_NO", call.getPhoneNo()); + + logger.info("calling CTI API url: " + URL); + ctiResponse = this.callUrl(URL); + logger.info("calling CTI_CDR_CALL_INFO API returned " + ctiResponse); + + CTIData data = InputMapper.gson().fromJson(ctiResponse, CTIData.class); + CTIResponse model = data.getResponse(); + + if (model.getResponse_code().equals("1")) { + callDuartion = model.getCall_duration(); + callEndTime = model.getCall_end_date_time(); + callStartTime = model.getCall_start_date_time(); + } + if (callDuartion != null) + call.setCZcallDuration(Integer.parseInt(callDuartion)); + call.setRecordingPath(recordingPath); call.setCZcallEndTime(callEndTime); call.setCZcallStartTime(callStartTime); - call.setRecordingPath(recordingPath); - callReportRepo.save(call); - logger.info("CTI data sync saved for benCallID: " + call.getBenCallID()); - } else if (recordingPath != null) { - // Duration not available yet, but recording path is — save path only - call.setRecordingPath(recordingPath); callReportRepo.save(call); - logger.info("Only recordingPath saved (duration pending) for benCallID: " + call.getBenCallID()); - } else { - logger.warn("No CTI data available yet for sessionID: " + call.getCallID() - + ", benCallID: " + call.getBenCallID() + " - will retry next run"); + logger.info("calling CTI_CDR_CALL_INFO after API call save response " + call); + } catch (Exception e) { + logger.error("VoiceFile failed with error " + e.getMessage(), e); } - } catch (Exception e) { - logger.error("CTI data sync failed for benCallID: " + call.getBenCallID() - + ", sessionID: " + call.getCallID() + " - " + e.getMessage(), e); } } - } else { - logger.info("No pending records found for CTI data sync"); } } } \ No newline at end of file diff --git a/src/main/java/com/iemr/common/service/nhm_dashboard/NHM_DashboardServiceImpl.java b/src/main/java/com/iemr/common/service/nhm_dashboard/NHM_DashboardServiceImpl.java index 3360cdd7..d7afd579 100644 --- a/src/main/java/com/iemr/common/service/nhm_dashboard/NHM_DashboardServiceImpl.java +++ b/src/main/java/com/iemr/common/service/nhm_dashboard/NHM_DashboardServiceImpl.java @@ -24,13 +24,10 @@ import java.sql.Timestamp; import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.LocalTime; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,13 +65,6 @@ public class NHM_DashboardServiceImpl implements NHM_DashboardService { @Value("${cti-server-ip}") private String serverURL; - /** - * Number of days (ending yesterday) the detailed call report pull looks back to - * re-pull days that were missed. 1 = previous day only, i.e. old behaviour. - */ - @Value("${nhm-detailedcallreport-backfill-days:7}") - private int detailedCallReportBackfillDays; - public String pushAbandonCalls(AbandonCallSummary abandonCallSummary) throws Exception { logger.info("NHM_abandon call push API request : " + abandonCallSummary.toString()); @@ -144,59 +134,17 @@ public String pull_NHM_Data_CTI() throws IEMRException { logger.error(e.getLocalizedMessage()); } - StringBuilder detailedCallReportResult = new StringBuilder(); - // each pending day is pulled separately, so that one failing day does not stop - // the remaining days - for (LocalDate callDate : getPendingDetailedCallReportDates()) { - try { - List detailedCallReportList = callDetailedCallReportCTI_API(callDate); - if (detailedCallReportList.size() > 0) { - detailedCallReportResult.append(callDate).append(" : ") - .append(saveDetailedCallReport(detailedCallReportList)).append("; "); - } - } catch (Exception e) { - logger.error("DetailedCallReport pull failed for " + callDate + " - " + e.getLocalizedMessage()); - } - } - result2 = detailedCallReportResult.toString(); - - return response.concat(result1).concat(" ").concat(result2); - } - - /** - * Days (oldest first) for which detailed call report data still has to be - * pulled from CTI - yesterday plus any earlier day within the backfill window - * that has no data at all. Without this, a day missed because CTI was down or - * throttled ("Please wait for 1 hour") was never requested again and stayed - * permanently missing from the report. - */ - List getPendingDetailedCallReportDates() { - LocalDate lastDate = LocalDate.now().minusDays(1); - int lookBackDays = detailedCallReportBackfillDays > 0 ? detailedCallReportBackfillDays : 1; - LocalDate firstDate = lastDate.minusDays(lookBackDays - 1L); - - Set existingDates = new HashSet<>(); try { - List dates = detailedCallReportRepo.findExistingCallDates( - Timestamp.valueOf(firstDate.atStartOfDay()), - Timestamp.valueOf(lastDate.atTime(LocalTime.MAX).withNano(0))); - for (java.sql.Date date : dates) { - if (date != null) - existingDates.add(date.toLocalDate()); + List detailedCallReportList = callDetailedCallReportCTI_API(); + if (detailedCallReportList.size() > 0) { + result2 = saveDetailedCallReport(detailedCallReportList); + } } catch (Exception e) { - // on any problem in gap detection, fall back to the previous behaviour - logger.error("Error while detecting missing detailed call report dates - " + e.getLocalizedMessage()); - return Arrays.asList(lastDate); + logger.error(e.getLocalizedMessage()); } - List pendingDates = new ArrayList<>(); - for (LocalDate date = firstDate; !date.isAfter(lastDate); date = date.plusDays(1)) { - if (!existingDates.contains(date)) - pendingDates.add(date); - } - logger.info("DetailedCallReport pending dates between " + firstDate + " and " + lastDate + " : " + pendingDates); - return pendingDates; + return response.concat(result1).concat(" ").concat(result2); } public String saveAgentSummaryReport(List agentSummaryReportList) throws IEMRException { @@ -265,8 +213,8 @@ public List callAgentSummaryReportCTI_API() throws IEMRExcep date = LocalDateTime.now().minusDays(1); String[] dateArr = date.toString().split("T"); endDate = dateArr[0].concat(" 23:59:59"); - fromDate = dateArr[0].concat(" 00:00:00"); - + fromDate = dateArr[0].concat(" 00:00:01"); + // if (job != null && job.toLowerCase().contains("hour")) { // String jobVal = job.split(" ")[0]; // LocalDateTime nowTime = LocalDateTime.now(); @@ -300,18 +248,18 @@ else if (response.toLowerCase().contains("no data")) } public List callDetailedCallReportCTI_API() throws IEMRException { - return callDetailedCallReportCTI_API(LocalDate.now().minusDays(1)); - } - - public List callDetailedCallReportCTI_API(LocalDate callDate) throws IEMRException { List detailedCallReportList = new ArrayList(); // String job = ConfigProperties.getPropertyByName("get-details-call-report-job"); - // full day window - 00:00:00 and not 00:00:01, else calls placed in the very - // first second of the day are dropped - String fromDate = callDate.toString().concat(" 00:00:00"); - String endDate = callDate.toString().concat(" 23:59:59"); - + String endDate = null; + String fromDate = null; + + LocalDateTime date = null; + date = LocalDateTime.now().minusDays(1); + String[] dateArr = date.toString().split("T"); + endDate = dateArr[0].concat(" 23:59:59"); + fromDate = dateArr[0].concat(" 00:00:01"); + // if (job != null && job.toLowerCase().contains("hour")) { // String jobVal = job.split(" ")[0]; // LocalDateTime nowTime = LocalDateTime.now();