Ver código fonte

feat(business): 添加赛事删除和关闭功能

- 在 ITournamentsService 接口中添加 deleteTournament 和 closeSendTournament 方法
- 在 TournamentsServiceImpl 类中实现这两个方法
- 在 TournamentsMapper 中添加 deleteTournament 方法
- 更新 TournamentsVo 类,添加 isDelete 字段
- 修改 RedisKeys 类,增加 CHANNEL_ADMIN 常量- 更新 RewardClaimsServiceImpl 和 UserServiceImpl,使用新的消息广播机制
- 调整 ScheduleConfigServiceImpl 中的错误处理和日志记录
fugui001 3 meses atrás
pai
commit
6e9b1eeed3
14 arquivos alterados com 113 adições e 19 exclusões
  1. 1 1
      ruoyi-admin/src/main/resources/application-dev.yml
  2. 22 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/controller/TournamentsController.java
  3. 1 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/vo/TournamentsVo.java
  4. 2 1
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/mapper/ScheduleTournamentsReletionMapper.java
  5. 3 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/mapper/TournamentsMapper.java
  6. 1 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/IItemsService.java
  7. 16 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/ITournamentsService.java
  8. 5 1
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/RewardClaimsServiceImpl.java
  9. 15 11
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/ScheduleConfigServiceImpl.java
  10. 25 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/TournamentsServiceImpl.java
  11. 7 3
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/UserServiceImpl.java
  12. 3 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/utils/RedisKeys.java
  13. 5 0
      ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/ScheduleTournamentsReletionMapper.xml
  14. 7 2
      ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/TournamentsMapper.xml

+ 1 - 1
ruoyi-admin/src/main/resources/application-dev.yml

@@ -113,7 +113,7 @@ spring.data:
     # 数据库索引
     database: 0
     # redis 密码必须配置
-    auth: 123456
+    password: 123456
     # 连接超时时间
     timeout: 10s
     # 是否开启ssl

+ 22 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/controller/TournamentsController.java

@@ -145,5 +145,27 @@ public class TournamentsController extends BaseController {
         return R.ok(tournamentsService.uploadTournament(file));
     }
 
+    @SaCheckPermission("business:tournaments:deleteCheckTournament")
+    @Log(title = "【赛事管理-删除】", businessType = BusinessType.DELETE)
+    @RepeatSubmit()
+    @DeleteMapping("/deleteCheckTournament/{ids}")
+    public R<Void> deleteCheckTournament(@NotEmpty(message = "主键不能为空")
+                                             @PathVariable Long[] ids) {
+        return toAjax(tournamentsService.deleteTournament(ids[0]));
+    }
+
+
+    /**
+     * 关闭比赛
+     * @param id
+     * @return
+     */
+    @SaCheckPermission("business:tournaments:closeSendTournament")
+    @GetMapping("/closeSendTournament/{id}")
+    public R<Void> closeSendTournament(@NotNull(message = "主键不能为空")
+                                    @PathVariable Long id) {
+        return toAjax(tournamentsService.closeSendTournament(id));
+    }
+
 
 }

+ 1 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/vo/TournamentsVo.java

@@ -199,5 +199,6 @@ public class TournamentsVo implements Serializable {
      */
     private Boolean isComplaints;
 
+    private Boolean isDelete;
 
 }

+ 2 - 1
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/mapper/ScheduleTournamentsReletionMapper.java

@@ -28,6 +28,7 @@ public interface ScheduleTournamentsReletionMapper extends BaseMapperPlus<Schedu
     @InterceptorIgnore(tenantLine = "true")
     int selectByScheduleRelationExit(@Param("templateId") Long templateId);
 
-
+    @InterceptorIgnore(tenantLine = "true")
+    int deleteByConfigId(@Param("configId") Long configId);
 
 }

+ 3 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/mapper/TournamentsMapper.java

@@ -53,5 +53,8 @@ public interface TournamentsMapper extends BaseMapperPlus<Tournaments, Tournamen
     void batchInsertTournamentBlindStructures(@Param("tournamentId") Long tournamentId,
                                               @Param("blindStructureIds") List<Long> blindStructureIds);
 
+    @InterceptorIgnore(tenantLine = "true")
+    int deleteTournament(@Param("tournamentId") Long tournamentId);
+
 }
 

+ 1 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/IItemsService.java

@@ -74,4 +74,5 @@ public interface IItemsService {
     List<ItemsVo> selectItemsSelList();
 
 
+
 }

+ 16 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/ITournamentsService.java

@@ -94,4 +94,20 @@ public interface ITournamentsService {
      */
     SysOssVo uploadTournament(MultipartFile file);
 
+
+
+    /**
+     * 删除 tournament
+     *
+     * @return
+     */
+    Boolean deleteTournament(Long id);
+
+    /**
+     * 关闭报名
+     * @param id
+     * @return
+     */
+    Boolean closeSendTournament(Long id);
+
 }

+ 5 - 1
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/RewardClaimsServiceImpl.java

@@ -1,5 +1,6 @@
 package org.dromara.business.service.impl;
 
