<?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.casic.missiles.modular.system.dao.DeviceRuleMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.casic.missiles.modular.system.model.DeviceRule">
        <id column="ID" property="id"/>
        <result column="DEVCODE" property="devcode"/>
        <result column="HIGHVALUE" property="highvalue"/>
        <result column="LOWVALUE" property="lowvalue"/>
        <result column="OVERTIME" property="overtime"/>
        <result column="SALTATION" property="saltation"/>
        <result column="SENSORCODE" property="sensorcode"/>
        <result column="GRADE" property="grade"/>
        <result column="TS" property="ts"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        ID AS id, DEVCODE AS devcode, HIGHVALUE AS highvalue, LOWVALUE AS lowvalue, OVERTIME AS overtime,
        SALTATION AS saltation, SENSORCODE AS sensorcode, GRADE AS grade, TS AS ts
    </sql>

    <sql id="devCode_sql" databaseId="oracle">
        #{devCode}
    </sql>
    <sql id="devCode_sql" databaseId="mysql">
        CONCAT(#{devCode})
    </sql>
    <sql id="devCode_sql" databaseId="pgsql">
        CONCAT(#{devCode})
    </sql>

    <select id="getSensorCodeByDevCode" resultType="String">
        SELECT b.SENSORCODE AS "SENSORCODE"
        FROM base_sensor b
        LEFT JOIN bus_device d ON b.DEVICE_TYPE=d.DEVICE_TYPE
        WHERE d.VALID = '1'
        <!--<if test="devCode != null and devCode !=''">-->
        and d.DEVCODE =
        <include refid="devCode_sql"/>
        <!--</if>-->
    </select>

</mapper>
