Ver código fonte

feat(game-event): 添加项目列表实时统计功能

- 新增 listWithStats 接口支持实时人数、队数、组数统计
- 在 GameEventProjectVo 中增加 athleteCount、teamCount、groupCount 字段
- 实现 selectPageWithStats 方法通过 SQL 查询实时统计数据
- 添加完整的数据映射和权限控制配置
- 集成 Redis 缓存处理默认赛事 ID 逻辑
- 补充赛事名称和裁判组列表展示数据
zhou 1 semana atrás
pai
commit
c02757ecb7

+ 9 - 0
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/controller/GameEventProjectController.java

@@ -47,6 +47,15 @@ public class GameEventProjectController extends BaseController {
         return gameEventProjectService.queryPageList(bo, pageQuery);
     }
 
+    /**
+     * 查询项目列表(带实时人数、队数、组数统计)
+     */
+    @SaCheckPermission("system:gameEventProject:list")
+    @GetMapping("/listWithStats")
+    public TableDataInfo<GameEventProjectVo> listWithStats(GameEventProjectBo bo, PageQuery pageQuery) {
+        return gameEventProjectService.queryPageListWithStats(bo, pageQuery);
+    }
+
     /**
      * 查询所有赛事项目列表
      */

+ 15 - 0
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/domain/vo/GameEventProjectVo.java

@@ -200,4 +200,19 @@ public class GameEventProjectVo implements Serializable {
      */
     private Integer incompleteParticipants;
 
+    /**
+     * 实时统计:参赛人数
+     */
+    private Long athleteCount;
+
+    /**
+     * 实时统计:代表队数
+     */
+    private Long teamCount;
+
+    /**
+     * 实时统计:分组数
+     */
+    private Long groupCount;
+
 }

+ 11 - 0
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/mapper/GameEventProjectMapper.java

@@ -3,9 +3,11 @@ package org.dromara.system.mapper;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 import org.dromara.common.mybatis.annotation.DataColumn;
 import org.dromara.common.mybatis.annotation.DataPermission;
 import org.dromara.system.domain.GameEventProject;
+import org.dromara.system.domain.bo.GameEventProjectBo;
 import org.dromara.system.domain.vo.GameEventProjectVo;
 import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
 
@@ -47,4 +49,13 @@ public interface GameEventProjectMapper extends BaseMapperPlus<GameEventProject,
     default List<GameEventProjectVo> selectEventProjectList(Wrapper<GameEventProject> queryWrapper) {
         return this.selectVoList(queryWrapper);
     }
+
+    /**
+     * 分页查询项目列表并包含实时统计(XML 实现)
+     */
+    @DataPermission({
+        @DataColumn(key = "deptName", value = "create_dept"),
+        @DataColumn(key = "userName", value = "create_by")
+    })
+    Page<GameEventProjectVo> selectPageWithStats(@Param("page") Page<GameEventProjectVo> page, @Param("query") GameEventProjectBo bo);
 }

+ 5 - 0
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/service/IGameEventProjectService.java

@@ -45,6 +45,11 @@ public interface IGameEventProjectService {
      * @return 赛事项目分页列表
      */
     TableDataInfo<GameEventProjectVo> queryAllProjectList(GameEventProjectBo bo, PageQuery pageQuery);
+    
+    /**
+     * 分页查询项目列表并包含实时人数、队数、组数统计
+     */
+    TableDataInfo<GameEventProjectVo> queryPageListWithStats(GameEventProjectBo bo, PageQuery pageQuery);
 
     /**
      * 查询符合条件的赛事项目列表

+ 29 - 0
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/service/impl/GameEventProjectServiceImpl.java

@@ -9,6 +9,7 @@ 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.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.extern.slf4j.Slf4j;
 import org.dromara.common.redis.utils.RedisUtils;
@@ -707,4 +708,32 @@ public class GameEventProjectServiceImpl implements IGameEventProjectService {
                             Collectors.toMap(GameEventProject::getProjectId, GameEventProject::getProjectName));
         }
     }
+
+    @Override
+    public TableDataInfo<GameEventProjectVo> queryPageListWithStats(GameEventProjectBo bo, PageQuery pageQuery) {
+        // 处理默认赛事 ID
+        if (bo.getEventId() == null) {
+            Object cacheObject = RedisUtils.getCacheObject(GameEventConstant.DEFAULT_EVENT_ID);
+            if (cacheObject instanceof Integer) {
+                bo.setEventId(((Integer) cacheObject).longValue());
+            } else if (cacheObject instanceof Long) {
+                bo.setEventId((Long) cacheObject);
+            }
+        }
+
+        Page<GameEventProjectVo> result = baseMapper.selectPageWithStats(pageQuery.build(), bo);
+        List<GameEventProjectVo> rows = result.getRecords();
+        // 补充展示数据(赛事名称、裁判组列表)
+        GameEvent gameEvent = gameEventMapper.selectById(bo.getEventId());
+        rows.forEach(vo -> {
+            if (gameEvent != null) {
+                vo.setEventName(gameEvent.getEventName());
+            }
+            if (StringUtils.isNotEmpty(vo.getRefereeGroup())) {
+                vo.setRefereeGroups(JSONUtil.toList(vo.getRefereeGroup(), Long.class));
+            }
+        });
+
+        return TableDataInfo.build(result);
+    }
 }

+ 33 - 0
ruoyi-modules/ruoyi-game-event/src/main/resources/mapper/system/GameEventProjectMapper.xml

@@ -4,4 +4,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.dromara.system.mapper.GameEventProjectMapper">
 
+    <resultMap type="org.dromara.system.domain.vo.GameEventProjectVo" id="GameEventProjectVoWithStatsResult">
+        <result property="athleteCount" column="athlete_count"/>
+        <result property="teamCount" column="team_count"/>
+        <result property="groupCount" column="group_count"/>
+    </resultMap>
+
+    <select id="selectPageWithStats" resultMap="GameEventProjectVoWithStatsResult">
+        SELECT p.*,
+            IFNULL((SELECT COUNT(*) FROM game_athlete a WHERE a.event_id = p.event_id AND a.del_flag = '0' 
+            AND (JSON_CONTAINS(a.project_value, JSON_ARRAY(p.project_id)) 
+            OR JSON_CONTAINS(a.project_value, JSON_ARRAY(CAST(p.project_id AS CHAR))))), 0) as athlete_count,
+            IFNULL((SELECT COUNT(DISTINCT team_id) FROM game_athlete a WHERE a.event_id = p.event_id AND a.del_flag = '0' 
+            AND (JSON_CONTAINS(a.project_value, JSON_ARRAY(p.project_id)) 
+            OR JSON_CONTAINS(a.project_value, JSON_ARRAY(CAST(p.project_id AS CHAR))))), 0) as team_count,
+            IFNULL((SELECT COUNT(*) FROM game_event_group g WHERE g.project_id = p.project_id AND g.del_flag = '0'), 0) as group_count
+        FROM game_event_project p
+        <where>
+            p.del_flag = '0'
+            <if test="query.eventId != null">
+                AND p.event_id = #{query.eventId}
+            </if>
+            <if test="query.classification != null and query.classification != ''">
+                AND p.classification = #{query.classification}
+            </if>
+            <if test="query.projectName != null and query.projectName != ''">
+                AND p.project_name LIKE CONCAT('%', #{query.projectName}, '%')
+            </if>
+            <!-- 数据权限 -->
+            ${query.params.dataScope}
+        </where>
+        ORDER BY p.create_time DESC
+    </select>
+
 </mapper>