Merge remote-tracking branch 'origin/feature/REQ-1102' into feature/REQ-1102

This commit is contained in:
zhansihu 2023-09-15 10:57:36 +08:00
commit c3a61c8ccb
30 changed files with 479 additions and 145 deletions

View File

@ -0,0 +1,7 @@
client.test("request executed successful", function () {
client.assert(response.status == 200, "Response status is not 200")
});
client.test("response body status successful", function () {
client.assert(response.body.code == 0, "Response body code is not 0")
});

View File

@ -0,0 +1,8 @@
{
"local": {
"host": "http://localhost:8080"
},
"dev": {
"host": "https://dev-app.axzo.cn/msg-center/webApi/message/"
}
}

View File

@ -0,0 +1,13 @@
###
POST {{host}}/api/saas-role-user/list
Accept: application/json
Content-Type: application/json
{
}
> reponse-check.js

View File

@ -22,7 +22,7 @@ public interface SaasRoleGroupApi {
* @return
*/
@PostMapping("/api/saasRoleGroup/save")
ApiResult saveOrUpdate(@RequestBody SaasRoleGroupVO req);
ApiResult<Long> saveOrUpdate(@RequestBody SaasRoleGroupVO req);
/**
* 获取权限分组列表

View File

@ -7,6 +7,7 @@ import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
import cn.axzo.tyr.client.model.vo.SaveOrUpdateRoleVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -27,7 +28,7 @@ public interface TyrSaasRoleApi {
* 如果权限列表不为空则创建通用权限
*/
@PostMapping("/api/saasRole/saveOrUpdate")
ApiResult<Long> saveOrUpdate(@RequestBody SaveOrUpdateRoleVO saveOrUpdateRole);
ApiResult<Long> saveOrUpdate(@RequestBody @Validated SaveOrUpdateRoleVO saveOrUpdateRole);
/**
* 根据id查询详情

View File

@ -1,12 +1,15 @@
package cn.axzo.tyr.client.feign;
import cn.axzo.framework.domain.web.result.ApiResult;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserRelationDTO;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserParam;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserReq;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import javax.validation.Valid;
import java.util.List;
/**
* 角色
@ -20,6 +23,12 @@ public interface TyrSaasRoleUserApi {
@PostMapping("/api/saas-role-user/save-or-update")
ApiResult<Void> saveOrUpdate(@RequestBody @Valid RoleUserReq req);
/**
* 用户角色列表 限制1000条
* @param param
* @return
*/
@PostMapping("/api/saas-role-user/list")
ApiResult<List<SaasRoleUserRelationDTO>> roleUserList(@RequestBody @Valid RoleUserParam param);
}

View File

@ -18,6 +18,16 @@ public class BasicDictTreeResp {
private Long parentId;
/**
* 工作台类型"ent", "proj", "oms"
*/
private String workspaceType;
/**
* 类型"ouType", "terminal"
*/
private String type;
/**
* 字典名称
*/

View File

@ -0,0 +1,71 @@
package cn.axzo.tyr.client.model.roleuser.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author haiyangjin
* @date 2023/9/14
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SaasRoleUserRelationDTO {
/**
* 主键ID
*/
private Long id;
/**
* 身份Id
*/
private Long identityId;
/**
* 身份类型 1:工人 2:从业人员 3:班组长 4:运营人员 5:政务人员
*/
private Integer identityType;
/**
* 角色Id
*/
private Long roleId;
/**
* 自然人Id
*/
private Long naturalPersonId;
/**
* 创建者
*/
private Long createBy;
/**
* 更新者
*/
private Long updateBy;
/**
* 所属单位Id 用户在当前工作台的所属单位
*/
private Long ouId;
/**
* 工作台Id
*/
private Long workspaceId;
/**
* 资源类型
*/
private Integer resourceType;
/**
* 资源Id
*/
private Long resourceId;
}

View File

@ -0,0 +1,53 @@
package cn.axzo.tyr.client.model.roleuser.req;
import cn.axzo.tyr.client.model.enums.IdentityType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Set;
/**
* @author haiyangjin
* @date 2023/9/14
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RoleUserParam {
/**
* 工作台id
*/
private Long workspaceId;
/**
* 单位id
*/
private Long ouId;
/**
* personId
*/
private Long personId;
/**
* 身份id
* 传身份id的时候请带上身份类型 身份id会重复
*/
private Long identityId;
/**
* 身份类型
*/
private IdentityType identityType;
/**
* role ids
*/
private Set<Long> roleIds;
}

View File

