package cn.axzo.msg.center.notices.manager;

import java.util.ArrayList;

import org.junit.jupiter.api.Test;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.fastjson.JSONObject;

import lombok.Getter;
import lombok.Setter;

/**
 * @author yanglin
 */
public class VolcImportTest {

    @Test
    void gen() {
        String filePath = "/Users/yanglin/Desktop/1.xlsx";
        ArrayList<JSONObject> templates = new ArrayList<>();
        EasyExcel.read(filePath, Row.class, new ReadListener<Row>() {
            @Override public void invoke(Row row, AnalysisContext context) {
                JSONObject template = new JSONObject();
                template.put("serviceName", "add");
                template.put("messageTemplateType", 1);
                template.put("innerTemplateNo", row.getInnerTemplateNo());
                template.put("channelTemplateCode", row.getVolcTemplateNo());
                template.put("title", row.getTitle());
                template.put("templateContent", row.getContent());
                template.put("remark", "");
                template.put("channel", "volc");
                templates.add(template);
            }

            @Override
            public void doAfterAllAnalysed(AnalysisContext context) {
            }
        }).sheet().doRead();
        System.out.println(templates);
    }

    @Setter @Getter
    public static class Row {
        @ExcelProperty(index = 0)
        private String innerTemplateNo;
        @ExcelProperty(index = 1)
        private String aliyunTemplateNo;
        @ExcelProperty(index = 2)
        private String volcTemplateNo;
        @ExcelProperty(index = 3)
        private String volcRemark;
        @ExcelProperty(index = 4)
        private String templateType;
        @ExcelProperty(index = 5)
        private String title;
        @ExcelProperty(index = 6)
        private String content;
    }
}