+import cn.hutool.json.JSONObject;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -706,7 +707,10 @@ public class RewardClaimsServiceImpl implements IRewardClaimsService {
                 } finally {
                     ItemOperationLock.releaseLock(bo.getPlayerId()); // 确保释放锁
                 }
-                redisUtil.publish("channel:item_updates", rewardClaimsVo.getPlayerId());
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("channelType", "item_update");
+                jsonObject.put("value", rewardClaimsVo.getPlayerId());
+                redisUtil.publish(RedisKeys.CHANNEL_ADMIN, jsonObject);
                 return Boolean.TRUE;
             }else{
                 throw new RuntimeException("该奖励已处理,请勿重复操作");

+ 15 - 11
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/ScheduleConfigServiceImpl.java

@@ -175,7 +175,7 @@ public class ScheduleConfigServiceImpl implements IScheduleConfigService {
 
         // 1. 查询创建方案
         CreationSchemeVo scheme = schemeRepo.selectAllCreationSchemesInfo(dto.getCreationSchemeCode());
-        if (scheme == null) throw new IllegalArgumentException("Invalid scheme code: " + dto.getCreationSchemeCode());
+        if (scheme == null) throw new IllegalArgumentException("无效的创建方案 Invalid scheme code: " + dto.getCreationSchemeCode());
 
         // 2. 计算开始和结束日期
         LocalDate startDate = calculateStartDate(dto.getCreationSchemeCode());
@@ -465,23 +465,23 @@ public class ScheduleConfigServiceImpl implements IScheduleConfigService {
 
     public R<String> updateScheduleConfig(Long configId, ScheduleConfigRequestBo dto) {
 
-        if(dto.getExecTimes().size()<=0){
+        if(dto.getExecTimes().isEmpty()){
             return R.fail("时间设置为空");
         }
-        if(dto.getRepeatTypes().size()<=0){
+        if(dto.getRepeatTypes().isEmpty()){
             return R.fail("重复设置为空");
         }
 
-        int selectByScheduleRelationExit = scheduleTournamentsReletionMapper.selectByScheduleRelationExit(dto.getTemplateId());
+     /*   int selectByScheduleRelationExit = scheduleTournamentsReletionMapper.selectByScheduleRelationExit(dto.getTemplateId());
         if(selectByScheduleRelationExit>0){
             //已经生成过赛事数据
             return R.fail("该配置已经分配过赛事!");
-        }
-
+        }*/
         // 1. 检查配置是否存在
         ScheduleConfigVo existingConfig = baseMapper.selectScheduleConfigById(configId);
         if (existingConfig == null) {
-            throw new IllegalArgumentException("Schedule config not found for id: " + configId);
+            log.info("Schedule config not found for id: {}", configId);
+            return R.fail("该配置不存在!");
         }
         CreationSchemeVo scheme = schemeRepo.selectAllCreationSchemesInfo(dto.getCreationSchemeCode());
 
@@ -544,14 +544,14 @@ public class ScheduleConfigServiceImpl implements IScheduleConfigService {
         // 1. 检查配置是否存在
         ScheduleConfigVo existingConfig = baseMapper.selectScheduleConfigById(configId);
 
-        int selectByScheduleRelationExit = scheduleTournamentsReletionMapper.selectByScheduleRelationExit(existingConfig.getTemplateId());
+    /*    int selectByScheduleRelationExit = scheduleTournamentsReletionMapper.selectByScheduleRelationExit(existingConfig.getTemplateId());
         if(selectByScheduleRelationExit>0){
             //已经生成过赛事数据
             return R.fail("该配置已经分配过赛事!禁止删除!");
-        }
-
+        }*/
         if (existingConfig == null) {
-            throw new IllegalArgumentException("Schedule config not found for id: " + configId);
+            log.info("Schedule config not found for id: {}", configId);
+            return R.fail("该配置不存在!禁止删除!");
         }
         try {
             // 2. 🔴 按依赖顺序删除关联数据
@@ -573,6 +573,10 @@ public class ScheduleConfigServiceImpl implements IScheduleConfigService {
             baseMapper.deleteScheduleConfig(ids);
             log.info("Deleted schedule config with id: {}", configId);
 
+            //4 删除  赛事分配的模版关系表
+            scheduleTournamentsReletionMapper.deleteByConfigId(configId);
+            log.info("Deleted schedule_tournaments_reletion config with id: {}", configId);
+
         } catch (Exception e) {
             log.error("Error deleting schedule config and its associations, configId: {}", configId, e);
             throw e; // 事务会回滚

+ 25 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/TournamentsServiceImpl.java

@@ -1,5 +1,6 @@
 package org.dromara.business.service.impl;
 
+import cn.hutool.json.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 
 import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
@@ -12,6 +13,8 @@ import org.dromara.business.domain.enums.GameStatus;
 import org.dromara.business.domain.vo.*;
 import org.dromara.business.mapper.*;
 import org.dromara.business.service.IBlindLevelsService;
+import org.dromara.business.utils.RedisKeys;
+import org.dromara.business.utils.RedisUtil;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.common.mybatis.core.page.PageQuery;
@@ -24,6 +27,7 @@ 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.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.dromara.business.domain.bo.TournamentsBo;
 import org.dromara.business.service.ITournamentsService;
@@ -70,6 +74,9 @@ public class TournamentsServiceImpl implements ITournamentsService {
 
     private final IBlindLevelsService blindLevelsService;
 
+    @Autowired
+    RedisUtil redisUtil;
+
     /**
      * 查询【请填写功能名称】
      *
@@ -517,6 +524,24 @@ public class TournamentsServiceImpl implements ITournamentsService {
         return sysOssVo;
     }
 
+    @Override
+    public Boolean deleteTournament(Long id) {
+        return baseMapper.deleteTournament(id)  > 0;
+    }
+
+    // 管理关闭锦标赛
+    @Override
+    public Boolean closeSendTournament(Long id) {
+        if(id==null || id==0L){
+            return false;
+        }
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("channelType", "tournament_close");
+        jsonObject.put("value", id);
+        redisUtil.publish(RedisKeys.CHANNEL_ADMIN, jsonObject);
+        return true;
+    }
+
 
     private List<ItemsPrizeDto> parsePrizeList(String itemsPrizeListJson, ObjectMapper mapper) throws Exception {
         if (itemsPrizeListJson == null || itemsPrizeListJson.isBlank()) {

+ 7 - 3
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/UserServiceImpl.java

@@ -1,7 +1,9 @@
 package org.dromara.business.service.impl;
 
+import cn.hutool.json.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.dromara.business.domain.PlayerItems;
 import org.dromara.business.domain.PlayersItemsLog;
 import org.dromara.business.domain.User;
@@ -13,6 +15,7 @@ import org.dromara.business.domain.vo.UserVo;
 import org.dromara.business.mapper.*;
 import org.dromara.business.service.IUserService;
 import org.dromara.business.utils.ItemOperationLock;
+import org.dromara.business.utils.RedisKeys;
 import org.dromara.business.utils.RedisUtil;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
@@ -54,7 +57,6 @@ public class UserServiceImpl implements IUserService {
     @Autowired
     RedisUtil redisUtil;
 
-
     /**
      * 查询【请填写功能名称】
      *
@@ -339,8 +341,10 @@ public class UserServiceImpl implements IUserService {
                 if (updateCount <= 0) {
                     throw new RuntimeException("道具发放失败");
                 }
-
-                redisUtil.publish("channel:item_updates", bo.getUserId());
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("channelType", "item_update");
+                jsonObject.put("value", bo.getUserId());
+                redisUtil.publish(RedisKeys.CHANNEL_ADMIN, jsonObject);
                 return Boolean.TRUE;
 
             } finally {

+ 3 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/utils/RedisKeys.java

@@ -8,6 +8,9 @@ public class RedisKeys {
     //手牌 底牌
     public static final String GAME_POKER_TEST_HANDS = "game:poker:test:hands";
 
+    //消息广播
+    public static final String CHANNEL_ADMIN = "channel:admin";
+
     /**
      * 生成排行榜 key
      * @param tournamentId 比赛 ID

+ 5 - 0
ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/ScheduleTournamentsReletionMapper.xml

@@ -32,6 +32,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
 
 
+    <!-- 删除:根据ConfigId -->
+    <delete id="deleteByConfigId" parameterType="long">
+        DELETE FROM schedule_tournaments_reletion
+        WHERE config_id = #{configId}
+    </delete>
 
 
     <!-- 查询:根据模版ID -->

+ 7 - 2
ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/TournamentsMapper.xml

@@ -10,11 +10,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
 
     <select id="selectTournamentsVoList" resultType="org.dromara.business.domain.vo.TournamentsVo">
-        SELECT id, name, start_time, end_time,game_type, starting_chips, level_duration, late_registration_level, max_players, status, created_at, updated_at,sign_time,competition_icon,tournaments_bi_id,robot_count FROM tournaments  ${ew.customSqlSegment}
+        SELECT id, name, start_time, end_time,game_type, starting_chips, level_duration, late_registration_level, max_players, status, created_at, updated_at,sign_time,competition_icon,tournaments_bi_id,robot_count,is_delete FROM tournaments  ${ew.customSqlSegment}
     </select>
 
     <select id="selectVoByIdInfo" resultType="org.dromara.business.domain.vo.TournamentsVo">
-       SELECT id, name, start_time, end_time,game_type, starting_chips, level_duration, late_registration_level, max_players, status, created_at, updated_at,sign_time,competition_icon,tournaments_bi_id,robot_count FROM tournaments WHERE id =  #{id}
+       SELECT id, name, start_time, end_time,game_type, starting_chips, level_duration, late_registration_level, max_players, status, created_at, updated_at,sign_time,competition_icon,tournaments_bi_id,robot_count,is_delete FROM tournaments WHERE id =  #{id}
     </select>
 
 
@@ -130,4 +130,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         tournament_id = tournament_id
     </insert>
 
+
+    <delete id="deleteTournament">
+         update tournaments set is_delete=true where id=#{tournamentId}
+    </delete>
+
 </mapper>