public class AddressServiceImpl implements AddressService {
//定義全局變量idList,查出該部門下的子部門后,放進去
private List<Long> idList=new ArrayList();
@Autowired
private AddressMapper addressMapper;
@Override
public List<Address> selectInParent(Long id) {
List<Long> ids=getIds(id);
ids.add(id);
List<Address> addressList=addressMapper.selectInParent(ids,Constants.ABLE_CONFIG.DEFAULT_ABLE);
//***用完后清空該集合,不然再次查詢時,之前的查詢的部門也在里面
idList.clear();
return addressList;
}
//遞歸方法,私有的
private List<Long> getIds(Long id){
List<Address> list=addressMapper.selectByParent(id,Constants.ABLE_CONFIG.DEFAULT_ABLE);
for (int i=0;i<list.size();i++){
idList.add(list.get(i).getId());
getIds(list.get(i).getId());
}
return idList;
}
}