<?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.IecBreakerParamMapper">
  <resultMap id="BaseResultMap" type="com.huatek.busi.entity.IecBreakerParam">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Sep 03 09:32:53 CST 2019.
    -->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="site_id" jdbcType="VARCHAR" property="siteId" />
    <result column="eqm_code" jdbcType="VARCHAR" property="eqmCode" />
    <result column="system_code" jdbcType="VARCHAR" property="systemCode" />
    <result column="d_time" jdbcType="TIMESTAMP" property="dTime" />
    <result column="abort_current" jdbcType="VARCHAR" property="abortCurrent" />
    <result column="abort_voltage" jdbcType="VARCHAR" property="abortVoltage" />
    <result column="faild_rate" jdbcType="VARCHAR" property="faildRate" />
    <result column="is_fault" jdbcType="VARCHAR" property="isFault" />
    <result column="is_break" jdbcType="VARCHAR" property="isBreak" />
    <result column="ins_date" jdbcType="TIMESTAMP" property="insDate" />
  </resultMap>
  <sql id="Base_Column_List">
    id, site_id, eqm_code, system_code, d_time, abort_current, abort_voltage, faild_rate, 
    is_fault, is_break, ins_date
  </sql>
  <select id="findIecBreakerParam" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from iec_breaker_param t
    where t.site_id=#{siteId} and  t.eqm_code=#{mainTreeId} and t.is_break='0'
  </select>
  
  <select id="findYxdl" parameterType="java.lang.String" resultType="java.util.Map">
     select  MAX(CONVERT(abort_current,DECIMAL(10.2))) as yxdl
     from iec_breaker_param t
     where t.site_id=#{siteId} and  t.eqm_code=#{eqmCode} 
     <if test="sTime != null">
          and t.d_time &gt;= #{sTime}
     </if>
     <if test="eTime != null ">
          and t.d_time  &lt; #{eTime}
     </if>     
     and t.is_break='1'
  </select>
  
  
   <select id="findIecBreakerParamNow" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from iec_breaker_param t
    where t.site_id=#{siteId} and  t.eqm_code=#{mainTreeId} and t.is_break='0'
	<if test="sTime != null">
		and d_time <![CDATA[>=]]> #{sTime}
	</if>
	<if test="eTime != null">
		and d_time <![CDATA[<]]> #{eTime}
	</if>
	order by ins_date desc;
  </select>
  
  
  <select id="getEvaluateData" resultType="com.huatek.busi.vo.epa.IecBreakerParamEvaluateVo">
		SELECT
			t.faild_rate as  faildRate
		FROM
			`iec_breaker_param` t
		<where>
			<if test="mainTreeId != null  and mainTreeId !='' ">
				t.eqm_code = #{mainTreeId}
			</if>
			<if test="startTime != null">
				and d_time <![CDATA[>=]]> #{startTime}
			</if>
			<if test="endTime != null">
				and d_time <![CDATA[<=]]> #{endTime}
			</if>
		</where>
	</select>
	
	<select id="findIecBreakerParamByDay" parameterType="java.lang.String" resultType="java.util.Map">
		SELECT 
		    iec.`site_id` as siteId,
		    iec.`eqm_code` as eqmCode,
		    COUNT(iec.`is_break`) as  breakCount
		FROM iec_breaker_param iec WHERE iec.`is_break`='0' 
		 <if test="sTime != null">
	          and iec.d_time &gt;= #{sTime}
	     </if>
	     <if test="eTime != null ">
	          and iec.d_time  &lt; #{eTime}
	     </if>
		GROUP BY  iec.`eqm_code`,iec.`site_id` 
	     
  </select>
</mapper>