Browse Source

导出敏感词模板

导入值敏感字
develop
Mr.Wang 5 months ago
parent
commit
67970ce70d
  1. 57
      zc-business/src/main/java/com/zc/business/controller/DcInfoBoardVocabularyController.java
  2. 13
      zc-business/src/main/java/com/zc/business/mapper/DcInfoBoardVocabularyMapper.java
  3. 6
      zc-business/src/main/java/com/zc/business/service/IDcInfoBoardVocabularyService.java
  4. 78
      zc-business/src/main/java/com/zc/business/service/impl/DcInfoBoardVocabularyServiceImpl.java
  5. BIN
      zc-business/src/main/resources/excelTemplate/敏感字模板.xlsx
  6. 8
      zc-business/src/main/resources/mapper/business/DcInfoBoardVocabularyMapper.xml

57
zc-business/src/main/java/com/zc/business/controller/DcInfoBoardVocabularyController.java

@ -1,29 +1,24 @@
package com.zc.business.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.zc.business.domain.DcInfoBoardVocabulary;
import com.zc.business.service.IDcInfoBoardVocabularyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;
/**
* 情报板敏感字管理Controller
@ -66,6 +61,32 @@ public class DcInfoBoardVocabularyController extends BaseController
util.exportExcel(response, list, "情报板敏感字管理数据");
}
@ApiOperation("导出敏感词模板")
@Log(title = "导出敏感词模板", businessType = BusinessType.EXPORT)
@PostMapping("/exportModel")
public void exportModel(HttpServletResponse response)
{
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("excelTemplate/敏感字模板.xlsx");
try {
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
workbook.write(response.getOutputStream());
}catch (Exception e){
e.printStackTrace();
}
}
/**
* 导入值敏感字
*/
@ApiOperation("导入值敏感字")
@PostMapping("/importVocabulary")
public AjaxResult importVocabulary(MultipartFile file) throws Exception{
return dcInfoBoardVocabularyService.importVocabulary(file);
}
/**
* 获取情报板敏感字管理详细信息
*/

13
zc-business/src/main/java/com/zc/business/mapper/DcInfoBoardVocabularyMapper.java

