<?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.plan.mapper.EquipmentInspectionPlanRtuMapper">



    <!-- 通用查询映射结果 -->
    <resultMap id="rtuVOResultMap" type="org.springblade.modules.business.equipment.inspection.plan.vo.EquipmentInspectionRtuVO">
        <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="rtu_code" property="rtuCode"/>
        <result column="rtu_name" property="rtuName"/>
        <result column="lng" property="lng"/>
        <result column="lat" property="lat"/>
        <result column="org_id" property="orgId"/>
        <result column="project_id" property="projectId"/>
        <result column="manageCompany" property="manage_company"/>


        <result column="rtu_kinds" property="rtuKinds"/>
        <result column="remark" property="remark"/>
        <result column="location_desc" property="locationDesc"/>
        <result column="remark" property="remark"/>
        <result column="is_rain" property="isRain"/>
        <result column="is_river" property="isRiver"/>
        <result column="is_res" property="isRes"/>

        <result column="is_ground" property="isGround"/>
        <result column="is_satellite" property="isSatellite"/>

        <result column="rtu_brand" property="rtuBrand"/>
        <result column="rtu_model" property="rtuModel"/>
        <result column="rtu_replace_date" property="rtuReplaceDate"/>
        <result column="datagram_to_sheng" property="datagramToSheng"/>
        <result column="datagram_to_shi" property="datagramToShi"/>
        <result column="datagram_to_qu" property="datagramToQu"/>

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

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

        <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="battery_model" property="batteryModel"/>
        <result column="battery_replace_date" property="batteryReplaceDate"/>
        <result column="sun_power_model" property="sunPowerModel"/>

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

        <result column="satellite_model" property="satelliteModel"/>

        <result column="project_name" property="projectName"/>
        <result column="org_name" property="orgName"/>
        <result column="reportTime" property="reportTime"/>

    </resultMap>

    <resultMap id="equipmentInspectionVOResultMap" type="org.springblade.modules.business.equipment.inspection.plan.vo.EquipmentInspectionRtuVO">
        <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="rtu_code" property="rtuCode"/>
        <result column="rtu_name" property="rtuName"/>
        <result column="lng" property="lng"/>
        <result column="lat" property="lat"/>
        <result column="org_id" property="orgId"/>
        <result column="project_id" property="projectId"/>
        <result column="manageCompany" property="manage_company"/>


        <result column="rtu_kinds" property="rtuKinds"/>
        <result column="remark" property="remark"/>
        <result column="location_desc" property="locationDesc"/>
        <result column="remark" property="remark"/>
        <result column="is_rain" property="isRain"/>
        <result column="is_river" property="isRiver"/>
        <result column="is_res" property="isRes"/>

        <result column="is_ground" property="isGround"/>
        <result column="is_satellite" property="isSatellite"/>

        <result column="rtu_brand" property="rtuBrand"/>
        <result column="rtu_model" property="rtuModel"/>
        <result column="rtu_replace_date" property="rtuReplaceDate"/>
        <result column="datagram_to_sheng" property="datagramToSheng"/>
        <result column="datagram_to_shi" property="datagramToShi"/>
        <result column="datagram_to_qu" property="datagramToQu"/>

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

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

        <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="battery_model" property="batteryModel"/>
        <result column="battery_replace_date" property="batteryReplaceDate"/>
        <result column="sun_power_model" property="sunPowerModel"/>

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

        <result column="satellite_model" property="satelliteModel"/>

        <result column="project_name" property="projectName"/>
        <result column="org_name" property="orgName"/>

        <result column="run_status_id" property="runStatus"/>

    </resultMap>


    <select id="selectPage" resultMap="rtuVOResultMap">
        SELECT
        n.*,
        p.project_name ,d.dept_name AS org_name,r.create_time AS  reportTime,s.run_status_id
        FROM
        rtu_info n
        LEFT JOIN project_info p ON n.project_id = p.id
        LEFT JOIN blade_dept d ON n.org_id = d.id
        LEFT JOIN equipment_inspection_report_info r ON r.rtu_code= n.rtu_code
        LEFT JOIN rtu_status s ON s.rtu_code = n.rtu_code
        WHERE
        n.is_deleted = 0
        <if test="rtuDTO.rtu_code!=null">
            and n.rtu_code = #{rtuDTO.rtu_code}
        </if>
        <if test="rtuDTO.planId!=null">
            and r.plan_id = #{rtuDTO.planId}
        </if>
        <if test="rtuDTO.orgId!=null">
            and n.org_id = #{rtuDTO.orgId}
        </if>
        <if test="rtuDTO.projectId!=null">
            and n.project_id = #{rtuDTO.projectId}
        </if>
        <if test="rtuDTO.planId!=null">
            and r.plan_id = #{rtuDTO.planId}
        </if>
        order  by n.org_id,n.project_id,n.rtu_code,r.create_time
    </select>

    <select id="myPage" resultMap="equipmentInspectionVOResultMap">
        SELECT
        n.*,
        p.project_name ,d.dept_name AS org_name,s.run_status_id
        FROM
        rtu_info n
        LEFT JOIN  project_info p ON n.project_id = p.id
        LEFT JOIN  blade_dept d ON n.org_id = d.id
        LEFT JOIN equipment_inspection_report_info r ON r.rtu_code= n.rtu_code
        LEFT JOIN rtu_status s ON s.rtu_code = n.rtu_code
        WHERE
        n.is_deleted = 0
        <if test="rtuDTO.orgId!=null">
            and n.org_id = #{rtuDTO.orgId}
        </if>
        <if test="rtuDTO.projectId!=null">
            and n.project_id = #{rtuDTO.projectId}
        </if>
        <if test="rtuDTO.planId!=null">
            and (r.plan_id is null OR r.plan_id = #{rtuDTO.planId})
        </if>
        and r.create_time is null

        order  by n.org_id,n.project_id,n.rtu_code,r.create_time

    </select>
</mapper>
