<?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.ycwl.basic.mapper.FaceSampleMapper">
    <insert id="add">
        insert into face_sample(id, scenic_id, device_id, face_url, match_sample_ids, first_match_rate, match_result,`status`, create_at)
        values (#{id}, #{scenicId}, #{deviceId}, #{faceUrl}, #{matchSampleIds}, #{firstMatchRate}, #{matchResult},#{status},#{createAt})
    </insert>
    <update id="update">
        update face_sample
        <set>
            <if test="scenicId!= null ">
                scenic_id = #{scenicId},
            </if>
            <if test="deviceId!= null ">
                device_id = #{deviceId},
            </if>
            <if test="faceUrl!= null and faceUrl!= ''">
                face_url = #{faceUrl},
            </if>
            <if test="matchSampleIds!= null and matchSampleIds!= ''">
                match_sample_ids = #{matchSampleIds},
            </if>
            <if test="firstMatchRate!= null ">
                first_match_rate = #{firstMatchRate},
            </if>
            <if test="matchResult!= null and matchResult!= ''">
                match_result = #{matchResult},
            </if>
            <if test="status!= null ">
                `status` = #{status},
            </if>
            <if test="score!= null ">
                `score` = #{score},
            </if>
            update_at = now(),
        </set>
        where id = #{id}
    </update>
    <delete id="deleteById">
        delete from face_sample where id = #{id}
    </delete>
    <delete id="deleteByIds">
        <if test="list!= null and list.size() > 0">
            delete from face_sample where id in (
            <foreach collection="list" item="id" separator=",">
                #{id}
            </foreach>
            )
        </if>
    </delete>
    <select id="list" resultType="com.ycwl.basic.model.pc.faceSample.resp.FaceSampleRespVO">
        select f.id, f.scenic_id, s.name scenicName, device_id, d.name deviceName, face_url, f.score, match_sample_ids, first_match_rate, match_result, f.`status`, f.create_at
        from face_sample f
        left join scenic s on s.id = f.scenic_id
        left join device d on d.id = f.device_id
        <where>
            <if test="scenicId!= null and scenicId!= ''">
                and f.scenic_id = #{scenicId}
            </if>
            <if test="deviceId!= null and deviceId!= ''">
                and device_id = #{deviceId}
            </if>
            <if test="matchSampleIds!= null and matchSampleIds!= ''">
                and match_sample_ids like concat('%', #{matchSampleIds}, '%')
            </if>
            <if test="startTime!=null">
                and f.create_at >= #{startTime}
            </if>
            <if test="endTime!=null">
                and f.create_at &lt;= #{endTime}
            </if>
            <if test="status!= null ">
                and f.`status` = #{status}
            </if>
        </where>
        ORDER BY f.create_at desc
    </select>
    <select id="getById" resultType="com.ycwl.basic.model.pc.faceSample.resp.FaceSampleRespVO">
        select id, scenic_id, device_id, face_url, match_sample_ids, first_match_rate, match_result,`status`, create_at
        from face_sample
        where id = #{id}
    </select>
    <select id="listByIds" resultType="com.ycwl.basic.model.pc.faceSample.entity.FaceSampleEntity">
        select *
        from face_sample
        where id in (
        <foreach collection="list" item="id" separator=",">
            #{id}
        </foreach>
        )
        order by create_at desc
    </select>
    <select id="getEntity" resultType="com.ycwl.basic.model.pc.faceSample.entity.FaceSampleEntity">
        select *
        from face_sample
        where id = #{id}
    </select>
    <select id="listEntityBeforeDate" resultType="com.ycwl.basic.model.pc.faceSample.entity.FaceSampleEntity">
        select *
        from face_sample
        where scenic_id = #{scenicId} and create_at &lt;= #{endDate}
    </select>
</mapper>
