张延森 4 лет назад
Родитель
Сommit
9c88bec38e

+ 17
- 0
src/main/java/com/yunzhi/demo/common/DateUtils.java Просмотреть файл

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 Просмотреть файл

1
 package com.yunzhi.demo.controller;
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
 import com.yunzhi.demo.common.BaseController;
5
 import com.yunzhi.demo.common.BaseController;
4
 import com.yunzhi.demo.common.ResponseBean;
6
 import com.yunzhi.demo.common.ResponseBean;
7
+import com.yunzhi.demo.entity.TaPost;
5
 import com.yunzhi.demo.service.ITaPersonService;
8
 import com.yunzhi.demo.service.ITaPersonService;
6
 import com.yunzhi.demo.service.ITaPostDataService;
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
 import io.swagger.annotations.Api;
14
 import io.swagger.annotations.Api;
8
 import io.swagger.annotations.ApiOperation;
15
 import io.swagger.annotations.ApiOperation;
16
+import io.swagger.annotations.ApiParam;
9
 import org.springframework.beans.factory.annotation.Autowired;
17
 import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.web.bind.annotation.GetMapping;
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
 import org.springframework.web.bind.annotation.RestController;
20
 import org.springframework.web.bind.annotation.RestController;
13
 
21
 
22
+import java.util.List;
14
 import java.util.Map;
23
 import java.util.Map;
15
 
24
 
16
 
25
 
24
     @Autowired
33
     @Autowired
25
     ITaPersonService iTaPersonService;
34
     ITaPersonService iTaPersonService;
26
 
35
 
36
+    @Autowired
37
+    ITaReadLogService iTaReadLogService;
38
+
39
+    @Autowired
40
+    ITaPostService iTaPostService;
41
+
27
 
42
 
28
     @GetMapping("/admin/index/post-data")
43
     @GetMapping("/admin/index/post-data")
29
     @ApiOperation(value="首页简单的几个统计", notes = "首页简单的几个统计", httpMethod = "GET", response = ResponseBean.class)
44
     @ApiOperation(value="首页简单的几个统计", notes = "首页简单的几个统计", httpMethod = "GET", response = ResponseBean.class)
36
 
51
 
37
         return ResponseBean.success(result);
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 Просмотреть файл

1
 package com.yunzhi.demo.mapper;
1
 package com.yunzhi.demo.mapper;
2
 
2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
3
 import com.yunzhi.demo.entity.TaPerson;
4
 import com.yunzhi.demo.entity.TaPerson;
4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6
+import com.yunzhi.demo.vo.StatisPerson;
5
 import org.apache.ibatis.annotations.Mapper;
7
 import org.apache.ibatis.annotations.Mapper;
8
+import org.apache.ibatis.annotations.Param;
6
 
9
 
