feat(registration): 支持集体项目报名
- DTO添加teamIds字段接收集体ID列表 - Controller处理集体报名逻辑 - 为每个集体创建martial_athlete记录用于编排
This commit is contained in:
@@ -3,7 +3,6 @@ package org.springblade.modules.martial.controller;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -15,20 +14,20 @@ import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.modules.martial.pojo.entity.MartialAthlete;
|
||||
import org.springblade.modules.martial.pojo.entity.MartialRegistrationOrder;
|
||||
import org.springblade.modules.martial.pojo.entity.MartialTeam;
|
||||
import org.springblade.modules.martial.pojo.entity.MartialTeamMember;
|
||||
import org.springblade.modules.martial.pojo.dto.RegistrationSubmitDTO;
|
||||
import org.springblade.modules.martial.pojo.vo.MartialRegistrationOrderVO;
|
||||
import org.springblade.modules.martial.service.IMartialAthleteService;
|
||||
import org.springblade.modules.martial.service.IMartialRegistrationOrderService;
|
||||
import org.springblade.modules.martial.service.IMartialTeamService;
|
||||
import org.springblade.modules.martial.mapper.MartialTeamMemberMapper;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 报名订单 控制器
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@@ -38,19 +37,15 @@ public class MartialRegistrationOrderController extends BladeController {
|
||||
|
||||
private final IMartialRegistrationOrderService registrationOrderService;
|
||||
private final IMartialAthleteService athleteService;
|
||||
private final IMartialTeamService teamService;
|
||||
private final MartialTeamMemberMapper teamMemberMapper;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@Operation(summary = "详情", description = "传入ID")
|
||||
public R detail(@RequestParam Long id) {
|
||||
return R.data(registrationOrderService.getDetailWithRelations(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页列表 - 只返回当前用户的报名记录(包含关联数据)
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "分页列表", description = "分页查询当前用户的报名记录")
|
||||
public R<IPage<MartialRegistrationOrderVO>> list(MartialRegistrationOrder registrationOrder, Query query) {
|
||||
@@ -63,11 +58,8 @@ public class MartialRegistrationOrderController extends BladeController {
|
||||
return R.data(pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交报名订单
|
||||
*/
|
||||
@PostMapping("/submit")
|
||||
@Operation(summary = "提交报名", description = "提交报名订单并关联选手")
|
||||
@Operation(summary = "提交报名", description = "提交报名订单并关联选手或集体")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public R submit(@RequestBody RegistrationSubmitDTO dto) {
|
||||
log.info("=== 提交报名订单 ===");
|
||||
@@ -75,6 +67,7 @@ public class MartialRegistrationOrderController extends BladeController {
|
||||
log.info("赛事ID: {}", dto.getCompetitionId());
|
||||
log.info("项目IDs: {}", dto.getProjectIds());
|
||||
log.info("选手IDs: {}", dto.getAthleteIds());
|
||||
log.info("集体IDs: {}", dto.getTeamIds());
|
||||
log.info("联系电话: {}", dto.getContactPhone());
|
||||
log.info("总金额: {}", dto.getTotalAmount());
|
||||
|
||||
@@ -87,9 +80,20 @@ public class MartialRegistrationOrderController extends BladeController {
|
||||
order.setUserId(AuthUtil.getUserId());
|
||||
order.setUserName(AuthUtil.getUserName());
|
||||
|
||||
// Parse athlete IDs
|
||||
// Parse IDs
|
||||
List<Long> athleteIds = Func.toLongList(dto.getAthleteIds());
|
||||
order.setTotalParticipants(athleteIds.size());
|
||||
List<Long> teamIds = Func.toLongList(dto.getTeamIds());
|
||||
List<Long> projectIds = Func.toLongList(dto.getProjectIds());
|
||||
Long firstProjectId = projectIds.isEmpty() ? null : projectIds.get(0);
|
||||
|
||||
// Determine if this is a team registration
|
||||
boolean isTeamRegistration = !teamIds.isEmpty();
|
||||
|
||||
if (isTeamRegistration) {
|
||||
order.setTotalParticipants(teamIds.size());
|
||||
} else {
|
||||
order.setTotalParticipants(athleteIds.size());
|
||||
}
|
||||
|
||||
// Save order
|
||||
boolean saved = registrationOrderService.save(order);
|
||||
@@ -100,31 +104,60 @@ public class MartialRegistrationOrderController extends BladeController {
|
||||
Long orderId = order.getId();
|
||||
log.info("订单创建成功,订单ID: {}", orderId);
|
||||
|
||||
// Parse project IDs
|
||||
List<Long> projectIds = Func.toLongList(dto.getProjectIds());
|
||||
Long firstProjectId = projectIds.isEmpty() ? null : projectIds.get(0);
|
||||
|
||||
// Update athletes with orderId, competitionId and projectId
|
||||
if (!athleteIds.isEmpty()) {
|
||||
LambdaUpdateWrapper<MartialAthlete> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.in(MartialAthlete::getId, athleteIds)
|
||||
.set(MartialAthlete::getOrderId, orderId)
|
||||
.set(MartialAthlete::getCompetitionId, dto.getCompetitionId());
|
||||
|
||||
if (firstProjectId != null) {
|
||||
updateWrapper.set(MartialAthlete::getProjectId, firstProjectId);
|
||||
if (isTeamRegistration) {
|
||||
// Handle team registration
|
||||
for (Long teamId : teamIds) {
|
||||
MartialTeam team = teamService.getById(teamId);
|
||||
if (team == null) {
|
||||
log.warn("集体不存在: {}", teamId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get team members
|
||||
LambdaQueryWrapper<MartialTeamMember> memberWrapper = new LambdaQueryWrapper<>();
|
||||
memberWrapper.eq(MartialTeamMember::getTeamId, teamId);
|
||||
memberWrapper.eq(MartialTeamMember::getIsDeleted, 0);
|
||||
List<MartialTeamMember> members = teamMemberMapper.selectList(memberWrapper);
|
||||
|
||||
// Create a martial_athlete record for the team
|
||||
MartialAthlete teamAthlete = new MartialAthlete();
|
||||
teamAthlete.setOrderId(orderId);
|
||||
teamAthlete.setCompetitionId(dto.getCompetitionId());
|
||||
teamAthlete.setProjectId(firstProjectId);
|
||||
teamAthlete.setTeamName(team.getTeamName());
|
||||
teamAthlete.setPlayerName(team.getTeamName());
|
||||
teamAthlete.setOrganization(team.getTeamName());
|
||||
teamAthlete.setRegistrationStatus(0);
|
||||
teamAthlete.setCompetitionStatus(0);
|
||||
teamAthlete.setCreateUser(AuthUtil.getUserId());
|
||||
teamAthlete.setCreateTime(new java.util.Date());
|
||||
teamAthlete.setTenantId("000000");
|
||||
teamAthlete.setIsDeleted(0);
|
||||
teamAthlete.setStatus(1);
|
||||
|
||||
athleteService.save(teamAthlete);
|
||||
log.info("创建集体参赛记录: teamName={}, athleteId={}", team.getTeamName(), teamAthlete.getId());
|
||||
}
|
||||
} else {
|
||||
// Handle individual registration
|
||||
if (!athleteIds.isEmpty()) {
|
||||
LambdaUpdateWrapper<MartialAthlete> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.in(MartialAthlete::getId, athleteIds)
|
||||
.set(MartialAthlete::getOrderId, orderId)
|
||||
.set(MartialAthlete::getCompetitionId, dto.getCompetitionId());
|
||||
|
||||
if (firstProjectId != null) {
|
||||
updateWrapper.set(MartialAthlete::getProjectId, firstProjectId);
|
||||
}
|
||||
|
||||
boolean updated = athleteService.update(updateWrapper);
|
||||
log.info("更新选手关联,选手数量: {}, 更新结果: {}", athleteIds.size(), updated);
|
||||
}
|
||||
|
||||
boolean updated = athleteService.update(updateWrapper);
|
||||
log.info("更新选手关联,选手数量: {}, 更新结果: {}", athleteIds.size(), updated);
|
||||
}
|
||||
|
||||
return R.data(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@Operation(summary = "删除", description = "传入ID")
|
||||
public R remove(@RequestParam String ids) {
|
||||
|
||||
@@ -5,48 +5,28 @@ import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 报名提交DTO
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "报名提交数据")
|
||||
public class RegistrationSubmitDTO {
|
||||
|
||||
/**
|
||||
* 订单号
|
||||
*/
|
||||
@Schema(description = "订单号")
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 赛事ID
|
||||
*/
|
||||
@Schema(description = "赛事ID")
|
||||
private Long competitionId;
|
||||
|
||||
/**
|
||||
* 项目ID列表(逗号分隔)
|
||||
*/
|
||||
@Schema(description = "项目ID列表")
|
||||
private String projectIds;
|
||||
|
||||
/**
|
||||
* 选手ID列表(逗号分隔)
|
||||
*/
|
||||
@Schema(description = "选手ID列表")
|
||||
@Schema(description = "选手ID列表(个人项目)")
|
||||
private String athleteIds;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
@Schema(description = "集体ID列表(集体项目)")
|
||||
private String teamIds;
|
||||
|
||||
@Schema(description = "联系电话")
|
||||
private String contactPhone;
|
||||
|
||||
/**
|
||||
* 总金额
|
||||
*/
|
||||
@Schema(description = "总金额")
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user