<?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.TpParaValidationElevatorMapper">

    <resultMap type="TpParaValidationElevator" id="TpParaValidationElevatorResult">
        <result property="id" column="id"/>
        <result property="elevatorModelId" column="elevator_model_id"/>
        <result property="paraValidationId" column="para_validation_id"/>
        <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"/>
    </resultMap>

    <sql id="selectTpParaValidationElevatorVo">
        select id,
               elevator_model_id,
               para_validation_id,
               del_flag,
               create_time,
               create_by,
               update_time,
               update_by,
               remark
        from tp_para_validation_elevator
    </sql>

    <select id="selectTpParaValidationElevatorList" parameterType="TpParaValidationElevator"
            resultMap="TpParaValidationElevatorResult">
        <include refid="selectTpParaValidationElevatorVo"/>
        <where>
            <if test="elevatorModelId != null ">and elevator_model_id = #{elevatorModelId}</if>
            <if test="paraValidationId != null ">and para_validation_id = #{paraValidationId}</if>
        </where>
    </select>

    <select id="selectTpParaValidationElevatorById" parameterType="Long" resultMap="TpParaValidationElevatorResult">
        <include refid="selectTpParaValidationElevatorVo"/>
        where id = #{id}
    </select>

    <insert id="insertTpParaValidationElevator" parameterType="TpParaValidationElevator" useGeneratedKeys="true"
            keyProperty="id">
        insert into tp_para_validation_elevator
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="elevatorModelId != null">elevator_model_id,</if>
            <if test="paraValidationId != null">para_validation_id,</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="elevatorModelId != null">#{elevatorModelId},</if>
            <if test="paraValidationId != null">#{paraValidationId},</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="updateTpParaValidationElevator" parameterType="TpParaValidationElevator">
        update tp_para_validation_elevator
        <trim prefix="SET" suffixOverrides=",">
            <if test="elevatorModelId != null">elevator_model_id = #{elevatorModelId},</if>
            <if test="paraValidationId != null">para_validation_id = #{paraValidationId},</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="deleteTpParaValidationElevatorById" parameterType="Long">
        delete
        from tp_para_validation_elevator
        where id = #{id}
    </delete>

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

    <resultMap id="TpParaValidationElevatorDtoResult" extends="TpParaValidationElevatorResult"
               type="com.ruoyi.project.business.dto.TpParaValidationElevatorDto">
        <result property="areaName" column="area_name"/>
        <result property="areaNameUS" column="area_nameUS"/>
        <result property="areaNameES" column="area_nameES"/>
        <result property="areaNameRU" column="area_nameRU"/>
        <result property="elevatorModel" column="elevator_model"/>
    </resultMap>


    <select id="initData" parameterType="long" resultMap="TpParaValidationElevatorDtoResult">
        SELECT tpve.*,
               tem.elevator_model,
               ta.area_name,
               ta.area_nameES,
               ta.area_nameRU,
               ta.area_nameUS
        FROM tp_para_validation_elevator tpve
                 LEFT JOIN tp_elevator_model tem ON tem.id = tpve.elevator_model_id
                 LEFT JOIN tb_area ta ON ta.area_id = tem.area_id
        WHERE para_validation_id = #{id}
          and tpve.del_flag = '0'
    </select>

    <select id="getValidationCount" parameterType="long" resultType="int">
        SELECT count(*)
        FROM tp_para_validation_elevator tpve

        WHERE elevator_model_id = #{id}
          and del_flag = '0'
    </select>
</mapper>