<?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.bonus.material.ma.mapper.WholeSetMapper">
    <resultMap type="com.bonus.material.ma.domain.WholeSet" id="WholeSetResult">
        <result property="id"    column="id"    />
        <result property="wholeTypeName"    column="whole_type_name"    />
        <result property="ascriptionType"    column="ascription_type"    />
        <result property="typeId"    column="type_id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="partNum"    column="part_num"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectWholeSetVo">
        select id, whole_type_name, ascription_type, type_id, parent_id, part_num, status, create_by, create_time, update_time from ma_whole_set
    </sql>

    <select id="selectWholeSetList" parameterType="com.bonus.material.ma.domain.WholeSet" resultMap="WholeSetResult">
        <include refid="selectWholeSetVo"/>
        <where>  
            <if test="wholeTypeName != null  and wholeTypeName != ''"> and whole_type_name like concat('%', #{wholeTypeName}, '%')</if>
            <if test="ascriptionType != null "> and ascription_type = #{ascriptionType}</if>
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="partNum != null "> and part_num = #{partNum}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectWholeSetById" parameterType="Long" resultMap="WholeSetResult">
        <include refid="selectWholeSetVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertWholeSet" parameterType="com.bonus.material.ma.domain.WholeSet" useGeneratedKeys="true" keyProperty="id">
        insert into ma_whole_set
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wholeTypeName != null">whole_type_name,</if>
            <if test="ascriptionType != null">ascription_type,</if>
            <if test="typeId != null">type_id,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="partNum != null">part_num,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="wholeTypeName != null">#{wholeTypeName},</if>
            <if test="ascriptionType != null">#{ascriptionType},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="partNum != null">#{partNum},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateWholeSet" parameterType="com.bonus.material.ma.domain.WholeSet">
        update ma_whole_set
        <trim prefix="SET" suffixOverrides=",">
            <if test="wholeTypeName != null">whole_type_name = #{wholeTypeName},</if>
            <if test="ascriptionType != null">ascription_type = #{ascriptionType},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="partNum != null">part_num = #{partNum},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWholeSetById" parameterType="Long">
        delete from ma_whole_set where id = #{id}
    </delete>

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