package com.yihu.jw.wechat.service;


import com.yihu.jw.entity.base.words.BaseSensitiveDO;
import com.yihu.jw.file_upload.FileUploadService;
import com.yihu.jw.hospital.prescription.dao.BaseSensitiveDao;
import com.yihu.jw.utils.SensitivewordFilter;
import com.yihu.mysql.query.BaseJpaService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;

/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2020/7/6
 */
@Service
public class BaseSensitiveFilterWordsService extends BaseJpaService<BaseSensitiveDO, BaseSensitiveDao> {



    @Autowired
    FileUploadService fileUploadService;


    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(BaseSensitiveFilterWordsService.class);

    /**
     * 敏感词过滤
     * @param txt
     * @return
     */
    public String filterSensitiveWords(String txt, List<BaseSensitiveDO> list){
        HashSet<String> set = new HashSet<>();
        for (BaseSensitiveDO one : list) {
            set.add(one.getSensitiveWord());
        }
        SensitivewordFilter filter = new SensitivewordFilter(set);
        /*Set<String> words = filter.getSensitiveWord(txt, 1);*/
        String replaceTxt = filter.replaceSensitiveWord(txt, 1, "***");
        return replaceTxt;
    }
}





