package com.lsw;

import com.jfinal.config.*;
import com.jfinal.core.JFinal;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.kit.PathKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
import com.jfinal.plugin.activerecord.dialect.OracleDialect;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;
import com.lsw.controller.*;

/**
 * @author 李书文
 * @description 应用程序入口
 * @time 2016年10月22日
 */
public class Application extends JFinalConfig {

    @Override
    public void configConstant(Constants me) {
        loadPropertyFile("jdbc.properites");//加载配置文件2
        me.setDevMode(true);
    }

    @Override
    public void configRoute(Routes me) {
        me.add("/", IndexController.class, "/WEB-INF/view/");
        me.add("/report", ReportController.class, "/WEB-INF/view/report");
        me.add("/big", BigScreenController.class, "/WEB-INF/view/big-screen");
        me.add("/app", AppController.class, "/WEB-INF/view/app");
        me.add("/export", ExportController.class, "/WEB-INF/view/export");
    }

    @Override
    public void configPlugin(Plugins me) {
        ActiveRecordPlugin arp = null;
        String driver = getProperty("oracle.driver");
        String url = getProperty("oracle.url");
        String username = getProperty("oracle.username");
        String password = getProperty("oracle.password");
        DruidPlugin dp = new DruidPlugin(url, username, password, driver);
        me.add(dp);
        arp = new ActiveRecordPlugin(dp);//设置数据库方言
        arp.addSqlTemplate("report.sql");
        arp.addSqlTemplate("big.sql");
        arp.setDialect(new OracleDialect());
        arp.setContainerFactory(new CaseInsensitiveContainerFactory());//忽略大小写
        arp.setShowSql(true);
        me.add(arp);
    }

    @Override
    public void configInterceptor(Interceptors me) {
    }

    @Override
    public void configHandler(Handlers me) {
        me.add(new ContextPathHandler("path"));
    }

    private void welcome() {
        System.out.println("系统启动完成 ");
    }

    public static void main(String[] args) {
        JFinal.start("src/main/webapp", 9999, "/", 5);
    }

    @Override
    public void configEngine(Engine me) {
        me.addSharedFunction("/WEB-INF/view/common/header.html"); //头部
    }

}
