<?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.smartapplication.temperaturerecord.mapper.TemperatureRecordMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="temperatureRecordResultMap" type="org.springblade.smartapplication.temperaturerecord.entity.TemperatureRecord">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <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="original_picture_url" property="originalPictureUrl"/>
        <result column="face_url" property="faceUrl"/>
        <result column="infrared_original_picture_url" property="infraredOriginalPictureUrl"/>
        <result column="infrared_face_url" property="infraredFaceUrl"/>
        <result column="camera_id" property="cameraId"/>
        <result column="camera_name" property="cameraName"/>
        <result column="recog_time" property="recogTime"/>
        <result column="temperature" property="temperature"/>
        <result column="device_id" property="deviceId"/>
        <result column="device_name" property="deviceName"/>
        <result column="match_value" property="matchValue"/>
        <result column="person_name" property="personName"/>
        <result column="phone" property="phone"/>
        <result column="address" property="address"/>
        <result column="age" property="age"/>
        <result column="type" property="type"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
        <result column="gender" property="gender"/>
        <result column="org_position" property="orgPosition"/>
        <result column="is_exception" property="isException"/>
        <result column="product_id" property="productId"/>
    </resultMap>


    <select id="selectTemperatureRecordPage" resultMap="temperatureRecordResultMap">
        select record.id,record.create_user,record.create_dept,record.create_time,record.update_user,record.update_time,record.status,record.is_deleted,record.original_picture_url,
        record.face_url,record.infrared_original_picture_url,record.infrared_face_url,record.camera_id,record.camera_name,record.recog_time,record.temperature,record.device_id,
        record.match_value,record.person_name,record.phone,record.address,record.age,record.type,record.longitude,record.latitude,record.gender,record.org_position,
        device.name AS device_name from yc_temperature_record record
        left JOIN yc_temperature_device device on device.device_id = record.device_id
        where record.is_deleted = 0

        <if test="temperatureRecord != null">
            <if test="temperatureRecord.personName != null and temperatureRecord.personName.trim() != '' ">
                and record.person_name like '%${temperatureRecord.personName}%'
            </if>
            <if test="temperatureRecord.gender != null and temperatureRecord.gender.trim() != '' ">
                and record.gender = '${temperatureRecord.gender}'
            </if>
            <if test="temperatureRecord.address != null and temperatureRecord.address.trim() != '' ">
                and record.address like '%${temperatureRecord.address}%'
            </if>
            <if test="temperatureRecord.phone != null and temperatureRecord.phone.trim() != '' ">
                and record.phone like '%${temperatureRecord.phone}%'
            </if>
            <if test="temperatureRecord.deviceId != null and temperatureRecord.deviceId.trim() != '' ">
                and record.device_id like '%${temperatureRecord.deviceId}%'
            </if>
            <if test="temperatureRecord.deviceName != null and temperatureRecord.deviceName.trim() != '' ">
                and device.name like '%${temperatureRecord.deviceName}%'
            </if>
        </if>


        ORDER BY recog_time DESC

    </select>

</mapper>
