【8.3.3】【role】更新接口,获取角色绑定的数据权限

dev-8.3.3
stylefeng 2025-01-24 22:09:27 +08:00
parent c3b34d451e
commit e5d4535d2e
14 changed files with 120 additions and 34 deletions

View File

@ -24,6 +24,9 @@
*/
package cn.stylefeng.roses.kernel.rule.enums.permission;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.rule.base.ReadableEnum;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.rule.exception.enums.DataScopeExceptionEnum;
import lombok.Getter;
@ -35,7 +38,7 @@ import lombok.Getter;
* @since 2020/11/5 15:22
*/
@Getter
public enum DataScopeTypeEnum {
public enum DataScopeTypeEnum implements ReadableEnum<DataScopeTypeEnum> {
/**
*
@ -105,4 +108,26 @@ public enum DataScopeTypeEnum {
throw new ServiceException(DataScopeExceptionEnum.DATA_SCOPE_ERROR);
}
@Override
public Object getKey() {
return code;
}
@Override
public Object getName() {
return message;
}
@Override
public DataScopeTypeEnum parseToEnum(String originValue) {
if (ObjectUtil.isEmpty(originValue)) {
return null;
}
for (DataScopeTypeEnum value : DataScopeTypeEnum.values()) {
if (value.code.equals(Convert.toInt(originValue))) {
return value;
}
}
return null;
}
}

View File

@ -0,0 +1,26 @@
package cn.stylefeng.roses.kernel.sys.api;
import cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.api.pojo.org.OrganizationLevelRequest;
import java.util.List;
/**
* Api
*
* @author fengshuonan
* @since 2023/6/18 23:14
*/
public interface OrgLevelServiceApi {
/**
*
*
* @param organizationLevelRequest
* @return List<OrganizationLevel>
* @author fengshuonan
* @since 2025/01/22 09:44
*/
List<OrganizationLevel> findList(OrganizationLevelRequest organizationLevelRequest);
}

View File

@ -1,4 +1,4 @@
package cn.stylefeng.roses.kernel.sys.modular.org.entity;
package cn.stylefeng.roses.kernel.sys.api.entity;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;

View File

@ -1,8 +1,8 @@
package cn.stylefeng.roses.kernel.sys.modular.org.pojo.request;
package cn.stylefeng.roses.kernel.sys.api.pojo.org;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import lombok.EqualsAndHashCode;

View File

@ -5,8 +5,8 @@ import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.OrganizationLevelRequest;
import cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.api.pojo.org.OrganizationLevelRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.service.OrganizationLevelService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;

View File

@ -3,6 +3,7 @@ package cn.stylefeng.roses.kernel.sys.modular.org.entity;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseExpandFieldEntity;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.tree.factory.base.AbstractTreeNode;
import cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

View File

@ -1,7 +1,7 @@
package cn.stylefeng.roses.kernel.sys.modular.org.mapper;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.OrganizationLevelRequest;
import cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.api.pojo.org.OrganizationLevelRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.OrganizationLevelVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

View File

@ -3,7 +3,7 @@
<mapper namespace="cn.stylefeng.roses.kernel.sys.modular.org.mapper.OrganizationLevelMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel">
<resultMap id="BaseResultMap" type="cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel">
<id column="org_level_id" property="orgLevelId" />
<result column="level_number" property="levelNumber" />
<result column="level_name" property="levelName" />

View File

@ -1,6 +1,6 @@
package cn.stylefeng.roses.kernel.sys.modular.org.pojo.response;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;

View File

@ -1,28 +1,17 @@
package cn.stylefeng.roses.kernel.sys.modular.org.service;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.OrganizationLevelRequest;
import cn.stylefeng.roses.kernel.sys.api.OrgLevelServiceApi;
import cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.api.pojo.org.OrganizationLevelRequest;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
*
*
* @author fengshuonan
* @since 2025/01/22 09:44
*/
public interface OrganizationLevelService extends IService<OrganizationLevel> {
/**
*
*
* @param organizationLevelRequest
* @return List<OrganizationLevel>
* @author fengshuonan
* @since 2025/01/22 09:44
*/
List<OrganizationLevel> findList(OrganizationLevelRequest organizationLevelRequest);
public interface OrganizationLevelService extends IService<OrganizationLevel>, OrgLevelServiceApi {
/**
*

View File

@ -26,19 +26,19 @@ import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
import cn.stylefeng.roses.kernel.rule.tree.factory.DefaultTreeBuildFactory;
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveOrgCallbackApi;
import cn.stylefeng.roses.kernel.sys.api.constants.SysConstants;
import cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.api.enums.org.DetectModeEnum;
import cn.stylefeng.roses.kernel.sys.api.enums.org.OrgTypeEnum;
import cn.stylefeng.roses.kernel.sys.api.exception.enums.OrgExceptionEnum;
import cn.stylefeng.roses.kernel.sys.api.pojo.org.CompanyDeptDTO;
import cn.stylefeng.roses.kernel.sys.api.pojo.org.HrOrganizationDTO;
import cn.stylefeng.roses.kernel.sys.api.pojo.org.OrganizationLevelRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.constants.OrgConstants;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.HrOrganization;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.modular.org.factory.OrganizationFactory;
import cn.stylefeng.roses.kernel.sys.modular.org.mapper.HrOrganizationMapper;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.CommonOrgTreeRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.HrOrganizationRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.OrganizationLevelRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.CommonOrgTreeResponse;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.HomeCompanyInfo;
import cn.stylefeng.roses.kernel.sys.modular.org.service.HrOrganizationService;

View File

@ -1,12 +1,12 @@
package cn.stylefeng.roses.kernel.sys.modular.org.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.api.exception.SysException;
import cn.stylefeng.roses.kernel.sys.api.exception.enums.OrgExceptionEnum;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.api.pojo.org.OrganizationLevelRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.enums.OrganizationLevelExceptionEnum;
import cn.stylefeng.roses.kernel.sys.modular.org.mapper.OrganizationLevelMapper;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.OrganizationLevelRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.service.OrganizationLevelService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

View File

@ -2,6 +2,11 @@ package cn.stylefeng.roses.kernel.sys.modular.role.entity;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.annotation.EnumFieldFormat;
import cn.stylefeng.roses.kernel.rule.annotation.SimpleFieldFormat;
import cn.stylefeng.roses.kernel.rule.enums.permission.DataScopeTypeEnum;
import cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.api.format.OrgNameFormatProcess;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
@ -44,7 +49,8 @@ public class SysRoleDataScope extends BaseEntity {
*/
@TableField("data_scope_type")
@ChineseDescription("数据范围类型10-仅本人数据20-本部门数据30-本部门及以下数据31-本公司及以下数据32-指定机构层级及以下40-指定机构集合数据41-指定机构及以下50-全部数据")
private Integer data_scope_type;
@EnumFieldFormat(processEnum = DataScopeTypeEnum.class)
private Integer dataScopeType;
/**
* 32-使
@ -58,6 +64,7 @@ public class SysRoleDataScope extends BaseEntity {
*/
@TableField(value = "define_org_list", typeHandler = JacksonTypeHandler.class)
@ChineseDescription("指定机构集合列表用在类型为40-指定机构集合数据,情况时使用")
@SimpleFieldFormat(processClass = OrgNameFormatProcess.class)
private List<String> defineOrgList;
/**
@ -65,8 +72,18 @@ public class SysRoleDataScope extends BaseEntity {
*/
@TableField("define_org_id")
@ChineseDescription("指定机构的id用在类型为41-指定机构及以下,情况时使用")
@SimpleFieldFormat(processClass = OrgNameFormatProcess.class)
private Long defineOrgId;
//-------------------------------非实体字段-------------------------------
/**
*
*/
@TableField(exist = false)
@ChineseDescription("层级的详情")
private OrganizationLevel organizationLevel;
//-------------------------------移除掉的字段-------------------------------
/**

View File

@ -10,7 +10,10 @@ import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.log.api.util.BusinessLogUtil;
import cn.stylefeng.roses.kernel.rule.enums.permission.DataScopeTypeEnum;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.sys.api.OrgLevelServiceApi;
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveRoleCallbackApi;
import cn.stylefeng.roses.kernel.sys.api.entity.OrganizationLevel;
import cn.stylefeng.roses.kernel.sys.api.pojo.org.OrganizationLevelRequest;
import cn.stylefeng.roses.kernel.sys.api.pojo.role.response.RoleBindDataScopeResponse;
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleDataScope;
import cn.stylefeng.roses.kernel.sys.modular.role.enums.exception.SysRoleDataScopeExceptionEnum;
@ -39,12 +42,14 @@ import java.util.stream.Collectors;
* @date 2023/06/10 21:29
*/
@Service
public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMapper, SysRoleDataScope> implements SysRoleDataScopeService,
RemoveRoleCallbackApi {
public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMapper, SysRoleDataScope> implements SysRoleDataScopeService, RemoveRoleCallbackApi {
@Resource
private SysRoleService sysRoleService;
@Resource
private OrgLevelServiceApi orgLevelServiceApi;
@Override
public void add(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
SysRoleDataScope sysRoleDataScope = new SysRoleDataScope();
@ -74,6 +79,27 @@ public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMap
public PageResult<SysRoleDataScope> findPage(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
LambdaQueryWrapper<SysRoleDataScope> wrapper = createWrapper(sysRoleDataScopeRequest);
Page<SysRoleDataScope> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
List<SysRoleDataScope> records = sysRolePage.getRecords();
if (ObjectUtil.isEmpty(records)) {
return PageResultFactory.createPageResult(sysRolePage);
}
// 组织机构层级编码,转化为层级的名称
boolean haveOrgLevelType = false;
for (SysRoleDataScope record : records) {
if (DataScopeTypeEnum.DEFINE_ORG_LEVEL_WITH_CHILD.getCode().equals(record.getDataScopeType())) {
haveOrgLevelType = true;
break;
}
}
if (haveOrgLevelType) {
List<OrganizationLevel> list = orgLevelServiceApi.findList(new OrganizationLevelRequest());
for (SysRoleDataScope record : records) {
record.setOrganizationLevel(list.stream().filter(item -> item.getLevelCode().equals(record.getOrgLevelCode())).findFirst().orElse(null));
}
}
return PageResultFactory.createPageResult(sysRolePage);
}
@ -190,8 +216,10 @@ public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMap
LambdaQueryWrapper<SysRoleDataScope> queryWrapper = new LambdaQueryWrapper<>();
// 根据角色id进行查询
Long roleId = sysRoleDataScopeRequest.getRoleId();
queryWrapper.eq(ObjectUtil.isNotNull(roleId), SysRoleDataScope::getRoleId, roleId);
queryWrapper.eq(SysRoleDataScope::getRoleId, sysRoleDataScopeRequest.getRoleId());
// 按类型排序
queryWrapper.orderByAsc(SysRoleDataScope::getDataScopeType);
return queryWrapper;
}