se-modules/se-system/src/main/java/com/se/system/controller/IndexController.java
@@ -62,7 +62,7 @@ @Log(title = "新增用户统计", businessType = BusinessType.OTHER) @GetMapping("/newUserCount") public Map<String, Object> newUserCount(Integer day) { if (null == day || day < 1) day = 7; if (null == day || day < 1) day = 15; if (day > 365) day = 365; Map<String, Object> map = new HashMap<>(); @@ -84,10 +84,13 @@ // ⑤用户统计排行(活跃用户):以一定时间段内的登录时间或登录次数排名,展示前五名的用户信息 @Log(title = "用户统计排行", businessType = BusinessType.OTHER) @GetMapping("/userCountList") public Map<String, Object> userCountList() { Map<String, Object> map = new HashMap<>(); public List<Map<String, Object>> userCountList(Integer day, Integer amount) { if (null == day || day < 1) day = 15; if (day > 365) day = 365; if (null == amount) amount = 5; if (amount > 100) amount = 100; return map; return indexService.userCountList(day, amount); } // ⑥常用系统展示/各系统访问信息:基于用户访问次数排名,展示前五个系统的排名 se-modules/se-system/src/main/java/com/se/system/mapper/IndexMapper.java
@@ -1,13 +1,19 @@ package com.se.system.mapper; import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import java.util.List; import java.util.Map; @Mapper @Repository @SuppressWarnings("ALL") public interface IndexMapper { public interface IndexMapper { public int newUserCount(@Param("createTime") String createTime); //@MapKey("username") public List<Map<String, Object>> userCountList(@Param("createTime") String createTime, @Param("amount") Integer amount); } se-modules/se-system/src/main/java/com/se/system/service/IndexService.java
@@ -6,6 +6,8 @@ import javax.annotation.Resource; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.List; import java.util.Map; @Component @SuppressWarnings("ALL") @@ -16,10 +18,21 @@ public static SimpleDateFormat YYYY_MM_DD_HH_MM_SS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public int newUserCount(int day) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, -day); String createTime = YYYY_MM_DD_HH_MM_SS.format(calendar.getTime()); String createTime = getCreateTime(day); return indexMapper.newUserCount(createTime); } private String getCreateTime(int day) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, -day); return YYYY_MM_DD_HH_MM_SS.format(calendar.getTime()); } public List<Map<String, Object>> userCountList(Integer day, Integer amount) { String createTime = getCreateTime(day); return indexMapper.userCountList(createTime, amount); } } se-modules/se-system/src/main/resources/mapper/system/IndexMapper.xml
@@ -6,4 +6,13 @@ <select id="newUserCount" resultType="java.lang.Integer"> select count(*) from sys_user where create_time >= #{createTime}; </select> <select id="userCountList" resultType="java.util.Map"> select user_name userName, count(*) count from sys_logininfor where access_time >= #{createTime} group by user_name order by count desc limit ${amount}; </select> </mapper>