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;
}
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;
}
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());
}
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());
}
Aggregations