feat(source): 新增根据人脸和设备ID获取素材的功能

- 在SourceMapper接口中新增getSourceByFaceAndDeviceId方法
- 支持通过faceId、deviceId、type和排序策略查询特定素材
- 在XML映射文件中实现对应的SQL查询逻辑
- 支持多种排序策略:最新、最早、评分降序、评分升序、随机和已购买优先
- 查询结果限制为一条记录
This commit is contained in:
2025-11-20 14:55:28 +08:00
parent 8d2d0901fd
commit aaa8d8310a
2 changed files with 43 additions and 0 deletions

View File

@@ -131,4 +131,14 @@ public interface SourceMapper {
* @return 设备ID列表
*/
List<Long> getDeviceIdsByFaceId(Long faceId);
/**
* 根据faceId和设备ID获取source
* @param faceId 人脸ID
* @param deviceId 设备ID
* @param type 素材类型(1-视频,2-图片)
* @param sortStrategy 排序策略
* @return source实体
*/
SourceEntity getSourceByFaceAndDeviceId(Long faceId, Long deviceId, Integer type, String sortStrategy);
}

View File

@@ -410,4 +410,37 @@
WHERE ms.face_id = #{faceId}
ORDER BY s.device_id ASC
</select>
<select id="getSourceByFaceAndDeviceId" resultType="com.ycwl.basic.model.pc.source.entity.SourceEntity">
SELECT s.*
FROM source s
INNER JOIN member_source ms ON s.id = ms.source_id
WHERE ms.face_id = #{faceId}
AND s.device_id = #{deviceId}
AND s.type = #{type}
<choose>
<when test='sortStrategy == "LATEST"'>
ORDER BY s.create_time DESC
</when>
<when test='sortStrategy == "EARLIEST"'>
ORDER BY s.create_time ASC
</when>
<when test='sortStrategy == "SCORE_DESC"'>
ORDER BY IFNULL(s.score, 0) DESC, s.create_time DESC
</when>
<when test='sortStrategy == "SCORE_ASC"'>
ORDER BY IFNULL(s.score, 0) ASC, s.create_time ASC
</when>
<when test='sortStrategy == "RANDOM"'>
ORDER BY RAND()
</when>
<when test='sortStrategy == "PURCHASED_FIRST"'>
ORDER BY ms.is_buy DESC, s.create_time DESC
</when>
<otherwise>
ORDER BY s.create_time DESC
</otherwise>
</choose>
LIMIT 1
</select>
</mapper>