<?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.GisOfflineExperimentReportMapper">
	<sql id="Base_Column_List">
		id as id,
        site_id as siteId,
        gis_id as gisId,
        low_voltage_action_part as lowVoltageActionPart,
        dc_resistor_part as dcResistorPart,
        action_feature_part as actionFeaturePart,
        sf6_relay_accuracy_part as sf6RelayAccuracyPart,
        sf6_gas_water_content_part as sf6GasWaterContentPart,
        created_time as createdTime,
        modified_time as modifiedTime,
        creator as creator,
        modifier as modifier
	</sql>
	<sql id="Base_Column_List_simple">
		t.id as id,
		t.site_id as siteId,
		t.gis_id as gisId,
		t.created_time as createdTime,
		t.modified_time as modifiedTime,
		(select su.user_name from sys_user su where su.id = t.creator)as creator,
		(select su.user_name from sys_user su where su.id = t.modifier)as modifier
	</sql>
	<select id="findGisOfflineExperimentReportList"
		parameterType="com.huatek.busi.dto.GisOfflineExperimentReportDto"
		resultType="com.huatek.busi.vo.routinetest.gis.GisOfflineExperimentReportVo">
		select 
			<include refid="Base_Column_List_simple"/>,
			brand.gis_name AS gisName,
			<!-- tree.system_code as systemCode, -->
			st.name AS stName 
		from 
			gis_offline_experiment_report t
			LEFT JOIN busi_offline_gis_brand brand ON t.gis_id = brand.main_equipment_id 
	  		LEFT JOIN busi_site_tree st  ON t.gis_id = st.id 
		<where>
			<if test="gisName != null and gisName != ''">
				and st.name like concat('%', #{gisName}, '%')
			</if>
			<if test="checkDate != null">
				AND DATE_FORMAT(t.created_time,'%Y-%m-%d')  <![CDATA[>=]]> #{checkDate}
			</if>
			<if test="endCheckDate != null">
				AND DATE_FORMAT(t.created_time,'%Y-%m-%d') <![CDATA[<=]]> #{endCheckDate}
	
			</if>
		</where>
		order by t.created_time desc
	</select>
	<select id="getByTreeId" resultType="com.huatek.busi.entity.GisOfflineExperimentReport">
		select 
			<include refid="Base_Column_List"/>
		from 
			gis_offline_experiment_report t
		where t.gis_id = #{mainTreeId}
		order by t.created_time desc, t.modified_time desc
		limit 1
	</select>
</mapper>