|
|
@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -43,8 +44,26 @@ public class ProductRecommendationController {
|
|
|
Object limitObj = params.get("limit");
|
|
|
int limit = limitObj != null ? toInt(limitObj) : 6;
|
|
|
|
|
|
- List<Map<String, Object>> result = productRecommendationService.getDimensionRecommendations(
|
|
|
- dimensionCode, familyId, memberId, excludeIds, limit, userId);
|
|
|
+ // 分页支持:page + size(不传 page 时保持原有 limit 行为,向后兼容)
|
|
|
+ Object pageObj = params.get("page");
|
|
|
+ int page = pageObj != null ? Math.max(1, toInt(pageObj)) : 1;
|
|
|
+ Object sizeObj = params.get("size");
|
|
|
+ int size = sizeObj != null ? Math.max(1, toInt(sizeObj)) : limit;
|
|
|
+
|
|
|
+ // 取全量候选(limit = page * size),再按页切片,保证翻页不重复、不遗漏
|
|
|
+ int fetchLimit = page * size;
|
|
|
+ List<Map<String, Object>> full = productRecommendationService.getDimensionRecommendations(
|
|
|
+ dimensionCode, familyId, memberId, excludeIds, fetchLimit, userId);
|
|
|
+
|
|
|
+ List<Map<String, Object>> result;
|
|
|
+ if (pageObj == null) {
|
|
|
+ // 未传 page:保持原有语义(取前 limit 条)
|
|
|
+ result = full.size() > limit ? full.subList(0, limit) : full;
|
|
|
+ } else {
|
|
|
+ int from = (page - 1) * size;
|
|
|
+ int to = Math.min(from + size, full.size());
|
|
|
+ result = from >= full.size() ? Collections.emptyList() : full.subList(from, to);
|
|
|
+ }
|
|
|
|
|
|
return Result.success(result);
|
|
|
}
|