♻️ Refactoring code. 数据权限 DataScope.java 增加链式操作方便使用

This commit is contained in:
lbw committed 2022-05-13 10:51:22 +08:00
1 parent 73c6fa415d
commit c5f291943e
7 files changed
+36 -14

No files matched your search

@@ -56,4 +56,31 @@ public class DataScope extends HashMap {
*/
private DataScopeFuncEnum func = DataScopeFuncEnum.ALL;
/**
* of 获取实例
*/
public static DataScope of() {
return new DataScope();
}
public DataScope scopeName(String scopeName) {
this.scopeName = scopeName;
return this;
}
public DataScope deptIds(List<Long> deptIds) {
this.deptIds = deptIds;
return this;
}
public DataScope only(boolean isOnly) {
this.isOnly = isOnly;
return this;
}
public DataScope func(DataScopeFuncEnum func) {
this.func = func;
return this;
}
}
@@ -27,7 +27,7 @@ public class SelectCountByScope extends AbstractMethod {
this.sqlComment());
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
return this.addSelectMappedStatementForOther(mapperClass, sqlSource, Integer.class);
return this.addSelectMappedStatementForOther(mapperClass, sqlSource, Long.class);
}
}
@@ -36,7 +36,7 @@ public class FileProperties {
/**
* 默认的存储桶名称
*/
private String bucketName = "payerp";
private String bucketName = "local";
/**
* 本地文件配置信息
@@ -22,6 +22,7 @@ import com.pig4cloud.pigx.admin.api.entity.SysUser;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.core.util.RetOps;
import org.springframework.core.Ordered;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
@@ -29,10 +30,7 @@ import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
/**
* @author lengleng
@@ -64,11 +62,8 @@ public interface PigxUserDetailsService extends UserDetailsService, Ordered {
* @return UserDetails
*/
default UserDetails getUserDetails(R<UserInfo> result) {
if (result == null || result.getData() == null) {
throw new UsernameNotFoundException("用户不存在");
}
UserInfo info = RetOps.of(result).getData().orElseThrow(() -> new UsernameNotFoundException("用户不存在"));
UserInfo info = result.getData();
Set<String> dbAuthsSet = new HashSet<>();
if (ArrayUtil.isNotEmpty(info.getRoles())) {
// 获取角色
@@ -127,7 +127,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
// 查询数据权限内部门
List<Long> deptOwnIdList = deptMapper.selectListByScope(
Wrappers.<SysDept>lambdaQuery().like(StrUtil.isNotBlank(deptName), SysDept::getName, deptName),
new DataScope()).stream().map(SysDept::getDeptId).collect(Collectors.toList());
DataScope.of()).stream().map(SysDept::getDeptId).collect(Collectors.toList());
// 权限内部门
List<TreeNode<Long>> collect = deptAllList.stream()
@@ -153,7 +153,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/
@Override
public IPage getUsersWithRolePage(Page page, UserDTO userDTO) {
return baseMapper.getUserVosPage(page, userDTO, new DataScope());
return baseMapper.getUserVosPage(page, userDTO, DataScope.of());
}
/**
@@ -258,7 +258,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override
public List<UserExcelVO> listUser(UserDTO userDTO) {
// 根据数据权限查询全部的用户信息
List<UserVO> voList = baseMapper.selectVoListByScope(userDTO, new DataScope());
List<UserVO> voList = baseMapper.selectVoListByScope(userDTO, DataScope.of());
// 转换成execl 对象输出
List<UserExcelVO> userExcelVOList = voList.stream().map(userVO -> {
UserExcelVO excelVO = new UserExcelVO();
+1 -1
View File
@@ -40,7 +40,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.version>3.8.1</maven.compiler.version>
<spring.checkstyle.version>0.0.31</spring.checkstyle.version>
<spring.checkstyle.version>0.0.29</spring.checkstyle.version>
<git.commit.version>2.2.5</git.commit.version>
<spring-boot-admin.version>2.6.7</spring-boot-admin.version>
<captcha.version>1.2.7</captcha.version>