<?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.TransformerEvaluationResultsMapper">
    <resultMap id="BaseResultMap" type="com.huatek.busi.entity.TransformerEvaluationResults">
        <id column="id" jdbcType="VARCHAR" property="id"/>
        <result column="main_tree_id" jdbcType="VARCHAR" property="mainTreeId"/>
        <result column="designed_life" jdbcType="DOUBLE" property="designedLife"/>
        <result column="expect_life" jdbcType="DOUBLE" property="expectlife"/>
        <result column="surplus_life" jdbcType="DOUBLE" property="surplusLife"/>
        <result column="score" jdbcType="DOUBLE" property="score"/>
        <result column="health_index" jdbcType="VARCHAR" property="healthIndex"/>
        <result column="advice" jdbcType="VARCHAR" property="advice"/>
        <result column="future_failure_rate" jdbcType="DOUBLE" property="futureFailureRate"/>
        <result column="aging_rate" jdbcType="DOUBLE" property="agingRate"/>
        <result column="evaluate_date" jdbcType="DATE" property="evaluateDate"/>
        <result column="safety" jdbcType="VARCHAR" property="safety"/>
        <result column="reliability" jdbcType="VARCHAR" property="reliability"/>
        <result column="maintainability" jdbcType="VARCHAR" property="maintainability"/>
        <result column="economic_row" jdbcType="VARCHAR" property="economicRow"/>
        <result column="monitoring_ability" jdbcType="VARCHAR" property="monitoringAbility"/>
        <result column="amplitude" jdbcType="VARCHAR" property="amplitude"/>
    </resultMap>

    <resultMap id="BaseResultMapVo" type="com.huatek.busi.vo.TransformerEvaluationResultsVo">
        <id column="id" jdbcType="VARCHAR" property="id"/>
        <result column="main_tree_id" jdbcType="VARCHAR" property="mainTreeId"/>
        <result column="designed_life" jdbcType="DOUBLE" property="designedLife"/>
        <result column="expect_life" jdbcType="DOUBLE" property="expectlife"/>
        <result column="surplus_life" jdbcType="DOUBLE" property="surplusLife"/>
        <result column="score" jdbcType="DOUBLE" property="score"/>
        <result column="health_index" jdbcType="VARCHAR" property="healthIndex"/>
        <result column="advice" jdbcType="VARCHAR" property="advice"/>
        <result column="future_failure_rate" jdbcType="DOUBLE" property="futureFailureRate"/>
        <result column="aging_rate" jdbcType="DOUBLE" property="agingRate"/>
        <result column="evaluate_date" jdbcType="DATE" property="evaluateDate"/>
        <result column="safety" jdbcType="VARCHAR" property="safety"/>
        <result column="reliability" jdbcType="VARCHAR" property="reliability"/>
        <result column="maintainability" jdbcType="VARCHAR" property="maintainability"/>
        <result column="economic_row" jdbcType="VARCHAR" property="economicRow"/>
        <result column="monitoring_ability" jdbcType="VARCHAR" property="monitoringAbility"/>
        <result column="amplitude" jdbcType="VARCHAR" property="amplitude"/>
    </resultMap>

    <sql id="Base_Column_List">
    id, main_tree_id, designed_life, expect_life, surplus_life, score, health_index,
    advice,cast(future_failure_rate as DECIMAL(10,4)) as future_failure_rate,cast(aging_rate as DECIMAL(10,4))as aging_rate,evaluate_date,
    safety,reliability,maintainability,economic_row,monitoring_ability,amplitude,type
  </sql>

    <select id="page" resultMap="BaseResultMapVo">
        select
        <include refid="Base_Column_List"/>
        from transformer_evaluation_results t
        <where>
            <if test="mainTreeId != null">
                main_tree_id = #{mainTreeId}
            </if>
            <if test="startTime != null">
                and evaluate_date <![CDATA[>=]]> #{startTime}
            </if>
            <if test="endTime != null">
                and evaluate_date <![CDATA[<=]]> #{endTime}
            </if>
            <if test="type != null and type != '' ">
                and type = #{type}
            </if>
        </where>
        order by t.evaluate_date desc
    </select>

    <select id="findLatestResult" resultMap="BaseResultMapVo">
        select
        <include refid="Base_Column_List"/>
        from transformer_evaluation_results t
        <where>
            type = '1'
            <if test="mainTreeId != null">
                and main_tree_id = #{mainTreeId}
            </if>
        </where>
        order by t.evaluate_date desc
        LIMIT 1
    </select>

</mapper>
