浏览代码

feat(system): 新增赛事与类目/标签关联功能

- 添加赛事与类目/标签关联实体类 TournamentCategoryTagTemplate
- 实现关联表的 MyBatis 映射文件及 SQL 操作
- 提供插入、删除、查询类目/标签 ID 及名称的方法
- 在赛事模板中增加 rebuy 和 delayShow 字段支持
- 更新赛事模板查询与保存逻辑以支持类目/标签关联
- 实现赛事创建与更新时的类目/标签绑定功能
- 支持赛事编辑时清除并重新绑定类目/标签关系
fugui001 1 周之前
父节点
当前提交
ddff3f93d7

+ 35 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/TournamentCategoryTagTemplate.java

@@ -0,0 +1,35 @@
+package org.dromara.business.domain;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.dromara.common.mybatis.core.domain.BaseEntity;
+
+import java.io.Serial;
+
+/**
+ * 赛事与类目/标签关联对象 tournament_category_tag_template
+ *
+ * @author Lion Li
+ * @date 2025-12-12
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@TableName("tournament_category_tag_template")
+public class TournamentCategoryTagTemplate extends BaseEntity {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 赛事ID,关联 tournaments.id
+     */
+    private Long tournamentId;
+
+    /**
+      * 类目/标ID,关联 category_tag.id
+     */
+    private Long categoryTagId;
+
+
+}

+ 5 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/TournamentsTemplate.java

@@ -144,4 +144,9 @@ public class TournamentsTemplate extends BaseEntity {
      */
     private  Integer qualifierValue;
 
+    // 重复买入:<0不可重复买入,0-不限制,>0限制次数
+    private Integer rebuy;
+    //0-默认不开启延迟看牌,1-开启
+    private Integer delayShow;
+
 }

+ 38 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/mapper/TournamentCategoryTagTemplateMapper.java

@@ -0,0 +1,38 @@
+package org.dromara.business.mapper;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
+import org.apache.ibatis.annotations.Param;
+import org.dromara.business.domain.TournamentCategoryTagTemplate;
+import org.dromara.business.domain.vo.TournamentCategoryTagVo;
+import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
+
+import java.util.List;
+
+/**
+ * 赛事与类目/标签关联Mapper接口
+ *
+ * @author Lion Li
+ * @date 2025-12-12
+ */
+@DS("mysql2")
+public interface TournamentCategoryTagTemplateMapper extends BaseMapperPlus<TournamentCategoryTagTemplate, TournamentCategoryTagVo> {
+
+    @InterceptorIgnore(tenantLine = "true")
+    int insertTournamentCategoryTag(TournamentCategoryTagTemplate categoryTag);
+
+    @InterceptorIgnore(tenantLine = "true")
+    int deleteByTournamentCategoryTagTournamentId(@Param("tournamentId") Long tournamentId);
+
+    @InterceptorIgnore(tenantLine = "true")
+    int deleteTournamentCategoryTagByIds(@Param("tournamentId") Long tournamentId, @Param("categoryTagId") Long categoryTagId);
+
+    @InterceptorIgnore(tenantLine = "true")
+    List<Long> selectCategoryOrTagId(@Param("type") String type, @Param("tournamentId") Long tournamentId);
+
+    @InterceptorIgnore(tenantLine = "true")
+    List<String> selectNameCategoryOrTagId(@Param("type") String type,@Param("tournamentId") Long tournamentId);
+
+
+
+}

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

@@ -66,6 +66,8 @@ public class TournamentsTemplateServiceImpl implements ITournamentsTemplateServi
 
     private final UserComplaintsMapper userComplaintsMapper;
 
