fix: 修复组织机构相关bug

1. 新增、修改组织机构清理当前用户组织树缓存
2. setOrg 方法取出没必要的 id去重
3. 超级管理员只查看自己的数据
4. 组织机构不可删除BUG
pull/9/head
Parker 3 years ago
parent 5362be8ad6
commit c936e391f5

File diff suppressed because one or more lines are too long

@ -162,6 +162,22 @@ public interface UserApi {
HttpServletRequest request
);
/**
* Id
* @param pageNo
* @param pageSize
* @param request request
* @return ResultVo
*/
@GetMapping("/findPageByTenant")
ResultVo<?> findPageByTenant(
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest request
);
/**
*
* @param model

@ -68,12 +68,4 @@ public interface UserOrgRefApi {
//@GetMapping("/getRolesByUserId")
ResultVo<UserOrgRefModel> getDefOrgByUserId(String userId);
/**
*
*
* @param userId ID
* @return ResultVo
*/
ResultVo<UserOrgRefWebModel> getOrgInfoByUserId(String userId);
}

@ -136,6 +136,12 @@ public class UserModel extends ApiWrapper {
@ValidatorLenMax(20)
private String tenantId;
/** 是否租户管理员 */
@ApiModelProperty(value = "是否租户管理员")
@ExcelIgnore
@ValidatorLenMax(1)
private String izTenantAdmin;
/** 是否存在组织 */
@JsonIgnore
@ExcelIgnore
@ -143,4 +149,6 @@ public class UserModel extends ApiWrapper {
private String izExistOrg;
}

@ -60,13 +60,13 @@ public class QueryTenantHandler implements QueryBuilderChain{
boolean tenantFlag = ReflectUtil.hasField(entityClazz, MyBatisConstants.FIELD_TENANT);
if(tenantFlag) {
String tenantId = UserUtil.getTenantId();
UserModel user = UserUtil.getUser();
//UserModel user = UserUtil.getUser();
// 超级管理员可以操作 无租户限制, 其余用户全部有租户限制
if(!UserUtil.SUPER_ADMIN.equals(user.getUsername()) &&
StringUtils.isNotEmpty(tenantId)
){
// if(!UserUtil.SUPER_ADMIN.equals(user.getUsername()) &&
// StringUtils.isNotEmpty(tenantId)
// ){
wrapper.eq(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT), tenantId);
}
//}
}
return wrapper;
}
@ -82,18 +82,18 @@ public class QueryTenantHandler implements QueryBuilderChain{
boolean tenantFlag = ReflectUtil.hasField(entityClazz, MyBatisConstants.FIELD_TENANT);
if(tenantFlag) {
String tenantId = UserUtil.getTenantId();
UserModel user = UserUtil.getUser();
//UserModel user = UserUtil.getUser();
// 超级管理员可以操作 无租户限制, 其余用户全部有租户限制
if(!UserUtil.SUPER_ADMIN.equals(user.getUsername()) &&
StringUtils.isNotEmpty(tenantId)
){
// if(!UserUtil.SUPER_ADMIN.equals(user.getUsername()) &&
// StringUtils.isNotEmpty(tenantId)
// ){
String fieldName = webQueryConf.get(MyBatisConstants.FIELD_TENANT);
if(StringUtils.isEmpty(fieldName)){
fieldName = FieldUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT);
}
wrapper.eq(fieldName, tenantId);
}
//}
}
return wrapper;
}

