package cn.com.ctop.toutiao.modules.report.controller;

import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.common.module.utils.ExportExcelUtils;
import cn.com.ctop.toutiao.modules.report.DTO.ColumnDTO;
import cn.com.ctop.toutiao.modules.report.DTO.DateDTO;
import cn.com.ctop.toutiao.modules.report.entity.ByteDanceVideoReportDaily;
import cn.com.ctop.toutiao.modules.report.service.IByteDanceVideoReportDailyService;
import com.github.pagehelper.PageInfo;
import io.micrometer.core.instrument.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 视频按时间段统计
 *
 * @author jeecg-boot
 * @version V1.0
 * @date 2020-05-13
 */
@Slf4j
@Api(tags = "视频按时间段统计")
@RestController
@RequestMapping("/toutiao/videoReportDaily")
public class ByteDanceVideoReportDailyController {
    @Autowired
    private IByteDanceVideoReportDailyService videoReportDailyService;


    @AutoLog(value = "头条视频账户视频关联方法")
    @ApiOperation(value = "头条视频账户视频关联方法", notes = "头条视频账户视频关联方法")
    @PostMapping(value = "/accountVideoMap")
    public Result accountVideoMap(HttpServletRequest req) {
        Result result = new Result();
        videoReportDailyService.accountVideoMap();
        result.setSuccess(true);
        return result;
    }

    @AutoLog(value = "头条视频按天汇总")
    @ApiOperation(value = "头条视频按天汇总", notes = "头条视频按天汇总")
    @PostMapping(value = "/bytedanceVideoInfoListDaily")
    public Result<PageInfo<ByteDanceVideoReportDaily>> bytedanceVideoInfoList(@RequestBody DateDTO dateDTO) {
        Result<PageInfo<ByteDanceVideoReportDaily>> result = new Result();
        Integer pageNo = dateDTO.getPageNo();
        Integer pageSize = dateDTO.getPageSize();
        if (pageNo == null) {
            pageNo = 0;
        }
        if (pageSize == null) {
            pageSize = 10;
        }
        PageInfo<ByteDanceVideoReportDaily> list = videoReportDailyService.videoInfoListDaily(dateDTO.getStartDate(), dateDTO.getEndDate(), dateDTO.getSignature(), dateDTO.getCost(), pageNo, pageSize, dateDTO.getProjectIds(), dateDTO.getAccountIds(), dateDTO.getSort());
        result.setResult(list);
        result.setSuccess(true);
        return result;
    }

    @AutoLog(value = "头条视频按周汇总")
    @ApiOperation(value = "头条视频按周汇总", notes = "头条视频按周汇总")
    @PostMapping(value = "/bytedanceVideoInfoListWeek")
    public Result<PageInfo<ByteDanceVideoReportDaily>> bytedanceVideoInfoListWeek(@RequestBody DateDTO dateDTO,
                                                                                  HttpServletRequest req) {
        Result<PageInfo<ByteDanceVideoReportDaily>> result = new Result();

        Integer pageNo = dateDTO.getPageNo();
        Integer pageSize = dateDTO.getPageSize();
        if (pageNo == null) {
            pageNo = 0;
        }
        if (pageSize == null) {
            pageSize = 10;
        }

        PageInfo<ByteDanceVideoReportDaily> list = videoReportDailyService.videoInfoListWeek(dateDTO.getStartDate(), dateDTO.getEndDate(), dateDTO.getSignature(), dateDTO.getCost(), pageNo, pageSize, dateDTO.getProjectIds(), dateDTO.getAccountIds(), dateDTO.getSort());
        result.setResult(list);
        result.setSuccess(true);
        return result;
    }

    @AutoLog(value = "头条视频汇总")
    @ApiOperation(value = "头条视频汇总", notes = "头条视频汇总")
    @PostMapping(value = "/videoInfoListTotal")
    public Result<PageInfo<ByteDanceVideoReportDaily>> videoInfoListTotal(@RequestBody DateDTO dateDTO,
                                                                          HttpServletRequest req) {
        Result<PageInfo<ByteDanceVideoReportDaily>> result = new Result();
        Integer pageNo = dateDTO.getPageNo();
        Integer pageSize = dateDTO.getPageSize();
        if (pageNo == null) {
            pageNo = 0;
        }
        if (pageSize == null) {
            pageSize = 10;
        }
        PageInfo<ByteDanceVideoReportDaily> list = videoReportDailyService.videoInfoListTotal(dateDTO.getStartDate(), dateDTO.getEndDate(), dateDTO.getSignature(), dateDTO.getCost(), pageNo, pageSize, dateDTO.getProjectIds(), dateDTO.getAccountIds(), dateDTO.getSort());
        result.setResult(list);
        result.setSuccess(true);
        return result;
    }

