傅行帆 vor 5 Jahren
Ursprung
Commit
6c01239c27

+ 33
- 1
src/main/java/com/huiju/estateagents/controller/StatisticalController.java Datei anzeigen

@@ -1,14 +1,25 @@
1 1
 package com.huiju.estateagents.controller;
2 2
 
3
+import com.alibaba.excel.EasyExcel;
4
+import com.alibaba.excel.ExcelWriter;
5
+import com.alibaba.excel.write.metadata.WriteSheet;
3 6
 import com.huiju.estateagents.base.BaseController;
4 7
 import com.huiju.estateagents.base.ResponseBean;
8
+import com.huiju.estateagents.excel.StatsBuilding;
9
+import com.huiju.estateagents.excel.handler.CustomCellWriteHandler;
5 10
 import com.huiju.estateagents.service.IStatisticalService;
6 11
 import org.springframework.beans.factory.annotation.Autowired;
7 12
 import org.springframework.format.annotation.DateTimeFormat;
8
-import org.springframework.web.bind.annotation.*;
13
+import org.springframework.web.bind.annotation.GetMapping;
14
+import org.springframework.web.bind.annotation.RequestMapping;
15
+import org.springframework.web.bind.annotation.RequestParam;
16
+import org.springframework.web.bind.annotation.RestController;
9 17
 
10 18
 import javax.servlet.http.HttpServletRequest;
19
+import javax.servlet.http.HttpServletResponse;
20
+import java.io.IOException;
11 21
 import java.time.LocalDate;
22
+import java.util.List;
12 23
 
13 24
 /**
14 25
  * 数据统计
@@ -212,4 +223,25 @@ public class StatisticalController extends BaseController {
212 223
                                                 HttpServletRequest request) {
213 224
         return iStatisticalService.getStatsTableList(pageNum,pageSize,getOrgId(request), startDate, endDate,buildingId, getTaPersonBuildingListByUserId(request),sortField,sortOrder);
214 225
     }
226
+
227
+    /**
228
+     * 项目排行统计图
229
+     * @return
230
+     */
231
+    @GetMapping(value = "/admin/stats/buildingExport")
232
+    public void getBuildingTableList(@RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
233
+                                             @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)  LocalDate endDate,
234
+                                             @RequestParam(value = "buildingId", required = false) String buildingId,
235
+                                             HttpServletRequest request, HttpServletResponse response) throws IOException {
236
+        response.setContentType("application/octet-stream");
237
+        response.setCharacterEncoding("utf-8");
238
+        response.setHeader("Content-disposition", "attachment;filename=项目统计.xlsx");
239
+        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), StatsBuilding.class).registerWriteHandler(new CustomCellWriteHandler()).build();
240
+        // 设置 sheet, 同一个sheet只需要设置一次
241
+        WriteSheet writeSheet = EasyExcel.writerSheet("项目统计").build();
242
+        List<StatsBuilding> list = iStatisticalService.getExportTableList(getOrgId(request), startDate, endDate,buildingId, getTaPersonBuildingListByUserId(request));
243
+        excelWriter.write(list, writeSheet);
244
+        // finish 会帮忙关闭流
245
+        excelWriter.finish();
246
+    }
215 247
 }

+ 30
- 8
src/main/java/com/huiju/estateagents/excel/StatsBuilding.java Datei anzeigen

@@ -1,5 +1,7 @@
1 1
 package com.huiju.estateagents.excel;
2 2
 
3
+import com.alibaba.excel.annotation.ExcelProperty;
4
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
3 5
 import lombok.Data;
4 6
 
5 7
 @Data
