|
@@ -0,0 +1,295 @@
|
|
|
+package org.dromara.system.service.impl;
|
|
|
+
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.dromara.system.domain.bo.GameAthleteCompetitionGroupBo;
|
|
|
+import org.dromara.system.domain.vo.GameAthleteCompetitionGroupVo;
|
|
|
+import org.dromara.system.domain.GameAthleteCompetitionGroup;
|
|
|
+import org.dromara.system.mapper.GameAthleteCompetitionGroupMapper;
|
|
|
+import org.dromara.system.service.IGameAthleteCompetitionGroupService;
|
|
|
+import org.dromara.system.domain.vo.GameEventGroupVo;
|
|
|
+import org.dromara.system.domain.vo.GameAthleteVo;
|
|
|
+import org.dromara.system.domain.vo.GameTeamVo;
|
|
|
+import org.dromara.system.service.IGameTeamService;
|
|
|
+import org.dromara.common.core.utils.SpringUtils;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 运动员比赛场次分组关联Service业务层处理
|
|
|
+ *
|
|
|
+ * @author zlt
|
|
|
+ * @date 2025-08-28
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class GameAthleteCompetitionGroupServiceImpl implements IGameAthleteCompetitionGroupService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GameAthleteCompetitionGroupMapper baseMapper;
|
|
|
+
|
|
|
+ private IGameTeamService gameTeamService;
|
|
|
+
|
|
|
+ // 获取队伍服务的辅助方法
|
|
|
+ private IGameTeamService getGameTeamService() {
|
|
|
+ if (gameTeamService == null) {
|
|
|
+ gameTeamService = SpringUtils.getBean(IGameTeamService.class);
|
|
|
+ }
|
|
|
+ return gameTeamService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询运动员比赛场次分组关联
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 运动员比赛场次分组关联
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public GameAthleteCompetitionGroupVo queryById(Long id) {
|
|
|
+ return baseMapper.selectVoById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询运动员比赛场次分组关联列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 运动员比赛场次分组关联分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<GameAthleteCompetitionGroupVo> queryPageList(GameAthleteCompetitionGroupBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<GameAthleteCompetitionGroup> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<GameAthleteCompetitionGroupVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的运动员比赛场次分组关联列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 运动员比赛场次分组关联列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<GameAthleteCompetitionGroupVo> queryList(GameAthleteCompetitionGroupBo bo) {
|
|
|
+ LambdaQueryWrapper<GameAthleteCompetitionGroup> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<GameAthleteCompetitionGroup> buildQueryWrapper(GameAthleteCompetitionGroupBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<GameAthleteCompetitionGroup> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(bo.getGroupId() != null, GameAthleteCompetitionGroup::getGroupId, bo.getGroupId());
|
|
|
+ lqw.eq(bo.getEventId() != null, GameAthleteCompetitionGroup::getEventId, bo.getEventId());
|
|
|
+ lqw.eq(bo.getProjectId() != null, GameAthleteCompetitionGroup::getProjectId, bo.getProjectId());
|
|
|
+ lqw.eq(bo.getAthleteId() != null, GameAthleteCompetitionGroup::getAthleteId, bo.getAthleteId());
|
|
|
+ lqw.eq(bo.getTeamId() != null, GameAthleteCompetitionGroup::getTeamId, bo.getTeamId());
|
|
|
+ lqw.eq(bo.getGroupIndex() != null, GameAthleteCompetitionGroup::getGroupIndex, bo.getGroupIndex());
|
|
|
+ lqw.eq(bo.getTrackIndex() != null, GameAthleteCompetitionGroup::getTrackIndex, bo.getTrackIndex());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getStatus()), GameAthleteCompetitionGroup::getStatus, bo.getStatus());
|
|
|
+ lqw.orderByAsc(GameAthleteCompetitionGroup::getGroupIndex)
|
|
|
+ .orderByAsc(GameAthleteCompetitionGroup::getTrackIndex);
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增运动员比赛场次分组关联
|
|
|
+ *
|
|
|
+ * @param bo 运动员比赛场次分组关联
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(GameAthleteCompetitionGroupBo bo) {
|
|
|
+ GameAthleteCompetitionGroup add = MapstructUtils.convert(bo, GameAthleteCompetitionGroup.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ boolean flag = baseMapper.insert(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setId(add.getId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改运动员比赛场次分组关联
|
|
|
+ *
|
|
|
+ * @param bo 运动员比赛场次分组关联
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(GameAthleteCompetitionGroupBo bo) {
|
|
|
+ GameAthleteCompetitionGroup update = MapstructUtils.convert(bo, GameAthleteCompetitionGroup.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(GameAthleteCompetitionGroup entity) {
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除运动员比赛场次分组关联信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if (isValid) {
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据分组ID查询分组结果
|
|
|
+ *
|
|
|
+ * @param groupId 分组ID
|
|
|
+ * @return 分组结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getGroupResultFromDB(Long groupId) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 查询数据库中的分组结果
|
|
|
+ GameAthleteCompetitionGroupBo queryBo = new GameAthleteCompetitionGroupBo();
|
|
|
+ queryBo.setGroupId(groupId);
|
|
|
+ List<GameAthleteCompetitionGroupVo> groupData = queryList(queryBo);
|
|
|
+
|
|
|
+ if (groupData.isEmpty()) {
|
|
|
+ result.put("success", false);
|
|
|
+ result.put("message", "数据库中没有找到分组数据");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建分组结果
|
|
|
+ Map<String, Object> groupResult = new HashMap<>();
|
|
|
+ for (GameAthleteCompetitionGroupVo item : groupData) {
|
|
|
+ String key = item.getGroupIndex() + "-" + item.getTrackIndex();
|
|
|
+ Map<String, Object> athlete = new HashMap<>();
|
|
|
+ athlete.put("athleteId", item.getAthleteId());
|
|
|
+ athlete.put("athleteCode", item.getAthleteCode());
|
|
|
+ athlete.put("name", item.getAthleteName());
|
|
|
+ athlete.put("teamId", item.getTeamId());
|
|
|
+ athlete.put("teamName", item.getTeamName());
|
|
|
+ groupResult.put(key, athlete);
|
|
|
+ }
|
|
|
+
|
|
|
+ result.put("success", true);
|
|
|
+ result.put("groupResult", groupResult);
|
|
|
+ result.put("totalAthletes", groupData.size());
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("从数据库查询分组结果失败", e);
|
|
|
+ result.put("success", false);
|
|
|
+ result.put("message", "查询分组结果失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存分组结果到数据库
|
|
|
+ *
|
|
|
+ * @param groupId 分组ID
|
|
|
+ * @param groupResult 分组结果
|
|
|
+ * @param groupInfo 分组信息
|
|
|
+ * @return 是否保存成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean saveGroupResult(Long groupId, Map<String, GameAthleteVo> groupResult, Object groupInfo) {
|
|
|
+ try {
|
|
|
+ // 先删除原有的分组数据
|
|
|
+ deleteGroupResultByGroupId(groupId);
|
|
|
+
|
|
|
+ // 保存新的分组数据
|
|
|
+ List<GameAthleteCompetitionGroupBo> boList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (Map.Entry<String, GameAthleteVo> entry : groupResult.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ GameAthleteVo value = entry.getValue();
|
|
|
+
|
|
|
+ String[] keyParts = key.split("-");
|
|
|
+ if (keyParts.length >= 2) {
|
|
|
+ GameAthleteCompetitionGroupBo bo = new GameAthleteCompetitionGroupBo();
|
|
|
+ bo.setGroupId(groupId);
|
|
|
+
|
|
|
+ // 设置组别和道次
|
|
|
+ bo.setGroupIndex(Long.valueOf(keyParts[0]));
|
|
|
+ bo.setTrackIndex(Long.valueOf(keyParts[1]));
|
|
|
+
|
|
|
+ // 设置运动员信息 - 直接从GameAthleteVo对象获取
|
|
|
+ bo.setAthleteId(value.getAthleteId());
|
|
|
+ bo.setAthleteCode(value.getAthleteCode());
|
|
|
+ bo.setAthleteName(value.getName());
|
|
|
+ bo.setTeamId(value.getTeamId());
|
|
|
+
|
|
|
+ // 通过队伍ID查询队伍名称
|
|
|
+ String teamName = "";
|
|
|
+ if (value.getTeamId() != null) {
|
|
|
+ try {
|
|
|
+ GameTeamVo team = getGameTeamService().queryById(value.getTeamId());
|
|
|
+ if (team != null) {
|
|
|
+ teamName = team.getTeamName();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("查询队伍名称失败,队伍ID: {}, 错误: {}", value.getTeamId(), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bo.setTeamName(teamName != null ? teamName : "");
|
|
|
+
|
|
|
+ // 设置其他信息
|
|
|
+ if (groupInfo instanceof GameEventGroupVo) {
|
|
|
+ GameEventGroupVo group = (GameEventGroupVo) groupInfo;
|
|
|
+ bo.setEventId(group.getEventId());
|
|
|
+ bo.setProjectId(group.getProjectId());
|
|
|
+ }
|
|
|
+
|
|
|
+ bo.setStatus("0"); // 正常状态
|
|
|
+ boList.add(bo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量插入
|
|
|
+ log.info("准备插入 {} 条分组数据", boList.size());
|
|
|
+ for (GameAthleteCompetitionGroupBo bo : boList) {
|
|
|
+ boolean insertResult = insertByBo(bo);
|
|
|
+ if (!insertResult) {
|
|
|
+ log.error("插入分组数据失败: groupId={}, athleteId={}, groupIndex={}, trackIndex={}",
|
|
|
+ bo.getGroupId(), bo.getAthleteId(), bo.getGroupIndex(), bo.getTrackIndex());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("分组数据保存完成,共插入 {} 条记录", boList.size());
|
|
|
+ return true;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("保存分组结果到数据库失败", e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据分组ID删除分组结果
|
|
|
+ *
|
|
|
+ * @param groupId 分组ID
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteGroupResultByGroupId(Long groupId) {
|
|
|
+ LambdaQueryWrapper<GameAthleteCompetitionGroup> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.eq(GameAthleteCompetitionGroup::getGroupId, groupId);
|
|
|
+ return baseMapper.delete(wrapper) > 0;
|
|
|
+ }
|
|
|
+}
|