<?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.FaceMapper">
    <insert id="add">
        insert into face(id, scenic_id, score, member_id, face_url, match_sample_ids, first_match_rate, match_result)
        values (#{id}, #{scenicId}, #{score}, #{memberId}, #{faceUrl}, #{matchSampleIds}, #{firstMatchRate}, #{matchResult})
    </insert>
    <update id="update">
        update face
        <set>
            <if test="scenicId!= null ">
                scenic_id = #{scenicId},
            </if>
            <if test="memberId!= null ">
                member_id = #{memberId},
            </if>
            <if test="score!= null ">
                score = #{score},
            </if>
            <if test="faceUrl!= null and faceUrl!= ''">
                face_url = #{faceUrl},
            </if>
            match_sample_ids = #{matchSampleIds},
            first_match_rate = #{firstMatchRate},
            match_result = #{matchResult},
        </set>
        where id = #{id}
    </update>
    <update id="finishedJourney">
        update face set finished_journey = 1 where id = #{id}
    </update>
    <delete id="deleteById">
        update face set is_delete = 1 where id = #{id}
    </delete>
    <delete id="deleteByIds">
    <if test="list!= null and list.size() > 0">
        update face set is_delete = 1 where id in (
        <foreach collection="list" item="id" separator=",">
            #{id}
        </foreach>
        )
    </if>
    </delete>
    <select id="list" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO">
        select id, scenic_id, member_id, face_url,score, match_sample_ids, first_match_rate, match_result
        from face
        <where>
            is_delete = 0
            <if test="memberId!= null and memberId!= ''">
                and member_id = #{memberId}
            </if>
            <if test="scenicId!= null">
                and scenic_id = #{scenicId}
            </if>
            <if test="matchSampleIds!= null and matchSampleIds!= ''">
                and match_sample_ids like concat('%', #{matchSampleIds}, '%')
            </if>
            <if test="startMatchRate!= null ">
                and first_match_rate &gt;= #{startMatchRate}
            </if>
            <if test="endMatchRate!= null ">
                and first_match_rate &lt;= #{endMatchRate}
            </if>
            <if test="startTime!=null">
                and create_at >= #{startTime}
            </if>
            <if test="endTime!=null">
                and create_at &lt;= #{endTime}
            </if>
            <if test="updateStartTime!=null">
                and update_at >= #{updateStartTime}
            </if>
            <if test="updateEndTime!=null">
                and update_at &lt;= #{updateEndTime}
            </if>
        </where>
    </select>
    <select id="getById" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO">
        select id, scenic_id, member_id, face_url,score, match_sample_ids, first_match_rate, match_result, create_at, update_at
        from face
        where id = #{id}
    </select>
    <select id="getLatestByMemberId" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO">
        select id, scenic_id, member_id, face_url,score, match_sample_ids, first_match_rate, match_result, create_at, update_at
        from face
        where member_id = #{userId} and scenic_id = #{scenicId} and is_delete = 0
        order by update_at desc
        limit 1
    </select>
    <select id="listByScenicIdAndNotFinished" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO">
        select id, scenic_id, member_id, face_url,score, match_sample_ids, first_match_rate, match_result, create_at, update_at
        from face
        where scenic_id = #{scenicId} and finished_journey != 1 and is_delete = 0
    </select>
    <select id="findLastFaceByUserId" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO">
        select id, scenic_id, member_id, face_url,score, match_sample_ids, first_match_rate, match_result, create_at, update_at
        from face
        where member_id = #{userId} and is_delete = 0
        order by update_at desc
        limit 1
    </select>
    <select id="get" resultType="com.ycwl.basic.model.pc.face.entity.FaceEntity">
        select *
        from face
        where id = #{id}
    </select>
    <select id="listByScenicAndUserId" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO">
        select id, face_url, create_at, update_at
        from face
        where member_id = #{userId} and scenic_id = #{scenicId} and is_delete = 0
        order by update_at desc
    </select>
    <select id="findLastFaceByScenicAndUserId" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO">
        select id, scenic_id, member_id, face_url,score, match_sample_ids, first_match_rate, match_result, create_at, update_at
        from face
        where member_id = #{userId} and scenic_id = #{scenicId} and is_delete = 0
        order by update_at desc
        limit 1
    </select>
    <select id="test" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO">
        SELECT * FROM `zt`.`face_sample` WHERE `scenic_id` = '3930324797233434624' AND `create_at` &lt; '2025-03-07 14:40:36' AND `device_id` = '3961959104355897344'
    </select>
    <select id="listEntityBeforeDate" resultType="com.ycwl.basic.model.pc.face.entity.FaceEntity">
        SELECT * FROM `zt`.`face` WHERE `scenic_id` = #{scenicId} AND `create_at` &lt; #{date}
    </select>
</mapper>
