<?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.LabReportParamDataMapper">
    <sql id="Base_Column_List">
        id,
        ref_id as refId,
        r_id AS rId,
        test_interval AS testInterval,
        test_type AS testType,
        offline_param AS offlineParam,
        valid_value_range AS validValueRange,
        current_value AS currentValue,
        unit,
        is_mark AS isMark,
        e_param AS eParam,
        test_result AS testResult,
        remark,
        create_user AS createUser,
        create_time AS createTime,
        update_user AS updateUser,
        update_time AS updateTime,
        deleted
    </sql>

    <select id="findList" parameterType="java.util.Map" resultType="com.huatek.busi.dto.LabReportParamDataDtos">
        SELECT
            B.site_id AS siteId,
            B.main_equ_id AS mainEquId,
            B.main_equ_name AS mainEquName,
            B.equ_little_type AS equLittleType,
            B.equipment_type AS eqType,
            A.id,
            A.m_id AS mId,
            A.test_item AS testItem,
            A.test_equ AS testEqu,
            A.checker,
            A.test_date AS testDate,
            A.maintenance_unit AS maintenanceUnit,
            A.test_staff AS testStaff,
            A.test_conclusion AS testConclusion,
            A.ref_id as refId,
            C.r_id AS rId,
            C.test_interval AS testInterval,
            C.test_type AS testType,
            C.offline_param AS offlineParam,
            C.valid_value_range AS validValueRange,
            C.current_value AS currentValue,
            C.unit,
            C.is_mark AS isMark,
            C.e_param AS eParam,
            C.test_result AS testResult,
            C.remark
        FROM
            x_lab_report_basis_data A
        LEFT JOIN x_r_master_data B ON A.m_id = B.id
        LEFT JOIN x_lab_report_param_data C ON A.id = C.r_id
        WHERE
            A.deleted = 0
        AND B.deleted = 0
        AND C.deleted = 0
        AND B.site_id = #{siteId}
        AND B.main_equ_id = #{mainEquId}
        AND B.equ_little_type = #{equLittleType}
        AND B.equ_little_id = #{equLittleId}
        AND B.equipment_type = #{eqType}
        AND A.test_item in
        <foreach collection="testItem" index="index" item="tItem" separator="," open="(" close=")">
            #{tItem, jdbcType=VARCHAR}
        </foreach>
        AND A.test_date in
        <foreach collection="testDate" index="index" item="tDate" separator="," open="(" close=")">
            #{tDate, jdbcType=VARCHAR}
        </foreach>
    </select>

    <update id="delete" parameterType="java.lang.String">
        UPDATE x_lab_report_param_data
        SET deleted = 1
        WHERE
            ref_id = #{refId}
    </update>

    <update id="deleteBlq" parameterType="java.lang.String">
        UPDATE x_lab_arrester_report_param_data
        SET deleted = 1
        WHERE
            ref_id = #{refId}
    </update>

    <update id="deleteDl" parameterType="java.lang.String">
        UPDATE x_lab_cable_report_param_data
        SET deleted = 1
        WHERE
            ref_id = #{refId}
    </update>

    <update id="deleteKgg" parameterType="java.lang.String">
        UPDATE x_lab_switchgear_report_param_data
        SET deleted = 1
        WHERE
            ref_id = #{refId}
    </update>

    <update id="deleteGen" parameterType="java.lang.String">
        UPDATE x_lab_generator_report_param_data
        SET deleted = 1
        WHERE
            ref_id = #{refId}
    </update>

    <select id="findAll" parameterType="com.huatek.busi.where.LabReportParamDataSelectVo" resultType="com.huatek.busi.dto.LabReportParamDataDto">
        SELECT
            <include refid="Base_Column_List"/>
        FROM
            x_lab_report_param_data
        WHERE
            r_id = #{id}
        AND ref_id = #{refId}
        AND deleted = #{deleted}
        AND is_mark = #{isMark}
        ORDER BY e_param DESC
    </select>

    <select id="findBlqAll" parameterType="com.huatek.busi.where.LabReportParamDataSelectVo" resultType="com.huatek.busi.dto.LabReportParamDataDto">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        x_lab_arrester_report_param_data
        WHERE
        r_id = #{id}
        AND ref_id = #{refId}
        AND deleted = #{deleted}
        AND is_mark = #{isMark}
        ORDER BY e_param DESC
    </select>

    <select id="findDlAll" parameterType="com.huatek.busi.where.LabReportParamDataSelectVo" resultType="com.huatek.busi.dto.LabReportParamDataDto">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        x_lab_cable_report_param_data
        WHERE
        r_id = #{id}
        AND ref_id = #{refId}
        AND deleted = #{deleted}
        AND is_mark = #{isMark}
        ORDER BY e_param DESC
    </select>

    <select id="findKggAll" parameterType="com.huatek.busi.where.LabReportParamDataSelectVo" resultType="com.huatek.busi.dto.LabReportParamDataDto">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        x_lab_switchgear_report_param_data
        WHERE
        r_id = #{id}
        AND ref_id = #{refId}
        AND deleted = #{deleted}
        AND is_mark = #{isMark}
        ORDER BY e_param DESC
    </select>

    <select id="findGenAll" parameterType="com.huatek.busi.where.LabReportParamDataSelectVo" resultType="com.huatek.busi.dto.LabReportParamDataDto">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        x_lab_generator_report_param_data
        WHERE
        r_id = #{id}
        AND ref_id = #{refId}
        AND deleted = #{deleted}
        AND is_mark = #{isMark}
        ORDER BY e_param DESC
    </select>

    <select id="statistics" parameterType="com.huatek.busi.where.LabReportBasisDataStatisticsWhereVo" resultType="com.huatek.busi.dto.LabReportBasisDataStatisticsDto">
        SELECT
            A.ref_id AS refId,
            A.test_interval AS testInterval,
            A.offline_param AS offlineParam,
            A.current_value AS currentValue,
            D.dcode AS dCode,
            D.dname AS dname,
            C.file_name AS fileName
        FROM
            x_lab_report_param_data A
        LEFT JOIN x_lab_report_basis_data B ON A.r_id = B.id
        LEFT JOIN x_r_master_data F ON B.m_id = F.id
        LEFT JOIN sys_file C ON A.ref_id = C.business_id
        LEFT JOIN sys_dictionnaire_detail D ON A.unit = D.dcode
        LEFT JOIN sys_dictionnaire E ON D.pid = E.id
        WHERE
            A.deleted = #{deleted}
        AND B.deleted = #{deleted}
        AND C.deleted = #{deleted}
        AND D.deleted = #{deleted}
        AND E.deleted = #{deleted}
        AND F.deleted = #{deleted}
        AND A.offline_param = #{offlineParam}
        AND B.test_item LIKE CONCAT(
            '%',
            #{testItem},
            '%'
        )
        AND c.file_type = #{fileType}
        AND F.equipment_type = #{equipmentType}
        AND E.`code` = 'IEC_O_UNIT'
        <if test="refId != null and refId != ''">
            AND A.ref_id = #{refId}
        </if>
    </select>

    <update id="updateByRefIds" parameterType="java.util.List">
        UPDATE x_lab_report_param_data
        SET deleted = 1
        WHERE
            ref_id in
        <foreach collection="refIds" index="index" item="refId" separator="," open="(" close=")">
            #{refId, jdbcType=VARCHAR}
        </foreach>
    </update>

    <update id="updateBlqByRefIds" parameterType="java.util.List">
        UPDATE x_lab_arrester_report_param_data
        SET deleted = 1
        WHERE
        ref_id in
        <foreach collection="refIds" index="index" item="refId" separator="," open="(" close=")">
            #{refId, jdbcType=VARCHAR}
        </foreach>
    </update>

    <update id="updateDlByRefIds" parameterType="java.util.List">
        UPDATE x_lab_cable_report_param_data
        SET deleted = 1
        WHERE
        ref_id in
        <foreach collection="refIds" index="index" item="refId" separator="," open="(" close=")">
            #{refId, jdbcType=VARCHAR}
        </foreach>
    </update>

    <update id="updateKggByRefIds" parameterType="java.util.List">
        UPDATE x_lab_switchgear_report_param_data
        SET deleted = 1
        WHERE
        ref_id in
        <foreach collection="refIds" index="index" item="refId" separator="," open="(" close=")">
            #{refId, jdbcType=VARCHAR}
        </foreach>
    </update>

    <update id="updateGenByRefIds" parameterType="java.util.List">
        UPDATE x_lab_generator_report_param_data
        SET deleted = 1
        WHERE
        ref_id in
        <foreach collection="refIds" index="index" item="refId" separator="," open="(" close=")">
            #{refId, jdbcType=VARCHAR}
        </foreach>
    </update>
</mapper>
