根据用户角色获取文件列表接口实现
This commit is contained in:
parent
87cb33a309
commit
1b4fa7eb24
@ -298,7 +298,7 @@ public class FileController {
|
|||||||
IPage<FileListVO> fileList = userFileService.userFileList(null, filePath, currentPage, pageCount);
|
IPage<FileListVO> fileList = userFileService.userFileList(null, filePath, currentPage, pageCount);
|
||||||
return RestResult.success().dataList(fileList.getRecords(), fileList.getTotal());
|
return RestResult.success().dataList(fileList.getRecords(), fileList.getTotal());
|
||||||
} else {
|
} else {
|
||||||
IPage<FileListVO> fileList = userFileService.getFileByFileType(Integer.valueOf(fileType), currentPage, pageCount, SecurityUtils.getLoginUser().getUserId());
|
IPage<FileListVO> fileList = userFileService.getFileByFileType(Integer.valueOf(fileType), currentPage, pageCount, SecurityUtils.getUserId());
|
||||||
return RestResult.success().dataList(fileList.getRecords(), fileList.getTotal());
|
return RestResult.success().dataList(fileList.getRecords(), fileList.getTotal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -567,4 +567,21 @@ public class FileController {
|
|||||||
return RestResult.success().message("修改文件访问范围成功");
|
return RestResult.success().message("修改文件访问范围成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "5.6 根据用户角色获取文件列表")
|
||||||
|
@ApiOperationSupport(order = 6)
|
||||||
|
@RequestMapping(value = "/getfilelistbyrole", method = RequestMethod.GET)
|
||||||
|
@ResponseBody
|
||||||
|
public RestResult<FileListVO> getFileListByRole(
|
||||||
|
@Parameter(description = "文件类型", required = true) String fileType,
|
||||||
|
@Parameter(description = "文件路径", required = false) String filePath,
|
||||||
|
@Parameter(description = "当前页", required = true) long currentPage,
|
||||||
|
@Parameter(description = "页面数量", required = true) long pageCount){
|
||||||
|
if ("0".equals(fileType)) {
|
||||||
|
IPage<FileListVO> fileList = userFileService.userFileListByRole(SecurityUtils.getUserId(), filePath, currentPage, pageCount);
|
||||||
|
return RestResult.success().dataList(fileList.getRecords(), fileList.getTotal());
|
||||||
|
} else {
|
||||||
|
IPage<FileListVO> fileList = userFileService.getFileByFileTypeAndRole(Integer.valueOf(fileType), currentPage, pageCount, SecurityUtils.getUserId());
|
||||||
|
return RestResult.success().dataList(fileList.getRecords(), fileList.getTotal());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.qiwenshare.common.util.DateUtil;
|
import com.qiwenshare.common.util.DateUtil;
|
||||||
|
import com.ruoyi.common.core.domain.BaseEntity;
|
||||||
import com.ruoyi.file.io.QiwenFile;
|
import com.ruoyi.file.io.QiwenFile;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,9 @@ public interface UserFileMapper extends BaseMapper<UserFile> {
|
|||||||
List<UserFile> selectUserFileByLikeRightFilePath(@Param("filePath") String filePath, @Param("userId") Long userId);
|
List<UserFile> selectUserFileByLikeRightFilePath(@Param("filePath") String filePath, @Param("userId") Long userId);
|
||||||
|
|
||||||
IPage<FileListVO> selectPageVo(Page<?> page, @Param("userFile") UserFile userFile, @Param("fileTypeId") Integer fileTypeId);
|
IPage<FileListVO> selectPageVo(Page<?> page, @Param("userFile") UserFile userFile, @Param("fileTypeId") Integer fileTypeId);
|
||||||
|
|
||||||
|
IPage<FileListVO> selectPageVoByRole(Page<?> page, @Param("userFile") UserFile userFile, @Param("fileTypeId") Integer fileTypeId, @Param("scopeParamSql") String scopeParamSql);
|
||||||
|
|
||||||
Long selectStorageSizeByUserId(@Param("userId") Long userId);
|
Long selectStorageSizeByUserId(@Param("userId") Long userId);
|
||||||
|
|
||||||
List<UserFile> selectByUserFileId(String userFileId);
|
List<UserFile> selectByUserFileId(String userFileId);
|
||||||
|
|||||||
@ -14,10 +14,13 @@ public interface IUserFileService extends IService<UserFile> {
|
|||||||
List<UserFile> selectSameUserFile(String fileName, String filePath, String extendName, Long userId);
|
List<UserFile> selectSameUserFile(String fileName, String filePath, String extendName, Long userId);
|
||||||
|
|
||||||
IPage<FileListVO> userFileList(Long userId, String filePath, Long beginCount, Long pageCount);
|
IPage<FileListVO> userFileList(Long userId, String filePath, Long beginCount, Long pageCount);
|
||||||
|
|
||||||
|
IPage<FileListVO> userFileListByRole(Long userId, String filePath, Long beginCount, Long pageCount);
|
||||||
void updateFilepathByUserFileId(String userFileId, String newfilePath, Long userId);
|
void updateFilepathByUserFileId(String userFileId, String newfilePath, Long userId);
|
||||||
void userFileCopy(Long userId, String userFileId, String newfilePath);
|
void userFileCopy(Long userId, String userFileId, String newfilePath);
|
||||||
|
|
||||||
IPage<FileListVO> getFileByFileType(Integer fileTypeId, Long currentPage, Long pageCount, Long userId);
|
IPage<FileListVO> getFileByFileType(Integer fileTypeId, Long currentPage, Long pageCount, Long userId);
|
||||||
|
IPage<FileListVO> getFileByFileTypeAndRole(Integer fileTypeId, Long currentPage, Long pageCount, Long userId);
|
||||||
List<UserFile> selectUserFileListByPath(String filePath, Long userId);
|
List<UserFile> selectUserFileListByPath(String filePath, Long userId);
|
||||||
List<UserFile> selectFilePathTreeByUserId(Long userId);
|
List<UserFile> selectFilePathTreeByUserId(Long userId);
|
||||||
void deleteUserFile(String userFileId, Long sessionUserId);
|
void deleteUserFile(String userFileId, Long sessionUserId);
|
||||||
|
|||||||
@ -10,6 +10,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qiwenshare.common.constant.FileConstant;
|
import com.qiwenshare.common.constant.FileConstant;
|
||||||
import com.qiwenshare.common.util.DateUtil;
|
import com.qiwenshare.common.util.DateUtil;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.file.dto.file.UserFileDTO;
|
import com.ruoyi.file.dto.file.UserFileDTO;
|
||||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
@ -23,8 +27,10 @@ import com.ruoyi.file.mapper.UserFileMapper;
|
|||||||
import com.ruoyi.file.service.IUserFileService;
|
import com.ruoyi.file.service.IUserFileService;
|
||||||
import com.ruoyi.file.util.FileTreeSelect;
|
import com.ruoyi.file.util.FileTreeSelect;
|
||||||
import com.ruoyi.file.vo.file.FileListVO;
|
import com.ruoyi.file.vo.file.FileListVO;
|
||||||
|
import com.ruoyi.system.mapper.SysUserMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@ -39,6 +45,27 @@ import java.util.stream.Collectors;
|
|||||||
@Service
|
@Service
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public class UserFileServiceImpl extends ServiceImpl<UserFileMapper, UserFile> implements IUserFileService {
|
public class UserFileServiceImpl extends ServiceImpl<UserFileMapper, UserFile> implements IUserFileService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全部文件权限
|
||||||
|
*/
|
||||||
|
public static final String FILE_SCOPE_ALL = "1";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义文件权限
|
||||||
|
*/
|
||||||
|
public static final String FILE_SCOPE_CUSTOM = "2";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仅公开文件权限
|
||||||
|
*/
|
||||||
|
public static final String FILE_SCOPE_PUBLIC = "3";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仅本人文件权限
|
||||||
|
*/
|
||||||
|
public static final String FILE_SCOPE_SELF = "4";
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
UserFileMapper userFileMapper;
|
UserFileMapper userFileMapper;
|
||||||
@Resource
|
@Resource
|
||||||
@ -47,7 +74,8 @@ public class UserFileServiceImpl extends ServiceImpl<UserFileMapper, UserFile> i
|
|||||||
FileDealComp fileDealComp;
|
FileDealComp fileDealComp;
|
||||||
@Resource
|
@Resource
|
||||||
SysRoleUserFileMapper roleUserFileMapper;
|
SysRoleUserFileMapper roleUserFileMapper;
|
||||||
|
@Autowired
|
||||||
|
SysUserMapper userMapper;
|
||||||
|
|
||||||
public static Executor executor = Executors.newFixedThreadPool(20);
|
public static Executor executor = Executors.newFixedThreadPool(20);
|
||||||
|
|
||||||
@ -90,6 +118,22 @@ public class UserFileServiceImpl extends ServiceImpl<UserFileMapper, UserFile> i
|
|||||||
return userFileMapper.selectPageVo(page, userFile, null);
|
return userFileMapper.selectPageVo(page, userFile, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<FileListVO> userFileListByRole(Long userId, String filePath, Long currentPage, Long pageCount) {
|
||||||
|
Page<FileListVO> page = new Page<>(currentPage, pageCount);
|
||||||
|
UserFile userFile = new UserFile();
|
||||||
|
LoginUser sessionUserBean = SecurityUtils.getLoginUser();
|
||||||
|
if (userId == null) {
|
||||||
|
userFile.setUserId(sessionUserBean.getUserId());
|
||||||
|
} else {
|
||||||
|
userFile.setUserId(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
userFile.setFilePath(URLDecoder.decodeForPath(filePath, StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
return userFileMapper.selectPageVoByRole(page, userFile, null, buildScopeParamSql(userId, "a"));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateFilepathByUserFileId(String userFileId, String newfilePath, Long userId) {
|
public void updateFilepathByUserFileId(String userFileId, String newfilePath, Long userId) {
|
||||||
UserFile userFile = userFileMapper.selectById(userFileId);
|
UserFile userFile = userFileMapper.selectById(userFileId);
|
||||||
@ -183,6 +227,15 @@ public class UserFileServiceImpl extends ServiceImpl<UserFileMapper, UserFile> i
|
|||||||
return userFileMapper.selectPageVo(page, userFile, fileTypeId);
|
return userFileMapper.selectPageVo(page, userFile, fileTypeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<FileListVO> getFileByFileTypeAndRole(Integer fileTypeId, Long currentPage, Long pageCount, Long userId) {
|
||||||
|
Page<FileListVO> page = new Page<>(currentPage, pageCount);
|
||||||
|
|
||||||
|
UserFile userFile = new UserFile();
|
||||||
|
userFile.setUserId(userId);
|
||||||
|
return userFileMapper.selectPageVoByRole(page, userFile, fileTypeId, buildScopeParamSql(userId, "a"));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserFile> selectUserFileListByPath(String filePath, Long userId) {
|
public List<UserFile> selectUserFileListByPath(String filePath, Long userId) {
|
||||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
@ -359,4 +412,48 @@ public class UserFileServiceImpl extends ServiceImpl<UserFileMapper, UserFile> i
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造文件范围查询参数sql
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @param userFileAlias 用户文件表别名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String buildScopeParamSql(Long userId, String userFileAlias) {
|
||||||
|
if (userId == null) {
|
||||||
|
throw new ServiceException("用户未登录");
|
||||||
|
}
|
||||||
|
SysUser user = userMapper.selectUserById(userId);
|
||||||
|
if (user.isAdmin()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
StringBuilder sqlString = new StringBuilder();
|
||||||
|
List<String> conditions = new ArrayList<String>();
|
||||||
|
|
||||||
|
for (SysRole role : user.getRoles()) {
|
||||||
|
String fileScope = role.getFileScope();
|
||||||
|
if (!FILE_SCOPE_CUSTOM.equals(fileScope) && conditions.contains(fileScope)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (FILE_SCOPE_ALL.equals(fileScope)) {
|
||||||
|
return "";
|
||||||
|
} else if (FILE_SCOPE_CUSTOM.equals(fileScope)) {
|
||||||
|
sqlString.append(StringUtils.format(
|
||||||
|
" OR {}.userFileId IN ( SELECT userFileId FROM sys_role_userfile WHERE role_id = {} ) ", userFileAlias,
|
||||||
|
role.getRoleId()));
|
||||||
|
} else if (FILE_SCOPE_PUBLIC.equals(fileScope)) {
|
||||||
|
sqlString.append(StringUtils.format(" OR {}.isPublic = 1", userFileAlias));
|
||||||
|
} else if (FILE_SCOPE_SELF.equals(fileScope)) {
|
||||||
|
sqlString.append(StringUtils.format(" OR {}.userId = {} ", userFileAlias, user.getUserId()));
|
||||||
|
}
|
||||||
|
conditions.add(fileScope);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(sqlString.toString())) {
|
||||||
|
return " AND (" + sqlString.substring(4) + ")";
|
||||||
|
} else {
|
||||||
|
return " AND " + StringUtils.format("{}.userId = {} ", userFileAlias, user.getUserId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,6 +86,44 @@
|
|||||||
ORDER BY isDir desc
|
ORDER BY isDir desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectPageVoByRole" resultType="com.ruoyi.file.vo.file.FileListVO">
|
||||||
|
select * from userfile a
|
||||||
|
left join image on a.fileId = image.fileId
|
||||||
|
left join file on file.fileId = a.fileId
|
||||||
|
<where>
|
||||||
|
<if test="fileTypeId != null">
|
||||||
|
<choose>
|
||||||
|
<when test="fileTypeId != 5">
|
||||||
|
extendName in (select fileExtendName from fileclassification where fileTypeId = #{fileTypeId})
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
extendName not in (select fileExtendName from fileclassification where fileTypeId in (1, 2, 3, 4))
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
and a.isDir = 0
|
||||||
|
</if>
|
||||||
|
<!--<if test="userFile.userId != null">
|
||||||
|
and a.userId = #{userFile.userId}
|
||||||
|
</if>-->
|
||||||
|
<if test="userFile.filePath != null">
|
||||||
|
and a.filePath = #{userFile.filePath}
|
||||||
|
</if>
|
||||||
|
<if test="userFile.extendName != null">
|
||||||
|
and a.extendName = #{userFile.extendName}
|
||||||
|
</if>
|
||||||
|
<if test="userFile.userFileId != null">
|
||||||
|
and a.userFileId = #{userFile.userFileId}
|
||||||
|
</if>
|
||||||
|
<if test="userFile.fileName != null">
|
||||||
|
and a.fileName = #{userFile.fileName}
|
||||||
|
</if>
|
||||||
|
and a.deleteFlag = 0 and a.isDir = 0
|
||||||
|
<!-- 查询范围过滤 -->
|
||||||
|
${scopeParamSql}
|
||||||
|
</where>
|
||||||
|
ORDER BY a.createTime desc
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="selectUserFileByLikeRightFilePath" resultType="com.ruoyi.file.domain.UserFile">
|
<select id="selectUserFileByLikeRightFilePath" resultType="com.ruoyi.file.domain.UserFile">
|
||||||
select * from userfile
|
select * from userfile
|
||||||
where (filePath = #{filePath} or filePath like concat(#{filePath},'/%')) and userId = #{userId} and deleteFlag = 0
|
where (filePath = #{filePath} or filePath like concat(#{filePath},'/%')) and userId = #{userId} and deleteFlag = 0
|
||||||
|
|||||||
@ -1,29 +0,0 @@
|
|||||||
package com.ruoyi.common.annotation;
|
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据权限过滤注解
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
@Target(ElementType.METHOD)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Documented
|
|
||||||
public @interface FacilityScope
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 部门表的别名
|
|
||||||
*/
|
|
||||||
public String deptAlias() default "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户表的别名
|
|
||||||
*/
|
|
||||||
public String userAlias() default "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 权限字符(用于多个角色匹配符合要求的权限)默认根据权限注解@ss获取,多个权限用逗号分隔开来
|
|
||||||
*/
|
|
||||||
public String permission() default "";
|
|
||||||
}
|
|
||||||
@ -1,128 +0,0 @@
|
|||||||
package com.ruoyi.framework.aspectj;
|
|
||||||
|
|
||||||
import com.ruoyi.common.annotation.DataScope;
|
|
||||||
import com.ruoyi.common.annotation.FacilityScope;
|
|
||||||
import com.ruoyi.common.core.domain.BaseEntity;
|
|
||||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
||||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
||||||
import com.ruoyi.common.core.text.Convert;
|
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
|
||||||
import com.ruoyi.framework.security.context.PermissionContextHolder;
|
|
||||||
import org.aspectj.lang.JoinPoint;
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
|
||||||
import org.aspectj.lang.annotation.Before;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 厂房数据过滤处理
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
@Aspect
|
|
||||||
@Component
|
|
||||||
public class FacilityScopeAspect
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 全部数据权限
|
|
||||||
*/
|
|
||||||
public static final String DATA_SCOPE_ALL = "1";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定数据权限
|
|
||||||
*/
|
|
||||||
public static final String DATA_SCOPE_CUSTOM = "2";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 部门数据权限
|
|
||||||
*/
|
|
||||||
public static final String DATA_SCOPE_DEPT = "3";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 部门及以下数据权限
|
|
||||||
*/
|
|
||||||
public static final String DATA_SCOPE_DEPT_AND_CHILD = "4";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 仅本人数据权限
|
|
||||||
*/
|
|
||||||
public static final String DATA_SCOPE_SELF = "5";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据权限过滤关键字
|
|
||||||
*/
|
|
||||||
public static final String DATA_SCOPE = "dataScope";
|
|
||||||
|
|
||||||
@Before("@annotation(controllerDataScope)")
|
|
||||||
public void doBefore(JoinPoint point, FacilityScope controllerDataScope) throws Throwable
|
|
||||||
{
|
|
||||||
clearDataScope(point);
|
|
||||||
handleDataScope(point, controllerDataScope);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void handleDataScope(final JoinPoint joinPoint, FacilityScope controllerDataScope)
|
|
||||||
{
|
|
||||||
// 获取当前的用户
|
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
||||||
if (StringUtils.isNotNull(loginUser))
|
|
||||||
{
|
|
||||||
SysUser currentUser = loginUser.getUser();
|
|
||||||
// 如果是超级管理员,则不过滤数据
|
|
||||||
if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin())
|
|
||||||
{
|
|
||||||
String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), PermissionContextHolder.getContext());
|
|
||||||
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
|
|
||||||
controllerDataScope.userAlias(), permission);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据范围过滤
|
|
||||||
*
|
|
||||||
* @param joinPoint 切点
|
|
||||||
* @param user 用户
|
|
||||||
* @param deptAlias 部门别名
|
|
||||||
* @param userAlias 用户别名
|
|
||||||
* @param permission 权限字符
|
|
||||||
*/
|
|
||||||
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, String permission)
|
|
||||||
{
|
|
||||||
StringBuilder sqlString = new StringBuilder();
|
|
||||||
sqlString.append(StringUtils.format(
|
|
||||||
" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE del_flag = '0' and facility_id in (\n" +
|
|
||||||
" select rf.facility_id from sys_role_facility rf\n" +
|
|
||||||
" left join sys_user_role ru on rf.role_id = ru.role_id\n" +
|
|
||||||
" where ru.user_id = {} )\n" +
|
|
||||||
") ",
|
|
||||||
deptAlias,
|
|
||||||
user.getUserId()));
|
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(sqlString.toString()))
|
|
||||||
{
|
|
||||||
Object params = joinPoint.getArgs()[0];
|
|
||||||
if (StringUtils.isNotNull(params) && params instanceof BaseEntity)
|
|
||||||
{
|
|
||||||
BaseEntity baseEntity = (BaseEntity) params;
|
|
||||||
baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 拼接权限sql前先清空params.dataScope参数防止注入
|
|
||||||
*/
|
|
||||||
private void clearDataScope(final JoinPoint joinPoint)
|
|
||||||
{
|
|
||||||
Object params = joinPoint.getArgs()[0];
|
|
||||||
if (StringUtils.isNotNull(params) && params instanceof BaseEntity)
|
|
||||||
{
|
|
||||||
BaseEntity baseEntity = (BaseEntity) params;
|
|
||||||
baseEntity.getParams().put(DATA_SCOPE, "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -48,6 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="roleKey" column="role_key" />
|
<result property="roleKey" column="role_key" />
|
||||||
<result property="roleSort" column="role_sort" />
|
<result property="roleSort" column="role_sort" />
|
||||||
<result property="dataScope" column="data_scope" />
|
<result property="dataScope" column="data_scope" />
|
||||||
|
<result property="fileScope" column="file_scope" />
|
||||||
<result property="status" column="role_status" />
|
<result property="status" column="role_status" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user