@ -61,7 +61,7 @@ public class UserUtil {
public static final String PREFIX_ID = "userId:";
public static final String PREFIX_ID_ROLES = "userId:roles:";
public static final String PREFIX_ID_DEF_ROLE = "userId:def_role:";
public static final String PREFIX_ID_ORGS = "userId:orgs";
public static final String PREFIX_ID_ORGS = "userId:orgs:";
public static final String PREFIX_ID_DEF_ORG = "userId:def_org:";
public static final String PREFIX_ID_PERMISSIONS = "userId:permissions:";
public static final String PREFIX_ID_MENUS = "userId:menus:";

@ -144,35 +144,6 @@ public class RoleServiceImpl extends CrudServiceImpl<RoleMapper, SysRole, RoleMo
return super.deleteAll(models);
}
@Override
public List<SysRole> findList(QueryWrapper<SysRole> queryWrapper) {
// 如果没有租户修改能力 则默认增加租户限制
if(!UserUtil.isHasUpdateTenantPerms(UserUtil.getUser())){
// 数据处理责任链
queryWrapper = new QueryTenantHandler(
new QueryDataPermsHandler()
).handler(entityClazz, queryWrapper);
}
return super.list(queryWrapper);
}
@Override
public List<SysRole> findAllList() {
QueryBuilder<SysRole> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysRole> queryWrapper = queryBuilder.build();
// 如果没有租户修改能力 则默认增加租户限制
if(!UserUtil.isHasUpdateTenantPerms(UserUtil.getUser())){
// 数据处理责任链
queryWrapper = new QueryTenantHandler(
new QueryDataPermsHandler()
).handler(entityClazz, queryWrapper);
}
return super.list(queryWrapper);
}
/**
*
* @param model model
@ -193,15 +164,9 @@ public class RoleServiceImpl extends CrudServiceImpl<RoleMapper, SysRole, RoleMo
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
}
UserModel currUser = UserUtil.getUser();
// 如果是超级管理员 需要特殊处理
// 如果租户ID 不为空 则直接判断租户
if(StringUtils.isNotBlank(model.getTenantId())){
wrapper.eq(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT), model.getTenantId());
}else {
// 如果是超级管理员 需要特殊处理
if(UserUtil.SUPER_ADMIN.equals(currUser.getUsername())){
// 角色分页 增加租户权限
wrapper.isNull(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT));
}else {
// 租户检测
// 数据处理责任链
@ -209,7 +174,6 @@ public class RoleServiceImpl extends CrudServiceImpl<RoleMapper, SysRole, RoleMo
new QueryDataPermsHandler()
).handler(entityClazz, wrapper);
}
}
return super.count(wrapper) == 0;
}
@ -235,15 +199,9 @@ public class RoleServiceImpl extends CrudServiceImpl<RoleMapper, SysRole, RoleMo
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
}
UserModel currUser = UserUtil.getUser();
// 如果是超级管理员 需要特殊处理
// 如果租户ID 不为空 则直接判断租户
if(StringUtils.isNotBlank(model.getTenantId())){
wrapper.eq(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT), model.getTenantId());
}else {
// 如果是超级管理员 需要特殊处理
if(UserUtil.SUPER_ADMIN.equals(currUser.getUsername())){
// 角色分页 增加租户权限
wrapper.isNull(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_TENANT));
}else {
// 租户检测
// 数据处理责任链
@ -251,9 +209,6 @@ public class RoleServiceImpl extends CrudServiceImpl<RoleMapper, SysRole, RoleMo
new QueryDataPermsHandler()
).handler(entityClazz, wrapper);
}
}
return super.count(wrapper) == 0;
}

@ -79,6 +79,9 @@ public class SysUser extends BaseEntity {
/** 是否存在组织 */
private String izExistOrg;
/** 是否租户管理员 */
private String izTenantAdmin;
// ========================================
/** 逻辑删除字段 */

@ -93,7 +93,6 @@ public class UserOrgRefServiceImpl extends ServiceImpl<UserOrgRefMapper, SysUser
List<SysUserOrgRef> orgRefList = super.list(wrapper);
if(CollUtil.isEmpty(orgRefList)){
// 判断是否是超级管理员 如果是超级管理员 则默认享有全部权限
if(StringUtils.equals(UserUtil.SUPER_ADMIN, userModel.getUsername())){
QueryWrapper<SysOrg> queryWrapper = new QueryWrapper<>();

@ -98,6 +98,7 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
// 如果没有租户修改能力 则清空对应字段
if(!UserUtil.isHasUpdateTenantPerms(UserUtil.getUser())){
model.setTenantId(null);
model.setIzTenantAdmin(null);
}
}
@ -193,6 +194,7 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
// 如果没有租户修改能力 则清空对应字段
if(!UserUtil.isHasUpdateTenantPerms(UserUtil.getUser())){
model.setTenantId(null);
model.setIzTenantAdmin(null);
}
}

