<?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.gyee.frame.mapper.auto.Alertrule2Mapper">
  <resultMap id="BaseResultMap" type="com.gyee.frame.model.auto.Alertrule2">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="ID" jdbcType="VARCHAR" property="id" />
    <result column="NAME" jdbcType="VARCHAR" property="name" />
    <result column="DESCRIPTION" jdbcType="VARCHAR" property="description" />
    <result column="EXPRESSION" jdbcType="VARCHAR" property="expression" />
    <result column="TAG" jdbcType="VARCHAR" property="tag" />
    <result column="RANK" jdbcType="VARCHAR" property="rank" />
    <result column="ENABLED" jdbcType="DECIMAL" property="enabled" />
    <result column="MODELID" jdbcType="VARCHAR" property="modelid" />
    <result column="EDNAVALUE" jdbcType="DECIMAL" property="ednavalue" />
    <result column="CATEGORY" jdbcType="VARCHAR" property="category" />
    <result column="RANGE" jdbcType="VARCHAR" property="range" />
    <result column="STATION" jdbcType="VARCHAR" property="station" />
    <result column="WINDTURBINE" jdbcType="VARCHAR" property="windturbine" />
    <result column="LINE" jdbcType="VARCHAR" property="line" />
    <result column="PROJECT" jdbcType="VARCHAR" property="project" />
    <result column="ELECTRICAL" jdbcType="VARCHAR" property="electrical" />
    <result column="TASKSTART" jdbcType="VARCHAR" property="taskstart" />
    <result column="RELATEDPARTS" jdbcType="VARCHAR" property="relatedparts" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    ID, NAME, DESCRIPTION, EXPRESSION, TAG, RANK, ENABLED, MODELID, EDNAVALUE, CATEGORY,
    RANGE, STATION, WINDTURBINE, LINE, PROJECT, ELECTRICAL, TASKSTART, RELATEDPARTS
  </sql>
  <select id="selectByExample" parameterType="com.gyee.frame.model.auto.Alertrule2Example" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from ALERTRULE2
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select 
    <include refid="Base_Column_List" />
    from ALERTRULE2
    where ID = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from ALERTRULE2
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.gyee.frame.model.auto.Alertrule2Example">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from ALERTRULE2
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.gyee.frame.model.auto.Alertrule2">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into ALERTRULE2 (ID, NAME, DESCRIPTION, 
      EXPRESSION, TAG, RANK, 
      ENABLED, MODELID, EDNAVALUE, 
      CATEGORY, RANGE, STATION,
      WINDTURBINE, LINE, PROJECT, 
      ELECTRICAL, TASKSTART, RELATEDPARTS
      )
    values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, 
      #{expression,jdbcType=VARCHAR}, #{tag,jdbcType=VARCHAR}, #{rank,jdbcType=VARCHAR}, 
      #{enabled,jdbcType=DECIMAL}, #{modelid,jdbcType=VARCHAR}, #{ednavalue,jdbcType=DECIMAL}, 
      #{category,jdbcType=VARCHAR}, #{range,jdbcType=VARCHAR}, #{station,jdbcType=VARCHAR}, 
      #{windturbine,jdbcType=VARCHAR}, #{line,jdbcType=VARCHAR}, #{project,jdbcType=VARCHAR}, 
      #{electrical,jdbcType=VARCHAR}, #{taskstart,jdbcType=VARCHAR}, #{relatedparts,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.gyee.frame.model.auto.Alertrule2">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into ALERTRULE2
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="name != null">
        NAME,
      </if>
      <if test="description != null">
        DESCRIPTION,
      </if>
      <if test="expression != null">
        EXPRESSION,
      </if>
      <if test="tag != null">
        TAG,
      </if>
      <if test="rank != null">
        RANK,
      </if>
      <if test="enabled != null">
        ENABLED,
      </if>
      <if test="modelid != null">
        MODELID,
      </if>
      <if test="ednavalue != null">
        EDNAVALUE,
      </if>
      <if test="category != null">
        CATEGORY,
      </if>
      <if test="range != null">
        RANGE,
      </if>
      <if test="station != null">
        STATION,
      </if>
      <if test="windturbine != null">
        WINDTURBINE,
      </if>
      <if test="line != null">
        LINE,
      </if>
      <if test="project != null">
        PROJECT,
      </if>
      <if test="electrical != null">
        ELECTRICAL,
      </if>
      <if test="taskstart != null">
        TASKSTART,
      </if>
      <if test="relatedparts != null">
        RELATEDPARTS,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
        #{description,jdbcType=VARCHAR},
      </if>
      <if test="expression != null">
        #{expression,jdbcType=VARCHAR},
      </if>
      <if test="tag != null">
        #{tag,jdbcType=VARCHAR},
      </if>
      <if test="rank != null">
        #{rank,jdbcType=VARCHAR},
      </if>
      <if test="enabled != null">
        #{enabled,jdbcType=DECIMAL},
      </if>
      <if test="modelid != null">
        #{modelid,jdbcType=VARCHAR},
      </if>
      <if test="ednavalue != null">
        #{ednavalue,jdbcType=DECIMAL},
      </if>
      <if test="category != null">
        #{category,jdbcType=VARCHAR},
      </if>
      <if test="range != null">
        #{range,jdbcType=VARCHAR},
      </if>
      <if test="station != null">
        #{station,jdbcType=VARCHAR},
      </if>
      <if test="windturbine != null">
        #{windturbine,jdbcType=VARCHAR},
      </if>
      <if test="line != null">
        #{line,jdbcType=VARCHAR},
      </if>
      <if test="project != null">
        #{project,jdbcType=VARCHAR},
      </if>
      <if test="electrical != null">
        #{electrical,jdbcType=VARCHAR},
      </if>
      <if test="taskstart != null">
        #{taskstart,jdbcType=VARCHAR},
      </if>
      <if test="relatedparts != null">
        #{relatedparts,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.gyee.frame.model.auto.Alertrule2Example" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select count(*) from ALERTRULE2
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update ALERTRULE2
    <set>
      <if test="record.id != null">
        ID = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.name != null">
        NAME = #{record.name,jdbcType=VARCHAR},
      </if>
      <if test="record.description != null">
        DESCRIPTION = #{record.description,jdbcType=VARCHAR},
      </if>
      <if test="record.expression != null">
        EXPRESSION = #{record.expression,jdbcType=VARCHAR},
      </if>
      <if test="record.tag != null">
        TAG = #{record.tag,jdbcType=VARCHAR},
      </if>
      <if test="record.rank != null">
        RANK = #{record.rank,jdbcType=VARCHAR},
      </if>
      <if test="record.enabled != null">
        ENABLED = #{record.enabled,jdbcType=DECIMAL},
      </if>
      <if test="record.modelid != null">
        MODELID = #{record.modelid,jdbcType=VARCHAR},
      </if>
      <if test="record.ednavalue != null">
        EDNAVALUE = #{record.ednavalue,jdbcType=DECIMAL},
      </if>
      <if test="record.category != null">
        CATEGORY = #{record.category,jdbcType=VARCHAR},
      </if>
      <if test="record.range != null">
        RANGE = #{record.range,jdbcType=VARCHAR},
      </if>
      <if test="record.station != null">
        STATION = #{record.station,jdbcType=VARCHAR},
      </if>
      <if test="record.windturbine != null">
        WINDTURBINE = #{record.windturbine,jdbcType=VARCHAR},
      </if>
      <if test="record.line != null">
        LINE = #{record.line,jdbcType=VARCHAR},
      </if>
      <if test="record.project != null">
        PROJECT = #{record.project,jdbcType=VARCHAR},
      </if>
      <if test="record.electrical != null">
        ELECTRICAL = #{record.electrical,jdbcType=VARCHAR},
      </if>
      <if test="record.taskstart != null">
        TASKSTART = #{record.taskstart,jdbcType=VARCHAR},
      </if>
      <if test="record.relatedparts != null">
        RELATEDPARTS = #{record.relatedparts,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update ALERTRULE2
    set ID = #{record.id,jdbcType=VARCHAR},
      NAME = #{record.name,jdbcType=VARCHAR},
      DESCRIPTION = #{record.description,jdbcType=VARCHAR},
      EXPRESSION = #{record.expression,jdbcType=VARCHAR},
      TAG = #{record.tag,jdbcType=VARCHAR},
      RANK = #{record.rank,jdbcType=VARCHAR},
      ENABLED = #{record.enabled,jdbcType=DECIMAL},
      MODELID = #{record.modelid,jdbcType=VARCHAR},
      EDNAVALUE = #{record.ednavalue,jdbcType=DECIMAL},
      CATEGORY = #{record.category,jdbcType=VARCHAR},
    RANGE = #{record.range,jdbcType=VARCHAR},
      STATION = #{record.station,jdbcType=VARCHAR},
      WINDTURBINE = #{record.windturbine,jdbcType=VARCHAR},
      LINE = #{record.line,jdbcType=VARCHAR},
      PROJECT = #{record.project,jdbcType=VARCHAR},
      ELECTRICAL = #{record.electrical,jdbcType=VARCHAR},
      TASKSTART = #{record.taskstart,jdbcType=VARCHAR},
      RELATEDPARTS = #{record.relatedparts,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.gyee.frame.model.auto.Alertrule2">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update ALERTRULE2
    <set>
      <if test="name != null">
        NAME = #{name,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
        DESCRIPTION = #{description,jdbcType=VARCHAR},
      </if>
      <if test="expression != null">
        EXPRESSION = #{expression,jdbcType=VARCHAR},
      </if>
      <if test="tag != null">
        TAG = #{tag,jdbcType=VARCHAR},
      </if>
      <if test="rank != null">
        RANK = #{rank,jdbcType=VARCHAR},
      </if>
      <if test="enabled != null">
        ENABLED = #{enabled,jdbcType=DECIMAL},
      </if>
      <if test="modelid != null">
        MODELID = #{modelid,jdbcType=VARCHAR},
      </if>
      <if test="ednavalue != null">
        EDNAVALUE = #{ednavalue,jdbcType=DECIMAL},
      </if>
      <if test="category != null">
        CATEGORY = #{category,jdbcType=VARCHAR},
      </if>
      <if test="range != null">
        RANGE = #{range,jdbcType=VARCHAR},
      </if>
      <if test="station != null">
        STATION = #{station,jdbcType=VARCHAR},
      </if>
      <if test="windturbine != null">
        WINDTURBINE = #{windturbine,jdbcType=VARCHAR},
      </if>
      <if test="line != null">
        LINE = #{line,jdbcType=VARCHAR},
      </if>
      <if test="project != null">
        PROJECT = #{project,jdbcType=VARCHAR},
      </if>
      <if test="electrical != null">
        ELECTRICAL = #{electrical,jdbcType=VARCHAR},
      </if>
      <if test="taskstart != null">
        TASKSTART = #{taskstart,jdbcType=VARCHAR},
      </if>
      <if test="relatedparts != null">
        RELATEDPARTS = #{relatedparts,jdbcType=VARCHAR},
      </if>
    </set>
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.gyee.frame.model.auto.Alertrule2">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update ALERTRULE2
    set NAME = #{name,jdbcType=VARCHAR},
      DESCRIPTION = #{description,jdbcType=VARCHAR},
      EXPRESSION = #{expression,jdbcType=VARCHAR},
      TAG = #{tag,jdbcType=VARCHAR},
      RANK = #{rank,jdbcType=VARCHAR},
      ENABLED = #{enabled,jdbcType=DECIMAL},
      MODELID = #{modelid,jdbcType=VARCHAR},
      EDNAVALUE = #{ednavalue,jdbcType=DECIMAL},
      CATEGORY = #{category,jdbcType=VARCHAR},
    RANGE = #{range,jdbcType=VARCHAR},
      STATION = #{station,jdbcType=VARCHAR},
      WINDTURBINE = #{windturbine,jdbcType=VARCHAR},
      LINE = #{line,jdbcType=VARCHAR},
      PROJECT = #{project,jdbcType=VARCHAR},
      ELECTRICAL = #{electrical,jdbcType=VARCHAR},
      TASKSTART = #{taskstart,jdbcType=VARCHAR},
      RELATEDPARTS = #{relatedparts,jdbcType=VARCHAR}
    where ID = #{id,jdbcType=VARCHAR}
  </update>

  <select id="getAlarmTotal"  resultType="com.gyee.frame.model.custom.AlarmTotalVo">
    select s.stationid wpId, s.windturbineid wtId, s.alerttext name from ( select snapid, sum(count) as count,sum(time) time from alarmcount
    a left join alarmsnap ss on a.snapid = ss.id
    where
     ss.windturbineid='${wtId}'
    and ss.windturbineid is not null
    and
     alarmdate >= to_date('${beginDate}','YYYY-MM-DD HH24:MI:SS')
    and alarmdate &lt; to_date('${endDate}','YYYY-MM-DD HH24:MI:SS')
    group by snapid ) t left join alarmsnap s
     on t.snapid = s.id order by  t.count desc

  </select>

  <select id="getAlarmTypenum"  resultType="com.gyee.frame.model.custom.SimpleVo">
     select count(*) value,w.name name from alertrule2 t,windturbine_parts w where t.relatedparts=w.id group by w.name
  </select>

</mapper>