傅行帆 пре 5 година
родитељ
комит
a1468344d2

+ 13
- 0
src/main/java/com/huiju/estateagents/job/CustomerStatisticTimeJob.java Прегледај датотеку

11
 import com.huiju.estateagents.service.ITaShareRecordService;
11
 import com.huiju.estateagents.service.ITaShareRecordService;
12
 import com.huiju.estateagents.statistic.service.ITaCustomerGenderStatisticService;
12
 import com.huiju.estateagents.statistic.service.ITaCustomerGenderStatisticService;
13
 import com.huiju.estateagents.statistic.service.ITaCustomerStatisticDailyService;
13
 import com.huiju.estateagents.statistic.service.ITaCustomerStatisticDailyService;
14
+import com.huiju.estateagents.statistic.service.ITaCustomerStatisticMonthlyService;
14
 import org.slf4j.Logger;
15
 import org.slf4j.Logger;
15
 import org.slf4j.LoggerFactory;
16
 import org.slf4j.LoggerFactory;
16
 import org.springframework.beans.factory.annotation.Autowired;
17
 import org.springframework.beans.factory.annotation.Autowired;
39
     
40
     
40
     @Autowired
41
     @Autowired
41
     private ITaCustomerGenderStatisticService taCustomerGenderStatisticService;
42
     private ITaCustomerGenderStatisticService taCustomerGenderStatisticService;
43
+    
44
+    @Autowired
45
+    private ITaCustomerStatisticMonthlyService customerStatisticMonthlyService;
42
 
46
 
43
     /**
47
     /**
44
      *
48
      *
67
     
71
     
68
         //每天的到访客户性别统计并入表
72
         //每天的到访客户性别统计并入表
69
         taCustomerGenderStatisticService.visiteSexStatisticDaily(nowDate);
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
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
 import com.huiju.estateagents.statistic.entity.TaCustomerStatisticMonthly;
4
 import com.huiju.estateagents.statistic.entity.TaCustomerStatisticMonthly;
5
 import org.apache.ibatis.annotations.Mapper;
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
  * <p>
12
  * <p>
14
  */
18
  */
15
 @Mapper
19
 @Mapper
16
 public interface TaCustomerStatisticMonthlyMapper extends BaseMapper<TaCustomerStatisticMonthly> {
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
 import com.baomidou.mybatisplus.extension.service.IService;
3
 import com.baomidou.mybatisplus.extension.service.IService;
4
 import com.huiju.estateagents.statistic.entity.TaCustomerStatisticMonthly;
4
 import com.huiju.estateagents.statistic.entity.TaCustomerStatisticMonthly;
5
 
5
 
6
+import java.time.LocalDateTime;
7
+
6
 /**
8
 /**
7
  * <p>
9
  * <p>
8
  * 客户分析月统计表 小程序盘客工具客户分析 服务类
10
  * 客户分析月统计表 小程序盘客工具客户分析 服务类
12
  * @since 2019-11-08
14
  * @since 2019-11-08
13
  */
15
  */
14
 public interface ITaCustomerStatisticMonthlyService extends IService<TaCustomerStatisticMonthly> {
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
 package com.huiju.estateagents.statistic.service.impl;
1
 package com.huiju.estateagents.statistic.service.impl;
2
 
2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
 import com.huiju.estateagents.common.CommConstant;
5
 import com.huiju.estateagents.common.CommConstant;
5
 import com.huiju.estateagents.statistic.entity.GenderStatistic;
6
 import com.huiju.estateagents.statistic.entity.GenderStatistic;
37
 		//获取新增客户的男女性别比和性别数
38
 		//获取新增客户的男女性别比和性别数
38
 		List<GenderStatistic> newCustomerSexList = customerGenderStatisticMapper.getNewCustomerSexCount();
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
 		//获取跟进客户的男女性别比和性别数
51
 		//获取跟进客户的男女性别比和性别数
51
 		List<GenderStatistic> followUpSexList = customerGenderStatisticMapper.getFollowUpSexCount();
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
 			}
70
 			}
70
 		});
71
 		});
71
 		//批量保存
72
 		//批量保存
72
-		saveBatchCustomerSexData(newVisiteSexList,nowDate);
73
+		saveBatchCustomerSexData(newVisiteSexList,nowDate,CommConstant.CUSTOMER_TYPE_VISITE);
73
 	}
74
 	}
74
 	
75
 	
