张延森 4 years ago
parent
commit
c6839e8ccd

+ 39
- 0
src/main/java/com/yunzhi/demo/controller/StatisticController.java View File

@@ -0,0 +1,39 @@
1
+package com.yunzhi.demo.controller;
2
+
3
+import com.yunzhi.demo.common.BaseController;
4
+import com.yunzhi.demo.common.ResponseBean;
5
+import com.yunzhi.demo.service.ITaPersonService;
6
+import com.yunzhi.demo.service.ITaPostDataService;
7
+import io.swagger.annotations.Api;
8
+import io.swagger.annotations.ApiOperation;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.web.bind.annotation.GetMapping;
11
+import org.springframework.web.bind.annotation.PostMapping;
12
+import org.springframework.web.bind.annotation.RestController;
13
+
14
+import java.util.Map;
15
+
16
+
17
+@Api(tags = "查询统计")
18
+@RestController
19
+public class StatisticController extends BaseController {
20
+
21
+    @Autowired
22
+    ITaPostDataService iTaPostDataService;
23
+
24
+    @Autowired
25
+    ITaPersonService iTaPersonService;
26
+
27
+
28
+    @GetMapping("/admin/index/post-data")
29
+    @ApiOperation(value="首页简单的几个统计", notes = "首页简单的几个统计", httpMethod = "GET", response = ResponseBean.class)
30
+    public ResponseBean getIndexPostData() {
31
+        // 获取总科普数, 以及 浏览量
32
+        Map<String, Object> result = iTaPostDataService.getIndexBasicData();
33
+        // 获取总学生人员
34
+        int totalStudents = iTaPersonService.countStudent();
35
+        result.put("student", totalStudents);
36
+
37
+        return ResponseBean.success(result);
38
+    }
39
+}

+ 4
- 0
src/main/java/com/yunzhi/demo/mapper/TaPostDataMapper.java View File

@@ -4,6 +4,8 @@ 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.Map;
8
+
7 9
 /**
8 10
  * <p>
9 11
  * 文章统计 Mapper 接口
@@ -16,4 +18,6 @@ import org.apache.ibatis.annotations.Mapper;
16 18
 public interface TaPostDataMapper extends BaseMapper<TaPostData> {
17 19
 
18 20
     int updatePvUvBy(String postId, int addUv, int addPv);
21
+
22
+    Map<String, Object> getIndexBasicData();
19 23
 }

+ 2
- 0
src/main/java/com/yunzhi/demo/service/ITaPersonService.java View File

@@ -14,4 +14,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
14 14
 public interface ITaPersonService extends IService<TaPerson> {
15 15
 
16 16
     TaPerson getByOpenid(String openid);
17
+
18
+    int countStudent();
17 19
 }

+ 4
- 0
src/main/java/com/yunzhi/demo/service/ITaPostDataService.java View File

@@ -4,6 +4,8 @@ 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.Map;
8
+
7 9
 /**
8 10
  * <p>
9 11
  * 文章统计 服务类
@@ -15,4 +17,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
15 17
 public interface ITaPostDataService extends IService<TaPostData> {
16 18
 
17 19
     void recordBy(String postId, TaPerson taPerson);
20
+
21
+    Map<String, Object> getIndexBasicData();
18 22
 }

+ 8
- 0
src/main/java/com/yunzhi/demo/service/impl/TaPersonServiceImpl.java View File

@@ -26,4 +26,12 @@ public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> i
26 26
                 .gt("status", Constants.STATUS_DELETED);
27 27
         return getOne(queryWrapper);
28 28
     }
29
+
30
+    @Override
31
+    public int countStudent() {
32
+        QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<TaPerson>()
33
+                .isNotNull("student_id")
34
+                .gt("status", Constants.STATUS_DELETED);
35
+        return count(queryWrapper);
36
+    }
29 37
 }

+ 7
- 0
src/main/java/com/yunzhi/demo/service/impl/TaPostDataServiceImpl.java View File

@@ -13,6 +13,8 @@ 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.Map;
17
+
16 18
 /**
17 19
  * <p>
18 20
  * 文章统计 服务实现类
@@ -50,4 +52,9 @@ public class TaPostDataServiceImpl extends ServiceImpl<TaPostDataMapper, TaPostD
50 52
             taReadLogMapper.insert(taReadLog);
51 53
         }
52 54
     }
55
+
56
+    @Override
57
+    public Map<String, Object> getIndexBasicData() {
58
+        return taPostDataMapper.getIndexBasicData();
59
+    }
53 60
 }

+ 10
- 0
src/main/resources/mapper/TaPostDataMapper.xml View File

@@ -9,4 +9,14 @@
9 9
         WHERE
10 10
             post_id = #{postId}
11 11
     </update>
12
+    <select id="getIndexBasicData" resultType="java.util.Map">
13
+        SELECT
14
+            count( 1 ) AS total,
15
+            sum( s.p_v ) AS pv
16
+        FROM
17
+            ta_post t
18
+                INNER JOIN ta_post_data s ON t.post_id = s.post_id
19
+        WHERE
20
+            t.`status` > -1
21
+    </select>
12 22
 </mapper>