@ -1,8 +1,8 @@
package com.zc.business.mapper;
import java.util.List;
import com.zc.business.domain.DcInfoBoardVocabulary;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 情报板敏感字管理Mapper接口
@ -10,8 +10,7 @@ import org.apache.ibatis.annotations.Param;
* @author ruoyi
* @date 2024-01-05
*/
public interface DcInfoBoardVocabularyMapper
{
public interface DcInfoBoardVocabularyMapper {
/**
* 查询情报板敏感字管理
*
@ -21,6 +20,12 @@ public interface DcInfoBoardVocabularyMapper
public DcInfoBoardVocabulary selectDcInfoBoardVocabularyById(Long id);
int selectWordNum(DcInfoBoardVocabulary dcInfoBoardVocabulary);
/**
* 导入敏感字
*/
int importVocabulary(List<DcInfoBoardVocabulary> dcInfoBoardVocabularyList);
/**
* 查询情报板敏感字管理列表
*

6
zc-business/src/main/java/com/zc/business/service/IDcInfoBoardVocabularyService.java

@ -4,6 +4,7 @@ import java.util.List;
import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.business.domain.DcInfoBoardVocabulary;
import org.springframework.web.multipart.MultipartFile;
/**
* 情报板敏感字管理Service接口
@ -29,6 +30,11 @@ public interface IDcInfoBoardVocabularyService
*/
List<DcInfoBoardVocabulary> selectDcInfoBoardVocabularyList(DcInfoBoardVocabulary dcInfoBoardVocabulary);
/**
* 导入敏感字
*/
AjaxResult importVocabulary(MultipartFile file) throws Exception;
/**
* 新增情报板敏感字管理
*

78
zc-business/src/main/java/com/zc/business/service/impl/DcInfoBoardVocabularyServiceImpl.java

@ -1,15 +1,23 @@
package com.zc.business.service.impl;
import java.net.URLDecoder;
import java.util.List;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zc.business.mapper.DcInfoBoardVocabularyMapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanValidators;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.zc.business.domain.DcInfoBoardVocabulary;
import com.zc.business.mapper.DcInfoBoardVocabularyMapper;
import com.zc.business.service.IDcInfoBoardVocabularyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.validation.Validator;
import java.net.URLDecoder;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* 情报板敏感字管理Service业务层处理
@ -18,11 +26,13 @@ import com.zc.business.service.IDcInfoBoardVocabularyService;
* @date 2024-01-05
*/
@Service
public class DcInfoBoardVocabularyServiceImpl implements IDcInfoBoardVocabularyService
{
public class DcInfoBoardVocabularyServiceImpl implements IDcInfoBoardVocabularyService {
@Autowired
private DcInfoBoardVocabularyMapper dcInfoBoardVocabularyMapper;
@Resource
protected Validator validator;
/**
* 查询情报板敏感字管理
*
@ -30,8 +40,7 @@ public class DcInfoBoardVocabularyServiceImpl implements IDcInfoBoardVocabularyS
* @return 情报板敏感字管理
*/
@Override
public DcInfoBoardVocabulary selectDcInfoBoardVocabularyById(Long id)
{
public DcInfoBoardVocabulary selectDcInfoBoardVocabularyById(Long id) {
return dcInfoBoardVocabularyMapper.selectDcInfoBoardVocabularyById(id);
}
@ -42,11 +51,36 @@ public class DcInfoBoardVocabularyServiceImpl implements IDcInfoBoardVocabularyS
* @return 情报板敏感字管理
*/
@Override
public List<DcInfoBoardVocabulary> selectDcInfoBoardVocabularyList(DcInfoBoardVocabulary dcInfoBoardVocabulary)
{
public List<DcInfoBoardVocabulary> selectDcInfoBoardVocabularyList(DcInfoBoardVocabulary dcInfoBoardVocabulary) {
return dcInfoBoardVocabularyMapper.selectDcInfoBoardVocabularyList(dcInfoBoardVocabulary);
}
/**
* 导入敏感字
*
* @param file
* @return
*/
@Override
public AjaxResult importVocabulary(MultipartFile file) throws Exception {
ExcelUtil<DcInfoBoardVocabulary> util = new ExcelUtil<>(DcInfoBoardVocabulary.class);
List<DcInfoBoardVocabulary> vocabularyList = util.importExcel(file.getInputStream());
BeanValidators.validateWithException(validator, vocabularyList);//对象属性验证
Date nowDate = DateUtils.getNowDate();
List<DcInfoBoardVocabulary> dcInfoBoardVocabularies = dcInfoBoardVocabularyMapper.selectDcInfoBoardVocabularyList(new DcInfoBoardVocabulary());
List<DcInfoBoardVocabulary> wordsNotInDcInfoBoard = vocabularyList.stream()
.filter(dcInfoBoardVocabulary -> StringUtils.isNotEmpty(dcInfoBoardVocabulary.getWord()))
.filter(v -> dcInfoBoardVocabularies.stream().noneMatch(d -> d.getWord().equals(v.getWord())))
.collect(Collectors.toList());
wordsNotInDcInfoBoard.forEach(dcInfoBoardVocabulary -> {
dcInfoBoardVocabulary.setCreateTime(nowDate);
});
if (wordsNotInDcInfoBoard.size() > 0) {
return AjaxResult.success(dcInfoBoardVocabularyMapper.importVocabulary(wordsNotInDcInfoBoard));
}
return AjaxResult.success().put("msg", "请检查数据是否重复,或存在空值");
}
/**
* 新增情报板敏感字管理
*
@ -54,11 +88,10 @@ public class DcInfoBoardVocabularyServiceImpl implements IDcInfoBoardVocabularyS
* @return 结果
*/
@Override
public AjaxResult insertDcInfoBoardVocabulary(DcInfoBoardVocabulary dcInfoBoardVocabulary)
{
public AjaxResult insertDcInfoBoardVocabulary(DcInfoBoardVocabulary dcInfoBoardVocabulary) {
dcInfoBoardVocabulary.setCreateTime(DateUtils.getNowDate());
int oldNum = dcInfoBoardVocabularyMapper.selectWordNum(dcInfoBoardVocabulary);
if (oldNum > 0){
if (oldNum > 0) {
return AjaxResult.error("该关键词已存在!");
}
dcInfoBoardVocabularyMapper.insertDcInfoBoardVocabulary(dcInfoBoardVocabulary);
@ -72,10 +105,9 @@ public class DcInfoBoardVocabularyServiceImpl implements IDcInfoBoardVocabularyS
* @return 结果
*/
@Override
public AjaxResult updateDcInfoBoardVocabulary(DcInfoBoardVocabulary dcInfoBoardVocabulary)
{
public AjaxResult updateDcInfoBoardVocabulary(DcInfoBoardVocabulary dcInfoBoardVocabulary) {
int oldNum = dcInfoBoardVocabularyMapper.selectWordNum(dcInfoBoardVocabulary);
if (oldNum > 0){
if (oldNum > 0) {
return AjaxResult.error("该关键词已存在!");
}
dcInfoBoardVocabularyMapper.updateDcInfoBoardVocabulary(dcInfoBoardVocabulary);
@ -89,8 +121,7 @@ public class DcInfoBoardVocabularyServiceImpl implements IDcInfoBoardVocabularyS
* @return 结果
*/
@Override
public int deleteDcInfoBoardVocabularyByIds(Long[] ids)
{
public int deleteDcInfoBoardVocabularyByIds(Long[] ids) {
return dcInfoBoardVocabularyMapper.deleteDcInfoBoardVocabularyByIds(ids);
}
@ -101,8 +132,7 @@ public class DcInfoBoardVocabularyServiceImpl implements IDcInfoBoardVocabularyS
* @return 结果
*/
@Override
public int deleteDcInfoBoardVocabularyById(Long id)
{
public int deleteDcInfoBoardVocabularyById(Long id) {
return dcInfoBoardVocabularyMapper.deleteDcInfoBoardVocabularyById(id);
}
@ -113,7 +143,7 @@ public class DcInfoBoardVocabularyServiceImpl implements IDcInfoBoardVocabularyS
* @return 结果
*/
@Override
public AjaxResult checkBoardContent(String content){
public AjaxResult checkBoardContent(String content) {
if (content == null || content.equals("")) {
return AjaxResult.error("情报板内容为空");
} else {
@ -125,7 +155,7 @@ public class DcInfoBoardVocabularyServiceImpl implements IDcInfoBoardVocabularyS
e.printStackTrace();
return AjaxResult.error();
}
for (int i = 0;i < boardVocabularies.size();i++) {
for (int i = 0; i < boardVocabularies.size(); i++) {
String word = boardVocabularies.get(i).getWord();
if (content.contains(word)) {
return AjaxResult.error("当前发布内容包含敏感字段'" + word + "',请修改");

BIN
zc-business/src/main/resources/excelTemplate/敏感字模板.xlsx

Binary file not shown.

8
zc-business/src/main/resources/mapper/business/DcInfoBoardVocabularyMapper.xml

@ -35,6 +35,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<insert id="importVocabulary" parameterType="list">
insert into dc_info_board_vocabulary (word,create_time)
values
<foreach collection="list" item="dcInfoBoardVocabulary" separator=",">
(#{dcInfoBoardVocabulary.word}, #{dcInfoBoardVocabulary.createTime})
</foreach>
</insert>
<insert id="insertDcInfoBoardVocabulary" parameterType="DcInfoBoardVocabulary" useGeneratedKeys="true" keyProperty="id">
insert into dc_info_board_vocabulary
<trim prefix="(" suffix=")" suffixOverrides=",">

Loading…
Cancel
Save