<?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.BmConstructionEqMapper">
    
    <resultMap type="BmConstructionEq" id="BmConstructionEqResult">
        <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="eqType"    column="eq_type"    />
        <result property="photo"    column="photo"    />
    </resultMap>

    <sql id="selectBmConstructionEqVo">
        select id, bm_project_id, create_by, create_time, update_by, update_time, is_del, eq_type, photo from bm_construction_eq
    </sql>

    <select id="selectBmConstructionEqList" parameterType="BmConstructionEq" resultMap="BmConstructionEqResult">
        SELECT
        e.id,
        e.bm_project_id,
        e.create_by,
        e.create_time,
        e.update_by,
        e.update_time,
        e.is_del,
        e.eq_type,
        e.photo,
        d.dict_label as eqTypeName
        FROM
        bm_construction_eq e
        LEFT JOIN sys_dict_data d on e.eq_type = d.dict_value and d.dict_type = 'project_schedule'
        <where>
            e.is_del = '0'
            <if test="bmProjectId != null "> and e.bm_project_id = #{bmProjectId}</if>
            <if test="isDel != null "> and e.is_del = #{isDel}</if>
            <if test="eqType != null  and eqType != ''"> and e.eq_type = #{eqType}</if>
            <if test="photo != null  and photo != ''"> and e.photo = #{photo}</if>
        </where>
        order by e.create_time DESC
    </select>
    
    <select id="selectBmConstructionEqById" parameterType="Long" resultMap="BmConstructionEqResult">
        SELECT
        e.id,
        e.bm_project_id,
        e.create_by,
        e.create_time,
        e.update_by,
        e.update_time,
        e.is_del,
        e.eq_type,
        e.photo,
        d.dict_label as eqTypeName
        FROM
        bm_construction_eq e
        LEFT JOIN sys_dict_data d on e.eq_type = d.dict_value and d.dict_type = 'project_schedule'
        where e.bm_project_id = #{id}
    </select>
        
    <insert id="insertBmConstructionEq" parameterType="BmConstructionEq" useGeneratedKeys="true" keyProperty="id">
        insert into bm_construction_eq
        <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="eqType != null">eq_type,</if>
            <if test="photo != null">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="eqType != null">#{eqType},</if>
            <if test="photo != null">#{photo},</if>
         </trim>
    </insert>

    <update id="updateBmConstructionEq" parameterType="BmConstructionEq">
        update bm_construction_eq
        <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="eqType != null">eq_type = #{eqType},</if>
            <if test="photo != null">photo = #{photo},</if>
        </trim>
        where id = #{id}
    </update>

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

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

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

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