瀏覽代碼

数据统计

傅行帆 5 年之前
父節點
當前提交
a1468344d2

+ 13
- 0
src/main/java/com/huiju/estateagents/job/CustomerStatisticTimeJob.java 查看文件

@@ -11,6 +11,7 @@ import com.huiju.estateagents.service.ITaShareChildRecordService;
11 11
 import com.huiju.estateagents.service.ITaShareRecordService;
12 12
 import com.huiju.estateagents.statistic.service.ITaCustomerGenderStatisticService;
13 13
 import com.huiju.estateagents.statistic.service.ITaCustomerStatisticDailyService;
14
+import com.huiju.estateagents.statistic.service.ITaCustomerStatisticMonthlyService;
14 15
 import org.slf4j.Logger;
15 16
 import org.slf4j.LoggerFactory;
16 17
 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,6 +40,9 @@ public class CustomerStatisticTimeJob extends BaseController {
39 40
     
40 41
     @Autowired
41 42
     private ITaCustomerGenderStatisticService taCustomerGenderStatisticService;
43
+    
44
+    @Autowired
45
+    private ITaCustomerStatisticMonthlyService customerStatisticMonthlyService;
42 46
 
43 47
     /**
44 48
      *
@@ -67,6 +71,15 @@ public class CustomerStatisticTimeJob extends BaseController {
67 71
     
68 72
         //每天的到访客户性别统计并入表
69 73
         taCustomerGenderStatisticService.visiteSexStatisticDaily(nowDate);
74
+    
75
+        //每月的新增客户统计并入表,但是每天都更新
76
+        customerStatisticMonthlyService.newCustomerStatisticMonthly(nowDate);
77
+    
78
+        //每月的跟进客户统计并入表,但是每天都更新
79
+        customerStatisticMonthlyService.followUpStatisticMonthly(nowDate);
80
+    
81
+        //每月的到访客户统计并入表,但是每天都更新
82
+        customerStatisticMonthlyService.visiteStatisticMonthly(nowDate);
70 83
     }
71 84
 
72 85
 }

+ 27
- 1
src/main/java/com/huiju/estateagents/statistic/mapper/TaCustomerStatisticMonthlyMapper.java 查看文件

@@ -3,6 +3,10 @@ package com.huiju.estateagents.statistic.mapper;
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 4
 import com.huiju.estateagents.statistic.entity.TaCustomerStatisticMonthly;
5 5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+import java.time.LocalDateTime;
9
+import java.util.List;
6 10
 
7 11
 /**
8 12
  * <p>
@@ -14,5 +18,27 @@ import org.apache.ibatis.annotations.Mapper;
14 18
  */
15 19
 @Mapper
16 20
 public interface TaCustomerStatisticMonthlyMapper extends BaseMapper<TaCustomerStatisticMonthly> {
17
-
21
+	
22
+	/**
23
+	 * 获取一个月新增客户的数据插入
24
+	 * @param nowDate
25
+	 * @param status
26
+	 * @return
27
+	 */
28
+	List<TaCustomerStatisticMonthly> getNewCustomerStatisticMonthly(@Param("nowDate") LocalDateTime nowDate,@Param("status") int status);
29
+	
30
+	/**
31
+	 * 获取一个月跟进客户数据插入
32
+	 * @param nowDate
33
+	 * @return
34
+	 */
35
+	List<TaCustomerStatisticMonthly> getFollowUpStatisticMonthly(@Param("nowDate") LocalDateTime nowDate);
36
+	
37
+	/**
38
+	 * 获取一个月访问客户数据插入
39
+	 * @param nowDate
40
+	 * @param checkin
41
+	 * @return
42
+	 */
43
+	List<TaCustomerStatisticMonthly> getVisiteStatisticMonthly(@Param("nowDate") LocalDateTime nowDate,@Param("checkin") int checkin);
18 44
 }

+ 20
- 1
src/main/java/com/huiju/estateagents/statistic/service/ITaCustomerStatisticMonthlyService.java 查看文件

@@ -3,6 +3,8 @@ package com.huiju.estateagents.statistic.service;
3 3
 import com.baomidou.mybatisplus.extension.service.IService;
4 4
 import com.huiju.estateagents.statistic.entity.TaCustomerStatisticMonthly;
5 5
 
6
+import java.time.LocalDateTime;
7
+
6 8
 /**
7 9
  * <p>
8 10
  * 客户分析月统计表 小程序盘客工具客户分析 服务类
@@ -12,5 +14,22 @@ import com.huiju.estateagents.statistic.entity.TaCustomerStatisticMonthly;
12 14
  * @since 2019-11-08
13 15
  */
14 16
 public interface ITaCustomerStatisticMonthlyService extends IService<TaCustomerStatisticMonthly> {
15
-
17
+	
18
+	/**
19
+	 * 每月新增客户统计,每天都更新
20
+	 * @param nowDate
21
+	 */
22
+	void newCustomerStatisticMonthly(LocalDateTime nowDate);
23
+	
24
+	/**
25
+	 * 每月跟进客户统计,每天都更新
26
+	 * @param nowDate
27
+	 */
28
+	void followUpStatisticMonthly(LocalDateTime nowDate);
29
+	
30
+	/**
31
+	 * 每月访客客户统计,每天都更新
32
+	 * @param nowDate
33
+	 */
34
+	void visiteStatisticMonthly(LocalDateTime nowDate);
16 35
 }

+ 13
- 7
src/main/java/com/huiju/estateagents/statistic/service/impl/TaCustomerGenderStatisticServiceImpl.java 查看文件

@@ -1,5 +1,6 @@
1 1
 package com.huiju.estateagents.statistic.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3 4
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4 5
 import com.huiju.estateagents.common.CommConstant;
5 6
 import com.huiju.estateagents.statistic.entity.GenderStatistic;
@@ -37,7 +38,7 @@ public class TaCustomerGenderStatisticServiceImpl extends ServiceImpl<TaCustomer
37 38
 		//获取新增客户的男女性别比和性别数
38 39
 		List<GenderStatistic> newCustomerSexList = customerGenderStatisticMapper.getNewCustomerSexCount();
39 40
 		//批量保存
40
-		saveBatchCustomerSexData(newCustomerSexList,nowDate);
41
+		saveBatchCustomerSexData(newCustomerSexList,nowDate,CommConstant.CUSTOMER_TYPE_NEW);
41 42
 	}
