diff --git a/src/main/java/com/datastat/controller/QueryController.java b/src/main/java/com/datastat/controller/QueryController.java index 6b3a7f9..d52a8c8 100644 --- a/src/main/java/com/datastat/controller/QueryController.java +++ b/src/main/java/com/datastat/controller/QueryController.java @@ -839,4 +839,15 @@ public String monthDownCount(HttpServletRequest request, public String viewCount(HttpServletRequest request, @Valid final RequestParams condition) { return queryService.getViewCount(request, condition); } + + /** + * Handles the request to view the modelers blog count. + * + * @param request the HttpServletRequest object containing client request data + * @return a String representing the view count of the modelers blog + */ + @RequestMapping(value = "/modelers/blog/view") + public String modelersBlogView(HttpServletRequest request) { + return queryService.getModelersBlogViewCount(request); + } } \ No newline at end of file diff --git a/src/main/java/com/datastat/dao/QueryDao.java b/src/main/java/com/datastat/dao/QueryDao.java index 7302851..7e53df4 100644 --- a/src/main/java/com/datastat/dao/QueryDao.java +++ b/src/main/java/com/datastat/dao/QueryDao.java @@ -3962,4 +3962,37 @@ public String getViewCount(CustomPropertiesConfig queryConf, RequestParams condi } return ResultUtil.resultJsonStr(statusCode, buckets, statusText); } + + /** + * Retrieves the view count for modeler's blog. + * + * @param queryConf Custom properties configuration object containing the necessary configuration information for the query. + * @return A JSON string containing the status code, result data, and status text. + * @throws Exception If an exception occurs during the execution of the query or processing of the response. + */ + @SneakyThrows + public String getModelersBlogViewCount(CustomPropertiesConfig queryConf) { + String query = String.format(queryConf.getModelersBlogViewCountQueryStr()); + ListenableFuture future = esAsyncHttpUtil.executeSearch(esUrl, queryConf.getModelersTrackerIndex(), query); + Response response = future.get(); + int statusCode = response.getStatusCode(); + String statusText = response.getStatusText(); + String responseBody = response.getResponseBody(UTF_8); + JsonNode dataNode = objectMapper.readTree(responseBody); + var buckets = dataNode.get("aggregations").get("group_by_id_and_title").get("buckets"); + var resJsonArray = objectMapper.createArrayNode(); + try { + for (var bucket : buckets) { + var jsonObject = objectMapper.createObjectNode(); + jsonObject.put("id", bucket.get("key").get("id").asText()); + jsonObject.put("title", bucket.get("key").get("title").asText()); + jsonObject.put("count", bucket.get("doc_count").asInt()); + resJsonArray.add(jsonObject); + } + } catch (Exception e) { + logger.error("query/modelers/blog/view get error - {}", e.getMessage()); + return ResultUtil.resultJsonStr(statusCode, objectMapper.valueToTree(resJsonArray), "No data found or query error"); + } + return ResultUtil.resultJsonStr(statusCode, objectMapper.valueToTree(resJsonArray), statusText); + } } diff --git a/src/main/java/com/datastat/model/CustomPropertiesConfig.java b/src/main/java/com/datastat/model/CustomPropertiesConfig.java index 3eef44a..34bb513 100644 --- a/src/main/java/com/datastat/model/CustomPropertiesConfig.java +++ b/src/main/java/com/datastat/model/CustomPropertiesConfig.java @@ -119,6 +119,7 @@ public class CustomPropertiesConfig { private String datasetEventIndex; private String openmindRepoIndex; private String searchNpsIndex; + private String modelersTrackerIndex; // -- query str -- private String extOsQueryStr; @@ -227,6 +228,7 @@ public class CustomPropertiesConfig { private String starCountQueryStr; private String openmindRepoQueryStr; private String repoViewCountQueryStr; + private String modelersBlogViewCountQueryStr; protected static final Map contributeTypeMap = new HashMap<>(); protected static final Map groupFieldMap = new HashMap<>(); diff --git a/src/main/java/com/datastat/service/QueryService.java b/src/main/java/com/datastat/service/QueryService.java index 7e517eb..8663490 100644 --- a/src/main/java/com/datastat/service/QueryService.java +++ b/src/main/java/com/datastat/service/QueryService.java @@ -1702,4 +1702,26 @@ public String getViewCount(HttpServletRequest request, RequestParams condition) } return result; } + + /** + * Retrieves the view count for the modelers blog from cache or database. + * + * This method attempts to fetch the view count of the modelers blog from a Redis cache. + * If the cache does not contain the data, it queries the database to obtain the view count + * and then stores this data in the cache for future requests. + * + * @param request the HttpServletRequest object, which may contain information needed for the database query + * @return the view count of the modelers blog as a String + */ + public String getModelersBlogViewCount(HttpServletRequest request) { + QueryDao queryDao = getQueryDao(request); + CustomPropertiesConfig queryConf = getQueryConf("foundry"); + String key = "get_modelers_blogview_count"; + String result = (String) redisDao.get(key); + if (result == null) { + result = queryDao.getModelersBlogViewCount(queryConf); + redisDao.set(key, result, redisDefaultExpire); + } + return result; + } }