<?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="quantity" column="quantity"/>
        <result property="elevatorCode" column="elevator_code"/>
        <result property="sortNumber" column="sort_number"/>
        <result property="offsetX" column="offset_x"/>
        <result property="offsetY" column="offset_y"/>
        <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"/>
        <result property="elevatorType" column="elevator_type"/>
    </resultMap>

    <resultMap type="com.ruoyi.project.business.domain.vo.Civil.TjElevatorVo" id="TjElevatorVOResult"
        extends="TjElevatorResult">
        <result property="areaId" column="area_id"/>
        <result property="elevatorNumber" column="elevator_number"/>
    </resultMap>

    <sql id="selectTjElevatorVo">
        select id,
               civil_engineering_id,
               elevator_model_id,
               quantity,
               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="TjElevatorVOResult">
        select e.*, m.elevator_model, m.elevator_type, m.area_id, e.quantity as elevator_number
        from tj_elevator e
        left join tp_elevator_model m on e.elevator_model_id = m.id
        where e.del_flag = '0'
        <if test="id != null">and e.civil_engineering_id = #{id}</if>
        <if test="elevatorId != null">and e.id = #{elevatorId}</if>

    </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="quantity != null">quantity,</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>
            <if test="offsetX != null">offset_x,</if>
            <if test="offsetY != null">offset_y,</if>
            <if test="sortNumber != null">sort_number,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="civilEngineeringId != null">#{civilEngineeringId},</if>
            <if test="elevatorModelId != null">#{elevatorModelId},</if>
            <if test="quantity != null">#{quantity},</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>
            <if test="offsetX != null">#{offsetX},</if>
            <if test="offsetY != null">#{offsetY},</if>
            <if test="sortNumber != null">#{sortNumber},</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="quantity != null">quantity = #{quantity},</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>