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,12 +5,16 @@ import org.apache.ibatis.annotations.Param;
5 5
 import org.springframework.stereotype.Repository;
6 6
 
7 7
 import java.util.List;
8
+import java.util.Map;
8 9
 
9 10
 @Repository
10 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,35 +21,47 @@ public class RAppAnalyzeService {
21 21
     @Resource
22 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 39
         Integer begintime = param.getBegintime();
27 40
         Integer endtime = param.getEndtime();
28
-        Integer level = param.getLevel();
29 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 43
         map.put("dlnum",dlnum);//登录次数
32 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 49
         map.put("dknum",dknum);//打开次数
38 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 52
         map.put("costtime",costtime);//使用时长
41 53
         map.put("pjcosttime", N_Utils.formatAvg(costtime,daynum));//平均使用时长
42 54
 
43 55
         //应用统计--应用时长概况(关于率的计算:各应用时长÷总使用时长,排名前5的应用)
44 56
         List<RAppVo> list2 = new ArrayList<>();
45 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 60
             RAppVo a = new RAppVo();
49 61
             RAppVo rate = rates2.get(0);
50 62
             a.setModulecode(rate.getModulecode());
51 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 65
             a.setCosttime(costtime2);
54 66
             a.setTimerate(N_Utils.getIntegerDivideAndMulitiply(costtime2,costtime));
55 67
             list2.add(a);
@@ -61,17 +73,14 @@ public class RAppAnalyzeService {
61 73
 
62 74
         //学校应用时长、次数统计
63 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 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 82
             for (RAppVo a : schools2) {
74
-                Map module = new HashMap();
83
+                Map<String, Object> module = new HashMap<>();
75 84
                 module.put("modulecode",a.getModulecode());
76 85
                 module.put("modulename",a.getModulename());
77 86
                 module.put("dknum",a.getDknum());

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

@@ -1,21 +1,25 @@
1 1
 <?xml version="1.0" encoding="UTF-8" ?>
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 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 9
     <select id="getLoginNum" resultType="java.lang.Integer">
6 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 13
         <if test="begintime!=null and begintime!=0">
10 14
             and ul.logtime between #{begintime} and #{endtime}
11 15
         </if>
12 16
     </select>
13 17
     <!--学校应用时长、次数统计-->
14 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 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 23
         <if test="begintime!=null and begintime!=0">
20 24
             and m.createtime between #{begintime} and #{endtime}
21 25
         </if>

Loading…
Cancel
Save