Browse Source

数据统计

傅行帆 5 years ago
parent
commit
ea2912aaae

+ 1
- 0
src/main/java/com/huiju/estateagents/common/CommConstant.java View File

375
     // ------- 性别 start -------
375
     // ------- 性别 start -------
376
     public static final Integer SEX_MALE = 1;
376
     public static final Integer SEX_MALE = 1;
377
     public static final Integer SEX_FEMALE = 2;
377
     public static final Integer SEX_FEMALE = 2;
378
+    public static final Integer SEX_UNKNOWN = 3;
378
     // ------- 性别 end -------
379
     // ------- 性别 end -------
379
 
380
 
380
     // ------- 推荐客户状态 start -------
381
     // ------- 推荐客户状态 start -------

+ 27
- 0
src/main/java/com/huiju/estateagents/statistic/entity/GenderStatistic.java View File

1
+package com.huiju.estateagents.statistic.entity;
2
+
3
+import lombok.Data;
4
+
5
+import java.math.BigDecimal;
6
+
7
+/**
8
+ * @author FXF
9
+ * @date 2019-11-08
10
+ */
11
+@Data
12
+public class GenderStatistic {
13
+
14
+	private Integer orgId;
15
+	
16
+	private Integer manSum;
17
+	
18
+	private BigDecimal manPct;
19
+	
20
+	private Integer womanSum;
21
+	
22
+	private BigDecimal womanPct;
23
+	
24
+	private Integer unknownSum;
25
+	
26
+	private BigDecimal unknownPct;
27
+}

+ 5
- 0
src/main/java/com/huiju/estateagents/statistic/entity/TaCustomerFollowUpRecord.java View File

59
      * 跟进人ID
59
      * 跟进人ID
60
      */
60
      */
61
     private Integer followerId;
61
     private Integer followerId;
62
+    
63
+    /**
64
+     * 客户性别
65
+     */
66
+    private Integer customerSex;
62
 }
67
 }

+ 2
- 1
src/main/java/com/huiju/estateagents/statistic/entity/TaCustomerGenderStatistic.java View File

7
 import lombok.experimental.Accessors;
7
 import lombok.experimental.Accessors;
8
 
8
 
9
 import java.io.Serializable;
9
 import java.io.Serializable;
10
+import java.math.BigDecimal;
10
 import java.time.LocalDateTime;
11
 import java.time.LocalDateTime;
11
 
12
 
12
 /**
13
 /**
48
     /**
49
     /**
49
      * 百分比 百分比
50
      * 百分比 百分比
50
      */
51
      */
51
-    private Integer percentage;
52
+    private BigDecimal percentage;
52
 
53
 
53
     /**
54
     /**
54
      * 创建时间
55
      * 创建时间

+ 22
- 1
src/main/java/com/huiju/estateagents/statistic/mapper/TaCustomerGenderStatisticMapper.java View File

1
 package com.huiju.estateagents.statistic.mapper;
1
 package com.huiju.estateagents.statistic.mapper;
2
 
2
 
3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.huiju.estateagents.statistic.entity.GenderStatistic;
4
 import com.huiju.estateagents.statistic.entity.TaCustomerGenderStatistic;
5
 import com.huiju.estateagents.statistic.entity.TaCustomerGenderStatistic;
5
 import org.apache.ibatis.annotations.Mapper;
6
 import org.apache.ibatis.annotations.Mapper;
6
 
7
 
8
+import java.util.List;
9
+import java.util.Map;
10
+
7
 /**
11
 /**
8
  * <p>
12
  * <p>
9
  * 客户分析性别统计表 小程序盘客工具客户分析 Mapper 接口
13
  * 客户分析性别统计表 小程序盘客工具客户分析 Mapper 接口
14
  */
18
  */
15
 @Mapper
19
 @Mapper