@ -47,6 +47,7 @@ public class RoleUserReq {
*/
@NotNull
private IdentityType identityType;
/**
* 完整的update所有RoleId都被更新
*/

View File

@ -1,13 +1,20 @@
package cn.axzo.tyr.client.model.vo;
import cn.axzo.trade.datasecurity.core.annotation.control.DisableCrypt;
import cn.axzo.tyr.client.model.permission.PermissionPointTreeNode;
import cn.hutool.core.collection.CollectionUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@Data
@ -16,47 +23,118 @@ import java.util.stream.Collectors;
@Builder
public class SaasRoleVO {
private Long id;
private Long id;
/**
* 角色名称
*/
private String name;
/**
* 角色名称
*/
private String name;
/**
* 角色类型common 普通角色 admin管理员
*/
private String roleType;
/**
* 角色类型 init 标准 common 自定义角色 admin管理员 super_admin 超管
*/
private String roleType;
/**
* 创建者
*/
private Long createBy;
/**
* 创建者
*/
private Long createBy;
/**
* 更新者
*/
private Long updateBy;
/**
* 更新者
*/
private Long updateBy;
/**
* 权限组
*/
private List<SaasPermissionGroupVO> permissionGroup;
/**
* 权限组
*/
private List<SaasPermissionGroupVO> permissionGroup;
/**
* 是否删除
*/
private Long isDelete;
/**
* 是否删除
*/
private Long isDelete;
private Date createAt;
private Date createAt;
private Date updateAt;
private Date updateAt;
/**
* 获取角色对应所用的权限
* @return
*/
public List<PermissionPointTreeNode> getFeature(){
return this.permissionGroup.stream().map(SaasPermissionGroupVO::getFeature).flatMap(List::stream).distinct().collect(Collectors.toList());
}
/**
* 获取角色对应所用的菜单不管例外
*
* @return
*/
public List<PermissionPointTreeNode> getFeature() {
return this.permissionGroup.stream().map(SaasPermissionGroupVO::getFeature).flatMap(List::stream).distinct().collect(Collectors.toList());
}
/**
* 获取角色基于单位ID和工作台ID所匹配的所以菜单包括通用和例外
* @param workspaceId
* @param ouId
* @return
*/
public List<PermissionPointTreeNode> getMatchFeature (Long workspaceId, Long ouId) {
Set<PermissionPointTreeNode> permissionPoint = new HashSet<>();
//例外
group:
for (SaasPermissionGroupVO permissionGroupVO : permissionGroup) {
// 通用权限
if (CollectionUtil.isEmpty(permissionGroupVO.getScopes())) {
permissionPoint.addAll(permissionGroupVO.getFeature());
}
List<SaasRolePermissionScopeVO> scopes = permissionGroupVO.getScopes();
scope:
for (SaasRolePermissionScopeVO scope : scopes) {
//正选
if (Objects.equals(scope.getType(), 1)) {
// 判断是否与当前工作台或者单位ID匹配
if (scope.getScopeType().equals("workspace")
&& match(true, permissionPoint, permissionGroupVO.getFeature(), scope.getScopeId(), workspaceId)) {
continue group;
}
if (scope.getScopeType().equals("ou")
&& match(true, permissionPoint, permissionGroupVO.getFeature(), scope.getScopeId(), ouId)
) {
continue group;
}
//反选
} else if (Objects.equals(scope.getType(), 2)) {
// 判断是否与当前工作台或者单位ID匹配
if (scope.getScopeType().equals("workspace")
&& match(false, permissionPoint, permissionGroupVO.getFeature(), scope.getScopeId(), workspaceId)
/* && !Objects.equals(scope.getScopeId(), workspaceId)
&& permissionPoint.addAll(permissionGroupVO.getFeature())*/) {
continue group;
}
if (scope.getScopeType().equals("ou")
&& match(false, permissionPoint, permissionGroupVO.getFeature(), scope.getScopeId(), ouId)
/* && !Objects.equals(scope.getScopeId(), ouId)
&& permissionPoint.addAll(permissionGroupVO.getFeature())*/) {
continue group;
}
}
}
}
return new ArrayList<>((Collection) permissionPoint);
}
private boolean match(boolean isMatch, Set<PermissionPointTreeNode> source, Collection<PermissionPointTreeNode> target, Long scopeId, Long workspaceId) {
if (isMatch && scopeId.equals(workspaceId)) {
source.addAll(target);
return true;
} else if (!isMatch && !Objects.equals(scopeId, workspaceId)) {
source.addAll(target);
return true;
}
return false;
}
}

View File

@ -79,6 +79,6 @@ public class SaveOrUpdateRoleVO {
* 项目部类型字典code
*/
@NotNull
private Long workspaceTypeCode;
private String workspaceTypeCode;
}
}

View File

