use of com.ibeiliao.deployment.admin.vo.account.Role in project Corgi by kevinYin.
the class RoleServiceImpl method update.
@Override
public int update(Role role) {
validate(role);
ParameterUtil.assertGreaterThanZero(role.getRoleId(), "角色ID不能为空.");
// 验证待修改的角色名不存在
Role roleInDB = getRoleByName(role.getRoleName());
if (roleInDB != null && role.getRoleId() != roleInDB.getRoleId()) {
throw new IllegalArgumentException("角色名已存在.");
}
RolePO po = VOUtil.from(role, RolePO.class);
po.setLastModify(new Date());
po.setOperator(AdminContext.getAccountId());
int rows = roleDao.update(po);
logger.info("admin#role#update | 更新角色成功 | roleId: {}, operator: {}", role.getRoleId(), AdminContext.getAccountId());
return rows;
}
use of com.ibeiliao.deployment.admin.vo.account.Role in project Corgi by kevinYin.
the class EditRoleController method validateRole.
/**
* 校验参数是否正确
* @param myRole
* @param menuIdList
* @param appIdList
* @return
*/
private Role validateRole(Map<String, Object> myRole, List<Integer> menuIdList, List<Integer> appIdList) {
ParameterUtil.assertNotNull(menuIdList, "必须要选择菜单权限");
ParameterUtil.assertNotNull(appIdList, "不需要选择app权限");
Role role = null;
String rolename = (String) myRole.get("rolename");
String remarks = (String) myRole.get("remarks");
int roleId = NumberUtils.toInt(String.valueOf(myRole.get("roleId")), 0);
if (StringUtils.isNotBlank(rolename) && StringUtils.isNotBlank(remarks)) {
role = new Role();
role.setRemarks(remarks);
role.setRoleName(rolename);
role.setRoleId(roleId);
}
ParameterUtil.assertNotNull(role, "role数据错误,rolename、remarks不能为空");
return role;
}
use of com.ibeiliao.deployment.admin.vo.account.Role in project Corgi by kevinYin.
the class EditRoleController method updateRole.
/**
* 增加或修改角色信息
* @param role JSON格式数据, {roleId:角色ID, rolename:角色名称, remarks:备注}
* @param menuIds JSON格式数据,菜单ID列表 []
* @param resIds JSON格式数据,资源ID列表 []
* @param appIds JSON格式数据,APP ID 列表 []
* @return result.success=true表示成功
*/
@MenuResource("增加/修改角色信息")
@RequestMapping(value = "updateRole.do", method = RequestMethod.POST)
@AdminLog
@ResponseBody
public RestResult<Object> updateRole(String role, String menuIds, String resIds, String appIds) {
logger.info("admin#role#updateRole | 新增/修改角色 | role: " + role + ", menuIds: " + menuIds + ", resIds: " + resIds + ", appIds: " + appIds);
ParameterUtil.assertNotBlank(role, "role不能为空");
ParameterUtil.assertNotBlank(menuIds, "menuIds不能为空");
ParameterUtil.assertNotBlank(resIds, "resIds不能为空");
Map<String, Object> myRole = JsonUtil.parseObject(role, new TypeReference<HashMap<String, Object>>() {
});
List<Integer> menuIdList = JsonUtil.parseObject(menuIds, new TypeReference<List<Integer>>() {
});
List<Integer> appIdList = JsonUtil.parseObject(appIds, new TypeReference<List<Integer>>() {
});
List<Integer> resIdList = JsonUtil.parseObject(resIds, new TypeReference<List<Integer>>() {
});
logger.info("admin#role#updateRole | 新增/修改角色 | role: {}, menuIdList: {}, appIdList: {} ", JsonUtil.toJSONString(myRole), JsonUtil.toJSONString(menuIdList), JsonUtil.toJSONString(appIdList));
Role theRole = validateRole(myRole, menuIdList, appIdList);
roleService.authRole(theRole, ListUtils.toSet(appIdList), ListUtils.toSet(menuIdList), ListUtils.toSet(resIdList));
return new RestResult<>(ApiCode.SUCCESS, "操作成功.");
}
use of com.ibeiliao.deployment.admin.vo.account.Role in project Corgi by kevinYin.
the class EditRoleController method listAllAppMenu.
/**
* 读取所有APP的菜单,及角色的菜单权限
* @param roleId 角色ID
* @return
*/
@MenuResource("读取角色菜单")
@RequestMapping("allAppMenus")
@ResponseBody
public Map<String, Object> listAllAppMenu(int roleId) {
Map<String, Object> map = new HashMap<>(4);
List<AppDefine> apps = appService.listAll();
List<MenuItem> appMenus = new ArrayList<>(apps.size());
for (AppDefine app : apps) {
appMenus.add(menuService.getMenuTree(app.getAppId()));
}
map.put("success", Boolean.TRUE);
map.put("appList", apps);
map.put("appMenus", appMenus);
if (roleId > 0) {
List<RoleMenuRelation> menuIds = roleService.listRoleMenus(roleId);
map.put("menuIds", menuIds);
Role role = roleService.getById(roleId);
map.put("role", role);
List<RoleResRelation> resList = roleService.listRoleResources(roleId);
map.put("resIds", resList);
}
return map;
}
use of com.ibeiliao.deployment.admin.vo.account.Role in project Corgi by kevinYin.
the class ListAccountController method listAccount.
/**
* 读取管理员列表
* @param keyword 搜索的关键字
* @param page 第几页
* @param pageSize 每页多少
* @return result.object=数据列表,数据列表不为null
*/
@RequestMapping("queryAccount")
@MenuResource("读取管理员列表")
@ResponseBody
public PageResult<List<AdminAccount>> listAccount(String keyword, int page, int pageSize, HttpServletRequest request) {
List<AdminAccount> list = adminAccountService.listAccounts(keyword, page, pageSize);
int total = adminAccountService.statAccount(keyword);
for (AdminAccount account : list) {
StringBuilder buf = new StringBuilder();
List<AccountRoleRelation> tmpList = adminAccountService.listAccountRoles(account.getUid());
for (AccountRoleRelation arr : tmpList) {
Role role = roleService.getById(arr.getRoleId());
if (role != null) {
if (buf.length() > 0)
buf.append(",");
buf.append(role.getRoleName());
}
}
account.setRoleName(buf.toString());
}
PageResult<List<AdminAccount>> result = new PageResult<>(list);
result.setCurrentPage(page);
result.setPageSize(pageSize);
result.setCount(total);
return result;
}
Aggregations