<?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.izouma.awesomeadmin.dao.DistrictInfoMapper">
    <resultMap id="BaseResultMap" type="com.izouma.awesomeadmin.model.DistrictInfo">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="del_flag" property="delFlag" jdbcType="CHAR"/>
        <result column="full_name" property="fullName" jdbcType="VARCHAR"/>
        <result column="short_name" property="shortName" jdbcType="VARCHAR"/>
        <result column="code" property="code" jdbcType="VARCHAR"/>
        <result column="lat" property="lat" jdbcType="DECIMAL"/>
        <result column="lng" property="lng" jdbcType="DECIMAL"/>
        <result column="remark" property="remark" jdbcType="VARCHAR"/>
    </resultMap>
    <sql id="Base_Column_List">
            id,            del_flag,            full_name,            short_name,            code,
            lat,            lng,            remark, use_flag
</sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from district_info
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete from district_info
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insertSelective" parameterType="com.izouma.awesomeadmin.model.DistrictInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into district_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id!= null">
                id,
            </if>
            <if test="delFlag!= null">
                del_flag,
            </if>
            <if test="fullName!= null">
                full_name,
            </if>
            <if test="shortName!= null">
                short_name,
            </if>
            <if test="code!= null">
                code,
            </if>
            <if test="lat!= null">
                lat,
            </if>
            <if test="lng!= null">
                lng,
            </if>
            <if test="remark!= null">
                remark,
            </if>
            <if test="useFlag!= null">
                use_flag,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="delFlag != null">
                #{delFlag,jdbcType=CHAR},
            </if>
            <if test="fullName != null">
                #{fullName,jdbcType=VARCHAR},
            </if>
            <if test="shortName != null">
                #{shortName,jdbcType=VARCHAR},
            </if>
            <if test="code != null">
                #{code,jdbcType=VARCHAR},
            </if>
            <if test="lat != null">
                #{lat,jdbcType=DECIMAL},
            </if>
            <if test="lng != null">
                #{lng,jdbcType=DECIMAL},
            </if>
            <if test="remark != null">
                #{remark,jdbcType=VARCHAR},
            </if>
            <if test="useFlag != null">
                #{useFlag,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.izouma.awesomeadmin.model.DistrictInfo">
        update district_info
        <set>
            <if test="id != null">
                id= #{id,jdbcType=INTEGER},
            </if>
            <if test="delFlag != null">
                del_flag= #{delFlag,jdbcType=CHAR},
            </if>
            <if test="fullName != null">
                full_name= #{fullName,jdbcType=VARCHAR},
            </if>
            <if test="shortName != null">
                short_name= #{shortName,jdbcType=VARCHAR},
            </if>
            <if test="code != null">
                code= #{code,jdbcType=VARCHAR},
            </if>
            <if test="lat != null">
                lat= #{lat,jdbcType=DECIMAL},
            </if>
            <if test="lng != null">
                lng= #{lng,jdbcType=DECIMAL},
            </if>
            <if test="remark != null">
                remark= #{remark,jdbcType=VARCHAR},
            </if>
            <if test="useFlag != null">
                use_flag= #{useFlag,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <select id="queryDistrictInfoByPage" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.DistrictInfo">
        select
        <include refid="Base_Column_List"/>
        from district_info
        <where>
            and del_flag = 'N'
            <if test="record.id != null and !&quot;&quot;.equals(record.id)">
                and id = #{record.id}
            </if>
            <if test="record.delFlag != null and !&quot;&quot;.equals(record.delFlag)">
                and del_flag = #{record.delFlag}
            </if>
            <if test="record.fullName != null and !&quot;&quot;.equals(record.fullName)">
                and full_name = #{record.fullName}
            </if>
            <if test="record.shortName != null and !&quot;&quot;.equals(record.shortName)">
                and short_name = #{record.shortName}
            </if>
            <if test="record.code != null and !&quot;&quot;.equals(record.code)">
                and code = #{record.code}
            </if>
            <if test="record.lat != null and !&quot;&quot;.equals(record.lat)">
                and lat = #{record.lat}
            </if>
            <if test="record.lng != null and !&quot;&quot;.equals(record.lng)">
                and lng = #{record.lng}
            </if>
            <if test="record.remark != null and !&quot;&quot;.equals(record.remark)">
                and remark = #{record.remark}
            </if>
            <if test="record.useFlag != null and !&quot;&quot;.equals(record.useFlag)">
                and use_flag = #{record.useFlag}
            </if>
            <if test="record.searchKey != null and !&quot;&quot;.equals(record.searchKey)">
                <trim prefix="and (" suffix=")" prefixOverrides="OR">
                    OR full_name LIKE concat('%',#{record.searchKey},'%')
                    OR short_name LIKE concat('%',#{record.searchKey},'%')
                    OR code LIKE concat('%',#{record.searchKey},'%')
                    OR remark LIKE concat('%',#{record.searchKey},'%')
                </trim>
            </if>
        </where>
        order by code
    </select>
    <select id="queryAllDistrictInfo" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.DistrictInfo">
        select
        <include refid="Base_Column_List"/>
        from district_info
        <where>
            and del_flag = 'N'
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
                and del_flag = #{delFlag}
            </if>
            <if test="fullName != null and !&quot;&quot;.equals(fullName)">
                and full_name = #{fullName}
            </if>
            <if test="shortName != null and !&quot;&quot;.equals(shortName)">
                and short_name = #{shortName}
            </if>
            <if test="code != null and !&quot;&quot;.equals(code)">
                and code = #{code}
            </if>
            <if test="lat != null and !&quot;&quot;.equals(lat)">
                and lat = #{lat}
            </if>
            <if test="lng != null and !&quot;&quot;.equals(lng)">
                and lng = #{lng}
            </if>
            <if test="remark != null and !&quot;&quot;.equals(remark)">
                and remark = #{remark}
            </if>
            <if test="useFlag != null and !&quot;&quot;.equals(useFlag)">
                and use_flag = #{useFlag}
            </if>
            <if test="cityCode != null and !&quot;&quot;.equals(cityCode)">
                and `code` LIKE CONCAT(LEFT(#{cityCode}, 4), '%')
                AND `code` != #{cityCode}
                AND char_length(`code`)=6
            </if>
            <if test="districtCode != null and !&quot;&quot;.equals(districtCode)">
                and `code` LIKE CONCAT(#{districtCode}, '%')
                AND `code` != #{districtCode}
            </if>
        </where>
        order by code
    </select>
    <select id="queryDistrictInfo" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.DistrictInfo">
        select
        <include refid="Base_Column_List"/>
        from district_info
        <where>
            and del_flag = 'N'
            <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
            <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
                and del_flag = #{delFlag}
            </if>
            <if test="fullName != null and !&quot;&quot;.equals(fullName)">
                and full_name = #{fullName}
            </if>
            <if test="shortName != null and !&quot;&quot;.equals(shortName)">
                and short_name = #{shortName}
            </if>
            <if test="code != null and !&quot;&quot;.equals(code)">
                and code = #{code}
            </if>
            <if test="lat != null and !&quot;&quot;.equals(lat)">
                and lat = #{lat}
            </if>
            <if test="lng != null and !&quot;&quot;.equals(lng)">
                and lng = #{lng}
            </if>
            <if test="remark != null and !&quot;&quot;.equals(remark)">
                and remark = #{remark}
            </if>

        </where>
        LIMIT 1
    </select>
    <update id="delete">
        UPDATE district_info SET del_flag = 'Y'
        <where>
            AND id = #{id}
        </where>
    </update>
    <select id="query" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.DistrictInfo">
        select
        <include refid="Base_Column_List"/>
        from district_info
        <where>
            and del_flag = 'N'
        </where>
        order by id desc
    </select>
</mapper>

