package com.oneplatform.permission.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.mendmix.common.CurrentRuntimeContext;
import com.mendmix.common.MendmixBaseException;
import com.mendmix.common.annotation.ApiMetadata;
import com.mendmix.common.constants.PermissionLevel;
import com.mendmix.common.model.IdParam;
import com.mendmix.common.model.NameValuePair;
import com.mendmix.common.model.Page;
import com.mendmix.common.model.PageParams;
import com.mendmix.common.model.PageQueryRequest;
import com.mendmix.common.model.SelectOption;
import com.mendmix.common.model.TreeModel;
import com.mendmix.common.util.BeanUtils;
import com.oneplatform.permission.constants.FunctionResourceType;
import com.oneplatform.permission.constants.GrantRelationType;
import com.oneplatform.permission.constants.SubRelationType;
import com.oneplatform.permission.dao.entity.FunctionResourceEntity;
import com.oneplatform.permission.dao.entity.UserRoleEntity;
import com.oneplatform.permission.dao.mapper.FunctionResourceEntityMapper;
import com.oneplatform.permission.dto.ObjectRelation;
import com.oneplatform.permission.dto.ResourceTreeModel;
import com.oneplatform.permission.dto.UserRole;
import com.oneplatform.permission.dto.param.FunctionResourceQueryParam;
import com.oneplatform.permission.dto.param.GrantPermItem;
import com.oneplatform.permission.dto.param.GrantRelationParam;
import com.oneplatform.permission.dto.param.GrantUserRolePermParam;
import com.oneplatform.permission.dto.param.RoleSetUserParam;
import com.oneplatform.permission.dto.param.UserRoleParam;
import com.oneplatform.permission.dto.param.UserRoleQueryParam;
import com.oneplatform.permission.service.FunctionResourceService;
import com.oneplatform.permission.service.InternalRelationService;
import com.oneplatform.permission.service.UserPermissionService;
import com.oneplatform.permission.service.UserRoleService;
@RestController
@RequestMapping("/role")
public class UserRoleController {
@Autowired
private UserRoleService userRoleService;
@Autowired
private UserPermissionService userPermissionService;
@Autowired
private FunctionResourceService functionResourceService;
@Autowired
private InternalRelationService internalRelationService;
@Autowired
private FunctionResourceEntityMapper functionResourceMapper;
@ApiMetadata(permissionLevel = PermissionLevel.PermissionRequired, actionLog = true)
@PostMapping("add")
public IdParam<Integer> add(@RequestBody UserRoleParam param) {
String tenantId = CurrentRuntimeContext.getTenantId(false);
return userRoleService.addUserRole(tenantId,param);
}
@ApiMetadata(permissionLevel = PermissionLevel.PermissionRequired, actionLog = true)
@PostMapping("delete")
public void delete(@RequestBody IdParam<Integer> param) {
userRoleService.deleteUserRole(param.getId());
}
@ApiMetadata(permissionLevel = PermissionLevel.PermissionRequired, actionLog = true)
@PostMapping("update")
public void update(@RequestBody UserRoleParam param) {
userRoleService.updateUserRole(param);
}
@ApiMetadata(permissionLevel = PermissionLevel.PermissionRequired, actionLog = true)
@PostMapping("toggle")
public void toggleUserGroup(@RequestBody IdParam<Integer> param) {
userRoleService.toggleUserRole(param.getId());
}
@ApiMetadata(permissionLevel = PermissionLevel.PermissionRequired, actionLog = true)
@GetMapping("{id}")
public UserRole get(@PathVariable("id") Integer id) {
return userRoleService.getUserRole(id);
}
@ApiMetadata(permissionLevel = PermissionLevel.PermissionRequired, actionLog = true)
@PostMapping("list")
public Page<UserRole> pageQry(@RequestBody PageQueryRequest<UserRoleQueryParam> queryParam) {
if(queryParam.getExample() == null)queryParam.setExample(new UserRoleQueryParam());
PageParams pageParams = new PageParams(queryParam.getPageNo(), queryParam.getPageSize());
return userRoleService.pageQryUserRole(pageParams,queryParam.getExample());
}
@ApiMetadata(permissionLevel = PermissionLevel.PermissionRequired, actionLog = true)
@GetMapping("options")
public List<SelectOption> options(@RequestParam(name="type") String type) {
UserRoleQueryParam param = new UserRoleQueryParam();
param.setRoleType(type);
param.setEnabled(true);
return userRoleService.listByQueryParam(param).stream().map( o -> {
return new SelectOption(o.getId().toString(), o.getName());
}).collect(Collectors.toList());
}
@ApiMetadata(permissionLevel = PermissionLevel.PermissionRequired)
@PostMapping(value = "/updateUsers")
@ResponseBody
public void updateRoleUsers(@RequestBody @Validated RoleSetUserParam param) {
UserRoleEntity roleEntity = userRoleService.getUserRoleEntity(param.getRoleId());
if(roleEntity == null || !roleEntity.getEnabled()) {
throw new MendmixBaseException("角色不存在或已禁用");
}
String roleId = param.getRoleId().toString();
List<String> userIds = param.getUserIds();
internalRelationService.updateParentSubRelations(SubRelationType.userToRole, roleId, userIds);
}
@ApiMetadata(permissionLevel = PermissionLevel.PermissionRequired)
@PostMapping(value = "/removeUsers")
@ResponseBody
public void removeRoleUsers(@RequestBody @Validated RoleSetUserParam param) {
String roleId = param.getRoleId().toString();
List<String> userIds = param.getUserIds();
for (String userId : userIds) {
internalRelationService.deleteUserRoleRelations(roleId, userId);
}
}
@ApiMetadata(permissionLevel = PermissionLevel.PermissionRequired)
@PostMapping(value = "/grant")
@ResponseBody
public void grantPermissions(@RequestBody GrantUserRolePermParam param) {
Map<String, List<String>> typeGroupMap = new HashMap<>(3);
List<String> tmpList;
for (GrantPermItem item : param.getPermItems()) {
tmpList = typeGroupMap.get(item.getType());
if (tmpList == null) {
tmpList = new ArrayList<>();
typeGroupMap.put(item.getType(), tmpList);
}
if(!tmpList.contains(item.getId().toString())) {
tmpList.add(item.getId().toString());
}
}
//查询按钮归属的菜单
if(typeGroupMap.containsKey(FunctionResourceType.button.name())){
List<Integer> buttonIds = typeGroupMap.get(FunctionResourceType.button.name()).stream().map(o -> {
return Integer.parseInt(o);
}).collect(Collectors.toList());
List<FunctionResourceEntity> buttons = functionResourceMapper.selectByPrimaryKeys(buttonIds);
for (FunctionResourceEntity button : buttons) {
tmpList = typeGroupMap.get(FunctionResourceType.button.name());
if (tmpList == null) {
tmpList = new ArrayList<>();
typeGroupMap.put(FunctionResourceType.menu.name(), tmpList);
}
if(!tmpList.contains(button.getParentId().toString())){
tmpList.add(button.getParentId().toString());
}
}
}
final List<GrantRelationParam> paramList = new ArrayList<>();
typeGroupMap.forEach((k, v) -> {
GrantRelationParam relationParam = new GrantRelationParam();
relationParam.setRelationType(GrantRelationType.funcToRole);
relationParam.setTargetId(param.getRoleId().toString());
relationParam.setSourceIdList(v);
paramList.add(relationParam);
});
userRoleService.updateGrantedPermissions(paramList);
}
@ApiMetadata(permissionLevel = PermissionLevel.PermissionRequired, actionL
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 532 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
m0_72731342
- 粉丝: 2
- 资源: 1832
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)