    @AutoLog(value = "头条视频按月汇总")
    @ApiOperation(value = "头条视频按月汇总", notes = "头条视频按月汇总")
    @PostMapping(value = "/bytedanceVideoInfoListMonth")
    public Result<PageInfo<ByteDanceVideoReportDaily>> bytedanceVideoInfoListMonth(@RequestBody DateDTO dateDTO,
                                                                                   HttpServletRequest req) {
        Result<PageInfo<ByteDanceVideoReportDaily>> result = new Result();

        if (StringUtils.isBlank(dateDTO.getSignature())) {
            dateDTO.setSignature(null);
        }
        Integer pageNo = dateDTO.getPageNo();
        Integer pageSize = dateDTO.getPageSize();
        if (pageNo == null) {
            pageNo = 0;
        }
        if (pageSize == null) {
            pageSize = 10;
        }
        PageInfo<ByteDanceVideoReportDaily> list = videoReportDailyService.videoInfoListMonth(dateDTO.getStartDate(), dateDTO.getEndDate(), dateDTO.getSignature(), dateDTO.getCost(), pageNo, pageSize, dateDTO.getProjectIds(), dateDTO.getAccountIds(), dateDTO.getSort());
        result.setResult(list);
        result.setSuccess(true);
        return result;
    }

    @AutoLog(value = "头条视频按天明细")
    @ApiOperation(value = "头条视频按天明细", notes = "头条视频按天明细")
    @PostMapping(value = "/bytedanceVideoInfoListDetail")
    public Result<List<ByteDanceVideoReportDaily>> bytedanceVideoInfoListDetail(@RequestBody DateDTO dateDTO,
                                                                                HttpServletRequest req) {
        Result<List<ByteDanceVideoReportDaily>> result = new Result();
        List<ByteDanceVideoReportDaily> list = videoReportDailyService.videoInfoListDetail(dateDTO.getStartDate(), dateDTO.getEndDate(), dateDTO.getSignature(), dateDTO.getAccountIds());
        result.setResult(list);
        result.setSuccess(true);
        return result;
    }

    @AutoLog(value = "查询视频报表保存的字段")
    @ApiOperation(value = "查询视频报表保存的字段", notes = "查询视频报表保存的字段")
    @PostMapping(value = "/getColumnJson")
    public Result<String> getColumnJson(@RequestBody ColumnDTO columnDTO, HttpServletRequest req) {
        Result<String> result = new Result();
        String json = videoReportDailyService.getColumnJson(columnDTO.getColumnType());
        result.setResult(json);
        result.setSuccess(true);
        return result;
    }

    @AutoLog(value = "保存或更新视频报表保存的字段")
    @ApiOperation(value = "保存或更新视频报表保存的字段", notes = "保存或更新视频报表保存的字段")
    @PostMapping(value = "/saveOrUpdateColumnJsonByAccountId")
    public Result<Object> saveOrUpdateColumnJsonByAccountId(@RequestBody ColumnDTO columnDTO) {
        try {
            Integer columnType = columnDTO.getColumnType();
            String json = columnDTO.getJson();
            Long accountId = columnDTO.getAccountId();
            if (Check.isNull(json) || Check.isNull(columnType) || Check.isNull(accountId)) {
                return Result.error("必填项为空");
            }
            videoReportDailyService.saveOrUpdateColumnJsonByAccountId(accountId, columnType, json);
            return Result.ok("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("执行异常，" + e.getMessage());
        }
    }

    @AutoLog(value = "查询视频报表保存的字段")
    @ApiOperation(value = "查询视频报表保存的字段", notes = "查询视频报表保存的字段")
    @PostMapping(value = "/getColumnJsonByAccountId")
    public Result<Object> getColumnJsonByAccountId(@RequestBody ColumnDTO columnDTO) {
        try {
            Integer columnType = columnDTO.getColumnType();
            Long accountId = columnDTO.getAccountId();
            if (Check.isNull(accountId) || Check.isNull(columnType)) {
                return Result.error("请选择账户和类型");
            }
            Result<Object> result = new Result();
            String json = videoReportDailyService.getColumnJsonByAccountId(accountId, columnType);
            result.setResult(json);
            result.setSuccess(true);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询异常，" + e.getMessage());
        }
    }

    @AutoLog(value = "保存或更新视频报表保存的字段")
    @ApiOperation(value = "保存或更新视频报表保存的字段", notes = "保存或更新视频报表保存的字段")
    @PostMapping(value = "/saveOrUpdateColumnJson")
    public Result saveOrUpdateColumnJson(@RequestBody ColumnDTO columnDTO, HttpServletRequest req) {
        Result result = new Result();
        videoReportDailyService.saveOrUpdateColumnJson(columnDTO.getColumnType(), columnDTO.getJson());
        result.setSuccess(true);
        return result;
    }

    @AutoLog(value = "头条视频汇总报表导出excel功能权限判断")
    @ApiOperation(value = "头条视频汇总报表导出excel功能权限判断", notes = "头条视频汇总报表导出excel功能权限判断")
    @PostMapping(value = "/videoInfoListTotalExportExcelPermission")
    public Result<Integer> videoInfoListTotalExportExcelPermission(HttpServletRequest req) {
        Result<Integer> result = new Result();
        int perCode = videoReportDailyService.videoInfoListTotalExportExcelPermission();
        result.setResult(perCode);
        result.setSuccess(true);
        return result;
    }

    @AutoLog(value = "视频报表按天明细导出Excel")
    @ApiOperation(value = "视频报表按天明细导出Excel", notes = "视频报表按天明细导出Excel")
    @PostMapping(value = "/bytedanceVideoInfoListDetailExportExcel")
    public void bytedanceVideoInfoListDetailExportExcel(@RequestBody DateDTO dateDTO,
                                                        HttpServletRequest request,
                                                        HttpServletResponse response) throws Exception {
        Result result = new Result<>();
        result.setSuccess(true);
        result.setMessage("success");

        //按天明细
        List<ByteDanceVideoReportDaily> list = videoReportDailyService.videoInfoListDetail(dateDTO.getStartDate(), dateDTO.getEndDate(), dateDTO.getSignature(), dateDTO.getAccountIds());

        //导出excel
        List<List<Object>> group = new ArrayList<>();
        if (!Check.isNull(list)) {
            for (ByteDanceVideoReportDaily sum : list) {
                List<Object> ByteDanceVideoReportDaily = new ArrayList();
                ByteDanceVideoReportDaily.add(sum.getAdvertiserName());  //客户
                ByteDanceVideoReportDaily.add(sum.getProjectName());  //项目名称
                ByteDanceVideoReportDaily.add(sum.getVideoUrl());  //视频链接
                ByteDanceVideoReportDaily.add(DateUtils.formatDate(sum.getStatDatetime()));  //时间
                ByteDanceVideoReportDaily.add(sum.getCost());  //消耗
                ByteDanceVideoReportDaily.add(sum.getHuanbi().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //环比
                group.add(ByteDanceVideoReportDaily);
            }
        }

        String[] groupHeaders = {"客户", "项目名称", "视频链接", "时间", "消耗", "环比"};
        OutputStream os = response.getOutputStream();
        ExportExcelUtils eeu = new ExportExcelUtils();
        XSSFWorkbook workbook = new XSSFWorkbook();
        eeu.exportExcel(workbook, 0, "周报表明细", groupHeaders, group);
        this.setResponseHeader(response, "周报表明细.xlsx");
        workbook.write(os);
        os.flush();
        os.close();
    }

    @AutoLog(value = "视频报表全局导出Excel")
    @ApiOperation(value = "视频报表全局导出Excel", notes = "视频报表全局导出Excel")
    @PostMapping(value = "/bytedanceVideoInfoListTotalExportExcel")
    public void bytedanceVideoInfoListTotal(@RequestBody DateDTO dateDTO,
                                            //@RequestParam("ids[]") Integer[] id2s,
                                            HttpServletRequest request,
                                            HttpServletResponse response) throws Exception {
        Result result = new Result<>();
        result.setSuccess(true);
        result.setMessage("success");

        //权限判断
        int perCode = videoReportDailyService.videoInfoListTotalExportExcelPermission();
        if (perCode == 0) {
            result.setMessage("无导出权限");
            result.setCode(500);
            return;
        }

        String[] columns = dateDTO.getColumns();

        List<ByteDanceVideoReportDaily> list = videoReportDailyService.videoInfoListTotalExcel(dateDTO.getStartDate(), dateDTO.getEndDate(), dateDTO.getSignature(), dateDTO.getCost(), dateDTO.getAccountIds(), dateDTO.getSort());

        //导出excel
        List<List<Object>> group = new ArrayList<>();
        if (!Check.isNull(list)) {
            for (ByteDanceVideoReportDaily sum : list) {
                List<Object> ByteDanceVideoReportDaily = new ArrayList();
                //循环
                for (String column : columns) {

                    if ("videoU".equals(column)) {
                        continue;
                    }

                    //if( column.equals("projectId")){
                    // ByteDanceVideoReportDaily.add(sum.getProjectId() );  //
                    // continue;
                    //}
                    //
                    if ("projectName".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getProjectName());  //
                        continue;
                    }

                    //if( column.equals("advertiserId")){
                    // ByteDanceVideoReportDaily.add(sum.getAdvertiserId() );  //
                    // continue;
                    //}
                    //
                    //if( column.equals("advertiserName")){
                    // ByteDanceVideoReportDaily.add(sum.getAdvertiserName() );  //
                    // continue;
                    //}

                    if ("statDatetime".equals(column)) {
                        ByteDanceVideoReportDaily.add(dateDTO.getStartDate() + "  ~  " + dateDTO.getEndDate());  //
                        continue;
                    }

                    if ("cost".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getCost().setScale(2, BigDecimal.ROUND_HALF_UP));  //
                        continue;
                    }

                    if ("signature".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getSignature());  //
                        continue;
                    }

                    if ("url".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getVideoUrl());  //下载的时候链接转换成头条的链接
                        continue;
                    }

                    if ("materialName".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getMaterialName());  //
                        continue;
                    }

                    if ("appType".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getAppType());  //
                        continue;
                    }

