| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class DistrictSv { |
| | |
| | | public int save(BaDistrict po){ |
| | | return this.baDistrictMapper.insert(po) ; |
| | | } |
| | | |
| | | /** |
| | | * 从第一级行政区划开始,得到所有行政区划信息 |
| | | * @param firstLevel 第一级行下区 level |
| | | * @return 所有行政区划集合 |
| | | */ |
| | | public List<BaDistrict> getAll(byte firstLevel){ |
| | | List<BaDistrict> list = this.baDistrictMapper.selectByLevel(firstLevel) ; |
| | | if(list != null && list.size() > 0){ |
| | | for(BaDistrict po : list){ |
| | | getSubDistrict(po) ; |
| | | } |
| | | } |
| | | return list ; |
| | | } |
| | | |
| | | /** |
| | | * 得到下级行政区划 |
| | | * @param po 上级行政区划 |
| | | */ |
| | | private void getSubDistrict(BaDistrict po){ |
| | | if(po != null && po.id != null){ |
| | | po.subDistricts = this.baDistrictMapper.selectBySupperId(po.id) ; |
| | | if(po.subDistricts != null && po.subDistricts.size() > 0){ |
| | | for(BaDistrict subPo : po.subDistricts){ |
| | | getSubDistrict(subPo) ; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |