<?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.dcs.hnyz.mapper.EquipmentExtensionMapper">

    <resultMap type="EquipmentExtension" id="EquipmentExtensionResult">
        <result property="id" column="id"/>
        <result property="equipmentId" column="equipment_id"/>
        <result property="pageId" column="page_id"/>
        <result property="x" column="x"/>
        <result property="y" column="y"/>
        <result property="size" column="size"/>
        <result property="status" column="status"/>
        <result property="height" column="height"/>
        <result property="width" column="width"/>
        <result property="rotate" column="rotate"/>
        <result property="modelId" column="model_id"/>
        <result property="isReverse" column="is_reverse"/>
    </resultMap>

    <sql id="selectEquipmentExtensionVo">
        select id, equipment_id, page_id, x, y, size, height, width, rotate, model_id, is_reverse
        from equipment_extension
    </sql>

    <select id="selectEquipmentExtensionList" parameterType="EquipmentExtension" resultMap="EquipmentExtensionResult">
        <include refid="selectEquipmentExtensionVo"/>
        <where>
            <if test="equipmentId != null ">and equipment_id = #{equipmentId}</if>
            <if test="pageId != null ">and page_id = #{pageId}</if>
        </where>
    </select>

    <select id="selectEquipmentExtensionById" parameterType="Long" resultMap="EquipmentExtensionResult">
        <include refid="selectEquipmentExtensionVo"/>
        where id = #{id}
    </select>

    <select id="getEquipmentExtensionFormList"
            resultType="com.dcs.hnyz.domain.vo.EquipmentExtensionFormVO">
        SELECT
        a.*,
        b.equipment_name,
        c.page_name,
        d.model_name
        FROM
        equipment_extension AS a
        LEFT JOIN equipment AS b ON a.equipment_id = b.equipment_id
        INNER JOIN page_control AS c ON a.page_id = c.page_id
        INNER JOIN model_component AS d ON a.model_id = d.model_id
        <where>
            <if test="pageId != null">
                AND a.page_id = #{pageId}
            </if>
            <if test="equipmentName != null and equipmentName != ''">
                AND b.equipment_name LIKE CONCAT('%', #{equipmentName}, '%')
            </if>
            <if test="status != null  and status != ''">and a.status = #{status}</if>
        </where>
    </select>

</mapper>