package com.ruoyi.sensitive.config;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.houbb.heaven.support.handler.IHandler;
import com.github.houbb.heaven.util.util.CollectionUtil;
import com.github.houbb.sensitive.word.api.IWordDeny;
import com.ruoyi.sensitive.domain.Word;
import com.ruoyi.sensitive.service.WordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author binbin.hou
 * @since 1.1.0
 */
@Component
public class MyDdWordDeny implements IWordDeny {

    @Autowired
    private WordService wordService;

    @Override
    public List<String> deny() {
        List<Word> wordList = wordService.list(Wrappers.lambdaQuery(Word.class)
                .select(Word::getWord)
                .eq(Word::getEnableStatus,1)
                .eq(Word::getType, 2));

        return CollectionUtil.toList(wordList, new IHandler<Word, String>() {
            @Override
            public String handle(Word word) {
                return word.getWord();
            }
        });
    }

}
