<?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.plan.mapper.PlanNeedDetailsMapper">
    <resultMap type="com.bonus.material.plan.domain.PlanNeedDetails" id="PlanNeedDetailsResult">
        <result property="id"    column="id"    />
        <result property="planId"    column="plan_id"    />
        <result property="typeId"    column="type_id"    />
        <result property="planNum"    column="plan_num"    />
        <result property="planPrice"    column="plan_price"    />
        <result property="planCost"    column="plan_cost"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectPlanNeedDetailsVo">
        select id, plan_id, type_id, plan_num, plan_price, plan_cost, create_time, update_by, update_time, remark, company_id from plan_need_details
    </sql>

    <select id="selectPlanNeedDetailsList" parameterType="com.bonus.material.plan.domain.PlanNeedDetails" resultMap="PlanNeedDetailsResult">
        <include refid="selectPlanNeedDetailsVo"/>
        <where>  
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="planNum != null "> and plan_num = #{planNum}</if>
            <if test="planPrice != null "> and plan_price = #{planPrice}</if>
            <if test="planCost != null "> and plan_cost = #{planCost}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectPlanNeedDetailsByPlanId" parameterType="Long" resultMap="PlanNeedDetailsResult">
        <include refid="selectPlanNeedDetailsVo"/>
        where plan_id = #{planId}
    </select>
        
    <insert id="insertPlanNeedDetails" parameterType="com.bonus.material.plan.domain.PlanNeedDetails" useGeneratedKeys="true" keyProperty="planId">
        insert into plan_need_details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="typeId != null">type_id,</if>
            <if test="planNum != null">plan_num,</if>
            <if test="planPrice != null">plan_price,</if>
            <if test="planCost != null">plan_cost,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="companyId != null">company_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="planNum != null">#{planNum},</if>
            <if test="planPrice != null">#{planPrice},</if>
            <if test="planCost != null">#{planCost},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="companyId != null">#{companyId},</if>
         </trim>
    </insert>

    <update id="updatePlanNeedDetails" parameterType="com.bonus.material.plan.domain.PlanNeedDetails">
        update plan_need_details
        <trim prefix="SET" suffixOverrides=",">
            <if test="id != null">id = #{id},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="planNum != null">plan_num = #{planNum},</if>
            <if test="planPrice != null">plan_price = #{planPrice},</if>
            <if test="planCost != null">plan_cost = #{planCost},</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>
            <if test="remark != null">remark = #{remark},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
        where plan_id = #{planId}
    </update>

    <delete id="deletePlanNeedDetailsByPlanId" parameterType="Long">
        delete from plan_need_details where plan_id = #{planId}
    </delete>

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