<?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.TbLocationMapper">
    
    <resultMap type="TbLocation" id="TbLocationResult">
        <result property="id"    column="id"    />
        <result property="number"    column="number"    />
        <result property="name"    column="name"    />
        <result property="company"    column="company"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectTbLocationVo">
        select id, number, name, company, remark, create_by, create_time, update_by, update_time from tb_location
    </sql>

    <select id="selectTbLocationList" parameterType="TbLocation" resultMap="TbLocationResult">
        <include refid="selectTbLocationVo"/>
        <where>  
            <if test="number != null  and number != ''"> and number = #{number}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="company != null  and company != ''"> and company = #{company}</if>
        </where>
    </select>
    
    <select id="selectTbLocationById" parameterType="Long" resultMap="TbLocationResult">
        <include refid="selectTbLocationVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTbLocation" parameterType="TbLocation" useGeneratedKeys="true" keyProperty="id">
        insert into tb_location
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="number != null and number != ''">number,</if>
            <if test="name != null">name,</if>
            <if test="company != null and company != ''">company,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="number != null and number != ''">#{number},</if>
            <if test="name != null">#{name},</if>
            <if test="company != null and company != ''">#{company},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateTbLocation" parameterType="TbLocation">
        update tb_location
        <trim prefix="SET" suffixOverrides=",">
            <if test="number != null and number != ''">number = #{number},</if>
            <if test="name != null">name = #{name},</if>
            <if test="company != null and company != ''">company = #{company},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbLocationById" parameterType="Long">
        delete from tb_location where id = #{id}
    </delete>

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