@ -64,9 +64,6 @@ public class UserOrgRefRestController implements UserOrgRefApi {
@Autowired
private IUserOrgRefService iUserOrgRefService;
@Autowired
private IUserService iUserService;
@Override
public ResultVo<List<UserOrgRefModel>> findListByUserId(String userId) {
List<UserOrgRefModel> listByUserId = iUserOrgRefService.findListByUserId(userId);
@ -103,76 +100,6 @@ public class UserOrgRefRestController implements UserOrgRefApi {
return ResultVo.success(userOrgRefModel);
}
/**
*
* @param userId ID
* @return ResultVo
*/
@ApiOperation(value = "用户组织机构", notes = "用户组织机构")
@Override
public ResultVo<UserOrgRefWebModel> getOrgInfoByUserId(String userId) {
UserOrgRefWebModel org = null;
// 不写SQL了 直接分页 第一页 取第一条
QueryBuilder<SysUserWeb> queryBuilder = new GenQueryBuilder<>();
Page<SysUserWeb, UserWebModel> page = new Page<>(1, 1);
QueryWrapper<SysUserWeb> queryWrapper = queryBuilder.build();
queryWrapper.eq(
"a.id",
userId
);
page.setQueryWrapper(queryWrapper);
page = iUserService.findPageByCus(page);
List<UserWebModel> list = page.getList();
if(CollUtil.isNotEmpty(list)){
UserWebModel userWebModel = list.get(0);
if(userWebModel != null){
// org = userAndOrgModel.getOrg();
// if(org != null){
//
// org.setUserId(userId);
// List<String> orgIds = Lists.newArrayListWithCapacity(3);
// orgIds.add(org.getCompanyId());
// orgIds.add(org.getDepartmentId());
// orgIds.add(org.getPostId());
// QueryWrapper<SysOrg> orgQueryWrapper = new QueryWrapper<>();
// orgQueryWrapper.in(
// FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID),
// orgIds);
// List<SysOrg> orgList = iSysOrgService.findList(orgQueryWrapper);
// if(CollUtil.isNotEmpty(orgList)){
// Map<String, SysOrg> tmp = Maps.newHashMap();
// for (SysOrg sysOrg : orgList) {
// tmp.put(sysOrg.getId(), sysOrg);
// }
//
// // 设置 名称
// SysOrg company = tmp.get(org.getCompanyId());
// if(company != null){
// org.setCompanyName(company.getOrgName());
// }
//
// SysOrg department = tmp.get(org.getDepartmentId());
// if(department != null){
// org.setDepartmentName(department.getOrgName());
// }
//
// SysOrg post = tmp.get(org.getPostId());
// if(post != null){
// org.setPostName(post.getOrgName());
// }
// }
// }
}
}
return ResultVo.success(org);
}
/**
*

@ -35,8 +35,11 @@ import org.opsli.api.wrapper.system.user.*;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.annotation.EnableLog;
import org.opsli.common.annotation.RequiresPermissionsCus;
import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.enums.DictType;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.exception.TokenException;
import org.opsli.common.utils.FieldUtil;
import org.opsli.common.utils.WrapperUtil;
import org.opsli.core.base.controller.BaseRestController;
import org.opsli.core.msg.TokenMsg;
@ -322,6 +325,9 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
Page<SysUserWeb, UserWebModel> page = new Page<>(pageNo, pageSize);
QueryWrapper<SysUserWeb> queryWrapper = queryBuilder.build();
// 不查看 为租户管理员的用户
queryWrapper.notIn("iz_tenant_admin", DictType.NO_YES_YES.getValue());
// 处理组织权限
OrgUtil.handleOrgIdGroupCondition(orgIdGroup, queryWrapper);
@ -336,6 +342,37 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
return ResultVo.success(page.getPageData());
}
/**
*
* @param pageNo
* @param pageSize
* @param request request
* @return ResultVo
*/
@ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器")
@RequiresPermissions("system_set_tenant_admin")
@Override
public ResultVo<?> findPageByTenant(Integer pageNo, Integer pageSize,
HttpServletRequest request) {
QueryBuilder<SysUserWeb> queryBuilder = new WebQueryBuilder<>(
SysUserWeb.class, request.getParameterMap());
Page<SysUserWeb, UserWebModel> page = new Page<>(pageNo, pageSize);
QueryWrapper<SysUserWeb> queryWrapper = queryBuilder.build();
// 只查看 为租户管理员的用户
queryWrapper.eq("iz_tenant_admin", DictType.NO_YES_YES.getValue());
page.setQueryWrapper(queryWrapper);
page = IService.findPageByCus(page);
// 密码防止分页泄露处理
for (UserWebModel userModel : page.getList()) {
userModel.setSecretKey(null);
userModel.setPassword(null);
userModel.setPasswordLevel(null);
}
return ResultVo.success(page.getPageData());
}
/**
*
* @param model

Loading…
Cancel
Save