访问记录监控
# 接口层
接口:
/**
* 访问单个短链接指定时间内访问记录监控数据
*/
@GetMapping("/api/short-link/v1/stats/access-record")
public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> shortLinkStatsAccessRecord(ShortLinkStatsAccessRecordReqDTO requestParam) {
return Results.success(shortLinkStatsService.shortLinkStatsAccessRecord(requestParam));
}
1
2
3
4
5
6
7
2
3
4
5
6
7
@Override
public IPage<ShortLinkStatsAccessRecordRespDTO> shortLinkStatsAccessRecord(ShortLinkStatsAccessRecordReqDTO requestParam) {
LambdaQueryWrapper<LinkAccessLogsDO> queryWrapper = Wrappers.lambdaQuery(LinkAccessLogsDO.class)
.eq(LinkAccessLogsDO::getGid, requestParam.getGid())
.eq(LinkAccessLogsDO::getFullShortUrl, requestParam.getFullShortUrl())
.between(LinkAccessLogsDO::getCreateTime, requestParam.getStartDate(), requestParam.getEndDate())
.eq(LinkAccessLogsDO::getDelFlag, 0)
.orderByDesc(LinkAccessLogsDO::getCreateTime);
IPage<LinkAccessLogsDO> linkAccessLogsDOIPage = linkAccessLogsMapper.selectPage(requestParam, queryWrapper);
IPage<ShortLinkStatsAccessRecordRespDTO> actualResult = linkAccessLogsDOIPage.convert(each -> BeanUtil.toBean(each, ShortLinkStatsAccessRecordRespDTO.class));
List<String> userAccessLogsList = actualResult.getRecords().stream()
.map(ShortLinkStatsAccessRecordRespDTO::getUser)
.toList();
List<Map<String, Object>> uvTypeList = linkAccessLogsMapper.selectUvTypeByUsers(
requestParam.getGid(),
requestParam.getFullShortUrl(),
requestParam.getStartDate(),
requestParam.getEndDate(),
userAccessLogsList
);
actualResult.getRecords().forEach(each -> {
String uvType = uvTypeList.stream()
.filter(item -> Objects.equals(each.getUser(), item.get("user")))
.findFirst()
.map(item -> item.get("UvType"))
.map(Object::toString)
.orElse("旧访客");
each.setUvType(uvType);
});
return actualResult;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 持久层
/**
* 获取用户信息是否新老访客
*/
@Select("<script> " +
"SELECT " +
" user, " +
" CASE " +
" WHEN MIN(create_time) BETWEEN #{startDate} AND #{endDate} THEN '新访客' " +
" ELSE '老访客' " +
" END AS uvType " +
"FROM " +
" t_link_access_logs " +
"WHERE " +
" full_short_url = #{fullShortUrl} " +
" AND gid = #{gid} " +
" AND user IN " +
" <foreach item='item' index='index' collection='userAccessLogsList' open='(' separator=',' close=')'> " +
" #{item} " +
" </foreach> " +
"GROUP BY " +
" user;" +
" </script>"
)
List<Map<String, Object>> selectUvTypeByUsers(
@Param("gid") String gid,
@Param("fullShortUrl") String fullShortUrl,
@Param("startDate") String startDate,
@Param("endDate") String endDate,
@Param("userAccessLogsList") List<String> userAccessLogsList
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30