public interface SysRoleAclService {
void changeRoleAcls(Integer roleId, List<Integer> aclIdList);
}
public class SysRoleAclServiceImpl implements SysRoleAclService {
@Resource
private SysRoleAclMapper sysRoleAclMapper;
@Override
public void changeRoleAcls(Integer roleId, List<Integer> aclIdList) {
List<Integer> originAclIdList = sysRoleAclMapper.getAclIdListByRoleIdList(Lists.newArrayList(roleId));
if (originAclIdList.size() == aclIdList.size()) {
Set<Integer> originAclIdSet = Sets.newHashSet(originAclIdList);
Set<Integer> aclIdSet = Sets.newHashSet(aclIdList);
originAclIdSet.removeAll(aclIdSet);
if (CollectionUtils.isEmpty(originAclIdSet)) {
return;
}
}
updateRoleAcls(roleId, aclIdList);
}
@Transactional
public void updateRoleAcls(int roleId, List<Integer> aclIdList) {
sysRoleAclMapper.deleteByRoleId(roleId);
if (CollectionUtils.isEmpty(aclIdList)) {
return;
}
List<SysRoleAcl> roleAclList = Lists.newArrayList();
for(Integer aclId : aclIdList) {
SysRoleAcl roleAcl = SysRoleAcl.builder().roleId(roleId).aclId(aclId).operator(RequestHolder.getCurrentUser().getUsername())
.operateIp(IPUtil.getIpAddress(RequestHolder.getCurrentRequest())).operateTime(new Date()).build();
roleAclList.add(roleAcl);
}
sysRoleAclMapper.batchInsert(roleAclList);
}
}