16
 public interface TaCustomerGenderStatisticMapper extends BaseMapper<TaCustomerGenderStatistic> {
20
 public interface TaCustomerGenderStatisticMapper extends BaseMapper<TaCustomerGenderStatistic> {
17
-
21
+	
22
+	/**
23
+	 * 获取新增客户的男女性别比
24
+	 * @return
25
+	 */
26
+	List<GenderStatistic> getNewCustomerSexCount();
27
+	
28
+	/**
29
+	 * 获取跟进客户的男女性别比
30
+	 * @return
31
+	 */
32
+	List<GenderStatistic> getFollowUpSexCount();
33
+	
34
+	/**
35
+	 * 获取到访客户的男女性别比
36
+	 * @return
37
+	 */
38
+	List<GenderStatistic> getVisiteSexCount();
18
 }
39
 }

+ 3
- 0
src/main/java/com/huiju/estateagents/statistic/service/ITaCustomerGenderStatisticService.java View File

17
 	
17
 	
18
 	/**
18
 	/**
19
 	 * 每天的新增客户性别统计
19
 	 * 每天的新增客户性别统计
20
+	 *
20
 	 * @param nowDate
21
 	 * @param nowDate
21
 	 */
22
 	 */
22
 	void newCustomerSexStatisticDaily(LocalDateTime nowDate);
23
 	void newCustomerSexStatisticDaily(LocalDateTime nowDate);
23
 	
24
 	
24
 	/**
25
 	/**
25
 	 * 每天的跟进客户性别统计
26
 	 * 每天的跟进客户性别统计
27
+	 *
26
 	 * @param nowDate
28
 	 * @param nowDate
27
 	 */
29
 	 */
28
 	void followUpSexStatisticDaily(LocalDateTime nowDate);
30
 	void followUpSexStatisticDaily(LocalDateTime nowDate);
29
 	
31
 	
30
 	/**
32
 	/**
31
 	 * 每天的到访客户性别统计
33
 	 * 每天的到访客户性别统计
34
+	 *
32
 	 * @param nowDate
35
 	 * @param nowDate
33
 	 */
36
 	 */
34
 	void visiteSexStatisticDaily(LocalDateTime nowDate);
37
 	void visiteSexStatisticDaily(LocalDateTime nowDate);

+ 61
- 2
src/main/java/com/huiju/estateagents/statistic/service/impl/TaCustomerGenderStatisticServiceImpl.java View File

1
 package com.huiju.estateagents.statistic.service.impl;
1
 package com.huiju.estateagents.statistic.service.impl;
2
 
2
 
3
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
3
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
+import com.huiju.estateagents.common.CommConstant;
5
+import com.huiju.estateagents.statistic.entity.GenderStatistic;
4
 import com.huiju.estateagents.statistic.entity.TaCustomerGenderStatistic;
6
 import com.huiju.estateagents.statistic.entity.TaCustomerGenderStatistic;
5
 import com.huiju.estateagents.statistic.mapper.TaCustomerGenderStatisticMapper;
7
 import com.huiju.estateagents.statistic.mapper.TaCustomerGenderStatisticMapper;
6
 import com.huiju.estateagents.statistic.service.ITaCustomerGenderStatisticService;
8
 import com.huiju.estateagents.statistic.service.ITaCustomerGenderStatisticService;
8
 import org.springframework.stereotype.Service;
10
 import org.springframework.stereotype.Service;
9
 
11
 
10
 import java.time.LocalDateTime;
12
 import java.time.LocalDateTime;
13
+import java.util.ArrayList;
14
+import java.util.List;
11
 
15
 
12
 /**
16
 /**
13
  * <p>
17
  * <p>
30
 	 */
34
 	 */
31
 	@Override
35
 	@Override
32
 	public void newCustomerSexStatisticDaily(LocalDateTime nowDate) {
36
 	public void newCustomerSexStatisticDaily(LocalDateTime nowDate) {
33
-	
37
+		//获取新增客户的男女性别比和性别数
38
+		List<GenderStatistic> newCustomerSexList = customerGenderStatisticMapper.getNewCustomerSexCount();
39
+		//批量保存
40
+		saveBatchCustomerSexData(newCustomerSexList,nowDate);
34
 	}
41
 	}
