魏熙美 5 년 전
부모
커밋
92479908a2

+ 11
- 0
src/main/java/com/huiju/estateagents/common/CommConstant.java 파일 보기

@@ -239,4 +239,15 @@ public class CommConstant {
239 239
      * 注册经纪人积分规则
240 240
      */
241 241
     public static final Integer POINTS_RULE_SIGNUP_AGENT = 4;
242
+
243
+
244
+    // ----   用户活跃数  查询条件 start ------
245
+
246
+    public static final String DAY = "day";
247
+
248
+    public static final String WEEK = "week";
249
+
250
+    public static final String MONTH = "month";
251
+
252
+    // ----     查询条件 end ------
242 253
 }

+ 31
- 0
src/main/java/com/huiju/estateagents/controller/StatisticalController.java 파일 보기

@@ -0,0 +1,31 @@
1
+package com.huiju.estateagents.controller;
2
+
3
+import com.huiju.estateagents.base.ResponseBean;
4
+import com.huiju.estateagents.service.IStatisticalService;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.web.bind.annotation.GetMapping;
7
+import org.springframework.web.bind.annotation.RequestMapping;
8
+import org.springframework.web.bind.annotation.RequestMethod;
9
+import org.springframework.web.bind.annotation.RestController;
10
+
11
+/**
12
+ * 数据统计
13
+ */
14
+@RestController
15
+@RequestMapping("/")
16
+public class StatisticalController {
17
+
18
+    @Autowired
19
+    private IStatisticalService iStatisticalService;
20
+
21
+    /**
22
+     * 首页统计
23
+     * @return
24
+     */
25
+    @GetMapping(value = "/indexStatistical")
26
+    public ResponseBean indexStatistical() {
27
+        return iStatisticalService.indexStatistical();
28
+    }
29
+
30
+
31
+}

+ 63
- 0
src/main/java/com/huiju/estateagents/mapper/TaPersonMapper.java 파일 보기

@@ -3,10 +3,13 @@ package com.huiju.estateagents.mapper;
3 3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4 4
 import com.huiju.estateagents.entity.TaPerson;
5 5
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6
+import com.huiju.estateagents.po.PersonPO;
6 7
 import org.apache.ibatis.annotations.Mapper;
7 8
 import org.apache.ibatis.annotations.Param;
9
+import org.apache.ibatis.annotations.Select;
8 10
 
9 11
 import java.io.Serializable;
12
+import java.util.Date;
10 13
 import java.util.List;
11 14
 import java.util.Map;
12 15
 
@@ -45,4 +48,64 @@ public interface TaPersonMapper extends BaseMapper<TaPerson> {
45 48
 
46 49
     List<Map<String,Object>> selectCardListofMine(IPage<Map<String,Object>> page, @Param("personType") String personType, @Param("status") int status,@Param("personIds")List<String> personIds);
47 50
 
51
+    //---------- 用户总数 start ------------
52
+
53
+    /**
54
+     * 总用户数
55
+     * @param personType
56
+     * @return
57
+     */
58
+    @Select("select count(1) from ta_person where person_type = #{personType}")
59
+    Integer selectUserCount(@Param("personType") String personType);
60
+
61
+    /**
62
+     * 总注册数
63
+     * @param personType
64
+     * @return
65
+     */
66
+    @Select("select count(1) from ta_person where person_type = #{personType} and phone is not null")
67
+    Integer selectRegisteredCount(@Param("personType") String personType);
68
+
69
+    /**
70
+     * 根据时间段查询
71
+     * @param personType
72
+     * @return
73
+     */
74
+    Integer selectRecentlyCount(@Param("personType") String personType, @Param("startDate")Date startDate, @Param("endDate")Date endDate);
75
+
76
+    //---------- 用户总数 end ------------
77
+
78
+    /**
79
+     * 用户行为
80
+     * @param personType
81
+     * @param startDate
82
+     * @param endDate
83
+     * @return
84
+     */
85
+    List<PersonPO> selectUserBehavior(@Param("personType") String personType, @Param("startDate")Date startDate, @Param("endDate")Date endDate);
86
+
87
+    /**
88
+     * 活跃用户数 / 最近新增的用户数
89
+     * @param personType
90
+     * @param dateType
91
+     * @return
92
+     */
93
+    List<Map<String, Object>> selectActiveUserCount(@Param("personType") String personType, @Param("dateType") String dateType, @Param("startDate")Date startDate, @Param("endDate")Date endDate);
94
+
95
+
96
+    /**
97
+     * 性别比例
98
+     * @param personType
99
+     * @return
100
+     */
101
+    @Select("select sex, count(1) from ta_person where person_type = #{personType} GROUP BY sex")
102
+    List<Map<String, Object>> selectSexUser(@Param("personType") String personType);
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
48 111
 }

