<?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.tofly.scada.mapper.AllocationMapper">

    <resultMap id="BaseResultMap" type="com.tofly.scada.entity.Allocation">
            <id property="id" column="ID" />
            <result property="deviceId" column="DEVICE_ID" />
            <result property="model" column="MODEL" />
            <result property="variableCode" column="VARIABLE_CODE" />
            <result property="variableName" column="VARIABLE_NAME" />
            <result property="displayName" column="DISPLAY_NAME" />
            <result property="unit" column="UNIT" />
            <result property="alarmUpperLimit" column="ALARM_UPPER_LIMIT" />
            <result property="alarmLowerLimit" column="ALARM_LOWER_LIMIT" />
            <result property="isAlarm" column="IS_ALARM" />
            <result property="sortNumber" column="SORT_NUMBER"/>
            <result property="accuracy" column="ACCURACY"/>
            <result property="archivesCode" column="ARCHIVES_CODE" />
            <result property="describe" column="DESCRIBE" />
            <result property="createUser" column="CREATE_USER" />
            <result property="createTime" column="CREATE_TIME"/>
            <result property="type" column="TYPE" />
    </resultMap>

    <sql id="Base_Column_List">
        ID,DEVICE_ID,MODEL,
        VARIABLE_CODE,VARIABLE_NAME,DISPLAY_NAME,
        UNIT,ALARM_UPPER_LIMIT,ALARM_LOWER_LIMIT,
        IS_ALARM,SORT_NUMBER,ACCURACY,
        ARCHIVES_CODE,DESCRIBE,CREATE_USER,
        CREATE_TIME,TYPE
    </sql>

    <select id="getIndexListByType" resultMap="BaseResultMap">
        select *
        from TF_INDEX_ALLOCATION t1
                 inner join tf_device_archive_manage t2
                            on t1.device_id = t2.id
                 inner join tf_water_info t3
                            on t2.water_id = t3.id
        where 1 = 1
        <if test="waterTypes != null">
            and t3.water_type in
            <foreach item="item" index="index" collection="waterTypes" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="indexTypes != null">
            and t1.type in
            <foreach item="item" index="index" collection="indexTypes" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>


        order by t3.id, t1.sort_number



    </select>
</mapper>
