package cn.com.tenlion.freemarker.util;

import cn.com.tenlion.freemarker.pojo.dtos.templateconfig.TemplateConfigDTO;
import cn.com.tenlion.freemarker.service.templateconfig.ITemplateConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class TemplateMapInit implements ApplicationRunner {

    @Autowired
    ITemplateConfigService iTemplateConfigService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        List<TemplateConfigDTO> list = iTemplateConfigService.listTemplateConfig(map);
        for (TemplateConfigDTO template: list) {
            TemplateBuilderUtil.getInstance().pushTemplate(template.getTemplateCode(), template);
        }
    }

}