7
 /**
10
 /**
8
  * <p>
11
  * <p>
15
 @Mapper
18
 @Mapper
16
 public interface TaPersonMapper extends BaseMapper<TaPerson> {
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 Просмотреть файл

4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
 import org.apache.ibatis.annotations.Mapper;
5
 import org.apache.ibatis.annotations.Mapper;
6
 
6
 
7
+import java.util.List;
7
 import java.util.Map;
8
 import java.util.Map;
8
 
9
 
9
 /**
10
 /**
20
     int updatePvUvBy(String postId, int addUv, int addPv);
21
     int updatePvUvBy(String postId, int addUv, int addPv);
21
 
22
 
22
     Map<String, Object> getIndexBasicData();
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 Просмотреть файл

1
 package com.yunzhi.demo.mapper;
1
 package com.yunzhi.demo.mapper;
2
 
2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
3
 import com.yunzhi.demo.entity.TaPost;
4
 import com.yunzhi.demo.entity.TaPost;
4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6
+import com.yunzhi.demo.vo.StatisPost;
5
 import org.apache.ibatis.annotations.Mapper;
7
 import org.apache.ibatis.annotations.Mapper;
8
+import org.apache.ibatis.annotations.Param;
6
 
9
 
7
 /**
10
 /**
8
  * <p>
11
  * <p>
15
 @Mapper
18
 @Mapper
16
 public interface TaPostMapper extends BaseMapper<TaPost> {
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 Просмотреть файл

6
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
7
 import org.apache.ibatis.annotations.Mapper;
7
 import org.apache.ibatis.annotations.Mapper;
8
 
8
 
9
+import java.util.List;
10
+import java.util.Map;
11
+
9
 /**
12
 /**
10
  * <p>
13
  * <p>
11
  * 阅读记录 Mapper 接口
14
  * 阅读记录 Mapper 接口
22
     IPage<MyReadLog> getMyReadList(IPage<MyReadLog> pg, String personId);
25
     IPage<MyReadLog> getMyReadList(IPage<MyReadLog> pg, String personId);
23
 
26
 
24
     int updateDuration(String personId, String postId, Integer duration);
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 Просмотреть файл

1
 package com.yunzhi.demo.service;
1
 package com.yunzhi.demo.service;
2
 
2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
3
 import com.yunzhi.demo.entity.TaPerson;
4
 import com.yunzhi.demo.entity.TaPerson;
4
 import com.baomidou.mybatisplus.extension.service.IService;
5
 import com.baomidou.mybatisplus.extension.service.IService;
6
+import com.yunzhi.demo.vo.StatisPerson;
5
 
7
 
6
 /**
8
 /**
7
  * <p>
9
  * <p>
16
     TaPerson getByOpenid(String openid);
18
     TaPerson getByOpenid(String openid);
17
 
19
 
18
     int countStudent();
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 Просмотреть файл

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

+ 3
- 0
src/main/java/com/yunzhi/demo/service/ITaPostService.java Просмотреть файл

3
 import com.baomidou.mybatisplus.core.metadata.IPage;
3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
 import com.yunzhi.demo.entity.TaPost;
4
 import com.yunzhi.demo.entity.TaPost;
5
 import com.baomidou.mybatisplus.extension.service.IService;
5
 import com.baomidou.mybatisplus.extension.service.IService;
6
+import com.yunzhi.demo.vo.StatisPost;
6
 
7
 
7
 /**
8
 /**
8
  * <p>
9
  * <p>
15
 public interface ITaPostService extends IService<TaPost> {
16
 public interface ITaPostService extends IService<TaPost> {
16
 
17
 
17
     IPage<TaPost> getIndexList(IPage<TaPost> page);
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 Просмотреть файл

5
 import com.yunzhi.demo.entity.TaReadLog;
5
 import com.yunzhi.demo.entity.TaReadLog;
6
 import com.baomidou.mybatisplus.extension.service.IService;
6
 import com.baomidou.mybatisplus.extension.service.IService;
7
 
7
 
8
+import java.util.List;
9
+import java.util.Map;
10
+
8
 /**
11
 /**
9
  * <p>
12
  * <p>
10
  * 阅读记录 服务类
13
  * 阅读记录 服务类
18
     IPage<MyReadLog> getMyReadList(IPage<MyReadLog> pg, String personId);
21
     IPage<MyReadLog> getMyReadList(IPage<MyReadLog> pg, String personId);
19
 int
22
 int
20
      updateDuration(String personId, String postId, Integer duration);
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 Просмотреть файл

1
 package com.yunzhi.demo.service.impl;
1
 package com.yunzhi.demo.service.impl;
2
 
2
 
3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
4
 import com.yunzhi.demo.common.Constants;
5
 import com.yunzhi.demo.common.Constants;
6
+import com.yunzhi.demo.common.StringUtils;
5
 import com.yunzhi.demo.entity.TaPerson;
7
 import com.yunzhi.demo.entity.TaPerson;
6
 import com.yunzhi.demo.mapper.TaPersonMapper;
8
 import com.yunzhi.demo.mapper.TaPersonMapper;
7
 import com.yunzhi.demo.service.ITaPersonService;
9
 import com.yunzhi.demo.service.ITaPersonService;
8
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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
 import org.springframework.stereotype.Service;
13
 import org.springframework.stereotype.Service;
10
 
14
 
11
 /**
15
 /**
19
 @Service
23
 @Service
20
 public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> implements ITaPersonService {
24
 public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> implements ITaPersonService {
21
 
25
 
26
+    @Autowired
27
+    TaPersonMapper taPersonMapper;
28
+
22
     @Override
29
     @Override
23
     public TaPerson getByOpenid(String openid) {
30
     public TaPerson getByOpenid(String openid) {
24
         QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<TaPerson>()
31
         QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<TaPerson>()
34
                 .gt("status", Constants.STATUS_DELETED);
41
                 .gt("status", Constants.STATUS_DELETED);
35
         return count(queryWrapper);
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 Просмотреть файл

13
 import org.springframework.scheduling.annotation.Async;
13
 import org.springframework.scheduling.annotation.Async;
14
 import org.springframework.stereotype.Service;
14
 import org.springframework.stereotype.Service;
15
 
15
 
16
+import java.util.List;
16
 import java.util.Map;
17
 import java.util.Map;
17
 
18
 
18
 /**
19
 /**

+ 32
- 0
src/main/java/com/yunzhi/demo/service/impl/TaPostServiceImpl.java Просмотреть файл

3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
 import com.yunzhi.demo.common.Constants;
5
 import com.yunzhi.demo.common.Constants;
6
+import com.yunzhi.demo.common.StringUtils;
6
 import com.yunzhi.demo.entity.TaPost;
7
 import com.yunzhi.demo.entity.TaPost;
7
 import com.yunzhi.demo.mapper.TaPostMapper;
8
 import com.yunzhi.demo.mapper.TaPostMapper;
8
 import com.yunzhi.demo.service.ITaPostService;
9
 import com.yunzhi.demo.service.ITaPostService;
9
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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
 import org.springframework.stereotype.Service;
13
 import org.springframework.stereotype.Service;
11
 
14
 
15
+import java.util.Locale;
16
+
12
 /**
17
 /**
13
  * <p>
18
  * <p>
14
  * 文章表 服务实现类
19
  * 文章表 服务实现类
20
 @Service
25
 @Service
21
 public class TaPostServiceImpl extends ServiceImpl<TaPostMapper, TaPost> implements ITaPostService {
26
 public class TaPostServiceImpl extends ServiceImpl<TaPostMapper, TaPost> implements ITaPostService {
22
 
27
 
28
+    @Autowired
29
+    TaPostMapper taPostMapper;
30
+
23
     @Override
31
     @Override
24
     public IPage<TaPost> getIndexList(IPage<TaPost> page) {
32
     public IPage<TaPost> getIndexList(IPage<TaPost> page) {
25
         QueryWrapper<TaPost> queryWrapper = new QueryWrapper<TaPost>()
33
         QueryWrapper<TaPost> queryWrapper = new QueryWrapper<TaPost>()
27
                 .orderByDesc("create_date");
35
                 .orderByDesc("create_date");
28
         return page(page, queryWrapper);
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 Просмотреть файл

1
 package com.yunzhi.demo.service.impl;
1
 package com.yunzhi.demo.service.impl;
2
 
2
 
3
 import com.baomidou.mybatisplus.core.metadata.IPage;
3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
+import com.yunzhi.demo.common.DateUtils;
4
 import com.yunzhi.demo.entity.MyReadLog;
5
 import com.yunzhi.demo.entity.MyReadLog;
5
 import com.yunzhi.demo.entity.TaReadLog;
6
 import com.yunzhi.demo.entity.TaReadLog;
6
 import com.yunzhi.demo.mapper.TaReadLogMapper;
7
 import com.yunzhi.demo.mapper.TaReadLogMapper;
9
 import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.stereotype.Service;
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
  * <p>
18
  * <p>
14
  * 阅读记录 服务实现类
19
  * 阅读记录 服务实现类
32
     public int updateDuration(String personId, String postId, Integer duration) {
37
     public int updateDuration(String personId, String postId, Integer duration) {
33
         return taReadLogMapper.updateDuration(personId, postId, duration);
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 Просмотреть файл

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 Просмотреть файл

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 Просмотреть файл

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.yunzhi.demo.mapper.TaPersonMapper">
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
 </mapper>
35
 </mapper>

+ 42
- 0
src/main/resources/mapper/TaPostMapper.xml Просмотреть файл

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.yunzhi.demo.mapper.TaPostMapper">
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
 </mapper>
47
 </mapper>

+ 45
- 0
src/main/resources/mapper/TaReadLogMapper.xml Просмотреть файл

35
         ORDER BY
35
         ORDER BY
36
             t.create_date DESC
36
             t.create_date DESC
37
     </select>
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
 </mapper>
83
 </mapper>