<?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.huatek.frame.base.mapper.ModelComponentDataMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.huatek.frame.base.entity.ModelComponentData">
        <id column="id" property="id"/>
        <result column="model_id" property="modelId"/>
        <result column="component_id" property="componentId"/>
        <result column="device_code" property="deviceCode"/>
        <result column="main_tree_id" property="mainTreeId"/>
        <result column="sensor_id" property="sensorId"/>
        <result column="install_position" property="installPosition"/>
        <result column="data_items" property="dataItems"/>
        <result column="status" property="status"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="remark" property="remark"/>
        <result column="del_flag" property="delFlag"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="BaseColumnList">
        id, model_id AS modelId, component_id AS componentId, device_code AS deviceCode, main_tree_id AS mainTreeId,
        sensor_id AS sensorId,sensor_name_detail AS sensorNameDetail, install_position AS installPosition, data_items AS dataItems, status,
        create_time AS createTime, update_time AS updateTime, remark, del_flag AS delFlag
    </sql>


    <select id="selectPages" resultType="com.huatek.frame.base.vo.ModelComponentDataVOOriginal">
        select
        d.id, d.model_id AS modelId, d.component_id AS componentId, d.device_code AS deviceCode, d.main_tree_id AS mainTreeId,
        t.name AS mainTreeName, d.sensor_id AS sensorId,d.sensor_name_detail AS sensorNameDetail, d.install_position AS installPosition,
        d.data_items AS dataItems, d.position_x AS positionX, d.position_y AS positionY, d.position_z AS positionZ, d.status,
        d.create_time AS createTime, d.update_time AS updateTime, d.remark, d.del_flag AS delFlag
        from model_component_data d
        left join busi_site_tree t
        on d.main_tree_id = t.id
        where d.del_flag = '0'
        <if test="modelId != null and modelId != ''">
            and d.model_id = #{modelId}
        </if>
        <if test="componentId != null and componentId != ''">
            and d.component_id = #{componentId}
        </if>
        <if test="mainTreeId != null and mainTreeId != ''">
            and d.main_tree_id = #{mainTreeId}
        </if>
        <if test="deviceCode != null and deviceCode != ''">
            and d.device_code = #{deviceCode}
        </if>
        <if test="status != null and status != ''">
            and d.status = #{status}
        </if>
        order by d.create_time desc
    </select>

    <insert id="saveEntity" parameterType="com.huatek.frame.base.entity.ModelComponentData">
        INSERT INTO model_component_data
        (id, model_id, component_id, device_code,
        main_tree_id, sensor_id, install_position,
        data_items, status,
        create_time, update_time, remark, del_flag)
        VALUES
        (#{id}, #{modelId}, #{componentId}, #{deviceCode},
        #{mainTreeId}, #{sensorId},
        #{installPosition}, #{dataItems}, #{status},
        #{createTime}, #{updateTime}, #{remark}, '0');
    </insert>
</mapper>
