You've already forked FrameTour-BE
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:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user