<?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.hw.wms.mapper.WmsBaseCategoryMapper">
    
    <resultMap type="WmsBaseCategory" id="WmsBaseCategoryResult">
        <result property="categoryId"    column="category_id"    />
        <result property="categoryName"    column="category_name"    />
        <result property="virtualFlag"    column="virtual_flag"    />
        <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="selectWmsBaseCategoryVo">
        select category_id, category_name, virtual_flag, remark, create_by, create_time, update_by, update_time from wms_base_category
    </sql>

    <select id="selectWmsBaseCategoryList" parameterType="WmsBaseCategory" resultMap="WmsBaseCategoryResult">
        <include refid="selectWmsBaseCategoryVo"/>
        <where>  
            <if test="categoryName != null  and categoryName != ''"> and category_name like concat('%', #{categoryName}, '%')</if>
            <if test="virtualFlag != null  and virtualFlag != ''"> and virtual_flag = #{virtualFlag}</if>
        </where>
    </select>
    
    <select id="selectWmsBaseCategoryByCategoryId" parameterType="Long" resultMap="WmsBaseCategoryResult">
        <include refid="selectWmsBaseCategoryVo"/>
        where category_id = #{categoryId}
    </select>
        
    <insert id="insertWmsBaseCategory" parameterType="WmsBaseCategory" useGeneratedKeys="true" keyProperty="categoryId">
        insert into wms_base_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="categoryName != null and categoryName != ''">category_name,</if>
            <if test="virtualFlag != null and virtualFlag != ''">virtual_flag,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">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="categoryName != null and categoryName != ''">#{categoryName},</if>
            <if test="virtualFlag != null and virtualFlag != ''">#{virtualFlag},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateWmsBaseCategory" parameterType="WmsBaseCategory">
        update wms_base_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="categoryName != null and categoryName != ''">category_name = #{categoryName},</if>
            <if test="virtualFlag != null and virtualFlag != ''">virtual_flag = #{virtualFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">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 category_id = #{categoryId}
    </update>

    <delete id="deleteWmsBaseCategoryByCategoryId" parameterType="Long">
        delete from wms_base_category where category_id = #{categoryId}
    </delete>

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