|
@ -6,6 +6,8 @@ import com.yihu.jw.base.dao.word.BaseSensitiveDao;
|
|
import com.yihu.jw.base.service.doctor.excelImport.BaseDoctorExcelDO;
|
|
import com.yihu.jw.base.service.doctor.excelImport.BaseDoctorExcelDO;
|
|
import com.yihu.jw.base.service.word.excelImport.BaseSensitiveExcelDO;
|
|
import com.yihu.jw.base.service.word.excelImport.BaseSensitiveExcelDO;
|
|
import com.yihu.jw.base.useragent.UserAgent;
|
|
import com.yihu.jw.base.useragent.UserAgent;
|
|
|
|
import com.yihu.jw.base.util.SensitiveWordInit;
|
|
|
|
import com.yihu.jw.base.util.SensitivewordFilter;
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
import com.yihu.jw.entity.base.sync.BaseSyncDataDO;
|
|
import com.yihu.jw.entity.base.sync.BaseSyncDataDO;
|
|
@ -18,6 +20,8 @@ import com.yihu.jw.rm.health.house.HealthyHouseMapping;
|
|
import com.yihu.jw.rm.iot.IotRequestMapping;
|
|
import com.yihu.jw.rm.iot.IotRequestMapping;
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
|
|
import jxl.Workbook;
|
|
|
|
import jxl.write.*;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
@ -98,9 +102,11 @@ public class BaseSensitiveService extends BaseJpaService<BaseSensitiveDO, BaseSe
|
|
* @param ids
|
|
* @param ids
|
|
*/
|
|
*/
|
|
public void delSensitiveWords(String ids) {
|
|
public void delSensitiveWords(String ids) {
|
|
List<String> list = JSONObject.parseObject(ids, List.class);
|
|
|
|
|
|
String[] list = ids.split(",");
|
|
for (String id : list) {
|
|
for (String id : list) {
|
|
baseSensitiveDao.delete(id);
|
|
|
|
|
|
if (StringUtils.isNotEmpty(id)){
|
|
|
|
baseSensitiveDao.delete(id);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@ -110,14 +116,16 @@ public class BaseSensitiveService extends BaseJpaService<BaseSensitiveDO, BaseSe
|
|
* @param status
|
|
* @param status
|
|
*/
|
|
*/
|
|
public void updateSensitiveWordsStatus(String ids, String status,String operatorCode,String name) {
|
|
public void updateSensitiveWordsStatus(String ids, String status,String operatorCode,String name) {
|
|
List<String> list = JSONObject.parseObject(ids, List.class);
|
|
|
|
|
|
String[] list = ids.split(",");
|
|
for (String id : list) {
|
|
for (String id : list) {
|
|
BaseSensitiveDO baseSensitiveDO = baseSensitiveDao.findOne(id);
|
|
|
|
baseSensitiveDO.setStatus(status);
|
|
|
|
baseSensitiveDO.setUpdateTime(DateUtil.getNowDate());
|
|
|
|
baseSensitiveDO.setOperatorCode(operatorCode);
|
|
|
|
baseSensitiveDO.setOperator(name);
|
|
|
|
baseSensitiveDao.save(baseSensitiveDO);
|
|
|
|
|
|
if (StringUtils.isNotEmpty(id)){
|
|
|
|
BaseSensitiveDO baseSensitiveDO = baseSensitiveDao.findOne(id);
|
|
|
|
baseSensitiveDO.setStatus(status);
|
|
|
|
baseSensitiveDO.setUpdateTime(DateUtil.getNowDate());
|
|
|
|
baseSensitiveDO.setOperatorCode(operatorCode);
|
|
|
|
baseSensitiveDO.setOperator(name);
|
|
|
|
baseSensitiveDao.save(baseSensitiveDO);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@ -133,7 +141,7 @@ public class BaseSensitiveService extends BaseJpaService<BaseSensitiveDO, BaseSe
|
|
public MixEnvelop findSensitiveWords(String status, String words, Integer page, Integer pageSize) {
|
|
public MixEnvelop findSensitiveWords(String status, String words, Integer page, Integer pageSize) {
|
|
StringBuffer sql = new StringBuffer("select * from base_sensitive s where 1=1 ");
|
|
StringBuffer sql = new StringBuffer("select * from base_sensitive s where 1=1 ");
|
|
StringBuffer countSql = new StringBuffer("select count(*) count from base_sensitive s where 1=1 ");
|
|
StringBuffer countSql = new StringBuffer("select count(*) count from base_sensitive s where 1=1 ");
|
|
if (StringUtils.isNotEmpty(status)){
|
|
|
|
|
|
if (!status.equalsIgnoreCase("null")){
|
|
sql.append(" AND s.status='").append(status).append("'");
|
|
sql.append(" AND s.status='").append(status).append("'");
|
|
countSql.append(" AND s.status='").append(status).append("'");
|
|
countSql.append(" AND s.status='").append(status).append("'");
|
|
}
|
|
}
|
|
@ -152,15 +160,48 @@ public class BaseSensitiveService extends BaseJpaService<BaseSensitiveDO, BaseSe
|
|
|
|
|
|
/**
|
|
/**
|
|
* 导出敏感词日志
|
|
* 导出敏感词日志
|
|
* @param operatorCode
|
|
|
|
|
|
* @param
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public MixEnvelop exportSensitiveWordsLog(HttpServletResponse response,String operatorCode){
|
|
|
|
String sql="SELECT * FROM base_import_sensitive b WHERE b.create_time=(SELECT MAX(b.create_time) FROM base_import_sensitive b) and b.operator_code='"+operatorCode+"'";
|
|
|
|
//获取日志
|
|
|
|
|
|
public String exportSensitiveWordsLog(OutputStream os,String operatorCode,String path) throws Exception {
|
|
|
|
String sql="SELECT * FROM base_import_sensitive b WHERE b.create_time=(SELECT MAX(b.create_time) FROM base_import_sensitive b WHERE b.operator_code='"+operatorCode+"') ";
|
|
List<BaseImportSensitiveDO> list =jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BaseImportSensitiveDO.class));
|
|
List<BaseImportSensitiveDO> list =jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BaseImportSensitiveDO.class));
|
|
|
|
|
|
|
|
// WritableWorkbook wwb = jxl.Workbook.createWorkbook(os);
|
|
|
|
//
|
|
|
|
// try {
|
|
|
|
// WritableSheet ws;
|
|
|
|
// ws = wwb.createSheet("sheet", 1);
|
|
|
|
//
|
|
|
|
// String[] header = {"序号", "原因"};
|
|
|
|
// int k = 0;
|
|
|
|
// for (String h : header) {
|
|
|
|
// addCell(ws, 0, k, h);//表名,行,列,header
|
|
|
|
// k++;
|
|
|
|
// }
|
|
|
|
// int i = 1;
|
|
|
|
//
|
|
|
|
// for (BaseImportSensitiveDO one : list) {
|
|
|
|
// addCell(ws, i, 0,one.getRow() , "");
|
|
|
|
// addCell(ws, i, 1, one.getProblem(), "");
|
|
|
|
// i++;
|
|
|
|
// }
|
|
|
|
// wwb.write();
|
|
|
|
// wwb.close();
|
|
|
|
// } catch (IOException e) {
|
|
|
|
// e.printStackTrace();
|
|
|
|
// if (wwb != null){
|
|
|
|
// wwb.close();
|
|
|
|
// }
|
|
|
|
// throw e;
|
|
|
|
// }
|
|
|
|
// byte[] bytes = wwb.toString().getBytes();
|
|
|
|
// InputStream in = new ByteArrayInputStream(bytes) {
|
|
|
|
// };
|
|
|
|
// UploadVO uploadVO = fileUploadService.uploadStream(in, "sentitiveLog.xls", path);
|
|
//拼接字符串
|
|
//拼接字符串
|
|
StringBuffer text = new StringBuffer();
|
|
StringBuffer text = new StringBuffer();
|
|
|
|
text.append("序号").append(" ").append("原因");
|
|
for(BaseImportSensitiveDO one:list){
|
|
for(BaseImportSensitiveDO one:list){
|
|
text.append("第");
|
|
text.append("第");
|
|
text.append(one.getRow());
|
|
text.append(one.getRow());
|
|
@ -170,35 +211,36 @@ public class BaseSensitiveService extends BaseJpaService<BaseSensitiveDO, BaseSe
|
|
text.append("\r\n");//换行字符
|
|
text.append("\r\n");//换行字符
|
|
}
|
|
}
|
|
byte[] bytes = text.toString().getBytes();
|
|
byte[] bytes = text.toString().getBytes();
|
|
OutputStream os = null;
|
|
|
|
try {
|
|
|
|
os = response.getOutputStream();
|
|
|
|
response.addHeader("Content-Type", "multipart/form-data");
|
|
|
|
os.write(bytes);
|
|
|
|
os.flush();
|
|
|
|
}catch (Exception e){
|
|
|
|
e.printStackTrace();
|
|
|
|
}finally {
|
|
|
|
if (os != null) {
|
|
|
|
try {
|
|
|
|
os.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
InputStream in = new ByteArrayInputStream(bytes);
|
|
|
|
UploadVO uploadVO = fileUploadService.uploadStream(in, "sentitiveLog.xls", path);
|
|
|
|
return uploadVO.getFullUri();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MixEnvelop.getSuccess("下载日志成功",os);
|
|
|
|
|
|
//添加单元格内容
|
|
|
|
public void addCell(WritableSheet ws, int row, int column, String data) throws WriteException {
|
|
|
|
Label label = new Label(column, row, data);
|
|
|
|
ws.addCell(label);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//添加单元格内容
|
|
|
|
public void addCell(WritableSheet ws, int row, int column, String data, String memo) throws WriteException {
|
|
|
|
Label label = new Label(column, row, data);
|
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(memo)) {
|
|
|
|
WritableCellFeatures cellFeatures = new WritableCellFeatures();
|
|
|
|
cellFeatures.setComment(memo);
|
|
|
|
label.setCellFeatures(cellFeatures);
|
|
|
|
}
|
|
|
|
ws.addCell(label);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 导入敏感词
|
|
* 导入敏感词
|
|
* @param correctLs
|
|
* @param correctLs
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public Map<String, Object> importSensitive(List<BaseSensitiveExcelDO> correctLs,String operatorCode,String name) {
|
|
|
|
|
|
public Map<String, Object> importSensitive(List<BaseSensitiveExcelDO> correctLs,String operatorCode,String name,OutputStream os,String fastdfs_file_url){
|
|
Map<String, Object> rs = new HashMap<>();
|
|
Map<String, Object> rs = new HashMap<>();
|
|
int total = correctLs.size();
|
|
int total = correctLs.size();
|
|
rs.put("total",total);
|
|
rs.put("total",total);
|
|
@ -237,9 +279,41 @@ public class BaseSensitiveService extends BaseJpaService<BaseSensitiveDO, BaseSe
|
|
baseSensitiveDO.setAddTime(nowDate);
|
|
baseSensitiveDO.setAddTime(nowDate);
|
|
baseSensitiveDao.save(baseSensitiveDO);
|
|
baseSensitiveDao.save(baseSensitiveDO);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
try {
|
|
|
|
String url = exportSensitiveWordsLog(os, operatorCode, fastdfs_file_url);
|
|
|
|
rs.put("downloadLogUrl",url);
|
|
|
|
Logger.getGlobal().info("downloadLogUrl="+url);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
rs.put("downloadLogUrl","导出日志失败");
|
|
|
|
Logger.getGlobal().info("Logerror="+e.getMessage());
|
|
|
|
}
|
|
rs.put("success",total);
|
|
rs.put("success",total);
|
|
return rs;
|
|
return rs;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 敏感词过滤
|
|
|
|
* @param txt
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public MixEnvelop filterSensitiveWords(String txt){
|
|
|
|
List<BaseSensitiveDO> list = (List<BaseSensitiveDO>) baseSensitiveDao.findAll();
|
|
|
|
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);
|
|
|
|
Logger.getGlobal().info("语句中包含敏感词的个数为:" + words.size() + "。包含:" + words);
|
|
|
|
Logger.getAnonymousLogger().info("过滤前="+txt);
|
|
|
|
String replaceTxt = filter.replaceSensitiveWord(txt, 1, "*");
|
|
|
|
Logger.getGlobal().info("过滤后="+replaceTxt);
|
|
|
|
return MixEnvelop.getSuccess("过滤成功",replaceTxt);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|