<?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.yiqi.core.mapper.GoodsCategoryMapper">

    <resultMap type="com.yiqi.core.domain.GoodsCategory" id="GoodsCategoryResult">
            <result property="id" column="id"/>
            <result property="categoryName" column="category_name"/>
            <result property="goodsType" column="goods_type"/>
            <result property="status" column="status"/>
            <result property="createBy" column="create_by"/>
            <result property="createById" column="create_by_id"/>
            <result property="createTime" column="create_time"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateById" column="update_by_id"/>
            <result property="updateTime" column="update_time"/>
            <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectGoodsCategoryVo">
        select * from goods_category
    </sql>

    <select id="selectGoodsCategoryList"  resultMap="GoodsCategoryResult">
        <include refid="selectGoodsCategoryVo"/>
        <where>
            <if test="categoryName != null  and categoryName != ''">
                and category_name like concat('%', #{categoryName}, '%')
            </if>
            <if test="goodsType != null  and goodsType != ''">
                and goods_type = #{goodsType}
            </if>
            <if test="status != null  and status != ''">
                and status = #{status}
            </if>
        </where>
    </select>

    <select id="selectGoodsCategoryById" parameterType="Long"
            resultMap="GoodsCategoryResult">
            <include refid="selectGoodsCategoryVo"/>
            where id = #{id}
    </select>

    <insert id="insertGoodsCategory"  useGeneratedKeys="true"
            keyProperty="id">
        insert into goods_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="categoryName != null">category_name,</if>
            <if test="goodsType != null and goodsType != ''">goods_type,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createById != null">create_by_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateById != null">update_by_id,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="categoryName != null">#{categoryName},</if>
            <if test="goodsType != null and goodsType != ''">#{goodsType},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createById != null">#{createById},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateById != null">#{updateById},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateGoodsCategory" >
        update goods_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="categoryName != null">category_name =
                #{categoryName},
            </if>
            <if test="goodsType != null and goodsType != ''">goods_type =
                #{goodsType},
            </if>
            <if test="status != null and status != ''">status =
                #{status},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createById != null">create_by_id =
                #{createById},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateById != null">update_by_id =
                #{updateById},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </if>
        </trim>
        where id = #{id}
    </update>

        <delete id="deleteGoodsCategoryById" parameterType="Long">
            delete from goods_category where id = #{id}
        </delete>

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



</mapper>