Search in sources :

Example 1 with RolePO

use of com.ibeiliao.deployment.admin.po.account.RolePO 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 RolePO

use of com.ibeiliao.deployment.admin.po.account.RolePO in project Corgi by kevinYin.

the class AdminAccountServiceImpl method listAccountApps.

@Override
public List<Integer> listAccountApps(long uid) {
    List<Integer> result = new ArrayList<>();
    // 读取角色列表
    List<RolePO> roleList = accountRoleRelationDao.listRoleByAccount(uid);
    for (RolePO po : roleList) {
        int roleId = po.getRoleId();
        List<RoleAppRelation> list = roleService.listRoleAppRelations(roleId);
        for (RoleAppRelation vo : list) {
            result.add(vo.getAppId());
        }
    }
    return result;
}
Also used : RoleAppRelation(com.ibeiliao.deployment.admin.vo.account.RoleAppRelation) RolePO(com.ibeiliao.deployment.admin.po.account.RolePO)

Example 3 with RolePO

use of com.ibeiliao.deployment.admin.po.account.RolePO in project Corgi by kevinYin.

the class RoleServiceImpl method save.

/**
 * 保存角色数据
 *
 * @param entity
 *            角色数据
 */
private void save(Role entity) {
    validate(entity);
    Role role = getRoleByName(entity.getRoleName());
    if (role != null) {
        throw new ServiceException(ApiCode.FAILURE, "角色已存在:" + entity.getRoleName());
    } else {
        RolePO po = VOUtil.from(entity, RolePO.class);
        Date now = new Date();
        po.setOperator(AdminContext.getAccountId());
        po.setCreateTime(now);
        po.setLastModify(now);
        roleDao.save(po);
    }
    logger.info("admin#role#save | 更新角色成功 | roleName: {}, operator: {}", entity.getRoleName(), AdminContext.getAccountId());
}
Also used : Role(com.ibeiliao.deployment.admin.vo.account.Role) ServiceException(com.ibeiliao.deployment.exception.ServiceException) RolePO(com.ibeiliao.deployment.admin.po.account.RolePO) Date(java.util.Date)

Example 4 with RolePO

use of com.ibeiliao.deployment.admin.po.account.RolePO in project Corgi by kevinYin.

the class RoleServiceImpl method authRole.

@Transactional(propagation = Propagation.REQUIRED)
@Override
public void authRole(Role role, Set<Integer> appIds, Set<Integer> menuIds, Set<Integer> resIds) {
    ParameterUtil.assertNotNull(role, "角色不能为空.");
    if (appIds == null || appIds.isEmpty()) {
        throw new ServiceException(ApiCode.FAILURE, "请分配应用系统权限.");
    }
    if (menuIds == null || menuIds.isEmpty() || resIds == null || resIds.isEmpty()) {
        throw new ServiceException(ApiCode.FAILURE, "请分配菜单资源权限.");
    }
    // 保存角色
    if (role.getRoleId() > 0) {
        RolePO old = this.roleDao.getById(role.getRoleId());
        if (old == null) {
            throw new ServiceException(ApiCode.FAILURE, "角色不存在,roleId:" + role.getRoleId());
        }
        this.update(role);
    } else {
        RolePO old = this.roleDao.getByName(role.getRoleName());
        if (old != null) {
            throw new ServiceException(ApiCode.FAILURE, "角色已经存在:" + old.getRoleName());
        }
        this.save(role);
    }
    int roleId = this.roleDao.getByName(role.getRoleName()).getRoleId();
    // 更新角色应用关系
    batchAddRoleAppRelation(roleId, appIds);
    // 更新角色菜单关系
    batchUpdateRoleMenu(roleId, menuIds);
    // 更新角色资源关系
    batchUpdateRoleRes(roleId, resIds);
    logger.info("admin#role#authRole | 新增角色并授权成功 | roleId: {}, operator: {}", roleId, AdminContext.getAccountId());
}
Also used : ServiceException(com.ibeiliao.deployment.exception.ServiceException) RolePO(com.ibeiliao.deployment.admin.po.account.RolePO) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RolePO (com.ibeiliao.deployment.admin.po.account.RolePO)4 Role (com.ibeiliao.deployment.admin.vo.account.Role)2 ServiceException (com.ibeiliao.deployment.exception.ServiceException)2 Date (java.util.Date)2 RoleAppRelation (com.ibeiliao.deployment.admin.vo.account.RoleAppRelation)1 Transactional (org.springframework.transaction.annotation.Transactional)1