75
 	/**
76
 	/**
77
 	 * @param customerSexList
78
 	 * @param customerSexList
78
 	 * @param nowDate
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
 		List<TaCustomerGenderStatistic> list = new ArrayList<>();
87
 		List<TaCustomerGenderStatistic> list = new ArrayList<>();
82
 		//划分男女未知三条数据
88
 		//划分男女未知三条数据
83
 		customerSexList.forEach(e -> {
89
 		customerSexList.forEach(e -> {
84
 			TaCustomerGenderStatistic maleCustomer = new TaCustomerGenderStatistic();
90
 			TaCustomerGenderStatistic maleCustomer = new TaCustomerGenderStatistic();
85
 			maleCustomer.setCreateDate(nowDate);
91
 			maleCustomer.setCreateDate(nowDate);
86
 			maleCustomer.setGenderType(CommConstant.SEX_MALE);
92
 			maleCustomer.setGenderType(CommConstant.SEX_MALE);
87
-			maleCustomer.setCustomerType(CommConstant.CUSTOMER_TYPE_NEW);
93
+			maleCustomer.setCustomerType(customerType);
88
 			maleCustomer.setCustomerNum(e.getManSum());
94
 			maleCustomer.setCustomerNum(e.getManSum());
89
 			maleCustomer.setPercentage(e.getManPct());
95
 			maleCustomer.setPercentage(e.getManPct());
90
 			maleCustomer.setOrgId(e.getOrgId());
96
 			maleCustomer.setOrgId(e.getOrgId());
93
 			TaCustomerGenderStatistic femaleCustomer = new TaCustomerGenderStatistic();
99
 			TaCustomerGenderStatistic femaleCustomer = new TaCustomerGenderStatistic();
94
 			femaleCustomer.setCreateDate(nowDate);
100
 			femaleCustomer.setCreateDate(nowDate);
95
 			femaleCustomer.setGenderType(CommConstant.SEX_FEMALE);
101
 			femaleCustomer.setGenderType(CommConstant.SEX_FEMALE);
96
-			femaleCustomer.setCustomerType(CommConstant.CUSTOMER_TYPE_NEW);
102
+			femaleCustomer.setCustomerType(customerType);
97
 			femaleCustomer.setCustomerNum(e.getWomanSum());
103
 			femaleCustomer.setCustomerNum(e.getWomanSum());
98
 			femaleCustomer.setPercentage(e.getWomanPct());
104
 			femaleCustomer.setPercentage(e.getWomanPct());
99
 			femaleCustomer.setOrgId(e.getOrgId());
105
 			femaleCustomer.setOrgId(e.getOrgId());
102
 			TaCustomerGenderStatistic unknownCustomer = new TaCustomerGenderStatistic();
108
 			TaCustomerGenderStatistic unknownCustomer = new TaCustomerGenderStatistic();
103
 			unknownCustomer.setCreateDate(nowDate);
109
 			unknownCustomer.setCreateDate(nowDate);
104
 			unknownCustomer.setGenderType(CommConstant.SEX_UNKNOWN);
110
 			unknownCustomer.setGenderType(CommConstant.SEX_UNKNOWN);
105
-			unknownCustomer.setCustomerType(CommConstant.CUSTOMER_TYPE_NEW);
111
+			unknownCustomer.setCustomerType(customerType);
106
 			unknownCustomer.setCustomerNum(e.getUnknownSum());
112
 			unknownCustomer.setCustomerNum(e.getUnknownSum());
107
 			unknownCustomer.setPercentage(e.getUnknownPct());
113
 			unknownCustomer.setPercentage(e.getUnknownPct());
108
 			unknownCustomer.setOrgId(e.getOrgId());
114
 			unknownCustomer.setOrgId(e.getOrgId());

+ 80
- 1
src/main/java/com/huiju/estateagents/statistic/service/impl/TaCustomerStatisticMonthlyServiceImpl.java Прегледај датотеку

1
 package com.huiju.estateagents.statistic.service.impl;
1
 package com.huiju.estateagents.statistic.service.impl;
2
 
2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5
+import com.huiju.estateagents.common.CommConstant;
4
 import com.huiju.estateagents.statistic.entity.TaCustomerStatisticMonthly;
6
 import com.huiju.estateagents.statistic.entity.TaCustomerStatisticMonthly;
5
 import com.huiju.estateagents.statistic.mapper.TaCustomerStatisticMonthlyMapper;
7
 import com.huiju.estateagents.statistic.mapper.TaCustomerStatisticMonthlyMapper;
6
 import com.huiju.estateagents.statistic.service.ITaCustomerStatisticMonthlyService;
8
 import com.huiju.estateagents.statistic.service.ITaCustomerStatisticMonthlyService;
9
+import org.springframework.beans.factory.annotation.Autowired;
7
 import org.springframework.stereotype.Service;
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
  * <p>
18
  * <p>
11
  * 客户分析月统计表 小程序盘客工具客户分析 服务实现类
19
  * 客户分析月统计表 小程序盘客工具客户分析 服务实现类
16
  */
24
  */
17
 @Service
25
 @Service
18
 public class TaCustomerStatisticMonthlyServiceImpl extends ServiceImpl<TaCustomerStatisticMonthlyMapper, TaCustomerStatisticMonthly> implements ITaCustomerStatisticMonthlyService {
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
 <!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.TaCustomerStatisticMonthlyMapper">
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
 </mapper>
47
 </mapper>