<?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.asset.mapper.TbPlaceMapper">
    
    <resultMap type="TbPlace" id="TbPlaceResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="purpose"    column="purpose"    />
    </resultMap>

    <sql id="selectTbPlaceVo">
        select id, name, purpose from tb_place
    </sql>

    <select id="selectTbPlaceList" parameterType="TbPlace" resultMap="TbPlaceResult">
        <include refid="selectTbPlaceVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="purpose != null  and purpose != ''"> and purpose = #{purpose}</if>
        </where>
    </select>
    
    <select id="selectTbPlaceById" parameterType="Long" resultMap="TbPlaceResult">
        <include refid="selectTbPlaceVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTbPlace" parameterType="TbPlace" useGeneratedKeys="true" keyProperty="id">
        insert into tb_place
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="purpose != null">purpose,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="purpose != null">#{purpose},</if>
         </trim>
    </insert>

    <update id="updateTbPlace" parameterType="TbPlace">
        update tb_place
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="purpose != null">purpose = #{purpose},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbPlaceById" parameterType="Long">
        delete from tb_place where id = #{id}
    </delete>

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

    <insert id="replace" parameterType="TbPlace">
        replace into tb_place
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="purpose != null">purpose,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="purpose != null">#{purpose},</if>
        </trim>
    </insert>
</mapper>