Browse Source

区域应用统计优化

tags/正式3.14.1
雍文秀 3 months ago
parent
commit
1c4a0b98c2

+ 6
- 2
sapi/src/main/java/com/xhkjedu/sapi/mapper/region/RAppAnalyzeMapper.java View File

5
 import org.springframework.stereotype.Repository;
5
 import org.springframework.stereotype.Repository;
6
 
6
 
7
 import java.util.List;
7
 import java.util.List;
8
+import java.util.Map;
8
 
9
 
9
 @Repository
10
 @Repository
10
 public interface RAppAnalyzeMapper {
11
 public interface RAppAnalyzeMapper {
11
     //登录次数
12
     //登录次数
12
-    Integer getLoginNum(@Param("level") Integer level, @Param("begintime") Integer begintime, @Param("endtime") Integer endtime,@Param("year") Integer year);
13
+    Integer getLoginNum(@Param("schoolIds") String schoolIds, @Param("begintime") Integer begintime, @Param("endtime") Integer endtime,@Param("year") Integer year);
13
 
14
 
14
     //学校应用时长、次数统计
15
     //学校应用时长、次数统计
15
-    List<RAppVo> listApp(@Param("level") Integer level, @Param("begintime") Integer begintime, @Param("endtime") Integer endtime,@Param("year") Integer year);
16
+    List<RAppVo> listApp(@Param("schoolIds") String schoolIds, @Param("begintime") Integer begintime, @Param("endtime") Integer endtime,@Param("year") Integer year);
17
+
18
+    //获取学校列表
19
+    List<Map<String, Object>> listSchool(@Param("level") Integer level);
16
 }
20
 }

+ 28
- 19
sapi/src/main/java/com/xhkjedu/sapi/service/region/RAppAnalyzeService.java View File

21
     @Resource
21
     @Resource
22
     private RAppAnalyzeMapper rAppAnalyzeMapper;
22
     private RAppAnalyzeMapper rAppAnalyzeMapper;
23
 
23
 
