package com.njzscloud.supervisory.district.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njzscloud.supervisory.district.pojo.DistrictTreeResult;
import com.njzscloud.supervisory.district.pojo.SysDistrictEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 省市区表
 */
@Mapper
public interface SysDistrictMapper extends BaseMapper<SysDistrictEntity> {

    @Select("SELECT id,\n" +
            "       province,\n" +
            "       city,\n" +
            "       area,\n" +
            "       town,\n" +
            "       IF(tier = 3, 0, pid) pid,\n" +
            "       tier,\n" +
            "       district_name,\n" +
            "       sort\n" +
            "FROM sys_district\n" +
            "WHERE tier >= 3 \n" +
            "AND province = '${province}' \n" +
            "AND city = '${city}'")
    List<DistrictTreeResult> selectByTier(@Param("province") String province, @Param("city") String city);
}
