|
|
@@ -39,10 +39,17 @@ import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -339,52 +346,82 @@ public class AgentIndexController {
|
|
|
|
|
|
@ApiOperation("查询用户行为数据统计")
|
|
|
@PostMapping("/userStatistic")
|
|
|
- public Result<?> userStatistic() {
|
|
|
- HashMap<String, Object> result = new HashMap<>();
|
|
|
- AppUserQueryParam param = new AppUserQueryParam();
|
|
|
- // 1. 查询今日数据
|
|
|
- param.setStartTime(DateUtil.getTodayStart());
|
|
|
- param.setEndTime(DateUtil.getTodayEnd());
|
|
|
- List<YtDyzUser> todayUsers = appFeign.queryUserByTime(param);
|
|
|
- //每个小时的用户数
|
|
|
- int[] todayUser = appFeign.queryUserByTodayTime();
|
|
|
- //今日登入
|
|
|
- List<String> todayLogin = appFeign.queryLoginRecords(param);
|
|
|
- Result<Map<String, Integer>> mapResult = riskFeign.queryBanned(param);
|
|
|
- Map<String, int[]> data = riskFeign.queryBannedByHourToday().getData();
|
|
|
- Map<String, Integer> todayMap = mapResult.getData();
|
|
|
- //用户新增数
|
|
|
- result.put("today", todayUsers.size());
|
|
|
- result.put("todayLogin", todayLogin.size());
|
|
|
- result.put("todayRisk", todayMap.get("risk"));
|
|
|
- result.put("todayLock", todayMap.get("lock"));
|
|
|
- result.put("todayRiskHour", data.get("riskHour"));
|
|
|
- result.put("todayLockHour", data.get("lockHour"));
|
|
|
- //每个小时的用户数
|
|
|
- result.put("todayUser", todayUser);
|
|
|
- // 2. 查询昨日数据
|
|
|
- param.setStartTime(DateUtil.getYesterdayStart());
|
|
|
- param.setEndTime(DateUtil.getYesterdayEnd());
|
|
|
- List<YtDyzUser> yesterdayUsers = appFeign.queryUserByTime(param);
|
|
|
- List<String> yesterdayLogin = appFeign.queryLoginRecords(param);
|
|
|
- Map<String, Integer> yesterdayMap = riskFeign.queryBanned(param).getData();
|
|
|
- result.put("yesterday", yesterdayUsers.size());
|
|
|
- result.put("yesterdayLogin", yesterdayLogin.size());
|
|
|
- //封禁数
|
|
|
- result.put("yesterdayRisk", yesterdayMap.get("risk"));
|
|
|
- //锁定数
|
|
|
- result.put("yesterdayLock", yesterdayMap.get("lock"));
|
|
|
- // 3. 查询本月数据
|
|
|
- param.setStartTime(DateUtil.getMonthStart());
|
|
|
- param.setEndTime(DateUtil.getMonthEnd());
|
|
|
- List<String> monthLogin = appFeign.queryLoginRecords(param);
|
|
|
- List<YtDyzUser> monthUsers = appFeign.queryUserByTime(param);
|
|
|
- Map<String, Integer> monthMap = riskFeign.queryBanned(param).getData();
|
|
|
- result.put("month", monthUsers.size());
|
|
|
- result.put("monthLogin", monthLogin.size());
|
|
|
- result.put("monthRisk", monthMap.get("risk"));
|
|
|
- result.put("monthLock", monthMap.get("lock"));
|
|
|
+ public Result<Map<String, Object>> getDashboardData() throws InterruptedException {
|
|
|
+ Map<String, Object> result = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
+ processPeriodData(result, "today",
|
|
|
+ DateUtil.getTodayStart(),
|
|
|
+ DateUtil.getTodayEnd(),
|
|
|
+ true);
|
|
|
+
|
|
|
+ processPeriodData(result, "yesterday",
|
|
|
+ DateUtil.getYesterdayStart(),
|
|
|
+ DateUtil.getYesterdayEnd(),
|
|
|
+ false);
|
|
|
+
|
|
|
+ processPeriodData(result, "month",
|
|
|
+ DateUtil.getMonthStart(),
|
|
|
+ DateUtil.getMonthEnd(),
|
|
|
+ false);
|
|
|
+
|
|
|
return Result.resultObjOk(result);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 统一处理时间段数据的公共方法
|
|
|
+ private void processPeriodData(Map<String, Object> result,
|
|
|
+ String prefix,
|
|
|
+ Date startTime,
|
|
|
+ Date endTime,
|
|
|
+ boolean isToday) {
|
|
|
+ AppUserQueryParam param = new AppUserQueryParam();
|
|
|
+ param.setStartTime(startTime);
|
|
|
+ param.setEndTime(endTime);
|
|
|
+
|
|
|
+ // 获取基础数据
|
|
|
+ int userCount = appFeign.queryUserByTime(param).size();
|
|
|
+ int loginCount = appFeign.queryLoginRecords(param).size();
|
|
|
+
|
|
|
+ try {
|
|
|
+ log.info("调用风险查询接口,参数: {}", param);
|
|
|
+
|
|
|
+ // 拆解调用步骤
|
|
|
+ Result<Map<String, Integer>> response = riskFeign.queryBanned(param);
|
|
|
+
|
|
|
+ if(response == null) {
|
|
|
+ log.error("Feign调用返回null!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("服务返回状态码: {}", response.getCode()); // 假设有getCode()
|
|
|
+ log.info("服务返回消息: {}", response.getMessage());
|
|
|
+ Map<String, Integer> riskMap = response.getData();
|
|
|
+
|
|
|
+ if(riskMap == null) {
|
|
|
+ log.warn("服务返回data字段为null");
|
|
|
+ } else {
|
|
|
+ log.info("获取风险数据: {}", riskMap);
|
|
|
+ }
|
|
|
+ result.put(prefix + "Risk", riskMap.get("risk"));
|
|
|
+ result.put(prefix + "Lock", riskMap.get("lock"));
|
|
|
+ } catch(Exception e) {
|
|
|
+ log.error("Feign调用异常", e); // 捕获Feign异常
|
|
|
+ }
|
|
|
+
|
|
|
+ // 存储通用指标(线程安全操作)
|
|
|
+ result.put(prefix, userCount);
|
|
|
+ result.put(prefix + "Login", loginCount);
|
|
|
+
|
|
|
+
|
|
|
+ // 今日特有逻辑
|
|
|
+ if (isToday) {
|
|
|
+ int[] todayUser = appFeign.queryUserByTodayTime();
|
|
|
+ Map<String, int[]> data = riskFeign.queryBannedByHourToday().getData();
|
|
|
+
|
|
|
+ result.put("todayUser", todayUser);
|
|
|
+ result.put("todayRiskHour", data.get("riskHour"));
|
|
|
+ result.put("todayLockHour", data.get("lockHour"));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|