package cc.smtweb.system.bpm.web;

import cc.smtweb.framework.core.annotation.SwStartListener;
import cc.smtweb.framework.core.cache.CacheManager;
import cc.smtweb.framework.core.common.SwConsts;
import cc.smtweb.framework.core.db.impl.DatabaseUtil;
import cc.smtweb.framework.core.db.vo.ModelCatalog;
import cc.smtweb.framework.core.mvc.controller.IStartListener;
import cc.smtweb.framework.core.mvc.service.TreeHelper;
import cc.smtweb.framework.core.systask.SysServiceFactory;
import cc.smtweb.framework.core.systask.SysThreadPool;
import cc.smtweb.system.bpm.web.design.db.ModelCatalogTreeHelper;
import cc.smtweb.system.bpm.web.sys.base.job.JobUtils;
import cc.smtweb.system.bpm.web.sys.oneTimeService.OneTimeServiceFactory;
import cc.smtweb.system.bpm.web.sys.oneTimeService.OneTimeTaskCleanService;

/**
 * Created by Akmm at 2022/7/8 19:57
 */
@SwStartListener()
public class BpmStartedListener implements IStartListener {
    public int order() {
        return SwConsts.DEFAULT_ORDER + 1;
    }

    @Override
    public void init() {
        SwConsts.SysParam.RUN_PROJECTS = "bpm";
        SysServiceFactory.getInstance().reg(new OneTimeTaskCleanService());
        TreeHelper.regTreeHelper(ModelCatalog.ENTITY_NAME, ModelCatalogTreeHelper.class);

    }

    @Override
    public void run() {
        //初始化数据库
        new DatabaseUtil(true, false).checkDb();
        //初始化缓存
        CacheManager.getIntance().init();
        OneTimeServiceFactory.getInstance().start();
        JobUtils.getInstance().start();
    }

    @Override
    public void close() {
        OneTimeServiceFactory.getInstance().stop();
        JobUtils.getInstance().stop();
        SysThreadPool.getInstance().stop();
    }
}