42 43
 	
43 44
 	/**
@@ -50,7 +51,7 @@ public class TaCustomerGenderStatisticServiceImpl extends ServiceImpl<TaCustomer
50 51
 		//获取跟进客户的男女性别比和性别数
51 52
 		List<GenderStatistic> followUpSexList = customerGenderStatisticMapper.getFollowUpSexCount();
52 53
 		//批量保存
53
-		saveBatchCustomerSexData(followUpSexList,nowDate);
54
+		saveBatchCustomerSexData(followUpSexList,nowDate,CommConstant.CUSTOMER_TYPE_FOLLOW);
54 55
 	}
55 56
 	
56 57
 	/**
@@ -69,7 +70,7 @@ public class TaCustomerGenderStatisticServiceImpl extends ServiceImpl<TaCustomer
69 70
 			}
70 71
 		});
71 72
 		//批量保存
72
-		saveBatchCustomerSexData(newVisiteSexList,nowDate);
73
+		saveBatchCustomerSexData(newVisiteSexList,nowDate,CommConstant.CUSTOMER_TYPE_VISITE);
73 74
 	}
74 75
 	
75 76
 	/**
@@ -77,14 +78,19 @@ public class TaCustomerGenderStatisticServiceImpl extends ServiceImpl<TaCustomer
77 78
 	 * @param customerSexList
78 79
 	 * @param nowDate
79 80
 	 */
