StreetMapper.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package com.zxyj.mapper;
  2. import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  3. import com.zxyj.entity.Street;
  4. import org.apache.ibatis.annotations.Mapper;
  5. import org.apache.ibatis.annotations.Param;
  6. import org.apache.ibatis.annotations.Select;
  7. import java.util.List;
  8. @Mapper
  9. public interface StreetMapper extends BaseMapper<Street> {
  10. /**
  11. * 根据层级查询地址列表
  12. */
  13. @Select("SELECT * FROM streets WHERE level = #{level} ORDER BY sort_order, id")
  14. List<Street> findByLevel(@Param("level") Integer level);
  15. /**
  16. * 根据父级ID查询子级地址
  17. */
  18. @Select("SELECT * FROM streets WHERE parent_id = #{parentId} ORDER BY sort_order, id")
  19. List<Street> findByParentId(@Param("parentId") Long parentId);
  20. /**
  21. * 根据编码查询
  22. */
  23. @Select("SELECT * FROM streets WHERE street_code = #{code}")
  24. Street findByCode(@Param("code") String code);
  25. /**
  26. * 查询所有省份
  27. */
  28. @Select("SELECT * FROM streets WHERE level = 1 ORDER BY sort_order, id")
  29. List<Street> findAllProvinces();
  30. /**
  31. * 查询指定省份下的城市
  32. */
  33. @Select("SELECT * FROM streets WHERE level = 2 AND parent_id = #{provinceId} ORDER BY sort_order, id")
  34. List<Street> findCitiesByProvince(@Param("provinceId") Long provinceId);
  35. /**
  36. * 查询指定城市下的区县
  37. */
  38. @Select("SELECT * FROM streets WHERE level = 3 AND parent_id = #{cityId} ORDER BY sort_order, id")
  39. List<Street> findDistrictsByCity(@Param("cityId") Long cityId);
  40. /**
  41. * 查询指定区县下的街道
  42. */
  43. @Select("SELECT * FROM streets WHERE level = 4 AND parent_id = #{districtId} ORDER BY sort_order, id")
  44. List<Street> findStreetsByDistrict(@Param("districtId") Long districtId);
  45. /**
  46. * 搜索地址(模糊匹配)
  47. */
  48. @Select("SELECT * FROM streets WHERE full_name LIKE CONCAT('%', #{keyword}, '%') ORDER BY level, sort_order LIMIT 20")
  49. List<Street> search(@Param("keyword") String keyword);
  50. }