|
@@ -13,13 +13,11 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
|
-import org.dromara.system.domain.GameEvent;
|
|
|
+import org.dromara.system.domain.*;
|
|
|
import org.dromara.system.domain.bo.GameAthleteBo;
|
|
|
import org.dromara.system.domain.constant.GameEventConstant;
|
|
|
import org.dromara.system.domain.vo.SysDictDataVo;
|
|
|
-import org.dromara.system.mapper.GameAthleteMapper;
|
|
|
-import org.dromara.system.mapper.GameEventMapper;
|
|
|
-import org.dromara.system.mapper.GameRefereeMapper;
|
|
|
+import org.dromara.system.mapper.*;
|
|
|
import org.dromara.system.service.IGameAthleteService;
|
|
|
import org.dromara.system.service.IGameRefereeService;
|
|
|
import org.dromara.system.service.ISysDictTypeService;
|
|
@@ -29,8 +27,6 @@ import org.springframework.stereotype.Service;
|
|
|
import org.dromara.system.domain.bo.GameEventProjectBo;
|
|
|
import org.dromara.system.domain.bo.GameRefereeBo;
|
|
|
import org.dromara.system.domain.vo.GameEventProjectVo;
|
|
|
-import org.dromara.system.domain.GameEventProject;
|
|
|
-import org.dromara.system.mapper.GameEventProjectMapper;
|
|
|
import org.dromara.system.service.IGameEventProjectService;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -51,6 +47,9 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
private final GameEventProjectMapper baseMapper;
|
|
|
private final GameEventMapper gameEventMapper;
|
|
|
private final ISysDictTypeService sysDictTypeService;
|
|
|
+ private final GameTeamMapper gameTeamMapper;
|
|
|
+ private final GameAthleteMapper gameAthleteMapper;
|
|
|
+ private final GameEventGroupMapper gameEventGroupMapper;
|
|
|
|
|
|
@Autowired
|
|
|
@Lazy
|
|
@@ -60,10 +59,15 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
@Lazy
|
|
|
private IGameAthleteService gameAthleteService;
|
|
|
|
|
|
- public GameEventProjectServiceImpl(GameEventProjectMapper baseMapper, GameEventMapper gameEventMapper, ISysDictTypeService sysDictTypeService) {
|
|
|
+ public GameEventProjectServiceImpl(GameEventProjectMapper baseMapper, GameEventMapper gameEventMapper,
|
|
|
+ ISysDictTypeService sysDictTypeService, GameTeamMapper gameTeamMapper, GameAthleteMapper gameAthleteMapper,
|
|
|
+ GameEventGroupMapper gameEventGroupMapper) {
|
|
|
this.baseMapper = baseMapper;
|
|
|
this.gameEventMapper = gameEventMapper;
|
|
|
this.sysDictTypeService = sysDictTypeService;
|
|
|
+ this.gameTeamMapper = gameTeamMapper;
|
|
|
+ this.gameAthleteMapper = gameAthleteMapper;
|
|
|
+ this.gameEventGroupMapper = gameEventGroupMapper;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -209,6 +213,74 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 计算项目的参赛人数
|
|
|
+ * @param projectId 项目ID
|
|
|
+ * @return 参赛人数
|
|
|
+ */
|
|
|
+ private Long calculateParticipateNum(Long projectId) {
|
|
|
+ if (projectId == null) {
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询所有运动员,筛选出参与该项目的运动员
|
|
|
+ List<GameAthlete> allAthletes = gameAthleteMapper.selectList(
|
|
|
+ Wrappers.lambdaQuery(GameAthlete.class)
|
|
|
+ .select(GameAthlete::getProjectValue)
|
|
|
+ );
|
|
|
+
|
|
|
+ long count = allAthletes.stream()
|
|
|
+ .filter(athlete -> {
|
|
|
+ if (StringUtils.isNotBlank(athlete.getProjectValue())) {
|
|
|
+ try {
|
|
|
+ List<Long> projectList = JSONUtil.toList(athlete.getProjectValue(), Long.class);
|
|
|
+ return projectList.contains(projectId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("解析运动员项目列表失败: {}", athlete.getProjectValue(), e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ })
|
|
|
+ .count();
|
|
|
+
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算项目的参赛队伍数
|
|
|
+ * @param projectId 项目ID
|
|
|
+ * @return 参赛队伍数
|
|
|
+ */
|
|
|
+ private Long calculateGroupNum(Long projectId) {
|
|
|
+ if (projectId == null) {
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询所有队伍,筛选出参与该项目的队伍
|
|
|
+ List<GameTeam> allTeams = gameTeamMapper.selectList(
|
|
|
+ Wrappers.lambdaQuery(GameTeam.class)
|
|
|
+ .select(GameTeam::getProjectValue)
|
|
|
+ );
|
|
|
+
|
|
|
+ long count = allTeams.stream()
|
|
|
+ .filter(team -> {
|
|
|
+ if (StringUtils.isNotBlank(team.getProjectValue())) {
|
|
|
+ try {
|
|
|
+ List<Long> projectList = JSONUtil.toList(team.getProjectValue(), Long.class);
|
|
|
+ return projectList.contains(projectId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("解析队伍项目列表失败: {}", team.getProjectValue(), e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ })
|
|
|
+ .count();
|
|
|
+
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
private LambdaQueryWrapper<GameEventProject> buildQueryWrapper(GameEventProjectBo bo) {
|
|
|
Map<String, Object> params = bo.getParams();
|
|
|
LambdaQueryWrapper<GameEventProject> lqw = Wrappers.lambdaQuery();
|
|
@@ -377,6 +449,8 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
removeProjectFromReferees(ids);
|
|
|
//删除项目前批量删除运动员的关联信息
|
|
|
removeProjectFromAthletes(ids);
|
|
|
+ //删除项目前批量删除分组表game_event_group中的关联信息
|
|
|
+ removeProjectFromGroups(ids);
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
|
}
|
|
|
|
|
@@ -439,6 +513,43 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 从所有分组中移除指定项目的关联信息
|
|
|
+ *
|
|
|
+ * @param projectIds 要移除的项目ID集合
|
|
|
+ */
|
|
|
+ private void removeProjectFromGroups(Collection<Long> projectIds) {
|
|
|
+ try {
|
|
|
+ if (CollectionUtils.isEmpty(projectIds)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询所有包含这些项目的分组
|
|
|
+ List<GameEventGroup> groups = gameEventGroupMapper.selectList(
|
|
|
+ Wrappers.lambdaQuery(GameEventGroup.class)
|
|
|
+ .in(GameEventGroup::getProjectId, projectIds)
|
|
|
+ );
|
|
|
+
|
|
|
+ log.info("找到 {} 个分组需要删除,项目ID列表: {}", groups.size(), projectIds);
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(groups)) {
|
|
|
+ // 提取分组ID列表
|
|
|
+ List<Long> groupIds = groups.stream()
|
|
|
+ .map(GameEventGroup::getGroupId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 批量删除分组
|
|
|
+ int deletedCount = gameEventGroupMapper.deleteBatchIds(groupIds);
|
|
|
+ log.info("成功删除 {} 个分组,分组ID列表: {}", deletedCount, groupIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("分组关联清理完成,共处理 {} 个分组", groups.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("清理分组关联失败,项目ID列表: {}", projectIds, e);
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<GameEventProjectVo> listProjectsByEventIdAndProjectIndex(Long eventId, List<Long> projectIds) {
|
|
|
if (CollectionUtils.isEmpty(projectIds)) {
|