Browse Source

feat: 活动报名支持批量提交 registrants 列表

ActivityRegistrationService 新增 batchRegister() 批量创建报名记录,支持 childId 可选(手动输入报名人); ActivityController 兼容新旧两种参数格式。

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
iwt 3 months ago
parent
commit
0c58c213e4

+ 8 - 1
cfc-backend/src/main/java/com/etotem/cfc/controller/ActivityController.java

@@ -79,8 +79,15 @@ public class ActivityController {
     @PostMapping("/register")
     public Result<Map<String, Object>> register(@RequestBody Map<String, Object> params, @RequestAttribute(value = "userId", required = false) Long userId) {
         Long activityId = params.get("id") != null ? Long.valueOf(params.get("id").toString()) : null;
-        Long childId = params.get("childId") != null ? Long.valueOf(params.get("childId").toString()) : null;
         if (activityId == null) return Result.error("活动ID不能为空");
+        // batch registration with registrants list
+        Object registrantsObj = params.get("registrants");
+        if (registrantsObj instanceof List && !((List) registrantsObj).isEmpty()) {
+            List<Map<String, Object>> registrants = (List<Map<String, Object>>) registrantsObj;
+            return registrationService.batchRegister(activityId, userId, registrants);
+        }
+        // single registration (backward compatibility)
+        Long childId = params.get("childId") != null ? Long.valueOf(params.get("childId").toString()) : null;
         if (childId == null) return Result.error("孩子ID不能为空");
         return registrationService.register(activityId, userId, childId);
     }

+ 38 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/ActivityRegistrationService.java

@@ -26,6 +26,40 @@ public class ActivityRegistrationService {
     @Resource
     private ActivityMapper activityMapper;
 
+    @Transactional
+    public Result<Map<String, Object>> batchRegister(Long activityId, Long userId, List<Map<String, Object>> registrants) {
+        Activity activity = activityMapper.selectById(activityId);
+        if (activity == null) return Result.error("活动不存在");
+        if (!"published".equals(activity.getStatus())) return Result.error("活动未发布");
+        if (activity.getRequireRegistration() != null && activity.getRequireRegistration() == 0) {
+            return Result.error("该活动无需报名");
+        }
+        List<Long> ids = new ArrayList<>();
+        for (Map<String, Object> reg : registrants) {
+            String name = (String) reg.get("name");
+            if (name == null || name.trim().isEmpty()) return Result.error("报名人姓名不能为空");
+            String phone = (String) reg.get("phone");
+            Object childIdObj = reg.get("childId");
+            Long childId = childIdObj != null ? Long.valueOf(childIdObj.toString()) : null;
+            if (childId != null) {
+                if (isRegistered(activityId, childId)) {
+                    return Result.error("已报名: " + name);
+                }
+            }
+            ActivityRegistration ar = new ActivityRegistration();
+            ar.setActivityId(activityId); ar.setUserId(userId); ar.setChildId(childId);
+            ar.setRegistrantName(name.trim()); ar.setRegistrantPhone(phone != null ? phone.trim() : null);
+            ar.setStatus("pending"); ar.setRegisteredAt(LocalDateTime.now());
+            ar.setCreatedAt(LocalDateTime.now()); ar.setUpdatedAt(LocalDateTime.now());
+            registrationMapper.insert(ar);
+            ids.add(ar.getId());
+        }
+        Map<String, Object> result = new HashMap<>();
+        result.put("registrationIds", ids);
+        result.put("count", ids.size());
+        return Result.success(result);
+    }
+
     @Transactional
     public Result<Map<String, Object>> register(Long activityId, Long userId, Long childId) {
         Activity activity = activityMapper.selectById(activityId);
@@ -88,6 +122,8 @@ public class ActivityRegistrationService {
             Map<String, Object> item = new HashMap<>();
             item.put("id", reg.getId()); item.put("activityId", reg.getActivityId());
             item.put("childId", reg.getChildId()); item.put("status", reg.getStatus());
+            item.put("registrantName", reg.getRegistrantName());
+            item.put("registrantPhone", reg.getRegistrantPhone());
             item.put("registeredAt", reg.getRegisteredAt());
             Activity activity = activityMapper.selectById(reg.getActivityId());
             if (activity != null) {
@@ -111,6 +147,8 @@ public class ActivityRegistrationService {
             Map<String, Object> item = new HashMap<>();
             item.put("id", reg.getId()); item.put("childId", reg.getChildId());
             item.put("userId", reg.getUserId()); item.put("status", reg.getStatus());
+            item.put("registrantName", reg.getRegistrantName());
+            item.put("registrantPhone", reg.getRegistrantPhone());
             item.put("registeredAt", reg.getRegisteredAt());
             return item;
         }).collect(Collectors.toList());