24
-    public Map listApp(RegionParam param) {
25
-        Map map = new HashMap();
24
+    public Map<String, Object> listApp(RegionParam param) {
25
+        Map<String, Object> map = new HashMap<>();
26
+        List<Map<String, Object>> schoolList = rAppAnalyzeMapper.listSchool(param.getLevel());
27
+        if(N_Utils.isListEmpty(schoolList)) {
28
+            map.put("dlnum",0);//登录次数
29
+            map.put("pjdlnum",0);//平均登录次数
30
+            map.put("dknum",0);//打开次数
31
+            map.put("pjdknum",0);//平均打开次数
32
+            map.put("costtime",0);//使用时长
33
+            map.put("pjcosttime",0);//平均使用时长
34
+            map.put("rates",new ArrayList<>());
35
+            map.put("schools",new ArrayList<>());
36
+            return map;
37
+        }
38
+        String schoolIds = schoolList.stream().map(m -> m.get("schoolid").toString()).collect(Collectors.joining(","));
26
         Integer begintime = param.getBegintime();
39
         Integer begintime = param.getBegintime();
27
         Integer endtime = param.getEndtime();
40
         Integer endtime = param.getEndtime();
28
-        Integer level = param.getLevel();
29
         Integer daynum = N_Utils.getTimestampDay(begintime,endtime);//使用天数
41
         Integer daynum = N_Utils.getTimestampDay(begintime,endtime);//使用天数
30
-        Integer dlnum = rAppAnalyzeMapper.getLoginNum(level,begintime,endtime,param.getYear());
42
+        Integer dlnum = rAppAnalyzeMapper.getLoginNum(schoolIds,begintime,endtime,param.getYear());
31
         map.put("dlnum",dlnum);//登录次数
43
         map.put("dlnum",dlnum);//登录次数
32
         map.put("pjdlnum", N_Utils.formatAvg(dlnum,daynum));//平均登录次数
44
         map.put("pjdlnum", N_Utils.formatAvg(dlnum,daynum));//平均登录次数
33
 
45
 
34
         //应用时长、次数统计
46
         //应用时长、次数统计
35
-        List<RAppVo> list = rAppAnalyzeMapper.listApp(level,begintime,endtime,param.getYear());
36
-        Integer dknum = list.stream().collect(Collectors.summingInt(RAppVo::getDknum));
47
+        List<RAppVo> list = rAppAnalyzeMapper.listApp(schoolIds,begintime,endtime,param.getYear());
48
+        Integer dknum = list.stream().mapToInt(RAppVo::getDknum).sum();
37
         map.put("dknum",dknum);//打开次数
49
         map.put("dknum",dknum);//打开次数
38
         map.put("pjdknum", N_Utils.formatAvg(dknum,daynum));//平均打开次数
50
         map.put("pjdknum", N_Utils.formatAvg(dknum,daynum));//平均打开次数
39
-        Integer costtime = list.stream().collect(Collectors.summingInt(RAppVo::getCosttime));
51
+        Integer costtime = list.stream().mapToInt(RAppVo::getCosttime).sum();
40
         map.put("costtime",costtime);//使用时长
52
         map.put("costtime",costtime);//使用时长
41
         map.put("pjcosttime", N_Utils.formatAvg(costtime,daynum));//平均使用时长
53
         map.put("pjcosttime", N_Utils.formatAvg(costtime,daynum));//平均使用时长
42
 
54
 
43
         //应用统计--应用时长概况(关于率的计算:各应用时长÷总使用时长,排名前5的应用)
55
         //应用统计--应用时长概况(关于率的计算:各应用时长÷总使用时长,排名前5的应用)
44
         List<RAppVo> list2 = new ArrayList<>();
56
         List<RAppVo> list2 = new ArrayList<>();
45
         Map<String, List<RAppVo>> rcollect = list.stream().collect(Collectors.groupingBy(RAppVo::getModulecode));
57
         Map<String, List<RAppVo>> rcollect = list.stream().collect(Collectors.groupingBy(RAppVo::getModulecode));
46
-        for(Map.Entry rmap:rcollect.entrySet()) {
47
-            List<RAppVo> rates2 = (List<RAppVo>) rmap.getValue();
58
+        for(Map.Entry<String, List<RAppVo>> rmap:rcollect.entrySet()) {
59
+            List<RAppVo> rates2 = rmap.getValue();
48
             RAppVo a = new RAppVo();
60
             RAppVo a = new RAppVo();
49
             RAppVo rate = rates2.get(0);
61
             RAppVo rate = rates2.get(0);
50
             a.setModulecode(rate.getModulecode());
62
             a.setModulecode(rate.getModulecode());
51
             a.setModulename(rate.getModulename());
63
             a.setModulename(rate.getModulename());
52
-            Integer costtime2 = rates2.stream().collect(Collectors.summingInt(RAppVo::getCosttime));
64
+            Integer costtime2 = rates2.stream().mapToInt(RAppVo::getCosttime).sum();
53
             a.setCosttime(costtime2);
65
             a.setCosttime(costtime2);
54
             a.setTimerate(N_Utils.getIntegerDivideAndMulitiply(costtime2,costtime));
66
             a.setTimerate(N_Utils.getIntegerDivideAndMulitiply(costtime2,costtime));
55
             list2.add(a);
67
             list2.add(a);
61
 
73
 
62
         //学校应用时长、次数统计
74
         //学校应用时长、次数统计
63
         Map<Integer, List<RAppVo>> scollect = list.stream().collect(Collectors.groupingBy(RAppVo::getSchoolid));
75
         Map<Integer, List<RAppVo>> scollect = list.stream().collect(Collectors.groupingBy(RAppVo::getSchoolid));
64
-        List<Map> schools = new ArrayList<>();
65
-        for(Map.Entry smap:scollect.entrySet()) {
66
-            List<RAppVo> schools2 = (List<RAppVo>) smap.getValue();
76
+        List<Map<String, Object>> schools = new ArrayList<>();
77
+        for(Map.Entry<Integer, List<RAppVo>> smap:scollect.entrySet()) {
78
+            List<RAppVo> schools2 = smap.getValue();
67
             RAppVo school = schools2.get(0);
79
             RAppVo school = schools2.get(0);
68
-            Map s = new HashMap();
69
-            s.put("schoolid",school.getSchoolid());
70
-            s.put("schoolname",school.getSchoolname());
71
-            s.put("shortname",school.getShortname());
72
-            List<Map> modules = new ArrayList<>();//学校模块列表
80
+            Map<String, Object> s = schoolList.stream().filter(m -> m.get("schoolid").equals(school.getSchoolid())).findFirst().orElse(new HashMap<>());
81
+            List<Map<String, Object>> modules = new ArrayList<>();//学校模块列表
73
             for (RAppVo a : schools2) {
82
             for (RAppVo a : schools2) {
74
-                Map module = new HashMap();
83
+                Map<String, Object> module = new HashMap<>();
75
                 module.put("modulecode",a.getModulecode());
84
                 module.put("modulecode",a.getModulecode());
76
                 module.put("modulename",a.getModulename());
85
                 module.put("modulename",a.getModulename());
77
                 module.put("dknum",a.getDknum());
86
                 module.put("dknum",a.getDknum());

+ 9
- 5
sapi/src/main/resources/mapper/region/RAppAnalyzeMapper.xml View File

1
 <?xml version="1.0" encoding="UTF-8" ?>
1
 <?xml version="1.0" encoding="UTF-8" ?>
2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
 <mapper namespace="com.xhkjedu.sapi.mapper.region.RAppAnalyzeMapper">
3
 <mapper namespace="com.xhkjedu.sapi.mapper.region.RAppAnalyzeMapper">
4
+    <!--获取学校列表-->
5
+    <select id="listSchool" resultType="java.util.Map">
6
+        select s.schoolid,s.schoolname,s.shortname from t_school s where s.schoollevel=#{level} and s.schoolstate=1
7
+    </select>
4
     <!--登录次数-->
8
     <!--登录次数-->
5
     <select id="getLoginNum" resultType="java.lang.Integer">
9
     <select id="getLoginNum" resultType="java.lang.Integer">
6
         select count(ul.ulid)
10
         select count(ul.ulid)
7
-        from t_school s right join t_user_log ul on s.schoolid=ul.schoolid
8
-        where s.schoollevel=#{level} and s.schoolstate=1 and ul.year=#{year}
11
+        from t_user_log ul
12
+        where ul.schoolid in(${schoolIds}) and ul.year=#{year}
9
         <if test="begintime!=null and begintime!=0">
13
         <if test="begintime!=null and begintime!=0">
10
             and ul.logtime between #{begintime} and #{endtime}
14
             and ul.logtime between #{begintime} and #{endtime}
11
         </if>
15
         </if>
12
     </select>
16
     </select>
13
     <!--学校应用时长、次数统计-->
17
     <!--学校应用时长、次数统计-->
14
     <select id="listApp" resultType="com.xhkjedu.sapi.vo.region.RAppVo">
18
     <select id="listApp" resultType="com.xhkjedu.sapi.vo.region.RAppVo">
15
-        select m.schoolid,s.schoolname,s.shortname,m.modulecode,count(m.amid)dknum,sum(m.costtime)costtime
19
+        select m.schoolid,m.modulecode,count(m.amid)dknum,sum(m.costtime)costtime
16
         ,(select m2.modulename from t_moduledefault m2 where m2.mabbrevname=m.modulecode limit 1)modulename
20
         ,(select m2.modulename from t_moduledefault m2 where m2.mabbrevname=m.modulecode limit 1)modulename
17
-        from t_school s right join t_app_monitor m on m.schoolid=s.schoolid
18
-        where s.schoollevel=#{level} and s.schoolstate=1 and m.year=#{year}
21
+        from t_app_monitor m
22
+        where m.schoolid in(${schoolIds}) and m.year=#{year}
19
         <if test="begintime!=null and begintime!=0">
23
         <if test="begintime!=null and begintime!=0">
20
             and m.createtime between #{begintime} and #{endtime}
24
             and m.createtime between #{begintime} and #{endtime}
21
         </if>
25
         </if>

Loading…
Cancel
Save