<?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.BmProjectConstructionMapper">
    
    <resultMap type="BmProjectConstruction" id="BmProjectConstructionResult">
        <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="constructionCode"    column="construction_code"    />
        <result property="isConstruction"    column="is_construction"    />
        <result property="constructionStartdate"    column="construction_startdate"    />
        <result property="constructionEnddate"    column="construction_enddate"    />
        <result property="constructionDoc"    column="construction_doc"    />
        <result property="constructionPhoto"    column="construction_photo"    />
    </resultMap>

    <sql id="selectBmProjectConstructionVo">
        select id, bm_project_id, create_by, create_time, update_by, update_time, is_del, construction_code, is_construction, construction_startdate, construction_enddate, construction_doc, construction_photo from bm_project_construction
    </sql>

    <select id="selectBmProjectConstructionList" parameterType="BmProjectConstruction" resultMap="BmProjectConstructionResult">
        <include refid="selectBmProjectConstructionVo"/>
        <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="constructionCode != null  and constructionCode != ''"> and construction_code = #{constructionCode}</if>
            <if test="isConstruction != null  and isConstruction != ''"> and is_construction = #{isConstruction}</if>
            <if test="constructionStartdate != null "> and construction_startdate like concat('%', #{constructionStartdate}, '%')</if>
            <if test="constructionEnddate != null "> and construction_enddate like concat('%', #{constructionEnddate}, '%')</if>
            <if test="constructionDoc != null  and constructionDoc != ''"> and construction_doc = #{constructionDoc}</if>
            <if test="constructionPhoto != null  and constructionPhoto != ''"> and construction_photo = #{constructionPhoto}</if>
        </where>
        order by create_time DESC
    </select>
    
    <select id="selectBmProjectConstructionById" parameterType="Long" resultMap="BmProjectConstructionResult">
      select c.id, c.bm_project_id, c.create_by, c.create_time, c.update_by, c.update_time, c.is_del, c.construction_code, c.is_construction, c.construction_startdate, c.construction_enddate, c.construction_doc, c.construction_photo, p.order_begin_time, p.order_end_time
      from bm_project_construction c
      left join bm_project p on c.bm_project_id = p.id
      where c.bm_project_id = #{id} limit 1
    </select>
        
    <insert id="insertBmProjectConstruction" parameterType="BmProjectConstruction" useGeneratedKeys="true" keyProperty="id">
        insert into bm_project_construction
        <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="constructionCode != null">construction_code,</if>
            <if test="isConstruction != null">is_construction,</if>
            <if test="constructionStartdate != null">construction_startdate,</if>
            <if test="constructionEnddate != null">construction_enddate,</if>
            <if test="constructionDoc != null">construction_doc,</if>
            <if test="constructionPhoto != null">construction_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="constructionCode != null">#{constructionCode},</if>
            <if test="isConstruction != null">#{isConstruction},</if>
            <if test="constructionStartdate != null">#{constructionStartdate},</if>
            <if test="constructionEnddate != null">#{constructionEnddate},</if>
            <if test="constructionDoc != null">#{constructionDoc},</if>
            <if test="constructionPhoto != null">#{constructionPhoto},</if>
         </trim>
    </insert>

    <update id="updateBmProjectConstruction" parameterType="BmProjectConstruction">
        update bm_project_construction
        <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="constructionCode != null">construction_code = #{constructionCode},</if>
            <if test="isConstruction != null">is_construction = #{isConstruction},</if>
            <if test="constructionStartdate != null">construction_startdate = #{constructionStartdate},</if>
            <if test="constructionEnddate != null">construction_enddate = #{constructionEnddate},</if>
            <if test="constructionDoc != null">construction_doc = #{constructionDoc},</if>
            <if test="constructionPhoto != null">construction_photo = #{constructionPhoto},</if>
        </trim>
        where id = #{id}
    </update>

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

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

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

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