<?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.yunzhi.marketing.mapper.TdCityMapper">
    <select id="selectCity" resultType="com.yunzhi.marketing.entity.TdCity">
        SELECT
	*,
	LEFT(pinyin,1) AS initial
FROM
	td_city
	<where>
	    1=1
	    <if test="null != status and status != '' ">
         and   status = #{status}
        </if>
        <if test="leveltype != null and leveltype != ''">
        and   leveltype = #{leveltype}
        </if>
    </where>
ORDER BY
	pinyin
    </select>


    <select id="selectWxCity" resultType="com.yunzhi.marketing.entity.TdCity">

        SELECT
                    c.id,
                    c.name,
                    c.parentid,
                    c.shortname,
                    c.leveltype,
                    c.citycode,
                    c.zipcode,
                    c.lng,
                    c.lat,
                    c.pinyin,
                    oc.org_id,
                    oc.`status`,
                    LEFT (c.pinyin, 1) AS initial
                FROM
                ta_org_city oc
                INNER JOIN td_city c ON oc.city_id = c.id
                WHERE
                oc.org_id = #{orgId}
                and  oc.parentid  !=100000
                and  oc.status = 1
                ORDER BY
                c.pinyin
    </select>
    <select id="getOrgDefaultCity" resultType="com.yunzhi.marketing.entity.TdCity">
        SELECT
            t.*
        FROM
            td_city t
            JOIN ta_org s ON t.id = s.default_city_id
        WHERE
            s.org_id = #{orgId}
    </select>
    <select id="getCascadeCity" resultType="com.yunzhi.marketing.entity.TdCity">
        SELECT
            *
        FROM
            td_city t
        WHERE
            t.parentid = #{parentCity}
          AND t.leveltype = #{levelType}
        ORDER BY
            t.id
    </select>

</mapper>
