|
@@ -2,6 +2,8 @@ package com.huiju.estateagents.service.impl;
|
2
|
2
|
|
3
|
3
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
4
|
4
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
5
|
+import com.huiju.estateagents.center.taUser.entity.TaUser;
|
|
6
|
+import com.huiju.estateagents.center.taUser.mapper.TaUserMapper;
|
5
|
7
|
import com.huiju.estateagents.common.StringUtils;
|
6
|
8
|
import com.huiju.estateagents.entity.*;
|
7
|
9
|
import com.huiju.estateagents.excel.ConsultantKPIExport;
|
|
@@ -13,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
13
|
15
|
import org.springframework.stereotype.Service;
|
14
|
16
|
|
15
|
17
|
import java.time.LocalDateTime;
|
|
18
|
+import java.util.ArrayList;
|
16
|
19
|
import java.util.List;
|
17
|
20
|
|
18
|
21
|
/**
|
|
@@ -28,34 +31,67 @@ public class TsConsultantKpiServiceImpl extends ServiceImpl<TsConsultantKpiMappe
|
28
|
31
|
@Autowired
|
29
|
32
|
TsConsultantKpiMapper tsConsultantKpiMapper;
|
30
|
33
|
|
|
34
|
+ @Autowired
|
|
35
|
+ TaUserMapper taUserMapper;
|
|
36
|
+
|
31
|
37
|
@Autowired
|
32
|
38
|
TaRecommendCustomerMapper taRecommendCustomerMapper;
|
33
|
39
|
|
|
40
|
+ /**
|
|
41
|
+ * 获取用户授权楼盘
|
|
42
|
+ * 如果 buildingId 参数存在, 则校验参数是否在授权范围内
|
|
43
|
+ *
|
|
44
|
+ * @param userId
|
|
45
|
+ * @param buildingId
|
|
46
|
+ * @return List 长度 0 代表未授权楼盘, null 代表管理员, 不校验楼盘授权
|
|
47
|
+ */
|
|
48
|
+ public List<String> getBuildingListOf(Integer userId, String buildingId) {
|
|
49
|
+ List<String> unAuthrized = new ArrayList<String>(){{
|
|
50
|
+ add("*"); // 构造SQL building_id in ('*') , 目的是为了阻止检索到数据
|
|
51
|
+ }};
|
|
52
|
+
|
|
53
|
+ TaUser taUser = taUserMapper.selectById(userId);
|
|
54
|
+ if (taUser == null) {
|
|
55
|
+ return unAuthrized;
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ if (taUser.getIsAdmin()) {
|
|
59
|
+ return null;
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ List<String> buildings = taUserMapper.getBuildingIdsOf(userId, buildingId);
|
|
63
|
+ return null == buildings || buildings.size() == 0 ? unAuthrized : buildings;
|
|
64
|
+ }
|
|
65
|
+
|
34
|
66
|
@Override
|
35
|
|
- public IPage<TsConsultantKpi> stsKPIDaily(Integer pageNum, Integer pageSize, Integer orgId, String buildingId, String startDate, String endDate, String asc, String desc) {
|
|
67
|
+ public IPage<TsConsultantKpi> stsKPIDaily(Integer pageNum, Integer pageSize, Integer orgId, Integer userId, String buildingId, String startDate, String endDate, String asc, String desc) {
|
36
|
68
|
if (StringUtils.isEmpty(asc) && StringUtils.isEmpty(desc)) {
|
37
|
69
|
desc = "new_persons";
|
38
|
70
|
}
|
39
|
71
|
|
|
72
|
+ List<String> buildingIds = getBuildingListOf(userId, buildingId);
|
40
|
73
|
IPage<TsConsultantKpi> page = new Page<>(pageNum, pageSize);
|
41
|
|
- return tsConsultantKpiMapper.stsKPIDaily(page, orgId, buildingId, startDate, endDate, asc, desc);
|
|
74
|
+ return tsConsultantKpiMapper.stsKPIDaily(page, orgId, buildingIds, startDate, endDate, asc, desc);
|
42
|
75
|
}
|
43
|
76
|
|
44
|
77
|
@Override
|
45
|
|
- public TsConsultantKpi stsKPITotalByOrg(Integer orgId, String buildingId, String startDate, String endDate) {
|
|
78
|
+ public TsConsultantKpi stsKPITotalByOrg(Integer orgId, Integer userId, String buildingId, String startDate, String endDate) {
|
|
79
|
+ List<String> buildingIds = getBuildingListOf(userId, buildingId);
|
|
80
|
+
|
46
|
81
|
// 合计数据, 但是不包含 客户总计 列
|
47
|
|
- TsConsultantKpi result = tsConsultantKpiMapper.stsKPITotalByOrg(orgId, buildingId, startDate, endDate);
|
|
82
|
+ TsConsultantKpi result = tsConsultantKpiMapper.stsKPITotalByOrg(orgId, buildingIds, startDate, endDate);
|
48
|
83
|
|
49
|
84
|
// 统计当前时间段内的已经固化的置业的客户
|
50
|
|
- Integer totalPersons = tsConsultantKpiMapper.stsAllCustomersByOrg(orgId, buildingId, startDate, endDate);
|
|
85
|
+ Integer totalPersons = tsConsultantKpiMapper.stsAllCustomersByOrg(orgId, buildingIds, startDate, endDate);
|
51
|
86
|
result.setTotalPersons(totalPersons);
|
52
|
87
|
|
53
|
88
|
return result;
|
54
|
89
|
}
|
55
|
90
|
|
56
|
91
|
@Override
|
57
|
|
- public List<ConsultantKPIExport> stsKPIDailyExport(Integer orgId, String buildingId, String startDate, String endDate) {
|
58
|
|
- return tsConsultantKpiMapper.stsKPIDailyExport(orgId, buildingId, startDate, endDate);
|
|
92
|
+ public List<ConsultantKPIExport> stsKPIDailyExport(Integer orgId, Integer userId, String buildingId, String startDate, String endDate) {
|
|
93
|
+ List<String> buildingIds = getBuildingListOf(userId, buildingId);
|
|
94
|
+ return tsConsultantKpiMapper.stsKPIDailyExport(orgId, buildingIds, startDate, endDate);
|
59
|
95
|
}
|
60
|
96
|
|
61
|
97
|
@Override
|