浏览代码

* bug fix

顾绍勇 5 年前
父节点
当前提交
18ddd16a17

+ 44
- 0
src/main/java/com/huiju/estateagents/bo/request/ActivityStatisticResponseBO.java 查看文件

@@ -0,0 +1,44 @@
1
+package com.huiju.estateagents.bo.request;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 活动统计返回实体
7
+ *
8
+ * @author gusy
9
+ * @date 2020/4/26 13:15
10
+ */
11
+@Data
12
+public class ActivityStatisticResponseBO {
13
+
14
+    /**
15
+     * 活动分享人数
16
+     */
17
+    private Integer sharePersons;
18
+
19
+    /**
20
+     * 活动分享次数
21
+     */
22
+    private Integer shareNum;
23
+
24
+    /**
25
+     * 活动访问人数
26
+     */
27
+    private Integer visitPersons;
28
+
29
+    /**
30
+     * 活动访问次数
31
+     */
32
+    private Integer visitNum;
33
+
34
+    /**
35
+     * 分享新增用户
36
+     */
37
+    private Integer newPersons;
38
+
39
+    /**
40
+     * 分享新增客户
41
+     */
42
+    private Integer newCustomers;
43
+
44
+}

+ 65
- 0
src/main/java/com/huiju/estateagents/controller/ActivityManageController.java 查看文件

@@ -0,0 +1,65 @@
1
+package com.huiju.estateagents.controller;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.huiju.estateagents.base.BaseController;
5
+import com.huiju.estateagents.base.ResponseBean;
6
+import com.huiju.estateagents.service.impl.ActivityManageServiceImpl;
7
+import org.apache.commons.lang3.StringUtils;
8
+import org.slf4j.Logger;
9
+import org.slf4j.LoggerFactory;
10
+import org.springframework.beans.factory.annotation.Autowired;
11
+import org.springframework.stereotype.Controller;
12
+import org.springframework.web.bind.annotation.RequestMapping;
13
+import org.springframework.web.bind.annotation.RequestMethod;
14
+import org.springframework.web.bind.annotation.ResponseBody;
15
+
16
+import javax.servlet.http.HttpServletRequest;
17
+
18
+/**
19
+ * 活动管理
20
+ *
21
+ * @author gusy
22
+ * @date 2020/4/26 10:42
23
+ */
24
+@Controller
25
+@RequestMapping("/api")
26
+public class ActivityManageController extends BaseController {
27
+
28
+    private Logger logger = LoggerFactory.getLogger(ActivityManageController.class);
29
+
30
+    @Autowired
31
+    private ActivityManageServiceImpl activityManageService;
32
+
33
+    /**
34
+     * 根据类型获取统计数据
35
+     *
36
+     * @param type 报名活动:activity、
37
+     *             H5:h5、
38
+     *             助力:help、
39
+     *             拼团:group、
40
+     *             直播:live
41
+     * @return
42
+     */
43
+    @RequestMapping(value = "/admin/activityManage/getStatisticData", method = RequestMethod.GET)
44
+    @ResponseBody
45
+    public ResponseBean getStatisticDataByType(String type, String id, HttpServletRequest request) {
46
+        logger.info("getStatisticDataByType 接收参数:type:{},id:{}", type, id);
47
+
48
+        ResponseBean responseBean = new ResponseBean();
49
+
50
+        // 校验参数
51
+        if (StringUtils.isBlank(type) || StringUtils.isBlank(id)) {
52
+            responseBean.addError("参数错误");
53
+            return responseBean;
54
+        }
55
+
56
+        try {
57
+            responseBean = activityManageService.getStatisticDataByType(type, id,getOrgId(request));
58
+            logger.info("getStatisticDataByType 返回结果:{}", JSONObject.toJSONString(responseBean));
59
+        } catch (Exception e) {
60
+            logger.error("异常:", e);
61
+            responseBean.addError(e.getMessage());
62
+        }
63
+        return responseBean;
64
+    }
65
+}

+ 25
- 0
src/main/java/com/huiju/estateagents/mapper/ActivityManageMapper.java 查看文件

@@ -0,0 +1,25 @@
1
+package com.huiju.estateagents.mapper;
2
+
3
+import com.huiju.estateagents.bo.request.ActivityStatisticResponseBO;
4
+import org.apache.ibatis.annotations.Mapper;
5
+import org.apache.ibatis.annotations.Param;
6
+import org.springframework.stereotype.Component;
7
+
8
+/**
9
+ * @author gusy
10
+ * @date 2020/4/26 11:16
11
+ */
12
+@Component
13
+@Mapper
14
+public interface ActivityManageMapper {
15
+
16
+    /**
17
+     * 获取活动统计数据
18
+     *
19
+     * @return
20
+     */
21
+    ActivityStatisticResponseBO getStatisticDataByType(@Param("type") String type,
22
+                                                       @Param("id") String id,
23
+                                                       @Param("orgId") Integer orgId);
24
+
25
+}

