<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yx.face.dao.AreaCodeDao">

    <select id="getAddress" resultType="com.yx.face.model.vo.AreaCodeVO">
        SELECT name,
               code,
               address
        FROM area_code
        WHERE super_code = #{code}
    </select>

    <select id="getCodeId" resultType="java.lang.Integer">
        SELECT id
        FROM area_code
        WHERE code = #{code}
        LIMIT 0,1
    </select>

    <select id="getAddressName" resultType="java.lang.String">
        SELECT name
        FROM area_code
        WHERE code = #{code}
        LIMIT 0,1
    </select>
    <select id="getAddressCode" resultType="java.lang.Integer">
        SELECT code
        FROM area_code
        WHERE super_code = #{code}
    </select>

    <select id="getSubAddressCode" resultType="java.lang.Integer">
        SELECT code
        FROM area_code
        WHERE super_code = #{code}
        ORDER BY id
        LIMIT 0,1
    </select>

    <select id="getSupAddressCode" resultType="java.lang.Integer">
        SELECT super_code
        FROM area_code
        WHERE code = #{code}
    </select>
    <select id="getAddressAll" resultType="java.lang.String">
        SELECT address
        FROM area_code
        WHERE code = #{code}
        LIMIT 0,1

    </select>

    <select id="getProvince" resultType="com.yx.face.model.vo.AreaCodeVOList">
        select
            id as areaCodeId,
            name as name
        from area_code
        where type =0
        order by `name`='贵州省' desc,id
    </select>
    <select id="getAreaList" resultType="com.yx.face.model.vo.AreaCodeVOList">
        select
            id as areaCodeId,
            name as name
        from area_code
        where super_code =
              (
                  select code from area_code where id = #{areaCodeId}
              )
        order by id
    </select>


    <select id="getByCode" resultType="com.yx.face.model.vo.AreaCodeVO">
        select
            *
        from area_code
        where code=#{code}
    </select>
    <select id="getAreaCode" resultType="com.yx.face.model.entity.AreaCode">
        select
        *
        from area_code
        <where>
            <if test="name !=null ">
               and name = #{name}
            </if>
            <if test="type !=null ">
               and type = #{type}
            </if>
            <if test="superCode !=null ">
               and super_code = #{superCode}
            </if>
        </where>
    </select>
</mapper>

