<?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.busi.mapper.IecPointsConfMapper">

	<sql id="Base_Column_List1">
		t.id as id,
		t.site_id as siteId,
		s.site_name as siteName,
		t.site_tree_id as siteTreeId,
		tree.name as equipmentName,
		tree.system_code as systemCode,
		t.main_equipment_type as mainEquipmentType,
		t.sub_tree_id as subTreeId,
		gstree.name as subEquipmentName,
		t.sub_equipment_type as subEquipmentType,
		gsensor.id as sensorId,
		t.sensor_code as sensorCode,
		gsensor.sensor_name as sensorName,
		t.gtype as gtype,
		ampltype.ampl_desc as amplDesc,
		t.filed as filed,
		t.filed_desc as filedDesc,
		t.stype as stype,
		t.sadr as sadr,
		t.sno as sno,
		t.isget as isget,
		t.state as state,
		t.unit as unit,
		t.sysunit as sysunit,
		t.devrate as devrate,
		t.warnflag as warnflag,
		t.thresholdfield as thresholdfield,
		t.desct as desct,
		t.d_time as dTime
	</sql>

	<sql id="Base_Column_List2">
		t.id as id,
		t.site_id as siteId,
		s.site_name as siteName,
		t.site_tree_id as siteTreeId,
		tree.name as equipmentName,
		tree.system_code as systemCode,
		t.main_equipment_type as mainEquipmentType,
		t.gtype as gtype,
		t.stype as stype,
		t.sadr as sadr,
		t.sno as sno,
		t.isget as isget,
		t.state as state,
		t.unit as unit,
		t.sysunit as sysunit,
		t.devrate as devrate,
		t.warnflag as warnflag,
		t.thresholdfield as thresholdfield,
		t.desct as desct,
		t.d_time as dTime
	</sql>

	<select id="findIecPointsConfVo" resultType="com.huatek.busi.vo.IecPointsConfVo">
		select
		<include refid="Base_Column_List1"/>
		FROM
		iec_points_conf t
		LEFT JOIN busi_site s ON t.site_id = s.id
		LEFT JOIN busi_site_tree tree ON t.site_tree_id = tree.id
		LEFT JOIN busi_generator_sub_tree gstree ON t.sub_tree_id = gstree.id
		LEFT JOIN busi_generator_sensor gsensor ON t.sensor_id = gsensor.id
		LEFT JOIN busi_generator_ampl_type ampltype ON t.gtype = ampltype.id
		where t.id = #{id}
	</select>

    <select id="selectIecPointsConfPage" parameterType="com.huatek.busi.dto.IecPointsConfDto" resultType="com.huatek.busi.vo.IecPointsConfVo">
        SELECT
        	<include refid="Base_Column_List2"/>
        FROM
        	iec_points_conf t 
        		LEFT JOIN busi_site s ON t.site_id = s.id
  				LEFT JOIN busi_site_tree tree ON t.site_tree_id = tree.id
        <where>
        	and t.state = '1'
	        <if test="stype != null and stype != ''">
	             and t.stype = #{stype}
	        </if>
	        <if test="sadr != null">
	             and t.sadr = #{sadr}
	        </if>
        </where>
        order by t.d_time desc
    </select>
	
	<select id="checksadr" resultType="java.lang.Integer">
		SELECT
		  t.sadr
		FROM iec_points_conf t
		<where>
			AND t.sadr = #{sadr} AND t.state = '1' AND t.site_id = #{siteId}
			<if test="id != null and id != ''">
				AND t.id != #{id}
			</if>
		</where>
	</select>
</mapper>