public int delete(Long id) {
//删除权限的集合ids
List<Long> ids = new ArrayList<>();
ids.add(id);
//递归的将一级分类下的id也加入到集合中
this.getIds(ids,id);
SmsPermissionExample example = new SmsPermissionExample();
example.createCriteria().andIdIn(ids);
return smsPermissionMapper.deleteByExample(example);
}
//递归获取所有的节点
private void getIds(List<Long> ids, Long id) {
SmsPermissionExample example = new SmsPermissionExample();
example.createCriteria().andPidEqualTo(id);
List<SmsPermission> smsPermissions = smsPermissionMapper.selectByExample(example);
//遍历二级分类的对象,把二级分类的id加入到要删除的集合中
if(smsPermissions.size()>0){
for (SmsPermission permission : smsPermissions) {
Long permissionId = permission.getId();
ids.add(permissionId);
//把二级分类的每一个ID,查询它下面的子节点
this.getIds(ids,permissionId);
}
}
}