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

    <sql id="Base_Column_List">
            id as id,
            equipment_id as equipmentId,
            site_id as siteId,
            local_release as localRelease,
            mechanism_check as mechanismCheck,
            leakage_check as leakageCheck,
            press_check as pressCheck,
            temper_check as temperCheck,
            water_check as waterCheck,
            micro_water as microWater,
            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.local_release as localRelease,
           t.mechanism_check as mechanismCheck,
           t.leakage_check as leakageCheck,
           t.press_check as pressCheck,
           t.temper_check as temperCheck,
           t.water_check as waterCheck,
           t.micro_water as microWater,
           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="selectBusiOfflineGisCheckPage" parameterType="com.huatek.busi.dto.BusiOfflineGisCheckDto" 
    resultType="com.huatek.busi.vo.BusiOfflineGisCheckVo">
        SELECT
        	<include refid="Base_Column_List2"/>,
        	bst.name as bstName,
            st.name as stName
       FROM
        	busi_offline_gis_check t
		 LEFT JOIN busi_site_tree bst ON 	t.equipment_id = bst.id
		 LEFT JOIN busi_gis_sub_tree st ON bst.id  = st.equipment_id
        WHERE 
        	t.status = '1'
        <if test="id != null and id != ''">
             and t.id = #{id}
        </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="checkDate != null">
             and t.check_date &gt;= #{checkDate}
        </if>
        <if test="endCheckDate != null">
             and t.check_date &lt; #{endCheckDate}
        </if>
    </select>

	<select id="getBusiOfflineGisCheckVo" parameterType="java.lang.String" resultType="com.huatek.busi.vo.BusiOfflineGisCheckVo">
		SELECT
        	<include refid="Base_Column_List2"/>
        FROM
        	busi_offline_gis_check t, busi_site_tree bst
        WHERE 
        	t.equipment_id = bst.id and t.id = #{id}
	</select>

	<select id="checkExist" resultType="java.lang.String">
		SELECT
		  tree.name
		FROM busi_offline_gis_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>

	<delete id="batchDel">
		 delete from busi_offline_gis_check where id in 
        <foreach item="item" index="index" collection="ids"
		      open="(" separator="," close=")">
		        #{item}
		  </foreach>
	</delete>
</mapper>