<?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="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="plan_id" property="planId"/>
        <result column="rtu_code" property="rtuCode"/>
        <result column="report_desc" property="reportDesc"/>
        <result column="build_location_desc" property="buildLocationDesc"/>
        <result column="lng" property="lng"/>
        <result column="lat" property="lat"/>
        <result column="manage_company" property="manageCompany"/>
        <result column="rtu_kinds" property="rtuKinds"/>
        <result column="rtu_brand" property="rtuBrand"/>
        <result column="rtu_model" property="rtuModel"/>
        <result column="rtu_replace_date" property="rtuReplaceDate"/>
        <result column="datagram_to_level1" property="datagramToLevel1"/>
        <result column="datagram_to_level2" property="datagramToLevel2"/>
        <result column="datagram_to_level3" property="datagramToLevel3"/>
        <result column="rtu_desc" property="rtuDesc"/>

        <result column="rain_sensor_brand" property="rainSensorBrand"/>
        <result column="rain_sensor_model" property="rainSensorModel"/>
        <result column="rain_sensor_replace_date" property="rainSensorReplaceDate"/>

        <result column="rain_sensor_desc" property="rainSensorDesc"/>

        <result column="water_sensor_type" property="waterSensorType"/>
        <result column="water_sensor_brand" property="waterSensorBrand"/>
        <result column="water_sensor_model" property="waterSensorModel"/>
        <result column="water_sensor_replace_date" property="waterSensorReplaceDate"/>
        <result column="water_sensor_desc" property="waterSensorDesc"/>



        <result column="ground_sensor_type" property="groundSensorType"/>
        <result column="ground_sensor_brand" property="groundSensorBrand"/>
        <result column="ground_sensor_model" property="groundSensorModel"/>
        <result column="ground_sensor_replace_date" property="groundSensorReplaceDate"/>
        <result column="ground_sensor_desc" property="groundSensorDesc"/>


        <result column="battery_model" property="batteryModel"/>
        <result column="battery_replace_date" property="batteryReplaceDate"/>
        <result column="sun_power_model" property="sunPowerModel"/>
        <result column="sun_power_replace_date" property="sunPowerReplaceDate"/>
        <result column="power_desc" property="powerDesc"/>


        <result column="sim_ccid" property="simCcid"/>
        <result column="sim_pay" property="simPay"/>
        <result column="sim_pay_end_date" property="simPayEndDate"/>
        <result column="network_desc" property="networkDesc"/>


        <result column="satellite" property="satellite"/>
        <result column="satellite_model" property="satelliteModel"/>
        <result column="satellite_desc" property="satelliteDesc"/>


        <result column="rtu_status" property="rtuStatus"/>
        <result column="rain_sensor_status" property="rainSensorStatus"/>
        <result column="water_level_sensor_status" property="waterLevelSensorStatus"/>
        <result column="ground_water_sensor_status" property="groundWaterSensorStatus"/>
        <result column="network_status" property="networkStatus"/>
        <result column="satellite_status" property="satelliteStatus"/>
        <result column="power_status" property="powerStatus"/>
        <result column="rain_sensor_active" property="rainSensorActive"/>
        <result column="water_level_sensor_active" property="waterLevelSensorActive"/>
        <result column="ground_water_sensor_active" property="groundWaterSensorActive"/>
        <result column="network_active" property="networkActive"/>
        <result column="satellite_active" property="satelliteActive"/>


        <result column="base_photo1_take" property="basePhoto1Take"/>
        <result column="base_photo1_url" property="basePhoto1Url"/>
        <result column="base_photo2_take" property="basePhoto2Take"/>
        <result column="base_photo2_url" property="basePhoto2Url"/>
        <result column="rtu_photo_take" property="rtuPhotoTake"/>
        <result column="rtu_photo_url" property="rtuPhotoUrl"/>
        <result column="rain_sensor_photo_take" property="rainSensorPhotoTake"/>
        <result column="rain_sensor_photo_url" property="rainSensorPhotoUrl"/>
        <result column="water_sensor_photo_take" property="waterSensorPhotoTake"/>
        <result column="water_sensor_photo_url" property="waterSensorPhotoUrl"/>
        <result column="ground_sensor_photo_take" property="groundSensorPhotoTake"/>
        <result column="ground_sensor_photo_url" property="groundSensorPhotoUrl"/>
        <result column="battery_photo_take" property="batteryPhotoTake"/>
        <result column="battery_photo_url" property="batteryPhotoUrl"/>
        <result column="sun_photo_take" property="sunPhotoTake"/>
        <result column="sun_photo_url" property="sunPhotoUrl"/>
    </resultMap>


    <resultMap id="reportVOResultMap"
               type="org.springblade.modules.business.equipment.inspection.report.vo.EquipmentInspectionReportVO">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="plan_id" property="planId"/>
        <result column="rtu_code" property="rtuCode"/>
        <result column="report_desc" property="reportDesc"/>
        <result column="build_location_desc" property="buildLocationDesc"/>
        <result column="lng" property="lng"/>
        <result column="lat" property="lat"/>
        <result column="manage_company" property="manageCompany"/>
        <result column="rtu_kinds" property="rtuKinds"/>
        <result column="rtu_brand" property="rtuBrand"/>
        <result column="rtu_model" property="rtuModel"/>
        <result column="rtu_replace_date" property="rtuReplaceDate"/>
        <result column="datagram_to_level1" property="datagramToLevel1"/>
        <result column="datagram_to_level2" property="datagramToLevel2"/>
        <result column="datagram_to_level3" property="datagramToLevel3"/>
        <result column="rtu_desc" property="rtuDesc"/>

        <result column="rain_sensor_brand" property="rainSensorBrand"/>
        <result column="rain_sensor_model" property="rainSensorModel"/>
        <result column="rain_sensor_replace_date" property="rainSensorReplaceDate"/>

        <result column="rain_sensor_desc" property="rainSensorDesc"/>

        <result column="water_sensor_type" property="waterSensorType"/>
        <result column="water_sensor_brand" property="waterSensorBrand"/>
        <result column="water_sensor_model" property="waterSensorModel"/>
        <result column="water_sensor_replace_date" property="waterSensorReplaceDate"/>
        <result column="water_sensor_desc" property="waterSensorDesc"/>



        <result column="ground_sensor_type" property="groundSensorType"/>
        <result column="ground_sensor_brand" property="groundSensorBrand"/>
        <result column="ground_sensor_model" property="groundSensorModel"/>
        <result column="ground_sensor_replace_date" property="groundSensorReplaceDate"/>
        <result column="ground_sensor_desc" property="groundSensorDesc"/>


        <result column="battery_model" property="batteryModel"/>
        <result column="battery_replace_date" property="batteryReplaceDate"/>
        <result column="sun_power_model" property="sunPowerModel"/>
        <result column="sun_power_replace_date" property="sunPowerReplaceDate"/>
        <result column="power_desc" property="powerDesc"/>


        <result column="sim_ccid" property="simCcid"/>
        <result column="sim_pay" property="simPay"/>
        <result column="sim_pay_end_date" property="simPayEndDate"/>
        <result column="network_desc" property="networkDesc"/>


        <result column="satellite" property="satellite"/>
        <result column="satellite_model" property="satelliteModel"/>
        <result column="satellite_desc" property="satelliteDesc"/>


        <result column="rtu_status" property="rtuStatus"/>
        <result column="rain_sensor_status" property="rainSensorStatus"/>
        <result column="water_level_sensor_status" property="waterLevelSensorStatus"/>
        <result column="ground_water_sensor_status" property="groundWaterSensorStatus"/>
        <result column="network_status" property="networkStatus"/>
        <result column="satellite_status" property="satelliteStatus"/>
        <result column="power_status" property="powerStatus"/>
        <result column="rain_sensor_active" property="rainSensorActive"/>
        <result column="water_level_sensor_active" property="waterLevelSensorActive"/>
        <result column="ground_water_sensor_active" property="groundWaterSensorActive"/>
        <result column="network_active" property="networkActive"/>
        <result column="satellite_active" property="satelliteActive"/>


        <result column="base_photo1_take" property="basePhoto1Take"/>
        <result column="base_photo1_url" property="basePhoto1Url"/>
        <result column="base_photo2_take" property="basePhoto2Take"/>
        <result column="base_photo2_url" property="basePhoto2Url"/>
        <result column="rtu_photo_take" property="rtuPhotoTake"/>
        <result column="rtu_photo_url" property="rtuPhotoUrl"/>
        <result column="rain_sensor_photo_take" property="rainSensorPhotoTake"/>
        <result column="rain_sensor_photo_url" property="rainSensorPhotoUrl"/>
        <result column="water_sensor_photo_take" property="waterSensorPhotoTake"/>
        <result column="water_sensor_photo_url" property="waterSensorPhotoUrl"/>
        <result column="ground_sensor_photo_take" property="groundSensorPhotoTake"/>
        <result column="ground_sensor_photo_url" property="groundSensorPhotoUrl"/>
        <result column="battery_photo_take" property="batteryPhotoTake"/>
        <result column="battery_photo_url" property="batteryPhotoUrl"/>
        <result column="sun_photo_take" property="sunPhotoTake"/>
        <result column="sun_photo_url" property="sunPhotoUrl"/>

        <result column="org_id" property="orgId"/>
        <result column="project_id" property="projectId"/>
        <result column="rtu_name" property="rtuName"/>

        <result column="real_name" property="servicePersonName"/>


    </resultMap>

    <select id="selectPage" resultMap="reportVOResultMap">
        SELECT
        r.*, rtu.rtu_name,rtu.org_id,rtu.project_id,u.real_name
        FROM
        equipment_inspection_report_info r
        LEFT JOIN  rtu_info rtu ON rtu.rtu_code = r.rtu_code
        LEFT JOIN  blade_user u ON u.id = r.create_user
        WHERE
        r.is_deleted = 0
        and r.plan_id = #{reportDTO.planId}
        <if test="reportDTO.rtuName!=null">
            and rtu.rtu_name like concat(concat('%', #{reportDTO.rtuName}), '%')
        </if>
        <if test="reportDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{reportDTO.rtuCode}), '%')
        </if>
        <if test="reportDTO.orgId!=null">
            and rtu.org_id = #{reportDTO.orgId}
        </if>
        <if test="reportDTO.projectId!=null ">
            and rtu.project_id = #{reportDTO.projectId}
        </if>
        <if test="reportDTO.createUser!=null ">
            and r.create_user = #{reportDTO.createUser}
        </if>
        order by  r.create_time desc
    </select>

    <select id="yearPlanEquipmentInspectionReportCount" resultType="java.lang.Long">
        SELECT
        count(*)
        FROM
        equipment_inspection_report_info r
        LEFT JOIN  rtu_info rtu ON rtu.rtu_code = r.rtu_code
        WHERE
        r.is_deleted = 0
        <if test="planId!=null">
        and r.plan_id = #{planId}
        </if>
        <if test="orgId!=null">
            and rtu.org_id = #{orgId}
        </if>
    </select>

    <select id="selectTodayReportList" resultMap="reportVOResultMap">
        SELECT
        r.*, rtu.rtu_name,rtu.org_id,rtu.project_id,u.real_name
        FROM
        equipment_inspection_report_info r
        LEFT JOIN  rtu_info rtu ON rtu.rtu_code = r.rtu_code
        LEFT JOIN  blade_user u ON u.id = r.create_user
        WHERE
        r.is_deleted = 0
        and r.plan_id = #{reportDTO.planId}
        <if test="reportDTO.orgId!=null">
            and rtu.org_id = #{reportDTO.orgId}
        </if>
        <if test="reportDTO.createTime!=null ">
            and r.create_time >= #{reportDTO.createTime}
        </if>
        order by  r.create_time desc
    </select>
</mapper>