+    private final TournamentCategoryTagTemplateMapper tournamentCategoryTagTemplateMapper;
+
     /**
      * 查询【请填写功能名称】
      *
@@ -130,6 +132,12 @@ public class TournamentsTemplateServiceImpl implements ITournamentsTemplateServi
         }else{
             tournamentsVo.setIsComplaints(false);
         }
+
+        //查询类目和标签ID
+        List<Long> category = tournamentCategoryTagTemplateMapper.selectCategoryOrTagId("CATEGORY", tournamentId);
+        tournamentsVo.setCategoryId(category);
+        List<Long> tag = tournamentCategoryTagTemplateMapper.selectCategoryOrTagId("TAG", tournamentId);
+        tournamentsVo.setTagId(tag);
         return tournamentsVo;
     }
 
@@ -198,6 +206,10 @@ public class TournamentsTemplateServiceImpl implements ITournamentsTemplateServi
 
            /* int totalSignNum = participantsMapper.selectParticipantsTotal(tournamentId);
             record.setSignNum(totalSignNum);*/
+            List<String> category = tournamentCategoryTagTemplateMapper.selectNameCategoryOrTagId("CATEGORY", tournamentId);
+            List<String> tag = tournamentCategoryTagTemplateMapper.selectNameCategoryOrTagId("TAG", tournamentId);
+            record.setCategoryName(category);
+            record.setTagName(tag);
         }
 
         return TableDataInfo.build(result);
@@ -311,6 +323,8 @@ public class TournamentsTemplateServiceImpl implements ITournamentsTemplateServi
             // 处理奖励分布
             processPrizeDistributions(tournamentId, prizeList);
 
+            addCategoryTag(tournamentId, bo.getCategoryId(),bo.getTagId());
+
             return true;
 
         } catch (Exception e) {
@@ -394,7 +408,27 @@ public class TournamentsTemplateServiceImpl implements ITournamentsTemplateServi
         condition.setRequiredQuantity(requiredQuantity);
         tournamentEntryConditionsMapper.insert(condition);
     }
+    private void addCategoryTag(Long tournamentId, List<Long> categoryIds, List<Long> tagIds) {
+        // 如果 categoryIds 有值,则为每个 categoryId 插入一条记录
+        if (CollectionUtils.isNotEmpty(categoryIds)) {
+            for (Long categoryId : categoryIds) {
+                TournamentCategoryTagTemplate categoryTag = new TournamentCategoryTagTemplate();
+                categoryTag.setTournamentId(tournamentId);
+                categoryTag.setCategoryTagId(categoryId);
+                tournamentCategoryTagTemplateMapper.insertTournamentCategoryTag(categoryTag);
+            }
+        }
 
+        // 如果 tagIds 有值,则为每个 tagId 插入一条记录
+        if (CollectionUtils.isNotEmpty(tagIds)) {
+            for (Long tagId : tagIds) {
+                TournamentCategoryTagTemplate tag = new TournamentCategoryTagTemplate();
+                tag.setTournamentId(tournamentId);
+                tag.setCategoryTagId(tagId);
+                tournamentCategoryTagTemplateMapper.insertTournamentCategoryTag(tag);
+            }
+        }
+    }
     private void processPrizeDistributions(Long tournamentId, List<ItemsPrizeDto> itemsPrizeList) {
         // 排序(按排名正序)
         Collections.sort(itemsPrizeList, Comparator.comparing(ItemsPrizeDto::getRanking));
@@ -472,6 +506,10 @@ public class TournamentsTemplateServiceImpl implements ITournamentsTemplateServi
             }
             //重新处理奖励分布
             processPrizeDistributions(tournamentId, prizeList);
