|
@ -0,0 +1,352 @@
|
|
|
package com.yihu.jw.base.service.word;
|
|
|
|
|
|
import com.yihu.jw.base.dao.word.BaseImportSensitiveDao;
|
|
|
import com.yihu.jw.base.dao.word.BaseSensitiveDao;
|
|
|
import com.yihu.jw.base.service.doctor.excelImport.BaseDoctorExcelDO;
|
|
|
import com.yihu.jw.base.service.word.excelImport.BaseSensitiveExcelDO;
|
|
|
import com.yihu.jw.base.useragent.UserAgent;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
import com.yihu.jw.entity.base.sync.BaseSyncDataDO;
|
|
|
import com.yihu.jw.entity.base.words.BaseImportSensitiveDO;
|
|
|
import com.yihu.jw.entity.base.words.BaseSensitiveDO;
|
|
|
import com.yihu.jw.file_upload.FileUploadService;
|
|
|
import com.yihu.jw.restmodel.iot.common.UploadVO;
|
|
|
import com.yihu.jw.restmodel.web.MixEnvelop;
|
|
|
import com.yihu.jw.rm.health.house.HealthyHouseMapping;
|
|
|
import com.yihu.jw.rm.iot.IotRequestMapping;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
import java.util.*;
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
/**
|
|
|
* @author HZY
|
|
|
* @vsrsion 1.0
|
|
|
* Created at 2020/7/6
|
|
|
*/
|
|
|
@Service
|
|
|
public class BaseSensitiveService extends BaseJpaService<BaseSensitiveDO, BaseSensitiveDao> {
|
|
|
|
|
|
@Autowired
|
|
|
private BaseSensitiveDao baseSensitiveDao;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private BaseImportSensitiveDao baseImportSensitiveDao;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
FileUploadService fileUploadService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 创建敏感词汇
|
|
|
* @param words
|
|
|
* @param explanation
|
|
|
*/
|
|
|
public void createSensitiveWords(String words, String explanation,String operatorCode,String name) {
|
|
|
BaseSensitiveDO baseSensitiveDO = new BaseSensitiveDO();
|
|
|
baseSensitiveDO.setSensitiveWord(words);
|
|
|
baseSensitiveDO.setExplanation(explanation);
|
|
|
baseSensitiveDO.setStatus("1");
|
|
|
baseSensitiveDO.setAddTime(DateUtil.getNowDate());
|
|
|
baseSensitiveDO.setOperatorCode(operatorCode);
|
|
|
baseSensitiveDO.setOperator(name);
|
|
|
baseSensitiveDao.save(baseSensitiveDO);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新敏感词汇
|
|
|
* @param id
|
|
|
* @param words
|
|
|
* @param explanation
|
|
|
*/
|
|
|
public void updateSensitiveWords(String id, String words, String explanation,String operatorCode,String name) {
|
|
|
BaseSensitiveDO baseSensitiveDO = baseSensitiveDao.findOne(id);
|
|
|
baseSensitiveDO.setSensitiveWord(words);
|
|
|
baseSensitiveDO.setExplanation(explanation);
|
|
|
baseSensitiveDO.setRenewTime(DateUtil.getNowDate());
|
|
|
baseSensitiveDO.setOperatorCode(operatorCode);
|
|
|
baseSensitiveDO.setOperator(name);
|
|
|
baseSensitiveDao.save(baseSensitiveDO);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除敏感词
|
|
|
* @param id
|
|
|
*/
|
|
|
public void delSensitiveWords(String id) {
|
|
|
baseSensitiveDao.delete(id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改敏感词状态
|
|
|
* @param id
|
|
|
* @param status
|
|
|
*/
|
|
|
public void updateSensitiveWordsStatus(String id, String status,String operatorCode,String name) {
|
|
|
BaseSensitiveDO baseSensitiveDO = baseSensitiveDao.findOne(id);
|
|
|
baseSensitiveDO.setStatus(status);
|
|
|
baseSensitiveDO.setRenewTime(DateUtil.getNowDate());
|
|
|
baseSensitiveDO.setOperatorCode(operatorCode);
|
|
|
baseSensitiveDO.setOperator(name);
|
|
|
baseSensitiveDao.save(baseSensitiveDO);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询所有敏感词
|
|
|
* @param status
|
|
|
* @param words
|
|
|
* @param page
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop findSensitiveWords(String status, String words, Integer page, Integer pageSize) {
|
|
|
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 ");
|
|
|
if (StringUtils.isNotEmpty(status)){
|
|
|
sql.append(" AND s.status='").append(status).append("'");
|
|
|
countSql.append(" AND s.status='").append(status).append("'");
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(words)){
|
|
|
sql.append(" AND (s.sensitive like'%").append(words).append("%'").append(" or ").append("s.explanation like'%").append(words).append("%')");
|
|
|
countSql.append(" AND (s.sensitive like'%").append(words).append("%'").append(" or ").append("s.explanation like'%").append(words).append("%')");
|
|
|
}
|
|
|
sql.append(" ORDER BY s.update_time LIMIT ").append((page-1)*pageSize).append(",").append(pageSize);
|
|
|
Logger.getAnonymousLogger().info("sql="+sql.toString());
|
|
|
List<BaseSyncDataDO> list = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(BaseSyncDataDO.class));
|
|
|
List<Map<String, Object>> mapList = jdbcTemplate.queryForList(countSql.toString());
|
|
|
long count = (long)mapList.get(0).get("count");
|
|
|
return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find,list,page,pageSize,count);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 导入词汇文件
|
|
|
* @param path
|
|
|
* @return
|
|
|
*/
|
|
|
public MixEnvelop importSensitiveWords(String path,String operatorCode,String name) {
|
|
|
Logger.getAnonymousLogger().info("path="+path+"----operatorCode="+operatorCode+"------name="+name);
|
|
|
List<BaseSensitiveDO> list = new ArrayList<BaseSensitiveDO>();
|
|
|
File file = null;
|
|
|
InputStream input = null;
|
|
|
if (path != null && path.length() > 7) {
|
|
|
// 判断文件是否是Excel(2003、2007)
|
|
|
String suffix = path
|
|
|
.substring(path.lastIndexOf("."), path.length());
|
|
|
file = new File(path);
|
|
|
try {
|
|
|
input = new FileInputStream(file);
|
|
|
} catch (FileNotFoundException e) {
|
|
|
System.out.println("未找到指定的文件!");
|
|
|
}
|
|
|
// Excel2003
|
|
|
if (".xls".equals(suffix)) {
|
|
|
POIFSFileSystem fileSystem = null;
|
|
|
// 工作簿
|
|
|
HSSFWorkbook workBook = null;
|
|
|
try {
|
|
|
fileSystem = new POIFSFileSystem(input);
|
|
|
workBook = new HSSFWorkbook(fileSystem);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
// 获取第一个工作簿
|
|
|
HSSFSheet sheet = workBook.getSheetAt(0);
|
|
|
list = getContent((Sheet) sheet);
|
|
|
// Excel2007
|
|
|
} else if (".xlsx".equals(suffix)) {
|
|
|
XSSFWorkbook workBook = null;
|
|
|
try {
|
|
|
workBook = new XSSFWorkbook(input);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
// 获取第一个工作簿
|
|
|
XSSFSheet sheet = workBook.getSheetAt(0);
|
|
|
list = getContent(sheet);
|
|
|
}
|
|
|
HashMap<String, String> rs = new HashMap<>();
|
|
|
int total = list.size();
|
|
|
rs.put("total",total+"");
|
|
|
Date nowDate = DateUtil.getNowDate();
|
|
|
for (BaseSensitiveDO one : list) {
|
|
|
BaseSensitiveDO sensitive = baseSensitiveDao.findBySensitiveWord(one.getSensitiveWord());
|
|
|
if (sensitive!=null){
|
|
|
BaseImportSensitiveDO importSensitiveDO = new BaseImportSensitiveDO();
|
|
|
importSensitiveDO.setRow(one.getId());
|
|
|
importSensitiveDO.setProblem("敏感词已存在");
|
|
|
importSensitiveDO.setCreateTime(nowDate);
|
|
|
importSensitiveDO.setCreateUser(operatorCode);
|
|
|
importSensitiveDO.setCreateUserName(name);
|
|
|
baseImportSensitiveDao.save(importSensitiveDO);
|
|
|
total-=1;
|
|
|
continue;
|
|
|
}
|
|
|
if (one.getSensitiveWord()==null){
|
|
|
BaseImportSensitiveDO importSensitiveDO = new BaseImportSensitiveDO();
|
|
|
importSensitiveDO.setRow(one.getId());
|
|
|
importSensitiveDO.setProblem("敏感词为空");
|
|
|
importSensitiveDO.setCreateTime(nowDate);
|
|
|
importSensitiveDO.setCreateUser(operatorCode);
|
|
|
importSensitiveDO.setCreateUserName(name);
|
|
|
baseImportSensitiveDao.save(importSensitiveDO);
|
|
|
total-=1;
|
|
|
continue;
|
|
|
}
|
|
|
one.setId(UUID.randomUUID().toString().replaceAll("-",""));
|
|
|
one.setStatus("1");
|
|
|
baseSensitiveDao.save(one);
|
|
|
}
|
|
|
rs.put("success",total+"");
|
|
|
} else {
|
|
|
MixEnvelop.getError("非法的文件路径!");
|
|
|
}
|
|
|
return MixEnvelop.getSuccess("导入成功");
|
|
|
}
|
|
|
|
|
|
|
|
|
// 获取Excel内容
|
|
|
public static List<BaseSensitiveDO> getContent(Sheet sheet) {
|
|
|
List<BaseSensitiveDO> list = new ArrayList<BaseSensitiveDO>();
|
|
|
// Excel数据总行数
|
|
|
int rowCount = sheet.getPhysicalNumberOfRows();
|
|
|
// 遍历数据行,略过标题行,从第二行开始
|
|
|
for (int i = 1; i < rowCount; i++) {
|
|
|
BaseSensitiveDO ub = new BaseSensitiveDO();
|
|
|
Row row = sheet.getRow(i);
|
|
|
int cellCount = row.getPhysicalNumberOfCells();
|
|
|
// 遍历行单元格
|
|
|
for (int j = 0; j < cellCount; j++) {
|
|
|
Cell cell = row.getCell(j);
|
|
|
switch (j) {
|
|
|
case 0:
|
|
|
ub.setId(cell.getStringCellValue());
|
|
|
break;
|
|
|
case 1:
|
|
|
ub.setSensitiveWord(cell.getStringCellValue());
|
|
|
break;
|
|
|
case 2:
|
|
|
ub.setExplanation(cell.getStringCellValue());
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
list.add(ub);
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public MixEnvelop exportSensitiveWordsLog(String url,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;
|
|
|
//获取日志
|
|
|
List<BaseImportSensitiveDO> list =jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BaseImportSensitiveDO.class));
|
|
|
//拼接字符串
|
|
|
StringBuffer text = new StringBuffer();
|
|
|
for(BaseImportSensitiveDO one:list){
|
|
|
text.append("第");
|
|
|
text.append(one.getRow());
|
|
|
text.append("行");
|
|
|
text.append(" ");
|
|
|
text.append(one.getProblem());
|
|
|
text.append("\r\n");//换行字符
|
|
|
}
|
|
|
InputStream is = new ByteArrayInputStream(text.toString().getBytes());
|
|
|
String name = genAttachmentFileName("导入日志.txt", "import.txt");
|
|
|
UploadVO uploadVO=new UploadVO();
|
|
|
try {
|
|
|
Logger.getAnonymousLogger().info("文件上传参数=name"+name+"---url="+url);
|
|
|
uploadVO = fileUploadService.uploadStream(is, name, url);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
Logger.getAnonymousLogger().info("文件上传失败");
|
|
|
Logger.getAnonymousLogger().info(e.getMessage());
|
|
|
return MixEnvelop.getError("日志导出失败");
|
|
|
}
|
|
|
return MixEnvelop.getSuccess("下载日志成功",uploadVO);
|
|
|
}
|
|
|
|
|
|
public String genAttachmentFileName(String cnName, String defaultName) {
|
|
|
try {
|
|
|
cnName = new String(cnName.getBytes("gb2312"), "ISO8859-1");
|
|
|
} catch (Exception e) {
|
|
|
cnName = defaultName;
|
|
|
}
|
|
|
return cnName;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 导入敏感词
|
|
|
* @param correctLs
|
|
|
* @return
|
|
|
*/
|
|
|
public Map<String, Object> importSensitive(List<BaseSensitiveExcelDO> correctLs,String operatorCode,String name) {
|
|
|
Map<String, Object> rs = new HashMap<>();
|
|
|
int total = correctLs.size();
|
|
|
rs.put("total",total);
|
|
|
Date nowDate = DateUtil.getNowDate();
|
|
|
for (BaseSensitiveExcelDO one : correctLs) {
|
|
|
BaseSensitiveDO sensitive = baseSensitiveDao.findBySensitiveWord(one.getSensitiveWord());
|
|
|
if (sensitive!=null){
|
|
|
BaseImportSensitiveDO importSensitiveDO = new BaseImportSensitiveDO();
|
|
|
importSensitiveDO.setRow(one.getId());
|
|
|
importSensitiveDO.setProblem("敏感词已存在");
|
|
|
importSensitiveDO.setCreateTime(nowDate);
|
|
|
importSensitiveDO.setCreateUser(operatorCode);
|
|
|
importSensitiveDO.setCreateUserName(name);
|
|
|
baseImportSensitiveDao.save(importSensitiveDO);
|
|
|
total-=1;
|
|
|
continue;
|
|
|
}
|
|
|
if (StringUtils.isEmpty(one.getSensitiveWord())){
|
|
|
BaseImportSensitiveDO importSensitiveDO = new BaseImportSensitiveDO();
|
|
|
importSensitiveDO.setRow(one.getId());
|
|
|
importSensitiveDO.setProblem("敏感词为空");
|
|
|
importSensitiveDO.setCreateTime(nowDate);
|
|
|
importSensitiveDO.setCreateUser(operatorCode);
|
|
|
importSensitiveDO.setCreateUserName(name);
|
|
|
baseImportSensitiveDao.save(importSensitiveDO);
|
|
|
total-=1;
|
|
|
continue;
|
|
|
}
|
|
|
BaseSensitiveDO baseSensitiveDO = new BaseSensitiveDO();
|
|
|
baseSensitiveDO.setId(UUID.randomUUID().toString().replaceAll("-",""));
|
|
|
baseSensitiveDO.setStatus("1");
|
|
|
baseSensitiveDO.setExplanation(one.getExplanation());
|
|
|
baseSensitiveDO.setSensitiveWord(one.getSensitiveWord());
|
|
|
baseSensitiveDO.setOperatorCode(operatorCode);
|
|
|
baseSensitiveDO.setOperator(name);
|
|
|
baseSensitiveDO.setAddTime(nowDate);
|
|
|
baseSensitiveDao.save(baseSensitiveDO);
|
|
|
}
|
|
|
rs.put("success",total);
|
|
|
return rs;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|