|
@@ -1,8 +1,6 @@
|
|
|
package com.hfln.portal.infrastructure.gateway.impl;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
-import com.alibaba.excel.util.StringUtils;
|
|
|
-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.device.OnoffDTO;
|
|
@@ -32,13 +30,15 @@ import org.springframework.stereotype.Service;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class WebStatsGatewayImpl implements WebStatsGateway {
|
|
|
|
|
|
+
|
|
|
@Autowired
|
|
|
private DevInfoService devInfoService;
|
|
|
|
|
@@ -46,15 +46,9 @@ public class WebStatsGatewayImpl implements WebStatsGateway {
|
|
|
private EventListService eventListService;
|
|
|
|
|
|
@Autowired
|
|
|
- private DailyActiveUsersService dailyActiveUsersService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private EventsService eventsService;
|
|
|
|
|
|
@Autowired
|
|
|
- private UserService userService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private TblTenantService tblTenantService;
|
|
|
|
|
|
@Autowired
|
|
@@ -63,6 +57,9 @@ public class WebStatsGatewayImpl implements WebStatsGateway {
|
|
|
@Autowired
|
|
|
private DevOnOffInfoService devOnOffInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserActivityService userActivityService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public PageRecord<EventListDTO> fallQuery(EventListParams params) {
|
|
@@ -105,102 +102,22 @@ public class WebStatsGatewayImpl implements WebStatsGateway {
|
|
|
|
|
|
@Override
|
|
|
public PageRecord<UserDailyActiveDTO> queryUserDailyActive(UserDailyActiveParams params) {
|
|
|
+ // 手机号不为空,查询单个用户
|
|
|
+ log.info("查询指定用户日活 phone{}", params.getPhone());
|
|
|
+ if (params.getPhone() != null){
|
|
|
+ Page<UserActivity> userActivityPage = userActivityService.queryUserActivity(params);
|
|
|
|
|
|
- PageRecord<UserDailyActiveDTO> pageRecord = new PageRecord<>();
|
|
|
+ List<UserDailyActiveDTO> dtoList = CopyUtils.copyList(userActivityPage.getRecords(), UserDailyActiveDTO.class);
|
|
|
|
|
|
- LambdaQueryWrapper<DailyActiveUsers> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- if (Objects.nonNull(params.getCreateTimeStart())) {
|
|
|
- queryWrapper.ge(DailyActiveUsers::getCreateTime, params.getCreateTimeStart());
|
|
|
- }
|
|
|
- if (Objects.nonNull(params.getCreateTimeEnd())) {
|
|
|
- queryWrapper.lt(DailyActiveUsers::getCreateTime, params.getCreateTimeEnd().plusDays(1));
|
|
|
- }
|
|
|
- queryWrapper.orderByDesc(DailyActiveUsers::getCreateTime);
|
|
|
-
|
|
|
- // ------------------------
|
|
|
- // 手机号不为空 → 查询指定用户
|
|
|
- // ------------------------
|
|
|
- if (StringUtils.isNotBlank(params.getPhone())) {
|
|
|
- final String phone = params.getPhone();
|
|
|
- UserInfo userInfo = userService.lambdaQuery()
|
|
|
- .eq(UserInfo::getPhone, phone)
|
|
|
- .one();
|
|
|
-
|
|
|
- if (userInfo == null) {
|
|
|
- pageRecord.setRows(Collections.emptyList());
|
|
|
- pageRecord.setTotal(0L);
|
|
|
- pageRecord.setPageNum(params.getPageNo());
|
|
|
- pageRecord.setPageSize(params.getPageSize());
|
|
|
- pageRecord.setTotalPageNum(0);
|
|
|
- return pageRecord;
|
|
|
- }
|
|
|
-
|
|
|
- queryWrapper.eq(DailyActiveUsers::getUserId, userInfo.getUserId());
|
|
|
- List<DailyActiveUsers> userRecords = dailyActiveUsersService.list(queryWrapper);
|
|
|
-
|
|
|
- UserDailyActiveDTO dto = new UserDailyActiveDTO();
|
|
|
- dto.setPhone(phone);
|
|
|
- dto.setVisitCount(userRecords.size());
|
|
|
-
|
|
|
- pageRecord.setRows(Collections.singletonList(dto));
|
|
|
- pageRecord.setTotal(userRecords.isEmpty() ? 0L : 1L);
|
|
|
- pageRecord.setPageNum(params.getPageNo());
|
|
|
- pageRecord.setPageSize(params.getPageSize());
|
|
|
- pageRecord.setTotalPageNum(1);
|
|
|
- return pageRecord;
|
|
|
+ return CopyUtils.copyPage(userActivityPage, dtoList);
|
|
|
}
|
|
|
+ // 手机号为空,查询所有用户
|
|
|
+ log.info("查询所有用户日活---------------------------");
|
|
|
+ Page<UserActivity> userActivityPage = userActivityService.queryAllUserActivity(params);
|
|
|
|
|
|
- // ------------------------
|
|
|
- // 手机号为空 → 查询所有用户
|
|
|
- // ------------------------
|
|
|
- List<DailyActiveUsers> allRecords = dailyActiveUsersService.list(queryWrapper);
|
|
|
- if (allRecords.isEmpty()) {
|
|
|
- pageRecord.setRows(Collections.emptyList());
|
|
|
- pageRecord.setTotal(0L);
|
|
|
- pageRecord.setPageNum(params.getPageNo());
|
|
|
- pageRecord.setPageSize(params.getPageSize());
|
|
|
- pageRecord.setTotalPageNum(0);
|
|
|
- return pageRecord;
|
|
|
- }
|
|
|
+ List<UserDailyActiveDTO> dtoList = CopyUtils.copyList(userActivityPage.getRecords(), UserDailyActiveDTO.class);
|
|
|
|
|
|
- // 批量查询用户信息
|
|
|
- Set<Long> userIds = allRecords.stream()
|
|
|
- .map(DailyActiveUsers::getUserId)
|
|
|
- .collect(Collectors.toSet());
|
|
|
- List<UserInfo> userInfos = userService.listByIds(userIds);
|
|
|
- Map<Long, String> userIdPhoneMap = userInfos.stream()
|
|
|
- .collect(Collectors.toMap(UserInfo::getUserId, UserInfo::getPhone));
|
|
|
-
|
|
|
- // 聚合访问次数
|
|
|
- Map<Long, Long> visitCountMap = allRecords.stream()
|
|
|
- .collect(Collectors.groupingBy(DailyActiveUsers::getUserId, Collectors.counting()));
|
|
|
-
|
|
|
- // 转 DTO 列表
|
|
|
- List<UserDailyActiveDTO> dtoList = visitCountMap.entrySet().stream()
|
|
|
- .map(entry -> {
|
|
|
- UserDailyActiveDTO dto = new UserDailyActiveDTO();
|
|
|
- dto.setPhone(userIdPhoneMap.get(entry.getKey()));
|
|
|
- dto.setVisitCount(entry.getValue().intValue());
|
|
|
- return dto;
|
|
|
- }).collect(Collectors.toList());
|
|
|
-
|
|
|
- // ------------------------
|
|
|
- // Java 层分页
|
|
|
- // ------------------------
|
|
|
- int pageNo = params.getPageNo();
|
|
|
- int pageSize = params.getPageSize();
|
|
|
- int total = dtoList.size();
|
|
|
- int start = (pageNo - 1) * pageSize;
|
|
|
- int end = Math.min(start + pageSize, total);
|
|
|
- List<UserDailyActiveDTO> pageList = start >= total ? Collections.emptyList() : dtoList.subList(start, end);
|
|
|
-
|
|
|
- pageRecord.setRows(pageList);
|
|
|
- pageRecord.setTotal((long) total);
|
|
|
- pageRecord.setPageNum(pageNo);
|
|
|
- pageRecord.setPageSize(pageSize);
|
|
|
- pageRecord.setTotalPageNum((total + pageSize - 1) / pageSize);
|
|
|
-
|
|
|
- return pageRecord;
|
|
|
+ return CopyUtils.copyPage(userActivityPage, dtoList);
|
|
|
}
|
|
|
|
|
|
@Override
|