Merge remote-tracking branch 'origin/feature/REQ-1102' into feature/REQ-1102
This commit is contained in:
commit
b0b2d0b0e6
7
integration-test/src/test/resources/reponse-check.js
Normal file
7
integration-test/src/test/resources/reponse-check.js
Normal 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")
|
||||
});
|
||||
8
integration-test/src/test/resources/rest-client.env.json
Normal file
8
integration-test/src/test/resources/rest-client.env.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"local": {
|
||||
"host": "http://localhost:8080"
|
||||
},
|
||||
"dev": {
|
||||
"host": "https://dev-app.axzo.cn/msg-center/webApi/message/"
|
||||
}
|
||||
}
|
||||
13
integration-test/src/test/resources/role-user.http
Normal file
13
integration-test/src/test/resources/role-user.http
Normal file
@ -0,0 +1,13 @@
|
||||
###
|
||||
POST {{host}}/api/saas-role-user/list
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
> reponse-check.js
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -47,6 +47,7 @@ public class RoleUserReq {
|
||||
*/
|
||||
@NotNull
|
||||
private IdentityType identityType;
|
||||
|
||||
/**
|
||||
* 完整的update,所有RoleId都被更新
|
||||
*/
|
||||
|
||||
@ -79,6 +79,6 @@ public class SaveOrUpdateRoleVO {
|
||||
* 项目部类型字典code
|
||||
*/
|
||||
@NotNull
|
||||
private Long workspaceTypeCode;
|
||||
private String workspaceTypeCode;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)) {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -256,6 +256,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);
|
||||
}
|
||||
@ -344,7 +346,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 +359,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,6 +376,7 @@ 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));
|
||||
|
||||
@ -225,7 +225,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 +240,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 +305,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, "角色分组信息错误");
|
||||
|
||||
@ -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.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).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user