Search in sources :

Example 1 with AccountRoleRelationPO

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

the class AdminAccountServiceImpl method update.

/**
 * 更新帐号信息,但不会更新帐号的状态(冻结、正常)
 * @param account 帐号信息
 * @param roleIds 角色ID,至少要有一个角色
 */
private void update(AdminAccount account, Set<Integer> roleIds) {
    validateAdminAccount(account, roleIds, false);
    // 帐号校验
    AdminAccountPO po = adminAccountDao.getById(account.getUid());
    ParameterUtil.assertNotNull(po, "帐号不存在.");
    // 处理帐号
    po = VOUtil.from(account, AdminAccountPO.class);
    po.setLastModify(new Date());
    logger.info("admin#account#update | 更新帐号 | uid: {}", po.getUid());
    int rows = adminAccountDao.update(po);
    ParameterUtil.assertGreaterThanZero(rows, "更新帐号失败.");
    logger.info("admin#account#update | 删除帐号角色关系 | uid: {}", po.getUid());
    accountRoleRelationDao.deleteByAccount(po.getUid());
    // 处理帐号角色关系
    for (Integer roleId : roleIds) {
        AccountRoleRelationPO relation = new AccountRoleRelationPO();
        relation.setUid(po.getUid());
        relation.setRoleId(roleId);
        logger.info("admin#account#update | 添加用户角色关系 | uid: {}, roleId: {}", relation.getUid(), roleId);
        accountRoleRelationDao.save(relation);
    }
}
Also used : AdminAccountPO(com.ibeiliao.deployment.admin.po.account.AdminAccountPO) AccountRoleRelationPO(com.ibeiliao.deployment.admin.po.account.AccountRoleRelationPO)

Example 2 with AccountRoleRelationPO

use of com.ibeiliao.deployment.admin.po.account.AccountRoleRelationPO 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);
}
Also used : ServiceException(com.ibeiliao.deployment.exception.ServiceException) AdminAccountPO(com.ibeiliao.deployment.admin.po.account.AdminAccountPO) AccountRoleRelationPO(com.ibeiliao.deployment.admin.po.account.AccountRoleRelationPO)

Aggregations

AccountRoleRelationPO (com.ibeiliao.deployment.admin.po.account.AccountRoleRelationPO)2 AdminAccountPO (com.ibeiliao.deployment.admin.po.account.AdminAccountPO)2 ServiceException (com.ibeiliao.deployment.exception.ServiceException)1