<?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.project.business.mapper.TjElevatorMapper">
    
    <resultMap type="TjElevator" id="TjElevatorResult">
        <result property="id"    column="id"    />
        <result property="civilEngineeringId"    column="civil_engineering_id"    />
        <result property="elevatorModelId"    column="elevator_model_id"    />
        <result property="elevatorCode"    column="elevator_code"    />
        <result property="addType"    column="add_type"    />
        <result property="quotationId"    column="quotation_id"    />
        <result property="specification"    column="specification"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
        <result property="elevatorModel" column="elevator_model" />
    </resultMap>

    <sql id="selectTjElevatorVo">
        select id, civil_engineering_id, elevator_model_id, elevator_code, add_type, quotation_id, specification, del_flag, create_time, create_by, update_time, update_by, remark from tj_elevator
    </sql>

    <select id="selectTjElevatorList" parameterType="TjElevator" resultMap="TjElevatorResult">
        <include refid="selectTjElevatorVo"/>
        <where>  
            <if test="civilEngineeringId != null "> and civil_engineering_id = #{civilEngineeringId}</if>
            <if test="elevatorModelId != null "> and elevator_model_id = #{elevatorModelId}</if>
            <if test="elevatorCode != null  and elevatorCode != ''"> and elevator_code = #{elevatorCode}</if>
            <if test="addType != null  and addType != ''"> and add_type = #{addType}</if>
            <if test="quotationId != null "> and quotation_id = #{quotationId}</if>
            <if test="specification != null  and specification != ''"> and specification = #{specification}</if>
        </where>
    </select>
    
    <select id="selectTjElevatorById" parameterType="Long" resultMap="TjElevatorResult">
        <include refid="selectTjElevatorVo"/>
        where id = #{id}
    </select>

    <select id="selectElevatorListByCivilEngineeringId" resultMap="TjElevatorResult">
        select e.*, m.elevator_model from tj_elevator e
        left join tp_elevator_model m on e.elevator_model_id = m.id
        where e.civil_engineering_id = #{id}
        and e.del_flag = '0'
    </select>

    <insert id="insertTjElevator" parameterType="TjElevator" useGeneratedKeys="true" keyProperty="id">
        insert into tj_elevator
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="civilEngineeringId != null">civil_engineering_id,</if>
            <if test="elevatorModelId != null">elevator_model_id,</if>
            <if test="elevatorCode != null">elevator_code,</if>
            <if test="addType != null">add_type,</if>
            <if test="quotationId != null">quotation_id,</if>
            <if test="specification != null">specification,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="civilEngineeringId != null">#{civilEngineeringId},</if>
            <if test="elevatorModelId != null">#{elevatorModelId},</if>
            <if test="elevatorCode != null">#{elevatorCode},</if>
            <if test="addType != null">#{addType},</if>
            <if test="quotationId != null">#{quotationId},</if>
            <if test="specification != null">#{specification},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTjElevator" parameterType="TjElevator">
        update tj_elevator
        <trim prefix="SET" suffixOverrides=",">
            <if test="civilEngineeringId != null">civil_engineering_id = #{civilEngineeringId},</if>
            <if test="elevatorModelId != null">elevator_model_id = #{elevatorModelId},</if>
            <if test="elevatorCode != null">elevator_code = #{elevatorCode},</if>
            <if test="addType != null">add_type = #{addType},</if>
            <if test="quotationId != null">quotation_id = #{quotationId},</if>
            <if test="specification != null">specification = #{specification},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTjElevatorById" parameterType="Long">
        delete from tj_elevator where id = #{id}
    </delete>

    <delete id="deleteTjElevatorByIds" parameterType="String">
        delete from tj_elevator where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>