mod addrole

This commit is contained in:
2021-04-28 10:00:29 +08:00
parent 4bb70de669
commit b796dd97bc
2 changed files with 24 additions and 18 deletions

View File

@@ -56,7 +56,7 @@ public class MenuController {
@PostMapping("addRole")
@ApiOperation(value = "角色授权", notes = "roleId,menuIds,中间用逗号连接")
public ResultVO<Object> addRoleMenu(@RequestParam Long roleId,@RequestParam List<String> menuIds) {
public ResultVO<Object> addRoleMenu(@RequestParam Long roleId,@RequestParam(required=false) List<String> menuIds) {
redisUtil.del("auth");
return menuService.addRoleMenu(roleId, menuIds);
}

View File

@@ -108,25 +108,31 @@ public class MenuServiceImpl2 implements MenuService {
@Override
@Transactional
public ResultVO<Object> addRoleMenu(Long roleId, List<String> menuIds) {
if (null == roleId) {
return ResultVO.getFailed("授权角色不能为空");
}
baseMapper.deleteByCondition(OS_REL_ROLE_OS.getTableName(), Condition.creatCriteria().andEqual("ROLE_ID", roleId).build());
baseMapper.deleteByCondition(OS_REL_ROLE_MENU.getTableName(), Condition.creatCriteria().andEqual("ROLE_ID", roleId).build());
menuIds.forEach(menuId -> {
if (menuId.startsWith("OS")) {
Map<String, Object> data = new HashMap<>();
data.put("ROLE_ID", roleId);
data.put("OS_ID", Long.valueOf(menuId.substring(2)));
data.put("VERSION", 1);
data.put("DELETED", 1);
tableService.saveWithDate(OS_REL_ROLE_OS, data);
} else {
Map<String, Object> data = new HashMap<>();
data.put("ROLE_ID", roleId);
data.put("MENU_ID", menuId);
data.put("VERSION", 1);
data.put("DELETED", 1);
tableService.saveWithDate(OS_REL_ROLE_MENU, data);
}
});
if (menuIds != null) {
menuIds.forEach(menuId -> {
if (menuId.startsWith("OS")) {
Map<String, Object> data = new HashMap<>();
data.put("ROLE_ID", roleId);
data.put("OS_ID", Long.valueOf(menuId.substring(2)));
data.put("VERSION", 1);
data.put("DELETED", 1);
tableService.saveWithDate(OS_REL_ROLE_OS, data);
} else {
Map<String, Object> data = new HashMap<>();
data.put("ROLE_ID", roleId);
data.put("MENU_ID", menuId);
data.put("VERSION", 1);
data.put("DELETED", 1);
tableService.saveWithDate(OS_REL_ROLE_MENU, data);
}
});
}
return ResultVO.getSuccess();
}