<?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.BmProjectInfoMapper">
    
    <resultMap type="BmProjectInfo" id="BmProjectInfoResult">
        <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="name"    column="name"    />
        <result property="isDel"    column="is_del"    />
        <result property="contactor"    column="contactor"    />
        <result property="phone"    column="phone"    />
        <result property="needAmt"    column="need_amt"    />
        <result property="fixedAssets"    column="fixed_assets"    />
        <result property="productName"    column="product_name"    />
        <result property="productQty"    column="product_qty"    />
        <result property="productPrice"    column="product_price"    />
        <result property="productTax"    column="product_tax"    />
        <result property="productEmp"    column="product_emp"    />
        <result property="plannedLand"    column="planned_land"    />
        <result property="independentLand"    column="independent_land"    />
        <result property="circulationLan"    column="circulation_lan"    />
        <result property="needRoom"    column="need_room"    />
        <result property="needFactoryRoom"    column="need_factory_room"    />
        <result property="needBusRoom"    column="need_bus_room"    />
        <result property="other"    column="other"    />
        <result property="address"    column="address"    />
        <result property="isFrameorder"    column="is_frameorder"    />
        <result property="attachment"    column="attachment"    />
        <result property="description"    column="description"    />
        <collection  property="referralList"  javaType="java.util.List"  resultMap="BmProjectReferralResult" />
    </resultMap>

    <resultMap type="BmProjectReferral" id="BmProjectReferralResult">
        <result property="id"    column="r_id"    />
        <result property="bmProjectId"    column="r_bm_project_id"    />
        <result property="createBy"    column="r_create_by"    />
        <result property="createTime"    column="r_create_time"    />
        <result property="updateBy"    column="r_update_by"    />
        <result property="updateTime"    column="r_update_time"    />
        <result property="isDel"    column="r_is_del"    />
        <result property="phone"    column="r_phone"    />
        <result property="sysDeptId"    column="r_sys_dept_id"    />
        <result property="investmentAllcocation"    column="r_investment_allcocation"    />
        <result property="referral"    column="r_referral"    />
        <result property="referralPhone"    column="r_referral_phone"    />
    </resultMap>

    <sql id="selectBmProjectInfoVo">
        select id, bm_project_id, create_by, create_time, update_by, update_time, name, is_del, contactor, phone, need_amt, fixed_assets, product_name, product_qty, product_price, product_tax, product_emp, planned_land, independent_land, circulation_lan, need_room, need_factory_room, need_bus_room, other, address, is_frameorder, attachment, description from bm_project_info
    </sql>

    <select id="selectBmProjectInfoList" parameterType="BmProjectInfo" resultMap="BmProjectInfoResult">
        <include refid="selectBmProjectInfoVo"/>
        <where>
            is_del = '0'
            <if test="bmProjectId != null "> and bm_project_id = #{bmProjectId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="contactor != null  and contactor != ''"> and contactor like concat('%', #{contactor}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
            <if test="needAmt != null "> and need_amt = #{needAmt}</if>
            <if test="fixedAssets != null "> and fixed_assets = #{fixedAssets}</if>
            <if test="productName != null  and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
            <if test="productQty != null  and productQty != ''"> and product_qty = #{productQty}</if>
            <if test="productPrice != null "> and product_price = #{productPrice}</if>
            <if test="productTax != null "> and product_tax = #{productTax}</if>
            <if test="productEmp != null  and productEmp != ''"> and product_emp = #{productEmp}</if>
            <if test="plannedLand != null "> and planned_land = #{plannedLand}</if>
            <if test="independentLand != null "> and independent_land = #{independentLand}</if>
            <if test="circulationLan != null "> and circulation_lan = #{circulationLan}</if>
            <if test="needRoom != null "> and need_room = #{needRoom}</if>
            <if test="needFactoryRoom != null "> and need_factory_room = #{needFactoryRoom}</if>
            <if test="needBusRoom != null "> and need_bus_room = #{needBusRoom}</if>
            <if test="other != null  and other != ''"> and other like concat('%', #{other}, '%')</if>
            <if test="address != null  and address != ''"> and address like concat('%', #{address}, '%')</if>
            <if test="isFrameorder != null  and isFrameorder != ''"> and is_frameorder = #{isFrameorder}</if>
            <if test="attachment != null  and attachment != ''"> and attachment = #{attachment}</if>
            <if test="description != null  and description != ''"> and description like concat('%', #{description}, '%')</if>
        </where>
    </select>
    
    <select id="selectBmProjectInfoById" parameterType="Long" resultMap="BmProjectInfoResult">
    SELECT
	i.id,
	i.bm_project_id,
	i.create_by,
	i.create_time,
	i.update_by,
	i.update_time,
	i.NAME,
	i.is_del,
	i.contactor,
	i.phone,
	i.need_amt,
	i.fixed_assets,
	i.product_name,
	i.product_qty,
	i.product_price,
	i.product_tax,
	i.product_emp,
	i.planned_land,
	i.independent_land,
	i.circulation_lan,
	i.need_room,
	i.need_factory_room,
	i.need_bus_room,
	i.other,
	i.address,
	i.is_frameorder,
	i.attachment,
	i.description,
	r.id as r_id,
	r.bm_project_id as r_bm_project_id,
	r.create_by as r_create_by,
	r.create_time as r_create_time,
	r.update_by as r_update_by,
	r.update_time as r_update_time,
	r.is_del as r_is_del,
	r.phone as r_phone,
	r.sys_dept_id as r_sys_dept_id,
	r.investment_allcocation as r_investment_allcocation,
	r.referral as r_referral,
	r.referral_phone as r_referral_phone
    FROM
	bm_project_info i
	LEFT JOIN bm_project_referral r ON i.bm_project_id = r.bm_project_id
	AND i.is_del = '0'
        where i.bm_project_id = #{id}
    </select>
        
    <insert id="insertBmProjectInfo" parameterType="BmProjectInfo" useGeneratedKeys="true" keyProperty="id">
        insert ignore into bm_project_info
        <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="name != null">name,</if>
            <if test="isDel != null">is_del,</if>
            <if test="contactor != null">contactor,</if>
            <if test="phone != null">phone,</if>
            <if test="needAmt != null">need_amt,</if>
            <if test="fixedAssets != null">fixed_assets,</if>
            <if test="productName != null">product_name,</if>
            <if test="productQty != null">product_qty,</if>
            <if test="productPrice != null">product_price,</if>
            <if test="productTax != null">product_tax,</if>
            <if test="productEmp != null">product_emp,</if>
            <if test="plannedLand != null">planned_land,</if>
            <if test="independentLand != null">independent_land,</if>
            <if test="circulationLan != null">circulation_lan,</if>
            <if test="needRoom != null">need_room,</if>
            <if test="needFactoryRoom != null">need_factory_room,</if>
            <if test="needBusRoom != null">need_bus_room,</if>
            <if test="other != null">other,</if>
            <if test="address != null">address,</if>
            <if test="isFrameorder != null">is_frameorder,</if>
            <if test="attachment != null">attachment,</if>
            <if test="description != null">description,</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="name != null">#{name},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="contactor != null">#{contactor},</if>
            <if test="phone != null">#{phone},</if>
            <if test="needAmt != null">#{needAmt},</if>
            <if test="fixedAssets != null">#{fixedAssets},</if>
            <if test="productName != null">#{productName},</if>
            <if test="productQty != null">#{productQty},</if>
            <if test="productPrice != null">#{productPrice},</if>
            <if test="productTax != null">#{productTax},</if>
            <if test="productEmp != null">#{productEmp},</if>
            <if test="plannedLand != null">#{plannedLand},</if>
            <if test="independentLand != null">#{independentLand},</if>
            <if test="circulationLan != null">#{circulationLan},</if>
            <if test="needRoom != null">#{needRoom},</if>
            <if test="needFactoryRoom != null">#{needFactoryRoom},</if>
            <if test="needBusRoom != null">#{needBusRoom},</if>
            <if test="other != null">#{other},</if>
            <if test="address != null">#{address},</if>
            <if test="isFrameorder != null">#{isFrameorder},</if>
            <if test="attachment != null">#{attachment},</if>
            <if test="description != null">#{description},</if>
         </trim>
    </insert>

    <update id="updateBmProjectInfo" parameterType="BmProjectInfo">
        update bm_project_info
        <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="name != null">name = #{name},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="contactor != null">contactor = #{contactor},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="needAmt != null">need_amt = #{needAmt},</if>
            <if test="fixedAssets != null">fixed_assets = #{fixedAssets},</if>
            <if test="productName != null">product_name = #{productName},</if>
            <if test="productQty != null">product_qty = #{productQty},</if>
            <if test="productPrice != null">product_price = #{productPrice},</if>
            <if test="productTax != null">product_tax = #{productTax},</if>
            <if test="productEmp != null">product_emp = #{productEmp},</if>
            <if test="plannedLand != null">planned_land = #{plannedLand},</if>
            <if test="independentLand != null">independent_land = #{independentLand},</if>
            <if test="circulationLan != null">circulation_lan = #{circulationLan},</if>
            <if test="needRoom != null">need_room = #{needRoom},</if>
            <if test="needFactoryRoom != null">need_factory_room = #{needFactoryRoom},</if>
            <if test="needBusRoom != null">need_bus_room = #{needBusRoom},</if>
            <if test="other != null">other = #{other},</if>
            <if test="address != null">address = #{address},</if>
            <if test="isFrameorder != null">is_frameorder = #{isFrameorder},</if>
            <if test="attachment != null">attachment = #{attachment},</if>
            <if test="description != null">description = #{description},</if>
        </trim>
        where id = #{id}
    </update>

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

    <update id="deleteBmProjectInfoById" parameterType="Long">
        update  bm_project_info set id_del = '1' where id = #{id}
    </update>

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

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