|
@@ -1,31 +1,37 @@
|
|
|
package com.hfln.portal.infrastructure.gateway.impl;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.hfln.portal.common.constant.UserConstants;
|
|
|
import com.hfln.portal.common.dto.data.event.AlarmEventDTO;
|
|
|
import com.hfln.portal.common.dto.data.event.EventListDTO;
|
|
|
import com.hfln.portal.common.dto.data.event.StayTimeDTO;
|
|
|
+import com.hfln.portal.common.dto.data.user.UserDailyActiveResult;
|
|
|
+import com.hfln.portal.common.dto.data.user.UsersDailyActiveDTO;
|
|
|
import com.hfln.portal.common.request.event.AlarmEventParams;
|
|
|
import com.hfln.portal.common.request.event.EventListParams;
|
|
|
import com.hfln.portal.common.request.event.StayTimeParams;
|
|
|
+import com.hfln.portal.common.request.user.UserDailyActiveParams;
|
|
|
import com.hfln.portal.common.vo.PageRecord;
|
|
|
import com.hfln.portal.domain.customer.AdminUserType;
|
|
|
import com.hfln.portal.domain.customer.util.CopyUtils;
|
|
|
import com.hfln.portal.domain.gateway.WebStatsGateway;
|
|
|
import com.hfln.portal.infrastructure.po.AlarmEvent;
|
|
|
+import com.hfln.portal.infrastructure.po.DailyActiveUsers;
|
|
|
import com.hfln.portal.infrastructure.po.EventList;
|
|
|
import com.hfln.portal.infrastructure.po.StayTime;
|
|
|
-import com.hfln.portal.infrastructure.service.AlarmEventService;
|
|
|
-import com.hfln.portal.infrastructure.service.DevInfoService;
|
|
|
-import com.hfln.portal.infrastructure.service.EventService;
|
|
|
-import com.hfln.portal.infrastructure.service.StayTimeService;
|
|
|
+import com.hfln.portal.infrastructure.service.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
@@ -44,6 +50,9 @@ public class WebStatsGatewayImpl implements WebStatsGateway {
|
|
|
@Autowired
|
|
|
private AlarmEventService alarmEventService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DailyActiveUsersService dailyActiveUsersService;;
|
|
|
+
|
|
|
@Override
|
|
|
public PageRecord<EventListDTO> fallQuery(EventListParams params) {
|
|
|
Long tenantId = (Long) StpUtil.getSession().get(UserConstants.SA_USER_TENANT_ID);
|
|
@@ -119,5 +128,52 @@ public class WebStatsGatewayImpl implements WebStatsGateway {
|
|
|
// 封装成 PageRecord 返回
|
|
|
return CopyUtils.copyPage(page, dtoList);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserDailyActiveResult queryUserDailyActive(UserDailyActiveParams params) {
|
|
|
+
|
|
|
+ // 1.处理查询日期,入参为空则默认当天
|
|
|
+ LocalDate queryDate = (params.getQueryDate() != null) ? params.getQueryDate() : LocalDate.now();
|
|
|
+ LocalDateTime startOfDay = queryDate.atStartOfDay();
|
|
|
+ LocalDateTime endOfDay = queryDate.plusDays(1).atStartOfDay().minusNanos(1);
|
|
|
+
|
|
|
+ // 2. 查询总访问次数
|
|
|
+ LambdaQueryWrapper<DailyActiveUsers> countWrapper = new LambdaQueryWrapper<>();
|
|
|
+ countWrapper.eq(DailyActiveUsers::getUserId, params.getUserId())
|
|
|
+ .between(DailyActiveUsers::getCreateTime, startOfDay, endOfDay);
|
|
|
+ long totalCount = dailyActiveUsersService.count(countWrapper);
|
|
|
+
|
|
|
+ if (totalCount == 0) {
|
|
|
+ UserDailyActiveResult emptyResult = new UserDailyActiveResult();
|
|
|
+ emptyResult.setVisitCount(0);
|
|
|
+ emptyResult.setRecords(Collections.emptyList());
|
|
|
+ return emptyResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 查询用户单日的日活记录(按时间倒序)
|
|
|
+ LambdaQueryWrapper<DailyActiveUsers> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(DailyActiveUsers::getUserId, params.getUserId())
|
|
|
+ .between(DailyActiveUsers::getCreateTime, startOfDay, endOfDay)
|
|
|
+ .orderByDesc(DailyActiveUsers::getCreateTime);
|
|
|
+
|
|
|
+ List<DailyActiveUsers> dailyActiveUsers = dailyActiveUsersService.list(queryWrapper);
|
|
|
+
|
|
|
+ // 4. 转换 DTO
|
|
|
+ List<UsersDailyActiveDTO> records = dailyActiveUsers.stream().map(record -> {
|
|
|
+ UsersDailyActiveDTO dto = new UsersDailyActiveDTO();
|
|
|
+ dto.setDailyActiveId(record.getDailyActiveId());
|
|
|
+ dto.setUserId(record.getUserId());
|
|
|
+ dto.setVisitTime(record.getCreateTime()); // visitTime = createTime
|
|
|
+ return dto;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 5. 封装结果
|
|
|
+ UserDailyActiveResult result = new UserDailyActiveResult();
|
|
|
+ result.setVisitCount((int) totalCount);
|
|
|
+ result.setRecords(records);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
|