清理过期人脸

This commit is contained in:
Jerry Yan 2025-02-26 13:43:54 +08:00
parent 99f5adf841
commit 0aadd1d064
4 changed files with 52 additions and 7 deletions

View File

@ -43,4 +43,5 @@ public class FaceEntity {
private String matchResult; private String matchResult;
private Date createAt; private Date createAt;
private Date updateAt; private Date updateAt;
private int isDelete;
} }

View File

@ -32,5 +32,7 @@ public class FaceReqQuery extends BaseQueryParameterReq {
private String matchResult; private String matchResult;
private Date startTime; private Date startTime;
private Date endTime; private Date endTime;
private Date updateStartTime;
private Date updateEndTime;
private Integer finishedJourney; private Integer finishedJourney;
} }

View File

@ -1,10 +1,13 @@
package com.ycwl.basic.task; package com.ycwl.basic.task;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.ycwl.basic.mapper.FaceMapper;
import com.ycwl.basic.mapper.FaceSampleMapper; import com.ycwl.basic.mapper.FaceSampleMapper;
import com.ycwl.basic.mapper.ScenicMapper; import com.ycwl.basic.mapper.ScenicMapper;
import com.ycwl.basic.mapper.SourceMapper; import com.ycwl.basic.mapper.SourceMapper;
import com.ycwl.basic.mapper.VideoMapper; import com.ycwl.basic.mapper.VideoMapper;
import com.ycwl.basic.model.pc.face.req.FaceReqQuery;
import com.ycwl.basic.model.pc.face.resp.FaceRespVO;
import com.ycwl.basic.model.pc.faceSample.req.FaceSampleReqQuery; import com.ycwl.basic.model.pc.faceSample.req.FaceSampleReqQuery;
import com.ycwl.basic.model.pc.faceSample.resp.FaceSampleRespVO; import com.ycwl.basic.model.pc.faceSample.resp.FaceSampleRespVO;
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity; import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
@ -29,6 +32,8 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import static com.ycwl.basic.constant.FaceConstant.USER_FACE_DB_NAME;
@Component @Component
@EnableScheduling @EnableScheduling
@Slf4j @Slf4j
@ -45,6 +50,8 @@ public class FaceCleaner {
private VideoMapper videoMapper; private VideoMapper videoMapper;
@Autowired @Autowired
private ScenicRepository scenicRepository; private ScenicRepository scenicRepository;
@Autowired
private FaceMapper faceMapper;
@Scheduled(cron = "0 0 4 * * ?") @Scheduled(cron = "0 0 4 * * ?")
public void clean(){ public void clean(){
@ -56,6 +63,31 @@ public class FaceCleaner {
}); });
} }
@Scheduled(cron = "0 0 3 * * ?")
public void deleteExpireFace() {
ScenicReqQuery scenicQuery = new ScenicReqQuery();
List<ScenicRespVO> scenicList = scenicMapper.list(scenicQuery);
scenicList.parallelStream().forEach(scenic -> {
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenic.getId());
Integer sampleStoreDay = scenicConfig.getSampleStoreDay();
if (sampleStoreDay == null) {
log.info("当前景区{}人脸样本保存天数未设置默认3天", scenic.getName());
sampleStoreDay = 3;
}
FaceReqQuery req = new FaceReqQuery();
req.setScenicId(scenic.getId());
req.setUpdateEndTime(DateUtil.offsetDay(DateUtil.beginOfDay(new Date()), -sampleStoreDay));
List<FaceRespVO> list = faceMapper.list(req);
list.forEach(face -> {
boolean result = faceService.deleteFaceSample(USER_FACE_DB_NAME+face.getScenicId(), face.getId().toString());
if (result) {
faceMapper.deleteById(face.getId());
}
});
log.info("当前景区{},删除人脸样本{}个", scenic.getName(), list.size());
});
}
@Scheduled(cron = "0 0 3 * * ?") @Scheduled(cron = "0 0 3 * * ?")
public void deleteNotBuySource(){ public void deleteNotBuySource(){
ScenicReqQuery scenicQuery = new ScenicReqQuery(); ScenicReqQuery scenicQuery = new ScenicReqQuery();

View File

@ -30,11 +30,11 @@
update face set finished_journey = 1 where id = #{id} update face set finished_journey = 1 where id = #{id}
</update> </update>
<delete id="deleteById"> <delete id="deleteById">
delete from face where id = #{id} update face set is_delete = 1 where id = #{id}
</delete> </delete>
<delete id="deleteByIds"> <delete id="deleteByIds">
<if test="list!= null and list.size() > 0"> <if test="list!= null and list.size() > 0">
delete from face where id in ( update face set is_delete = 1 where id in (
<foreach collection="list" item="id" separator=","> <foreach collection="list" item="id" separator=",">
#{id} #{id}
</foreach> </foreach>
@ -45,9 +45,13 @@
select id, scenic_id, member_id, face_url,score, match_sample_ids, first_match_rate, match_result select id, scenic_id, member_id, face_url,score, match_sample_ids, first_match_rate, match_result
from face from face
<where> <where>
is_delete = 0
<if test="memberId!= null and memberId!= ''"> <if test="memberId!= null and memberId!= ''">
and member_id = #{memberId} and member_id = #{memberId}
</if> </if>
<if test="scenicId!= null">
and scenic_id = #{scenicId}
</if>
<if test="matchSampleIds!= null and matchSampleIds!= ''"> <if test="matchSampleIds!= null and matchSampleIds!= ''">
and match_sample_ids like concat('%', #{matchSampleIds}, '%') and match_sample_ids like concat('%', #{matchSampleIds}, '%')
</if> </if>
@ -63,6 +67,12 @@
<if test="endTime!=null"> <if test="endTime!=null">
and create_at &lt;= #{endTime} and create_at &lt;= #{endTime}
</if> </if>
<if test="updateStartTime!=null">
and update_at >= #{updateStartTime}
</if>
<if test="updateEndTime!=null">
and update_at &lt;= #{updateEndTime}
</if>
</where> </where>
</select> </select>
<select id="getById" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO"> <select id="getById" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO">
@ -73,19 +83,19 @@
<select id="getLatestByMemberId" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO"> <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 select id, scenic_id, member_id, face_url,score, match_sample_ids, first_match_rate, match_result, create_at, update_at
from face from face
where member_id = #{userId} and scenic_id = #{scenicId} where member_id = #{userId} and scenic_id = #{scenicId} and is_delete = 0
order by update_at desc order by update_at desc
limit 1 limit 1
</select> </select>
<select id="listByScenicIdAndNotFinished" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO"> <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 select id, scenic_id, member_id, face_url,score, match_sample_ids, first_match_rate, match_result, create_at, update_at
from face from face
where scenic_id = #{scenicId} and finished_journey != 1 where scenic_id = #{scenicId} and finished_journey != 1 and is_delete = 0
</select> </select>
<select id="findLastFaceByUserId" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO"> <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 select id, scenic_id, member_id, face_url,score, match_sample_ids, first_match_rate, match_result, create_at, update_at
from face from face
where member_id = #{userId} where member_id = #{userId} and is_delete = 0
order by update_at desc order by update_at desc
limit 1 limit 1
</select> </select>
@ -97,13 +107,13 @@
<select id="listByScenicAndUserId" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO"> <select id="listByScenicAndUserId" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO">
select id, face_url, create_at, update_at select id, face_url, create_at, update_at
from face from face
where member_id = #{userId} and scenic_id = #{scenicId} where member_id = #{userId} and scenic_id = #{scenicId} and is_delete = 0
order by update_at desc order by update_at desc
</select> </select>
<select id="findLastFaceByScenicAndUserId" resultType="com.ycwl.basic.model.pc.face.resp.FaceRespVO"> <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 select id, scenic_id, member_id, face_url,score, match_sample_ids, first_match_rate, match_result, create_at, update_at
from face from face
where member_id = #{userId} and scenic_id = #{scenicId} where member_id = #{userId} and scenic_id = #{scenicId} and is_delete = 0
order by update_at desc order by update_at desc
limit 1 limit 1
</select> </select>