+
+            tournamentCategoryTagTemplateMapper.deleteByTournamentCategoryTagTournamentId(tournamentId);
+
+            addCategoryTag(tournamentId, bo.getCategoryId(),bo.getTagId());
              return true;
         }catch (Exception e){
             log.error("赛事修改过程中发生异常", e);

+ 50 - 0
ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/TournamentCategoryTagTemplateMapper.xml

@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.dromara.business.mapper.TournamentCategoryTagTemplateMapper">
+
+
+    <!-- 插入单条(通常用于批量) -->
+    <insert id="insertTournamentCategoryTag">
+        INSERT INTO tournament_category_tag_template (tournament_id, category_tag_id)
+        VALUES (#{tournamentId}, #{categoryTagId})
+        ON DUPLICATE KEY UPDATE
+        tournament_id = tournament_id; <!-- 防止报错,实际不更新 -->
+    </insert>
+
+    <!-- 批量插入(推荐方式) -->
+    <insert id="batchInsertTournamentCategoryTag">
+        INSERT INTO tournament_category_tag_template (tournament_id, category_tag_id)
+        VALUES
+        <foreach collection="list" item="item" separator=",">
+            (#{item.tournamentId}, #{item.categoryTagId})
+        </foreach>
+        ON DUPLICATE KEY UPDATE
+        tournament_id = tournament_id;
+    </insert>
+
+    <!-- 根据赛事ID删除所有关联(用于“重新绑定”) -->
+    <delete id="deleteByTournamentCategoryTagTournamentId">
+        DELETE FROM tournament_category_tag_template
+        WHERE tournament_id = #{tournamentId}
+    </delete>
+
+    <!-- 删除单条关联 -->
+    <delete id="deleteTournamentCategoryTagByIds">
+        DELETE FROM tournament_category_tag_template
+        WHERE tournament_id = #{tournamentId}
+          AND category_tag_id = #{categoryTagId}
+    </delete>
+
+    <select id="selectCategoryOrTagId" resultType="Long">
+        select a.category_tag_id from tournament_category_tag_template  a left join  category_tag b  on a.category_tag_id=b.id  where b.type=#{type} and  a.tournament_id=#{tournamentId}
+    </select>
+
+
+    <select id="selectNameCategoryOrTagId" resultType="String">
+        select b.name from tournament_category_tag_template  a left join  category_tag b  on a.category_tag_id=b.id  where b.type=#{type} and  a.tournament_id=#{tournamentId}
+    </select>
+
+
+</mapper>

+ 9 - 3
ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/TournamentsTemplateMapper.xml

@@ -10,11 +10,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
 
     <select id="selectTournamentsVoListTemplate" 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,reward_players,total_signup,robot_count,delay_card_time,delay_card_num,action_time,competition_bg,min_players,game_variant,target_tournament_id,qualifier_value,qualifier_type,start_blind_level FROM tournaments_template  ${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,reward_players,total_signup,robot_count,delay_card_time,delay_card_num,action_time,competition_bg,min_players,game_variant,target_tournament_id,qualifier_value,qualifier_type,start_blind_level,rebuy,delay_show FROM tournaments_template  ${ew.customSqlSegment}
     </select>
 
     <select id="selectVoByIdInfoTemplate" 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,reward_players,total_signup,robot_count,delay_card_time,delay_card_num,action_time,competition_bg,min_players,game_variant,target_tournament_id,qualifier_value,qualifier_type,start_blind_level FROM tournaments_template 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,reward_players,total_signup,robot_count,delay_card_time,delay_card_num,action_time,competition_bg,min_players,game_variant,target_tournament_id,qualifier_value,qualifier_type,start_blind_level,rebuy,delay_show FROM tournaments_template WHERE id =  #{id}
     </select>
 
 
@@ -46,7 +46,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="targetTournamentId != null">target_tournament_id = #{targetTournamentId},</if>
             <if test="qualifierType != null">qualifier_type = #{qualifierType},</if>
             <if test="startBlindLevel != null">start_blind_level = #{startBlindLevel},</if>
-            <if test="qualifierValue != null">qualifier_value = #{qualifierValue}</if>
+            <if test="qualifierValue != null">qualifier_value = #{qualifierValue},</if>
+            <if test="rebuy != null">rebuy = #{rebuy},</if>
+            <if test="delayShow != null">delay_show = #{delayShow}</if>
         </set>
         WHERE id = #{id}
     </update>
@@ -79,6 +81,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="qualifierType != null">qualifier_type,</if>
             <if test="qualifierValue != null">qualifier_value,</if>
             <if test="startBlindLevel != null">start_blind_level,</if>
+            <if test="rebuy != null">rebuy,</if>
+            <if test="delayShow != null">delay_show,</if>
         </trim>
         VALUES
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -106,6 +110,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="qualifierType != null">#{qualifierType},</if>
             <if test="qualifierValue != null">#{qualifierValue},</if>
             <if test="startBlindLevel != null">#{startBlindLevel},</if>
+            <if test="rebuy != null">#{rebuy},</if>
+            <if test="delayShow != null">#{delayShow},</if>
         </trim>
     </insert>