Search in sources :

Example 1 with Role

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;
}
Also used : Role(com.ibeiliao.deployment.admin.vo.account.Role) RolePO(com.ibeiliao.deployment.admin.po.account.RolePO) Date(java.util.Date)

Example 2 with Role

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;
}
Also used : Role(com.ibeiliao.deployment.admin.vo.account.Role)

Example 3 with 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, "操作成功.");
}
Also used : Role(com.ibeiliao.deployment.admin.vo.account.Role) RestResult(com.ibeiliao.deployment.admin.common.RestResult) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) AdminLog(com.ibeiliao.deployment.admin.annotation.log.AdminLog) MenuResource(com.ibeiliao.deployment.admin.utils.resource.MenuResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with Role

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MenuItem(com.ibeiliao.deployment.admin.utils.resource.MenuItem) Role(com.ibeiliao.deployment.admin.vo.account.Role) RoleResRelation(com.ibeiliao.deployment.admin.vo.account.RoleResRelation) AppDefine(com.ibeiliao.deployment.admin.vo.account.AppDefine) RoleMenuRelation(com.ibeiliao.deployment.admin.vo.account.RoleMenuRelation) MenuResource(com.ibeiliao.deployment.admin.utils.resource.MenuResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with Role

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;
}
Also used : Role(com.ibeiliao.deployment.admin.vo.account.Role) AccountRoleRelation(com.ibeiliao.deployment.admin.vo.account.AccountRoleRelation) AdminAccount(com.ibeiliao.deployment.admin.vo.account.AdminAccount) List(java.util.List) PageResult(com.ibeiliao.deployment.admin.common.PageResult) MenuResource(com.ibeiliao.deployment.admin.utils.resource.MenuResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Role (com.ibeiliao.deployment.admin.vo.account.Role)6 MenuResource (com.ibeiliao.deployment.admin.utils.resource.MenuResource)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 RolePO (com.ibeiliao.deployment.admin.po.account.RolePO)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 AdminLog (com.ibeiliao.deployment.admin.annotation.log.AdminLog)1 PageResult (com.ibeiliao.deployment.admin.common.PageResult)1 RestResult (com.ibeiliao.deployment.admin.common.RestResult)1 MenuItem (com.ibeiliao.deployment.admin.utils.resource.MenuItem)1 AccountRoleRelation (com.ibeiliao.deployment.admin.vo.account.AccountRoleRelation)1 AdminAccount (com.ibeiliao.deployment.admin.vo.account.AdminAccount)1 AppDefine (com.ibeiliao.deployment.admin.vo.account.AppDefine)1 RoleMenuRelation (com.ibeiliao.deployment.admin.vo.account.RoleMenuRelation)1 RoleResRelation (com.ibeiliao.deployment.admin.vo.account.RoleResRelation)1 ServiceException (com.ibeiliao.deployment.exception.ServiceException)1