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

    <sql id="Base_Column_List">
            id as id,
            equipment_id as equipmentId,
            site_id as siteId,
            absolute_resistance as absoluteResistance,
            dc_resistance as dcResistance,
            switch_voltage as switchVoltage,
            leak_test as leakTest,
            deformation_test as deformationTest,
            discharge_test as dischargeTest,
            insulating_oil as insulatingOil,
            appearance_test as appearanceTest,
            insulation_test as insulationTest,
            function_check as functionCheck,
            association_check as associationCheck,
            pressure_check as pressureCheck,
            fasten_check as fastenCheck,
            grid_check as gridCheck,
            cool_check as coolCheck,
            vacuum_check as vacuumCheck,
            basic_check as basicCheck,
            check_date as checkDate,
            create_user as createUser,
            create_time as createTime,
            create_name as createName,
            status as status
    </sql>

	<sql id="Base_Column_List2">
		t.id as id,
		t.equipment_id as equipmentId,
		bst.name as equipmentName,
		t.site_id as siteId,
		t.absolute_resistance as absoluteResistance,
		t.dc_resistance as dcResistance,
		t.switch_voltage as switchVoltage,
		t.leak_test as leakTest,
		t.deformation_test as deformationTest,
		t.discharge_test as dischargeTest,
		t.insulating_oil as insulatingOil,
		t.appearance_test as appearanceTest,
		t.insulation_test as insulationTest,
		t.function_check as functionCheck,
		t.association_check as associationCheck,
		t.pressure_check as pressureCheck,
		t.fasten_check as fastenCheck,
		t.grid_check as gridCheck,
		t.cool_check as coolCheck,
		t.vacuum_check as vacuumCheck,
		t.basic_check as basicCheck,
		t.check_date as checkDate,
		t.create_user as createUser,
		t.create_time as createTime,
		t.create_name as createName,
		t.status as status
	</sql>

    <select id="selectBusiOfflineTransformerCheckPage" parameterType="com.huatek.busi.dto.BusiOfflineTransformerCheckDto" resultType="com.huatek.busi.vo.BusiOfflineTransformerCheckVo">
        SELECT
        		t.id as id,
				t.equipment_id as equipmentId,
				bst.name as equipmentName,
				t.site_id as siteId,
				t.absolute_resistance as absoluteResistance,
				t.dc_resistance as dcResistance,
				t.switch_voltage as switchVoltage,
				t.leak_test as leakTest,
				t.deformation_test as deformationTest,
				t.discharge_test as dischargeTest,
				t.insulating_oil as insulatingOil,
				t.appearance_test as appearanceTest,
				t.insulation_test as insulationTest,
				t.function_check as functionCheck,
				t.association_check as associationCheck,
				t.pressure_check as pressureCheck,
				t.fasten_check as fastenCheck,
				t.grid_check as gridCheck,
				t.cool_check as coolCheck,
				t.vacuum_check as vacuumCheck,
				t.basic_check as basicCheck,
				t.check_date as checkDate,
				t.create_user as createUser,
				t.create_time as createTime,
				t.create_name as createName,
				t.status as status,
				bst.name AS bstName,
				st.name AS stName 
        FROM 
        	busi_offline_transformer_check t 
			LEFT JOIN busi_site_tree bst ON 	t.equipment_id = bst.id
			LEFT JOIN busi_transformer_sub_tree st ON t.equipment_id = st.equipment_id
        WHERE 
        	t.status = '1'
        <if test="bstName != null and bstName != ''">
             AND bst.name like concat('%', #{bstName}, '%')
        </if>
        <if test="equipmentId != null and equipmentId != ''">
             and t.equipment_id = #{equipmentId}
        </if>
        <if test="siteId != null and siteId != ''">
             and t.site_id = #{siteId}
        </if>
        <if test="startCheckDate != null">
             AND DATE_FORMAT(t.check_date,'%Y-%m-%d') <![CDATA[>= ]]> DATE_FORMAT(#{startCheckDate},'%Y-%m-%d')
        </if>
        <if test="endCheckDate != null">
             AND DATE_FORMAT(t.check_date,'%Y-%m-%d') <![CDATA[<= ]]> DATE_FORMAT(#{endCheckDate},'%Y-%m-%d')
        </if>
        order by t.create_time desc
    </select>

	<select id="getBusiOfflineTransformerCheckVo" parameterType="java.lang.String" resultType="com.huatek.busi.vo.BusiOfflineTransformerCheckVo">
		SELECT
        	<include refid="Base_Column_List2"/>
        FROM
        	busi_offline_transformer_check t, busi_site_tree bst
        WHERE 
        	t.equipment_id = bst.id and t.id = #{id}
	</select>
	<delete id="batchDel">
		 delete from busi_offline_transformer_check where id in 
        <foreach item="item" index="index" collection="ids"
		      open="(" separator="," close=")">
		        #{item}
		  </foreach>
	</delete>
	
	<select id="checkExist" resultType="java.lang.String">
		SELECT
		  tree.name
		FROM busi_offline_transformer_check t,
		     busi_site_tree tree
		WHERE t.equipment_id = tree.id
		AND t.equipment_id = #{equipmentId}
		<if test="id != null and id != ''">
			AND t.id != #{id}
		</if>
		LIMIT 1
	</select>
</mapper>