|
|
@@ -1,5 +1,6 @@
|
|
|
package com.zhentao.controller;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.zhentao.common.Result;
|
|
|
import com.zhentao.entity.Activity;
|
|
|
import com.zhentao.service.ActivityService;
|
|
|
@@ -52,15 +53,42 @@ public class ActivityController {
|
|
|
*
|
|
|
* @param type 活动类型(可选,支持数字类型或 "hot" 表示热门活动)
|
|
|
* @param status 活动状态(可选)
|
|
|
- * @param limit 限制数量(可选)
|
|
|
+ * @param keyword 搜索关键词(可选,用于活动名称模糊查询)
|
|
|
+ * @param page 页码(可选,用于分页)
|
|
|
+ * @param pageSize 每页大小(可选,用于分页)
|
|
|
+ * @param limit 限制数量(可选,当使用分页时此参数无效)
|
|
|
* @return 活动列表
|
|
|
*/
|
|
|
@GetMapping("/list")
|
|
|
- public Result<List<Activity>> getActivityList(
|
|
|
+ public Result<?> getActivityList(
|
|
|
@RequestParam(required = false) String type,
|
|
|
@RequestParam(required = false) Integer status,
|
|
|
+ @RequestParam(required = false) String keyword,
|
|
|
+ @RequestParam(required = false) Integer page,
|
|
|
+ @RequestParam(required = false) Integer pageSize,
|
|
|
@RequestParam(required = false) Integer limit) {
|
|
|
try {
|
|
|
+ // 如果提供了分页参数,使用分页查询
|
|
|
+ if (page != null && pageSize != null && page > 0 && pageSize > 0) {
|
|
|
+ Integer typeInt = null;
|
|
|
+ if (type != null && !type.isEmpty() && !"hot".equalsIgnoreCase(type)) {
|
|
|
+ try {
|
|
|
+ typeInt = Integer.parseInt(type);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ // 忽略无法转换的类型
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Page<Activity> pageResult = activityService.getActivityPage(typeInt, status, keyword, page, pageSize);
|
|
|
+ // 将分页结果转换为前端需要的格式
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("list", pageResult.getRecords());
|
|
|
+ data.put("total", pageResult.getTotal());
|
|
|
+ data.put("page", page);
|
|
|
+ data.put("pageSize", pageSize);
|
|
|
+ return Result.success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 否则使用原来的逻辑(不分页)
|
|
|
List<Activity> activityList;
|
|
|
|
|
|
// 如果是热门活动
|
|
|
@@ -76,7 +104,7 @@ public class ActivityController {
|
|
|
// 忽略无法转换的类型
|
|
|
}
|
|
|
}
|
|
|
- activityList = activityService.getActivityList(typeInt, status, limit);
|
|
|
+ activityList = activityService.getActivityList(typeInt, status, keyword, limit);
|
|
|
}
|
|
|
|
|
|
return Result.success(activityList);
|