<?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.RMasterDataRecordMapper">
    <sql id="Base_Column_List">
        id,
        site_id AS siteId,
        main_equ_id AS mainEquId,
        equ_little_type AS equLittleType,
        equ_little_id AS equLittleId,
        equipment_type AS equipmentType,
        ref_id AS refId,
        test_item AS testItem,
        test_date AS testDate,
        create_user AS createUser,
        create_time AS createTime
    </sql>

    <select id="getRMasterDataRecord" parameterType="com.huatek.busi.entity.RMasterData" resultType="com.huatek.busi.dto.RMasterDataRecordDto">
		SELECT
            <include refid="Base_Column_List"/>
        FROM
            x_r_master_data_record
        WHERE
            site_id = #{siteId}
        AND main_equ_id = #{mainEquId}
        AND equ_little_type = #{equLittleType}
        AND equ_little_id = #{equLittleId}
        AND equipment_type = #{equipmentType}
        ORDER BY
            create_time DESC
        LIMIT 1
  </select>

    <select id="getRBLQDataRecord" parameterType="com.huatek.busi.entity.RMasterData" resultType="com.huatek.busi.dto.RMasterDataRecordDto">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        x_r_arrester_data_record
        WHERE
        site_id = #{siteId}
        AND main_equ_id = #{mainEquId}
        AND equ_little_type = #{equLittleType}
        AND equ_little_id = #{equLittleId}
        AND equipment_type = #{equipmentType}
        ORDER BY
        create_time DESC
        LIMIT 1
    </select>

    <select id="getRKGGDataRecord" parameterType="com.huatek.busi.entity.RMasterData" resultType="com.huatek.busi.dto.RMasterDataRecordDto">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        x_r_switchgear_data_record
        WHERE
        site_id = #{siteId}
        AND main_equ_id = #{mainEquId}
        AND equ_little_type = #{equLittleType}
        AND equ_little_id = #{equLittleId}
        AND equipment_type = #{equipmentType}
        ORDER BY
        create_time DESC
        LIMIT 1
    </select>

    <select id="getRGENDataRecord" parameterType="com.huatek.busi.entity.RMasterData" resultType="com.huatek.busi.dto.RMasterDataRecordDto">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        x_r_generator_data_record
        WHERE
        site_id = #{siteId}
        AND main_equ_id = #{mainEquId}
        AND equ_little_type = #{equLittleType}
        AND equ_little_id = #{equLittleId}
        AND equipment_type = #{equipmentType}
        ORDER BY
        create_time DESC
        LIMIT 1
    </select>

    <select id="getRCableDataRecord" parameterType="com.huatek.busi.entity.RMasterData" resultType="com.huatek.busi.dto.RMasterDataRecordDto">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        x_r_cable_data_record
        WHERE
        site_id = #{siteId}
        AND main_equ_id = #{mainEquId}
        AND equ_little_type = #{equLittleType}
        AND equ_little_id = #{equLittleId}
        AND equipment_type = #{equipmentType}
        ORDER BY
        create_time DESC
        LIMIT 1
    </select>

    <delete id="delete" parameterType="java.lang.String">
        delete from x_r_master_data_record where ref_id = #{refId}
    </delete>

    <delete id="deleteBlq" parameterType="java.lang.String">
        delete from x_r_arrester_data_record where ref_id = #{refId}
    </delete>

    <delete id="deleteDl" parameterType="java.lang.String">
        delete from x_r_cable_data_record where ref_id = #{refId}
    </delete>

    <delete id="deleteKgg" parameterType="java.lang.String">
        delete from x_r_switchgear_data_record where ref_id = #{refId}
    </delete>

    <delete id="deleteGen" parameterType="java.lang.String">
        delete from x_r_generator_data_record where ref_id = #{refId}
    </delete>

    <delete id="deleteBatch">
        delete from x_r_master_data_record where
        ref_id in
        <foreach collection="refIds" index="index" item="refId" open="(" separator="," close=")">
            #{refId}
        </foreach>
    </delete>

    <delete id="deleteBlqBatch">
        delete from x_r_arrester_data_record where
        ref_id in
        <foreach collection="refIds" index="index" item="refId" open="(" separator="," close=")">
            #{refId}
        </foreach>
    </delete>

    <delete id="deleteDlBatch">
        delete from x_r_cable_data_record where
        ref_id in
        <foreach collection="refIds" index="index" item="refId" open="(" separator="," close=")">
            #{refId}
        </foreach>
    </delete>

    <delete id="deleteKggBatch">
        delete from x_r_switchgear_data_record where
        ref_id in
        <foreach collection="refIds" index="index" item="refId" open="(" separator="," close=")">
            #{refId}
        </foreach>
    </delete>

    <delete id="deleteGenBatch">
        delete from x_r_generator_data_record where
        ref_id in
        <foreach collection="refIds" index="index" item="refId" open="(" separator="," close=")">
            #{refId}
        </foreach>
    </delete>
</mapper>
