<?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.zbf.system.mapper.TBaseGoodsBomMapper">

    <resultMap type="TBaseGoodsBom" id="TBaseGoodsBomResult">
            <result property="id"    column="id"    />
            <result property="pid"    column="pid"    />
            <result property="goodsId"    column="goods_id"    />
            <result property="goodsName"    column="goods_name"    />
            <result property="goodsType"    column="goods_type"    />
            <result property="serialNumber"    column="serial_number"    />
            <result property="goodsNum"    column="goods_num"    />
            <result property="remark"    column="remark"    />
            <result property="createTime"    column="create_time"    />
            <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectTBaseGoodsBomVo">
        select id, pid, goods_id, goods_name, goods_type, serial_number, goods_num, remark, create_time, update_time from t_base_goods_bom
    </sql>

    <select id="selectTBaseGoodsBomList" parameterType="TBaseGoodsBom" resultMap="TBaseGoodsBomResult">
        <include refid="selectTBaseGoodsBomVo"/>
        <where>
                        <if test="pid != null "> and pid = #{pid}</if>
                        <if test="goodsId != null  and goodsId != ''"> and goods_id = #{goodsId}</if>
                        <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
                        <if test="goodsType != null "> and goods_type = #{goodsType}</if>
                        <if test="serialNumber != null  and serialNumber != ''"> and serial_number = #{serialNumber}</if>
                        <if test="goodsNum != null "> and goods_num = #{goodsNum}</if>
        </where>
    </select>

    <select id="selectTBaseGoodsBomById" parameterType="Long" resultMap="TBaseGoodsBomResult">
            <include refid="selectTBaseGoodsBomVo"/>
            where id = #{id}
    </select>

    <insert id="insertTBaseGoodsBom" parameterType="TBaseGoodsBom" useGeneratedKeys="true" keyProperty="id">
        insert into t_base_goods_bom
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="pid != null">pid,</if>
                    <if test="goodsId != null">goods_id,</if>
                    <if test="goodsName != null">goods_name,</if>
                    <if test="goodsType != null">goods_type,</if>
                    <if test="serialNumber != null">serial_number,</if>
                    <if test="goodsNum != null">goods_num,</if>
                    <if test="remark != null">remark,</if>
                    <if test="createTime != null">create_time,</if>
                    <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="pid != null">#{pid},</if>
                    <if test="goodsId != null">#{goodsId},</if>
                    <if test="goodsName != null">#{goodsName},</if>
                    <if test="goodsType != null">#{goodsType},</if>
                    <if test="serialNumber != null">#{serialNumber},</if>
                    <if test="goodsNum != null">#{goodsNum},</if>
                    <if test="remark != null">#{remark},</if>
                    <if test="createTime != null">#{createTime},</if>
                    <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateTBaseGoodsBom" parameterType="TBaseGoodsBom">
        update t_base_goods_bom
        <trim prefix="SET" suffixOverrides=",">
                    <if test="pid != null">pid = #{pid},</if>
                    <if test="goodsId != null">goods_id = #{goodsId},</if>
                    <if test="goodsName != null">goods_name = #{goodsName},</if>
                    <if test="goodsType != null">goods_type = #{goodsType},</if>
                    <if test="serialNumber != null">serial_number = #{serialNumber},</if>
                    <if test="goodsNum != null">goods_num = #{goodsNum},</if>
                    <if test="remark != null">remark = #{remark},</if>
                    <if test="createTime != null">create_time = #{createTime},</if>
                    <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="enableTBaseGoodsBomByIds" parameterType="String">
        update t_base_goods_bom set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledTBaseGoodsBomByIds" parameterType="String">
        update t_base_goods_bom set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteTBaseGoodsBomById" parameterType="Long">
        delete from t_base_goods_bom  where id = #{id}
    </delete>

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