<?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.amms.mapper.ItemCategoryMapper">

    <resultMap type="com.amms.domain.ItemCategory" id="ItemCategoryResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="creator"    column="creator"    />
        <result property="createTime"    column="create_time"    />
        <result property="updater"    column="updater"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectItemCategoryVo">
        select id, name, creator, create_time, updater, update_time, remark from item_category
    </sql>

    <select id="selectItemCategoryList" parameterType="com.amms.domain.ItemCategory" resultMap="ItemCategoryResult">
        <include refid="selectItemCategoryVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="creator != null "> and creator = #{creator}</if>
            <if test="updater != null "> and updater = #{updater}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectItemCategoryById" parameterType="Long" resultMap="ItemCategoryResult">
        <include refid="selectItemCategoryVo"/>
        where id = #{id}
    </select>

    <insert id="insertItemCategory" parameterType="com.amms.domain.ItemCategory" useGeneratedKeys="true" keyProperty="id">
        insert into item_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="creator != null">creator,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updater != null">updater,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="creator != null">#{creator},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updater != null">#{updater},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateItemCategory" parameterType="com.amms.domain.ItemCategory">
        update item_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="creator != null">creator = #{creator},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updater != null">updater = #{updater},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteItemCategoryById" parameterType="Long">
        delete from item_category where id = #{id}
    </delete>
</mapper>
