class BackGroundServiceActor extends BaseActor {

  private void updateUserCount(Request actorMessage) {
    ProjectLogger.log("In BackgroundService actor in updateUserCount method.");
    Util.DbInfo locDbInfo = Util.dbInfoMap.get(JsonKey.GEO_LOCATION_DB);
    List<Object> locationIds = (List<Object>) actorMessage.getRequest().get(JsonKey.LOCATION_IDS);
    String operation = (String) actorMessage.getRequest().get(JsonKey.OPERATION);
    ProjectLogger.log("operation for updating UserCount" + operation);
    Response response =
        cassandraOperation.getRecordsByProperty(
            locDbInfo.getKeySpace(), locDbInfo.getTableName(), JsonKey.ID, locationIds);
    List<Map<String, Object>> list = (List<Map<String, Object>>) response.get(JsonKey.RESPONSE);
    if (null != list && !list.isEmpty()) {
      for (Map<String, Object> map : list) {
        String locationId = (String) map.get(JsonKey.ID);
        ProjectLogger.log("Processing start for LocationId " + locationId);
        Long userCountTTL = 0L;
        int userCount =
            (map.get(JsonKey.USER_COUNT) == null) ? 0 : (int) (map.get(JsonKey.USER_COUNT));
        ProjectLogger.log("userCount is " + userCount + "for location id " + locationId);
        if (userCount == 0
            && !StringUtils.isBlank(operation)
            && operation.equalsIgnoreCase("UpdateUserCountScheduler")) {
          ProjectLogger.log("Processing start for LocationId for Scheduler " + locationId);
          int count = getUserCount(locationId);
          Map<String, Object> reqMap = new HashMap<>();
          reqMap.put(JsonKey.ID, locationId);
          reqMap.put(JsonKey.USER_COUNT, count);
          reqMap.put(JsonKey.USER_COUNT_TTL, String.valueOf(System.currentTimeMillis()));
          cassandraOperation.updateRecord(
              locDbInfo.getKeySpace(), locDbInfo.getTableName(), reqMap);
        } else if (!StringUtils.isBlank(operation)
            && operation.equalsIgnoreCase("GeoLocationManagementActor")) {
          ProjectLogger.log(
              "Processing start for LocationId for GeoLocationManagementActor " + locationId);
          try {
            if (!StringUtils.isBlank((String) map.get(JsonKey.USER_COUNT_TTL))) {
              userCountTTL = Long.valueOf((String) map.get(JsonKey.USER_COUNT_TTL));
            }
          } catch (Exception ex) {
            ProjectLogger.log(
                "Exception occurred while converting string to long "
                    + (String) map.get(JsonKey.USER_COUNT_TTL));
            userCountTTL = 0L;
          }
          ProjectLogger.log("userCountTTL == " + userCountTTL);
          Long currentTime = System.currentTimeMillis();
          Long diff = currentTime - userCountTTL;
          int hours = (int) (diff / (1000 * 60 * 60));
          if (hours >= 24) {
            ProjectLogger.log("Updating user count for LocnId " + locationId);
            int usrCount = getUserCount(locationId);
            Map<String, Object> reqMap = new HashMap<>();
            reqMap.put(JsonKey.ID, locationId);
            reqMap.put(JsonKey.USER_COUNT, usrCount);
            reqMap.put(JsonKey.USER_COUNT_TTL, String.valueOf(System.currentTimeMillis()));
            cassandraOperation.updateRecord(
                locDbInfo.getKeySpace(), locDbInfo.getTableName(), reqMap);
          }
        }
      }
      ProjectLogger.log("Processing end user count update ");
    }
  }

}