|
|
@@ -2,6 +2,7 @@ package com.zhentao.controller;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.zhentao.common.Result;
|
|
|
import com.zhentao.entity.Activity;
|
|
|
import com.zhentao.entity.ActivityRegistration;
|
|
|
@@ -28,6 +29,41 @@ public class ActivityController {
|
|
|
private ActivityRegistrationService activityRegistrationService;
|
|
|
|
|
|
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ @GetMapping("/list")
|
|
|
+ public Result<?> list(
|
|
|
+ @RequestParam(value = "page", defaultValue = "1") Integer page,
|
|
|
+ @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
+ @RequestParam(value = "type", required = false) Integer type,
|
|
|
+ @RequestParam(value = "status", required = false) Integer status,
|
|
|
+ @RequestParam(value = "keyword", required = false) String keyword
|
|
|
+ ) {
|
|
|
+ try {
|
|
|
+ Page<Activity> pageObj = new Page<>(page, pageSize);
|
|
|
+ Page<Activity> result = activityMapper.selectActivityPage(pageObj, type, status, keyword);
|
|
|
+
|
|
|
+ // 计算每个活动实际报名人数(排除已取消 status=2)
|
|
|
+ if (result.getRecords() != null) {
|
|
|
+ for (Activity activity : result.getRecords()) {
|
|
|
+ if (activity == null || activity.getId() == null) continue;
|
|
|
+ LambdaQueryWrapper<ActivityRegistration> regQuery = new LambdaQueryWrapper<ActivityRegistration>()
|
|
|
+ .eq(ActivityRegistration::getActivityId, activity.getId())
|
|
|
+ .ne(ActivityRegistration::getStatus, 2);
|
|
|
+ long cnt = activityRegistrationService.count(regQuery);
|
|
|
+ activity.setActualParticipants((int) cnt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ java.util.Map<String, Object> data = new java.util.HashMap<>();
|
|
|
+ data.put("list", result.getRecords());
|
|
|
+ data.put("total", result.getTotal());
|
|
|
+ data.put("page", page);
|
|
|
+ data.put("pageSize", pageSize);
|
|
|
+ return Result.success(data);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return Result.error("查询活动列表失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 创建活动
|
|
|
@@ -48,6 +84,9 @@ public class ActivityController {
|
|
|
if (activity.getIsHot() == null) {
|
|
|
activity.setIsHot(false);
|
|
|
}
|
|
|
+ if (activity.getIsDeleted() == null) {
|
|
|
+ activity.setIsDeleted(0);
|
|
|
+ }
|
|
|
activity.setCreatedTime(LocalDateTime.now());
|
|
|
|
|
|
int rows = activityMapper.insert(activity);
|
|
|
@@ -72,6 +111,14 @@ public class ActivityController {
|
|
|
System.out.println("=== 更新活动 ===");
|
|
|
System.out.println("活动ID: " + id);
|
|
|
System.out.println("活动数据: " + activity);
|
|
|
+
|
|
|
+ if (activity != null && activity.getIsDeleted() != null && activity.getName() == null) {
|
|
|
+ int rows = activityMapper.updateIsDeletedById(id, activity.getIsDeleted());
|
|
|
+ if (rows > 0) {
|
|
|
+ return Result.success("更新成功");
|
|
|
+ }
|
|
|
+ return Result.error("更新失败");
|
|
|
+ }
|
|
|
|
|
|
// 检查活动是否存在
|
|
|
Activity existingActivity = activityMapper.selectById(id);
|