package com.cm.plugin.startup;

import com.cm.plugin.manager.SensitiveWordsManager;
import com.cm.plugin.service.ISensitiveWordsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.List;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: SensitiveWordsStartUp
 * @Description: 敏感词启动
 * @Author: WangGeng
 * @Date: 2020/6/17 20:21
 * @Version: 1.0
 **/
@Component
public class SensitiveWordsStartUp implements ApplicationRunner {

    private static final Logger LOG = LoggerFactory.getLogger(SensitiveWordsStartUp.class);

    @Autowired
    private ISensitiveWordsService sensitiveWordsService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        LOG.debug("初始化敏感词开始");
        long startTime = System.currentTimeMillis();
        List<String> sensitiveWords = sensitiveWordsService.listSensitiveWordsForString();
        SensitiveWordsManager.getInstance().initSensitiveWords(sensitiveWords);
        long endTime = System.currentTimeMillis();
        LOG.debug("初始化敏感词结束，耗时：{}ms", (endTime - startTime));
    }

}
