add 资料中心-文件操作

This commit is contained in:
liao
2023-10-30 11:57:52 +08:00
parent dae14456cb
commit ec83f25f50
11 changed files with 214 additions and 56 deletions
@@ -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条
@@ -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
@@ -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");
}
}
}
@@ -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<LawsDataCenterF
* @param lawsDataCenterFile
* @param pageNo
* @param pageSize
* @param req
* @return
*/
@AutoLog(value = "资料中心-文件数据-分页列表查询")
@@ -53,27 +49,11 @@ public class LawsDataCenterFileController extends JeroController<LawsDataCenterF
@GetMapping(value = "/page")
public Result<IPage<LawsDataCenterFile>> queryPageList(LawsDataCenterFile lawsDataCenterFile,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) {
IPage<LawsDataCenterFile> pageList = lawsDataCenterFileService.queryPage(lawsDataCenterFile, pageNo, pageSize, req);
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
IPage<LawsDataCenterFile> 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<List<LawsDataCenterFile>> queryList(LawsDataCenterFile lawsDataCenterFile, HttpServletRequest req) {
List<LawsDataCenterFile> list = lawsDataCenterFileService.queryList(lawsDataCenterFile, req);
return Result.OK(list);
}
/**
* 添加
*
@@ -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;
}
@@ -20,19 +20,9 @@ public interface ILawsDataCenterFileService extends IService<LawsDataCenterFile>
* @param lawsDataCenterFile
* @param pageNo
* @param pageSize
* @param req
* @return
*/
IPage<LawsDataCenterFile> queryPage(LawsDataCenterFile lawsDataCenterFile, Integer pageNo, Integer pageSize, HttpServletRequest req);
/**
* 列表查询
*
* @param lawsDataCenterFile
* @param req
* @return
*/
List<LawsDataCenterFile> queryList(LawsDataCenterFile lawsDataCenterFile, HttpServletRequest req);
IPage<LawsDataCenterFile> queryPage(LawsDataCenterFile lawsDataCenterFile, Integer pageNo, Integer pageSize);
/**
* 保存
@@ -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<LawsDataCenterFileMapper, LawsDataCenterFile> implements ILawsDataCenterFileService {
@Autowired
private ILawsDataCenterFolderService lawsDataCenterFolderService;
/**
* 分页查询
@@ -34,29 +48,35 @@ public class LawsDataCenterFileServiceImpl extends ServiceImpl<LawsDataCenterFil
* @param lawsDataCenterFile
* @param pageNo
* @param pageSize
* @param req
* @return
*/
@Override
public IPage<LawsDataCenterFile> queryPage(LawsDataCenterFile lawsDataCenterFile, Integer pageNo, Integer pageSize,
HttpServletRequest req) {
QueryWrapper<LawsDataCenterFile> queryWrapper = QueryGenerator.initQueryWrapper(lawsDataCenterFile, req.getParameterMap());
public IPage<LawsDataCenterFile> queryPage(LawsDataCenterFile lawsDataCenterFile, Integer pageNo, Integer pageSize) {
LambdaQueryWrapper<LawsDataCenterFile> queryWrapper = new LambdaQueryWrapper<>();
Page<LawsDataCenterFile> 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<LawsDataCenterFile> queryList(LawsDataCenterFile lawsDataCenterFile, HttpServletRequest req) {
return list(QueryGenerator.initQueryWrapper(lawsDataCenterFile, req.getParameterMap()));
}
/**
* 保存
*
@@ -65,11 +85,62 @@ public class LawsDataCenterFileServiceImpl extends ServiceImpl<LawsDataCenterFil
*/
@Override
public void add(LawsDataCenterFile lawsDataCenterFile) {
// 校验管理权限
checkManageAuthAdd(lawsDataCenterFile.getFolderId());
lawsDataCenterFile.setOwnerId(CurrentUserUtil.getId());
lawsDataCenterFile.setUploader(CurrentUserUtil.getName());
lawsDataCenterFile.setOrgCode(CurrentUserUtil.getOrgCode());
save(lawsDataCenterFile);
if (StringUtils.isBlank(lawsDataCenterFile.getFileId())) {
throw new JeroBootException(ResultCommon.EMPTY_COMMON, "fileId");
}
List<String> fileIds = Arrays.asList(lawsDataCenterFile.getFileId().split(","));
List<LawsDataCenterFile> 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<LawsDataCenterFil
*/
@Override
public void editById(LawsDataCenterFile lawsDataCenterFile) {
saveOrUpdate(lawsDataCenterFile);
// 校验管理权限
checkManageAuthEdit(lawsDataCenterFile.getId());
if (StringUtils.isBlank(lawsDataCenterFile.getFileId())) {
throw new JeroBootException(ResultCommon.EMPTY_COMMON, "fileId");
}
List<String> fileIds = Arrays.asList(lawsDataCenterFile.getFileId().split(","));
if (1 == fileIds.size()) {
updateById(lawsDataCenterFile);
return;
}
// 删除原来存储的
removeById(lawsDataCenterFile.getId());
List<LawsDataCenterFile> 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<LawsDataCenterFil
*/
@Override
public void deleteById(String id) {
removeById(id);
// 校验管理权限
checkManageAuthEdit(id);
removeById(id);
}
/**
@@ -100,7 +196,9 @@ public class LawsDataCenterFileServiceImpl extends ServiceImpl<LawsDataCenterFil
*/
@Override
public void deleteByIds(List<String> ids) {
removeByIds(ids);
// 校验管理权限
ids.forEach(id -> checkManageAuthEdit(id));
removeByIds(ids);
}
/**
@@ -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<LawsDataCenterF
@Autowired
private LawsDataCenterFolderMapper lawsDataCenterFolderMapper;
@Autowired
private ILawsDataCenterFileService lawsDataCenterFileService;
/**
* @Author: liao
@@ -148,6 +156,18 @@ public class LawsDataCenterFolderServiceImpl extends ServiceImpl<LawsDataCenterF
*/
@Override
public void deleteById(String id) {
removeById(id);
LambdaQueryWrapper<LawsDataCenterFolder> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(LawsDataCenterFolder::getParentId, id);
List<LawsDataCenterFolder> lawsDataCenterFolders = list(queryWrapper);
// 有子文件夹的文件夹不能删除
if (CollectionUtils.isNotEmpty(lawsDataCenterFolders)) {
throw new JeroBootException(ResultCommon.EXIST_SUB_FOLDERS);
}
removeById(id);
// 将该文件夹下面的文件夹关联删除
LambdaUpdateWrapper<LawsDataCenterFile> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.set(LawsDataCenterFile::getFolderId, null);
updateWrapper.eq(LawsDataCenterFile::getFolderId, id);
lawsDataCenterFileService.update(updateWrapper);
}
}
@@ -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
@@ -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
@@ -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