<?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.ruoyi.system.mapper.project.BmProjectReferralMapper">
    
    <resultMap type="BmProjectReferral" id="BmProjectReferralResult">
        <result property="id"    column="id"    />
        <result property="bmProjectId"    column="bm_project_id"    />
        <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="isDel"    column="is_del"    />
        <result property="phone"    column="phone"    />
        <result property="sysDeptId"    column="sys_dept_id"    />
        <result property="investmentAllcocation"    column="investment_allcocation"    />
        <result property="referral"    column="referral"    />
        <result property="referralPhone"    column="referral_phone"    />
    </resultMap>

    <sql id="selectBmProjectReferralVo">
        select id, bm_project_id, create_by, create_time, update_by, update_time, is_del, phone, sys_dept_id, investment_allcocation, referral, referral_phone from bm_project_referral
    </sql>

    <select id="selectBmProjectReferralList" parameterType="BmProjectReferral" resultMap="BmProjectReferralResult">
        <include refid="selectBmProjectReferralVo"/>
        <where>
            is_del = '0'
            <if test="bmProjectId != null "> and bm_project_id = #{bmProjectId}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="sysDeptId != null "> and sys_dept_id = #{sysDeptId}</if>
            <if test="investmentAllcocation != null "> and investment_allcocation = #{investmentAllcocation}</if>
            <if test="referral != null  and referral != ''"> and referral = #{referral}</if>
            <if test="referralPhone != null  and referralPhone != ''"> and referral_phone = #{referralPhone}</if>
        </where>
    </select>
    
    <select id="selectBmProjectReferralById" parameterType="Long" resultMap="BmProjectReferralResult">
        <include refid="selectBmProjectReferralVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBmProjectReferral" parameterType="BmProjectReferral" useGeneratedKeys="true" keyProperty="id">
        insert into bm_project_referral
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bmProjectId != null">bm_project_id,</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="isDel != null">is_del,</if>
            <if test="phone != null">phone,</if>
            <if test="sysDeptId != null">sys_dept_id,</if>
            <if test="investmentAllcocation != null">investment_allcocation,</if>
            <if test="referral != null">referral,</if>
            <if test="referralPhone != null">referral_phone,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bmProjectId != null">#{bmProjectId},</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="isDel != null">#{isDel},</if>
            <if test="phone != null">#{phone},</if>
            <if test="sysDeptId != null">#{sysDeptId},</if>
            <if test="investmentAllcocation != null">#{investmentAllcocation},</if>
            <if test="referral != null">#{referral},</if>
            <if test="referralPhone != null">#{referralPhone},</if>
         </trim>
    </insert>

    <update id="updateBmProjectReferral" parameterType="BmProjectReferral">
        update bm_project_referral
        <trim prefix="SET" suffixOverrides=",">
            <if test="bmProjectId != null">bm_project_id = #{bmProjectId},</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="isDel != null">is_del = #{isDel},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="sysDeptId != null">sys_dept_id = #{sysDeptId},</if>
            <if test="investmentAllcocation != null">investment_allcocation = #{investmentAllcocation},</if>
            <if test="referral != null">referral = #{referral},</if>
            <if test="referralPhone != null">referral_phone = #{referralPhone},</if>
        </trim>
        where id = #{id}
    </update>

<!--    <delete id="deleteBmProjectReferralById" parameterType="Long">
        delete from bm_project_referral where id = #{id}
    </delete>-->

    <update id="deleteBmProjectReferralById" parameterType="Long">
        update  bm_project_referral set  is_del = '1' where id = #{id}
    </update>

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

    <update id="deleteBmProjectReferralByIds" parameterType="String">
        update  bm_project_referral set  is_del = '1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>