张延森 преди 5 години
родител
ревизия
77c5117503

+ 2
- 0
src/main/java/com/huiju/estateagents/center/taUser/mapper/TaUserMapper.java Целия файл

@@ -33,4 +33,6 @@ public interface TaUserMapper extends BaseMapper<TaUser> {
33 33
     Integer validateWeight(@Param("buildingIds") List<String> buildingIds, @Param("buildingId") String buildingId, @Param("weight") String weight, @Param("userId")Integer userId);
34 34
 
35 35
     TaUser getAdminByAppID(@Param("appid") String appID);
36
+
37
+    List<String> getBuildingIdsOf(@Param("userId") Integer userId,@Param("buildingId") String buildingId);
36 38
 }

+ 7
- 3
src/main/java/com/huiju/estateagents/controller/TsConsultantKpiController.java Целия файл

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
8 8
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
9 9
 import com.huiju.estateagents.base.BaseController;
10 10
 import com.huiju.estateagents.base.ResponseBean;
11
+import com.huiju.estateagents.center.taUser.entity.TaUser;
11 12
 import com.huiju.estateagents.common.DateUtils;
12 13
 import com.huiju.estateagents.common.ExcelUtils;
13 14
 import com.huiju.estateagents.common.StringUtils;
@@ -15,6 +16,7 @@ import com.huiju.estateagents.entity.*;
15 16
 import com.huiju.estateagents.excel.ConsultantKPIExport;
16 17
 import com.huiju.estateagents.excel.TaActivityDynamicEnlistExport;
17 18
 import com.huiju.estateagents.excel.handler.CustomCellWriteHandler;
19
+import io.swagger.models.auth.In;
18 20
 import org.slf4j.Logger;
19 21
 import org.slf4j.LoggerFactory;
20 22
 import org.springframework.beans.factory.annotation.Autowired;
@@ -76,11 +78,12 @@ public class TsConsultantKpiController extends BaseController {
76 78
         }
77 79
 
78 80
         Integer orgId = getOrgId(request);
