| | |
| | | |
| | | import com.dy.pipIrrGlobal.daoBa.BaDistrictMapper; |
| | | import com.dy.pipIrrGlobal.pojoBa.BaDistrict; |
| | | import com.dy.pipIrrGlobal.util.DistrictLevel; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | |
| | |
| | | @Service |
| | | public class DistrictSv { |
| | | |
| | | private BaDistrictMapper baDistrictMapper ; |
| | | private BaDistrictMapper dao; |
| | | |
| | | @Autowired |
| | | private void setBaDistrictMapper(BaDistrictMapper baDistrictMapper){ |
| | | this.baDistrictMapper = baDistrictMapper ; |
| | | } |
| | | |
| | | |
| | | public int save(BaDistrict po){ |
| | | return this.baDistrictMapper.insert(po) ; |
| | | private void setDao(BaDistrictMapper dao){ |
| | | this.dao = dao; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param firstLevel 第一级行下区 level |
| | | * @return 所有行政区划集合 |
| | | */ |
| | | public List<BaDistrict> getAll(byte firstLevel){ |
| | | List<BaDistrict> list = this.baDistrictMapper.selectByLevel(firstLevel) ; |
| | | public List<BaDistrict> selectAllByLevel(byte firstLevel){ |
| | | List<BaDistrict> list = this.dao.selectByLevel(firstLevel) ; |
| | | if(list != null && list.size() > 0){ |
| | | for(BaDistrict po : list){ |
| | | po.canDelete = false ; |
| | | po.canAdd = true ; |
| | | getSubDistrict(po) ; |
| | | } |
| | | } |
| | | return list ; |
| | | } |
| | | |
| | | /** |
| | | * 得到一个行政区 |
| | | * @param id 行政区ID |
| | | * @return 行政区实体 |
| | | */ |
| | | public BaDistrict selectById(Long id){ |
| | | return this.dao.selectByPrimaryKey(id) ; |
| | | } |
| | | |
| | | /** |
| | | * 保存实体 |
| | | * @param po 实体 |
| | | * @return 数量 |
| | | */ |
| | | @Transactional |
| | | public int save(BaDistrict po){ |
| | | return this.dao.putin(po) ; |
| | | } |
| | | |
| | | /** |
| | | * 保存修改实体 |
| | | * @param po 实体 |
| | | * @return 数量 |
| | | */ |
| | | @Transactional |
| | | public int update(BaDistrict po){ |
| | | return this.dao.updateByPrimaryKeySelective(po) ; |
| | | } |
| | | |
| | | /** |
| | | * 保存修改实体 |
| | | * @param id 实体ID |
| | | * @return 数量 |
| | | */ |
| | | @Transactional |
| | | public int delete(Long id){ |
| | | return this.dao.deleteLogicById(id) ; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | private void getSubDistrict(BaDistrict po){ |
| | | if(po != null && po.id != null){ |
| | | po.subDistricts = this.baDistrictMapper.selectBySupperId(po.id) ; |
| | | po.subDistricts = this.dao.selectBySupperId(po.id) ; |
| | | if(po.subDistricts != null && po.subDistricts.size() > 0){ |
| | | for(BaDistrict subPo : po.subDistricts){ |
| | | getSubDistrict(subPo) ; |
| | | } |
| | | }else{ |
| | | //没有下级了,可以删除 |
| | | po.canDelete = false ; |
| | | if(po.level.code.byteValue() == DistrictLevel.Village.code.byteValue()){ |
| | | //到村级了,不可以再添加行政区了 |
| | | po.canAdd = false ; |
| | | } |
| | | } |
| | | } |
| | | } |