+ 1
- 0
src/main/java/com/huiju/estateagents/mapper/TaBuildingDynamicMapper.java 查看文件

@@ -3,6 +3,7 @@ package com.huiju.estateagents.mapper;
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.huiju.estateagents.bo.request.ActivityStatisticResponseBO;
6 7
 import com.huiju.estateagents.entity.TaBuildingDynamic;
7 8
 import com.huiju.estateagents.entity.TaPersonBuilding;
8 9
 import org.apache.ibatis.annotations.Mapper;

+ 27
- 0
src/main/java/com/huiju/estateagents/service/IActivityManageService.java 查看文件

@@ -0,0 +1,27 @@
1
+package com.huiju.estateagents.service;
2
+
3
+import com.huiju.estateagents.base.ResponseBean;
4
+import com.huiju.estateagents.bo.request.ActivityStatisticResponseBO;
5
+import com.huiju.estateagents.mapper.ActivityManageMapper;
6
+import com.huiju.estateagents.service.impl.ActivityManageServiceImpl;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.stereotype.Service;
9
+
10
+/**
11
+ * @author gusy
12
+ * @date 2020/4/26 11:14
13
+ */
14
+@Service
15
+public class IActivityManageService implements ActivityManageServiceImpl {
16
+
17
+    @Autowired
18
+    private ActivityManageMapper activityManageMapper;
19
+
20
+    @Override
21
+    public ResponseBean getStatisticDataByType(String type, String id,Integer orgId) {
22
+        ResponseBean responseBean = new ResponseBean();
23
+        ActivityStatisticResponseBO responseBO = activityManageMapper.getStatisticDataByType(type, id,orgId);
24
+        responseBean.addSuccess(responseBO);
25
+        return responseBean;
26
+    }
27
+}

+ 12
- 0
src/main/java/com/huiju/estateagents/service/impl/ActivityManageServiceImpl.java 查看文件

@@ -0,0 +1,12 @@
1
+package com.huiju.estateagents.service.impl;
2
+
3
+import com.huiju.estateagents.base.ResponseBean;
4
+
5
+/**
6
+ * @author gusy
7
+ * @date 2020/4/26 11:13
8
+ */
9
+public interface ActivityManageServiceImpl {
10
+
11
+    ResponseBean getStatisticDataByType(String type,String id,Integer orgId);
12
+}

+ 183
- 0
src/main/resources/mapper/ActivityManageMapper.xml 查看文件

@@ -0,0 +1,183 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.huiju.estateagents.mapper.ActivityManageMapper">
4
+
5
+    <select id = "getStatisticDataByType" resultType="com.huiju.estateagents.bo.request.ActivityStatisticResponseBO">
6
+      select
7
+        -- 活动分享人数
8
+        (SELECT count(DISTINCT b.person_id) FROM ta_share_count b
9
+        WHERE b.org_id = a.org_id
10
+            <choose>
11
+                <when test=" type == 'live'">
12
+                    AND b.tagert_type like concat('%',a.target_type,'%')
13
+                </when>
14
+                <otherwise>
15
+                    AND b.tagert_type = a.target_type
16
+                </otherwise>
17
+            </choose>
18
+            AND b.be_share = a.target_id
19
+        ) as share_persons,
20
+
21
+        -- 活动分享次数
22
+        (SELECT count(*) FROM ta_share_count c
23
+        WHERE c.org_id = a.org_id
24
+            <choose>
25
+                <when test=" type == 'live'">
26
+                    AND c.tagert_type like concat('%',a.target_type,'%')
27
+                </when>
28
+                <otherwise>
29
+                    AND c.tagert_type = a.target_type
30
+                </otherwise>
31
+            </choose>
32
+            AND c.be_share = a.target_id
33
+        ) as share_num,
34
+
35
+        -- 活动访问人数
36
+        (select count( DISTINCT d.person_id ) from ta_person_visit_record d
37
+        WHERE d.org_id = a.org_id
38
+            <choose>
39
+                <when test=" type == 'live'">
40
+                    AND d.target_type like concat('%',REPLACE(a.target_type, 'activity', 'dynamic'),'%')
41
+                </when>
42
+                <otherwise>
43
+                    AND d.target_type = REPLACE(a.target_type, 'activity', 'dynamic')
44
+                </otherwise>
45
+            </choose>
46
+            AND d.target_id = a.target_id
47
+            AND d.`event` = 'detail'
48
+        ) as visit_persons,
49
+
50
+        -- 活动访问次数
51
+        (select count(*) from ta_person_visit_record e
52
+        WHERE e.org_id = a.org_id
53
+            <choose>
54
+                <when test=" type == 'live'">
55
+                    AND e.target_type like concat('%',REPLACE(a.target_type, 'activity', 'dynamic'),'%')
56
+                </when>
57
+                <otherwise>
58
+                    AND e.target_type = REPLACE(a.target_type, 'activity', 'dynamic')
59
+                </otherwise>
60
+            </choose>
61
+            AND e.target_id = a.target_id
62
+            AND e.`event` = 'detail'
63
+        ) as visit_num,
64
+
65
+        -- 分享新增用户
66
+        (select count(*) from ta_share_person_from f
67
+        where	f.org_id = a.org_id
68
+        <choose>
69
+            <when test=" type == 'live'">
70
+                AND f.target_type = concat('%',REPLACE(a.target_type, 'activity', 'dynamic'), '_share%')
71
+            </when>
72
+            <otherwise>
73
+                AND f.target_type = concat(REPLACE(a.target_type, 'activity', 'dynamic'), '_share')
74
+            </otherwise>
75
+        </choose>
76
+        AND f.target_id = a.target_id
77
+        AND f.`status` > 0
78
+        AND f.is_first_time = 1
79
+        ) as new_persons,
80
+
81
+        -- 分享新增客户
82
+        (select count(*) from ta_share_person_from g
83
+        inner join ta_person h on h.person_id = g.person_id
84
+        where	g.org_id = a.org_id
85
+        <choose>
86
+            <when test=" type == 'live'">
87
+                AND g.target_type = concat('%',REPLACE(a.target_type, 'activity', 'dynamic'), '_share%')
88
+            </when>
89
+            <otherwise>
90
+                AND g.target_type = concat(REPLACE(a.target_type, 'activity', 'dynamic'), '_share')
91
+            </otherwise>
92
+        </choose>
93
+        AND g.target_id = a.target_id
94
+        AND g.`status` > 0
95
+        AND g.is_first_time = 1
96
+        AND h.phone is not null
97
+        ) as new_customers
98
+
99
+        from (
100
+            <if test=" type == 'activity' ">
101
+                SELECT
102
+                    t.org_id,
103
+                    t.building_id,
104
+                    s.building_name,
105
+                    t.dynamic_id AS target_id,
106
+                    t.title AS target_name,
107
+                    'activity' AS target_type
108
+                FROM
109
+                    ta_building_dynamic t
110
+                LEFT JOIN ta_building s ON s.building_id = t.building_id
111
+                WHERE
112
+                  t.`status` > - 1
113
+                  AND t.dynamic_id = #{id}
114
+            </if>
115
+
116
+            <if test=" type == 'h5' " >
117
+                    SELECT
118
+                    t.org_id,
119
+                    t.building_id,
120
+                    s.building_name,
121
+                    t.drainage_id AS target_id,
122
+                    t.`name` AS target_name,
123
+                    'h5' AS target_type
124
+                FROM
125
+                  ta_drainage t
126
+                LEFT JOIN ta_building s ON s.building_id = t.building_id
127
+                WHERE
128
+                  t.`status` > - 1
129
+                  AND t.drainage_id = #{id}
130
+            </if>
131
+
132
+            <if test=" type == 'help' ">
133
+                SELECT
134
+                    t.org_id,
135
+                    t.building_id,
136
+                    s.building_name,
137
+                    t.help_activity_id AS target_id,
138
+                    t.title AS target_name,
139
+                    'help' AS target_type
140
+                FROM
141
+                    ta_help_activity t
142
+                LEFT JOIN ta_building s ON s.building_id = t.building_id
143
+                WHERE
144
+                    t.`status` > - 1
145
+                    AND t.help_activity_id = #{id}
146
+            </if>
147
+
148
+            <if test=" type == 'group' ">
149
+                SELECT
150
+                    t.org_id,
151
+                    t.building_id,
152
+                    s.building_name,
153
+                    t.group_activity_id AS target_id,
154
+                    t.activity_name AS target_name,
155
+                    'group' AS target_type
156
+                FROM
157
+                    ta_share_activity t
158
+                LEFT JOIN ta_building s ON s.building_id = t.building_id
159
+                WHERE
160
+                    t.`status` > - 1
161
+                    AND t.group_activity_id = #{id}
162
+            </if>
163
+
164
+            <if test=" type == 'live' ">
165
+                SELECT
166
+                    t.org_id,
167
+                    t.building_id,
168
+                    s.building_name,
169
+                    t.live_activity_id AS target_id,
170
+                    t.live_activity_title AS target_name,
171
+                    'live' AS target_type
172
+                FROM
173
+                    ta_live_activity t
174
+                LEFT JOIN ta_building s ON s.building_id = t.building_id
175
+                WHERE
176
+                    t.`status` > -1
177
+                    AND t.live_activity_id = #{id}
178
+                    AND t.org_id = #{orgId}
179
+            </if>
180
+        ) a
181
+    </select>
182
+
183
+</mapper>

+ 0
- 1
src/main/resources/mapper/TaBuildingDynamicMapper.xml 查看文件

@@ -190,5 +190,4 @@
190 190
         from ta_building_dynamic
191 191
         where org_id = #{orgId}
192 192
     </select>
193
-
194 193
 </mapper>