<?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.inspect.metadata.eqpbook.mapper.BasedataEqpBookMapper">

    <resultMap type="BasedataEqpBook" id="BasedataEqpBookResult">
        <result property="eqpBookId" column="eqp_book_id"/>
        <result property="stationName" column="station_name"/>
        <result property="stationCode" column="station_code"/>
        <result property="areaId" column="area_id"/>
        <result property="areaName" column="area_name"/>
        <result property="patrolDeviceName" column="patrol_device_name"/>
        <result property="patrolDeviceCode" column="patrol_device_code"/>
        <result property="upSystemDeviceCode" column="up_system_device_code"/>
        <result property="deviceModel" column="device_model"/>
        <result property="manufacturer" column="manufacturer"/>
        <result property="useUnit" column="use_unit"/>
        <result property="deviceSource" column="device_source"/>
        <result property="productionDate" column="production_date"/>
        <result property="productionCode" column="production_code"/>
        <result property="isTransport" column="is_transport"/>
        <result property="useMode" column="use_mode"/>
        <result property="videoMode" column="video_mode"/>
        <result property="place" column="place"/>
        <result property="positionX" column="position_x"/>
        <result property="positionY" column="position_y"/>
        <result property="positionZ" column="position_z"/>
        <result property="type" column="type"/>
        <result property="patrolDeviceInfo" column="patrol_device_info"/>
        <result property="robotsCode" column="robots_code"/>
        <result property="ipAddr" column="ip_addr"/>
        <result property="port" column="port"/>
        <result property="user" column="user"/>
        <result property="password" column="password"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="mainSystemCode" column="main_system_code"/>
        <result property="mapFilePath" column="map_file_path"/>
        <result property="videoNvrCode" column="video_nvr_code"/>
    </resultMap>

    <resultMap type="PatrolTaskFtp" id="PatrolTaskFtpResult">
        <result property="lineId" column="line_id"/>
        <result property="ftpIp" column="ftp_ip"/>
        <result property="ftpPort" column="ftp_port"/>
        <result property="ftpUserName" column="ftp_user_name"/>
        <result property="ftpPwd" column="ftp_pwd"/>
        <result property="ftpPath" column="ftp_path"/>
        <result property="ftpType" column="ftp_type"/>
    </resultMap>

    <sql id="selectBasedataEqpBookVo">
        select eqp_book_id,
               station_name,
               station_code,
               area_id,
               area_name,
               patrol_device_name,
               patrol_device_code,
               up_system_device_code,
               device_model,
               manufacturer,
               use_unit,
               device_source,
               production_date,
               production_code,
               is_transport,
               use_mode,
               video_mode,
               place,
               position_x,
               position_y,
               position_z,
               type,
               patrol_device_info,
               robots_code,
               ip_addr,
               port,
               user,
               password,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time,
               main_system_code,
               map_file_path,
               video_nvr_code
        from basedata_eqpbook
    </sql>

    <sql id="selectPatrolTaskFtpVo">
        select line_id, ftp_ip, ftp_port, ftp_user_name, ftp_pwd, ftp_path, ftp_type
        from patrol_task_ftp
    </sql>

    <select id="selectBasedataEqpBookList" parameterType="BasedataEqpBook" resultMap="BasedataEqpBookResult">
        <include refid="selectBasedataEqpBookVo"/>
        <where>
            <if test="stationName != null  and stationName != ''">and station_name like concat('%', #{stationName},
                '%')
            </if>
            <if test="stationCode != null  and stationCode != ''">and station_code = #{stationCode}</if>
            <if test="areaId != null ">and area_id = #{areaId}</if>
            <if test="areaName != null  and areaName != ''">and area_name like concat('%', #{areaName}, '%')</if>
            <if test="patrolDeviceName != null  and patrolDeviceName != ''">and patrol_device_name like concat('%',
                #{patrolDeviceName}, '%')
            </if>
            <if test="patrolDeviceCode != null  and patrolDeviceCode != ''">and patrol_device_code =
                #{patrolDeviceCode}
            </if>
            <if test="deviceModel != null  and deviceModel != ''">and device_model = #{deviceModel}</if>
            <if test="manufacturer != null  and manufacturer != ''">and manufacturer = #{manufacturer}</if>
            <if test="useUnit != null  and useUnit != ''">and use_unit = #{useUnit}</if>
            <if test="deviceSource != null  and deviceSource != ''">and device_source = #{deviceSource}</if>
            <if test="productionDate != null  and productionDate != ''">and production_date = #{productionDate}</if>
            <if test="productionCode != null  and productionCode != ''">and production_code = #{productionCode}</if>
            <if test="isTransport != null  and isTransport != ''">and is_transport = #{isTransport}</if>
            <if test="useMode != null  and useMode != ''">and use_mode = #{useMode}</if>
            <if test="videoMode != null  and videoMode != ''">and video_mode = #{videoMode}</if>
            <if test="place != null  and place != ''">and place = #{place}</if>
            <if test="positionX != null  and positionX != ''">and position_x = #{positionX}</if>
            <if test="positionY != null  and positionY != ''">and position_y = #{positionY}</if>
            <if test="positionZ != null  and positionZ != ''">and position_z = #{positionZ}</if>
            <if test="type != null  and type != ''">and type = #{type}</if>
            <if test="patrolDeviceInfo != null  and patrolDeviceInfo != ''">and patrol_device_info =
                #{patrolDeviceInfo}
            </if>
            <if test="robotsCode != null  and robotsCode != ''">and robots_code = #{robotsCode}</if>
            <if test="ipAddr != null  and ipAddr != ''">and ip_addr = #{ipAddr}</if>
            <if test="port != null  and port != ''">and port = #{port}</if>
            <if test="user != null  and user != ''">and user = #{user}</if>
            <if test="password != null  and password != ''">and password = #{password}</if>
            <if test="mainSystemCode != null  and mainSystemCode != ''">and main_system_code = #{mainSystemCode}</if>
            <if test="mapFilePath != null  and mapFilePath != ''">and map_file_path = #{mapFilePath}</if>
            <if test="videoNvrCode != null  and videoNvrCode != ''">and video_nvr_code = #{videoNvrCode}</if>
            <if test="params != null">
                <if test="params.patrolDeviceTypeFlag != null and params.patrolDeviceTypeFlag != '' and params.patrolDeviceTypeFlag == 'nvr'">
                    and type = '11'
                </if>
            </if>
            <if test="params != null">
                <if test="params.patrolDeviceTypeFlag != null and params.patrolDeviceTypeFlag != '' and params.patrolDeviceTypeFlag == 'ipc'">
                    and type != '11' and type != '20' or type is null
                </if>
            </if>
            <if test="params != null">
                <if test="params.patrolDeviceTypeFlag != null and params.patrolDeviceTypeFlag != '' and params.patrolDeviceTypeFlag == 'robotAndUav'">
                    and type in ('1','2','3','13')
                </if>
            </if>
            <if test="params != null">
                <if test="params.patrolDeviceTypeFlag != null and params.patrolDeviceTypeFlag != '' and params.patrolDeviceTypeFlag == 'uav'">
                    and type = '13'
                </if>
            </if>
            <if test="params != null">
                <if test="params.robotFlag != null and params.robotFlag == '1'">
                    and type in ('1','2','3')
                </if>
            </if>
        </where>
    </select>

    <select id="selectBasedataEqpBookOnlineList"
            parameterType="com.inspect.metadata.eqpbook.domain.vo.BasedataEqpBookTreeQueryFilterVo"
            resultMap="BasedataEqpBookResult">
        <include refid="selectBasedataEqpBookVo"/>
        <where>
            <if test="patrolDeviceName != null  and patrolDeviceName != ''">and patrol_device_name like concat('%',
                #{patrolDeviceName}, '%')
            </if>
            <if test="patrolDeviceCode != null  and patrolDeviceCode != ''">and patrol_device_code =
                #{patrolDeviceCode}
            </if>
            <if test="ids != null and ids.size() > 0">
                and eqp_book_id in
                <foreach item="item" collection="ids" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectBasedataEqpBookByEqpBookId" parameterType="Long" resultMap="BasedataEqpBookResult">
        <include refid="selectBasedataEqpBookVo"/>
        where eqp_book_id = #{eqpBookId}
    </select>

    <select id="selectBasedataEqpBookByEqpBookIds" parameterType="java.util.List" resultMap="BasedataEqpBookResult">
        <include refid="selectBasedataEqpBookVo"/>
        <where>
            eqp_book_id IN
            <foreach item="item" collection="bookIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </where>
    </select>

    <insert id="insertBasedataEqpBook" parameterType="BasedataEqpBook" useGeneratedKeys="true" keyProperty="eqpBookId">
        insert into basedata_eqpbook
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stationName != null">station_name,</if>
            <if test="stationCode != null">station_code,</if>
            <if test="areaId != null">area_id,</if>
            <if test="areaName != null">area_name,</if>
            <if test="patrolDeviceName != null">patrol_device_name,</if>
            <if test="patrolDeviceCode != null">patrol_device_code,</if>
            <if test="deviceModel != null">device_model,</if>
            <if test="manufacturer != null">manufacturer,</if>
            <if test="useUnit != null">use_unit,</if>
            <if test="deviceSource != null">device_source,</if>
            <if test="productionDate != null">production_date,</if>
            <if test="productionCode != null">production_code,</if>
            <if test="isTransport != null">is_transport,</if>
            <if test="useMode != null">use_mode,</if>
            <if test="videoMode != null">video_mode,</if>
            <if test="place != null">place,</if>
            <if test="positionX != null">position_x,</if>
            <if test="positionY != null">position_y,</if>
            <if test="positionZ != null">position_z,</if>
            <if test="type != null">type,</if>
            <if test="patrolDeviceInfo != null">patrol_device_info,</if>
            <if test="robotsCode != null">robots_code,</if>
            <if test="ipAddr != null">ip_addr,</if>
            <if test="port != null">port,</if>
            <if test="user != null">user,</if>
            <if test="password != null">password,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="mainSystemCode != null">main_system_code,</if>
            <if test="mapFilePath != null">map_file_path,</if>
            <if test="videoNvrCode != null">video_nvr_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stationName != null">#{stationName},</if>
            <if test="stationCode != null">#{stationCode},</if>
            <if test="areaId != null">#{areaId},</if>
            <if test="areaName != null">#{areaName},</if>
            <if test="patrolDeviceName != null">#{patrolDeviceName},</if>
            <if test="patrolDeviceCode != null">#{patrolDeviceCode},</if>
            <if test="deviceModel != null">#{deviceModel},</if>
            <if test="manufacturer != null">#{manufacturer},</if>
            <if test="useUnit != null">#{useUnit},</if>
            <if test="deviceSource != null">#{deviceSource},</if>
            <if test="productionDate != null">#{productionDate},</if>
            <if test="productionCode != null">#{productionCode},</if>
            <if test="isTransport != null">#{isTransport},</if>
            <if test="useMode != null">#{useMode},</if>
            <if test="videoMode != null">#{videoMode},</if>
            <if test="place != null">#{place},</if>
            <if test="positionX != null">#{positionX},</if>
            <if test="positionY != null">#{positionY},</if>
            <if test="positionZ != null">#{positionZ},</if>
            <if test="type != null">#{type},</if>
            <if test="patrolDeviceInfo != null">#{patrolDeviceInfo},</if>
            <if test="robotsCode != null">#{robotsCode},</if>
            <if test="ipAddr != null">#{ipAddr},</if>
            <if test="port != null">#{port},</if>
            <if test="user != null">#{user},</if>
            <if test="password != null">#{password},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="mainSystemCode != null">#{mainSystemCode},</if>
            <if test="mapFilePath != null">#{mapFilePath},</if>
            <if test="videoNvrCode != null">#{videoNvrCode},</if>
        </trim>
    </insert>

    <update id="updateBasedataEqpBook" parameterType="BasedataEqpBook">
        update basedata_eqpbook
        <trim prefix="SET" suffixOverrides=",">
            <if test="stationName != null">station_name = #{stationName},</if>
            <if test="stationCode != null">station_code = #{stationCode},</if>
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="areaName != null">area_name = #{areaName},</if>
            <if test="patrolDeviceName != null">patrol_device_name = #{patrolDeviceName},</if>
            <if test="patrolDeviceCode != null">patrol_device_code = #{patrolDeviceCode},</if>
            <if test="deviceModel != null">device_model = #{deviceModel},</if>
            <if test="manufacturer != null">manufacturer = #{manufacturer},</if>
            <if test="useUnit != null">use_unit = #{useUnit},</if>
            <if test="deviceSource != null">device_source = #{deviceSource},</if>
            <if test="productionDate != null">production_date = #{productionDate},</if>
            <if test="productionCode != null">production_code = #{productionCode},</if>
            <if test="isTransport != null">is_transport = #{isTransport},</if>
            <if test="useMode != null">use_mode = #{useMode},</if>
            <if test="videoMode != null">video_mode = #{videoMode},</if>
            <if test="place != null">place = #{place},</if>
            <if test="positionX != null">position_x = #{positionX},</if>
            <if test="positionY != null">position_y = #{positionY},</if>
            <if test="positionZ != null">position_z = #{positionZ},</if>
            <if test="type != null">type = #{type},</if>
            <if test="patrolDeviceInfo != null">patrol_device_info = #{patrolDeviceInfo},</if>
            <if test="robotsCode != null">robots_code = #{robotsCode},</if>
            <if test="ipAddr != null">ip_addr = #{ipAddr},</if>
            <if test="port != null">port = #{port},</if>
            <if test="user != null">user = #{user},</if>
            <if test="password != null">password = #{password},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="mainSystemCode != null">main_system_code = #{mainSystemCode},</if>
            <if test="mapFilePath != null">map_file_path = #{mapFilePath},</if>
            <if test="videoNvrCode != null">video_nvr_code = #{videoNvrCode},</if>
        </trim>
        where eqp_book_id = #{eqpBookId}
    </update>

    <delete id="deleteBasedataEqpBookByEqpBookId" parameterType="Long">
        delete
        from basedata_eqpbook
        where eqp_book_id = #{eqpBookId}
    </delete>

    <delete id="deleteBasedataEqpBookByEqpBookIds" parameterType="String">
        delete from basedata_eqpbook where eqp_book_id in
        <foreach item="eqpBookId" collection="array" open="(" separator="," close=")">
            #{eqpBookId}
        </foreach>
    </delete>

    <select id="getUavList" resultMap="BasedataEqpBookResult">
        SELECT a.eqp_book_id,
               b.dict_label patrol_device_name
        FROM basedata_eqpbook a,
             sys_dict_data b
        WHERE b.dict_type = 'device_type'
          AND a.type = b.dict_value
    </select>

    <select id="checkEqpBookNameUnique" resultMap="BasedataEqpBookResult">
        <include refid="selectBasedataEqpBookVo"/>
        <where>
            patrol_device_name = #{patrolDeviceName}
            <if test="eqpBookId != null">and eqp_book_id != #{eqpBookId}</if>
            limit 1
        </where>
    </select>

    <select id="checkEqpBookCodeUnique" resultMap="BasedataEqpBookResult">
        <include refid="selectBasedataEqpBookVo"/>
        <where>
            patrol_device_code=#{patrolDeviceCode}
            <if test="eqpBookId != null">and eqp_book_id != #{eqpBookId}</if>
            limit 1
        </where>
    </select>

    <select id="getRobotUavList" resultMap="BasedataEqpBookResult">
        SELECT a.eqp_book_id,
               a.patrol_device_name,
               a.patrol_device_code
        FROM basedata_eqpbook a,
             sys_dict_data b
        WHERE b.dict_type = 'device_type_robot_uav'
          AND a.type = b.dict_value
    </select>

    <select id="selectBasedataEqpBookByPatrolDeviceCode" parameterType="String" resultMap="BasedataEqpBookResult">
        <include refid="selectBasedataEqpBookVo"/>
        where patrol_device_code = #{patrolDeviceCode}
    </select>

    <select id="selectPatrolTaskFtpByLineId" parameterType="Long" resultMap="PatrolTaskFtpResult">
        <include refid="selectPatrolTaskFtpVo"/>
        where line_id = #{lineId}
    </select>

    <select id="deviceNumList" resultType="java.util.Map">
        SELECT type, count(1) num
        FROM basedata_eqpbook b
        GROUP BY b.type
    </select>

    <select id="deviceStatusList" resultType="String">
        SELECT count(1) num
        FROM basedata_mont_patdevstadata b1
        WHERE date_format(b1.time, '%y%m%d') = date_format(NOW(), '%y%m%d')
        UNION ALL
        SELECT count(1) num
        FROM basedata_mont_patdevstadata b2
        WHERE date_format(b2.time, '%y%m') = date_format(NOW(), '%y%m')
        UNION ALL
        SELECT count(1) num
        FROM basedata_mont_patdevstadata b3
    </select>
    <resultMap type="BasedataMontPatDevStaData" id="BasedataMontPatDevStaDataResult">
        <result property="montPatDevStaDataId" column="mont_patdevstadata_id"/>
        <result property="eqpBookId" column="eqp_book_id"/>
        <result property="patrolDeviceCode" column="patrol_device_code"/>
        <result property="patrolDeviceName" column="patrol_device_name"/>
        <result property="time" column="time"/>
        <result property="type" column="type"/>
        <result property="typeName" column="type_name"/>
        <result property="value" column="value"/>
        <result property="valueName" column="value_name"/>
        <result property="valueUnit" column="value_unit"/>
        <result property="unit" column="unit"/>
        <!--添加功能J.6.8-->
        <result property="content" column="content"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="deleteFlag" column="delete_flag"/>
    </resultMap>
    <select id="deviceStatusListInfo" resultMap="BasedataMontPatDevStaDataResult">
        SELECT
        *
        FROM
        basedata_mont_patdevstadata b1
        <where>
            <if test="patrolDeviceName != null and patrolDeviceName != ''">AND b1.patrol_device_name like concat('%',
                #{patrolDeviceName}, '%')
            </if>
            <if test="beginTime != null">AND date_format( b1.time, '%y%m%d' ) &gt;= date_format(#{beginTime},'%y%m%d')
            </if>
            <if test="endTime != null">AND date_format( b1.time, '%y%m%d' ) &lt;= date_format(#{endTime},'%y%m%d')</if>
        </where>
    </select>

    <select id="deviceOlinList" resultType="String">
        SELECT count(
                       DISTINCT (bpo.eqp_book_id)) num
        FROM basedata_mont_patdev_online bpo
        WHERE bpo.`status` = '0'
          AND bpo.del_flag != '2'
            AND date_format(bpo.action_time,'%y%m%d') = date_format( NOW(),'%y%m%d')
        UNION ALL
        SELECT count(
                       DISTINCT (bpo.eqp_book_id)) num
        FROM basedata_mont_patdev_online bpo
        WHERE bpo.`status` = '0'
          AND bpo.del_flag != '2'
            AND date_format(bpo.action_time,'%y%m') = date_format( NOW(),'%y%m')
        UNION ALL
        SELECT count(
                       DISTINCT (bpo.eqp_book_id)) num
        FROM basedata_mont_patdev_online bpo
        WHERE bpo.`status` = '0'
          AND bpo.del_flag != '2'
    </select>

    <select id="alarmList" resultType="String">
        SELECT COUNT(1)
        FROM patrol_result a
                 INNER JOIN result_analysis b ON a.line_id = b.business_id
            AND b.result_type = '0'
            AND b.res_status != '2'
	INNER JOIN patrol_task c
        ON a.task_code = c.task_code
            LEFT JOIN patrol_task_info z ON a.device_id = z.device_id
            AND c.task_id = z.task_major_id
            LEFT JOIN basedata_patrolpoint d ON a.device_id = d.patrol_point_id
            LEFT JOIN patrol_preset_pos k ON d.patrol_point_id = k.patrol_point_id
            LEFT JOIN basedata_device e ON d.device_id = e.device_id
            AND e.power_main_equ_flag = "No"
            LEFT JOIN basedata_device f ON d.device_id = f.device_id
            AND f.power_main_equ_flag = "Yes"
            LEFT JOIN basedata_area g ON e.area_id = g.area_id
            LEFT JOIN basedata_devicetype h ON e.device_type_id = h.device_type_id
        WHERE
            date_format( a.create_time
            , '%y%m%d' ) = date_format( NOW()
            , '%y%m%d' )
        UNION ALL
        SELECT COUNT(1)
        FROM patrol_result a
                 INNER JOIN result_analysis b ON a.line_id = b.business_id
            AND b.result_type = '0'
            AND b.res_status != '2'
	INNER JOIN patrol_task c
        ON a.task_code = c.task_code
            LEFT JOIN patrol_task_info z ON a.device_id = z.device_id
            AND c.task_id = z.task_major_id
            LEFT JOIN basedata_patrolpoint d ON a.device_id = d.patrol_point_id
            LEFT JOIN patrol_preset_pos k ON d.patrol_point_id = k.patrol_point_id
            LEFT JOIN basedata_device e ON d.device_id = e.device_id
            AND e.power_main_equ_flag = "No"
            LEFT JOIN basedata_device f ON d.device_id = f.device_id
            AND f.power_main_equ_flag = "Yes"
            LEFT JOIN basedata_area g ON e.area_id = g.area_id
            LEFT JOIN basedata_devicetype h ON e.device_type_id = h.device_type_id
        WHERE
            date_format( a.create_time
            , '%y%m' ) = date_format( NOW()
            , '%y%m' )
        UNION ALL
        SELECT COUNT(1)
        FROM patrol_result a
                 INNER JOIN result_analysis b ON a.line_id = b.business_id
            AND b.result_type = '0'
            AND b.res_status != '2'
	INNER JOIN patrol_task c
        ON a.task_code = c.task_code
            LEFT JOIN patrol_task_info z ON a.device_id = z.device_id
            AND c.task_id = z.task_major_id
            LEFT JOIN basedata_patrolpoint d ON a.device_id = d.patrol_point_id
            LEFT JOIN patrol_preset_pos k ON d.patrol_point_id = k.patrol_point_id
            LEFT JOIN basedata_device e ON d.device_id = e.device_id
            AND e.power_main_equ_flag = "No"
            LEFT JOIN basedata_device f ON d.device_id = f.device_id
            AND f.power_main_equ_flag = "Yes"
            LEFT JOIN basedata_area g ON e.area_id = g.area_id
            LEFT JOIN basedata_devicetype h ON e.device_type_id = h.device_type_id
    </select>
    <resultMap type="PatrolResult" id="PatrolResultResult">
        <result property="lineId" column="line_id"/>
        <result property="patrolDeviceName" column="patrol_device_name"/>
        <result property="patrolDeviceCode" column="patrol_device_code"/>
        <result property="taskName" column="task_name"/>
        <result property="taskCode" column="task_code"/>
        <result property="deviceName" column="device_name"/>
        <result property="deviceId" column="device_id"/>
        <result property="valueType" column="value_type"/>
        <result property="value" column="value"/>
        <result property="valueUnit" column="value_unit"/>
        <result property="unit" column="unit"/>
        <result property="time" column="time"/>
        <result property="recognitionType" column="recognition_type"/>
        <result property="fileType" column="file_type"/>
        <result property="filePath" column="file_path"/>
        <result property="rectangle" column="rectangle"/>
        <result property="taskPatrolledId" column="task_patrolled_id"/>
        <result property="valid" column="valid"/>
        <result property="patrolStatus" column="patrol_status"/>
        <result property="checkPerson" column="check_person"/>
        <result property="checkTime" column="check_time"/>
        <result property="checkResult" column="check_result"/>
        <result property="materialId" column="material_id"/>
        <result property="dataType" column="data_type"/>
        <result property="threshold" column="threshold"/>
        <result property="taskId" column="task_id"/>
        <result property="mainId" column="main_id"/>
        <result property="resultContent" column="result_content"/>
        <result property="devNo" column="dev_no"/>
        <result property="componentName" column="component_name"/>
        <result property="componentId" column="component_id"/>
        <result property="bayName" column="bay_name"/>
        <result property="mainDevId" column="main_dev_id"/>
        <result property="deviceCode" column="device_code"/>
        <result property="areaName" column="area_name"/>
        <result property="phase" column="phase"/>
        <result property="devType" column="devType"/>
        <result property="createTime" column="create_time"/>
        <result property="resStatus" column="res_status"/>
        <result property="pointStatus" column="point_status"/>
        <result property="suggestion" column="suggestion"/>
        <result property="areaId" column="area_id"/>
        <result property="presetPosCode" column="preset_pos_code"/>
        <result property="description" column="description"/>
    </resultMap>
    <select id="alarmListInfo" parameterType="ResultAnalysis" resultMap="PatrolResultResult">
        SELECT
        b.result_content,
        b.create_time,
        b.res_status,
        b.suggestion,
        b.point_status,
        b.description,
        g.area_id,
        g.area_name,
        z.dev_no,
        f.device_name AS device_name,
        e.device_code AS device_code,
        f.device_id AS main_dev_id,
        e.device_name AS component_name,
        e.device_id AS component_id,
        g.area_name AS bay_name,
        f.phy_asset_id AS material_id,
        a.file_type,
        a.file_path,
        a.line_id,
        h.device_type_name AS devType,
        a.device_id,
        h.phase AS phase,
        k.preset_pos_code,
        k.patrol_device_code,
        b.description
        FROM
        patrol_result a
        INNER JOIN result_analysis b ON a.line_id = b.business_id and b.result_type = '0' and b.res_status != '2'
        INNER JOIN patrol_task c ON a.task_code = c.task_code
        LEFT JOIN patrol_task_info z ON a.device_id = z.device_id
        AND c.task_id = z.task_major_id
        LEFT JOIN basedata_patrolpoint d ON a.device_id = d.patrol_point_id
        LEFT JOIN patrol_preset_pos k on d.patrol_point_id = k.patrol_point_id
        LEFT JOIN basedata_device e ON d.device_id = e.device_id
        AND e.power_main_equ_flag = "No"
        LEFT JOIN basedata_device f ON e.parent_id = f.device_id
        AND f.power_main_equ_flag = "Yes"
        LEFT JOIN basedata_area g ON e.area_id = g.area_id
        LEFT JOIN basedata_devicetype h ON e.device_type_id = h.device_type_id
        <where>
            <if test="createTime != null  ">and b.create_time = #{createTime}</if>
            <if test="pointStatus != null  and pointStatus != ''">and b.point_status = #{pointStatus}</if>
            <if test="resultContent != null  and resultContent != ''">and b.result_content like concat
                ('%',#{resultContent},'%')
            </if>
            <if test="mainDevId != null  and mainDevId != ''">and e.parent_id = #{mainDevId}</if>
            <if test="beginTime != null and beginTime != ''">
                and date_format(b.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
            </if>
            <if test="endTime != null and endTime != ''">
                and date_format(b.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
            </if>
        </where>
        order by a.line_id desc
    </select>
    <select id="abnormalList" resultType="String">
        SELECT COUNT(DISTINCT (a.device_id)) num
        FROM patrol_result a
                 INNER JOIN result_analysis b ON a.line_id = b.business_id
            AND b.result_type = '2'
                 INNER JOIN patrol_task c ON a.task_code = c.task_code
                 LEFT JOIN patrol_task_info z ON a.device_id = z.device_id
            AND c.task_id = z.task_major_id
                 LEFT JOIN basedata_patrolpoint d ON a.device_id = d.patrol_point_id
                 LEFT JOIN patrol_preset_pos k ON d.patrol_point_id = k.patrol_point_id
                 LEFT JOIN basedata_device e ON d.device_id = e.device_id
            AND e.power_main_equ_flag = "No"
                 LEFT JOIN basedata_device f ON d.device_id = f.device_id
            AND f.power_main_equ_flag = "Yes"
                 LEFT JOIN basedata_area g ON e.area_id = g.area_id
                 LEFT JOIN basedata_devicetype h ON e.device_type_id = h.device_type_id
        WHERE date_format(a.create_time, '%y%m%d') = date_format(NOW(), '%y%m%d')
        UNION ALL
        SELECT COUNT(DISTINCT (a.device_id)) num
        FROM patrol_result a
                 INNER JOIN result_analysis b ON a.line_id = b.business_id
            AND b.result_type = '2'
                 INNER JOIN patrol_task c ON a.task_code = c.task_code
                 LEFT JOIN patrol_task_info z ON a.device_id = z.device_id
            AND c.task_id = z.task_major_id
                 LEFT JOIN basedata_patrolpoint d ON a.device_id = d.patrol_point_id
                 LEFT JOIN patrol_preset_pos k ON d.patrol_point_id = k.patrol_point_id
                 LEFT JOIN basedata_device e ON d.device_id = e.device_id
            AND e.power_main_equ_flag = "No"
                 LEFT JOIN basedata_device f ON d.device_id = f.device_id
            AND f.power_main_equ_flag = "Yes"
                 LEFT JOIN basedata_area g ON e.area_id = g.area_id
                 LEFT JOIN basedata_devicetype h ON e.device_type_id = h.device_type_id
        WHERE date_format(a.create_time, '%y%m') = date_format(NOW(), '%y%m')
        UNION ALL
        SELECT COUNT(DISTINCT (a.device_id)) num
        FROM patrol_result a
                 INNER JOIN result_analysis b ON a.line_id = b.business_id
            AND b.result_type = '2'
                 INNER JOIN patrol_task c ON a.task_code = c.task_code
                 LEFT JOIN patrol_task_info z ON a.device_id = z.device_id
            AND c.task_id = z.task_major_id
                 LEFT JOIN basedata_patrolpoint d ON a.device_id = d.patrol_point_id
                 LEFT JOIN patrol_preset_pos k ON d.patrol_point_id = k.patrol_point_id
                 LEFT JOIN basedata_device e ON d.device_id = e.device_id
            AND e.power_main_equ_flag = "No"
                 LEFT JOIN basedata_device f ON d.device_id = f.device_id
            AND f.power_main_equ_flag = "Yes"
                 LEFT JOIN basedata_area g ON e.area_id = g.area_id
                 LEFT JOIN basedata_devicetype h ON e.device_type_id = h.device_type_id
    </select>


    <select id="abnormalListInfo" parameterType="ResultAnalysis" resultMap="PatrolResultResult">
        SELECT
        b.result_content,
        b.create_time,
        b.res_status,
        b.suggestion,
        b.point_status,
        b.description,
        g.area_id,
        g.area_name,
        z.dev_no,
        f.device_name AS device_name,
        e.device_code AS device_code,
        f.device_id AS main_dev_id,
        e.device_name AS component_name,
        e.device_id AS component_id,
        g.area_name AS bay_name,
        f.phy_asset_id AS material_id,
        a.file_type,
        a.file_path,
        a.line_id,
        h.device_type_name AS devType,
        a.device_id,
        h.phase AS phase,
        k.preset_pos_code,
        k.patrol_device_code
        FROM
        patrol_result a
        INNER JOIN result_analysis b ON a.line_id = b.business_id and b.result_type = '2'
        INNER JOIN patrol_task c ON a.task_code = c.task_code
        LEFT JOIN patrol_task_info z ON a.device_id = z.device_id
        AND c.task_id = z.task_major_id
        LEFT JOIN basedata_patrolpoint d ON a.device_id = d.patrol_point_id
        LEFT JOIN patrol_preset_pos k on d.patrol_point_id = k.patrol_point_id
        LEFT JOIN basedata_device e ON d.device_id = e.device_id
        AND e.power_main_equ_flag = "No"
        LEFT JOIN basedata_device f ON e.parent_id = f.device_id
        AND f.power_main_equ_flag = "Yes"
        LEFT JOIN basedata_area g ON e.area_id = g.area_id
        LEFT JOIN basedata_devicetype h ON e.device_type_id = h.device_type_id
        <where>
            <if test="createTime != null  ">and b.create_time = #{createTime}</if>
            <if test="pointStatus != null  and pointStatus != ''">and b.point_status = #{pointStatus}</if>
            <if test="deviceName != null  and deviceName != ''">and f.device_name like concat ('%',#{deviceName},'%')
            </if>
            <if test="resultContent != null  and resultContent != ''">and b.result_content like concat
                ('%',#{resultContent},'%')
            </if>
            <if test="beginTime != null and beginTime != ''">
                and date_format(b.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
            </if>
            <if test="endTime != null and endTime != ''">
                and date_format(b.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
            </if>
        </where>
        order by a.line_id desc
    </select>
    <resultMap type="BasedataPatrolPoint" id="BasedataPatrolPointResult">
        <result property="patrolPointId" column="patrol_point_id"/>
        <result property="relationAreaId" column="relation_area_id"/>
        <result property="patrolPointName" column="patrol_point_name"/>
        <result property="parentName" column="parent_name"/>
        <result property="alarmThreshold" column="alarm_threshold"/>
        <result property="algSubtypeIds" column="alg_subtype_ids"/>
        <result property="lowerValue" column="lower_value"/>
        <result property="upperValue" column="upper_value"/>
        <result property="deviceName" column="device_name"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <select id="getSubtypeData" resultMap="BasedataPatrolPointResult">
        SELECT
        a.patrol_point_id,
        a.relation_area_id,
        (SELECT c.device_name FROM basedata_device c WHERE c.device_id = b.parent_id) parent_name,
        b.device_name,
        a.patrol_point_name,
        a.alarm_threshold,
        a.alg_subtype_ids,
        IFNULL(a.update_time, a.create_time) AS update_time
        FROM
        basedata_patrolpoint a,
        basedata_device b
        WHERE
        a.device_id = b.device_id
        AND a.alarm_threshold != ''
        AND a.alarm_threshold != '[]'
        <if test="deviceName != null  and deviceName != ''">and b.device_name = #{deviceName}</if>
        <if test="patrolPointName != null  and patrolPointName != ''">and a.patrol_point_name like concat('%',
            #{patrolPointName}, '%')</if>
        <if test="algSubtypeIds != null and algSubtypeIds != ''">
            AND a.alg_subtype_ids REGEXP CONCAT('(^|,)(', REPLACE(#{algSubtypeIds}, ',', '|'), ')(,|$)')
        </if>
        ORDER BY
        update_time DESC,
        a.device_id
    </select>

    <select id="selectDevInfoById" parameterType="String" resultType="java.util.Map">
        select *
        from basedata_device a
        where a.device_id = #{deviceId}
    </select>

    <select id="selectBasePointByPointId" parameterType="String" resultType="java.util.Map">
        select a.*
        FROM basedata_patrolpoint a
        where a.patrol_point_id = #{pointId}
    </select>
    <select id="selectBasePointPre" parameterType="String" resultType="java.util.Map">
        select a.*
        FROM basedata_patrolpoint_preset a
        where a.patrol_point_id = #{pointId}
    </select>

    <select id="selectPointInfoById" parameterType="String" resultType="java.util.Map">
        select *
        from basedata_patrolpoint
        where patrol_point_id = #{deviceId}
    </select>

    <resultMap type="BasedataEqpBookChannel" id="BasedataEqpBookChannelResult">
        <result property="channelId" column="channel_id"/>
        <result property="channelCode" column="channel_code"/>
        <result property="channelName" column="channel_name"/>
        <result property="parentChannelId" column="parent_channel_id"/>
        <result property="eqpBookId" column="eqp_book_id"/>
        <result property="channelType" column="channel_type"/>
        <result property="onlineState" column="online_state"/>
        <result property="channelContent" column="channel_content"/>
        <result property="provider" column="provider"/>
        <result property="address" column="address"/>
        <result property="host" column="host"/>
        <result property="port" column="port"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="deleteFlag" column="delete_flag"/>
        <result property="patrolDeviceCode" column="patrol_device_code"/>
        <result property="username" column="username"/>
        <result property="password" column="password"/>
    </resultMap>

    <select id="queryEqpBookCode" parameterType="String" resultType="String">
        SELECT b.channel_code
        FROM basedata_eqpbook a,
             basedata_eqpbook_channel b
        WHERE a.main_system_code = #{patrolDeviceCode}
          AND a.eqp_book_id = b.eqp_book_id
          AND b.channel_type = 'ir' limit 1;
    </select>

</mapper>