81
+        Integer userId = getUserId(request);
79 82
         try {
80 83
             // 汇总明细
81
-            IPage<TsConsultantKpi> result = iTsConsultantKpiService.stsKPIDaily(pageNum, pageSize, orgId, buildingId, startDate, endDate, StringUtils.humpToLine(asc), StringUtils.humpToLine(desc));
84
+            IPage<TsConsultantKpi> result = iTsConsultantKpiService.stsKPIDaily(pageNum, pageSize, orgId, userId, buildingId, startDate, endDate, StringUtils.humpToLine(asc), StringUtils.humpToLine(desc));
82 85
             // 汇总
83
-            TsConsultantKpi total = iTsConsultantKpiService.stsKPITotalByOrg(orgId, buildingId, startDate, endDate);
86
+            TsConsultantKpi total = iTsConsultantKpiService.stsKPITotalByOrg(orgId, userId, buildingId, startDate, endDate);
84 87
             return ResponseBean.success(new HashMap<String, Object>(){{
85 88
                 put("paged", result);
86 89
                 put("total", total);
@@ -116,10 +119,11 @@ public class TsConsultantKpiController extends BaseController {
116 119
         }
117 120
 
118 121
         Integer orgId = getOrgId(request);
122
+        Integer userId = getUserId(request);
119 123
         try {
120 124
 
121 125
             // 汇总明细
122
-            List<ConsultantKPIExport> result = iTsConsultantKpiService.stsKPIDailyExport(orgId, buildingId, startDate, endDate);
126
+            List<ConsultantKPIExport> result = iTsConsultantKpiService.stsKPIDailyExport(orgId, userId, buildingId, startDate, endDate);
123 127
             ExcelUtils.flush(response, ConsultantKPIExport.class, result, "置业顾问KPI统计" + DateUtils.today());
124 128
         } catch (Exception e){
125 129
 //            e.printStackTrace();

+ 25
- 6
src/main/java/com/huiju/estateagents/mapper/TsConsultantKpiMapper.java Целия файл

@@ -2,7 +2,6 @@ package com.huiju.estateagents.mapper;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4 4
 import com.huiju.estateagents.entity.TaPerson;
5
-import com.huiju.estateagents.entity.TaShareCount;
6 5
 import com.huiju.estateagents.entity.TsConsultantKpi;
7 6
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
8 7
 import com.huiju.estateagents.excel.ConsultantKPIExport;
@@ -23,27 +22,47 @@ import java.util.List;
23 22
 @Mapper
24 23
 public interface TsConsultantKpiMapper extends BaseMapper<TsConsultantKpi> {
25 24
 
25
+    /**
26
+     * 置业KPI 汇总
27
+     * @param page
28
+     * @param orgId
29
+     * @param buildingIds
30
+     * @param startDate
31
+     * @param endDate
32
+     * @param asc
33
+     * @param desc
34
+     * @return
35
+     */
26 36
     IPage<TsConsultantKpi> stsKPIDaily(IPage<TsConsultantKpi> page,
27 37
                                        @Param("orgId") Integer orgId,
28
-                                       @Param("buildingId") String buildingId,
38
+                                       @Param("buildingIds") List<String> buildingIds,
29 39
                                        @Param("startDate") String startDate,
30 40
                                        @Param("endDate") String endDate,
31 41
                                        @Param("asc") String asc,
32 42
                                        @Param("desc") String desc);
33 43
 
34
-    TsConsultantKpi stsKPITotalByOrg(@Param("orgId") Integer orgId, @Param("buildingId") String buildingId, @Param("startDate") String startDate, @Param("endDate") String endDate);
44
+    TsConsultantKpi stsKPITotalByOrg(@Param("orgId") Integer orgId,
45
+                                     @Param("buildingIds") List<String> buildingIds,
46
+                                     @Param("startDate") String startDate,
47
+                                     @Param("endDate") String endDate);
35 48
 
36
-    List<ConsultantKPIExport> stsKPIDailyExport(@Param("orgId") Integer orgId, @Param("buildingId") String buildingId, @Param("startDate") String startDate, @Param("endDate") String endDate);
49
+    List<ConsultantKPIExport> stsKPIDailyExport(@Param("orgId") Integer orgId,
50
+                                                @Param("buildingIds") List<String> buildingIds,
51
+                                                @Param("startDate") String startDate,
52
+                                                @Param("endDate") String endDate);
37 53
 
38 54
     /**
39 55
      * 统计当前时间段内的, 已经固化的置业数据的所有客户
40 56
      * @param orgId
41
-     * @param buildingId
57
+     * @param buildingIds
42 58
      * @param startDate
43 59
      * @param endDate
44 60
      * @return
45 61
      */
46
-    Integer stsAllCustomersByOrg(@Param("orgId") Integer orgId, @Param("buildingId") String buildingId, @Param("startDate") String startDate, @Param("endDate") String endDate);
62
+    Integer stsAllCustomersByOrg(@Param("orgId") Integer orgId,
63
+                                 @Param("buildingIds") List<String> buildingIds,
64
+                                 @Param("startDate") String startDate,
65
+                                 @Param("endDate") String endDate);
47 66
 
48 67
 
49 68
     /**

+ 3
- 3
src/main/java/com/huiju/estateagents/service/ITsConsultantKpiService.java Целия файл

@@ -18,11 +18,11 @@ import java.util.List;
18 18
  */
19 19
 public interface ITsConsultantKpiService extends IService<TsConsultantKpi> {
20 20
 
21
-    IPage<TsConsultantKpi> stsKPIDaily(Integer pageNum, Integer pageSize, Integer orgId, String buildingId, String startDate, String endDate, String asc, String desc);
21
+    IPage<TsConsultantKpi> stsKPIDaily(Integer pageNum, Integer pageSize, Integer orgId, Integer userId, String buildingId, String startDate, String endDate, String asc, String desc);
22 22
 
23
-    TsConsultantKpi stsKPITotalByOrg(Integer orgId, String buildingId, String startDate, String endDate);
23
+    TsConsultantKpi stsKPITotalByOrg(Integer orgId, Integer userId, String buildingId, String startDate, String endDate);
24 24
 
25
-    List<ConsultantKPIExport> stsKPIDailyExport(Integer orgId, String buildingId, String startDate, String endDate);
25
+    List<ConsultantKPIExport> stsKPIDailyExport(Integer orgId, Integer userId, String buildingId, String startDate, String endDate);
26 26
 
27 27
     IPage<TaRecommendCustomer> getCustomerListOfConsultant(IPage<TaRecommendCustomer> page, Integer orgId, String userId, String buildingId, LocalDateTime startDate, LocalDateTime endDate);
28 28
 

+ 43
- 7
src/main/java/com/huiju/estateagents/service/impl/TsConsultantKpiServiceImpl.java Целия файл

@@ -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

+ 8
- 0
src/main/resources/mapper/TaUserMapper.xml Целия файл

@@ -125,4 +125,12 @@
125 125
         AND m.is_admin = 1
126 126
     </select>
127 127
 
128
+    <select id="getBuildingIdsOf" resultType="java.lang.String">
129
+        select building_id from ta_person_building
130
+        where user_id = #{userId}
131
+        <if test="buildingId != null and buildingId != ''">
132
+            and building_id != #{buildingId}
133
+        </if>
134
+    </select>
135
+
128 136
 </mapper>

+ 25
- 9
src/main/resources/mapper/TsConsultantKpiMapper.xml Целия файл

@@ -31,8 +31,12 @@
31 31
             WHERE
32 32
                 t.org_id = #{orgId}
33 33
                 AND t.statis_date BETWEEN #{startDate} AND #{endDate}
34
-            <if test="buildingId != null and buildingId != ''">
35
-                AND t.building_id = #{buildingId}
34
+            <if test="buildingIds != null">
35
+                AND t.building_id in
36
+                <foreach item="buildingId" index="index" collection="buildingIds"
37
+                         open="(" separator="," close=")">
38
+                    #{buildingId}
39
+                </foreach>
36 40
             </if>
37 41
             GROUP BY
38 42
                 t.user_id,
@@ -74,8 +78,12 @@
74 78
         WHERE
75 79
             t.org_id = #{orgId}
76 80
             AND t.statis_date BETWEEN #{startDate} AND #{endDate}
77
-        <if test="buildingId != null and buildingId != ''">
78
-            AND t.building_id = #{buildingId}
81
+        <if test="buildingIds != null">
82
+            AND t.building_id in
83
+            <foreach item="buildingId" index="index" collection="buildingIds"
84
+                     open="(" separator="," close=")">
85
+                #{buildingId}
86
+            </foreach>
79 87
         </if>
80 88
     </select>
81 89
 
@@ -107,9 +115,13 @@
107 115
         WHERE
108 116
             t.org_id = #{orgId}
109 117
         AND t.statis_date BETWEEN #{startDate} AND #{endDate}
110
-        <if test="buildingId != null and buildingId != ''">
111
-            AND t.building_id = #{buildingId}
112
-        </if>
118
+    <if test="buildingIds != null">
119
+        AND t.building_id in
120
+        <foreach item="buildingId" index="index" collection="buildingIds"
121
+                 open="(" separator="," close=")">
122
+            #{buildingId}
123
+        </foreach>
124
+    </if>
113 125
         GROUP BY
114 126
             t.user_id,
115 127
             t.building_id
@@ -130,8 +142,12 @@
130 142
             p.org_id = #{orgId}
131 143
             AND p.`status` > 0
132 144
             AND t.statis_date BETWEEN #{startDate} AND #{endDate}
133
-        <if test="buildingId != null and buildingId != ''">
134
-            AND t.building_id = #{buildingId}
145
+        <if test="buildingIds != null">
146
+            AND t.building_id in
147
+            <foreach item="buildingId" index="index" collection="buildingIds"
148
+                     open="(" separator="," close=")">
149
+                #{buildingId}
150
+            </foreach>
135 151
         </if>
136 152
     </select>
137 153