35
 	
42
 	
36
 	/**
43
 	/**
40
 	 */
47
 	 */
41
 	@Override
48
 	@Override
42
 	public void followUpSexStatisticDaily(LocalDateTime nowDate) {
49
 	public void followUpSexStatisticDaily(LocalDateTime nowDate) {
43
-	
50
+		//获取跟进客户的男女性别比和性别数
51
+		List<GenderStatistic> followUpSexList = customerGenderStatisticMapper.getFollowUpSexCount();
52
+		//批量保存
53
+		saveBatchCustomerSexData(followUpSexList,nowDate);
44
 	}
54
 	}
45
 	
55
 	
46
 	/**
56
 	/**
50
 	 */
60
 	 */
51
 	@Override
61
 	@Override
52
 	public void visiteSexStatisticDaily(LocalDateTime nowDate) {
62
 	public void visiteSexStatisticDaily(LocalDateTime nowDate) {
63
+		//获取到访客户的男女性别比和性别数
64
+		List<GenderStatistic> visiteSexList = customerGenderStatisticMapper.getVisiteSexCount();
65
+		List<GenderStatistic> newVisiteSexList = new ArrayList<>();
66
+		visiteSexList.forEach(e -> {
67
+			if (null != e.getOrgId() && !e.getOrgId().equals("null")){
68
+				newVisiteSexList.add(e);
69
+			}
70
+		});
71
+		//批量保存
72
+		saveBatchCustomerSexData(newVisiteSexList,nowDate);
73
+	}
53
 	
74
 	
75
+	/**
76
+	 * 批量保存性别数据
77
+	 * @param customerSexList
78
+	 * @param nowDate
79
+	 */
80
+	private void saveBatchCustomerSexData(List<GenderStatistic> customerSexList, LocalDateTime nowDate) {
81
+		List<TaCustomerGenderStatistic> list = new ArrayList<>();
82
+		//划分男女未知三条数据
83
+		customerSexList.forEach(e -> {
84
+			TaCustomerGenderStatistic maleCustomer = new TaCustomerGenderStatistic();
85
+			maleCustomer.setCreateDate(nowDate);
86
+			maleCustomer.setGenderType(CommConstant.SEX_MALE);
87
+			maleCustomer.setCustomerType(CommConstant.CUSTOMER_TYPE_NEW);
88
+			maleCustomer.setCustomerNum(e.getManSum());
89
+			maleCustomer.setPercentage(e.getManPct());
90
+			maleCustomer.setOrgId(e.getOrgId());
91
+			list.add(maleCustomer);
92
+			
93
+			TaCustomerGenderStatistic femaleCustomer = new TaCustomerGenderStatistic();
94
+			femaleCustomer.setCreateDate(nowDate);
95
+			femaleCustomer.setGenderType(CommConstant.SEX_FEMALE);
96
+			femaleCustomer.setCustomerType(CommConstant.CUSTOMER_TYPE_NEW);
97
+			femaleCustomer.setCustomerNum(e.getWomanSum());
98
+			femaleCustomer.setPercentage(e.getWomanPct());
99
+			femaleCustomer.setOrgId(e.getOrgId());
100
+			list.add(femaleCustomer);
101
+			
102
+			TaCustomerGenderStatistic unknownCustomer = new TaCustomerGenderStatistic();
103
+			unknownCustomer.setCreateDate(nowDate);
104
+			unknownCustomer.setGenderType(CommConstant.SEX_UNKNOWN);
105
+			unknownCustomer.setCustomerType(CommConstant.CUSTOMER_TYPE_NEW);
106
+			unknownCustomer.setCustomerNum(e.getUnknownSum());
107
+			unknownCustomer.setPercentage(e.getUnknownPct());
108
+			unknownCustomer.setOrgId(e.getOrgId());
109
+			list.add(unknownCustomer);
110
+		});
111
+		//批量插入
112
+		this.saveBatch(list);
54
 	}
113
 	}