@ -23,9 +23,8 @@ public class SaasRoleGroupController implements SaasRoleGroupApi {
private final SaasRoleGroupService saasRoleGroupService;
@Override
public ApiResult saveOrUpdate(SaasRoleGroupVO req) {
saasRoleGroupService.saveOrUpdate(req);
return ApiResult.ok();
public ApiResult<Long> saveOrUpdate(SaasRoleGroupVO req) {
return ApiResult.ok(saasRoleGroupService.saveOrUpdate(req));
}
@Override

View File

@ -2,13 +2,18 @@ package cn.axzo.tyr.server.controller.roleuser;
import cn.axzo.framework.domain.web.result.ApiResult;
import cn.axzo.tyr.client.feign.TyrSaasRoleUserApi;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserRelationDTO;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserParam;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserReq;
import cn.axzo.tyr.server.service.SaasRoleUserRelationService;
import cn.axzo.tyr.server.service.SaasRoleUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.List;
/**
* @author tanjie@axzo.cn
@ -19,10 +24,16 @@ import javax.validation.Valid;
@RequiredArgsConstructor
public class RoleUserController implements TyrSaasRoleUserApi {
private final SaasRoleUserService saasRoleUserService;
private final SaasRoleUserRelationService saasRoleUserRelationService;
@Override
public ApiResult<Void> saveOrUpdate(@Valid RoleUserReq req) {
saasRoleUserService.saveOrUpdate(req);
return ApiResult.ok();
}
@Override
public ApiResult<List<SaasRoleUserRelationDTO>> roleUserList(@RequestBody @Valid RoleUserParam param) {
return ApiResult.ok(saasRoleUserRelationService.list(param));
}
}

View File

@ -62,10 +62,11 @@ public class OMSRoleJobHandler extends IJobHandler {
// 创建角色分组
SaasRoleGroup roleGroup = new SaasRoleGroup();
roleGroup.setWorkspaceTypeCode("6");
roleGroup.setOuTypeCode("7");
roleGroup.setOuTypeCode("6");
roleGroup.setName("管理员");
roleGroup.setWorkspaceId(-1l);
roleGroup.setOuId(-1l);
roleGroup.setSort(1);
roleGroupDao.save(roleGroup);
// 查询OMS的角色 workspaceType=6 OMS的角色
List<SaasRole> oldRole = roleDao.lambdaQuery()

View File

@ -15,13 +15,6 @@ import java.util.List;
@Repository
public class SaasRoleGroupRelationDao extends ServiceImpl<SaasRoleGroupRelationMapper, SaasRoleGroupRelation> {
public void deleteByRoleGroupId(List<Long> roleGroupId) {
lambdaUpdate()
.in(SaasRoleGroupRelation::getSaasRoleGroupId, roleGroupId)
.set(BaseEntity::getIsDelete, TableIsDeleteEnum.DELETE.value)
.update();
}
@Override
public boolean removeByIds(Collection<? extends Serializable> idList) {
if (CollectionUtils.isEmpty(idList)) {

View File

@ -62,9 +62,8 @@ public class SaasPermissionGroupScope extends BaseEntity<SaasPermissionGroupScop
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
SaasPermissionGroupScope that = (SaasPermissionGroupScope) o;
return Objects.equals(pgroupId, that.pgroupId) && Objects.equals(type, that.type) && Objects.equals(scopeType, that.scopeType) && Objects.equals(scopeId, that.scopeId) && Objects.equals(isDelete, that.isDelete);
return Objects.equals(pgroupId, that.pgroupId) && Objects.equals(type, that.type) && Objects.equals(scopeType, that.scopeType) && Objects.equals(scopeId, that.scopeId);
}
}

View File

@ -58,9 +58,8 @@ public class SaasPgroupPermissionRelation extends BaseEntity<SaasPgroupPermissio
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
SaasPgroupPermissionRelation that = (SaasPgroupPermissionRelation) o;
return Objects.equals(groupId, that.groupId) && Objects.equals(featureId, that.featureId) && Objects.equals(isDelete, that.isDelete);
return Objects.equals(groupId, that.groupId) && Objects.equals(featureId, that.featureId);
}
}

View File

@ -50,9 +50,8 @@ public class SaasRoleGroupRelation extends BaseEntity<SaasRoleGroupRelation> imp
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
SaasRoleGroupRelation that = (SaasRoleGroupRelation) o;
return Objects.equals(roleId, that.roleId) && Objects.equals(saasRoleGroupId, that.saasRoleGroupId) && Objects.equals(isDelete, that.isDelete);
return Objects.equals(roleId, that.roleId) && Objects.equals(saasRoleGroupId, that.saasRoleGroupId);
}
}

View File

@ -8,7 +8,7 @@ import java.util.List;
public interface SaasRoleGroupService {
List<SaasRoleGroupVO> getList(QuerySaasRoleGroupReq req);
void saveOrUpdate(SaasRoleGroupVO req);
Long saveOrUpdate(SaasRoleGroupVO req);
void delete(List<Long> ids);
}

View File

@ -0,0 +1,14 @@
package cn.axzo.tyr.server.service;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserRelationDTO;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserParam;
import java.util.List;
/**
* @author haiyangjin
* @date 2023/9/14
*/
public interface SaasRoleUserRelationService {
List<SaasRoleUserRelationDTO> list(RoleUserParam param);
}

View File

@ -1,8 +1,11 @@
package cn.axzo.tyr.server.service;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserParam;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserReq;
import cn.axzo.tyr.server.repository.entity.SaasPgroupPermissionRelation;
import javax.validation.Valid;
import java.util.List;
/**
* @author tanjie@axzo.cn
@ -11,6 +14,4 @@ import javax.validation.Valid;
public interface SaasRoleUserService {
void saveOrUpdate( RoleUserReq req);
}

View File

@ -61,6 +61,16 @@ public class PermissionGroupImpl implements PermissionGroupService {
@Override
public List<SaasPermissionGroupVO> query(QuerySaasPermissionGroupReq req) {
if (CollectionUtils.isEmpty(req.getWorkspaceId())) {
req.setWorkspaceId(Arrays.asList(-1l));
} else if(!req.getWorkspaceId().contains(-1l)){
req.getWorkspaceId().add(-1l);
}
if (CollectionUtils.isEmpty(req.getOuId())) {
req.setOuId(Arrays.asList(-1l));
} else if (!req.getOuId().contains(-1l)) {
req.getOuId().add(-1l);
}
// 如果角色id不为空则先查询角色权限集关联表
List<SaasPgroupRoleRelation> relationList = null;
if (CollectionUtils.isNotEmpty(req.getRoleIds())) {
@ -232,7 +242,7 @@ public class PermissionGroupImpl implements PermissionGroupService {
@Override
@Transactional(rollbackFor = Exception.class)
public void savePermissionPoints(SavePermissionGroupPPVO save) {
SaasPermissionGroup saasPermissionGroup = getRequiredPermissionGroup(save.getId(), PermissionGroupType.COMMON);
SaasPermissionGroup saasPermissionGroup = getRequiredPermissionGroup(save.getId(), null);
List<SaasPgroupPermissionRelation> pgpRelations = Optional.ofNullable(save.getSelectedPPIds()).orElse(new ArrayList<>()).stream().map(ppId -> {
SaasPgroupPermissionRelation target = new SaasPgroupPermissionRelation();
target.setGroupId(saasPermissionGroup.getId());
@ -256,6 +266,8 @@ public class PermissionGroupImpl implements PermissionGroupService {
saasPermissionGroup = new SaasPermissionGroup();
saasPermissionGroup.setCreateBy(permissionGroup.getOperatorId());
saasPermissionGroup.setCreatorName(Optional.ofNullable(permissionGroup.getOperatorName()).orElse(""));
saasPermissionGroup.setUpdateBy(permissionGroup.getOperatorId());
saasPermissionGroup.setUpdatorName(Optional.ofNullable(permissionGroup.getOperatorName()).orElse(""));
saasPermissionGroup.setIsCommon(PermissionGroupType.SPECIAL.getCode());
saasPermissionGroup.setCreateAt(now);
}
@ -314,7 +326,7 @@ public class PermissionGroupImpl implements PermissionGroupService {
throw new BizException(BaseCode.BAD_REQUEST, "权限集不存在");
}
SaasPermissionGroup saasPermissionGroup = groups.get(0);
if (!Objects.equals(saasPermissionGroup.getIsCommon(), type.getCode())) {
if (Objects.nonNull(type) && !Objects.equals(saasPermissionGroup.getIsCommon(), type.getCode())) {
throw new BizException(BaseCode.BAD_REQUEST, String.format("权限集不是%s权限集", type.getDesc()));
}
return saasPermissionGroup;
@ -344,7 +356,7 @@ public class PermissionGroupImpl implements PermissionGroupService {
// 删除例外scope
saasPermissionGroupScopeDao.removeByIds(scopes.stream().map(SaasPermissionGroupScope::getId).sorted().collect(Collectors.toList()));
}
// 删除通用权限集
// 删除权限集
permissionGroupDao.lambdaUpdate()
.in(BaseEntity::getId,deleteGroupIds)
.set(BaseEntity::getIsDelete, TableIsDeleteEnum.DELETE.value)
@ -357,10 +369,11 @@ public class PermissionGroupImpl implements PermissionGroupService {
private void validSaasPermissionGroup(SaveOrUpdatePermissionGroupVO permissionGroup) {
SaasRole saasRole = saasRoleDao.getById(permissionGroup.getRoleId());
if (Objects.isNull(saasRole)) {
throw new BizException(BaseCode.BAD_REQUEST, "角色不存在");
throw new BizException(BaseCode.BAD_REQUEST, "权限集不存在");
}
if (Objects.nonNull(permissionGroup.getId())) {
int relationCount = roleRelationDao.lambdaQuery().eq(SaasPgroupRoleRelation::getRoleId, permissionGroup.getRoleId())
int relationCount = roleRelationDao.lambdaQuery()
.eq(SaasPgroupRoleRelation::getRoleId, permissionGroup.getRoleId())
.eq(SaasPgroupRoleRelation::getGroupId, permissionGroup.getId())
.eq(SaasPgroupRoleRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).count();
if (relationCount == 0) {
@ -373,11 +386,12 @@ public class PermissionGroupImpl implements PermissionGroupService {
if (CollectionUtils.isEmpty(selectedWorkspace) && CollectionUtils.isEmpty(selectedOu)) {
throw new BizException(BaseCode.BAD_REQUEST, "例外不能为空");
}
// TODO 校验规则是产品给的吗?
if (CollectionUtils.isNotEmpty(selectedWorkspace)) {
Map<Integer, List<SaveOrUpdatePermissionGroupVO.PermissionGroupScopeVO>> selectedWorkspaceMap = selectedWorkspace.stream()
.collect(Collectors.groupingBy(SaveOrUpdatePermissionGroupVO.PermissionGroupScopeVO::getType));
List<SaveOrUpdatePermissionGroupVO.PermissionGroupScopeVO> includeScopes = Optional.ofNullable(selectedWorkspaceMap.get(PermissionScope.INCLUDE)).orElse(new ArrayList<>());
List<SaveOrUpdatePermissionGroupVO.PermissionGroupScopeVO> excludeScopes = Optional.ofNullable(selectedWorkspaceMap.get(PermissionScope.EXCLUDE)).orElse(new ArrayList<>());
List<SaveOrUpdatePermissionGroupVO.PermissionGroupScopeVO> includeScopes = Optional.ofNullable(selectedWorkspaceMap.get(PermissionScope.INCLUDE.getCode())).orElse(new ArrayList<>());
List<SaveOrUpdatePermissionGroupVO.PermissionGroupScopeVO> excludeScopes = Optional.ofNullable(selectedWorkspaceMap.get(PermissionScope.EXCLUDE.getCode())).orElse(new ArrayList<>());
if (includeScopes.size() + excludeScopes.size() != selectedWorkspace.size()) {
throw new BizException(BaseCode.BAD_REQUEST, "选择类型设置错误");
}
@ -389,8 +403,8 @@ public class PermissionGroupImpl implements PermissionGroupService {
if (CollectionUtils.isNotEmpty(selectedOu)) {
Map<Integer, List<SaveOrUpdatePermissionGroupVO.PermissionGroupScopeVO>> selectedOuMap = selectedOu.stream()
.collect(Collectors.groupingBy(SaveOrUpdatePermissionGroupVO.PermissionGroupScopeVO::getType));
List<SaveOrUpdatePermissionGroupVO.PermissionGroupScopeVO> includeScopes = Optional.ofNullable(selectedOuMap.get(PermissionScope.INCLUDE)).orElse(new ArrayList<>());
List<SaveOrUpdatePermissionGroupVO.PermissionGroupScopeVO> excludeScopes = Optional.ofNullable(selectedOuMap.get(PermissionScope.EXCLUDE)).orElse(new ArrayList<>());
List<SaveOrUpdatePermissionGroupVO.PermissionGroupScopeVO> includeScopes = Optional.ofNullable(selectedOuMap.get(PermissionScope.INCLUDE.getCode())).orElse(new ArrayList<>());
List<SaveOrUpdatePermissionGroupVO.PermissionGroupScopeVO> excludeScopes = Optional.ofNullable(selectedOuMap.get(PermissionScope.EXCLUDE.getCode())).orElse(new ArrayList<>());
if (includeScopes.size() + excludeScopes.size() != selectedWorkspace.size()) {
throw new BizException(BaseCode.BAD_REQUEST, "选择类型设置错误");
}

View File

@ -13,8 +13,8 @@ import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
import cn.axzo.tyr.client.model.vo.SaasPermissionGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
import cn.axzo.tyr.client.model.vo.SaveOrUpdateRoleVO;
import cn.axzo.tyr.server.repository.entity.*;
import cn.axzo.tyr.server.repository.dao.*;
import cn.axzo.tyr.server.repository.entity.*;
import cn.axzo.tyr.server.service.*;
import cn.hutool.core.bean.BeanUtil;
import lombok.RequiredArgsConstructor;
@ -209,6 +209,14 @@ public class RoleServiceImpl implements RoleService {
if (Objects.isNull(saasRole)) {
throw new BizException(BaseCode.BAD_REQUEST, "角色不存在");
}
if (Objects.isNull(saveOrUpdateRole.getPermissionGroupId())) {
throw new BizException(BaseCode.BAD_REQUEST, "更新角色时权限集不能为空不存在");
}
SaasPermissionGroup group = saasPermissionGroupDao.lambdaQuery().eq(SaasPermissionGroup::getId, saveOrUpdateRole.getPermissionGroupId())
.eq(SaasPermissionGroup::getIsDelete, TableIsDeleteEnum.NORMAL.value).one();
if (Objects.isNull(group)) {
throw new BizException(BaseCode.BAD_REQUEST, "权限集不存在");
}
} else {
saasRole = new SaasRole();
saasRole.setCreateBy(saveOrUpdateRole.getOperatorId());
@ -225,7 +233,6 @@ public class RoleServiceImpl implements RoleService {
saasRole.setDescription(saasRole.getDescription());
saasRole.setRoleType(saveOrUpdateRole.getRoleType());
saasRole.setWorkspaceId(saveOrUpdateRole.getWorkspaceId());
// saasRole.setWorkspaceType(saveOrUpdateRole.getWorkspaceType());
saasRole.setOwnerOuId(saveOrUpdateRole.getOwnerOuId());
saasRole.setUpdateBy(saveOrUpdateRole.getOperatorId());
saasRole.setUpdateAt(now);
@ -241,10 +248,10 @@ public class RoleServiceImpl implements RoleService {
}).collect(Collectors.toList()));
saasPermissionGroupDao.saveOrUpdate(saasPermissionGroup);
SaasPgroupRoleRelation pgrr = new SaasPgroupRoleRelation();
pgrr.setCreateBy(saveOrUpdateRole.getOperatorId());
pgrr.setRoleId(saasRole.getId());
pgrr.setUpdateBy(saveOrUpdateRole.getOperatorId());
pgrr.setGroupId(saasPermissionGroup.getId());
pgrr.setCreateBy(saveOrUpdateRole.getOperatorId());
pgrr.setUpdateBy(saveOrUpdateRole.getOperatorId());
pgrr.setCreateAt(now);
pgrr.setUpdateAt(now);
// 新增或保存角色通用权限映射
@ -306,7 +313,7 @@ public class RoleServiceImpl implements RoleService {
Map<Long, SaasRoleGroup> roleGroupMap = groups.stream().collect(Collectors.toMap(SaasRoleGroup::getId, Function.identity()));
List<SaveOrUpdateRoleVO.GroupInfoVO> invalidRoleGroups = groupTrees.stream().filter(rg -> {
SaasRoleGroup target = roleGroupMap.get(rg.getId());
return Objects.isNull(target) || !Objects.equals(target.getWorkspaceTypeCode(), rg.getWorkspaceTypeCode().toString());
return Objects.isNull(target) || !Objects.equals(target.getWorkspaceTypeCode(), rg.getWorkspaceTypeCode());
}).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(invalidRoleGroups)) {
throw new BizException(BaseCode.BAD_REQUEST, "角色分组信息错误");

View File

@ -22,7 +22,7 @@ public class SaasPermissionGroupScopeServiceImpl implements SaasPermissionGroupS
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(List<SaasPermissionGroupScope> scopes) {
if (CollectionUtils.isNotEmpty(scopes)) {
if (CollectionUtils.isEmpty(scopes)) {
return;
}
List<SaasPermissionGroupScope> exists = saasPermissionGroupScopeDao.lambdaQuery()

View File

@ -18,24 +18,24 @@ import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class SaasPgroupPermissionRelationServiceImpl implements SaasPgroupPermissionRelationService {
private final SaasPgroupPermissionRelationDao saasPgroupPermissionRelationDao;
private final SaasPgroupPermissionRelationDao saasPgroupPermissionRelationDao;
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(List<SaasPgroupPermissionRelation> relations) {
if (CollectionUtils.isNotEmpty(relations)) {
return;
}
List<SaasPgroupPermissionRelation> exists = saasPgroupPermissionRelationDao.lambdaQuery()
.in(SaasPgroupPermissionRelation::getGroupId, relations.stream().map(SaasPgroupPermissionRelation::getGroupId).distinct().sorted().collect(Collectors.toList()))
.eq(SaasPgroupPermissionRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
Collection<SaasPgroupPermissionRelation> insertList = CollectionUtils.subtract(relations, exists);
Collection<SaasPgroupPermissionRelation> deleteList = CollectionUtils.subtract(exists, relations);
if (CollectionUtils.isNotEmpty(insertList)) {
saasPgroupPermissionRelationDao.saveBatch(insertList);
}
if (CollectionUtils.isNotEmpty(deleteList)) {
saasPgroupPermissionRelationDao.removeByIds(deleteList.stream().map(SaasPgroupPermissionRelation::getId).sorted().collect(Collectors.toList()));
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(List<SaasPgroupPermissionRelation> relations) {
if (CollectionUtils.isEmpty(relations)) {
return;
}
List<SaasPgroupPermissionRelation> exists = saasPgroupPermissionRelationDao.lambdaQuery()
.in(SaasPgroupPermissionRelation::getGroupId, relations.stream().map(SaasPgroupPermissionRelation::getGroupId).distinct().sorted().collect(Collectors.toList()))
.eq(SaasPgroupPermissionRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
Collection<SaasPgroupPermissionRelation> insertList = CollectionUtils.subtract(relations, exists);
Collection<SaasPgroupPermissionRelation> deleteList = CollectionUtils.subtract(exists, relations);
if (CollectionUtils.isNotEmpty(insertList)) {
saasPgroupPermissionRelationDao.saveBatch(insertList);
}
if (CollectionUtils.isNotEmpty(deleteList)) {
saasPgroupPermissionRelationDao.removeByIds(deleteList.stream().map(SaasPgroupPermissionRelation::getId).collect(Collectors.toList()));
}
}
}

View File

@ -1,12 +1,15 @@
package cn.axzo.tyr.server.service.impl;
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
import cn.axzo.framework.domain.web.BizException;
import cn.axzo.framework.domain.web.code.BaseCode;
import cn.axzo.tyr.client.model.enums.PermissionGroupType;
import cn.axzo.tyr.server.repository.entity.SaasPermissionGroup;
import cn.axzo.tyr.server.repository.entity.SaasPgroupRoleRelation;
import cn.axzo.tyr.server.repository.dao.SaasPermissionGroupDao;
import cn.axzo.tyr.server.repository.dao.SaasPgroupRoleRelationDao;
import cn.axzo.tyr.server.service.SaasPgroupRoleRelationService;
import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
@ -22,32 +25,23 @@ import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class SaasPgroupRoleRelationServiceImpl implements SaasPgroupRoleRelationService {
private final SaasPgroupRoleRelationDao saasPgroupRoleRelationDao;
private final SaasPermissionGroupDao saasPermissionGroupDao;
private final SaasPgroupRoleRelationDao saasPgroupRoleRelationDao;
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdateCommon(SaasPgroupRoleRelation commonRelation) {
List<SaasPgroupRoleRelation> relations = saasPgroupRoleRelationDao.lambdaQuery().eq(SaasPgroupRoleRelation::getRoleId, commonRelation.getRoleId())
.eq(SaasPgroupRoleRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
if (CollectionUtils.isEmpty(relations)) {
saasPgroupRoleRelationDao.save(commonRelation);
return;
}
List<SaasPgroupRoleRelation> prr = relations.stream().filter(e -> Objects.equals(commonRelation.getGroupId(), e.getGroupId())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(prr)) {
// 通用权限集已经 存在
return;
}
List<Long> permissionGroupIds = relations.stream().map(SaasPgroupRoleRelation::getGroupId).sorted().collect(Collectors.toList());
List<SaasPermissionGroup> commonGroups = saasPermissionGroupDao.lambdaQuery().in(SaasPermissionGroup::getId, permissionGroupIds)
.eq(SaasPermissionGroup::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.eq(SaasPermissionGroup::getIsCommon, PermissionGroupType.COMMON.getCode()).list();
if (CollectionUtils.isNotEmpty(commonGroups)) {
Set<Long> commonGroupIds = commonGroups.stream().map(SaasPermissionGroup::getId).collect(Collectors.toSet());
// 移除以前的通用权限集
saasPgroupRoleRelationDao.removeByIds(relations.stream().filter(e -> commonGroupIds.contains(e.getGroupId())).collect(Collectors.toList()));
}
saasPgroupRoleRelationDao.save(commonRelation);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdateCommon(SaasPgroupRoleRelation commonRelation) {
List<SaasPgroupRoleRelation> relations = saasPgroupRoleRelationDao.lambdaQuery().eq(SaasPgroupRoleRelation::getRoleId, commonRelation.getRoleId())
.eq(SaasPgroupRoleRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
if (CollectionUtils.isEmpty(relations)) {
saasPgroupRoleRelationDao.save(commonRelation);
return;
}
List<SaasPgroupRoleRelation> prr = relations.stream().filter(e -> Objects.equals(commonRelation.getGroupId(), e.getGroupId())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(prr)) {
// 通用权限集已经 存在
return;
}else {
throw new BizException(BaseCode.BAD_REQUEST,"传入的权限集id与已存在的通用权限集id不一致 req{}", JSONUtil.toJsonStr(commonRelation));
}
}
}

View File

@ -18,27 +18,28 @@ import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class SaasRoleGroupRelationServiceImpl implements SaasRoleGroupRelationService {
private final SaasRoleGroupRelationDao saasRoleGroupRelationDao;
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(List<SaasRoleGroupRelation> relations) {
if (CollectionUtils.isEmpty(relations)) {
return;
}
List<SaasRoleGroupRelation> exists = saasRoleGroupRelationDao.lambdaQuery()
.in(SaasRoleGroupRelation::getRoleId, relations.stream().map(SaasRoleGroupRelation::getRoleId).distinct().sorted().collect(Collectors.toList()))
.eq(SaasRoleGroupRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
if (CollectionUtils.isEmpty(exists)) {
saasRoleGroupRelationDao.saveBatch(relations);
return;
}
Collection<SaasRoleGroupRelation> insertList = CollectionUtils.subtract(relations, exists);
Collection<SaasRoleGroupRelation> deleteList = CollectionUtils.subtract(exists, relations);
if (CollectionUtils.isNotEmpty(insertList)) {
saasRoleGroupRelationDao.saveBatch(insertList);
}
if (CollectionUtils.isNotEmpty(deleteList)) {
saasRoleGroupRelationDao.removeByIds(deleteList.stream().map(SaasRoleGroupRelation::getId).sorted().collect(Collectors.toList()));
}
}
private final SaasRoleGroupRelationDao saasRoleGroupRelationDao;
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(List<SaasRoleGroupRelation> relations) {
if (CollectionUtils.isEmpty(relations)) {
return;
}
List<SaasRoleGroupRelation> exists = saasRoleGroupRelationDao.lambdaQuery()
.in(SaasRoleGroupRelation::getRoleId, relations.stream().map(SaasRoleGroupRelation::getRoleId).distinct().sorted().collect(Collectors.toList()))
.eq(SaasRoleGroupRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).list();
if (CollectionUtils.isEmpty(exists)) {
saasRoleGroupRelationDao.saveBatch(relations);
return;
}
Collection<SaasRoleGroupRelation> insertList = CollectionUtils.subtract(relations, exists);
Collection<SaasRoleGroupRelation> deleteList = CollectionUtils.subtract(exists, relations);
if (CollectionUtils.isNotEmpty(insertList)) {
saasRoleGroupRelationDao.saveBatch(insertList);
}
if (CollectionUtils.isNotEmpty(deleteList)) {
saasRoleGroupRelationDao.removeByIds(deleteList.stream().map(SaasRoleGroupRelation::getId).collect(Collectors.toList()));
}
}
}

View File

@ -73,7 +73,7 @@ public class SaasRoleGroupServiceImpl implements SaasRoleGroupService {
}
@Override
public void saveOrUpdate(SaasRoleGroupVO req) {
public Long saveOrUpdate(SaasRoleGroupVO req) {
// 拼接ouTypeCode字符串
String ouTypeCodeStr = null;
if (CollectionUtils.isNotEmpty(req.getOuTypeCode())) {
@ -88,6 +88,7 @@ public class SaasRoleGroupServiceImpl implements SaasRoleGroupService {
saasRoleGroup.setWorkspaceId(req.getWorkspaceId() != null ? req.getWorkspaceId():-1l);
saasRoleGroup.setOuId(req.getOuId() != null ? req.getOuId():-1l);
saasRoleGroupDao.saveOrUpdate(saasRoleGroup);
return saasRoleGroup.getId();
}
/**
@ -99,8 +100,10 @@ public class SaasRoleGroupServiceImpl implements SaasRoleGroupService {
if (CollectionUtils.isEmpty(ids)) {
return;
}
int relationCount = saasRoleGroupRelationDao.lambdaQuery().in(SaasRoleGroupRelation::getSaasRoleGroupId, ids)
.eq(SaasRoleGroupRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value).count();
int relationCount = saasRoleGroupRelationDao.lambdaQuery()
.in(SaasRoleGroupRelation::getSaasRoleGroupId, ids)
.eq(SaasRoleGroupRelation::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.count();
if (relationCount > 0) {
throw new BizException(BaseCode.BAD_REQUEST, "分组关联角色,不能删除");
}

View File

@ -0,0 +1,48 @@
package cn.axzo.tyr.server.service.impl;
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserRelationDTO;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserParam;
import cn.axzo.tyr.server.repository.dao.SaasRoleUserRelationDao;
import cn.axzo.tyr.server.repository.entity.SaasRoleUserRelation;
import cn.axzo.tyr.server.service.SaasRoleUserRelationService;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @author haiyangjin
* @date 2023/9/14
*/
@Slf4j
@Service
public class SaasRoleUserRelationServiceImpl implements SaasRoleUserRelationService {
@Resource
private SaasRoleUserRelationDao saasRoleUserRelationDao;
@Override
public List<SaasRoleUserRelationDTO> list(RoleUserParam param) {
List<SaasRoleUserRelation> saasRoleUserRelations = saasRoleUserRelationDao.lambdaQuery().eq(Objects.nonNull(param.getIdentityId()), SaasRoleUserRelation::getIdentityId, param.getIdentityId())
.eq(Objects.nonNull(param.getIdentityType()), SaasRoleUserRelation::getIdentityType, param.getIdentityType())
.eq(Objects.nonNull(param.getWorkspaceId()), SaasRoleUserRelation::getWorkspaceId, param.getWorkspaceId())
.eq(Objects.nonNull(param.getOuId()), SaasRoleUserRelation::getOuId, param.getOuId())
.in(CollectionUtil.isNotEmpty(param.getRoleIds()), SaasRoleUserRelation::getRoleId, param.getRoleIds())
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.last("LIMIT 1000")
.list();
if (CollectionUtil.isEmpty(saasRoleUserRelations)) {
return Collections.emptyList();
}
return saasRoleUserRelations.stream().map(e -> BeanUtil.copyProperties(e, SaasRoleUserRelationDTO.class)).collect(Collectors.toList());
}
}