package cn.com.countrygarden.bi.main.service.ck.impl;

import cn.com.countrygarden.bi.main.service.ck.CkDataExportHandler;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 服务可视化数据维护
 *
 * @ClassName:CkBiDataExportHandler.java
 * @Description:功能描述
 * @author: lisenlin
 * @date: 2020/9/18
 */
@Service("ckBi")
public class CkBiDataExportHandler implements CkDataExportHandler {

    @Override
    public void buildData(List<List<String>> rowsDatas) {
        ArrayList<String> strings = CollUtil.newArrayList("合计", "");
        List<String> rowsData = rowsDatas.get(0);
        for (int i1 = 2; i1 < rowsData.size(); i1++) {
            strings.add(count(rowsDatas, i1));
        }
        rowsDatas.set(0, strings);
    }

    private String count(List<List<String>> rowsDatas, int i1) {
        BigDecimal result = new BigDecimal(0);
        for (int i = 0; i < rowsDatas.size(); i++) {
            result=result.add(Convert.toBigDecimal(rowsDatas.get(i).get(i1), BigDecimal.ZERO));
        }
        return result.intValue() + "";
    }


    @Override
    public void buildWorkBook(XSSFWorkbook workbook) {
//      处理采用的合并之类的逻辑
        try{
            workbook.getSheetAt(0).addMergedRegion(new CellRangeAddress(2,2,0,1));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