                    if ("clickMaterial".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getClickMaterial());  //
                        continue;
                    }

                    if ("play25FeedBreakRate".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getPlay25FeedBreakRate().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //
                        continue;
                    }

                    if ("playOverRate".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getPlayOverRate().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //
                        continue;
                    }

                    if ("convertRate".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getConvertRate().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //
                        continue;
                    }

                    if ("active".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getActive());  //
                        continue;
                    }

                    if ("downloadFinish".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getDownloadFinish());  //
                        continue;
                    }

                    if ("downloadStart".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getDownloadStart());  //
                        continue;
                    }

                    if ("installFinish".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getInstallFinish());  //
                        continue;
                    }

                    if ("register".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getRegister());  //
                        continue;
                    }

                    if ("payCount".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getPayCount());  //
                        continue;
                    }

                    //if( column.equals("inAppUv")){
                    // ByteDanceVideoReportDaily.add(sum.getInAppUv());  //
                    // continue;
                    //}

                    //if( column.equals("inAppDetailUv")){
                    // ByteDanceVideoReportDaily.add(sum.getInAppDetailUv());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("inAppCart")){
                    // ByteDanceVideoReportDaily.add(sum.getInAppCart());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("inAppOrder")){
                    // ByteDanceVideoReportDaily.add(sum.getInAppOrder());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("inAppPay")){
                    // ByteDanceVideoReportDaily.add(sum.getInAppPay());  //
                    // continue;
                    //}

                    //if( column.equals("phone")){
                    // ByteDanceVideoReportDaily.add(sum.getPhone());  //
                    // continue;
                    //}

                    if ("form".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getForm());  //
                        continue;
                    }

                    //if( column.equals("mapSearch")){
                    // ByteDanceVideoReportDaily.add(sum.getMapSearch());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("button")){
                    // ByteDanceVideoReportDaily.add(sum.getButton());  //
                    // continue;
                    //}

                    //if( column.equals("viewMaterial")){
                    // ByteDanceVideoReportDaily.add(sum.getViewMaterial());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("qq")){
                    // ByteDanceVideoReportDaily.add(sum.getQq());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("lottery")){
                    // ByteDanceVideoReportDaily.add(sum.getLottery());  //
                    // continue;
                    //}

                    //if( column.equals("vote")){
                    // ByteDanceVideoReportDaily.add(sum.getVote());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("redirect")){
                    // ByteDanceVideoReportDaily.add(sum.getRedirect());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("shopping")){
                    // ByteDanceVideoReportDaily.add(sum.getShopping());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("consult")){
                    // ByteDanceVideoReportDaily.add(sum.getConsult());  //
                    // continue;
                    //}

                    //if( column.equals("wechat")){
                    // ByteDanceVideoReportDaily.add(sum.getWechat());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("phoneConfirm")){
                    // ByteDanceVideoReportDaily.add(sum.getPhoneConfirm());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("phoneConnect")){
                    // ByteDanceVideoReportDaily.add(sum.getPhoneConnect());  //
                    // continue;
                    //}
                    //
                    //
                    //if( column.equals("consultEffective")){
                    // ByteDanceVideoReportDaily.add(sum.getConsultEffective());  //
                    // continue;
                    //}

                    if ("totalPlay".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getTotalPlay());  //
                        continue;
                    }

                    if ("validPlay".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getValidPlay());  //
                        continue;
                    }

                    if ("wifiPlay".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getWifiPlay());  //
                        continue;
                    }

                    if ("play25FeedBreak".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getPlay25FeedBreak());  //
                        continue;
                    }

                    if ("play50FeedBreak".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getPlay50FeedBreak());  //
                        continue;
                    }

                    if ("play75FeedBreak".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getPlay75FeedBreak());  //
                        continue;
                    }

                    if ("play100FeedBreak".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getPlay100FeedBreak());  //
                        continue;
                    }

                    //if( column.equals("advancedCreativePhoneClick")){
                    // ByteDanceVideoReportDaily.add(sum.getAdvancedCreativePhoneClick());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("advancedCreativeCounselClick")){
                    // ByteDanceVideoReportDaily.add(sum.getAdvancedCreativeCounselClick());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("advancedCreativeFormClick")){
                    // ByteDanceVideoReportDaily.add(sum.getAdvancedCreativeFormClick());  //
                    // continue;
                    //}

                    if ("shareMaterial".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getShowMaterial());  //
                        continue;
                    }

                    //if( column.equals("commentMaterial")){
                    // ByteDanceVideoReportDaily.add(sum.getCommentMaterial());  //
                    // continue;
                    //}

                    if ("follow".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getFollow());  //
                        continue;
                    }

                    //if( column.equals("homeVisited")){
                    // ByteDanceVideoReportDaily.add(sum.getHomeVisited());  //
                    // continue;
                    //}

                    //if( column.equals("iesChallengeClick")){
                    // ByteDanceVideoReportDaily.add(sum.getIesChallengeClick());  //
                    // continue;
                    //}

                    //if( column.equals("iesMusicClick")){
                    // ByteDanceVideoReportDaily.add(sum.getIesMusicClick());  //
                    // continue;
                    //}

                    if ("nextDayOpen".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getNextDayOpen());  //
                        continue;
                    }

                    if ("nextDayOpenRate".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getNextDayOpenRate().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //
                        continue;
                    }

                    if ("nextDayOpenCost".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getNextDayOpenCost().setScale(2, BigDecimal.ROUND_HALF_UP));  //
                        continue;
                    }

                    if ("activePayAmount".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getActivePayAmount());  //
                        continue;
                    }

                    if ("validPlayCost".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getValidPlayCost().setScale(2, BigDecimal.ROUND_HALF_UP));  //
                        continue;
                    }

                    //if( column.equals("advancedCreativeCouponAddition")){
                    // ByteDanceVideoReportDaily.add(sum.getAdvancedCreativeCouponAddition());  //
                    // continue;
                    //}

                    if ("convertMaterial".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getConvertMaterial());  //
                        continue;
                    }

                    if ("activePayCost".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getActivePayCost() == null ? 0 : sum.getActivePayCost().setScale(2, BigDecimal.ROUND_HALF_UP));  //
                        continue;
                    }

                    //if( column.equals("download")){
                    // ByteDanceVideoReportDaily.add(sum.getDownload());  //
                    // continue;
                    //}

                    if ("cpc".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getCpc().setScale(2, BigDecimal.ROUND_HALF_UP));  //
                        continue;
                    }

                    //if( column.equals("locationClick")){
                    // ByteDanceVideoReportDaily.add(sum.getLocationClick());  //
                    // continue;
                    //}

                    if ("ctr".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getCtr().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //
                        continue;
                    }

                    if ("cpm".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getCpm());  //
                        continue;
                    }

                    if ("wifiPlayRate".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getWifiPlayRate().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //
                        continue;
                    }

                    if ("likeMaterial".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getLikeMaterial());  //
                        continue;
                    }

                    if ("activeCost".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getActiveCost().setScale(2, BigDecimal.ROUND_HALF_UP));  //
                        continue;
                    }

                    if ("gameAddictionCost".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getGameAddictionCost().setScale(2, BigDecimal.ROUND_HALF_UP));  //
                        continue;
                    }

                    if ("gameAddiction".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getGameAddiction());  //
                        continue;
                    }

                    if ("activeRate".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getActiveRate().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //
                        continue;
                    }

                    if ("gameAddictionRate".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getGameAddictionRate().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //
                        continue;
                    }

                    if ("activeRegisterRate".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getActiveRegisterRate().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //
                        continue;
                    }

                    if ("downloadFinishCost".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getDownloadFinishCost().setScale(2, BigDecimal.ROUND_HALF_UP));  //
                        continue;
                    }

                    if ("activeRegisterCost".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getActiveRegisterCost().setScale(2, BigDecimal.ROUND_HALF_UP));  //
                        continue;
                    }

                    if ("showMaterial".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getShowMaterial());  //
                        continue;
                    }


                    if ("downloadFinishRate".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getDownloadFinishRate().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //
                        continue;
                    }

                    if ("installFinishRate".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getInstallFinishRate().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //
                        continue;
                    }
                    //
                    //if( column.equals("coupon")){
                    // ByteDanceVideoReportDaily.add(sum.getCoupon());  //
                    // continue;
                    //}
                    //
                    //if( column.equals("couponSinglePage")){
                    // ByteDanceVideoReportDaily.add(sum.getCouponSinglePage());  //
                    // continue;
                    //}

                    if ("playOver".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getPlayOver());  //
                        continue;
                    }

                    if ("downloadStartCost".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getDownloadStartCost().setScale(2, BigDecimal.ROUND_HALF_UP));  //
                        continue;
                    }

                    //if( column.equals("message")){
                    // ByteDanceVideoReportDaily.add(sum.getMessage());  //
                    // continue;
                    //}

                    if ("validPlayRate".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getValidPlayRate().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //
                        continue;
                    }

                    if ("averagePlayTimePerPlay".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getAveragePlayTimePerPlay().setScale(2, BigDecimal.ROUND_HALF_UP));  //
                        continue;
                    }

                    if ("convertCost".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getConvertCost().setScale(2, BigDecimal.ROUND_HALF_UP));  //
                        continue;
                    }

                    if ("installFinishCost".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getInstallFinishCost().setScale(2, BigDecimal.ROUND_HALF_UP));  //
                        continue;
                    }

                    if ("downloadStartRate".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getDownloadStartRate().multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP) + "%");  //
                        continue;
                    }

                    if ("companyId".equals(column)) {
                        ByteDanceVideoReportDaily.add(sum.getCompanyId());  //
                        continue;
                    }
                }

                group.add(ByteDanceVideoReportDaily);
            }
        }


        //String[] groupHeaders = {"客户", "视频链接", "时间", "消耗","环比"};
        List<String> listHeaders = new ArrayList<>();

        //循环
        for (String column : columns) {
            //if( column.equals("projectId")){
            // listHeaders.add("projectId");
            //}

            if ("projectName".equals(column)) {
                listHeaders.add("项目名称");
            }

            //if( column.equals("advertiserId")){
            // listHeaders.add("客户id");
            //}

            //if( column.equals("advertiserName")){
            // listHeaders.add("客户");
            //}

            if ("statDatetime".equals(column)) {
                listHeaders.add("时间");
            }  /////

            if ("cost".equals(column)) {
                listHeaders.add("消耗");
            }  /////

            if ("signature".equals(column)) {
                listHeaders.add("视频id");
            }  /////

            if ("url".equals(column)) {
                listHeaders.add("视频链接");
            }  /////

            if ("materialName".equals(column)) {
                listHeaders.add("视频描述");
            }  /////

            //if( column.equals("appType")){
            // listHeaders.add("媒体");
            //}

            if ("clickMaterial".equals(column)) {
                listHeaders.add("点击数");
            }  /////

            if ("play25FeedBreakRate".equals(column)) {
                listHeaders.add("25%进度播放率");
            }

            if ("playOverRate".equals(column)) {
                listHeaders.add("播完率");
            }  /////

            if ("convertRate".equals(column)) {
                listHeaders.add("转化率");
            }  /////

            if ("active".equals(column)) {
                listHeaders.add("激活数");
            }  /////

            if ("downloadFinish".equals(column)) {
                listHeaders.add("安卓下载完成数");
            }  /////

            if ("downloadStart".equals(column)) {
                listHeaders.add("安卓下载开始数");
            }  /////

            if ("installFinish".equals(column)) {
                listHeaders.add("安卓安装完成");
            }

            if ("register".equals(column)) {
                listHeaders.add("注册数");
            }

            if ("payCount".equals(column)) {
                listHeaders.add("付费次数");
            }  /////

            //if( column.equals("inAppUv")){
            // listHeaders.add("APP内访问");
            //}

            //if( column.equals("inAppDetailUv")){
            // listHeaders.add("APP内访问详情页");
            //}

            //if( column.equals("inAppCart")){
            // listHeaders.add("app内加入购物车");
            //}

            //if( column.equals("inAppOrder")){
            // listHeaders.add("app内下单");
            //}

            //if( column.equals("inAppPay")){
            // listHeaders.add("app内付费");
            //}

            //if( column.equals("phone")){
            // listHeaders.add("点击电话按钮");
            //}

            if ("form".equals(column)) {
                listHeaders.add("表单提交");
            }  /////

            //if( column.equals("mapSearch")){
            // listHeaders.add("地图搜索");
            //}  /////

            //if( column.equals("button")){
            // listHeaders.add("按钮button");
            //}  /////

            //if( column.equals("viewMaterial")){
            // listHeaders.add("关键页面浏览");
            //}  ////

            //if( column.equals("qq")){
            // listHeaders.add("QQ咨询");
            //}  /////

            //if( column.equals("lottery")){
            // listHeaders.add("抽奖");
            //}  /////

            //if( column.equals("vote")){
            // listHeaders.add("投票");
            //}  /////

            //if( column.equals("redirect")){
            // listHeaders.add("页面跳转");
            //}  /////

            //if( column.equals("shopping")){
            // listHeaders.add("商品购买");
            //}  /////

            //if( column.equals("consult")){
            // listHeaders.add("在线咨询");
            //}  ////

            //if( column.equals("wechat")){
            // listHeaders.add("微信复制");
            //}  ////

            //if( column.equals("phoneConfirm")){
            // listHeaders.add("智能电话-确认拨打");
            //}  /////

            //if( column.equals("phoneConnect")){
            // listHeaders.add("智能电话-确认接通");
            //}  /////


            //if( column.equals("consultEffective")){
            // listHeaders.add("有效咨询");
            //}  /////

            if ("totalPlay".equals(column)) {
                listHeaders.add("播放数");
            }  /////

            if ("validPlay".equals(column)) {
                listHeaders.add("有效播放数");
            }  /////

            if ("wifiPlay".equals(column)) {
                listHeaders.add("wifi播放");
            }

            if ("play25FeedBreak".equals(column)) {
                listHeaders.add("25%进度播放数");
            }

            if ("play50FeedBreak".equals(column)) {
                listHeaders.add("50%进度播放数");
            }

            if ("play75FeedBreak".equals(column)) {
                listHeaders.add("75%进度播放数");
            }

            if ("play100FeedBreak".equals(column)) {
                listHeaders.add("100%进度播放数");
            }

            //if( column.equals("advancedCreativePhoneClick")){
            // listHeaders.add("附加创意电话按钮点击");
            //}  /////

            //if( column.equals("advancedCreativeCounselClick")){
            // listHeaders.add("附加创意在线咨询点击");
            //}  /////

            //if( column.equals("advancedCreativeFormClick")){
            // listHeaders.add("附加创意表单按钮点击");
            //}  /////

            if ("shareMaterial".equals(column)) {
                listHeaders.add("分享数");
            }  /////

            //if( column.equals("commentMaterial")){
            // listHeaders.add("评论提交数");
            //}  /////

            if ("follow".equals(column)) {
                listHeaders.add("新增关注数");
            }  /////

            //if( column.equals("homeVisited")){
            // listHeaders.add("主页访问量");
            //}

            //if( column.equals("iesChallengeClick")){
            // listHeaders.add("挑战赛查看数");
            //}

            //if( column.equals("iesMusicClick")){
            // listHeaders.add("音乐查看数");
            //}  /////

            if ("nextDayOpen".equals(column)) {
                listHeaders.add("次留数");
            }  /////

            if ("nextDayOpenRate".equals(column)) {
                listHeaders.add("次留率");
            }  /////

            if ("nextDayOpenCost".equals(column)) {
                listHeaders.add("次留成本");
            }  /////

            if ("activePayAmount".equals(column)) {
                listHeaders.add("付费次数");
            }

            if ("validPlayCost".equals(column)) {
                listHeaders.add("有效播放成本");
            }  /////

            //if( column.equals("advancedCreativeCouponAddition")){
            // listHeaders.add("附加创意卡券领取");
            //}  /////

            if ("convertMaterial".equals(column)) {
                listHeaders.add("转化数");
            }

            if ("activePayCost".equals(column)) {
                listHeaders.add("付费成本");
            }  /////

            //if( column.equals("download")){
            // listHeaders.add("下载开始");
            //}  ////

            if ("cpc".equals(column)) {
                listHeaders.add("平均点击单价");
            }

            //if( column.equals("locationClick")){
            // listHeaders.add("POI点击数");
            //}

            if ("ctr".equals(column)) {
                listHeaders.add("点击率");
            }

            if ("cpm".equals(column)) {
                listHeaders.add("平均千次展现费用");
            }

            if ("wifiPlayRate".equals(column)) {
                listHeaders.add("WiFi播放占比");
            }  /////

            if ("likeMaterial".equals(column)) {
                listHeaders.add("点赞数");
            }  /////

            if ("activeCost".equals(column)) {
                listHeaders.add("激活成本");
            }  ////

            if ("gameAddictionCost".equals(column)) {
                listHeaders.add("关键行为成本");
            }  /////

            if ("gameAddiction".equals(column)) {
                listHeaders.add("关键行为数");
            }  ////

            if ("activeRate".equals(column)) {
                listHeaders.add("激活率");
            }  /////

            if ("gameAddictionRate".equals(column)) {
                listHeaders.add("关键行为率");
            }  /////

            if ("activeRegisterRate".equals(column)) {
                listHeaders.add("注册率");
            }  /////

            if ("downloadFinishCost".equals(column)) {
                listHeaders.add("安卓下载完成成本");
            }  /////

            if ("activeRegisterCost".equals(column)) {
                listHeaders.add("注册成本");
            }  ////

            if ("showMaterial".equals(column)) {
                listHeaders.add("展示数");
            }  /////

            if ("downloadFinishRate".equals(column)) {
                listHeaders.add("安卓下载完成率");
            }  /////

            if ("installFinishRate".equals(column)) {
                listHeaders.add("安卓安装完成率");
            }

            //if( column.equals("coupon")){
            // listHeaders.add("建站卡券领取");
            //}  /////

            //if( column.equals("couponSinglePage")){
            // listHeaders.add("卡券页领取");
            //}  /////

            if ("playOver".equals(column)) {
                listHeaders.add("完播数");
            }

            if ("downloadStartCost".equals(column)) {
                listHeaders.add("安卓下载开始成本");
            }  /////

            if ("message".equals(column)) {
                listHeaders.add("短信咨询");
            }  /////

            if ("validPlayRate".equals(column)) {
                listHeaders.add("有效播放率");
            }  /////

            if ("averagePlayTimePerPlay".equals(column)) {
                listHeaders.add("平均单次播放时长");
            }

            if ("convertCost".equals(column)) {
                listHeaders.add("转化成本");
            }

            if ("installFinishCost".equals(column)) {
                listHeaders.add("安卓安装完成成本");
            }

            if ("downloadStartRate".equals(column)) {
                listHeaders.add("安卓下载开始率");
            }  /////

            //if( column.equals("companyId")){
            // listHeaders.add("companyId");
            //}
        }

        String[] groupHeaders = listHeaders.toArray(new String[listHeaders.size()]);

        OutputStream os = response.getOutputStream();
        ExportExcelUtils eeu = new ExportExcelUtils();
        XSSFWorkbook workbook = new XSSFWorkbook();
        eeu.exportExcel(workbook, 0, "头条视频总报表", groupHeaders, group);
        this.setResponseHeader(response, "头条视频总报表.xlsx");
        workbook.write(os);
        os.flush();
        os.close();
    }

    //发送响应流方法
    public void setResponseHeader(HttpServletResponse response, String fileName) {
        try {
            try {
                fileName = new String(fileName.getBytes(), "ISO8859-1");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            response.setContentType("application/octet-stream;charset=ISO8859-1");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.addHeader("Pargam", "no-cache");
            response.addHeader("Cache-Control", "no-cache");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }


}
