<?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="org.springblade.modules.business.equipment.inspection.report.mapper.EquipmentInspectionReportMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="orderProcessInfoResultMap"
               type="org.springblade.modules.business.equipment.inspection.report.entity.EquipmentInspectionReportEntity">


        <result column="inspection_id" property="inspectionId"/>
        <result column="rtu_code" property="rtuCode"/>
        <result column="lng" property="lng"/>
        <result column="lat" property="lat"/>
        <result column="location_desc" property="locationDesc"/>
        <result column="site_check_item" property="siteCheckItem"/>
        <result column="site_check_photos" property="siteCheckPhotos"/>
        <result column="site_check_remark" property="siteCheckRemark"/>

        <result column="rain_site_check_item" property="rainSiteCheckItem"/>
        <result column="rain_site_check_photos" property="rainSiteCheckPhotos"/>
        <result column="rain_site_check_remark" property="rainSiteCheckRemark"/>
        <result column="rain_site_check_result" property="rainSiteCheckResult"/>

        <result column="water_site_check_item" property="waterSiteCheckItem"/>
        <result column="water_site_check_photos" property="waterSiteCheckPhotos"/>
        <result column="water_site_check_remark" property="waterSiteCheckRemark"/>
        <result column="water_site_check_result" property="waterSiteCheckResult"/>

        <result column="ground_site_check_item" property="groundSiteCheckItem"/>
        <result column="ground_site_check_photos" property="groundSiteCheckPhotos"/>
        <result column="ground_site_check_remark" property="groundSiteCheckRemark"/>
        <result column="ground_site_check_result" property="groundSiteCheckResult"/>

        <result column="other_equipment_check_item" property="otherEquipmentCheckItem"/>
        <result column="other_equipment_check_photos" property="otherEquipmentCheckPhotos"/>
        <result column="other_equipment_check_remark" property="otherEquipmentCheckRemark"/>
        <result column="other_equipment_check_result" property="otherEquipmentCheckResult"/>

        <result column="rtu_replace" property="rtuReplace"/>
        <result column="rtu_model_remark" property="rtuModelRemark"/>
        <result column="rtu_replace_photos" property="rtuReplacePhotos"/>
        <result column="rain_sensor_replace" property="rainSensorReplace"/>
        <result column="rain_sensor_model_remark" property="rainSensorModelRemark"/>
        <result column="rain_sensor_replace_photos" property="rainSensorReplacePhotos"/>
        <result column="water_sensor_replace" property="waterSensorReplace"/>
        <result column="water_sensor_model_remark" property="waterSensorModelRemark"/>
        <result column="water_sensor_replace_photos" property="waterSensorReplacePhotos"/>
        <result column="ground_sensor_replace" property="groundSensorReplace"/>
        <result column="ground_sensor_model_remark" property="groundSensorModelRemark"/>
        <result column="ground_sensor_replace_photos" property="groundSensorReplacePhotos"/>
        <result column="battery_replace" property="batteryReplace"/>
        <result column="battery_model_remark" property="batteryModelRemark"/>
        <result column="battery_replace_photos" property="batteryReplacePhotos"/>
        <result column="sun_power_replace" property="sunPowerReplace"/>
        <result column="sun_power_model_remark" property="sunPowerModelRemark"/>
        <result column="sun_power_replace_photos" property="sunPowerReplacePhotos"/>
        <result column="battery_controller_replace" property="batteryControllerReplace"/>
        <result column="battery_controller_model_remark" property="batteryControllerModelRemark"/>
        <result column="battery_controller_replace_photos" property="batteryControllerReplacePhotos"/>
        <result column="other_equipment_replace" property="otherEquipmentReplace"/>
        <result column="other_equipment_replace_remark" property="otherEquipmentCheckRemark"/>
        <result column="other_equipment_replace_photos" property="otherEquipmentReplacePhotos"/>

        <result column="remain_question" property="remainQuestion"/>
        <result column="remain_question_state" property="remainQuestionState"/>
        <result column="remain_question_resolution" property="remainQuestionResolution"/>
        <result column="inspection_work_photos" property="inspectionWorkPhotos"/>

        <result column="rain_season_kind" property="rainSeasonKind"/>

        <result column="network_signal_status" property="networkSignalStatus"/>
        <result column="photo_supplement_submit_status" property="photoSupplementSubmitStatus"/>

        <result column="network_sim_id" property="networkSimId"/>
        <result column="network_payer" property="networkPayer"/>
    </resultMap>


    <resultMap id="reportVOResultMap"
               type="org.springblade.modules.business.equipment.inspection.report.vo.EquipmentInspectionReportVO">

        <result column="inspection_id" property="inspectionId"/>
        <result column="rtu_code" property="rtuCode"/>
        <result column="lng" property="lng"/>
        <result column="lat" property="lat"/>
        <result column="location_desc" property="locationDesc"/>
        <result column="site_check_item" property="siteCheckItem"/>
        <result column="site_check_photos" property="siteCheckPhotos"/>
        <result column="site_check_remark" property="siteCheckRemark"/>

        <result column="rain_site_check_item" property="rainSiteCheckItem"/>
        <result column="rain_site_check_photos" property="rainSiteCheckPhotos"/>
        <result column="rain_site_check_remark" property="rainSiteCheckRemark"/>
        <result column="rain_site_check_result" property="rainSiteCheckResult"/>

        <result column="water_site_check_item" property="waterSiteCheckItem"/>
        <result column="water_site_check_photos" property="waterSiteCheckPhotos"/>
        <result column="water_site_check_remark" property="waterSiteCheckRemark"/>
        <result column="water_site_check_result" property="waterSiteCheckResult"/>

        <result column="ground_site_check_item" property="groundSiteCheckItem"/>
        <result column="ground_site_check_photos" property="groundSiteCheckPhotos"/>
        <result column="ground_site_check_remark" property="groundSiteCheckRemark"/>
        <result column="ground_site_check_result" property="groundSiteCheckResult"/>

        <result column="other_equipment_check_item" property="otherEquipmentCheckItem"/>
        <result column="other_equipment_check_photos" property="otherEquipmentCheckPhotos"/>
        <result column="other_equipment_check_remark" property="otherEquipmentCheckRemark"/>
        <result column="other_equipment_check_result" property="otherEquipmentCheckResult"/>

        <result column="rtu_replace" property="rtuReplace"/>
        <result column="rtu_model_remark" property="rtuModelRemark"/>
        <result column="rtu_replace_photos" property="rtuReplacePhotos"/>
        <result column="rain_sensor_replace" property="rainSensorReplace"/>
        <result column="rain_sensor_model_remark" property="rainSensorModelRemark"/>
        <result column="rain_sensor_replace_photos" property="rainSensorReplacePhotos"/>
        <result column="water_sensor_replace" property="waterSensorReplace"/>
        <result column="water_sensor_model_remark" property="waterSensorModelRemark"/>
        <result column="water_sensor_replace_photos" property="waterSensorReplacePhotos"/>
        <result column="ground_sensor_replace" property="groundSensorReplace"/>
        <result column="ground_sensor_model_remark" property="groundSensorModelRemark"/>
        <result column="ground_sensor_replace_photos" property="groundSensorReplacePhotos"/>
        <result column="battery_replace" property="batteryReplace"/>
        <result column="battery_model_remark" property="batteryModelRemark"/>
        <result column="battery_replace_photos" property="batteryReplacePhotos"/>
        <result column="sun_power_replace" property="sunPowerReplace"/>
        <result column="sun_power_model_remark" property="sunPowerModelRemark"/>
        <result column="sun_power_replace_photos" property="sunPowerReplacePhotos"/>
        <result column="battery_controller_replace" property="batteryControllerReplace"/>
        <result column="battery_controller_model_remark" property="batteryControllerModelRemark"/>
        <result column="battery_controller_replace_photos" property="batteryControllerReplacePhotos"/>
        <result column="other_equipment_replace" property="otherEquipmentReplace"/>
        <result column="other_equipment_replace_remark" property="otherEquipmentCheckRemark"/>
        <result column="other_equipment_replace_photos" property="otherEquipmentReplacePhotos"/>

        <result column="remain_question" property="remainQuestion"/>
        <result column="remain_question_state" property="remainQuestionState"/>
        <result column="remain_question_resolution" property="remainQuestionResolution"/>
        <result column="inspection_work_photos" property="inspectionWorkPhotos"/>

        <result column="rain_season_kind" property="rainSeasonKind"/>


        <result column="rtu_name" property="rtuName"/>
        <result column="real_name" property="servicePersonName"/>
        <result column="ad_city" property="adCity"/>
        <result column="ad_dist" property="adDist"/>
        <result column="is_rain" property="isRain"/>
        <result column="isRiver" property="isRiver"/>
        <result column="isRiver" property="isRes"/>
        <result column="is_ground" property="isGround"/>
        <result column="is_camera" property="isCamera"/>
        <result column="ancestors" property="ancestors"/>
        <result column="adcd" property="adCode"/>

        <result column="network_signal_status" property="networkSignalStatus"/>
        <result column="photo_supplement_submit_status" property="photoSupplementSubmitStatus"/>

        <result column="network_sim_id" property="networkSimId"/>
        <result column="network_payer" property="networkPayer"/>
    </resultMap>

    <select id="selectList" resultMap="reportVOResultMap">
        SELECT
        r.*,u.real_name
        FROM
        equipment_inspection_report_info r
        LEFT JOIN rtu_info i ON i.rtu_code = r.rtu_code and i.is_deleted=0
        LEFT JOIN blade_user u ON u.id = r.create_user and u.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = i.ad_code and a.is_deleted=0
        WHERE
        r.is_deleted = 0
        <if test="inspectionReportDTO.rtuCode!=null">
            and r.rtu_code = #{inspectionReportDTO.rtuCode}
        </if>
        <if test="inspectionReportDTO.inspectionYearStartDate!=null">
            and r.create_time &gt;= #{inspectionReportDTO.inspectionYearStartDate}
        </if>
        <if test="inspectionReportDTO.inspectionYearEndDate!=null">
            and r.create_time &lt; #{inspectionReportDTO.inspectionYearEndDate}
        </if>
        <if test="inspectionReportDTO.excludeCode!=null and inspectionReportDTO.excludeCode==1">
            and a.exclude_ad = 0
        </if>
        <if test="inspectionReportDTO.adCode!=null">
            and (i.ad_code =#{inspectionReportDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE
            is_deleted =0 and ancestors
            like concat(concat('%', #{inspectionReportDTO.adCode}), '%')))
        </if>
        order by r.rtu_code ASC,r.create_time desc
    </select>

    <select id="selectPage" resultMap="reportVOResultMap">
        SELECT
        r.*, rtu.rtu_name,u.real_name,rtu.ad_city,rtu.ad_dist,rtu.is_rain,rtu.is_river,rtu.is_res,rtu.is_ground,rtu.is_rain,rtu.is_river,rtu.is_res,rtu.is_ground
        FROM
        equipment_inspection_report_info r
        LEFT JOIN rtu_info rtu ON rtu.rtu_code = r.rtu_code and rtu.is_deleted=0
        LEFT JOIN blade_user u ON u.id = r.create_user and u.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = rtu.ad_code and a.is_deleted=0
        WHERE
        r.is_deleted = 0
        <if test="inspectionReportDTO.createUser!=null">
            and r.create_user =#{inspectionReportDTO.createUser}
        </if>
        <if test="inspectionReportDTO.rtuName!=null">
            and rtu.rtu_name like concat(concat('%', #{inspectionReportDTO.rtuName}), '%')
        </if>
        <if test="inspectionReportDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{inspectionReportDTO.rtuCode}), '%')
        </if>
        <if test="inspectionReportDTO.rainSeasonKind!=null">
            and r.rain_season_kind = #{inspectionReportDTO.rainSeasonKind}
        </if>
        <if test="inspectionReportDTO.inspectionYearStartDate!=null">
            and r.create_time &gt;= #{inspectionReportDTO.inspectionYearStartDate}
        </if>
        <if test="inspectionReportDTO.inspectionYearEndDate!=null">
            and r.create_time &lt; #{inspectionReportDTO.inspectionYearEndDate}
        </if>
        <if test="inspectionReportDTO.excludeCode!=null and inspectionReportDTO.excludeCode==1">
            and a.exclude_ad = 0
        </if>
        <if test="inspectionReportDTO.adCode!=null">
            and (a.adcd =#{inspectionReportDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE
            is_deleted =0 and ancestors
            like concat(concat('%', #{inspectionReportDTO.adCode}), '%')))
        </if>
        order by r.create_time DESC,rtu.rtu_code ASC
    </select>

    <select id="equipmentInspectionReportCount" resultType="java.lang.Long">
        SELECT
        count(*)
        FROM
        equipment_inspection_report_info r
        LEFT JOIN rtu_info i ON r.rtu_code = i.rtu_code and i.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = i.ad_code and a.is_deleted=0
        WHERE
        r.is_deleted = 0
        <if test="inspectionReportDTO.rainSeasonKind!=null">
            and r.rain_season_kind = #{inspectionReportDTO.rainSeasonKind}
        </if>
        <if test="inspectionReportDTO.inspectionYearStartDate!=null">
            and r.create_time &gt;= #{inspectionReportDTO.inspectionYearStartDate}
        </if>
        <if test="inspectionReportDTO.inspectionYearEndDate!=null">
            and r.create_time &lt; #{inspectionReportDTO.inspectionYearEndDate}
        </if>
        <if test="inspectionReportDTO.excludeCode!=null and inspectionReportDTO.excludeCode==1">
            and a.exclude_ad = 0
        </if>
        <if test="inspectionReportDTO.adCode!=null">
            and (a.adcd =#{inspectionReportDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE
            is_deleted = 0 and ancestors like concat(concat('%', #{inspectionReportDTO.adCode}), '%')))
        </if>

    </select>

    <select id="selectTodayReportList" resultMap="reportVOResultMap">
        SELECT
        r.*, rtu.rtu_name,rtu.org_id,rtu.project_id,u.real_name,rtu.ad_city,rtu.ad_dist,a.adcd,a.ancestors,rtu.is_rain,rtu.is_river,rtu.is_res,rtu.is_ground
        FROM
        equipment_inspection_report_info r
        LEFT JOIN rtu_info rtu ON rtu.rtu_code = r.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = rtu.ad_code and a.is_deleted=0
        LEFT JOIN blade_user u ON u.id = r.create_user
        WHERE
        r.is_deleted = 0
        <if test="inspectionReportDTO.createTime!=null ">
            and DATE_FORMAT(r.create_time,'%Y-%m-%d') = DATE_FORMAT(#{inspectionReportDTO.createTime},'%Y-%m-%d')
        </if>
        <if test="inspectionReportDTO.rtuCode!=null">
            and rtu.rtu_code like concat(concat('%', #{inspectionReportDTO.rtuCode}), '%')
        </if>
        <if test="inspectionReportDTO.rtuName!=null">
            and rtu.rtu_name like concat(concat('%', #{inspectionReportDTO.rtuName}), '%')
        </if>
        <if test="inspectionReportDTO.excludeCode!=null and inspectionReportDTO.excludeCode==1">
            and a.exclude_ad = 0
        </if>
        <if test="inspectionReportDTO.adCode!=null">
            and (a.adcd =#{inspectionReportDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE
            is_deleted =0 and ancestors
            like concat(concat('%', #{inspectionReportDTO.adCode}), '%')))
        </if>
        order by r.create_time desc
    </select>

    <select id="selectTodayReportPage" resultMap="reportVOResultMap">
        SELECT
        r.*, rtu.rtu_name,rtu.org_id,rtu.project_id,u.real_name,rtu.ad_city,rtu.ad_dist,a.adcd,a.ancestors,rtu.is_rain,rtu.is_river,rtu.is_res,rtu.is_ground
        FROM
        equipment_inspection_report_info r
        LEFT JOIN rtu_info rtu ON rtu.rtu_code = r.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = rtu.ad_code and a.is_deleted=0
        LEFT JOIN blade_user u ON u.id = r.create_user
        WHERE
        r.is_deleted = 0
        <if test="inspectionReportDTO.createTime!=null ">
            and DATE_FORMAT(r.create_time,'%Y-%m-%d') = DATE_FORMAT(#{inspectionReportDTO.createTime},'%Y-%m-%d')
        </if>
        <if test="inspectionReportDTO.rtuCode!=null">
            and rtu.rtu_code like concat(concat('%', #{inspectionReportDTO.rtuCode}), '%')
        </if>
        <if test="inspectionReportDTO.rtuName!=null">
            and rtu.rtu_name like concat(concat('%', #{inspectionReportDTO.rtuName}), '%')
        </if>
        <if test="inspectionReportDTO.excludeCode!=null and inspectionReportDTO.excludeCode==1">
            and a.exclude_ad = 0
        </if>
        <if test="inspectionReportDTO.adCode!=null">
            and (a.adcd =#{inspectionReportDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE
            is_deleted =0 and ancestors
            like concat(concat('%', #{inspectionReportDTO.adCode}), '%')))
        </if>
        order by r.create_time desc
    </select>


    <select id="todayReportCount" resultType="java.lang.Long">
        select count(*) from
        ( SELECT
        r.rtu_code
        FROM
        equipment_inspection_report_info r
        LEFT JOIN rtu_info rtu ON rtu.rtu_code = r.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = rtu.ad_code and a.is_deleted=0
        WHERE
        r.is_deleted = 0
        <if test="inspectionReportDTO.createTime!=null ">
            and DATE_FORMAT(r.create_time,'%Y-%m-%d') = DATE_FORMAT(#{inspectionReportDTO.createTime},'%Y-%m-%d')
        </if>
        <if test="inspectionReportDTO.excludeCode!=null and inspectionReportDTO.excludeCode==1">
            and a.exclude_ad = 0
        </if>
        <if test="inspectionReportDTO.adCode!=null">
            and (a.adcd =#{inspectionReportDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE
            is_deleted = 0 and ancestors
            like concat(concat('%', #{inspectionReportDTO.adCode}), '%')))
        </if>
         group by r.rtu_code ) s

    </select>

    <select id="selectRemainingproblemsPage" resultMap="reportVOResultMap">
        SELECT
        r.*, rtu.rtu_name,u.real_name,rtu.ad_city,rtu.ad_dist,rtu.is_rain,rtu.is_river,rtu.is_res,rtu.is_ground
        FROM
        equipment_inspection_report_info r
        LEFT JOIN rtu_info rtu ON rtu.rtu_code = r.rtu_code and rtu.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = rtu.ad_code and a.is_deleted=0
        LEFT JOIN blade_user u ON u.id = r.create_user and u.is_deleted=0
        WHERE
        r.is_deleted = 0
        and (r.remain_question_state = 1 or r.remain_question_state = 2)
        <if test="inspectionReportDTO.rtuName!=null">
            and rtu.rtu_name like concat(concat('%', #{inspectionReportDTO.rtuName}), '%')
        </if>
        <if test="inspectionReportDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{inspectionReportDTO.rtuCode}), '%')
        </if>
        <if test="inspectionReportDTO.rainSeasonKind!=null">
            and r.rain_season_kind = #{inspectionReportDTO.rainSeasonKind}
        </if>
        <if test="inspectionReportDTO.inspectionYearStartDate!=null">
            and r.create_time &gt;= #{inspectionReportDTO.inspectionYearStartDate}
        </if>
        <if test="inspectionReportDTO.inspectionYearEndDate!=null">
            and r.create_time &lt; #{inspectionReportDTO.inspectionYearEndDate}
        </if>
        <if test="inspectionReportDTO.excludeCode!=null and inspectionReportDTO.excludeCode==1">
            and a.exclude_ad = 0
        </if>
        <if test="inspectionReportDTO.adCode!=null">
            and (a.adcd =#{inspectionReportDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE
            is_deleted =0 and ancestors
            like concat(concat('%', #{inspectionReportDTO.adCode}), '%')))
        </if>
        order by r.remain_question_resolution , r.create_time DESC,rtu.rtu_code ASC
    </select>

    <select id="selectRainSeasonRemainingproblemsList" resultMap="reportVOResultMap">
        SELECT
        r.*, rtu.rtu_name,rtu.org_id,dept.dept_name AS org_name,u.real_name,rtu.ad_city,rtu.ad_dist,rtu.is_rain,rtu.is_river,rtu.is_res,rtu.is_ground
        FROM
        equipment_inspection_report_info r
        LEFT JOIN rtu_info rtu ON rtu.rtu_code = r.rtu_code and rtu.is_deleted=0
        LEFT JOIN blade_user u ON u.id = r.create_user and u.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = rtu.ad_code and a.is_deleted=0
        LEFT JOIN blade_dept dept ON dept.id = rtu.org_id and dept.is_deleted=0
        WHERE
        r.is_deleted = 0
        and (r.remain_question_state = 1 or r.remain_question_state = 2)
        <if test="inspectionReportDTO.rainSeasonKind!=null">
            and r.rain_season_kind = #{inspectionReportDTO.rainSeasonKind}
        </if>
        <if test="inspectionReportDTO.excludeCode!=null and inspectionReportDTO.excludeCode==1">
            and a.exclude_ad = 0
        </if>
        <if test="inspectionReportDTO.adCode!=null">
            and (a.adcd =#{inspectionReportDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE
            is_deleted =0 and ancestors
            like concat(concat('%', #{inspectionReportDTO.adCode}), '%')))
        </if>
        order by r.remain_question_state ASC,r.create_time DESC,rtu.rtu_code ASC
    </select>

    <select id="selectRainSeasonUncolseRemainingproblemsList" resultMap="reportVOResultMap">
        SELECT
        r.*, rtu.rtu_name,rtu.org_id,dept.dept_name AS org_name,u.real_name,rtu.ad_city,rtu.ad_dist,rtu.is_rain,rtu.is_river,rtu.is_res,rtu.is_ground
        FROM
        equipment_inspection_report_info r
        LEFT JOIN rtu_info rtu ON rtu.rtu_code = r.rtu_code and rtu.is_deleted=0
        LEFT JOIN blade_user u ON u.id = r.create_user and u.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = rtu.ad_code and a.is_deleted=0
        LEFT JOIN blade_dept dept ON dept.id = rtu.org_id and dept.is_deleted=0
        WHERE
        r.is_deleted = 0
        and r.remain_question_state = 1
        <if test="inspectionReportDTO.rainSeasonKind!=null">
            and r.rain_season_kind = #{inspectionReportDTO.rainSeasonKind}
        </if>
        <if test="inspectionReportDTO.excludeCode!=null and inspectionReportDTO.excludeCode==1">
            and a.exclude_ad = 0
        </if>
        <if test="inspectionReportDTO.adCode!=null">
            and (a.adcd =#{inspectionReportDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE
            is_deleted =0 and ancestors
            like concat(concat('%', #{inspectionReportDTO.adCode}), '%')))
        </if>
        order by r.remain_question_state ASC,r.create_time DESC,rtu.rtu_code ASC
    </select>

    <select id="selectNoNetworkSignalPage" resultMap="reportVOResultMap">

        SELECT
        r.*, rtu.rtu_name,u.real_name,rtu.ad_city,rtu.ad_dist,rtu.is_rain,rtu.is_river,rtu.is_res,rtu.is_ground
        FROM
        equipment_inspection_report_info r
        LEFT JOIN rtu_info rtu ON rtu.rtu_code = r.rtu_code and rtu.is_deleted=0
        LEFT JOIN blade_user u ON u.id = r.create_user and u.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = rtu.ad_code and a.is_deleted=0
        WHERE
        r.is_deleted = 0
        and r.network_signal_status = 1
        <if test="inspectionReportDTO.rtuName!=null">
            and rtu.rtu_name like concat(concat('%', #{inspectionReportDTO.rtuName}), '%')
        </if>
        <if test="inspectionReportDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{inspectionReportDTO.rtuCode}), '%')
        </if>
        <if test="inspectionReportDTO.rainSeasonKind!=null">
            and r.rain_season_kind = #{inspectionReportDTO.rainSeasonKind}
        </if>
        <if test="inspectionReportDTO.inspectionYearStartDate!=null">
            and r.create_time &gt;= #{inspectionReportDTO.inspectionYearStartDate}
        </if>
        <if test="inspectionReportDTO.inspectionYearEndDate!=null">
            and r.create_time &lt; #{inspectionReportDTO.inspectionYearEndDate}
        </if>
        <if test="inspectionReportDTO.excludeCode!=null and inspectionReportDTO.excludeCode==1">
            and a.exclude_ad = 0
        </if>
        <if test="inspectionReportDTO.adCode!=null">
            and (rtu.ad_code =#{inspectionReportDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE
            is_deleted =0 and ancestors
            like concat(concat('%', #{inspectionReportDTO.adCode}), '%')))
        </if>
        order by  r.photo_supplement_submit_status ASC,r.create_time ASC,rtu.rtu_code ASC
    </select>
</mapper>
