B.E.N.S.O.N 2 tygodni temu
rodzic
commit
e5277740a3
2 zmienionych plików z 28 dodań i 7 usunięć
  1. +18
    -4
      src/main/java/com/ffii/fpsms/modules/usage/FeatureUsageLogService.java
  2. +10
    -3
      src/main/java/com/ffii/fpsms/modules/usage/web/FeatureUsageLogController.java

+ 18
- 4
src/main/java/com/ffii/fpsms/modules/usage/FeatureUsageLogService.java Wyświetl plik

@@ -3,6 +3,7 @@ package com.ffii.fpsms.modules.usage;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.time.LocalDate;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@@ -41,18 +42,31 @@ public class FeatureUsageLogService extends AbstractService {
}

@Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class, readOnly = true)
public List<Map<String, Object>> summarizeByFeature(String featureCode) {
String sql = """
public List<Map<String, Object>> summarizeByFeature(String featureCode, LocalDate startDate, LocalDate endDate) {
StringBuilder sql = new StringBuilder("""
SELECT user_id AS userId, username,
SUM(CASE WHEN action_type = 'PAGE_VIEW' THEN 1 ELSE 0 END) AS pageViews,
SUM(CASE WHEN action_type = 'DOWNLOAD' THEN 1 ELSE 0 END) AS downloads,
SUM(CASE WHEN action_type = 'PRINT' THEN 1 ELSE 0 END) AS prints
FROM feature_usage_log
WHERE feature_code = :featureCode
""");
Map<String, Object> args = new HashMap<>(4);
args.put("featureCode", featureCode);
if (startDate != null) {
sql.append(" AND created_at >= :startDate");
args.put("startDate", startDate.atStartOfDay());
}
if (endDate != null) {
sql.append(" AND created_at < :endDateExclusive");
args.put("endDateExclusive", endDate.plusDays(1).atStartOfDay());
}
sql.append("""
GROUP BY user_id, username
ORDER BY username
""";
return jdbcDao.queryForList(sql, Map.of("featureCode", featureCode));
""");
return jdbcDao.queryForList(sql.toString(), args);
}

}

+ 10
- 3
src/main/java/com/ffii/fpsms/modules/usage/web/FeatureUsageLogController.java Wyświetl plik

@@ -1,6 +1,7 @@
package com.ffii.fpsms.modules.usage.web;

import java.util.HashMap;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@@ -11,6 +12,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@@ -91,12 +93,17 @@ public class FeatureUsageLogController {

@GetMapping("/summary")
@PreAuthorize("hasAnyAuthority('TESTING','ADMIN')")
public DataRes<Map<String, List<Map<String, Object>>>> summary() {
public DataRes<Map<String, List<Map<String, Object>>>> summary(
@RequestParam(value = "startDate", required = false) LocalDate startDate,
@RequestParam(value = "endDate", required = false) LocalDate endDate) {
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
throw new BadRequestException("startDate must be earlier than or equal to endDate");
}
Map<String, List<Map<String, Object>>> data = new HashMap<>(2);
data.put("reportManagement",
featureUsageLogService.summarizeByFeature(FeatureUsageLogService.FEATURE_REPORT_MANAGEMENT));
featureUsageLogService.summarizeByFeature(FeatureUsageLogService.FEATURE_REPORT_MANAGEMENT, startDate, endDate));
data.put("truckRoutingSummary",
featureUsageLogService.summarizeByFeature(FeatureUsageLogService.FEATURE_TRUCK_ROUTING_SUMMARY));
featureUsageLogService.summarizeByFeature(FeatureUsageLogService.FEATURE_TRUCK_ROUTING_SUMMARY, startDate, endDate));
return new DataRes<>(data);
}



Ładowanie…
Anuluj
Zapisz