张延森 il y a 4 ans
Parent
révision
9c88bec38e

+ 17
- 0
src/main/java/com/yunzhi/demo/common/DateUtils.java Voir le fichier

@@ -0,0 +1,17 @@
1
+package com.yunzhi.demo.common;
2
+
3
+import java.time.Duration;
4
+import java.time.LocalDateTime;
5
+import java.time.format.DateTimeFormatter;
6
+
7
+public class DateUtils {
8
+    public static LocalDateTime from(String str, String formater) {
9
+        DateTimeFormatter fmt = DateTimeFormatter.ofPattern(formater);
10
+        return LocalDateTime.parse(str, fmt);
11
+    }
12
+
13
+    public static long daysBetween(LocalDateTime dt1, LocalDateTime dt2) {
14
+        Duration duration = Duration.between(dt1, dt2);
15
+        return duration.toDays();
16
+    }
17
+}

+ 76
- 1
src/main/java/com/yunzhi/demo/controller/StatisticController.java Voir le fichier

@@ -1,16 +1,25 @@
1 1
 package com.yunzhi.demo.controller;
2 2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
4
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
3 5
 import com.yunzhi.demo.common.BaseController;
4 6
 import com.yunzhi.demo.common.ResponseBean;
7
+import com.yunzhi.demo.entity.TaPost;
5 8
 import com.yunzhi.demo.service.ITaPersonService;
6 9
 import com.yunzhi.demo.service.ITaPostDataService;
10
+import com.yunzhi.demo.service.ITaPostService;
11
+import com.yunzhi.demo.service.ITaReadLogService;
12
+import com.yunzhi.demo.vo.StatisPerson;
13
+import com.yunzhi.demo.vo.StatisPost;
7 14
 import io.swagger.annotations.Api;
8 15
 import io.swagger.annotations.ApiOperation;
16
+import io.swagger.annotations.ApiParam;
9 17
 import org.springframework.beans.factory.annotation.Autowired;
10 18
 import org.springframework.web.bind.annotation.GetMapping;
11
-import org.springframework.web.bind.annotation.PostMapping;
19
+import org.springframework.web.bind.annotation.RequestParam;
12 20
 import org.springframework.web.bind.annotation.RestController;
13 21
 
22
+import java.util.List;
14 23
 import java.util.Map;
15 24
 
16 25
 
