<?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.BmProjectProductMapper">
    
    <resultMap type="BmProjectProduct" id="BmProjectProductResult">
        <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="totInvestment"    column="tot_investment"    />
        <result property="macInvestment"    column="mac_investment"    />
        <result property="productDate"    column="product_date"    />
        <result property="productPhoto"    column="product_photo"    />
        <result property="arrivalListPhoto"    column="arrival_list_photo"    />
        <result property="orderContractPhoto"    column="order_contract_photo"    />
        <result property="isOk"    column="is_ok"    />
        <result property="okDate"    column="ok_date"    />
        <result property="entryPhoto"    column="entry_photo"    />
    </resultMap>

    <sql id="selectBmProjectProductVo">
        select id, bm_project_id, create_by, create_time, update_by, update_time, is_del, tot_investment, mac_investment, product_date, product_photo, arrival_list_photo, order_contract_photo, is_ok, ok_date,entry_photo from bm_project_product
    </sql>

    <select id="selectBmProjectProductList" parameterType="BmProjectProduct" resultMap="BmProjectProductResult">
        <include refid="selectBmProjectProductVo"/>
        <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="totInvestment != null "> and tot_investment = #{totInvestment}</if>
            <if test="macInvestment != null "> and mac_investment = #{macInvestment}</if>
            <if test="productDate != null "> and product_date = #{productDate}</if>
            <if test="productPhoto != null  and productPhoto != ''"> and product_photo = #{productPhoto}</if>
            <if test="arrivalListPhoto != null  and arrivalListPhoto != ''"> and arrival_list_photo = #{arrivalListPhoto}</if>
            <if test="orderContractPhoto != null  and orderContractPhoto != ''"> and order_contract_photo = #{orderContractPhoto}</if>
            <if test="isOk != null  and isOk != ''"> and is_ok = #{isOk}</if>
            <if test="okDate != null "> and ok_date = #{okDate}</if>
        </where>
        order by create_time DESC
    </select>
    
    <select id="selectBmProjectProductById" parameterType="Long" resultMap="BmProjectProductResult">
        <include refid="selectBmProjectProductVo"/>
        where bm_project_id = #{id} and is_del = '0' limit 1
    </select>
        
    <insert id="insertBmProjectProduct" parameterType="BmProjectProduct" useGeneratedKeys="true" keyProperty="id">
        insert into bm_project_product
        <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="totInvestment != null">tot_investment,</if>
            <if test="macInvestment != null">mac_investment,</if>
            <if test="productDate != null">product_date,</if>
            <if test="productPhoto != null">product_photo,</if>
            <if test="arrivalListPhoto != null">arrival_list_photo,</if>
            <if test="orderContractPhoto != null">order_contract_photo,</if>
            <if test="isOk != null">is_ok,</if>
            <if test="okDate != null">ok_date,</if>
            <if test="entryPhoto != null">entry_photo,</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="totInvestment != null">#{totInvestment},</if>
            <if test="macInvestment != null">#{macInvestment},</if>
            <if test="productDate != null">#{productDate},</if>
            <if test="productPhoto != null">#{productPhoto},</if>
            <if test="arrivalListPhoto != null">#{arrivalListPhoto},</if>
            <if test="orderContractPhoto != null">#{orderContractPhoto},</if>
            <if test="isOk != null">#{isOk},</if>
            <if test="okDate != null">#{okDate},</if>
            <if test="entryPhoto != null">#{entryPhoto},</if>
         </trim>
    </insert>

    <update id="updateBmProjectProduct" parameterType="BmProjectProduct">
        update bm_project_product
        <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="totInvestment != null">tot_investment = #{totInvestment},</if>
            <if test="macInvestment != null">mac_investment = #{macInvestment},</if>
            <if test="productDate != null">product_date = #{productDate},</if>
            <if test="productPhoto != null">product_photo = #{productPhoto},</if>
            <if test="arrivalListPhoto != null">arrival_list_photo = #{arrivalListPhoto},</if>
            <if test="orderContractPhoto != null">order_contract_photo = #{orderContractPhoto},</if>
            <if test="isOk != null">is_ok = #{isOk},</if>
            <if test="okDate != null">ok_date = #{okDate},</if>
            <if test="entryPhoto != null">entry_photo = #{entryPhoto},</if>
        </trim>
        where id = #{id}
    </update>

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

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

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

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