diff --git a/zc-business/src/main/java/com/zc/business/controller/DcInfoBoardVocabularyController.java b/zc-business/src/main/java/com/zc/business/controller/DcInfoBoardVocabularyController.java index 64cfc39f..b13740bb 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcInfoBoardVocabularyController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcInfoBoardVocabularyController.java @@ -1,33 +1,28 @@ 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 - * + * * @author ruoyi * @date 2024-01-05 */ @@ -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); + } + /** * 获取情报板敏感字管理详细信息 */ diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcInfoBoardVocabularyMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcInfoBoardVocabularyMapper.java index b9d4adc7..1656fc60 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcInfoBoardVocabularyMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcInfoBoardVocabularyMapper.java @@ -1,29 +1,34 @@ 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接口 - * + * * @author ruoyi * @date 2024-01-05 */ -public interface DcInfoBoardVocabularyMapper -{ +public interface DcInfoBoardVocabularyMapper { /** * 查询情报板敏感字管理 - * + * * @param id 情报板敏感字管理主键 * @return 情报板敏感字管理 */ public DcInfoBoardVocabulary selectDcInfoBoardVocabularyById(Long id); int selectWordNum(DcInfoBoardVocabulary dcInfoBoardVocabulary); + + /** + * 导入敏感字 + */ + int importVocabulary(List dcInfoBoardVocabularyList); + /** * 查询情报板敏感字管理列表 - * + * * @param dcInfoBoardVocabulary 情报板敏感字管理 * @return 情报板敏感字管理集合 */ @@ -31,7 +36,7 @@ public interface DcInfoBoardVocabularyMapper /** * 新增情报板敏感字管理 - * + * * @param dcInfoBoardVocabulary 情报板敏感字管理 * @return 结果 */ @@ -39,7 +44,7 @@ public interface DcInfoBoardVocabularyMapper /** * 修改情报板敏感字管理 - * + * * @param dcInfoBoardVocabulary 情报板敏感字管理 * @return 结果 */ @@ -47,7 +52,7 @@ public interface DcInfoBoardVocabularyMapper /** * 删除情报板敏感字管理 - * + * * @param id 情报板敏感字管理主键 * @return 结果 */ @@ -55,7 +60,7 @@ public interface DcInfoBoardVocabularyMapper /** * 批量删除情报板敏感字管理 - * + * * @param ids 需要删除的数据主键集合 * @return 结果 */ diff --git a/zc-business/src/main/java/com/zc/business/service/IDcInfoBoardVocabularyService.java b/zc-business/src/main/java/com/zc/business/service/IDcInfoBoardVocabularyService.java index 128130d4..c825e6e7 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcInfoBoardVocabularyService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcInfoBoardVocabularyService.java @@ -4,18 +4,19 @@ import java.util.List; import com.ruoyi.common.core.domain.AjaxResult; import com.zc.business.domain.DcInfoBoardVocabulary; +import org.springframework.web.multipart.MultipartFile; /** * 情报板敏感字管理Service接口 - * + * * @author ruoyi * @date 2024-01-05 */ -public interface IDcInfoBoardVocabularyService +public interface IDcInfoBoardVocabularyService { /** * 查询情报板敏感字管理 - * + * * @param id 情报板敏感字管理主键 * @return 情报板敏感字管理 */ @@ -23,15 +24,20 @@ public interface IDcInfoBoardVocabularyService /** * 查询情报板敏感字管理列表 - * + * * @param dcInfoBoardVocabulary 情报板敏感字管理 * @return 情报板敏感字管理集合 */ List selectDcInfoBoardVocabularyList(DcInfoBoardVocabulary dcInfoBoardVocabulary); + /** + * 导入敏感字 + */ + AjaxResult importVocabulary(MultipartFile file) throws Exception; + /** * 新增情报板敏感字管理 - * + * * @param dcInfoBoardVocabulary 情报板敏感字管理 * @return 结果 */ @@ -39,7 +45,7 @@ public interface IDcInfoBoardVocabularyService /** * 修改情报板敏感字管理 - * + * * @param dcInfoBoardVocabulary 情报板敏感字管理 * @return 结果 */ @@ -47,7 +53,7 @@ public interface IDcInfoBoardVocabularyService /** * 批量删除情报板敏感字管理 - * + * * @param ids 需要删除的情报板敏感字管理主键集合 * @return 结果 */ @@ -55,7 +61,7 @@ public interface IDcInfoBoardVocabularyService /** * 删除情报板敏感字管理信息 - * + * * @param id 情报板敏感字管理主键 * @return 结果 */ diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcInfoBoardVocabularyServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcInfoBoardVocabularyServiceImpl.java index d93b412e..8e964600 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcInfoBoardVocabularyServiceImpl.java +++ b/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 selectDcInfoBoardVocabularyList(DcInfoBoardVocabulary dcInfoBoardVocabulary) - { + public List selectDcInfoBoardVocabularyList(DcInfoBoardVocabulary dcInfoBoardVocabulary) { return dcInfoBoardVocabularyMapper.selectDcInfoBoardVocabularyList(dcInfoBoardVocabulary); } + /** + * 导入敏感字 + * + * @param file + * @return + */ + @Override + public AjaxResult importVocabulary(MultipartFile file) throws Exception { + ExcelUtil util = new ExcelUtil<>(DcInfoBoardVocabulary.class); + List vocabularyList = util.importExcel(file.getInputStream()); + BeanValidators.validateWithException(validator, vocabularyList);//对象属性验证 + Date nowDate = DateUtils.getNowDate(); + List dcInfoBoardVocabularies = dcInfoBoardVocabularyMapper.selectDcInfoBoardVocabularyList(new DcInfoBoardVocabulary()); + List 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 + "',请修改"); diff --git a/zc-business/src/main/resources/excelTemplate/敏感字模板.xlsx b/zc-business/src/main/resources/excelTemplate/敏感字模板.xlsx new file mode 100644 index 00000000..04c9562e Binary files /dev/null and b/zc-business/src/main/resources/excelTemplate/敏感字模板.xlsx differ diff --git a/zc-business/src/main/resources/mapper/business/DcInfoBoardVocabularyMapper.xml b/zc-business/src/main/resources/mapper/business/DcInfoBoardVocabularyMapper.xml index b1df6aaf..d57b97a3 100644 --- a/zc-business/src/main/resources/mapper/business/DcInfoBoardVocabularyMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcInfoBoardVocabularyMapper.xml @@ -3,7 +3,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -16,7 +16,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -35,6 +35,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + insert into dc_info_board_vocabulary (word,create_time) + values + + (#{dcInfoBoardVocabulary.word}, #{dcInfoBoardVocabulary.createTime}) + + + insert into dc_info_board_vocabulary @@ -61,9 +69,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from dc_info_board_vocabulary where id in + delete from dc_info_board_vocabulary where id in #{id} - \ No newline at end of file +