@@ -24,6 +33,12 @@ public class StatisticController extends BaseController {
24 33
     @Autowired
25 34
     ITaPersonService iTaPersonService;
26 35
 
36
+    @Autowired
37
+    ITaReadLogService iTaReadLogService;
38
+
39
+    @Autowired
40
+    ITaPostService iTaPostService;
41
+
27 42
 
28 43
     @GetMapping("/admin/index/post-data")
29 44
     @ApiOperation(value="首页简单的几个统计", notes = "首页简单的几个统计", httpMethod = "GET", response = ResponseBean.class)
@@ -36,4 +51,64 @@ public class StatisticController extends BaseController {
36 51
 
37 52
         return ResponseBean.success(result);
38 53
     }
54
+
55
+    /**
56
+     * 首页科普浏览统计
57
+     * @param startDate
58
+     * @param endDate
59
+     * @return
60
+     */
61
+    @GetMapping("/admin/index/post-pv")
62
+    @ApiOperation(value="首页科普浏览统计", notes = "首页科普浏览统计", httpMethod = "GET", response = ResponseBean.class)
63
+    public ResponseBean getIndexPostPV(@ApiParam(value = "开始日期", example="YYYY-MM-DD") @RequestParam("startDate") String startDate,
64
+                                       @ApiParam(value = "结束日期", example="YYYY-MM-DD") @RequestParam("endDate") String endDate) {
65
+        List<Map<String, Integer>> result = iTaReadLogService.getIndexPostPV(startDate, endDate);
66
+        return ResponseBean.success(result);
67
+    }
68
+
69
+    /**
70
+     * 首页学生浏览统计
71
+     * @param startDate
72
+     * @param endDate
73
+     * @return
74
+     */
75
+    @GetMapping("/admin/index/post-uv")
76
+    public ResponseBean getIndexPostUV(@ApiParam(value = "开始日期", example="YYYY-MM-DD") @RequestParam("startDate") String startDate,
77
+                                       @ApiParam(value = "结束日期", example="YYYY-MM-DD") @RequestParam("endDate") String endDate) {
78
+        List<Map<String, Integer>> result = iTaReadLogService.getIndexPostUV(startDate, endDate);
79
+        return ResponseBean.success(result);
80
+    }
81
+
82
+    @GetMapping("/admin/statis/post-data")
83
+    @ApiOperation(value="科普统计", notes = "科普统计", httpMethod = "GET", response = ResponseBean.class)
84
+    public ResponseBean getPostData(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
85
+                                    @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
86
+                                    @ApiParam(value = "开始日期", example="YYYY-MM-DD") @RequestParam(value = "startDate", required = false) String startDate,
87
+                                    @ApiParam(value = "结束日期", example="YYYY-MM-DD") @RequestParam(value = "endDate", required = false) String endDate,
88
+                                    @ApiParam(value = "科普分类") @RequestParam(value = "name", required = false) String name,
89
+                                    @ApiParam(value = "科普分类") @RequestParam(value = "typeId", required = false) String typeId,
90
+                                    @ApiParam("升序") @RequestParam(value = "asc", required = false) String asc,
91
+                                    @ApiParam("降序") @RequestParam(value = "desc", required = false) String desc) {
92
+        IPage<StatisPost> pg = new Page<>(pageNum, pageSize);
93
+
94
+        IPage<StatisPost> postList = iTaPostService.getPostStatis(pg, startDate, endDate, name, typeId, asc, desc);
95
+
96
+        return ResponseBean.success(postList);
97
+    }
98
+
99
+    @GetMapping("/admin/statis/student-data")
100
+    @ApiOperation(value="学生统计", notes = "学生统计", httpMethod = "GET", response = ResponseBean.class)
101
+    public ResponseBean getPersonData(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
102
+                                      @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
103
+                                      @ApiParam(value = "姓名") @RequestParam(value = "name", required = false) String name,
104
+                                      @ApiParam(value = "学校") @RequestParam(value = "schoolId", required = false) String schoolId,
105
+                                      @ApiParam(value = "专业") @RequestParam(value = "specialtyId", required = false) String specialtyId,
106
+                                      @ApiParam("升序") @RequestParam(value = "asc", required = false) String asc,
107
+                                      @ApiParam("降序") @RequestParam(value = "desc", required = false) String desc) {
108
+        IPage<StatisPerson> pg = new Page<>(pageNum, pageSize);
109
+
110
+        IPage<StatisPerson> personList = iTaPersonService.getStudentStatis(pg, name, schoolId, specialtyId, asc, desc);
111
+
112
+        return ResponseBean.success(personList);
113
+    }
39 114
 }

+ 9
- 0
src/main/java/com/yunzhi/demo/mapper/TaPersonMapper.java Voir le fichier

@@ -1,8 +1,11 @@
1 1
 package com.yunzhi.demo.mapper;
2 2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
3 4
 import com.yunzhi.demo.entity.TaPerson;
4 5
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6
+import com.yunzhi.demo.vo.StatisPerson;
5 7
 import org.apache.ibatis.annotations.Mapper;
8
+import org.apache.ibatis.annotations.Param;
6 9
 
