<?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.fs.oms.mapper.OmsProductCategoryMapper">
    
    <resultMap type="OmsProductCategory" id="OmsProductCategoryResult">
        <result property="cateId"    column="cate_id"    />
        <result property="pid"    column="pid"    />
        <result property="cateName"    column="cate_name"    />
        <result property="sort"    column="sort"    />
        <result property="pic" column="pic"/>
        <result property="isShow"    column="is_show"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectOmsProductCategoryVo">
        select cate_id, pid, cate_name, sort, pic, is_show, create_time, update_time, is_del from oms_product_category
    </sql>

    <select id="selectOmsProductCategoryList" parameterType="OmsProductCategory" resultMap="OmsProductCategoryResult">
        <include refid="selectOmsProductCategoryVo"/>
        <where>  
            <if test="pid != null "> and pid = #{pid}</if>
            <if test="cateName != null  and cateName != ''"> and cate_name like concat('%', #{cateName}, '%')</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="pic != null  and pic != ''"> and pic = #{pic}</if>
            <if test="isShow != null "> and is_show = #{isShow}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectOmsProductCategoryById" parameterType="Long" resultMap="OmsProductCategoryResult">
        <include refid="selectOmsProductCategoryVo"/>
        where cate_id = #{cateId}
    </select>
        
    <insert id="insertOmsProductCategory" parameterType="OmsProductCategory" useGeneratedKeys="true" keyProperty="cateId">
        insert into oms_product_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pid != null">pid,</if>
            <if test="cateName != null and cateName != ''">cate_name,</if>
            <if test="sort != null">sort,</if>
            <if test="isShow != null">is_show,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pid != null">#{pid},</if>
            <if test="cateName != null and cateName != ''">#{cateName},</if>
            <if test="sort != null">#{sort},</if>
            <if test="isShow != null">#{isShow},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateOmsProductCategory" parameterType="OmsProductCategory">
        update oms_product_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="pid != null">pid = #{pid},</if>
            <if test="cateName != null and cateName != ''">cate_name = #{cateName},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="isShow != null">is_show = #{isShow},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where cate_id = #{cateId}
    </update>

    <delete id="deleteOmsProductCategoryById" parameterType="Long">
        delete from oms_product_category where cate_id = #{cateId}
    </delete>

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