<?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.zcloud.fire.check.persistence.mapper.FireCheckRecordPointMapper">

     <select id="getCheckRecordPointList" resultType="com.zcloud.fire.check.persistence.dataobject.FireCheckRecordPointDO">
        select GROUP_CONCAT(DISTINCT crd.fire_device_code)      as fireDeviceCode,
               GROUP_CONCAT(DISTINCT crd.fire_device_type_name) as fireDeviceTypeName,
               cfp.fire_region_code                             as fireRegionCode,
               cfp.fire_region_id                               as fireRegionId,
               cfp.fire_region_name                             as fireRegionName,
               cfp.fire_point_code                              as firePointCode,
               cfp.fire_point_id                                as firePointId,
               cfp.fire_point_name                              as firePointName,
               cfp.checked_flag                                as checkedFlag,
               cfp.fire_record_id                              as fireRecordId,
               cfp.fire_record_point_id                          as fireRecordPointId,
               cfp.fire_check_id                              as fireCheckId,
                cfp.id
        from fire_check_record_point cfp
                 left join fire_check_record_device crd
                           on crd.fire_record_point_id = cfp.fire_record_point_id and
                              crd.delete_enum = 'FALSE'
         left join fire_point fp on fp.fire_point_id = cfp.fire_point_id
        where cfp.fire_record_id = #{fireRecordId}
          and crd.delete_enum = 'FALSE'
         <if test="checkedFlag != null">
             and crd.checked_flag = #{checkedFlag}
         </if>
        group by cfp.fire_record_point_id
         order by fp.create_time desc ,cfp.create_time desc

    </select>
    <select id="getLastThreeRecord" resultType="string">
        select fire_record_point_id
        from fire_check_record_point
        where fire_point_id = #{firePointId}
        group by fire_record_point_id
        order by create_time desc
            limit 3
    </select>
    <select id="getCheckRecordPointListByCheckRecordIds" resultType="com.zcloud.fire.check.persistence.dataobject.FireCheckRecordPointDO">
        select crp.fire_record_id,
        GROUP_CONCAT(DISTINCT fr.fire_region_name) as fireRegionName,
        GROUP_CONCAT(DISTINCT fr.fire_region_code) as fireRegionCode,
        GROUP_CONCAT(DISTINCT frp.fire_point_name) as firePointName,
        GROUP_CONCAT(DISTINCT frp.fire_point_code) as firePointCode
        from fire_check_record_point crp
        left join fire_region fr on fr.fire_region_id = crp.fire_region_id
        left join fire_point frp on frp.fire_point_id = crp.fire_point_id
        where crp.delete_enum = 'FALSE'
        and crp.fire_record_id in
            <foreach item="item" collection="fireCheckRecordIdList" separator="," open="(" close=")" index="">
                #{item}
            </foreach>
        group by crp.fire_record_id
    </select>
</mapper>

