|
|
@@ -0,0 +1,550 @@
|
|
|
+package org.dromara.business.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.business.domain.*;
|
|
|
+import org.dromara.business.domain.bo.TournamentBlindStructuresBo;
|
|
|
+import org.dromara.business.domain.bo.TournamentsBo;
|
|
|
+import org.dromara.business.domain.dto.ItemsPrizeDto;
|
|
|
+import org.dromara.business.domain.dto.TournamentsDto;
|
|
|
+import org.dromara.business.domain.enums.GameStatus;
|
|
|
+import org.dromara.business.domain.vo.*;
|
|
|
+import org.dromara.business.mapper.*;
|
|
|
+import org.dromara.business.service.ITournamentsTemplateService;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
+import org.dromara.system.domain.vo.SysOssVo;
|
|
|
+import org.dromara.system.service.ISysOssService;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+/**
|
|
|
+ * 【请填写功能名称】Service业务层处理
|
|
|
+ *
|
|
|
+ * @author Lion Li
|
|
|
+ * @date 2025-06-11
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class TournamentsTemplateServiceImpl implements ITournamentsTemplateService {
|
|
|
+
|
|
|
+ private final TournamentsTemplateMapper baseMapper;
|
|
|
+
|
|
|
+
|
|
|
+ private final TournamentEntryConditionsTemplateMapper tournamentEntryConditionsMapper;
|
|
|
+
|
|
|
+
|
|
|
+ private final TournamentBlindStructuresTemplateMapper tournamentBlindStructuresMapper;
|
|
|
+
|
|
|
+
|
|
|
+ private final PrizeDistributionsTemplateMapper prizeDistributionsMapper;
|
|
|
+
|
|
|
+
|
|
|
+ private final PrizeDistributionItemsTemplateMapper prizeDistributionItemsMapper;
|
|
|
+
|
|
|
+
|
|
|
+ private final ISysOssService ossService;
|
|
|
+
|
|
|
+ private final ParticipantsMapper participantsMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询【请填写功能名称】
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 【请填写功能名称】
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TournamentsVo queryById(Long id){
|
|
|
+ TournamentsVo tournamentsVo = baseMapper.selectVoByIdInfoTemplate(id);
|
|
|
+ Long tournamentId = tournamentsVo.getId();
|
|
|
+ //赛事报名条件
|
|
|
+ TournamentEntryConditionsVo tournamentEntryConditionsVo = tournamentEntryConditionsMapper.selectByTournamentInfoTemplate(tournamentId);
|
|
|
+ if(tournamentEntryConditionsVo!=null){
|
|
|
+ tournamentsVo.setItemsId(tournamentEntryConditionsVo.getItemId());
|
|
|
+ tournamentsVo.setItemsNum(tournamentEntryConditionsVo.getRequiredQuantity());
|
|
|
+ tournamentsVo.setItemsName(tournamentEntryConditionsVo.getItemsName());
|
|
|
+ }
|
|
|
+
|
|
|
+ //绑定的盲注信息
|
|
|
+ TournamentBlindStructuresVo tournamentBlindStructuresVo = tournamentBlindStructuresMapper.selectTournamentBlindStructureByTournamentIdTemplate(tournamentId);
|
|
|
+ if(tournamentBlindStructuresVo!=null){
|
|
|
+ tournamentsVo.setBlindStructureId(tournamentBlindStructuresVo.getBlindStructureId());
|
|
|
+ tournamentsVo.setBlindStructuresName(tournamentBlindStructuresVo.getBlindStructuresName());
|
|
|
+ }
|
|
|
+
|
|
|
+ //排名
|
|
|
+ List<PrizeDistributionsVo> prizeDistributionsVos = prizeDistributionsMapper.selectByTournamentIdTemplate(tournamentId);
|
|
|
+ if(prizeDistributionsVos!=null){
|
|
|
+ List<ItemsPrizeDto> itemsPrizeList=new ArrayList<>();
|
|
|
+
|
|
|
+ // 提取并按排名正序排序后,取出 id 列表
|
|
|
+ List<Long> ids = prizeDistributionsVos.stream()
|
|
|
+ .sorted(Comparator.comparing(PrizeDistributionsVo::getPaiming))
|
|
|
+ .map(PrizeDistributionsVo::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ int i=0;
|
|
|
+ for (Long id2 : ids) {
|
|
|
+ i++;
|
|
|
+ //奖品
|
|
|
+ PrizeDistributionItemsVo prizeDistributionItemsVos = prizeDistributionItemsMapper.selectByPrizeDistributionIdTemplate(id2);
|
|
|
+ ItemsPrizeDto itemsPrizeBo = new ItemsPrizeDto();
|
|
|
+ itemsPrizeBo.setRanking(Long.valueOf(i));
|
|
|
+ itemsPrizeBo.setItemId(prizeDistributionItemsVos.getItemId());
|
|
|
+ itemsPrizeBo.setQuantity(prizeDistributionItemsVos.getQuantity());
|
|
|
+ itemsPrizeList.add(itemsPrizeBo);
|
|
|
+
|
|
|
+ }
|
|
|
+ tournamentsVo.setItemsPrizeList(itemsPrizeList);
|
|
|
+
|
|
|
+ String statusText= GameStatus.getDescriptionFromCode(tournamentsVo.getStatus());
|
|
|
+ tournamentsVo.setStatusText(statusText);
|
|
|
+ }
|
|
|
+ int totalSignNum = participantsMapper.selectParticipantsTotal(tournamentId);
|
|
|
+ tournamentsVo.setSignNum(totalSignNum);
|
|
|
+ return tournamentsVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询【请填写功能名称】列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 【请填写功能名称】分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<TournamentsVo> queryPageList(TournamentsBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<TournamentsTemplate> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<TournamentsVo> result = baseMapper.selectVoPageTemplate(pageQuery.build(), lqw);
|
|
|
+ List<TournamentsVo> records = result.getRecords();
|
|
|
+ for (TournamentsVo record : records) {
|
|
|
+ Long tournamentId = record.getId();
|
|
|
+ String statusText= GameStatus.getDescriptionFromCode(record.getStatus());
|
|
|
+ record.setStatusText(statusText);
|
|
|
+ //赛事报名条件
|
|
|
+ TournamentEntryConditionsVo tournamentEntryConditionsVo = tournamentEntryConditionsMapper.selectByTournamentInfoTemplate(tournamentId);
|
|
|
+ if(tournamentEntryConditionsVo!=null){
|
|
|
+ record.setItemsId(tournamentEntryConditionsVo.getItemId());
|
|
|
+ record.setItemsNum(tournamentEntryConditionsVo.getRequiredQuantity());
|
|
|
+ record.setItemsName(tournamentEntryConditionsVo.getItemsName());
|
|
|
+ }
|
|
|
+
|
|
|
+ //绑定的盲注信息
|
|
|
+ TournamentBlindStructuresVo tournamentBlindStructuresVo = tournamentBlindStructuresMapper.selectTournamentBlindStructureByTournamentIdTemplate(tournamentId);
|
|
|
+ if(tournamentBlindStructuresVo!=null){
|
|
|
+ record.setBlindStructureId(tournamentBlindStructuresVo.getBlindStructureId());
|
|
|
+ record.setBlindStructuresName(tournamentBlindStructuresVo.getBlindStructuresName());
|
|
|
+ }
|
|
|
+
|
|
|
+ //排名
|
|
|
+ List<PrizeDistributionsVo> prizeDistributionsVos = prizeDistributionsMapper.selectByTournamentIdTemplate(tournamentId);
|
|
|
+ if(prizeDistributionsVos!=null){
|
|
|
+ List<ItemsPrizeDto> itemsPrizeList=new ArrayList<>();
|
|
|
+
|
|
|
+ // 提取并按排名正序排序后,取出 id 列表
|
|
|
+ List<Long> ids = prizeDistributionsVos.stream()
|
|
|
+ .sorted(Comparator.comparing(PrizeDistributionsVo::getPaiming))
|
|
|
+ .map(PrizeDistributionsVo::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ int i=0;
|
|
|
+ for (Long id2 : ids) {
|
|
|
+ i++;
|
|
|
+ //奖品
|
|
|
+ PrizeDistributionItemsVo prizeDistributionItemsVos = prizeDistributionItemsMapper.selectByPrizeDistributionIdTemplate(id2);
|
|
|
+ ItemsPrizeDto itemsPrizeBo = new ItemsPrizeDto();
|
|
|
+ itemsPrizeBo.setRanking(Long.valueOf(i));
|
|
|
+ itemsPrizeBo.setItemId(prizeDistributionItemsVos.getItemId());
|
|
|
+ itemsPrizeBo.setQuantity(prizeDistributionItemsVos.getQuantity());
|
|
|
+ itemsPrizeBo.setItemsName(prizeDistributionItemsVos.getItemsName());
|
|
|
+ itemsPrizeList.add(itemsPrizeBo);
|
|
|
+ }
|
|
|
+ record.setItemsPrizeList(itemsPrizeList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* int totalSignNum = participantsMapper.selectParticipantsTotal(tournamentId);
|
|
|
+ record.setSignNum(totalSignNum);*/
|
|
|
+ }
|
|
|
+
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的【请填写功能名称】列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 【请填写功能名称】列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<TournamentsVo> queryList(TournamentsBo bo) {
|
|
|
+ LambdaQueryWrapper<TournamentsTemplate> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectTournamentsVoListTemplate(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private static final Map<String, SFunction<TournamentsTemplate, ?>> ORDER_FIELD_MAP = new HashMap<>();
|
|
|
+
|
|
|
+ static {
|
|
|
+ ORDER_FIELD_MAP.put("startTime", TournamentsTemplate::getStartTime);
|
|
|
+ // 可以继续添加其他支持排序的字段
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<TournamentsTemplate> buildQueryWrapper(TournamentsBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<TournamentsTemplate> lqw = Wrappers.lambdaQuery();
|
|
|
+
|
|
|
+ // 获取排序字段和方式
|
|
|
+ String sortBy = bo.getSortBy();
|
|
|
+ Boolean isAsc = bo.getIsAsc();
|
|
|
+
|
|
|
+ // 如果有排序字段,并且该字段支持排序
|
|
|
+ if (sortBy != null && ORDER_FIELD_MAP.containsKey(sortBy)) {
|
|
|
+ SFunction<TournamentsTemplate, ?> columnFunc = ORDER_FIELD_MAP.get(sortBy);
|
|
|
+ if (Boolean.TRUE.equals(isAsc)) {
|
|
|
+ lqw.orderBy(true, true, columnFunc); // 升序
|
|
|
+ } else {
|
|
|
+ lqw.orderBy(true, false, columnFunc); // 降序
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 默认排序(比如按开始时间降序)
|
|
|
+ lqw.orderByDesc(TournamentsTemplate::getStartTime);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getName()), TournamentsTemplate::getName, bo.getName());
|
|
|
+ lqw.like(bo.getId() != null, TournamentsTemplate::getId, bo.getId());
|
|
|
+ lqw.like(bo.getStartTime() != null, TournamentsTemplate::getStartTime, bo.getStartTime());
|
|
|
+ lqw.eq(bo.getGameType() != null, TournamentsTemplate::getGameType, bo.getGameType());
|
|
|
+ lqw.eq(bo.getStartingChips() != null, TournamentsTemplate::getStartingChips, bo.getStartingChips());
|
|
|
+ lqw.eq(bo.getLevelDuration() != null, TournamentsTemplate::getLevelDuration, bo.getLevelDuration());
|
|
|
+ lqw.eq(bo.getLateRegistrationLevel() != null, TournamentsTemplate::getLateRegistrationLevel, bo.getLateRegistrationLevel());
|
|
|
+ lqw.eq(bo.getMaxPlayers() != null, TournamentsTemplate::getMaxPlayers, bo.getMaxPlayers());
|
|
|
+ lqw.eq(bo.getStatus() != null, TournamentsTemplate::getStatus, bo.getStatus());
|
|
|
+ lqw.eq(bo.getCreatedAt() != null, TournamentsTemplate::getCreatedAt, bo.getCreatedAt());
|
|
|
+ lqw.eq(bo.getUpdatedAt() != null, TournamentsTemplate::getUpdatedAt, bo.getUpdatedAt());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增【请填写功能名称】
|
|
|
+ *
|
|
|
+ * @param bo 【请填写功能名称】
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(TournamentsDto bo) {
|
|
|
+ try {
|
|
|
+
|
|
|
+
|
|
|
+ // 转换 BO -> Entity
|
|
|
+ TournamentsTemplate add = new TournamentsTemplate();
|
|
|
+ BeanUtils.copyProperties(bo, add);
|
|
|
+
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+
|
|
|
+ // 解析 itemsPrizeList JSON 字符串
|
|
|
+ List<ItemsPrizeDto> prizeList = bo.getItemsPrizeList();
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(prizeList)) {
|
|
|
+ log.error("奖励列表为空");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Long userId = LoginHelper.getUserId();
|
|
|
+ add.setCreateUserId(userId);
|
|
|
+ // 处理开始时间
|
|
|
+ add.setStartTime(parseDateTime(bo.getStartTime()));
|
|
|
+
|
|
|
+ //比赛ID
|
|
|
+ add.setTournamentsBiId(getCurrentDateTime()+bo.getGameType()+getRandomFourDigitNumber());
|
|
|
+
|
|
|
+ // 插入赛事主表
|
|
|
+ boolean flag = baseMapper.insertTournamentTemplate(add) > 0;
|
|
|
+ if (!flag) {
|
|
|
+ throw new RuntimeException("赛事插入失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long tournamentId = add.getId();
|
|
|
+
|
|
|
+ // 绑定盲注结构
|
|
|
+ bindBlindStructure(tournamentId, bo.getBlindStructureId());
|
|
|
+
|
|
|
+ // 添加报名条件
|
|
|
+ addEntryCondition(tournamentId, bo.getItemsId(), bo.getItemsNum());
|
|
|
+
|
|
|
+ // 处理奖励分布
|
|
|
+ processPrizeDistributions(tournamentId, prizeList);
|
|
|
+
|
|
|
+ return true;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("赛事插入过程中发生异常", e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量插入 1000 条赛事记录
|
|
|
+ *
|
|
|
+ * @return 是否批量插入成功
|
|
|
+ */
|
|
|
+
|
|
|
+ public Boolean batchInsertTournaments() {
|
|
|
+ try {
|
|
|
+ for (int i = 0; i < 1000; i++) {
|
|
|
+ // 模拟构造 TournamentsDto 数据
|
|
|
+ TournamentsDto bo = new TournamentsDto();
|
|
|
+
|
|
|
+ // 设置基础字段
|
|
|
+ bo.setName("赛事名称_" + i);
|
|
|
+ bo.setGameType((long) (1)); // 假设有5种类型
|
|
|
+ bo.setStartingChips(10000L);
|
|
|
+ bo.setLevelDuration(15L);
|
|
|
+ bo.setLateRegistrationLevel(3L);
|
|
|
+ bo.setMaxPlayers(100L);
|
|
|
+ bo.setStatus(1L); // 默认状态为进行中等
|
|
|
+ bo.setStartTime(LocalDateTime.now().plusMinutes(60L * i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+/*
|
|
|
+ bo.setCompetitionIcon("http://public-photos-fugui.oss-cn-beijing.aliyuncs.com/2025/07/05/987480c995204231aa21c3e8ec9af12b.png");
|
|
|
+*/
|
|
|
+ bo.setRewardPlayers(3);
|
|
|
+ bo.setSignTime(10L);
|
|
|
+
|
|
|
+ // 设置盲注结构 ID(假设存在)
|
|
|
+ bo.setBlindStructureId(9L);
|
|
|
+
|
|
|
+ // 设置报名条件
|
|
|
+ bo.setItemsId(1L);
|
|
|
+ bo.setItemsNum(10L);
|
|
|
+
|
|
|
+ // 设置奖励列表
|
|
|
+ List<ItemsPrizeDto> prizeList = new ArrayList<>();
|
|
|
+ ItemsPrizeDto prize = new ItemsPrizeDto();
|
|
|
+ prize.setRanking(1L);
|
|
|
+ prize.setItemId(1L);
|
|
|
+ prize.setQuantity(10L);
|
|
|
+ prize.setItemsName("三湘杯参赛卡");
|
|
|
+ prizeList.add(prize);
|
|
|
+ bo.setItemsPrizeList(prizeList);
|
|
|
+
|
|
|
+ // 调用已有的插入方法
|
|
|
+ if (!insertByBo(bo)) {
|
|
|
+ log.error("第 {} 条赛事插入失败", i + 1);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("批量插入赛事过程中发生异常", e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void bindBlindStructure(Long tournamentId, Long blindStructureId) {
|
|
|
+ TournamentBlindStructureTemplate structure = new TournamentBlindStructureTemplate();
|
|
|
+ structure.setTournamentId(tournamentId);
|
|
|
+ structure.setBlindStructureId(blindStructureId);
|
|
|
+ tournamentBlindStructuresMapper.insertTournamentBlindStructureTemplate(structure);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addEntryCondition(Long tournamentId, Long itemId, Long requiredQuantity) {
|
|
|
+ TournamentEntryConditionsTemplate condition = new TournamentEntryConditionsTemplate();
|
|
|
+ condition.setTournamentId(tournamentId);
|
|
|
+ condition.setItemId(itemId);
|
|
|
+ condition.setRequiredQuantity(requiredQuantity);
|
|
|
+ tournamentEntryConditionsMapper.insert(condition);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processPrizeDistributions(Long tournamentId, List<ItemsPrizeDto> itemsPrizeList) {
|
|
|
+ // 排序(按排名正序)
|
|
|
+ Collections.sort(itemsPrizeList, Comparator.comparing(ItemsPrizeDto::getRanking));
|
|
|
+
|
|
|
+ for (ItemsPrizeDto prizeBo : itemsPrizeList) {
|
|
|
+ PrizeDistributionsTemplate prizeDistribution = new PrizeDistributionsTemplate();
|
|
|
+ prizeDistribution.setTournamentId(tournamentId);
|
|
|
+ prizeDistribution.setPaiming(Long.valueOf(prizeBo.getRanking()));
|
|
|
+ prizeDistributionsMapper.insertTemplate(prizeDistribution);
|
|
|
+
|
|
|
+ PrizeDistributionItemsTemplate distributionItems = new PrizeDistributionItemsTemplate();
|
|
|
+ distributionItems.setPrizeDistributionId(prizeDistribution.getId());
|
|
|
+ distributionItems.setItemId(Long.valueOf(prizeBo.getItemId()));
|
|
|
+ distributionItems.setQuantity(Long.valueOf(prizeBo.getQuantity()));
|
|
|
+ prizeDistributionItemsMapper.insert(distributionItems);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改【请填写功能名称】
|
|
|
+ *
|
|
|
+ * @param bo 【请填写功能名称】
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(TournamentsDto bo) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 转换 BO -> Entity
|
|
|
+ TournamentsTemplate update = new TournamentsTemplate();
|
|
|
+ BeanUtils.copyProperties(bo, update);
|
|
|
+
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ // 解析 itemsPrizeList JSON 字符串
|
|
|
+ List<ItemsPrizeDto> prizeList = bo.getItemsPrizeList();
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(prizeList)) {
|
|
|
+ log.error("奖励列表为空");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Long userId = LoginHelper.getUserId();
|
|
|
+ update.setUpdateUserId(userId);
|
|
|
+ // 处理开始时间
|
|
|
+ update.setStartTime(parseDateTime(bo.getStartTime()));
|
|
|
+
|
|
|
+ // 插入赛事主表
|
|
|
+ boolean flag = baseMapper.updateTournamentsByIdTemplate(update) > 0;
|
|
|
+ if (!flag) {
|
|
|
+ throw new RuntimeException("赛事修改失败");
|
|
|
+ }
|
|
|
+ Long tournamentId= update.getId();
|
|
|
+ //删除 旧盲注绑定信息
|
|
|
+ tournamentBlindStructuresMapper.deleteTournamentBlindStructureByTournamentIdTemplate(tournamentId);
|
|
|
+
|
|
|
+ // 绑定盲注结构
|
|
|
+ bindBlindStructure(tournamentId, bo.getBlindStructureId());
|
|
|
+
|
|
|
+ // 修改报名条件
|
|
|
+ TournamentEntryConditionsTemplate tournamentEntryConditions=new TournamentEntryConditionsTemplate();
|
|
|
+ tournamentEntryConditions.setItemId(bo.getItemsId());
|
|
|
+ tournamentEntryConditions.setRequiredQuantity(bo.getItemsNum());
|
|
|
+ tournamentEntryConditionsMapper.updateByTournamentIdTemplate(tournamentEntryConditions);
|
|
|
+
|
|
|
+ //删除奖励排名 同时删除奖励对应信息
|
|
|
+ List<PrizeDistributionsVo> prizeDistributionsVos = prizeDistributionsMapper.selectByTournamentIdTemplate(tournamentId);
|
|
|
+ if(prizeDistributionsVos.size()>0){
|
|
|
+ for (PrizeDistributionsVo prizeDistributionsVo : prizeDistributionsVos) {
|
|
|
+ prizeDistributionsMapper.deleteByIdsTemplate(prizeDistributionsVo.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //重新处理奖励分布
|
|
|
+ processPrizeDistributions(tournamentId, prizeList);
|
|
|
+ return true;
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("赛事修改过程中发生异常", e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(TournamentsTemplate entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除【请填写功能名称】信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteTournamentByIdsTemplate(ids) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<TournamentBlindStructuresListVo> selectTournamentBlindStructuresList(TournamentBlindStructuresBo bo, PageQuery pageQuery) {
|
|
|
+ Page<TournamentBlindStructuresListVo> result = baseMapper.selectTournamentBlindStructuresListTemplate(pageQuery.build(), bo);
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void saveOrUpdateTournamentBlindStructure(Long tournamentId, List<Long> blindStructureIds) {
|
|
|
+ // 先删除原有数据
|
|
|
+ baseMapper.deleteByBlindTournamentIdTemplate(tournamentId);
|
|
|
+ // 插入新数据
|
|
|
+ if (CollectionUtils.isNotEmpty(blindStructureIds)) {
|
|
|
+ baseMapper.batchInsertTournamentBlindStructuresTemplate(tournamentId,blindStructureIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SysOssVo uploadTournament(MultipartFile file) {
|
|
|
+ // 1. 上传文件到 OSS
|
|
|
+ SysOssVo sysOssVo = ossService.upload(file);
|
|
|
+ return sysOssVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<ItemsPrizeDto> parsePrizeList(String itemsPrizeListJson, ObjectMapper mapper) throws Exception {
|
|
|
+ if (itemsPrizeListJson == null || itemsPrizeListJson.isBlank()) {
|
|
|
+ throw new IllegalArgumentException("itemsPrizeList 不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ String cleanedJson = itemsPrizeListJson.trim();
|
|
|
+ if (cleanedJson.startsWith(",")) {
|
|
|
+ cleanedJson = cleanedJson.substring(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ return mapper.readValue(
|
|
|
+ cleanedJson,
|
|
|
+ mapper.getTypeFactory().constructCollectionType(List.class, ItemsPrizeDto.class)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date parseDateTime(String dateTimeStr) throws ParseException {
|
|
|
+ if (dateTimeStr == null || dateTimeStr.isBlank()) {
|
|
|
+ throw new IllegalArgumentException("startTime 不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.parse(dateTimeStr, formatter);
|
|
|
+ return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前年月日时分秒(格式:yyyy-MM-dd HH:mm:ss)
|
|
|
+ *
|
|
|
+ * @return 格式化后的时间字符串
|
|
|
+ */
|
|
|
+ public static String getCurrentDateTime() {
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
+ return now.format(formatter);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 随机获取一个四位数(1000 ~ 9999)
|
|
|
+ *
|
|
|
+ * @return 四位数整数
|
|
|
+ */
|
|
|
+ public static int getRandomFourDigitNumber() {
|
|
|
+ Random random = new Random();
|
|
|
+ // 生成 [1000, 9999] 范围内的随机数
|
|
|
+ return 1000 + random.nextInt(9000);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|