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

    <resultMap type="TpCaseElevator" id="TpCaseElevatorResult">
        <result property="id" column="id"/>
        <result property="elevatorModelId" column="elevator_model_id"/>
        <result property="relatedCaseId" column="related_case_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="selectTpCaseElevatorVo">
        select id,
               elevator_model_id,
               related_case_id,
               del_flag,
               create_time,
               create_by,
               update_time,
               update_by,
               remark
        from tp_case_elevator
    </sql>

    <resultMap id="TpCaseElevatorDto" type="com.ruoyi.project.business.dto.TpCaseElevatorDto"
               extends="TpCaseElevatorResult">
        <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="TpCaseElevatorDto">
        SELECT tce.*,
               tem.elevator_model,
               ta.area_name,
               ta.area_nameES,
               ta.area_nameRU,
               ta.area_nameUS
        FROM tp_case_elevator tce
                 LEFT JOIN tp_elevator_model tem ON tem.id = tce.elevator_model_id
                 LEFT JOIN tb_area ta ON ta.area_id = tem.area_id
        WHERE related_case_id = #{id}
          and tce.del_flag = '0'
    </select>


    <select id="getCount" parameterType="long" resultType="int">
        SELECT count(*)
        FROM tp_case_elevator
        WHERE elevator_model_id = #{id}
          and del_flag = '0'
    </select>

    <select id="selectCaseCount" parameterType="long" resultType="int">
    select sum(main.num) as num
    from(
        SELECT count(*) as num
        FROM tp_para_related_action dtl
        left join tp_para_library lib on lib.para_code = dtl.para_code and lib.del_flag = 0
        where lib.id = #{paraId} and dtl.del_flag = 0
          union
        SELECT count(*) as num
        FROM tp_para_related_logic dtl
        left join tp_para_library lib on lib.para_code = dtl.para_code and lib.del_flag = 0
        where lib.id = #{paraId} and dtl.del_flag = 0
    ) main
    </select>


</mapper>