|
|
package com.yoho.yhmessage.rest;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import com.yoho.message.dal.MessageSensitiveWordsMapper;
|
|
|
import com.yoho.message.dal.model.MessageSensitiveWords;
|
|
|
import com.yoho.service.model.sms.response.CommonRspBO;
|
|
|
|
|
|
@Controller
|
|
|
@RequestMapping("/FilterInfoRest")
|
|
|
public class FilterInfoRest {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(FilterInfoRest.class);
|
|
|
|
|
|
@Autowired
|
|
|
private MessageSensitiveWordsMapper messageSensitiveWordsMapper;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* Description: 添加敏感词<br>
|
|
|
*
|
|
|
* @author amos.shan<br>
|
|
|
* @taskId <br>
|
|
|
* @return <br>
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
@SuppressWarnings("resource")
|
|
|
@RequestMapping(value = "/addSensitiveWords")
|
|
|
@ResponseBody
|
|
|
public CommonRspBO addSensitiveWords() throws IOException {
|
|
|
CommonRspBO commonRspBO = new CommonRspBO(200, "OK");
|
|
|
List<MessageSensitiveWords> wordList = null;
|
|
|
File file = new File("D:\\SensitiveWord.txt"); // 读取文件
|
|
|
InputStreamReader read = new InputStreamReader(new FileInputStream(file), "UTF-8");
|
|
|
try {
|
|
|
if (file.isFile() && file.exists()) { // 文件流是否存在
|
|
|
wordList = new ArrayList<MessageSensitiveWords>();
|
|
|
BufferedReader bufferedReader = new BufferedReader(read);
|
|
|
String txt = null;
|
|
|
while ((txt = bufferedReader.readLine()) != null) {
|
|
|
MessageSensitiveWords word = new MessageSensitiveWords();
|
|
|
word.setSensitiveWord(txt);
|
|
|
wordList.add(word);
|
|
|
}
|
|
|
messageSensitiveWordsMapper.insertSensitiveWordsBatch(wordList);
|
|
|
} else {
|
|
|
commonRspBO.setCode(-1);
|
|
|
commonRspBO.setMessage("敏感词库不存在");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
commonRspBO.setCode(-1);
|
|
|
commonRspBO.setMessage(e.getMessage());
|
|
|
} finally {
|
|
|
read.close(); // 关闭文件流
|
|
|
}
|
|
|
return commonRspBO;
|
|
|
}
|
|
|
} |
...
|
...
|
|