package com.huijy.management.service.impl;

import java.util.List;
import java.util.Set;

import com.huijy.common.constant.Constants;
import com.huijy.common.core.redis.RedisCache;
import com.huijy.common.utils.DateUtils;
import com.huijy.common.utils.SensitiveWordUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.huijy.management.mapper.TSensitiveWordsMapper;
import com.huijy.management.domain.TSensitiveWords;
import com.huijy.management.service.ITSensitiveWordsService;

/**
 * 敏感词Service业务层处理
 *
 * @author huijy
 * @date 2021-08-30
 */
@Service
public class TSensitiveWordsServiceImpl implements ITSensitiveWordsService
{
    @Autowired
    private TSensitiveWordsMapper tSensitiveWordsMapper;
    @Autowired
    private RedisCache redisCache;

    /**
     * 查询敏感词
     *
     * @param sensitiveWordsId 敏感词主键
     * @return 敏感词
     */
    @Override
    public TSensitiveWords selectTSensitiveWordsBySensitiveWordsId(Long sensitiveWordsId)
    {
        return tSensitiveWordsMapper.selectTSensitiveWordsBySensitiveWordsId(sensitiveWordsId);
    }

    /**
     * 查询敏感词列表
     *
     * @param tSensitiveWords 敏感词
     * @return 敏感词
     */
    @Override
    public List<TSensitiveWords> selectTSensitiveWordsList(TSensitiveWords tSensitiveWords)
    {
        return tSensitiveWordsMapper.selectTSensitiveWordsList(tSensitiveWords);
    }

    /**
     * 新增敏感词
     *
     * @param tSensitiveWords 敏感词
     * @return 结果
     */
    @Override
    public int insertTSensitiveWords(TSensitiveWords tSensitiveWords)
    {
        tSensitiveWords.setCreateTime(DateUtils.getNowDate());
        return tSensitiveWordsMapper.insertTSensitiveWords(tSensitiveWords);
    }

    /**
     * 修改敏感词
     *
     * @param tSensitiveWords 敏感词
     * @return 结果
     */
    @Override
    public int updateTSensitiveWords(TSensitiveWords tSensitiveWords)
    {
        return tSensitiveWordsMapper.updateTSensitiveWords(tSensitiveWords);
    }

    /**
     * 批量删除敏感词
     *
     * @param sensitiveWordsIds 需要删除的敏感词主键
     * @return 结果
     */
    @Override
    public int deleteTSensitiveWordsBySensitiveWordsIds(Long[] sensitiveWordsIds)
    {
        return tSensitiveWordsMapper.deleteTSensitiveWordsBySensitiveWordsIds(sensitiveWordsIds);
    }

    /**
     * 删除敏感词信息
     *
     * @param sensitiveWordsId 敏感词主键
     * @return 结果
     */
    @Override
    public int deleteTSensitiveWordsBySensitiveWordsId(Long sensitiveWordsId)
    {
        return tSensitiveWordsMapper.deleteTSensitiveWordsBySensitiveWordsId(sensitiveWordsId);
    }

    @Override
    public void useSensitiveWords() {
        Set<String> keys = tSensitiveWordsMapper.getSensitiveWordsSet();
        redisCache.setCacheSet(Constants.SENSITIVE_WORD_KEY,keys);
        SensitiveWordUtil.init();
    }
}