+ 26
- 0
src/main/java/com/huiju/estateagents/po/PersonPO.java 파일 보기

@@ -0,0 +1,26 @@
1
+package com.huiju.estateagents.po;
2
+
3
+import lombok.AllArgsConstructor;
4
+import lombok.Data;
5
+import lombok.NoArgsConstructor;
6
+
7
+import java.util.Date;
8
+
9
+/**
10
+ * 数据统计映射
11
+ *
12
+ */
13
+@Data
14
+@AllArgsConstructor
15
+@NoArgsConstructor
16
+public class PersonPO {
17
+
18
+    private Date date;
19
+
20
+    private Integer activityCount;
21
+
22
+    private Date visitTime;
23
+
24
+    private String activity;
25
+
26
+}

+ 22
- 0
src/main/java/com/huiju/estateagents/service/IStatisticalService.java 파일 보기

@@ -0,0 +1,22 @@
1
+package com.huiju.estateagents.service;
2
+
3
+import com.huiju.estateagents.base.ResponseBean;
4
+
5
+/**
6
+ * 数据统计 接口
7
+ */
8
+public interface IStatisticalService {
9
+
10
+    /**
11
+     * 首页统计总数
12
+     * @return
13
+     */
14
+    ResponseBean indexStatistical();
15
+
16
+    /**
17
+     * 活跃用户数
18
+     * @return
19
+     */
20
+    ResponseBean selectActiveUserCount(String dateType);
21
+
22
+}

+ 87
- 0
src/main/java/com/huiju/estateagents/service/impl/StatisticalServiceImpl.java 파일 보기

@@ -0,0 +1,87 @@
1
+package com.huiju.estateagents.service.impl;
2
+
3
+import com.huiju.estateagents.base.ResponseBean;
4
+import com.huiju.estateagents.common.CommConstant;
5
+import com.huiju.estateagents.exception.EstaException;
6
+import com.huiju.estateagents.mapper.TaPersonMapper;
7
+import com.huiju.estateagents.po.PersonPO;
8
+import com.huiju.estateagents.service.IStatisticalService;
9
+import lombok.extern.slf4j.Slf4j;
10
+import org.springframework.beans.factory.annotation.Autowired;
11
+import org.springframework.stereotype.Service;
12
+
13
+import java.time.LocalDateTime;
14
+import java.util.HashMap;
15
+import java.util.List;
16
+import java.util.Map;
17
+
18
+/**
19
+ * 数据统计
20
+ */
21
+@Service
22
+@Slf4j
23
+public class StatisticalServiceImpl implements IStatisticalService {
24
+
25
+    @Autowired
26
+    private TaPersonMapper taPersonMapper;
27
+
28
+
29
+    @Override
30
+    public ResponseBean indexStatistical() {
31
+
32
+        ResponseBean responseBean = new ResponseBean();
33
+        Map<String,Object> map = new HashMap<>();
34
+
35
+        // 总用户数
36
+        Integer selectUserCount = taPersonMapper.selectUserCount(CommConstant.PERSON_REALTY_CONSULTANT);
37
+
38
+        // 注册数
39
+        Integer selectRegisteredCount = taPersonMapper.selectRegisteredCount(CommConstant.PERSON_REALTY_CONSULTANT);
40
+
41
+        // 最近七天
42
+        Integer selectRecentlyCount = taPersonMapper.selectRecentlyCount(CommConstant.PERSON_REALTY_CONSULTANT, null, null);
43
+
44
+        // 用户行为
45
+        List<PersonPO> selectUserBehavior = taPersonMapper.selectUserBehavior(CommConstant.PERSON_REALTY_CONSULTANT, null, null);
46
+
47
+        // 用户活跃数 / 新增用户数
48
+        List<Map<String, Object>> selectActiveUserCount = taPersonMapper.selectActiveUserCount(CommConstant.PERSON_REALTY_CONSULTANT, CommConstant.DAY, null, null);
49
+
50
+        // 性别比例
51
+        List<Map<String, Object>> selectSexUser = taPersonMapper.selectSexUser(CommConstant.PERSON_REALTY_CONSULTANT);
52
+
53
+        map.put("selectUserCount", selectUserCount);
54
+        map.put("selectRegisteredCount", selectRegisteredCount);
55
+        map.put("selectRecentlyCount", selectRecentlyCount);
56
+        map.put("selectUserBehavior", selectUserBehavior);
57
+        map.put("selectActiveUserCount", selectActiveUserCount);
58
+        map.put("selectSexUser", selectSexUser);
59
+
60
+        responseBean.addSuccess(map);
61
+
62
+        return responseBean;
63
+    }
64
+
65
+    @Override
66
+    public ResponseBean selectActiveUserCount(String dateType) {
67
+        ResponseBean responseBean = new ResponseBean();
68
+
69
+        String type = null;
70
+        if (CommConstant.DAY.equals(dateType)) {
71
+            type = CommConstant.DAY;
72
+        } else if (CommConstant.WEEK.equals(dateType)) {
73
+            type = CommConstant.WEEK;
74
+        } else if (CommConstant.MONTH.equals(dateType)) {
75
+            type = CommConstant.MONTH;
76
+        } else {
77
+            responseBean.addError("无此查询类型!");
78
+        }
79
+
80
+        // 用户活跃数
81
+        List<Map<String, Object>> selectActiveUserCount = taPersonMapper.selectActiveUserCount(CommConstant.PERSON_REALTY_CONSULTANT, type, null, null);
82
+        Map<String, Object> map = new HashMap<>();
83
+        map.put("selectActiveUserCount", selectActiveUserCount);
84
+        responseBean.addSuccess(map);
85
+        return responseBean;
86
+    }
87
+}

