角色改获取单个页面的,保存接口返回Id
This commit is contained in:
parent
43ee7c4bea
commit
6a10e43dd6
@ -36,7 +36,7 @@ public interface FeatureResourceApi {
|
||||
ApiResult<Void> syncFromBase(@RequestBody @Valid ResourceSyncReq req);
|
||||
|
||||
@PostMapping("/api/featureResource/saveOrUpdate")
|
||||
ApiResult<Void> saveMenu(@RequestBody FeatureResourceTreeSaveReq req);
|
||||
ApiResult<Long> saveMenu(@RequestBody FeatureResourceTreeSaveReq req);
|
||||
|
||||
/** 查询功能资源树 **/
|
||||
@PostMapping("/api/featureResource/getTree")
|
||||
|
||||
@ -57,7 +57,7 @@ public interface TyrSaasRoleApi {
|
||||
|
||||
/** 角色和组件页面的关联关系 **/
|
||||
@PostMapping("/api/saasRoleGroup/relation/query")
|
||||
ApiResult<List<FeatureRoleRelationResp>> queryFeatureRoleRelation(@RequestParam Long featureId);
|
||||
ApiResult<FeatureRoleRelationResp> queryFeatureRoleRelation(@RequestParam Long featureId);
|
||||
|
||||
/**
|
||||
* 根据id查询详情
|
||||
|
||||
@ -49,10 +49,11 @@ public class FeatureResourceController implements FeatureResourceApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult<Void> saveMenu(FeatureResourceTreeSaveReq req) {
|
||||
public ApiResult<Long> saveMenu(FeatureResourceTreeSaveReq req) {
|
||||
log.info("save feature resource req : " + req.toString());
|
||||
featureResourceService.saveOrUpdateMenu(req);
|
||||
return ApiResult.ok();
|
||||
Long featureId = featureResourceService.saveOrUpdateMenu(req);
|
||||
log.info("save feature resource resp : " + featureId.toString());
|
||||
return ApiResult.ok(featureId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -112,7 +112,7 @@ public class SaasRoleController implements TyrSaasRoleApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult<List<FeatureRoleRelationResp>> queryFeatureRoleRelation(Long featureId) {
|
||||
public ApiResult<FeatureRoleRelationResp> queryFeatureRoleRelation(Long featureId) {
|
||||
return ApiResult.ok(roleService.queryFeatureRoleRelation(featureId));
|
||||
}
|
||||
|
||||
|
||||
@ -124,7 +124,7 @@ public interface RoleService extends IService<SaasRole> {
|
||||
|
||||
void saveOrUpdateFeatureRoleRelation(List<FeatureRoleRelationReq> req, Long operatorId);
|
||||
|
||||
List<FeatureRoleRelationResp> queryFeatureRoleRelation(Long featureId);
|
||||
FeatureRoleRelationResp queryFeatureRoleRelation(Long featureId);
|
||||
|
||||
@SuperBuilder
|
||||
@Data
|
||||
|
||||
@ -19,13 +19,15 @@ import java.util.List;
|
||||
*/
|
||||
public interface SaasFeatureResourceService {
|
||||
|
||||
void saveOrUpdateMenu(FeatureResourceTreeSaveReq req);
|
||||
Long saveOrUpdateMenu(FeatureResourceTreeSaveReq req);
|
||||
|
||||
void updateFeatureAuthType(Long featureId, Integer authType);
|
||||
|
||||
/**递归的**/
|
||||
List<SaasFeatureResource> listDescendant(Long featureId);
|
||||
|
||||
SaasFeatureResource featureResourceById(Long featureId);
|
||||
|
||||
FeatureResourceTreeNode getTreeFeatureDescendant(Long featureId);
|
||||
|
||||
/**删除指定菜单**/
|
||||
|
||||
@ -68,6 +68,7 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@ -92,6 +93,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
@ -1277,6 +1279,7 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
|
||||
return saasRoleGroupRes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveOrUpdateFeatureRoleRelation(List<FeatureRoleRelationReq> req, Long operatorId) {
|
||||
for (FeatureRoleRelationReq item : req) {
|
||||
@ -1314,30 +1317,22 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeatureRoleRelationResp> queryFeatureRoleRelation(Long featureId) {
|
||||
List<SaasFeatureResource> list = saasFeatureResourceService.listDescendant(featureId);
|
||||
List<Long> featureIds = list.stream().map(SaasFeatureResource::getId).collect(Collectors.toList());
|
||||
|
||||
List<SaasPgroupPermissionRelation> pgroupPermissionRelations = saasPgroupPermissionRelationDao.queryByFeatureIds(featureIds);
|
||||
Map<Long, List<SaasPgroupPermissionRelation>> permissionMap = pgroupPermissionRelations.stream().collect(Collectors.groupingBy(SaasPgroupPermissionRelation::getFeatureId));
|
||||
List<Long> groupIds = pgroupPermissionRelations.stream().map(SaasPgroupPermissionRelation::getGroupId).collect(Collectors.toList());
|
||||
List<SaasPgroupRoleRelation> relations = saasPgroupRoleRelationDao.listByGroupIds(groupIds);
|
||||
|
||||
List<FeatureRoleRelationResp> resps = new ArrayList<>();
|
||||
list.forEach(item -> {
|
||||
FeatureRoleRelationResp resp = new FeatureRoleRelationResp();
|
||||
resp.setFeatureId(item.getId());
|
||||
resp.setAuthType(item.getAuthType());
|
||||
List<SaasPgroupPermissionRelation> groups = permissionMap.get(item.getId());
|
||||
if (CollectionUtil.isNotEmpty(groups)) {
|
||||
List<Long> itemGroupIds = groups.stream().map(SaasPgroupPermissionRelation::getGroupId).collect(Collectors.toList());
|
||||
List<SaasPgroupRoleRelation> itemRoles = relations.stream().filter(role -> itemGroupIds.contains(role.getGroupId())).collect(Collectors.toList());
|
||||
List<Long> roleIds = itemRoles.stream().map(SaasPgroupRoleRelation::getRoleId).collect(Collectors.toList());
|
||||
public FeatureRoleRelationResp queryFeatureRoleRelation(Long featureId) {
|
||||
SaasFeatureResource featureResource = saasFeatureResourceService.featureResourceById(featureId);
|
||||
Assert.notNull(featureResource, "菜单不存在");
|
||||
FeatureRoleRelationResp resp = new FeatureRoleRelationResp();
|
||||
resp.setFeatureId(featureId);
|
||||
resp.setAuthType(featureResource.getAuthType());
|
||||
List<SaasPgroupPermissionRelation> pgroupPermissionRelations = saasPgroupPermissionRelationDao.queryByFeatureIds(Collections.singletonList(featureId));
|
||||
if (CollectionUtil.isNotEmpty(pgroupPermissionRelations)) {
|
||||
List<Long> groupIds = pgroupPermissionRelations.stream().map(SaasPgroupPermissionRelation::getGroupId).collect(Collectors.toList());
|
||||
List<SaasPgroupRoleRelation> relations = saasPgroupRoleRelationDao.listByGroupIds(groupIds);
|
||||
if (CollectionUtil.isNotEmpty(relations)) {
|
||||
List<Long> roleIds = relations.stream().map(SaasPgroupRoleRelation::getRoleId).collect(Collectors.toList());
|
||||
resp.setRoleIds(roleIds);
|
||||
}
|
||||
resps.add(resp);
|
||||
});
|
||||
return resps;
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
|
||||
private void validPermission(Set<Long> permissionIds) {
|
||||
|
||||
@ -192,7 +192,7 @@ public class SaasFeatureResourceServiceImpl implements SaasFeatureResourceServic
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@CacheEvict(value = SaasFeatureResourceCacheService.CACHE_FEATURE_RESOURCE_TREE,allEntries = true)
|
||||
public void saveOrUpdateMenu(FeatureResourceTreeSaveReq req) {
|
||||
public Long saveOrUpdateMenu(FeatureResourceTreeSaveReq req) {
|
||||
SaasFeatureResource baseResource = BeanMapper.copyBean(req, SaasFeatureResource.class);
|
||||
baseResource.setUpdateBy(req.getOperatorId());
|
||||
// 新增时候
|
||||
@ -223,6 +223,7 @@ public class SaasFeatureResourceServiceImpl implements SaasFeatureResourceServic
|
||||
} else {
|
||||
deleteComponentRecursionById(baseResource.getId(), null, req.getOperatorId());
|
||||
}
|
||||
return baseResource.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -306,6 +307,17 @@ public class SaasFeatureResourceServiceImpl implements SaasFeatureResourceServic
|
||||
.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SaasFeatureResource featureResourceById(Long featureId) {
|
||||
if (featureId == null) {
|
||||
return null;
|
||||
}
|
||||
return featureResourceDao.lambdaQuery()
|
||||
.eq(BaseEntity::getIsDelete,0)
|
||||
.eq(SaasFeatureResource::getId, featureId)
|
||||
.one();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@CacheEvict(value = SaasFeatureResourceCacheService.CACHE_FEATURE_RESOURCE_TREE,allEntries = true)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user