55
 }
114
 }

+ 56
- 0
src/main/resources/mapper/statistic/TaCustomerGenderStatisticMapper.xml View File

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.huiju.estateagents.statistic.mapper.TaCustomerGenderStatisticMapper">
3
 <mapper namespace="com.huiju.estateagents.statistic.mapper.TaCustomerGenderStatisticMapper">
4
 
4
 
5
+    <select id="getNewCustomerSexCount" resultType="com.huiju.estateagents.statistic.entity.GenderStatistic">
6
+        SELECT
7
+            org_id,
8
+            sum(if(sex = 1,1,0)) as man_sum,
9
+            sum(if(sex = 1,1,0))/count(*) as man_pct,
10
+            sum(if(sex = 2,1,0)) as woman_sum,
11
+            sum(if(sex = 2,1,0))/count(*) as woman_pct,
12
+            sum(if(sex != 1 and sex != 2,1,0)) as unknown_sum,
13
+            sum(if(sex != 1 and sex != 2,1,0))/count(*) as unknown_pct
14
+        FROM
15
+            ta_recommend_customer
16
+        WHERE
17
+            `STATUS` = 1
18
+            GROUP BY org_id
19
+    </select>
20
+    <select id="getFollowUpSexCount" resultType="com.huiju.estateagents.statistic.entity.GenderStatistic">
21
+        SELECT
22
+            t.org_id,
23
+            sum( IF ( t.customer_sex = 1, 1, 0 ) ) AS manSum,
24
+            sum( IF ( t.customer_sex = 1, 1, 0 ) ) / count( * ) AS manPct,
25
+            sum( IF ( t.customer_sex = 2, 1, 0 ) ) AS womanSum,
26
+            sum( IF ( t.customer_sex = 2, 1, 0 ) ) / count( * ) AS womanPct,
27
+            sum( IF ( t.customer_sex != 1 AND t.customer_sex != 2, 1, 0 ) ) AS unknownSum,
28
+            sum( IF ( t.customer_sex != 1 AND t.customer_sex != 2, 1, 0 ) ) / count( * ) AS unknownPct
29
+        FROM
30
+            ( SELECT * FROM ta_customer_follow_up_record GROUP BY customer_id ) t
31
+        GROUP BY
32
+            t.org_id
33
+    </select>
34
+    <select id="getVisiteSexCount" resultType="com.huiju.estateagents.statistic.entity.GenderStatistic">
35
+        SELECT
36
+            d.org_id,
37
+            sum( IF ( d.sex = 1, 1, 0 ) ) AS manSum,
38
+            sum( IF ( d.sex = 1, 1, 0 ) ) / count( * ) AS manPct,
39
+            sum( IF ( d.sex = 2, 1, 0 ) ) AS womanSum,
40
+            sum( IF ( d.sex = 2, 1, 0 ) ) / count( * ) AS womanPct,
41
+            sum( IF ( d.sex != 1 AND d.sex != 2, 1, 0 ) ) AS unknownSum,
42
+            sum( IF ( d.sex != 1 AND d.sex != 2, 1, 0 ) ) / count( * ) AS unknownPct
43
+        FROM
44
+            (
45
+                SELECT
46
+                    t.enlist_id,
47
+                    c.*
48
+                FROM
49
+                    ta_activity_dynamic_enlist t
50
+                    LEFT JOIN ta_recommend_customer c ON t.person_id = c.person_id
51
+                    AND t.building_id = c.building_id
52
+                    AND t.org_id = c.org_id
53
+                WHERE
54
+                    t.is_checkin = 1
55
+                GROUP BY
56
+                    c.customer_id
57
+            ) d
58
+        GROUP BY
59
+            d.org_id
60
+    </select>
5
 </mapper>
61
 </mapper>