package cn.wise.sc.energy.power.plant.business.utils.poi;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import cn.afterturn.easypoi.entity.ImageEntity;
import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.SpiderWebPlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.chart.ui.RectangleEdge;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 * @author 何昌杰
 */
public class WordDemo1 {

    public static void main(String[] args) throws IOException {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        String group1 = "huawei ";
        dataset.addValue(5, group1, "w1");
        dataset.addValue(6, group1, "w2");
        dataset.addValue(4, group1, "w3");
        dataset.addValue(2, group1, "w4");
        dataset.addValue(5, group1, "w5");
        dataset.addValue(5, group1, "w6");
        dataset.addValue(5, group1, "w7");
        dataset.addValue(8, group1, "w8");
        group1 = "apple ";
        dataset.addValue(2, group1, "w1");
        dataset.addValue(4, group1, "w2");
        dataset.addValue(4, group1, "w3");
        dataset.addValue(5, group1, "w4");
        dataset.addValue(5, group1, "w5");
        dataset.addValue(8, group1, "w6");
        dataset.addValue(9, group1, "w7");
        dataset.addValue(8, group1, "w8");

        SpiderWebPlot spiderwebplot = new SpiderWebPlot(dataset);

        JFreeChart jfreechart = new JFreeChart("Test", TextTitle.DEFAULT_FONT, spiderwebplot, false);
        LegendTitle legendtitle = new LegendTitle(spiderwebplot);
        legendtitle.setPosition(RectangleEdge.TOP);
        jfreechart.addSubtitle(legendtitle);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ChartUtils.writeChartAsPNG(out, jfreechart, 400, 500);
        ImageEntity imageEntity = new ImageEntity(out.toByteArray(), 200, 200);
        //word模板相对路径、word生成路径、word生成的文件名称、数据源

        HashMap<String, Object> map = new HashMap<>(4);
        long startTime = System.currentTimeMillis();
        //模拟饼状图数据
        HashMap<String, Integer> datas = new HashMap<>(3);
        datas.put("一号", 10);
        datas.put("二号", 20);
        datas.put("三号", 40);
        ImageEntity imageEntity1 = JfreeUtil.pieChart("测试", datas, 200, 200);
        map.put("picture", imageEntity);
        map.put("picture1", imageEntity1);

        //模拟其它普通数据
        map.put("username", "张三");
        map.put("date", "2019-10-10");
        map.put("desc", "测试");
        map.put("boo", true);
        //模拟表格数据
        ArrayList<HashMap<String, String>> list = new ArrayList<>(2);
        HashMap<String, String> temp = new HashMap<>(3);
        temp.put("sn", "1");
        temp.put("name", "第一个人");
        temp.put("age", "23");
        list.add(temp);
        for (int i = 0; i < 100; i++) {
            temp = new HashMap<>(3);
            temp.put("sn", "2");
            temp.put("name", "第二个人");
            temp.put("age", "24");
            list.add(temp);
        }

        map.put("personlist", list);

       // WordUtils.exportWord("C:\\Users\\admin\\Desktop\\template\\demo1.docx", "D:/", "生成文件.docx", map);
    }
}