80
-	private void saveBatchCustomerSexData(List<GenderStatistic> customerSexList, LocalDateTime nowDate) {
81
+	private void saveBatchCustomerSexData(List<GenderStatistic> customerSexList, LocalDateTime nowDate,String customerType) {
82
+		//先删除在添加
83
+		QueryWrapper<TaCustomerGenderStatistic> queryWrapper = new QueryWrapper<>();
84
+		queryWrapper.eq("customer_type",customerType);
85
+		customerGenderStatisticMapper.delete(queryWrapper);
86
+		
81 87
 		List<TaCustomerGenderStatistic> list = new ArrayList<>();
82 88
 		//划分男女未知三条数据
83 89
 		customerSexList.forEach(e -> {
84 90
 			TaCustomerGenderStatistic maleCustomer = new TaCustomerGenderStatistic();
85 91
 			maleCustomer.setCreateDate(nowDate);
86 92
 			maleCustomer.setGenderType(CommConstant.SEX_MALE);
87
-			maleCustomer.setCustomerType(CommConstant.CUSTOMER_TYPE_NEW);
93
+			maleCustomer.setCustomerType(customerType);
88 94
 			maleCustomer.setCustomerNum(e.getManSum());
89 95
 			maleCustomer.setPercentage(e.getManPct());
90 96
 			maleCustomer.setOrgId(e.getOrgId());
@@ -93,7 +99,7 @@ public class TaCustomerGenderStatisticServiceImpl extends ServiceImpl<TaCustomer
93 99
 			TaCustomerGenderStatistic femaleCustomer = new TaCustomerGenderStatistic();
94 100
 			femaleCustomer.setCreateDate(nowDate);
95 101
 			femaleCustomer.setGenderType(CommConstant.SEX_FEMALE);
96
-			femaleCustomer.setCustomerType(CommConstant.CUSTOMER_TYPE_NEW);
102
+			femaleCustomer.setCustomerType(customerType);
97 103
 			femaleCustomer.setCustomerNum(e.getWomanSum());
98 104
 			femaleCustomer.setPercentage(e.getWomanPct());
99 105
 			femaleCustomer.setOrgId(e.getOrgId());
@@ -102,7 +108,7 @@ public class TaCustomerGenderStatisticServiceImpl extends ServiceImpl<TaCustomer
102 108
 			TaCustomerGenderStatistic unknownCustomer = new TaCustomerGenderStatistic();
103 109
 			unknownCustomer.setCreateDate(nowDate);
104 110
 			unknownCustomer.setGenderType(CommConstant.SEX_UNKNOWN);
105
-			unknownCustomer.setCustomerType(CommConstant.CUSTOMER_TYPE_NEW);
111
+			unknownCustomer.setCustomerType(customerType);
106 112
 			unknownCustomer.setCustomerNum(e.getUnknownSum());
107 113
 			unknownCustomer.setPercentage(e.getUnknownPct());
108 114
 			unknownCustomer.setOrgId(e.getOrgId());

+ 80
- 1
src/main/java/com/huiju/estateagents/statistic/service/impl/TaCustomerStatisticMonthlyServiceImpl.java 查看文件

@@ -1,11 +1,19 @@
1 1
 package com.huiju.estateagents.statistic.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3 4
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5
+import com.huiju.estateagents.common.CommConstant;
4 6
 import com.huiju.estateagents.statistic.entity.TaCustomerStatisticMonthly;
5 7
 import com.huiju.estateagents.statistic.mapper.TaCustomerStatisticMonthlyMapper;
6 8
 import com.huiju.estateagents.statistic.service.ITaCustomerStatisticMonthlyService;
9
+import org.springframework.beans.factory.annotation.Autowired;
7 10
 import org.springframework.stereotype.Service;
8 11
 
12
+import java.time.LocalDateTime;
13
+import java.time.format.DateTimeFormatter;
14
+import java.util.ArrayList;
15
+import java.util.List;
16
+
9 17
 /**
10 18
  * <p>
11 19
  * 客户分析月统计表 小程序盘客工具客户分析 服务实现类
@@ -16,5 +24,76 @@ import org.springframework.stereotype.Service;
16 24
  */
17 25
 @Service
18 26
 public class TaCustomerStatisticMonthlyServiceImpl extends ServiceImpl<TaCustomerStatisticMonthlyMapper, TaCustomerStatisticMonthly> implements ITaCustomerStatisticMonthlyService {
19
-
27
+	
28
+	@Autowired
29
+	private TaCustomerStatisticMonthlyMapper customerStatisticMonthlyMapper;
30
+	
31
+	/**
32
+	 * 每月新增客户统计,每天都更新
33
+	 *
34
+	 * @param nowDate
35
+	 */
36
+	@Override
37
+	public void newCustomerStatisticMonthly(LocalDateTime nowDate) {
38
+		//获取当月新增客户总数
39
+		List<TaCustomerStatisticMonthly> newCustomerMonthList = customerStatisticMonthlyMapper.getNewCustomerStatisticMonthly(nowDate,CommConstant.STATUS_NORMAL);
40
+		//批量插入
41
+		statisticMonthlySaveBatch(newCustomerMonthList,nowDate, CommConstant.CUSTOMER_TYPE_NEW);
42
+	}
43
+	
44
+	/**
45
+	 * 每月跟进客户统计,每天都更新
46
+	 *
47
+	 * @param nowDate
48
+	 */
49
+	@Override
50
+	public void followUpStatisticMonthly(LocalDateTime nowDate) {
51
+		//获取当月跟进客户总数
52
+		List<TaCustomerStatisticMonthly> followUpMonthList = customerStatisticMonthlyMapper.getFollowUpStatisticMonthly(nowDate);
53
+		statisticMonthlySaveBatch(followUpMonthList,nowDate, CommConstant.CUSTOMER_TYPE_FOLLOW);
54
+	}
55
+	
56
+	/**
57
+	 * 每月访客客户统计,每天都更新
58
+	 *
59
+	 * @param nowDate
60
+	 */
61
+	@Override
62
+	public void visiteStatisticMonthly(LocalDateTime nowDate) {
63
+		//获取当月访问客户总数
64
+		List<TaCustomerStatisticMonthly> visiteMonthList = customerStatisticMonthlyMapper.getVisiteStatisticMonthly(nowDate,CommConstant.STATUS_NORMAL);
65
+		List<TaCustomerStatisticMonthly> newVisiteMonthList = new ArrayList<>();
66
+		visiteMonthList.forEach(e -> {
67
+			if (null != e.getOrgId() && !e.getOrgId().equals("null")){
68
+				newVisiteMonthList.add(e);
69
+			}
70
+		});
71
+		statisticMonthlySaveBatch(newVisiteMonthList,nowDate, CommConstant.CUSTOMER_TYPE_FOLLOW);
72
+	}
73
+	
74
+	/**
75
+	 * 批量保存当月的统计数据
76
+	 * @param list
77
+	 * @param nowDate
78
+	 * @param customerType
79
+	 */
80
+	private void statisticMonthlySaveBatch(List<TaCustomerStatisticMonthly> list, LocalDateTime nowDate, String customerType) {
81
+		//格式化年月日
82
+		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
83
+		String todayDate = nowDate.format(formatter);
84
+		
85
+		//先删除在添加
86
+		QueryWrapper<TaCustomerStatisticMonthly> queryWrapper = new QueryWrapper<>();
87
+		queryWrapper.eq("customer_type",customerType);
88
+		queryWrapper.eq("month",todayDate);
89
+		customerStatisticMonthlyMapper.delete(queryWrapper);
90
+		
91
+		list.forEach(e -> {
92
+			e.setCreateDate(nowDate);
93
+			e.setCustomerType(customerType);
94
+			e.setMonth(todayDate);
95
+		});
96
+		//批量保存
97
+		this.saveBatch(list);
98
+	}
20 99
 }

+ 42
- 0
src/main/resources/mapper/statistic/TaCustomerStatisticMonthlyMapper.xml 查看文件

@@ -2,4 +2,46 @@
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.TaCustomerStatisticMonthlyMapper">
4 4
 
5
+    <select id="getNewCustomerStatisticMonthly"
6
+            resultType="com.huiju.estateagents.statistic.entity.TaCustomerStatisticMonthly">
7
+        SELECT
8
+            org_id,
9
+            count( customer_id ) as customer_num
10
+        FROM
11
+            ta_recommend_customer
12
+        WHERE
13
+            `STATUS` = #{status}
14
+            AND date_format( create_date, '%Y-%m' ) = date_format( #{nowDate}, '%Y-%m' )
15
+        GROUP BY
16
+            org_id
17
+    </select>
18
+
19
+    <select id="getFollowUpStatisticMonthly"
20
+            resultType="com.huiju.estateagents.statistic.entity.TaCustomerStatisticMonthly">
21
+        SELECT
22
+            org_id,
23
+            count( DISTINCT ( customer_id ) ) as customer_num
24
+        FROM
25
+            ta_customer_follow_up_record
26
+        WHERE
27
+            date_format( create_date, '%Y-%m' ) = date_format( #{nowDate}, '%Y-%m' )
28
+        GROUP BY
29
+            org_id
30
+    </select>
31
+    <select id="getVisiteStatisticMonthly"
32
+            resultType="com.huiju.estateagents.statistic.entity.TaCustomerStatisticMonthly">
33
+        SELECT
34
+            count( DISTINCT ( c.customer_id ) ) as customer_num,
35
+            c.org_id
36
+        FROM
37
+            ta_activity_dynamic_enlist t
38
+            LEFT JOIN ta_recommend_customer c ON t.person_id = c.person_id
39
+            AND t.building_id = c.building_id
40
+            AND t.org_id = c.org_id
41
+        WHERE
42
+            t.is_checkin = #{checkin}
43
+            AND date_format( t.create_date, '%Y-%m' ) = date_format( #{nowDate}, '%Y-%m' )
44
+        GROUP BY
45
+            c.org_id
46
+    </select>
5 47
 </mapper>