mirror of https://gitee.com/stylefeng/roses
【8.3.3】【role】更新接口,获取角色绑定的数据权限
parent
c3b34d451e
commit
e5d4535d2e
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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" />
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
* 新增组织机构层级
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
//-------------------------------移除掉的字段-------------------------------
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue