|
|
package com.yoho.yhmessage.rest;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
...
|
...
|
@@ -36,29 +35,23 @@ public class FilterInfoRest { |
|
|
* @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");
|
|
|
InputStream in = FilterInfoRest.class.getResourceAsStream("SensitiveWord.txt"); // 读取文件
|
|
|
InputStreamReader read = new InputStreamReader(in, "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("敏感词库不存在");
|
|
|
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);
|
|
|
} catch (Exception e) {
|
|
|
commonRspBO.setCode(-1);
|
|
|
commonRspBO.setMessage(e.getMessage());
|
...
|
...
|
|