Search in sources :

Example 1 with RoleMenuDO

use of io.github.tesla.ops.system.domain.RoleMenuDO in project tesla by linking12.

the class RoleServiceImpl method save.

@CacheEvict(value = CACHE_NAME, key = ROLE_ALL_KEY)
@Transactional
@Override
public int save(RoleDO role) {
    int count = roleMapper.save(role);
    List<Long> menuIds = role.getMenuIds();
    Long roleId = role.getRoleId();
    List<RoleMenuDO> rms = new ArrayList<>();
    for (Long menuId : menuIds) {
        RoleMenuDO rmDo = new RoleMenuDO();
        rmDo.setRoleId(roleId);
        rmDo.setMenuId(menuId);
        rms.add(rmDo);
    }
    roleMenuMapper.removeByRoleId(roleId);
    if (rms.size() > 0) {
        roleMenuMapper.batchSave(rms);
    }
    return count;
}
Also used : ArrayList(java.util.ArrayList) RoleMenuDO(io.github.tesla.ops.system.domain.RoleMenuDO) CacheEvict(org.springframework.cache.annotation.CacheEvict) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RoleMenuDO

use of io.github.tesla.ops.system.domain.RoleMenuDO in project tesla by linking12.

the class RoleServiceImpl method update.

@CacheEvict(value = CACHE_NAME, key = ROLE_ALL_KEY)
@Override
public int update(RoleDO role) {
    int r = roleMapper.update(role);
    List<Long> menuIds = role.getMenuIds();
    Long roleId = role.getRoleId();
    roleMenuMapper.removeByRoleId(roleId);
    List<RoleMenuDO> rms = new ArrayList<>();
    for (Long menuId : menuIds) {
        RoleMenuDO rmDo = new RoleMenuDO();
        rmDo.setRoleId(roleId);
        rmDo.setMenuId(menuId);
        rms.add(rmDo);
    }
    if (rms.size() > 0) {
        roleMenuMapper.batchSave(rms);
    }
    return r;
}
Also used : ArrayList(java.util.ArrayList) RoleMenuDO(io.github.tesla.ops.system.domain.RoleMenuDO) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Aggregations

RoleMenuDO (io.github.tesla.ops.system.domain.RoleMenuDO)2 ArrayList (java.util.ArrayList)2 CacheEvict (org.springframework.cache.annotation.CacheEvict)2 Transactional (org.springframework.transaction.annotation.Transactional)1