feat(source): 添加根据sourceId查询faceId和根据faceId分页查询source的功能

- 在SourceController中新增getFaceIdsBySourceIds接口,支持根据sourceId列表查询关联的faceId
- 在SourceController中新增pageByFaceId接口,支持根据faceId分页查询关联的source记录
- 在SourceMapper中新增listFaceIdsBySourceIds和pageByFaceId数据访问方法
- 在SourceService中实现getFaceIdsBySourceIds和pageByFaceId业务逻辑
- 在SourceMapper.xml中新增对应的SQL查询语句
- 添加MemberSourceEntity实体类引用和LinkedHashMap导入
- 实现空值处理和分页功能,确保查询结果准确性
This commit is contained in:
2026-02-11 16:38:30 +08:00
parent 13b1b37c8a
commit 122d430dbb
5 changed files with 100 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ import com.ycwl.basic.utils.JwtTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
@@ -74,5 +75,24 @@ public class SourceController {
}
}
/**
* 根据sourceId列表查询关联的faceId
* @param sourceIds sourceId列表
* @return sourceId -> faceId 的映射,无关联则value为null
*/
@PostMapping("/faceIds")
public ApiResponse<Map<Long, Long>> getFaceIdsBySourceIds(@RequestBody List<Long> sourceIds) {
return sourceService.getFaceIdsBySourceIds(sourceIds);
}
/**
* 根据faceId分页查询关联的source记录
* @param sourceReqQuery 查询参数(需设置faceId,可选type/scenicId/isBuy)
* @return 分页source列表
*/
@PostMapping("/pageByFaceId")
public ApiResponse pageByFaceId(@RequestBody SourceReqQuery sourceReqQuery) {
return sourceService.pageByFaceId(sourceReqQuery);
}
}

View File

@@ -181,4 +181,18 @@ public interface SourceMapper {
* @return source实体列表
*/
List<SourceEntity> listSourceByFaceRelation(Long faceId, Integer type);
/**
* 根据sourceId列表查询关联的faceId
* @param sourceIds sourceId列表
* @return member_source记录列表(包含sourceId和faceId)
*/
List<MemberSourceEntity> listFaceIdsBySourceIds(List<Long> sourceIds);
/**
* 根据faceId分页查询关联的source记录
* @param sourceReqQuery 查询参数(需设置faceId)
* @return source响应列表
*/
List<SourceRespVO> pageByFaceId(SourceReqQuery sourceReqQuery);
}

View File

@@ -8,6 +8,7 @@ import com.ycwl.basic.utils.ApiResponse;
import java.io.File;
import java.util.List;
import java.util.Map;
/**
* @Author:longbinbin
@@ -23,4 +24,18 @@ public interface SourceService {
ApiResponse cutVideo(Long id);
String uploadAndUpdateUrl(Long id, File file);
/**
* 根据sourceId列表查询关联的faceId
* @param sourceIds sourceId列表
* @return sourceId -> faceId 的映射
*/
ApiResponse<Map<Long, Long>> getFaceIdsBySourceIds(List<Long> sourceIds);
/**
* 根据faceId分页查询关联的source记录
* @param sourceReqQuery 查询参数(需设置faceId)
* @return 分页结果
*/
ApiResponse<PageInfo<SourceRespVO>> pageByFaceId(SourceReqQuery sourceReqQuery);
}

View File

@@ -7,6 +7,7 @@ import com.ycwl.basic.integration.scenic.dto.scenic.ScenicV2DTO;
import com.ycwl.basic.mapper.SourceMapper;
import com.ycwl.basic.model.pc.device.entity.DeviceEntity;
import com.ycwl.basic.model.pc.scenic.entity.ScenicEntity;
import com.ycwl.basic.model.pc.source.entity.MemberSourceEntity;
import com.ycwl.basic.model.pc.source.entity.SourceEntity;
import com.ycwl.basic.model.pc.source.req.SourceReqQuery;
import com.ycwl.basic.model.pc.source.resp.SourceRespVO;
@@ -29,6 +30,7 @@ import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -201,4 +203,33 @@ public class SourceServiceImpl implements SourceService {
throw new BaseException("文件上传失败: " + e.getMessage());
}
}
@Override
public ApiResponse<Map<Long, Long>> getFaceIdsBySourceIds(List<Long> sourceIds) {
if (sourceIds == null || sourceIds.isEmpty()) {
return ApiResponse.success(Collections.emptyMap());
}
List<MemberSourceEntity> relations = sourceMapper.listFaceIdsBySourceIds(sourceIds);
Map<Long, Long> faceIdMap = relations.stream()
.collect(Collectors.toMap(
MemberSourceEntity::getSourceId,
MemberSourceEntity::getFaceId,
(existing, replacement) -> existing,
LinkedHashMap::new
));
// 对于没有关联的sourceId,填充null
Map<Long, Long> result = new LinkedHashMap<>();
for (Long sourceId : sourceIds) {
result.put(sourceId, faceIdMap.get(sourceId));
}
return ApiResponse.success(result);
}
@Override
public ApiResponse<PageInfo<SourceRespVO>> pageByFaceId(SourceReqQuery sourceReqQuery) {
PageHelper.startPage(sourceReqQuery.getPageNum(), sourceReqQuery.getPageSize());
List<SourceRespVO> list = sourceMapper.pageByFaceId(sourceReqQuery);
PageInfo<SourceRespVO> pageInfo = new PageInfo<>(list);
return ApiResponse.success(pageInfo);
}
}

View File

@@ -523,4 +523,24 @@
</if>
ORDER BY s.create_time DESC
</select>
<select id="listFaceIdsBySourceIds" resultType="com.ycwl.basic.model.pc.source.entity.MemberSourceEntity">
SELECT source_id, face_id
FROM member_source
WHERE source_id IN
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item}
</foreach>
GROUP BY source_id
</select>
<select id="pageByFaceId" resultType="com.ycwl.basic.model.pc.source.resp.SourceRespVO">
SELECT so.id, ms.face_id, ms.scenic_id, ms.type, so.thumb_url, so.url, so.video_url,
ms.is_free, so.create_time, ms.is_buy, so.device_id
FROM member_source ms
LEFT JOIN source so ON ms.source_id = so.id
WHERE ms.face_id = #{faceId} AND so.id IS NOT NULL
<if test="type != null">AND ms.type = #{type}</if>
<if test="scenicId != null">AND ms.scenic_id = #{scenicId}</if>
<if test="isBuy != null">AND ms.is_buy = #{isBuy}</if>
ORDER BY so.create_time DESC
</select>
</mapper>