@@ -8,30 +10,50 @@ public class StatsBuilding {
8 10
     /**
9 11
      * 项目名称
10 12
      */
13
+    @ColumnWidth(15)
14
+    @ExcelProperty(value = "项目名称", index = 0)
11 15
     private String buildingName;
12 16
 
13 17
     /**
14
-     * 观看次数
18
+     * 新增客户 公客加私客
15 19
      */
16
-    private Integer pvNum;
20
+    @ColumnWidth(15)
21
+    @ExcelProperty(value = "新增客户", index = 1)
22
+    private Integer khNum;
17 23
 
18 24
     /**
19
-     * 观看人数
25
+     * 公客
20 26
      */
21
-    private Integer uvNum;
27
+    @ColumnWidth(15)
28
+    @ExcelProperty(value = "公客", index = 2)
29
+    private Integer gkNum;
22 30
 
23 31
     /**
24 32
      * 私客
25 33
      */
34
+    @ColumnWidth(15)
35
+    @ExcelProperty(value = "私客", index = 3)
26 36
     private Integer skNum;
27 37
 
28 38
     /**
29
-     * 公客
39
+     * 观看人数
30 40
      */
31
-    private Integer gkNum;
41
+    @ColumnWidth(15)
42
+    @ExcelProperty(value = "访问人数", index = 4)
43
+    private Integer uvNum;
32 44
 
33 45
     /**
34
-     * 新增客户 公客加私客
46
+     * 观看次数
35 47
      */
36
-    private Integer khNum;
48
+    @ColumnWidth(15)
49
+    @ExcelProperty(value = "访问次数", index = 5)
50
+    private Integer pvNum;
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
37 59
 }

+ 10
- 0
src/main/java/com/huiju/estateagents/mapper/TaBuildingMapper.java Datei anzeigen

@@ -147,4 +147,14 @@ public interface TaBuildingMapper extends BaseMapper<TaBuilding> {
147 147
      */
148 148
     IPage<StatsBuilding> getStatsTableList(IPage<StatsBuilding> page, @Param("orgId") Integer orgId, @Param("startDate")  LocalDate startDate, @Param("endDate")  LocalDate endDate, @Param("buildingId") String buildingId, @Param("personBuildingList") List<TaPersonBuilding> personBuildingList,@Param("sortField") String sortField,@Param("orderType") String orderType);
149 149
 
150
+    /**
151
+     * 获取导出的数据
152
+     * @param orgId
153
+     * @param startDate
154
+     * @param endDate
155
+     * @param buildingId
156
+     * @param personBuildingList
157
+     * @return
158
+     */
159
+    List<StatsBuilding> getExportTableList(@Param("orgId") Integer orgId, @Param("startDate")  LocalDate startDate, @Param("endDate")  LocalDate endDate, @Param("buildingId") String buildingId, @Param("personBuildingList") List<TaPersonBuilding> personBuildingList);
150 160
 }

+ 12
- 0
src/main/java/com/huiju/estateagents/service/IStatisticalService.java Datei anzeigen

@@ -2,6 +2,7 @@ package com.huiju.estateagents.service;
2 2
 
3 3
 import com.huiju.estateagents.base.ResponseBean;
4 4
 import com.huiju.estateagents.entity.TaPersonBuilding;
5
+import com.huiju.estateagents.excel.StatsBuilding;
5 6
 
6 7
 import java.time.LocalDate;
7 8
 import java.util.List;
@@ -146,4 +147,15 @@ public interface IStatisticalService {
146 147
      * @return
147 148
      */
148 149
     ResponseBean getStatsTableList(Integer pageNum, Integer pageSize, Integer orgId, LocalDate startDate, LocalDate endDate, String buildingId, List<TaPersonBuilding> taPersonBuildingListByUserId,String sortField,String sortOrder);
150
+
151
+    /**
152
+     * 获取需要导出的数据
153
+     * @param orgId
154
+     * @param startDate
155
+     * @param endDate
156
+     * @param buildingId
157
+     * @param taPersonBuildingListByUserId
158
+     * @return
159
+     */
160
+    List<StatsBuilding> getExportTableList(Integer orgId, LocalDate startDate, LocalDate endDate, String buildingId, List<TaPersonBuilding> taPersonBuildingListByUserId);
149 161
 }

+ 15
- 0
src/main/java/com/huiju/estateagents/service/impl/StatisticalServiceImpl.java Datei anzeigen

@@ -459,6 +459,21 @@ public class StatisticalServiceImpl implements IStatisticalService {
459 459
         return ResponseBean.success(page);
460 460
     }
461 461
 
