<?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.sgzb.material.mapper.PlanNeedInfoMapper">
    
    <resultMap type="com.bonus.sgzb.material.domain.PlanNeedInfo" id="PlanNeedInfoResult">
        <result property="planId"    column="plan_id"    />
        <result property="unitId"    column="unit_id"    />
        <result property="code"    column="code"    />
        <result property="createBy"    column="create_by"    />
        <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="selectPlanNeedInfoVo">
        select plan_id, unit_id, code, create_by, create_time, update_by, update_time, remark, company_id
        from plan_need_info
    </sql>

    <select id="selectPlanNeedInfoList" parameterType="com.bonus.sgzb.material.domain.PlanNeedInfo" resultMap="PlanNeedInfoResult">
        <include refid="selectPlanNeedInfoVo"/>
        <where>  
            <if test="unitId != null "> and unit_id = #{unitId}</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectPlanNeedInfoByPlanId" parameterType="Long" resultMap="PlanNeedInfoResult">
        <include refid="selectPlanNeedInfoVo"/>
        where plan_id = #{planId}
    </select>
        
    <insert id="insertPlanNeedInfo" parameterType="com.bonus.sgzb.material.domain.PlanNeedInfo" useGeneratedKeys="true" keyProperty="planId">
        insert into plan_need_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="unitId != null">unit_id,</if>
            <if test="code != null">code,</if>
            <if test="createBy != null">create_by,</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="unitId != null">#{unitId},</if>
            <if test="code != null">#{code},</if>
            <if test="createBy != null">#{createBy},</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="updatePlanNeedInfo" parameterType="com.bonus.sgzb.material.domain.PlanNeedInfo">
        update plan_need_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="unitId != null">unit_id = #{unitId},</if>
            <if test="code != null">code = #{code},</if>
            <if test="createBy != null">create_by = #{createBy},</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="deletePlanNeedInfoByPlanId" parameterType="Long">
        delete from plan_need_info where plan_id = #{planId}
    </delete>

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