<?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.kaohe.mapper.KhTemItemMapper">
    
    <resultMap type="KhTemItem" id="KhTemItemResult">
        <result property="id"    column="id"    />
        <result property="temName"    column="tem_name"    />
        <result property="khitemId"    column="khitem_id"    />
        <result property="itemName"    column="item_name"    />
        <result property="temId"    column="tem_id"    />
        <result property="typeId"    column="type_id"    />
        <result property="type"    column="type"    />
    </resultMap>

    <sql id="selectKhTemItemVo">
        select id, tem_name, khitem_id, item_name, tem_id, type_id, type from kh_tem_item
    </sql>

    <select id="selectKhTemItemList" parameterType="KhTemItem" resultMap="KhTemItemResult">
        <include refid="selectKhTemItemVo"/>
        <where>  
            <if test="temName != null  and temName != ''"> and tem_name like concat('%', #{temName}, '%')</if>
            <if test="khitemId != null "> and khitem_id = #{khitemId}</if>
            <if test="itemName != null  and itemName != ''"> and item_name like concat('%', #{itemName}, '%')</if>
            <if test="temId != null "> and tem_id = #{temId}</if>
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
        </where>
    </select>
    
    <select id="selectKhTemItemById" parameterType="Long" resultMap="KhTemItemResult">
        <include refid="selectKhTemItemVo"/>
        where id = #{id}
    </select>

    <insert id="insertKhTemItem" parameterType="KhTemItem" useGeneratedKeys="true" keyProperty="id">
        insert into kh_tem_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="temName != null and temName != ''">tem_name,</if>
            <if test="khitemId != null">khitem_id,</if>
            <if test="itemName != null and itemName != ''">item_name,</if>
            <if test="temId != null">tem_id,</if>
            <if test="typeId != null">type_id,</if>
            <if test="type != null">type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="temName != null and temName != ''">#{temName},</if>
            <if test="khitemId != null">#{khitemId},</if>
            <if test="itemName != null and itemName != ''">#{itemName},</if>
            <if test="temId != null">#{temId},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="type != null">#{type},</if>
         </trim>
    </insert>

    <update id="updateKhTemItem" parameterType="KhTemItem">
        update kh_tem_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="temName != null and temName != ''">tem_name = #{temName},</if>
            <if test="khitemId != null">khitem_id = #{khitemId},</if>
            <if test="itemName != null and itemName != ''">item_name = #{itemName},</if>
            <if test="temId != null">tem_id = #{temId},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="type != null">type = #{type},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKhTemItemById" parameterType="Long">
        delete from kh_tem_item where id = #{id}
    </delete>

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