傅行帆 преди 5 години
родител
ревизия
ea2912aaae

+ 1
- 0
src/main/java/com/huiju/estateagents/common/CommConstant.java Целия файл

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

+ 27
- 0
src/main/java/com/huiju/estateagents/statistic/entity/GenderStatistic.java Целия файл

@@ -0,0 +1,27 @@
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 Целия файл

@@ -59,4 +59,9 @@ public class TaCustomerFollowUpRecord implements Serializable {
59 59
      * 跟进人ID
60 60
      */
61 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 Целия файл

@@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode;
7 7
 import lombok.experimental.Accessors;
8 8
 
9 9
 import java.io.Serializable;
10
+import java.math.BigDecimal;
10 11
 import java.time.LocalDateTime;
11 12
 
12 13
 /**
@@ -48,7 +49,7 @@ public class TaCustomerGenderStatistic implements Serializable {
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 Целия файл

@@ -1,9 +1,13 @@
1 1
 package com.huiju.estateagents.statistic.mapper;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.huiju.estateagents.statistic.entity.GenderStatistic;
4 5
 import com.huiju.estateagents.statistic.entity.TaCustomerGenderStatistic;
5 6
 import org.apache.ibatis.annotations.Mapper;
6 7
 
8
+import java.util.List;
9
+import java.util.Map;
10
+
7 11
 /**
8 12
  * <p>
9 13
  * 客户分析性别统计表 小程序盘客工具客户分析 Mapper 接口
@@ -14,5 +18,22 @@ import org.apache.ibatis.annotations.Mapper;
14 18
  */
15 19
 @Mapper
16 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 Целия файл

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

+ 61
- 2
src/main/java/com/huiju/estateagents/statistic/service/impl/TaCustomerGenderStatisticServiceImpl.java Целия файл

@@ -1,6 +1,8 @@
1 1
 package com.huiju.estateagents.statistic.service.impl;
2 2
 
3 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 6
 import com.huiju.estateagents.statistic.entity.TaCustomerGenderStatistic;
5 7
 import com.huiju.estateagents.statistic.mapper.TaCustomerGenderStatisticMapper;
6 8
 import com.huiju.estateagents.statistic.service.ITaCustomerGenderStatisticService;
@@ -8,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
8 10
 import org.springframework.stereotype.Service;
9 11
 
10 12
 import java.time.LocalDateTime;
13
+import java.util.ArrayList;
14
+import java.util.List;
11 15
 
12 16
 /**
13 17
  * <p>
@@ -30,7 +34,10 @@ public class TaCustomerGenderStatisticServiceImpl extends ServiceImpl<TaCustomer
30 34
 	 */
31 35
 	@Override
32 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,7 +47,10 @@ public class TaCustomerGenderStatisticServiceImpl extends ServiceImpl<TaCustomer
40 47
 	 */
41 48
 	@Override
42 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,6 +60,55 @@ public class TaCustomerGenderStatisticServiceImpl extends ServiceImpl<TaCustomer
50 60
 	 */
51 61
 	@Override
52 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 Целия файл

@@ -2,4 +2,60 @@
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 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 61
 </mapper>