package com.mortals.xhx.common.utils;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.config.ConfigureBuilder;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.deepoove.poi.plugin.table.MultipleRowTableRenderPolicy;
import com.mortals.xhx.base.system.gentable.model.GentableColumnEntity;
import com.mortals.xhx.base.system.gentable.model.GentableEntity;
import com.mortals.xhx.base.system.gentable.model.ProjectInfoEntity;
import lombok.var;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: zxfei
 * @date: 2022/5/16 23:11
 * @description:
 **/
public class PoiTlUtils {

    @Test
    public void testData() throws Exception{
        List<GentableEntity> tableList = new ArrayList<>();

        GentableEntity gentableEntity = new GentableEntity();
        gentableEntity.setTableName("test");
        gentableEntity.setFunctionName("ddddddd");

        List<GentableColumnEntity> columns = new ArrayList<>();
        GentableColumnEntity columnEntity = new GentableColumnEntity();
        columnEntity.initAttrValue();

        columns.add(columnEntity);
        gentableEntity.setColumns(columns);


        tableList.add(gentableEntity);
        tableList.add(gentableEntity);
        ProjectInfoEntity projectInfo=new ProjectInfoEntity();
        projectInfo.setPlatFormName("测试平台");
        Map data = new HashMap();
        data.put("tableList", tableList);
        data.put("projectInfo", projectInfo);

        ConfigureBuilder builder = Configure.builder();
        builder.bind("columns", new MultipleRowTableRenderPolicy());

        LoopRowTableRenderPolicy hackLoopTableRenderPolicy = new LoopRowTableRenderPolicy();
       // Configure config = Configure.builder().useSpringEL().bind("columns", hackLoopTableRenderPolicy).build();
        Configure config = Configure.builder().useSpringEL().bind("columns", new MultipleRowTableRenderPolicy()).build();

        XWPFTemplate template = XWPFTemplate.compile("src/test/resources/okr/base.docx",config).render(data);
        template.writeToFile("target/base.docx");
    }



}