+ 96
- 0
src/main/resources/mapper/TaPersonMapper.xml 파일 보기

@@ -138,4 +138,100 @@ FROM
138 138
         ORDER BY
139 139
         t.create_date DESC
140 140
     </select>
141
+
142
+
143
+    <select id="selectRecentlyCount" >
144
+        SELECT
145
+          SUM(activity_count)
146
+        FROM
147
+        (
148
+            SELECT
149
+              DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
150
+            FROM
151
+              sequence a
152
+            WHERE
153
+                <if test="startDate == null or endDate == null">
154
+                    a.rownum <![CDATA[ <= ]]> 7
155
+                </if>
156
+                <if test="startDate != null or endDate != null">
157
+                    a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
158
+                </if>
159
+        ) AS temp_date
160
+        LEFT JOIN (
161
+            SELECT
162
+            COUNT(1) as activity_count,
163
+            tpvr.visit_time AS visit_time
164
+            FROM
165
+            ta_person tp
166
+            INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
167
+        ) AS temp ON temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' )
168
+    </select>
169
+
170
+
171
+    <select id="selectUserBehavior" resultType="com.huiju.estateagents.po.PersonPO">
172
+        SELECT
173
+        *
174
+        FROM
175
+        (
176
+            SELECT
177
+            DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
178
+            FROM
179
+            sequence a
180
+            WHERE
181
+            <if test="startDate == null or endDate == null">
182
+                a.rownum <![CDATA[ <= ]]> 7
183
+            </if>
184
+            <if test="startDate != null or endDate != null">
185
+                a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
186
+            </if>
187
+        ) AS temp_date
188
+        LEFT JOIN (
189
+            SELECT
190
+            COUNT(1) as activityCount,
191
+            tpvr.visit_time AS visitTime,
192
+            tpvr.activity as activity
193
+            FROM
194
+            ta_person tp
195
+            INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
196
+            where tp.person_type = #{personType}
197
+            GROUP BY tpvr.activity
198
+        ) AS temp ON temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' )
199
+    </select>
200
+
201
+    <select id="selectActiveUserCount" resultType="map">
202
+        SELECT
203
+        *
204
+        FROM
205
+        (
206
+            SELECT
207
+              <if test="dateType === 'day'">
208
+                  DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
209
+              </if>
210
+              <if test="dateType === 'week'">
211
+                  DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum WEEK ), '%Y-%m-%d' ) AS date
212
+              </if>
213
+              <if test="dateType === 'month'">
214
+                  DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum MONTH ), '%Y-%m-%d' ) AS date
215
+              </if>
216
+            FROM
217
+              sequence a
218
+            WHERE
219
+              <if test="startDate == null or endDate == null">
220
+                  a.rownum <![CDATA[ <= ]]> 7
221
+              </if>
222
+              <if test="startDate != null or endDate != null">
223
+                  a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
224
+              </if>
225
+        ) AS temp_date
226
+        LEFT JOIN (
227
+            SELECT
228
+                COUNT(1) as activity_count,
229
+                tpvr.visit_time AS visit_time
230
+            FROM
231
+               ta_person tp
232
+            where tp.person_type = #{personType}
233
+            INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
234
+        ) AS temp ON temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' )
235
+    </select>
236
+
141 237
 </mapper>