7 10
 /**
8 11
  * <p>
@@ -15,4 +18,10 @@ import org.apache.ibatis.annotations.Mapper;
15 18
 @Mapper
16 19
 public interface TaPersonMapper extends BaseMapper<TaPerson> {
17 20
 
21
+    IPage<StatisPerson> getStudentStatis(IPage<StatisPerson> pg,
22
+                                        @Param("name") String name,
23
+                                        @Param("schoolId") String schoolId,
24
+                                        @Param("specialtyId") String specialtyId,
25
+                                        @Param("asc") String asc,
26
+                                        @Param("desc") String desc);
18 27
 }

+ 3
- 0
src/main/java/com/yunzhi/demo/mapper/TaPostDataMapper.java Voir le fichier

@@ -4,6 +4,7 @@ import com.yunzhi.demo.entity.TaPostData;
4 4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 5
 import org.apache.ibatis.annotations.Mapper;
6 6
 
7
+import java.util.List;
7 8
 import java.util.Map;
8 9
 
9 10
 /**
@@ -20,4 +21,6 @@ public interface TaPostDataMapper extends BaseMapper<TaPostData> {
20 21
     int updatePvUvBy(String postId, int addUv, int addPv);
21 22
 
22 23
     Map<String, Object> getIndexBasicData();
24
+
25
+    List<Map<String, Integer>> getIndexPostPV(String startDate, String endDate);
23 26
 }

+ 10
- 0
src/main/java/com/yunzhi/demo/mapper/TaPostMapper.java Voir le fichier

@@ -1,8 +1,11 @@
1 1
 package com.yunzhi.demo.mapper;
2 2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
3 4
 import com.yunzhi.demo.entity.TaPost;
4 5
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6
+import com.yunzhi.demo.vo.StatisPost;
5 7
 import org.apache.ibatis.annotations.Mapper;
8
+import org.apache.ibatis.annotations.Param;
6 9
 
7 10
 /**
8 11
  * <p>
@@ -15,4 +18,11 @@ import org.apache.ibatis.annotations.Mapper;
15 18
 @Mapper
16 19
 public interface TaPostMapper extends BaseMapper<TaPost> {
17 20
 
21
+    IPage<StatisPost> getPostStatis(IPage<StatisPost> pg,
22
+                                    @Param("startDate") String startDate,
23
+                                    @Param("endDate") String endDate,
24
+                                    @Param("name") String name,
25
+                                    @Param("typeId") String typeId,
26
+                                    @Param("asc") String asc,
27
+                                    @Param("desc") String desc);
18 28
 }

+ 7
- 0
src/main/java/com/yunzhi/demo/mapper/TaReadLogMapper.java Voir le fichier

@@ -6,6 +6,9 @@ import com.yunzhi.demo.entity.TaReadLog;
6 6
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
7 7
 import org.apache.ibatis.annotations.Mapper;
8 8
 
9
+import java.util.List;
10
+import java.util.Map;
11
+
9 12
 /**
10 13
  * <p>
11 14
  * 阅读记录 Mapper 接口
@@ -22,4 +25,8 @@ public interface TaReadLogMapper extends BaseMapper<TaReadLog> {
22 25
     IPage<MyReadLog> getMyReadList(IPage<MyReadLog> pg, String personId);
23 26
 
24 27
     int updateDuration(String personId, String postId, Integer duration);
28
+
29
+    List<Map<String, Integer>> getIndexPostPV(String startDate, String endDate, long days);
30
+
31
+    List<Map<String, Integer>> getIndexPostUV(String startDate, String endDate, long days);
25 32
 }

+ 4
- 0
src/main/java/com/yunzhi/demo/service/ITaPersonService.java Voir le fichier

@@ -1,7 +1,9 @@
1 1
 package com.yunzhi.demo.service;
2 2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
3 4
 import com.yunzhi.demo.entity.TaPerson;
4 5
 import com.baomidou.mybatisplus.extension.service.IService;
6
+import com.yunzhi.demo.vo.StatisPerson;
5 7
 
6 8
 /**
7 9
  * <p>
@@ -16,4 +18,6 @@ public interface ITaPersonService extends IService<TaPerson> {
16 18
     TaPerson getByOpenid(String openid);
17 19
 
18 20
     int countStudent();
21
+
22
+    IPage<StatisPerson> getStudentStatis(IPage<StatisPerson> pg, String name, String schoolId, String specialtyId, String asc, String desc);
19 23
 }

+ 1
- 0
src/main/java/com/yunzhi/demo/service/ITaPostDataService.java Voir le fichier

@@ -4,6 +4,7 @@ import com.yunzhi.demo.entity.TaPerson;
4 4
 import com.yunzhi.demo.entity.TaPostData;
5 5
 import com.baomidou.mybatisplus.extension.service.IService;
6 6
 
7
+import java.util.List;
7 8
 import java.util.Map;
8 9
 
9 10
 /**

+ 3
- 0
src/main/java/com/yunzhi/demo/service/ITaPostService.java Voir le fichier

@@ -3,6 +3,7 @@ package com.yunzhi.demo.service;
3 3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4 4
 import com.yunzhi.demo.entity.TaPost;
5 5
 import com.baomidou.mybatisplus.extension.service.IService;
6
+import com.yunzhi.demo.vo.StatisPost;
6 7
 
7 8
 /**
8 9
  * <p>
@@ -15,4 +16,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
15 16
 public interface ITaPostService extends IService<TaPost> {
16 17
 
17 18
     IPage<TaPost> getIndexList(IPage<TaPost> page);
19
+
20
+    IPage<StatisPost> getPostStatis(IPage<StatisPost> pg, String startDate, String endDate, String name, String typeId, String asc, String desc);
18 21
 }

+ 7
- 0
src/main/java/com/yunzhi/demo/service/ITaReadLogService.java Voir le fichier

@@ -5,6 +5,9 @@ import com.yunzhi.demo.entity.MyReadLog;
5 5
 import com.yunzhi.demo.entity.TaReadLog;
6 6
 import com.baomidou.mybatisplus.extension.service.IService;
7 7
 
8
+import java.util.List;
9
+import java.util.Map;
10
+
8 11
 /**
9 12
  * <p>
10 13
  * 阅读记录 服务类
@@ -18,4 +21,8 @@ public interface ITaReadLogService extends IService<TaReadLog> {
18 21
     IPage<MyReadLog> getMyReadList(IPage<MyReadLog> pg, String personId);
19 22
 int
20 23
      updateDuration(String personId, String postId, Integer duration);
24
+
25
+    List<Map<String, Integer>> getIndexPostPV(String startDate, String endDate);
26
+
27
+    List<Map<String, Integer>> getIndexPostUV(String startDate, String endDate);
21 28
 }

+ 32
- 0
src/main/java/com/yunzhi/demo/service/impl/TaPersonServiceImpl.java Voir le fichier

@@ -1,11 +1,15 @@
1 1
 package com.yunzhi.demo.service.impl;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
4 5
 import com.yunzhi.demo.common.Constants;
6
+import com.yunzhi.demo.common.StringUtils;
5 7
 import com.yunzhi.demo.entity.TaPerson;
6 8
 import com.yunzhi.demo.mapper.TaPersonMapper;
7 9
 import com.yunzhi.demo.service.ITaPersonService;
8 10
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
11
+import com.yunzhi.demo.vo.StatisPerson;
12
+import org.springframework.beans.factory.annotation.Autowired;
9 13
 import org.springframework.stereotype.Service;
10 14
 
11 15
 /**
@@ -19,6 +23,9 @@ import org.springframework.stereotype.Service;
19 23
 @Service
20 24
 public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> implements ITaPersonService {
21 25
 
26
+    @Autowired
27
+    TaPersonMapper taPersonMapper;
28
+
22 29
     @Override
23 30
     public TaPerson getByOpenid(String openid) {
24 31
         QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<TaPerson>()
@@ -34,4 +41,29 @@ public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> i
34 41
                 .gt("status", Constants.STATUS_DELETED);
35 42
         return count(queryWrapper);
36 43
     }
44
+
45
+    @Override
46
+    public IPage<StatisPerson> getStudentStatis(IPage<StatisPerson> pg, String name, String schoolId, String specialtyId, String asc, String desc) {
47
+        if (StringUtils.isEmpty(asc) && StringUtils.isEmpty(desc)) {
48
+            desc = "readedNum";
49
+        }
50
+        return taPersonMapper.getStudentStatis(pg, name, schoolId, specialtyId, getDBFieldBy(asc), getDBFieldBy(desc));
51
+    }
52
+
53
+    private String getDBFieldBy(String name) {
54
+        if (StringUtils.isEmpty(name)) {
55
+            return null;
56
+        }
57
+
58
+        switch (name.toLowerCase()) {
59
+            case "readedNum":
60
+                return "readed_num";
61
+            case "creditNum":
62
+                return "credit_num";
63
+            case "pointNum":
64
+                return "point_num";
65
+            default:
66
+                return "saved_num";
67
+        }
68
+    }
37 69
 }

+ 1
- 0
src/main/java/com/yunzhi/demo/service/impl/TaPostDataServiceImpl.java Voir le fichier

@@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
13 13
 import org.springframework.scheduling.annotation.Async;
14 14
 import org.springframework.stereotype.Service;
15 15
 
16
+import java.util.List;
16 17
 import java.util.Map;
17 18
 
18 19
 /**

+ 32
- 0
src/main/java/com/yunzhi/demo/service/impl/TaPostServiceImpl.java Voir le fichier

@@ -3,12 +3,17 @@ package com.yunzhi.demo.service.impl;
3 3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.yunzhi.demo.common.Constants;
6
+import com.yunzhi.demo.common.StringUtils;
6 7
 import com.yunzhi.demo.entity.TaPost;
7 8
 import com.yunzhi.demo.mapper.TaPostMapper;
8 9
 import com.yunzhi.demo.service.ITaPostService;
9 10
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
11
+import com.yunzhi.demo.vo.StatisPost;
12
+import org.springframework.beans.factory.annotation.Autowired;
10 13
 import org.springframework.stereotype.Service;
11 14
 
15
+import java.util.Locale;
16
+
12 17
 /**
13 18
  * <p>
14 19
  * 文章表 服务实现类
@@ -20,6 +25,9 @@ import org.springframework.stereotype.Service;
20 25
 @Service
21 26
 public class TaPostServiceImpl extends ServiceImpl<TaPostMapper, TaPost> implements ITaPostService {
22 27
 
28
+    @Autowired
29
+    TaPostMapper taPostMapper;
30
+
23 31
     @Override
24 32
     public IPage<TaPost> getIndexList(IPage<TaPost> page) {
25 33
         QueryWrapper<TaPost> queryWrapper = new QueryWrapper<TaPost>()
@@ -27,4 +35,28 @@ public class TaPostServiceImpl extends ServiceImpl<TaPostMapper, TaPost> impleme
27 35
                 .orderByDesc("create_date");
28 36
         return page(page, queryWrapper);
29 37
     }
38
+
39
+    @Override
40
+    public IPage<StatisPost> getPostStatis(IPage<StatisPost> pg, String startDate, String endDate, String name, String typeId, String asc, String desc) {
41
+        if (StringUtils.isEmpty(asc) && StringUtils.isEmpty(desc)) {
42
+            desc = "pv";
43
+        }
44
+        return taPostMapper.getPostStatis(pg, startDate, endDate, name, typeId, getDBFieldBy(asc), getDBFieldBy(desc));
45
+    }
46
+
47
+    private String getDBFieldBy(String name) {
48
+        if (StringUtils.isEmpty(name)) {
49
+            return null;
50
+        }
51
+
52
+        switch (name.toLowerCase()) {
53
+            case "uv":
54
+                return "u_v";
55
+            case "pv":
56
+                return "p_v";
57
+            default:
58
+                return "saved_num";
59
+        }
60
+    }
61
+
30 62
 }

+ 21
- 0
src/main/java/com/yunzhi/demo/service/impl/TaReadLogServiceImpl.java Voir le fichier

@@ -1,6 +1,7 @@
1 1
 package com.yunzhi.demo.service.impl;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
+import com.yunzhi.demo.common.DateUtils;
4 5
 import com.yunzhi.demo.entity.MyReadLog;
5 6
 import com.yunzhi.demo.entity.TaReadLog;
6 7
 import com.yunzhi.demo.mapper.TaReadLogMapper;
@@ -9,6 +10,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
9 10
 import org.springframework.beans.factory.annotation.Autowired;
10 11
 import org.springframework.stereotype.Service;
11 12
 
13
+import java.time.LocalDateTime;
14
+import java.util.List;
15
+import java.util.Map;
16
+
12 17
 /**
13 18
  * <p>
14 19
  * 阅读记录 服务实现类
@@ -32,4 +37,20 @@ public class TaReadLogServiceImpl extends ServiceImpl<TaReadLogMapper, TaReadLog
32 37
     public int updateDuration(String personId, String postId, Integer duration) {
33 38
         return taReadLogMapper.updateDuration(personId, postId, duration);
34 39
     }
40
+
41
+    @Override
42
+    public List<Map<String, Integer>> getIndexPostPV(String startDate, String endDate) {
43
+        LocalDateTime dt1 = DateUtils.from(startDate + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
44
+        LocalDateTime dt2 = DateUtils.from(endDate + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
45
+        long days = DateUtils.daysBetween(dt1, dt2);
46
+        return taReadLogMapper.getIndexPostPV(startDate, endDate, days);
47
+    }
48
+
49
+    @Override
50
+    public List<Map<String, Integer>> getIndexPostUV(String startDate, String endDate) {
51
+        LocalDateTime dt1 = DateUtils.from(startDate + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
52
+        LocalDateTime dt2 = DateUtils.from(endDate + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
53
+        long days = DateUtils.daysBetween(dt1, dt2);
54
+        return taReadLogMapper.getIndexPostUV(startDate, endDate, days);
55
+    }
35 56
 }

+ 23
- 0
src/main/java/com/yunzhi/demo/vo/StatisPerson.java Voir le fichier

@@ -0,0 +1,23 @@
1
+package com.yunzhi.demo.vo;
2
+
3
+import com.yunzhi.demo.entity.TaPerson;
4
+import io.swagger.annotations.ApiModel;
5
+import io.swagger.annotations.ApiModelProperty;
6
+import lombok.Data;
7
+
8
+@ApiModel(description = "学生统计")
9
+@Data
10
+public class StatisPerson extends TaPerson {
11
+
12
+    @ApiModelProperty(value = "积分")
13
+    private Integer pointNum;
14
+
15
+    @ApiModelProperty(value = "学分")
16
+    private String creditNum;
17
+
18
+    @ApiModelProperty(value = "收藏文章")
19
+    private Integer savedNum;
20
+
21
+    @ApiModelProperty(value = "阅读文章")
22
+    private Integer readedNum;
23
+}

+ 20
- 0
src/main/java/com/yunzhi/demo/vo/StatisPost.java Voir le fichier

@@ -0,0 +1,20 @@
1
+package com.yunzhi.demo.vo;
2
+
3
+import com.yunzhi.demo.entity.TaPost;
4
+import io.swagger.annotations.ApiModel;
5
+import io.swagger.annotations.ApiModelProperty;
6
+import lombok.Data;
7
+
8
+@ApiModel(description = "科普统计")
9
+@Data
10
+public class StatisPost extends TaPost {
11
+
12
+    @ApiModelProperty(value = "阅读人数")
13
+    private Long uV;
14
+
15
+    @ApiModelProperty(value = "浏览量")
16
+    private Long pV;
17
+
18
+    @ApiModelProperty(value = "收藏量")
19
+    private Long savedNum;
20
+}

+ 30
- 0
src/main/resources/mapper/TaPersonMapper.xml Voir le fichier

@@ -2,4 +2,34 @@
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.yunzhi.demo.mapper.TaPersonMapper">
4 4
 
5
+    <select id="getStudentStatis" resultType="com.yunzhi.demo.vo.StatisPerson">
6
+        SELECT
7
+            t.*,
8
+            s.credit_num,
9
+            s.point_num,
10
+            s.readed_num,
11
+            s.saved_num
12
+        FROM
13
+            ta_person t
14
+                INNER JOIN ta_person_data s ON t.person_id = s.person_id
15
+        WHERE
16
+            t.student_id > ''
17
+          AND t.`status` > - 1
18
+        <if test="name != null and name != ''">
19
+            AND t.`name` LIKE CONCAT('%', #{name}, '%')
20
+        </if>
21
+        <if test="schoolId != null and schoolId != ''">
22
+            AND t.school_id = #{schoolId}
23
+        </if>
24
+        <if test="specialtyId != null and specialtyId != ''">
25
+          AND t.specialty_id = #{specialtyId}
26
+        </if>
27
+        ORDER BY
28
+        <if test="asc != null and asc != ''">
29
+            ${asc} ASC
30
+        </if>
31
+        <if test="desc != null and desc != ''">
32
+            ${desc} DESC
33
+        </if>
34
+    </select>
5 35
 </mapper>

+ 42
- 0
src/main/resources/mapper/TaPostMapper.xml Voir le fichier

@@ -2,4 +2,46 @@
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.yunzhi.demo.mapper.TaPostMapper">
4 4
 
5
+    <select id="getPostStatis" resultType="com.yunzhi.demo.vo.StatisPost">
6
+        SELECT
7
+            *
8
+        FROM
9
+            (
10
+            SELECT
11
+                t.*,
12
+                sum( IF ( s.serial_no IS NULL, 0, 1 ) ) AS p_v,
13
+                count( DISTINCT s.person_id ) AS u_v,
14
+                sum( IF ( m.serial_no IS NULL, 0, 1 ) ) AS saved_num
15
+            FROM
16
+                ta_post t
17
+                LEFT JOIN ta_read_log s ON t.post_id = s.post_id
18
+                LEFT JOIN ta_post_save m ON t.post_id = m.post_id
19
+                AND m.`status` > - 1
20
+            WHERE
21
+                1 = 1
22
+              <if test="startDate != null and startDate != ''">
23
+                  AND s.create_date &gt;= DATE_FORMAT( #{startDate}, '%Y-%m-%d' )
24
+                  AND m.create_date &gt;= DATE_FORMAT( #{startDate}, '%Y-%m-%d' )
25
+              </if>
26
+              <if test="startDate != null and startDate != ''">
27
+                  AND s.create_date &lt;= DATE_FORMAT( #{endDate}, '%Y-%m-%d' )
28
+                  AND m.create_date &lt;= DATE_FORMAT( #{endDate}, '%Y-%m-%d' )
29
+              </if>
30
+              <if test="typeId != null and typeId != ''">
31
+                  AND t.type_id = #{typeId}
32
+              </if>
33
+              <if test="name != null and name != ''">
34
+                AND t.name LIKE CONCAT('%', #{name}, '%')
35
+              </if>
36
+            GROUP BY
37
+                t.post_id
38
+            ) a
39
+        ORDER BY
40
+          <if test="asc != null and asc != ''">
41
+            ${asc} ASC
42
+          </if>
43
+          <if test="desc != null and desc != ''">
44
+            ${desc} DESC
45
+          </if>
46
+    </select>
5 47
 </mapper>

+ 45
- 0
src/main/resources/mapper/TaReadLogMapper.xml Voir le fichier

@@ -35,4 +35,49 @@
35 35
         ORDER BY
36 36
             t.create_date DESC
37 37
     </select>
38
+    <select id="getIndexPostPV" resultType="java.util.Map">
39
+        SELECT
40
+            date_add( STR_TO_DATE( #{startDate}, '%Y-%m-%d' ), INTERVAL t.rownum DAY ) AS dt,
41
+            IFNULL( s.val, 0 ) AS val
42
+        FROM
43
+            sequence t
44
+            LEFT JOIN (
45
+                SELECT
46
+                    count( 1 ) AS val,
47
+                    DATE_FORMAT( create_date, '%Y-%m-%d' ) AS dt
48
+                FROM
49
+                    ta_read_log
50
+                WHERE
51
+                    DATE_FORMAT( create_date, '%Y-%m-%d' ) BETWEEN #{startDate} AND #{endDate}
52
+                GROUP BY
53
+                    DATE_FORMAT( create_date, '%Y-%m-%d' )
54
+            ) s ON t.rownum = to_days( s.dt ) - to_days( #{startDate} )
55
+        WHERE
56
+            t.rownum &lt; #{days}
57
+        ORDER BY
58
+            t.rownum ASC
59
+    </select>
60
+    <select id="getIndexPostUV" resultType="java.util.Map">
61
+
62
+        SELECT
63
+            date_add( STR_TO_DATE( #{startDate}, '%Y-%m-%d' ), INTERVAL t.rownum DAY ) AS dt,
64
+            IFNULL( s.val, 0 ) AS val
65
+        FROM
66
+            sequence t
67
+                LEFT JOIN (
68
+                SELECT
69
+                    count( DISTINCT person_id ) AS val,
70
+                    DATE_FORMAT( create_date, '%Y-%m-%d' ) AS dt
71
+                FROM
72
+                    ta_read_log
73
+                WHERE
74
+                    DATE_FORMAT( create_date, '%Y-%m-%d' ) BETWEEN #{startDate} AND #{endDate}
75
+                GROUP BY
76
+                    DATE_FORMAT( create_date, '%Y-%m-%d' )
77
+            ) s ON t.rownum = to_days( s.dt ) - to_days( #{startDate} )
78
+        WHERE
79
+            t.rownum &lt; #{days}
80
+        ORDER BY
81
+            t.rownum ASC
82
+    </select>
38 83
 </mapper>