package com.huiju.estateagents.statistic.controller;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.excel.ActivityStatistics.*;
import com.huiju.estateagents.excel.handler.CustomCellWriteHandler;
import com.huiju.estateagents.statistic.service.impl.TaActivityStaticServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/api")
public class ActivityStatisticController extends BaseController {

    @Autowired
    private TaActivityStaticServiceImpl taActivityStaticService;

    @GetMapping(value = "/admin/activityStatistical/total")
    public ResponseBean indexStatistical(@RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                         @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                         @RequestParam(value = "buildingId", required = false)String buildingId,
                                         @RequestParam(value = "targetType", required = false)String targetType,
                                         HttpServletRequest request) {
        return taActivityStaticService.activityStatistical(startDate, endDate, buildingId, targetType, getOrgId(request), getTaPersonBuildingListByUserId(request), getUserId(request));
    }

    /**
     * 活动趋势人数
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/selectAllActivityUser")
    public ResponseBean selectNewsUserCount(@RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                            @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                            @RequestParam(value = "buildingId", required = false)String buildingId,
                                            @RequestParam(value = "targetType", required = false)String targetType,
                                            HttpServletRequest request) {
        return taActivityStaticService.selectAllActivityUser(getOrgId(request), startDate, endDate, buildingId, targetType, getTaPersonBuildingListByUserId(request), getUserId(request));
    }

    /**
     * 活动表格统计人数
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/selectTableData")
    public ResponseBean selectTableData(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize,
                                            @RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                            @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                            @RequestParam(value = "buildingId", required = false)String buildingId,
                                            @RequestParam(value = "targetType", required = false)String targetType,
                                            @RequestParam(value = "sort", required = false)String sort,
                                            @RequestParam(value = "colKey", required = false)String colKey,
                                            HttpServletRequest request) {
        return taActivityStaticService.selectTableData(pageNum, pageSize, getOrgId(request), startDate, endDate, buildingId, targetType, sort, colKey, getTaPersonBuildingListByUserId(request), getUserId(request));
    }

    /**
     * 活动表格统计人数导出
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/tableDataExport")
    public void selectTableDataExport(@RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                        @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                        @RequestParam(value = "buildingId", required = false)String buildingId,
                                        @RequestParam(value = "targetType", required = false)String targetType,
                                        @RequestParam(value = "sort", required = false)String sort,
                                        @RequestParam(value = "colKey", required = false)String colKey,
                                        HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("application/octet-stream");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=活动统计.xlsx");
        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), StatisicAttractUser.class).registerWriteHandler(new CustomCellWriteHandler()).build();
        // 设置 sheet, 同一个sheet只需要设置一次
        WriteSheet writeSheet = EasyExcel.writerSheet("活动统计").build();
        List<StatisicAttractUser> data = taActivityStaticService.selectExportTableData(getOrgId(request), startDate, endDate, buildingId, targetType, sort, colKey, getTaPersonBuildingListByUserId(request), getUserId(request));
        excelWriter.write(data, writeSheet);
        // finish 会帮忙关闭流
        excelWriter.finish();
    }

    /**
     * 活动表格统计人数
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/activityStatisDetail")
    public ResponseBean selectActivityStatisDetail(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize,
                                        @RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                        @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                        @RequestParam(value = "buildingId", required = false)String buildingId,
                                        @RequestParam(value = "targetType", required = false)String targetType,
                                        @RequestParam(value = "activityName", required = false)String activityName,
                                        @RequestParam(value = "sort", required = false)String sort,
                                        @RequestParam(value = "colKey", required = false)String colKey,
                                        HttpServletRequest request) {
        return taActivityStaticService.selectActivityStatisDetail(pageNum, pageSize, getOrgId(request), startDate, endDate, buildingId, targetType, activityName, sort, colKey, getTaPersonBuildingListByUserId(request), getUserId(request));
    }

    /**
     * 活动表格统计人数导出
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/activityDetailTableDataExport")
    public void activityDetailTableDataExport(@RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                @RequestParam(value = "buildingId", required = false)String buildingId,
                                @RequestParam(value = "targetType", required = false)String targetType,
                                @RequestParam(value = "activityName", required = false)String activityName,
                                @RequestParam(value = "sort", required = false)String sort,
                                @RequestParam(value = "colKey", required = false)String colKey,
                                HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("application/octet-stream");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=活动统计.xlsx");
        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), ActivityDetailShareRecord.class).registerWriteHandler(new CustomCellWriteHandler()).build();
        // 设置 sheet, 同一个sheet只需要设置一次
        WriteSheet writeSheet = EasyExcel.writerSheet("活动统计").build();
        List<ActivityDetailShareRecord> data = taActivityStaticService.selectActivityStatisDetailExport(getOrgId(request), startDate, endDate, buildingId, targetType, activityName, sort, colKey, getTaPersonBuildingListByUserId(request), getUserId(request));
        excelWriter.write(data, writeSheet);
        // finish 会帮忙关闭流
        excelWriter.finish();
    }

    /**
     * 分享人数统计
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/selectActivitySharePersonNum")
    public ResponseBean selectActivitySharePersonNum(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize,
                                                   @RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                                   @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                                   @RequestParam(value = "sharePersonType", required = false)String sharePersonType,
                                                   @RequestParam(value = "sharePersonName", required = false)  String sharePersonName,
                                                   @RequestParam(value = "sharePersonPhone", required = false)String sharePersonPhone,
                                                   @RequestParam(value = "activityId", required = false)String activityId,
                                                   @RequestParam(value = "activityType", required = false)String activityType,
                                                   @RequestParam(value = "sort", required = false)String sort,
                                                   @RequestParam(value = "colKey", required = false)String colKey,
                                                   @RequestParam(value = "buildingId", required = false)String buildingId,
                                                   HttpServletRequest request) {
        return taActivityStaticService.selectActivitySharePersonNum(pageNum, pageSize, getOrgId(request), startDate, endDate, sharePersonType, sharePersonName, sharePersonPhone, activityId, activityType, buildingId, sort, colKey, getTaPersonBuildingListByUserId(request), getUserId(request));
    }

    /**
     * 分享人数统计导出
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/activitySharePersonNumExport")
    public void selectActivitySharePersonNum(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize,
                                             @RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                             @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                             @RequestParam(value = "sharePersonType", required = false)String sharePersonType,
                                             @RequestParam(value = "sharePersonName", required = false)  String sharePersonName,
                                             @RequestParam(value = "sharePhone", required = false)String sharePhone,
                                             @RequestParam(value = "activityId", required = false)String activityId,
                                             @RequestParam(value = "activityType", required = false)String activityType,
                                             @RequestParam(value = "sort", required = false)String sort,
                                             @RequestParam(value = "colKey", required = false)String colKey,
                                             @RequestParam(value = "buildingId", required = false)String buildingId,
                                             HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("application/octet-stream");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=活动统计.xlsx");
        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), SharePersonNum.class).registerWriteHandler(new CustomCellWriteHandler()).build();
        // 设置 sheet, 同一个sheet只需要设置一次
        WriteSheet writeSheet = EasyExcel.writerSheet("活动统计").build();
        List<SharePersonNum> data = taActivityStaticService.selectActivitySharePersonNumExport(getOrgId(request), startDate, endDate, sharePersonType, sharePersonName, sharePhone, activityId, activityType, buildingId, sort, colKey, getTaPersonBuildingListByUserId(request), getUserId(request));
        excelWriter.write(data, writeSheet);
        // finish 会帮忙关闭流
        excelWriter.finish();
    }

    /**
     * 分享次数统计
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/selectActivityShareNum")
    public ResponseBean selectActivityShareNum(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize,
                                                     @RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                                     @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                                     @RequestParam(value = "sharePersonType", required = false)String sharePersonType,
                                                     @RequestParam(value = "sharePersonName", required = false)  String sharePersonName,
                                                     @RequestParam(value = "sharePersonPhone", required = false)String sharePersonPhone,
                                                     @RequestParam(value = "activityId", required = false)String activityId,
                                                     @RequestParam(value = "activityType", required = false)String activityType,
                                                     @RequestParam(value = "personId", required = false)String personId,
                                                     @RequestParam(value = "buildingId", required = false)String buildingId,
                                                     @RequestParam(value = "sort", required = false)String sort,
                                                     @RequestParam(value = "colKey", required = false)String colKey,
                                                     HttpServletRequest request) {
        return taActivityStaticService.selectActivityShareNum(pageNum, pageSize, getOrgId(request), startDate, endDate, sharePersonType, sharePersonName, sharePersonPhone, activityId, activityType, personId, buildingId, sort, colKey, getTaPersonBuildingListByUserId(request), getUserId(request));
    }

    /**
     * 分享次数统计导出
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/selectActivityShareNumExport")
    public void selectActivityShareNumExport(@RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                             @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                             @RequestParam(value = "sharePersonType", required = false)String sharePersonType,
                                             @RequestParam(value = "sharePersonName", required = false)  String sharePersonName,
                                             @RequestParam(value = "sharePhone", required = false)String sharePhone,
                                             @RequestParam(value = "activityId", required = false)String activityId,
                                             @RequestParam(value = "activityType", required = false)String activityType,
                                             @RequestParam(value = "personId", required = false)String personId,
                                             @RequestParam(value = "buildingId", required = false)String buildingId,
                                             @RequestParam(value = "sort", required = false)String sort,
                                             @RequestParam(value = "colKey", required = false)String colKey,
                                             HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("application/octet-stream");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=活动统计.xlsx");
        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), ShareNum.class).registerWriteHandler(new CustomCellWriteHandler()).build();
        // 设置 sheet, 同一个sheet只需要设置一次
        WriteSheet writeSheet = EasyExcel.writerSheet("活动统计").build();
        List<ShareNum> data = taActivityStaticService.selectActivityShareNumExport(getOrgId(request), startDate, endDate, sharePersonType, sharePersonName, sharePhone, activityId, activityType, personId, buildingId, sort, colKey, getTaPersonBuildingListByUserId(request), getUserId(request));
        excelWriter.write(data, writeSheet);
        // finish 会帮忙关闭流
        excelWriter.finish();
    }

    /**
     * 注册人数统计
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/selectActivityAddRegistNum")
    public ResponseBean selectActivityAddRegistNum(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize,
                                               @RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                               @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                               @RequestParam(value = "personFrom", required = false)String personFrom,
                                               @RequestParam(value = "activityId", required = false)String activityId,
                                               @RequestParam(value = "activityType", required = false)String activityType,
                                               @RequestParam(value = "buildingId", required = false)String buildingId,
                                               @RequestParam(value = "province", required = false)String province,
                                               HttpServletRequest request) {
        return taActivityStaticService.selectActivityAddRegistNum(pageNum, pageSize, getOrgId(request), startDate, endDate, personFrom, activityId, activityType, buildingId, province, getTaPersonBuildingListByUserId(request), getUserId(request));
    }

    /**
     * 注册人数导出
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/selectActivityAddRegistNumExport")
    public void selectActivityAddRegistNumExport(@RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                                               @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                                               @RequestParam(value = "personFrom", required = false)String personFrom,
                                                               @RequestParam(value = "activityId", required = false)String activityId,
                                                               @RequestParam(value = "activityType", required = false)String activityType,
                                                               @RequestParam(value = "buildingId", required = false)String buildingId,
                                                               @RequestParam(value = "province", required = false)String province,
                                                               HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("application/octet-stream");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=活动统计.xlsx");
        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), AddRegistNum.class).registerWriteHandler(new CustomCellWriteHandler()).build();
        // 设置 sheet, 同一个sheet只需要设置一次
        WriteSheet writeSheet = EasyExcel.writerSheet("活动统计").build();
        List<AddRegistNum> data = taActivityStaticService.selectActivityAddRegistNumExport(getOrgId(request), startDate, endDate, personFrom, activityId, activityType, buildingId, province, getTaPersonBuildingListByUserId(request), getUserId(request));
        excelWriter.write(data, writeSheet);
        // finish 会帮忙关闭流
        excelWriter.finish();
    }

    /**
     * 访问次数统计
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/selectActivityVisitNum")
    public ResponseBean selectActivityVisitNum(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize,
                                                   @RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                                   @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                                   @RequestParam(value = "personFrom", required = false)String personFrom,
                                                   @RequestParam(value = "province", required = false)String province,
                                                   @RequestParam(value = "realtyConsultant", required = false)String realtyConsultant,
                                                   @RequestParam(value = "realtyConsultantPhone", required = false)String realtyConsultantPhone,
                                                   @RequestParam(value = "activityId", required = false)String activityId,
                                                   @RequestParam(value = "activityType", required = false)String activityType,
                                                   @RequestParam(value = "personId", required = false)String personId,
                                                   @RequestParam(value = "buildingId", required = false)String buildingId,
                                                   HttpServletRequest request) {
        return taActivityStaticService.selectActivityVisitNum(pageNum, pageSize, getOrgId(request), startDate, endDate, personFrom, province, realtyConsultant, realtyConsultantPhone, activityId, activityType, personId, buildingId, getTaPersonBuildingListByUserId(request));
    }

    /**
     * 访问次数统计
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/selectActivityVisitNumExport")
    public void selectActivityVisitNum(@RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                               @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                               @RequestParam(value = "personFrom", required = false)String personFrom,
                                               @RequestParam(value = "province", required = false)String province,
                                               @RequestParam(value = "realtyConsultant", required = false)String realtyConsultant,
                                               @RequestParam(value = "realtyConsultantPhone", required = false)String realtyConsultantPhone,
                                               @RequestParam(value = "activityId", required = false)String activityId,
                                               @RequestParam(value = "activityType", required = false)String activityType,
                                               @RequestParam(value = "personId", required = false)String personId,
                                               @RequestParam(value = "buildingId", required = false)String buildingId,
                                               HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("application/octet-stream");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=活动统计.xlsx");
        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), VisitNum.class).registerWriteHandler(new CustomCellWriteHandler()).build();
        // 设置 sheet, 同一个sheet只需要设置一次
        WriteSheet writeSheet = EasyExcel.writerSheet("活动统计").build();
        List<VisitNum> data = taActivityStaticService.selectActivityVisitNumExport(getOrgId(request), startDate, endDate, personFrom, province, realtyConsultant, realtyConsultantPhone, activityId, activityType, personId, buildingId);
        excelWriter.write(data, writeSheet);
        // finish 会帮忙关闭流
        excelWriter.finish();
    }

    /**
     * 访问人数统计
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/selectActivityVisitPersonNum")
    public ResponseBean selectActivityVisitPersonNum(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize,
                                               @RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                               @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                               @RequestParam(value = "personFrom", required = false)String personFrom,
                                               @RequestParam(value = "province", required = false)String province,
                                               @RequestParam(value = "realtyConsultant", required = false)String realtyConsultant,
                                               @RequestParam(value = "realtyConsultantPhone", required = false)String realtyConsultantPhone,
                                               @RequestParam(value = "personId", required = false)String personId,
                                               @RequestParam(value = "activityId", required = false)String activityId,
                                               @RequestParam(value = "activityType", required = false)String activityType,
                                               @RequestParam(value = "buildingId", required = false)String buildingId,
                                               HttpServletRequest request) {
        return taActivityStaticService.selectActivityVisitPersonNum(pageNum, pageSize, getOrgId(request), startDate, endDate, personFrom, province, realtyConsultant, realtyConsultantPhone, activityId, activityType, buildingId,  personId, getTaPersonBuildingListByUserId(request));
    }

    /**
     * 访问人数统计导出
     * @return
     */
    @GetMapping(value = "/admin/activityStatistical/selectActivityVisitPersonNumExport")
    public void selectActivityVisitPersonNumExport(@RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate startDate,
                                       @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDate endDate,
                                       @RequestParam(value = "personFrom", required = false)String personFrom,
                                       @RequestParam(value = "province", required = false)String province,
                                       @RequestParam(value = "realtyConsultant", required = false)String realtyConsultant,
                                       @RequestParam(value = "realtyConsultantPhone", required = false)String realtyConsultantPhone,
                                       @RequestParam(value = "personId", required = false)String personId,
                                       @RequestParam(value = "activityId", required = false)String activityId,
                                       @RequestParam(value = "activityType", required = false)String activityType,
                                       @RequestParam(value = "buildingId", required = false)String buildingId,
                                       HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("application/octet-stream");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=活动统计.xlsx");
        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), VisitPersonNum.class).registerWriteHandler(new CustomCellWriteHandler()).build();
        // 设置 sheet, 同一个sheet只需要设置一次
        WriteSheet writeSheet = EasyExcel.writerSheet("活动统计").build();
        List<VisitPersonNum> data = taActivityStaticService.selectActivityVisitPersonNumExport(getOrgId(request), startDate, endDate, personFrom, province, realtyConsultant, realtyConsultantPhone, activityId, activityType, buildingId,  personId, getTaPersonBuildingListByUserId(request));
        excelWriter.write(data, writeSheet);
        // finish 会帮忙关闭流
        excelWriter.finish();
    }

}
