<?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=".dao.GridMgmtAdminDivisionDao">

    <resultMap type=".entity.GridMgmtAdminDivision" id="GridMgmtAdminDivisionMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="province" column="province" jdbcType="VARCHAR"/>
        <result property="city" column="city" jdbcType="VARCHAR"/>
        <result property="county" column="county" jdbcType="VARCHAR"/>
        <result property="town" column="town" jdbcType="VARCHAR"/>
        <result property="village" column="village" jdbcType="VARCHAR"/>
        <result property="code" column="code" jdbcType="VARCHAR"/>
        <result property="level" column="level" jdbcType="INTEGER"/>
        <result property="grid" column="grid" jdbcType="VARCHAR"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="GridMgmtAdminDivisionMap">
        select idprovincecitycountytownvillagecodelevelgrid
        from grid_mgmt_admin_division
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="GridMgmtAdminDivisionMap">
        select
        idprovincecitycountytownvillagecodelevelgrid
        from grid_mgmt_admin_division
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="province != null and province != ''">
                and province = #{province}
            </if>
            <if test="city != null and city != ''">
                and city = #{city}
            </if>
            <if test="county != null and county != ''">
                and county = #{county}
            </if>
            <if test="town != null and town != ''">
                and town = #{town}
            </if>
            <if test="village != null and village != ''">
                and village = #{village}
            </if>
            <if test="code != null and code != ''">
                and code = #{code}
            </if>
            <if test="level != null">
                and level = #{level}
            </if>
            <if test="grid != null and grid != ''">
                and grid = #{grid}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from grid_mgmt_admin_division
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="province != null and province != ''">
                and province = #{province}
            </if>
            <if test="city != null and city != ''">
                and city = #{city}
            </if>
            <if test="county != null and county != ''">
                and county = #{county}
            </if>
            <if test="town != null and town != ''">
                and town = #{town}
            </if>
            <if test="village != null and village != ''">
                and village = #{village}
            </if>
            <if test="code != null and code != ''">
                and code = #{code}
            </if>
            <if test="level != null">
                and level = #{level}
            </if>
            <if test="grid != null and grid != ''">
                and grid = #{grid}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into grid_mgmt_admin_division(provincecitycountytownvillagecodelevelgrid)
        values (#{province}#{city}#{county}#{town}#{village}#{code}#{level}#{grid})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into grid_mgmt_admin_division(provincecitycountytownvillagecodelevelgrid)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.province}#{entity.city}#{entity.county}#{entity.town}#{entity.village}#{entity.code}#{entity.level}#{entity.grid})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into grid_mgmt_admin_division(provincecitycountytownvillagecodelevelgrid)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.province}#{entity.city}#{entity.county}#{entity.town}#{entity.village}#{entity.code}#{entity.level}#{entity.grid})
        </foreach>
        on duplicate key update
        province = values(province)city = values(city)county = values(county)town = values(town)village =
        values(village)code = values(code)level = values(level)grid = values(grid)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update grid_mgmt_admin_division
        <set>
            <if test="province != null and province != ''">
                province = #{province},
            </if>
            <if test="city != null and city != ''">
                city = #{city},
            </if>
            <if test="county != null and county != ''">
                county = #{county},
            </if>
            <if test="town != null and town != ''">
                town = #{town},
            </if>
            <if test="village != null and village != ''">
                village = #{village},
            </if>
            <if test="code != null and code != ''">
                code = #{code},
            </if>
            <if test="level != null">
                level = #{level},
            </if>
            <if test="grid != null and grid != ''">
                grid = #{grid},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete
        from grid_mgmt_admin_division
        where id = #{id}
    </delete>

</mapper>

