|
@@ -1,8 +1,6 @@
|
|
|
package org.dromara.system.service.impl;
|
|
package org.dromara.system.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
-import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -29,6 +27,7 @@ import org.dromara.system.service.IGameEventProjectService;
|
|
|
import org.dromara.system.service.IGameRankGroupService;
|
|
import org.dromara.system.service.IGameRankGroupService;
|
|
|
import org.dromara.system.service.IGameTeamService;
|
|
import org.dromara.system.service.IGameTeamService;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -51,7 +50,6 @@ public class GameTeamServiceImpl implements IGameTeamService {
|
|
|
private final GameEventMapper gameEventMapper;
|
|
private final GameEventMapper gameEventMapper;
|
|
|
|
|
|
|
|
private final IGameRankGroupService gameRankGroupService;
|
|
private final IGameRankGroupService gameRankGroupService;
|
|
|
- private final IGameEventProjectService gameEventProjectService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 查询参赛队伍
|
|
* 查询参赛队伍
|
|
@@ -65,10 +63,13 @@ public class GameTeamServiceImpl implements IGameTeamService {
|
|
|
if (vo == null) {
|
|
if (vo == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- if (vo.getAthleteValue() != null) {
|
|
|
|
|
- log.info("teamId:{}, athleteValue:{}", teamId, vo.getAthleteValue());
|
|
|
|
|
- vo.setAthleteList(JSONUtil.toList(vo.getAthleteValue(), Long.class));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 重构:实时查询属于该队伍的运动员ID列表
|
|
|
|
|
+ List<Long> athleteIds = gameAthleteMapper.selectList(Wrappers.<GameAthlete>lambdaQuery()
|
|
|
|
|
+ .eq(GameAthlete::getTeamId, teamId)
|
|
|
|
|
+ .select(GameAthlete::getAthleteId))
|
|
|
|
|
+ .stream().map(GameAthlete::getAthleteId).collect(Collectors.toList());
|
|
|
|
|
+ vo.setAthleteList(athleteIds);
|
|
|
|
|
+ vo.setAthleteNum(athleteIds.size());
|
|
|
return vo;
|
|
return vo;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -92,13 +93,27 @@ public class GameTeamServiceImpl implements IGameTeamService {
|
|
|
LambdaQueryWrapper<GameTeam> lqw = buildQueryWrapper(bo);
|
|
LambdaQueryWrapper<GameTeam> lqw = buildQueryWrapper(bo);
|
|
|
// Page<GameTeamVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
// Page<GameTeamVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
Page<GameTeamVo> result = baseMapper.selectPageTeamListWithProjects(pageQuery.build(), lqw);
|
|
Page<GameTeamVo> result = baseMapper.selectPageTeamListWithProjects(pageQuery.build(), lqw);
|
|
|
- // 处理队员列表 JSON 转换
|
|
|
|
|
- result.getRecords().forEach(vo -> {
|
|
|
|
|
- if (StringUtils.isNotBlank(vo.getAthleteValue())) {
|
|
|
|
|
- List<Long> athleteIds = JSONUtil.toList(vo.getAthleteValue(), Long.class);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 重构:为每一页的队伍动态加载人数和成员列表
|
|
|
|
|
+ if (CollUtil.isNotEmpty(result.getRecords())) {
|
|
|
|
|
+ List<Long> teamIds = result.getRecords().stream().map(GameTeamVo::getTeamId).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ // 批量查询所有相关运动员
|
|
|
|
|
+ List<GameAthlete> allAthletes = gameAthleteMapper.selectList(Wrappers.<GameAthlete>lambdaQuery()
|
|
|
|
|
+ .in(GameAthlete::getTeamId, teamIds)
|
|
|
|
|
+ .select(GameAthlete::getAthleteId, GameAthlete::getTeamId));
|
|
|
|
|
+
|
|
|
|
|
+ // 按队伍ID分组
|
|
|
|
|
+ Map<Long, List<Long>> teamAthleteMap = allAthletes.stream()
|
|
|
|
|
+ .collect(Collectors.groupingBy(GameAthlete::getTeamId,
|
|
|
|
|
+ Collectors.mapping(GameAthlete::getAthleteId, Collectors.toList())));
|
|
|
|
|
+
|
|
|
|
|
+ result.getRecords().forEach(vo -> {
|
|
|
|
|
+ List<Long> athleteIds = teamAthleteMap.getOrDefault(vo.getTeamId(), new ArrayList<>());
|
|
|
vo.setAthleteList(athleteIds);
|
|
vo.setAthleteList(athleteIds);
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ vo.setAthleteNum(athleteIds.size());
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return TableDataInfo.build(result);
|
|
return TableDataInfo.build(result);
|
|
|
}
|
|
}
|
|
@@ -129,15 +144,14 @@ public class GameTeamServiceImpl implements IGameTeamService {
|
|
|
lqw.and(bo.getRgId() != null,
|
|
lqw.and(bo.getRgId() != null,
|
|
|
wrapper -> wrapper.eq(GameTeam::getRgId, bo.getRgId())
|
|
wrapper -> wrapper.eq(GameTeam::getRgId, bo.getRgId())
|
|
|
.or()
|
|
.or()
|
|
|
- .apply("rg_id IN (SELECT rg_id FROM game_rank_group WHERE FIND_IN_SET({0}, ancestors))", bo.getRgId())
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ .apply("rg_id IN (SELECT rg_id FROM game_rank_group WHERE FIND_IN_SET({0}, ancestors))",
|
|
|
|
|
+ bo.getRgId()));
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getLeader()), GameTeam::getLeader, bo.getLeader());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getLeader()), GameTeam::getLeader, bo.getLeader());
|
|
|
- lqw.eq(StringUtils.isNotBlank(bo.getAthleteValue()), GameTeam::getAthleteValue, bo.getAthleteValue());
|
|
|
|
|
|
|
+ // 重构:废弃 athleteValue 字段查询,此处不再支持根据原始 JSON 字符串查询
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getProjectValue()), GameTeam::getProjectValue, bo.getProjectValue());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getProjectValue()), GameTeam::getProjectValue, bo.getProjectValue());
|
|
|
lqw.apply(bo.getProjectId() != null,
|
|
lqw.apply(bo.getProjectId() != null,
|
|
|
"EXISTS (SELECT 1 FROM game_athlete ga WHERE ga.team_id = gt.team_id AND ga.del_flag = '0' AND (JSON_CONTAINS(ga.project_value, CAST({0} AS CHAR)) OR JSON_CONTAINS(ga.project_value, CONCAT('\"', {0}, '\"'))))",
|
|
"EXISTS (SELECT 1 FROM game_athlete ga WHERE ga.team_id = gt.team_id AND ga.del_flag = '0' AND (JSON_CONTAINS(ga.project_value, CAST({0} AS CHAR)) OR JSON_CONTAINS(ga.project_value, CONCAT('\"', {0}, '\"'))))",
|
|
|
bo.getProjectId());
|
|
bo.getProjectId());
|
|
|
- lqw.eq(bo.getAthleteNum() != null, GameTeam::getAthleteNum, bo.getAthleteNum());
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getNumberRange()), GameTeam::getNumberRange, bo.getNumberRange());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getNumberRange()), GameTeam::getNumberRange, bo.getNumberRange());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getTeamDescribe()), GameTeam::getTeamDescribe, bo.getTeamDescribe());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getTeamDescribe()), GameTeam::getTeamDescribe, bo.getTeamDescribe());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), GameTeam::getStatus, bo.getStatus());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), GameTeam::getStatus, bo.getStatus());
|
|
@@ -163,13 +177,24 @@ public class GameTeamServiceImpl implements IGameTeamService {
|
|
|
}
|
|
}
|
|
|
LambdaQueryWrapper<GameTeam> lqw = buildQueryWrapper(bo);
|
|
LambdaQueryWrapper<GameTeam> lqw = buildQueryWrapper(bo);
|
|
|
List<GameTeamVo> list = baseMapper.selectTeamListWithProjects(lqw);
|
|
List<GameTeamVo> list = baseMapper.selectTeamListWithProjects(lqw);
|
|
|
- // 处理队员列表 JSON 转换
|
|
|
|
|
- list.forEach(vo -> {
|
|
|
|
|
- if (StringUtils.isNotBlank(vo.getAthleteValue())) {
|
|
|
|
|
- List<Long> athleteIds = JSONUtil.toList(vo.getAthleteValue(), Long.class);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 重构:动态加载成员列表和人数
|
|
|
|
|
+ if (CollUtil.isNotEmpty(list)) {
|
|
|
|
|
+ List<Long> teamIds = list.stream().map(GameTeamVo::getTeamId).collect(Collectors.toList());
|
|
|
|
|
+ List<GameAthlete> allAthletes = gameAthleteMapper.selectList(Wrappers.<GameAthlete>lambdaQuery()
|
|
|
|
|
+ .in(GameAthlete::getTeamId, teamIds)
|
|
|
|
|
+ .select(GameAthlete::getAthleteId, GameAthlete::getTeamId));
|
|
|
|
|
+
|
|
|
|
|
+ Map<Long, List<Long>> teamAthleteMap = allAthletes.stream()
|
|
|
|
|
+ .collect(Collectors.groupingBy(GameAthlete::getTeamId,
|
|
|
|
|
+ Collectors.mapping(GameAthlete::getAthleteId, Collectors.toList())));
|
|
|
|
|
+
|
|
|
|
|
+ list.forEach(vo -> {
|
|
|
|
|
+ List<Long> athleteIds = teamAthleteMap.getOrDefault(vo.getTeamId(), new ArrayList<>());
|
|
|
vo.setAthleteList(athleteIds);
|
|
vo.setAthleteList(athleteIds);
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ vo.setAthleteNum(athleteIds.size());
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
return list;
|
|
return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -189,9 +214,9 @@ public class GameTeamServiceImpl implements IGameTeamService {
|
|
|
bo.setEventId((Long) cacheObject);
|
|
bo.setEventId((Long) cacheObject);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (bo.getAthleteList() != null) {
|
|
|
|
|
- bo.setAthleteValue(JSONUtil.toJsonStr(bo.getAthleteList()));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// if (bo.getAthleteList() != null) {
|
|
|
|
|
+// bo.setAthleteValue(JSONUtil.toJsonStr(bo.getAthleteList()));
|
|
|
|
|
+// }
|
|
|
GameTeam add = MapstructUtils.convert(bo, GameTeam.class);
|
|
GameTeam add = MapstructUtils.convert(bo, GameTeam.class);
|
|
|
validEntityBeforeSave(add);
|
|
validEntityBeforeSave(add);
|
|
|
// 查询是否重复
|
|
// 查询是否重复
|
|
@@ -225,9 +250,9 @@ public class GameTeamServiceImpl implements IGameTeamService {
|
|
|
bo.setEventId((Long) cacheObject);
|
|
bo.setEventId((Long) cacheObject);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (bo.getAthleteList() != null) {
|
|
|
|
|
- bo.setAthleteValue(JSONUtil.toJsonStr(bo.getAthleteList()));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// if (bo.getAthleteList() != null) {
|
|
|
|
|
+// bo.setAthleteValue(JSONUtil.toJsonStr(bo.getAthleteList()));
|
|
|
|
|
+// }
|
|
|
GameTeam update = MapstructUtils.convert(bo, GameTeam.class);
|
|
GameTeam update = MapstructUtils.convert(bo, GameTeam.class);
|
|
|
validEntityBeforeSave(update);
|
|
validEntityBeforeSave(update);
|
|
|
return baseMapper.updateById(update) > 0;
|
|
return baseMapper.updateById(update) > 0;
|
|
@@ -301,10 +326,6 @@ public class GameTeamServiceImpl implements IGameTeamService {
|
|
|
Wrappers.lambdaQuery(GameTeam.class)
|
|
Wrappers.lambdaQuery(GameTeam.class)
|
|
|
.eq(GameTeam::getEventId, eventId)
|
|
.eq(GameTeam::getEventId, eventId)
|
|
|
.in(GameTeam::getTeamName, names));
|
|
.in(GameTeam::getTeamName, names));
|
|
|
- // 批量添加队伍时,运动员列表为空列表而不是null
|
|
|
|
|
- list.forEach(team -> {
|
|
|
|
|
- team.setAthleteValue(new ArrayList<Long>().toString());
|
|
|
|
|
- });
|
|
|
|
|
if (count > 0) {
|
|
if (count > 0) {
|
|
|
throw new ServiceException("导入失败,有队伍名称重复");
|
|
throw new ServiceException("导入失败,有队伍名称重复");
|
|
|
}
|
|
}
|
|
@@ -332,9 +353,21 @@ public class GameTeamServiceImpl implements IGameTeamService {
|
|
|
List<GameTeamVo> list = baseMapper.selectVoList(
|
|
List<GameTeamVo> list = baseMapper.selectVoList(
|
|
|
Wrappers.lambdaQuery(GameTeam.class)
|
|
Wrappers.lambdaQuery(GameTeam.class)
|
|
|
.in(GameTeam::getTeamId, teamIds));
|
|
.in(GameTeam::getTeamId, teamIds));
|
|
|
- list.forEach(vo -> {
|
|
|
|
|
- vo.setAthleteList(JSONUtil.toList(vo.getAthleteValue(), Long.class));
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (CollUtil.isNotEmpty(list)) {
|
|
|
|
|
+ List<GameAthlete> allAthletes = gameAthleteMapper.selectList(Wrappers.<GameAthlete>lambdaQuery()
|
|
|
|
|
+ .in(GameAthlete::getTeamId, teamIds)
|
|
|
|
|
+ .select(GameAthlete::getAthleteId, GameAthlete::getTeamId));
|
|
|
|
|
+
|
|
|
|
|
+ Map<Long, List<Long>> teamAthleteMap = allAthletes.stream()
|
|
|
|
|
+ .collect(Collectors.groupingBy(GameAthlete::getTeamId,
|
|
|
|
|
+ Collectors.mapping(GameAthlete::getAthleteId, Collectors.toList())));
|
|
|
|
|
+
|
|
|
|
|
+ list.forEach(vo -> {
|
|
|
|
|
+ List<Long> athleteIds = teamAthleteMap.getOrDefault(vo.getTeamId(), new ArrayList<>());
|
|
|
|
|
+ vo.setAthleteList(athleteIds);
|
|
|
|
|
+ vo.setAthleteNum(athleteIds.size());
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
return list;
|
|
return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -346,19 +379,23 @@ public class GameTeamServiceImpl implements IGameTeamService {
|
|
|
* @return 是否更新成功
|
|
* @return 是否更新成功
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean updateTeamAthletes(Long teamId, List<Long> athleteIds) {
|
|
public Boolean updateTeamAthletes(Long teamId, List<Long> athleteIds) {
|
|
|
- GameTeam team = baseMapper.selectById(teamId);
|
|
|
|
|
- if (team == null) {
|
|
|
|
|
- throw new RuntimeException("队伍不存在");
|
|
|
|
|
|
|
+ // 重构:更新队伍运动员不再修改队伍表字段,而是批量修改运动员表中的 team_id
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 先将原属于该队伍的所有运动员 team_id 置空
|
|
|
|
|
+ // gameAthleteMapper.update(null, Wrappers.<GameAthlete>lambdaUpdate()
|
|
|
|
|
+ // .eq(GameAthlete::getTeamId, teamId)
|
|
|
|
|
+ // .set(GameAthlete::getTeamId, null));
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 将传入的运动员列表 team_id 设置为该队伍
|
|
|
|
|
+ if (CollUtil.isNotEmpty(athleteIds)) {
|
|
|
|
|
+ gameAthleteMapper.update(null, Wrappers.<GameAthlete>lambdaUpdate()
|
|
|
|
|
+ .in(GameAthlete::getAthleteId, athleteIds)
|
|
|
|
|
+ .set(GameAthlete::getTeamId, teamId));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 将运动员ID列表转换为JSON字符串
|
|
|
|
|
- String athleteValue = JSONUtil.toJsonStr(athleteIds);
|
|
|
|
|
- team.setAthleteValue(athleteValue);
|
|
|
|
|
- team.setAthleteNum(athleteIds.size());
|
|
|
|
|
-
|
|
|
|
|
- // 更新队伍信息
|
|
|
|
|
- return baseMapper.updateById(team) > 0;
|
|
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|