<?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.ArresterOfflineExperimentReportMapper">
  <resultMap id="BaseResultMap" type="com.huatek.busi.vo.ArresterOfflineExperimentReportVo">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="site_id" jdbcType="VARCHAR" property="siteId" />
    <result column="site_eqm_code" jdbcType="VARCHAR" property="siteEqmCode" />
    
    <result column="experiment_date" jdbcType="DATE" property="experimentDate" />
    <result column="ambient_temperature" jdbcType="VARCHAR" property="ambientTemperature" />
    <result column="relative_humidity" jdbcType="VARCHAR" property="relativeHumidity" />
    <result column="arrester_name" jdbcType="VARCHAR" property="arresterName" />
    
    <result column="insulation_resistance" jdbcType="LONGVARCHAR" property="insulationResistance" />
    <result column="dc_reference_voltage" jdbcType="LONGVARCHAR" property="dcReferenceVoltage" />
    <result column="discharge_counting_action" jdbcType="LONGVARCHAR" property="dischargeCountingAction" />
    <result column="conclusion_notes" jdbcType="VARCHAR" property="conclusionNotes" />
    <result column="checker" jdbcType="VARCHAR" property="checker" />
    <result column="experimenter" jdbcType="VARCHAR" property="experimenter" />
    <result column="signature1" jdbcType="VARCHAR" property="signature1" />
    <result column="signature2" jdbcType="VARCHAR" property="signature2" />
    <result column="create_user" jdbcType="VARCHAR" property="createUser" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_name" jdbcType="VARCHAR" property="createName" />
    <result column="modified_user" jdbcType="VARCHAR" property="modifiedUser" />
    <result column="modified_time" jdbcType="TIMESTAMP" property="modifiedTime" />
    <result column="modified_name" jdbcType="VARCHAR" property="modifiedName" />
    <result column="equipmentName" jdbcType="VARCHAR" property="equipmentName"/>
  </resultMap>
 
  <sql id="Base_Column_List">
      t.id,
	  t.site_id,
	  t.site_eqm_code,
	  brand.arrester_name AS arrester_name,
	  t.experiment_date,
	  t.ambient_temperature,
	  t.relative_humidity,
	  t.insulation_resistance,
	  t.dc_reference_voltage,
	  t.discharge_counting_action,
	  t.conclusion_notes,
	  t.checker,
	  t.experimenter,
	  t.signature1,
	  t.signature2,
	  t.create_user,
	  t.create_time,
	  t.modified_user,
	  t.modified_time,
	  st.name AS equipmentName
  </sql>
 
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from arrester_offline_experiment_report
    where id = #{id,jdbcType=VARCHAR}
  </select>
  
  <select id="queryList" parameterType="com.huatek.busi.dto.ArresterOfflineExperimentReportDto" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />,
    (select su.user_name from sys_user su where su.id = t.create_user)as create_name,
	(select su.user_name from sys_user su where su.id = t.modified_user)as modified_name
    from 
    	 arrester_offline_experiment_report t 
	  LEFT JOIN busi_offline_arrester_brand brand            
	    ON t.site_eqm_code = brand.main_equipment_id 
	  LEFT JOIN busi_site_tree st 
    ON t.site_eqm_code = st.id 
    <where>
	    <if test="id != null and id != ''">
	        t.id = #{id}
	    </if>
	    <if test="siteId != null and siteId != ''">
	       and t.site_id = #{siteId}
	    </if>
	    <if test="siteEqmCode != null and siteEqmCode != ''">
	       and t.site_eqm_code = #{siteEqmCode}
	    </if>
	    <if test="conclusionNotes != null and conclusionNotes != ''">
	       and t.conclusion_notes = #{conclusionNotes}
	    </if>  
	    <if test="checker != null and checker != ''">
	       and t.checker = #{checker}
	    </if>
	    <if test="experimenter != null and experimenter != ''">
	       and t.experimenter = #{experimenter}
	    </if>
	    <if test="signature1 != null and signature1 != ''">
	       and t.signature1 = #{signature1}
	    </if>  
	    <if test="signature2 != null and signature2 != ''">
	       and t.signature2 = #{signature2}
	    </if>  
	    <if test="createName != null and createName != ''">
	       and t.create_name = #{createName}
	    </if>  
	    <if test="startDate != null">
	       and DATE_FORMAT(t.create_time,'%Y-%m-%d') &gt;= #{startDate}
	    </if>
	    <if test="endDate != null">
	       and DATE_FORMAT(t.create_time,'%Y-%m-%d') &lt;= #{endDate}
	    </if>
    </where>
    ORDER BY t.experiment_date DESC 
  </select>
  <select id="getByTreeId" resultMap="BaseResultMap">
  	select 
    <include refid="Base_Column_List" />,
    (select su.user_name from sys_user su where su.id = t.create_user)as create_name,
	(select su.user_name from sys_user su where su.id = t.modified_user)as modified_name
    from arrester_offline_experiment_report t ,busi_offline_arrester_brand brand 
    where t.site_eqm_code=brand.main_equipment_id
    order by t.create_time desc, t.modified_time desc
    limit 1
  </select>
</mapper>