<?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.ruoyi.system.mapper.DiyCityMapper">
    
    <resultMap type="DiyCity" id="DiyCityResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="parentId"    column="parent_id"    />
        <result property="order"    column="order"    />
        <result property="lat"    column="lat"    />
        <result property="lng"    column="lng"    />
        <result property="provinceId"    column="province_id"    />
        <result property="cityId"    column="city_id"    />
        <result property="districtId"    column="district_id"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectDiyCityVo">
        select id, title, parent_id, order, lat, lng, province_id, city_id, district_id, created_at, updated_at from diy_city
    </sql>

    <select id="selectDiyCityList" parameterType="DiyCity" resultMap="DiyCityResult">
        <include refid="selectDiyCityVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="order != null "> and order = #{order}</if>
            <if test="lat != null  and lat != ''"> and lat = #{lat}</if>
            <if test="lng != null  and lng != ''"> and lng = #{lng}</if>
            <if test="provinceId != null "> and province_id = #{provinceId}</if>
            <if test="cityId != null "> and city_id = #{cityId}</if>
            <if test="districtId != null "> and district_id = #{districtId}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectDiyCityById" parameterType="Integer" resultMap="DiyCityResult">
        <include refid="selectDiyCityVo"/>
        where id = #{id}
    </select>

    <insert id="insertDiyCity" parameterType="DiyCity" useGeneratedKeys="true" keyProperty="id">
        insert into diy_city
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">title,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="order != null">order,</if>
            <if test="lat != null">lat,</if>
            <if test="lng != null">lng,</if>
            <if test="provinceId != null">province_id,</if>
            <if test="cityId != null">city_id,</if>
            <if test="districtId != null">district_id,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">#{title},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="order != null">#{order},</if>
            <if test="lat != null">#{lat},</if>
            <if test="lng != null">#{lng},</if>
            <if test="provinceId != null">#{provinceId},</if>
            <if test="cityId != null">#{cityId},</if>
            <if test="districtId != null">#{districtId},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateDiyCity" parameterType="DiyCity">
        update diy_city
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="order != null">order = #{order},</if>
            <if test="lat != null">lat = #{lat},</if>
            <if test="lng != null">lng = #{lng},</if>
            <if test="provinceId != null">province_id = #{provinceId},</if>
            <if test="cityId != null">city_id = #{cityId},</if>
            <if test="districtId != null">district_id = #{districtId},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDiyCityById" parameterType="Integer">
        delete from diy_city where id = #{id}
    </delete>

    <delete id="deleteDiyCityByIds" parameterType="String">
        delete from diy_city where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>