<?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.TransformerOfflineExperimentReportMapper">

  <sql id="Base_Column_List">
		id as id,
		transformer_id as transformerId,
		main_tree_id as mainTreeId,
		winding_bushing_dc_resistance as windingBushingDCResistance,
		windingiron_core_Isulation_resistance as WindingIronCoreIsulationResistance,
		winding_bushLoss_tangent as windingBushLossTangent,
		bush_loss_tangent as bushLossTangent,
		winding_bushing_dc_leakage_current as windingBushingDCLeakageCurrent,
		winding_resistance as windingResistance,
		winding_insulation_resistance_and_capacitance_dielectric_loss as windingInsulationResistanceAndCapacitanceDielectricLoss,
		bushing_capacitance_medium_loss as bushingCapacitanceMediumLoss,
		noload_current_and_noload_loss as noloadCurrentAndNoloadLoss,
		low_voltage_noload as lowVoltageNoLoad,
		excitation_characteristict as excitationCharacteristict,
		short_circuit_impedance_load_loss as shortCircuitImpedanceLoadLoss,
		sealing_test as sealingTest,
		sound_level_measurement as soundLevelMeasurement,
		temperature_rise_test as temperatureRiseTest,
		insulation_oilt_test as insulationOilTest,
		furfura_test as cardboardTest,
		cardboard_test as furfuralTest,
		create_name as createName,
		create_user as createUser,
		create_time as createTime,
		modified_name as modifiedName,
		modified_user as modifiedUser,
		modified_time as modifiedTime,
		status as status
    </sql>
    
    
	<select id="getTransformerList" resultType="com.huatek.busi.vo.routinetest.TransformerTestTmpVo">
		SELECT 
		  brand.id,
		  brand.transformer_name AS transformerName 
		FROM
		  `busi_offline_transformer_brand` brand,
		  `busi_site_tree` tree 
		WHERE brand.main_equipment_id = tree.id 
		  AND tree.equipment_type = '111' 
		  AND tree.status = '1' 
		  AND brand.`status` = '1' 
	</select>


	<select id="getTransformerInfo"
		resultType="com.huatek.busi.vo.routinetest.TransformerTestTmpDetailVo">
		SELECT
		t.id,
		t.transformer_name AS transformerName,
		t.main_equipment_id AS
		mainTreeId,
		t.equipment_model AS equipmentModel,
		t.rated_capacity AS
		ratedCapacity,
		t.cooling_node AS coolingNode,
		t.rated_high_current AS
		ratedHighCurrent,
		t.rated_low_current AS ratedLowCurrent,
		t.rated_high_voltage AS ratedHighVoltage,
		t.rated_low_voltage AS
		ratedLowVoltage,
		t.factory_time AS factoryTime,
		t.manufacturer AS
		manufacturer
		FROM
		`busi_offline_transformer_brand` t
		WHERE
		t.id = #{transformerId}
	</select>


	<update id="delete"  parameterType="java.util.List">
		update transformer_offline_experiment_report set status= '2' where id in

		<foreach collection="list" item="id" open="(" close=")"
			separator=",">
			#{id}
		</foreach>
	</update>


	<select id="page"
		resultType="com.huatek.busi.vo.routinetest.TransformerTestPageVo">
		SELECT
		t.id,
		t.transformer_id AS transformerId,
		b.transformer_name AS transformerName,
		b.manufacturer AS manufacturer,
		b.equipment_model AS equipmentModel,
		b.rated_capacity AS ratedCapacity,
		b.factory_time AS factoryTime,
		t.create_name AS createName,
		t.create_time AS createTime,
		t.modified_name AS modifiedName,
		t.modified_time AS modifiedTime,
		st.name AS stName
		FROM
		`transformer_offline_experiment_report` t
		LEFT JOIN busi_offline_transformer_brand b ON t.transformer_id =b.id
        LEFT JOIN busi_site_tree st ON 	t.main_tree_id = st.id
		WHERE
		t.`status` = '1'
		<if test="name != null and name != ''">
			AND st.name like concat('%', #{name}, '%')
		</if>
		<if test="timeStamp != null">
			AND DATE_FORMAT(t.test_time,'%Y-%m-%d')  <![CDATA[>=]]> #{timeStamp}
		</if>
		<if test="timeStampEnd != null">
			AND DATE_FORMAT(t.test_time,'%Y-%m-%d') <![CDATA[<=]]> #{timeStampEnd}

		</if>
		ORDER BY
		t.create_time DESC
	</select>

	<select id="selectByTreeId" resultType="com.huatek.busi.entity.TransformerOfflineExperimentReport">
		SELECT
		 <include refid="Base_Column_List"/>
		FROM
		`transformer_offline_experiment_report` t
		WHERE
		t.main_tree_id = #{mainTreeId}
		ORDER BY
		t.create_time DESC
		limit 1
	</select>
	
	<!-- 根据变压器ID获取 -->
	<select id="findByTransformerId"  parameterType="java.lang.String" resultType="java.lang.Integer">
		SELECT
		 count(*)
		FROM
		`transformer_offline_experiment_report` t
		WHERE
		t.transformer_id = #{mainTreeId}
	</select>
	
	<!-- 根据变压器ID获取 -->
	<select id="getTransformerId" parameterType="java.lang.String" resultType="java.lang.String">
		select 
  			tb.id
		from
		  busi_transformer_sensor  bts
		  left join busi_transformer_sub_tree  st on bts.equipment_id = st.id
		  left join busi_offline_transformer_brand tb on st.equipment_id = tb.main_equipment_id
		  where bts.sensor_code = #{sensorCode}
	</select>
</mapper>