use of com.ibeiliao.deployment.exception.ServiceException in project Corgi by kevinYin.
the class AdminAccountServiceImpl method lockAccount.
@Override
public void lockAccount(long uid) {
// 判断帐号是否存在
AdminAccountPO current = adminAccountDao.getById(uid);
ParameterUtil.assertNotNull(current, "帐号不存在,请重试。");
if (current.getAccountStatus() != AdminAccount.NOMAL) {
throw new ServiceException(ApiCode.FAILURE, "帐号状态错误,只能冻结正常的用户帐号。");
}
int rows = adminAccountDao.updateStatus(uid, AdminAccount.LOCKED, current.getAccountStatus(), new Date());
if (rows > 0) {
logger.info("admin#account#lockAccount | 冻结帐号成功 | uid: {}", uid);
} else {
logger.error("admin#account#lockAccount | 冻结帐号失败 | uid: {}", uid);
throw new ServiceException(ApiCode.FAILURE, "冻结用户帐号失败,未知错误,请重试");
}
}
use of com.ibeiliao.deployment.exception.ServiceException in project Corgi by kevinYin.
the class AdminAccountServiceImpl method unlockAccount.
@Override
public void unlockAccount(long uid) {
// 判断帐号是否存在
AdminAccountPO current = adminAccountDao.getById(uid);
ParameterUtil.assertNotNull(current, "帐号不存在,请重试。");
if (current.getAccountStatus() != AdminAccount.LOCKED) {
throw new ServiceException(ApiCode.FAILURE, "帐号状态错误,只能解冻被冻结的用户帐号。");
}
int rows = adminAccountDao.updateStatus(uid, AdminAccount.NOMAL, current.getAccountStatus(), new Date());
if (rows > 0) {
logger.info("admin#account#unlockAccount | 解冻帐号成功 | uid: {}", uid);
} else {
logger.error("admin#account#unlockAccount | 解冻帐号失败 | uid: {}", uid);
throw new ServiceException(ApiCode.FAILURE, "冻结用户帐号失败,未知错误,请重试");
}
}
use of com.ibeiliao.deployment.exception.ServiceException 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.exception.ServiceException 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());
}
use of com.ibeiliao.deployment.exception.ServiceException in project Corgi by kevinYin.
the class AdminAccountServiceImpl method add.
/**
* 增加新帐号
* @param account 帐号信息
* @param roleIds 角色ID,至少要有一个角色
*/
private void add(AdminAccount account, Set<Integer> roleIds) {
validateAdminAccount(account, roleIds, true);
// 帐号校验
if (adminAccountDao.getById(account.getUid()) != null) {
logger.info("admin#account#add | 帐号已存在 | uid: {}", account.getUid());
throw new ServiceException(ApiCode.FAILURE, "帐号已存在:" + account.getUid() + "");
}
AdminAccountPO po = VOUtil.from(account, AdminAccountPO.class);
// 处理帐号
po.setCreateTime(new Date());
po.setLastModify(po.getCreateTime());
this.adminAccountDao.save(po);
long uid = account.getUid();
logger.info("admin#account#add | 删除用户角色关系 | uid: {}", uid);
accountRoleRelationDao.deleteByAccount(uid);
// 处理帐号角色关系
for (Integer roleId : roleIds) {
AccountRoleRelationPO relation = new AccountRoleRelationPO();
relation.setUid(uid);
relation.setRoleId(roleId);
logger.info("admin#account#add | 添加用户角色关系 | uid: {}, roleId: {}", uid, roleId);
accountRoleRelationDao.save(relation);
}
logger.info("admin#account#add | 添加用户成功 | uid: {}", uid);
}
Aggregations