fix(registration): 根据赛事时间动态计算报名状态
- 1: 待开始 (赛事未开始) - 2: 进行中 (赛事进行中) - 3: 已结束 (赛事已结束)
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -45,14 +45,36 @@ public class MartialRegistrationOrderServiceImpl extends ServiceImpl<MartialRegi
|
||||
return convertToVO(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate competition status based on time
|
||||
* 1: pending (not started), 2: ongoing, 3: finished
|
||||
*/
|
||||
private Integer calculateCompetitionStatus(MartialCompetition competition) {
|
||||
if (competition == null) {
|
||||
return 1;
|
||||
}
|
||||
java.time.LocalDateTime now = java.time.LocalDateTime.now();
|
||||
java.time.LocalDateTime startTime = competition.getCompetitionStartTime();
|
||||
java.time.LocalDateTime endTime = competition.getCompetitionEndTime();
|
||||
|
||||
if (startTime == null || endTime == null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (now.isBefore(startTime)) {
|
||||
return 1; // pending
|
||||
} else if (now.isAfter(endTime)) {
|
||||
return 3; // finished
|
||||
} else {
|
||||
return 2; // ongoing
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<MartialRegistrationOrderVO> getListWithRelations(Long userId, Integer status, Integer current, Integer size) {
|
||||
// Build query
|
||||
// Build query - don't filter by status here, we'll filter after calculating
|
||||
LambdaQueryWrapper<MartialRegistrationOrder> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(MartialRegistrationOrder::getUserId, userId);
|
||||
if (status != null) {
|
||||
queryWrapper.eq(MartialRegistrationOrder::getStatus, status);
|
||||
}
|
||||
queryWrapper.orderByDesc(MartialRegistrationOrder::getCreateTime);
|
||||
|
||||
// Paginate
|
||||
@@ -110,7 +132,7 @@ public class MartialRegistrationOrderServiceImpl extends ServiceImpl<MartialRegi
|
||||
MartialRegistrationOrderVO vo = new MartialRegistrationOrderVO();
|
||||
BeanUtils.copyProperties(order, vo);
|
||||
|
||||
// Set competition info
|
||||
// Set competition info and calculate dynamic status
|
||||
MartialCompetition competition = competitionMap.get(order.getCompetitionId());
|
||||
if (competition != null) {
|
||||
vo.setCompetitionName(competition.getCompetitionName());
|
||||
@@ -119,6 +141,10 @@ public class MartialRegistrationOrderServiceImpl extends ServiceImpl<MartialRegi
|
||||
competition.getCompetitionStartTime().toString() : null);
|
||||
vo.setEndTime(competition.getCompetitionEndTime() != null ?
|
||||
competition.getCompetitionEndTime().toString() : null);
|
||||
// Calculate status based on competition time
|
||||
vo.setStatus(calculateCompetitionStatus(competition));
|
||||
} else {
|
||||
vo.setStatus(1); // Default to pending
|
||||
}
|
||||
|
||||
// Set athlete info
|
||||
@@ -177,7 +203,16 @@ public class MartialRegistrationOrderServiceImpl extends ServiceImpl<MartialRegi
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Filter by status if specified
|
||||
final Integer filterStatus = status;
|
||||
if (filterStatus != null && filterStatus > 0) {
|
||||
voList = voList.stream()
|
||||
.filter(vo -> filterStatus.equals(vo.getStatus()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
voPage.setRecords(voList);
|
||||
voPage.setTotal(voList.size());
|
||||
return voPage;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user