From ec83f25f50805a855351a9d8e5bacad14aa8bfe4 Mon Sep 17 00:00:00 2001 From: liao Date: Mon, 30 Oct 2023 11:57:52 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E8=B5=84=E6=96=99=E4=B8=AD=E5=BF=83-?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../laws/common/constant/ResultCommon.java | 1 + .../laws/common/util/CurrentUserUtil.java | 20 +++ .../modules/laws/common/util/DateUtil.java | 37 +++++ .../LawsDataCenterFileController.java | 24 +-- .../dataCenter/entity/LawsDataCenterFile.java | 13 +- .../service/ILawsDataCenterFileService.java | 12 +- .../impl/LawsDataCenterFileServiceImpl.java | 138 +++++++++++++++--- .../impl/LawsDataCenterFolderServiceImpl.java | 22 ++- .../main/resources/i18n/messages.properties | 1 + .../resources/i18n/messages_en.properties | 1 + .../resources/i18n/messages_zh.properties | 1 + 11 files changed, 214 insertions(+), 56 deletions(-) create mode 100644 laws-modules/src/main/java/com/jero/modules/laws/common/util/DateUtil.java diff --git a/laws-modules/src/main/java/com/jero/modules/laws/common/constant/ResultCommon.java b/laws-modules/src/main/java/com/jero/modules/laws/common/constant/ResultCommon.java index 3c979c31..757441ae 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/common/constant/ResultCommon.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/common/constant/ResultCommon.java @@ -20,6 +20,7 @@ public class ResultCommon { public static final String NOT_EXIST_PARAM = "message.no.exists.param"; // 参数{0}不存在 public static final String NO_PERMISSION = "message.no.permission"; // 没有数据操作权限 public static final String SELECT_DATA = "message.select.data"; // 请选择数据 + public static final String EXIST_SUB_FOLDERS = "message.exist.sub.folders"; // 文件夹下有子文件夹 ,该文件夹不允许删除 public static final String RMR_SET_QUALITY_OVER_TEN = "es.rmr.setQuality.overTen"; // 请最多选择10条 diff --git a/laws-modules/src/main/java/com/jero/modules/laws/common/util/CurrentUserUtil.java b/laws-modules/src/main/java/com/jero/modules/laws/common/util/CurrentUserUtil.java index 1fa97e66..ddd9b796 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/common/util/CurrentUserUtil.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/common/util/CurrentUserUtil.java @@ -30,6 +30,26 @@ public class CurrentUserUtil { return loginUser.getUsername(); } + /** + * @Author: liao + * @Date: 2023/10/30 9:49 + * @Description: 获取真实姓名 + **/ + public static String getRealName() { + LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + return loginUser.getRealname(); + } + + /** + * @Author: liao + * @Date: 2023/10/30 9:50 + * @Description: 姓名+工号 + **/ + public static String getName() { + LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + return loginUser.getRealname() + "(" + loginUser.getUsername() + ")"; + } + /** * @Author: liao * @Date: 2023/10/26 18:26 diff --git a/laws-modules/src/main/java/com/jero/modules/laws/common/util/DateUtil.java b/laws-modules/src/main/java/com/jero/modules/laws/common/util/DateUtil.java new file mode 100644 index 00000000..ebb86b67 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/common/util/DateUtil.java @@ -0,0 +1,37 @@ +package com.jero.modules.laws.common.util; + +import com.jero.common.exception.JeroBootException; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * @Author: liao + * @Date: 2023/10/30 11:46 + * @Description: 时间转换工具类 + */ +public class DateUtil { + + public static DateFormat DATE_FORMAT_DAY = new SimpleDateFormat("yyyy-MM-dd"); + public static DateFormat DATE_FORMAT_SECOND = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + public static Date getDateDay(String dateStr) { + try { + return DATE_FORMAT_DAY.parse(dateStr); + } catch (Exception e) { + e.printStackTrace(); + throw new JeroBootException("时间格式错误,正确格式yyyy-MM-dd"); + } + } + + public static Date getDateSecond(String dateStr) { + try { + return DATE_FORMAT_SECOND.parse(dateStr); + } catch (Exception e) { + e.printStackTrace(); + throw new JeroBootException("时间格式错误,正确格式yyyy-MM-dd HH:mm:ss"); + } + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/controller/LawsDataCenterFileController.java b/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/controller/LawsDataCenterFileController.java index 3d2e8aa9..c6317607 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/controller/LawsDataCenterFileController.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/controller/LawsDataCenterFileController.java @@ -1,10 +1,8 @@ package com.jero.modules.laws.dataCenter.controller; import java.util.Arrays; -import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import com.jero.common.api.vo.Result; import com.jero.common.util.MessageUtils; @@ -17,7 +15,6 @@ import com.jero.common.system.base.controller.JeroController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.ModelAndView; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import com.jero.common.aspect.annotation.AutoLog; @@ -45,7 +42,6 @@ public class LawsDataCenterFileController extends JeroController> queryPageList(LawsDataCenterFile lawsDataCenterFile, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, - @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, - HttpServletRequest req) { - IPage pageList = lawsDataCenterFileService.queryPage(lawsDataCenterFile, pageNo, pageSize, req); + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { + IPage pageList = lawsDataCenterFileService.queryPage(lawsDataCenterFile, pageNo, pageSize); return Result.OK(pageList); } - /** - * 列表查询 - * - * @param lawsDataCenterFile - * @param req - * @return - */ - @AutoLog(value = "资料中心-文件数据-列表查询") - @ApiOperation(value = "资料中心-文件数据-列表查询", notes = "资料中心-文件数据-列表查询") - @GetMapping(value = "/list") - public Result> queryList(LawsDataCenterFile lawsDataCenterFile, HttpServletRequest req) { - List list = lawsDataCenterFileService.queryList(lawsDataCenterFile, req); - return Result.OK(list); - } - /** * 添加 * diff --git a/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/entity/LawsDataCenterFile.java b/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/entity/LawsDataCenterFile.java index 493709ce..7a842f25 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/entity/LawsDataCenterFile.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/entity/LawsDataCenterFile.java @@ -5,6 +5,7 @@ import java.io.UnsupportedEncodingException; import java.util.Date; import java.math.BigDecimal; import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -42,7 +43,6 @@ public class LawsDataCenterFile implements Serializable { private java.lang.String id; /**创建人*/ @ApiModelProperty(value = "创建人") - @Dict(dictTable = "sys_user", dicCode = "username", dicText = "realname") private java.lang.String createBy; /**创建时间*/ @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd") @@ -73,7 +73,7 @@ public class LawsDataCenterFile implements Serializable { private java.lang.String fileName; /**上传资料(文件id)*/ @Excel(name = "上传资料(文件id)", width = 15) - @ApiModelProperty(value = "上传资料(文件id)") + @ApiModelProperty(value = "上传资料(文件id,上传时多个用逗号分隔)") @NotBlank(message = "上传资料不能为空") private java.lang.String fileId; /**推送范围(用户id逗号拼接)*/ @@ -94,4 +94,13 @@ public class LawsDataCenterFile implements Serializable { @Excel(name = "拥有者id", width = 15) @ApiModelProperty(value = "拥有者id") private java.lang.String ownerId; + /**上传人*/ + @Excel(name = "上传人", width = 15) + @ApiModelProperty(value = "上传人") + private java.lang.String uploader; + /**上传时间(逗号分隔)*/ + @Excel(name = "上传时间(逗号分隔)", width = 15) + @ApiModelProperty(value = "上传时间(逗号分隔)") + @TableField(exist = false) + private java.lang.String uploadTime; } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/service/ILawsDataCenterFileService.java b/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/service/ILawsDataCenterFileService.java index fd954bdb..f8f9bdaa 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/service/ILawsDataCenterFileService.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/service/ILawsDataCenterFileService.java @@ -20,19 +20,9 @@ public interface ILawsDataCenterFileService extends IService * @param lawsDataCenterFile * @param pageNo * @param pageSize - * @param req * @return */ - IPage queryPage(LawsDataCenterFile lawsDataCenterFile, Integer pageNo, Integer pageSize, HttpServletRequest req); - - /** - * 列表查询 - * - * @param lawsDataCenterFile - * @param req - * @return - */ - List queryList(LawsDataCenterFile lawsDataCenterFile, HttpServletRequest req); + IPage queryPage(LawsDataCenterFile lawsDataCenterFile, Integer pageNo, Integer pageSize); /** * 保存 diff --git a/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/service/impl/LawsDataCenterFileServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/service/impl/LawsDataCenterFileServiceImpl.java index 17931358..e7aa6aa8 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/service/impl/LawsDataCenterFileServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/service/impl/LawsDataCenterFileServiceImpl.java @@ -1,13 +1,25 @@ package com.jero.modules.laws.dataCenter.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.jero.modules.laws.common.constant.FieldCommon; +import com.jero.modules.laws.common.constant.ResultCommon; import com.jero.modules.laws.common.util.CurrentUserUtil; +import com.jero.modules.laws.common.util.DateUtil; import com.jero.modules.laws.dataCenter.entity.LawsDataCenterFile; +import com.jero.modules.laws.dataCenter.entity.LawsDataCenterFolder; import com.jero.modules.laws.dataCenter.mapper.LawsDataCenterFileMapper; import com.jero.modules.laws.dataCenter.service.ILawsDataCenterFileService; +import com.jero.modules.laws.dataCenter.service.ILawsDataCenterFolderService; +import com.spire.ms.System.Collections.ArrayList; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.jero.common.exception.JeroBootException; + +import java.util.Arrays; import java.util.List; import java.util.Date; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -27,6 +39,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @Transactional(rollbackFor = JeroBootException.class) public class LawsDataCenterFileServiceImpl extends ServiceImpl implements ILawsDataCenterFileService { + @Autowired + private ILawsDataCenterFolderService lawsDataCenterFolderService; /** * 分页查询 @@ -34,29 +48,35 @@ public class LawsDataCenterFileServiceImpl extends ServiceImpl queryPage(LawsDataCenterFile lawsDataCenterFile, Integer pageNo, Integer pageSize, - HttpServletRequest req) { - QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(lawsDataCenterFile, req.getParameterMap()); + public IPage queryPage(LawsDataCenterFile lawsDataCenterFile, Integer pageNo, Integer pageSize) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); Page page = new Page<>(pageNo, pageSize); + queryWrapper.like(StringUtils.isNotBlank(lawsDataCenterFile.getFileName()), + LawsDataCenterFile::getFileName, lawsDataCenterFile.getFileName()); + queryWrapper.like(StringUtils.isNotBlank(lawsDataCenterFile.getUploader()), + LawsDataCenterFile::getUploader, lawsDataCenterFile.getUploader()); + if (StringUtils.isNotBlank(lawsDataCenterFile.getUploadTime())) { + String[] timeArr = lawsDataCenterFile.getUploadTime().split(","); + queryWrapper.between(LawsDataCenterFile::getCreateTime, + DateUtil.getDateSecond(timeArr[0]), DateUtil.getDateSecond(timeArr[1])); + } + if (StringUtils.isBlank(lawsDataCenterFile.getFolderId())) { + queryWrapper.isNull(LawsDataCenterFile::getFolderId); + } else { + queryWrapper.eq(LawsDataCenterFile::getFolderId, lawsDataCenterFile.getFolderId()); + } + if (!CurrentUserUtil.getRoles().contains(FieldCommon.ROLE_ADMIN)) { + queryWrapper.and(qw -> qw + .eq(LawsDataCenterFile::getOwnerId, CurrentUserUtil.getId()).or() + .like(LawsDataCenterFile::getPushRangeIds, CurrentUserUtil.getId()) + ); + } return page(page, queryWrapper); } - /** - * 列表查询 - * - * @param lawsDataCenterFile - * @param req - * @return - */ - @Override - public List queryList(LawsDataCenterFile lawsDataCenterFile, HttpServletRequest req) { - return list(QueryGenerator.initQueryWrapper(lawsDataCenterFile, req.getParameterMap())); - } - /** * 保存 * @@ -65,11 +85,62 @@ public class LawsDataCenterFileServiceImpl extends ServiceImpl fileIds = Arrays.asList(lawsDataCenterFile.getFileId().split(",")); + List fileList = new ArrayList(); + fileIds.forEach(fileId -> { + LawsDataCenterFile file = new LawsDataCenterFile(); + BeanUtils.copyProperties(lawsDataCenterFile, file); + file.setFileId(fileId); + fileList.add(file); + }); + + saveBatch(fileList); } + /** + * @Author: liao + * @Date: 2023/10/30 9:59 + * @Description: 校验管理权限(新增) + * 如果角色不是管理员,并且文件夹id不为空,则需要校验是否拥有该文件夹管理权限 + **/ + private void checkManageAuthAdd(String folderId) { + if (CurrentUserUtil.getRoles().contains(FieldCommon.ROLE_ADMIN) || StringUtils.isBlank(folderId)) return; + LawsDataCenterFolder folder = lawsDataCenterFolderService.getById(folderId); + if (!CurrentUserUtil.getId().equals(folder.getOwnerId()) && + (StringUtils.isBlank(folder.getAuthManageIds()) || !folder.getAuthManageIds().contains(CurrentUserUtil.getId()))) { + throw new JeroBootException(ResultCommon.NO_PERMISSION); + } + } + + /** + * @Author: liao + * @Date: 2023/10/30 9:59 + * @Description: 校验管理权限(编辑) + * 如果角色不是管理员,并且不是自己上传的,则需要校验是否拥有该文件夹管理权限 + **/ + private void checkManageAuthEdit(String id) { + LawsDataCenterFile file = getById(id); + if (CurrentUserUtil.getRoles().contains(FieldCommon.ROLE_ADMIN) || CurrentUserUtil.getId().equals(file.getOwnerId())) return; + if (StringUtils.isBlank(file.getFolderId())) { + throw new JeroBootException(ResultCommon.NO_PERMISSION); + } + LawsDataCenterFolder folder = lawsDataCenterFolderService.getById(file.getFolderId()); + if (!CurrentUserUtil.getId().equals(folder.getOwnerId()) && + (StringUtils.isBlank(folder.getAuthManageIds()) || !folder.getAuthManageIds().contains(CurrentUserUtil.getId()))) { + throw new JeroBootException(ResultCommon.NO_PERMISSION); + } + } + /** * 更新 * @@ -78,7 +149,30 @@ public class LawsDataCenterFileServiceImpl extends ServiceImpl fileIds = Arrays.asList(lawsDataCenterFile.getFileId().split(",")); + if (1 == fileIds.size()) { + updateById(lawsDataCenterFile); + return; + } + // 删除原来存储的 + removeById(lawsDataCenterFile.getId()); + + List fileList = new ArrayList(); + fileIds.forEach(fileId -> { + LawsDataCenterFile file = new LawsDataCenterFile(); + BeanUtils.copyProperties(lawsDataCenterFile, file); + file.setFileId(fileId); + file.setId(null); + fileList.add(file); + }); + + saveBatch(fileList); } /** @@ -89,7 +183,9 @@ public class LawsDataCenterFileServiceImpl extends ServiceImpl ids) { - removeByIds(ids); + // 校验管理权限 + ids.forEach(id -> checkManageAuthEdit(id)); + removeByIds(ids); } /** diff --git a/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/service/impl/LawsDataCenterFolderServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/service/impl/LawsDataCenterFolderServiceImpl.java index 84c53051..14ded9af 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/service/impl/LawsDataCenterFolderServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/dataCenter/service/impl/LawsDataCenterFolderServiceImpl.java @@ -1,11 +1,17 @@ package com.jero.modules.laws.dataCenter.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.jero.modules.laws.common.constant.FieldCommon; +import com.jero.modules.laws.common.constant.ResultCommon; import com.jero.modules.laws.common.util.CurrentUserUtil; +import com.jero.modules.laws.dataCenter.entity.LawsDataCenterFile; import com.jero.modules.laws.dataCenter.entity.LawsDataCenterFolder; import com.jero.modules.laws.dataCenter.mapper.LawsDataCenterFolderMapper; +import com.jero.modules.laws.dataCenter.service.ILawsDataCenterFileService; import com.jero.modules.laws.dataCenter.service.ILawsDataCenterFolderService; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -35,6 +41,8 @@ public class LawsDataCenterFolderServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(LawsDataCenterFolder::getParentId, id); + List lawsDataCenterFolders = list(queryWrapper); + // 有子文件夹的文件夹不能删除 + if (CollectionUtils.isNotEmpty(lawsDataCenterFolders)) { + throw new JeroBootException(ResultCommon.EXIST_SUB_FOLDERS); + } + removeById(id); + // 将该文件夹下面的文件夹关联删除 + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.set(LawsDataCenterFile::getFolderId, null); + updateWrapper.eq(LawsDataCenterFile::getFolderId, id); + lawsDataCenterFileService.update(updateWrapper); } } diff --git a/laws-single-startup/src/main/resources/i18n/messages.properties b/laws-single-startup/src/main/resources/i18n/messages.properties index 302daf17..0d8c8786 100644 --- a/laws-single-startup/src/main/resources/i18n/messages.properties +++ b/laws-single-startup/src/main/resources/i18n/messages.properties @@ -16,6 +16,7 @@ message.exists.standard.number=standard number already exists message.no.exists.param=param {0} not exists message.no.permission=No data operation permission message.select.data=Please select data +message.exist.sub.folders=There are sub folders in the folder. The folder cannot be deleted successfully.cleared=successfully cleared successfully.deleted=successfully deleted diff --git a/laws-single-startup/src/main/resources/i18n/messages_en.properties b/laws-single-startup/src/main/resources/i18n/messages_en.properties index da12b370..c1583c7d 100644 --- a/laws-single-startup/src/main/resources/i18n/messages_en.properties +++ b/laws-single-startup/src/main/resources/i18n/messages_en.properties @@ -15,6 +15,7 @@ message.exists.standard.number=standard number already exists message.no.exists.param=param {0} not exists message.no.permission=No data operation permission message.select.data=Please select data +message.exist.sub.folders=There are sub folders in the folder. The folder cannot be deleted es.rmr.setQuality.overTen=Please select up to 10 diff --git a/laws-single-startup/src/main/resources/i18n/messages_zh.properties b/laws-single-startup/src/main/resources/i18n/messages_zh.properties index 35c8671a..5584b243 100644 --- a/laws-single-startup/src/main/resources/i18n/messages_zh.properties +++ b/laws-single-startup/src/main/resources/i18n/messages_zh.properties @@ -16,6 +16,7 @@ message.exists.standard.number=\u6807\u51C6\u7F16\u53F7\u5DF2\u7ECF\u5B58\u5728 message.no.exists.param=\u53C2\u6570{0}\u4E0D\u5B58\u5728 message.no.permission=\u6CA1\u6709\u6570\u636E\u64CD\u4F5C\u6743\u9650 message.select.data=\u8BF7\u9009\u62E9\u6570\u636E +message.exist.sub.folders=文件夹下有子文件夹 ,该文件夹不允许删除 successfully.cleared=\u6E05\u9664\u6210\u529F successfully.deleted=\u5220\u9664\u6210\u529F