|
@@ -22,6 +22,7 @@ import org.dromara.system.domain.GameTeam;
|
|
|
import org.dromara.system.domain.bo.GameAthleteBo;
|
|
|
import org.dromara.system.domain.bo.GameEventBo;
|
|
|
import org.dromara.system.domain.bo.GameTeamBo;
|
|
|
+import org.dromara.system.domain.bo.ProjectSelectionValidationBo;
|
|
|
import org.dromara.system.domain.constant.GameEventConstant;
|
|
|
import org.dromara.system.domain.vo.*;
|
|
|
import org.dromara.system.mapper.GameAthleteMapper;
|
|
@@ -342,7 +343,8 @@ public class GameAthleteServiceImpl implements IGameAthleteService {
|
|
|
if (entity.getAthleteCode() != null){
|
|
|
List<GameAthlete> list = baseMapper.selectList(new LambdaQueryWrapper<GameAthlete>()
|
|
|
.eq(GameAthlete::getAthleteCode, entity.getAthleteCode()));
|
|
|
- if (!list.isEmpty()){
|
|
|
+ //排除自己
|
|
|
+ if (list.size()>1){
|
|
|
throw new ServiceException(entity.getName()+"的编号已存在!");
|
|
|
}
|
|
|
}
|
|
@@ -542,4 +544,77 @@ public class GameAthleteServiceImpl implements IGameAthleteService {
|
|
|
public List<GameAthleteBo> findByProjectIds(Collection<Long> projectIds) {
|
|
|
return baseMapper.findByProjectIds(projectIds);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 项目选择验证
|
|
|
+ * @param bo 验证参数
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> validateProjectSelection(ProjectSelectionValidationBo bo) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ List<String> errors = new ArrayList<>();
|
|
|
+ List<String> warnings = new ArrayList<>();
|
|
|
+
|
|
|
+ // 1. 校验每人限报项目数
|
|
|
+ GameEventVo event = gameEventService.getDefaultEvent();
|
|
|
+ if (event.getLimitApplication() != null && event.getLimitApplication() > 0) {
|
|
|
+ if (bo.getSelectedProjectIds().size() > event.getLimitApplication()) {
|
|
|
+ errors.add(String.format("每人限报项目数为 %d 个,您已选择 %d 个项目",
|
|
|
+ event.getLimitApplication(), bo.getSelectedProjectIds().size()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 校验各项目的限报人数
|
|
|
+ for (Long projectId : bo.getSelectedProjectIds()) {
|
|
|
+ GameEventProjectVo project = gameEventProjectService.queryById(projectId);
|
|
|
+ if (project.getLimitPerson() != null && project.getLimitPerson() > 0) {
|
|
|
+ // 统计当前项目已报名人数
|
|
|
+ int currentCount = countAthletesByProjectId(projectId, bo.getAthleteId());
|
|
|
+
|
|
|
+ if (currentCount >= project.getLimitPerson()) {
|
|
|
+ errors.add(String.format("项目「%s」报名人数已满(%d/%d),无法添加",
|
|
|
+ project.getProjectName(), currentCount, project.getLimitPerson()));
|
|
|
+ } else if (currentCount >= project.getLimitPerson() * 0.9) {
|
|
|
+ warnings.add(String.format("项目「%s」报名人数接近上限(%d/%d)",
|
|
|
+ project.getProjectName(), currentCount, project.getLimitPerson()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ result.put("valid", errors.isEmpty());
|
|
|
+ result.put("errors", errors);
|
|
|
+ result.put("warnings", warnings);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 统计项目报名人数的方法
|
|
|
+ private int countAthletesByProjectId(Long projectId, Long excludeAthleteId) {
|
|
|
+ LambdaQueryWrapper<GameAthlete> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.like(GameAthlete::getProjectValue, projectId.toString());
|
|
|
+
|
|
|
+ if (excludeAthleteId != null) {
|
|
|
+ wrapper.ne(GameAthlete::getAthleteId, excludeAthleteId);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<GameAthlete> athletes = baseMapper.selectList(wrapper);
|
|
|
+
|
|
|
+ // 需要解析JSON格式的projectValue字段
|
|
|
+ int count = 0;
|
|
|
+ for (GameAthlete athlete : athletes) {
|
|
|
+ if (StringUtils.isNotBlank(athlete.getProjectValue())) {
|
|
|
+ try {
|
|
|
+ List<Long> projectIds = JSONUtil.toList(athlete.getProjectValue(), Long.class);
|
|
|
+ if (projectIds.contains(projectId)) {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("解析运动员项目列表失败: {}", athlete.getProjectValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return count;
|
|
|
+ }
|
|
|
}
|