462
+    /**
463
+     * 获取需要导出的数据
464
+     *
465
+     * @param orgId
466
+     * @param startDate
467
+     * @param endDate
468
+     * @param buildingId
469
+     * @param personBuildingList
470
+     * @return
471
+     */
472
+    @Override
473
+    public List<StatsBuilding> getExportTableList(Integer orgId, LocalDate startDate, LocalDate endDate, String buildingId, List<TaPersonBuilding> personBuildingList) {
474
+        return taBuildingMapper.getExportTableList(orgId, startDate, endDate, buildingId, personBuildingList);
475
+    }
476
+
462 477
     /**
463 478
      * 项目公客排行折线图获取
464 479
      * @param orgId

+ 91
- 0
src/main/resources/mapper/TaBuildingMapper.xml Datei anzeigen

@@ -475,5 +475,96 @@
475 475
             ORDER BY ${sortField} ${orderType}
476 476
         </if>
477 477
     </select>
478
+    <select id="getExportTableList" resultType="com.huiju.estateagents.excel.StatsBuilding">
479
+        SELECT
480
+        t.building_id,
481
+        t.building_name,
482
+        IFNULL( t.pv_num, 0 ) AS pv_num,
483
+        IFNULL( uu.uv_num, 0 ) AS uv_num,
484
+        IFNULL( aa.sk_num, 0 ) AS sk_num,
485
+        IFNULL( bbb.gk_num, 0 ) AS gk_num,
486
+        IFNULL( aa.sk_num, 0 ) + IFNULL( bbb.gk_num, 0 ) AS kh_num
487
+        FROM
488
+        ta_building t
489
+        LEFT JOIN (
490
+        SELECT
491
+        count( * ) AS sk_num,
492
+        a.building_id
493
+        FROM
494
+        ta_recommend_customer a
495
+        WHERE
496
+        a.STATUS > 0
497
+        AND a.verify_status = 1
498
+        AND a.realty_consultant IS NOT NULL
499
+        AND a.realty_consultant != ''
500
+        AND a.org_id = #{orgId}
501
+        <if test="startDate != null">
502
+            and  TO_DAYS(a.create_date) >= TO_DAYS(#{startDate})
503
+        </if>
504
+        <if test="endDate != null">
505
+            and  TO_DAYS(a.create_date) &lt;= TO_DAYS(#{endDate})
506
+        </if>
507
+        GROUP BY
508
+        a.building_id
509
+        ) aa ON aa.building_id = t.building_id
510
+        LEFT JOIN (
511
+        SELECT
512
+        count( * ) AS gk_num,
513
+        bb.building_id
514
+        FROM
515
+        (
516
+        SELECT
517
+        b.*
518
+        FROM
519
+        ta_person b
520
+        WHERE
521
+        b.STATUS > 0
522
+        AND b.org_id = #{orgId}
523
+        AND IFNULL( b.person_type, '' ) IN ( 'estate agent', 'customer' )
524
+        AND b.person_id NOT IN ( SELECT c.person_id FROM ta_recommend_customer c WHERE c.org_id = 84 AND person_id IS NOT NULL AND person_id != '' )
525
+        <if test="startDate != null">
526
+            and  TO_DAYS(b.create_date) >= TO_DAYS(#{startDate})
527
+        </if>
528
+        <if test="endDate != null">
529
+            and  TO_DAYS(b.create_date) &lt;= TO_DAYS(#{endDate})
530
+        </if>
531
+        GROUP BY
532
+        b.person_id
533
+        ) bb
534
+        GROUP BY
535
+        bb.building_id
536
+        ) bbb ON bbb.building_id = t.building_id
537
+        LEFT JOIN (
538
+        SELECT
539
+        count( * ) AS uv_num,
540
+        u.be_uv AS building_id
541
+        FROM
542
+        ta_uv u
543
+        WHERE
544
+        u.tagert_type = 'project'
545
+        <if test="startDate != null">
546
+            and  TO_DAYS(u.create_date) >= TO_DAYS(#{startDate})
547
+        </if>
548
+        <if test="endDate != null">
549
+            and  TO_DAYS(u.create_date) &lt;= TO_DAYS(#{endDate})
550
+        </if>
551
+        GROUP BY
552
+        u.be_uv
553
+        ) uu ON uu.building_id = t.building_id
554
+        WHERE
555
+        t.org_id = #{orgId}
556
+        <if test="personBuildingList != null and personBuildingList.size > 0">
557
+            AND t.building_id in
558
+            <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
559
+                #{personBuilding.buildingId}
560
+            </foreach>
561
+        </if>
562
+        <if test="buildingId != null and buildingId != '' ">
563
+            AND t.building_id = #{buildingId}
564
+        </if>
565
+<!--        <if test="sortField != null and sortField != ''">-->
566
+<!--            ORDER BY ${sortField} ${orderType}-->
567
+<!--        </if>-->
568
+    </select>
478 569
 
479 570
 </mapper>