浏览代码

优化用户界面体验-首页重构(增加统计方法)

wenkai 2 周之前
父节点
当前提交
38417a6037

+ 5 - 3
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/controller/GameEventController.java

@@ -114,10 +114,12 @@ public class GameEventController extends BaseController {
 
     /**
      * 查询赛事数量
+     *
+     * @param type 0:所有 1:未开始 2:进行中 3:已结束
      * @return
      */
-    @GetMapping("/count")
-    public R<Long> count() {
-        return R.ok(gameEventService.countGameEvent());
+    @GetMapping("/count/{type}")
+    public R<Long> count(@PathVariable Long type) {
+        return R.ok(gameEventService.countGameEvent(type));
     }
 }

+ 1 - 1
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/service/IGameEventService.java

@@ -79,5 +79,5 @@ public interface IGameEventService {
      * 统计赛事个数
      * @return
      */
-    Long countGameEvent();
+    Long countGameEvent(Long type);
 }

+ 6 - 1
ruoyi-modules/ruoyi-game-event/src/main/java/org/dromara/system/service/impl/GameEventServiceImpl.java

@@ -156,13 +156,18 @@ public class GameEventServiceImpl implements IGameEventService {
 
     /**
      * 统计赛事个数
+     * 0:所有 1:未开始 2:进行中 3:已结束
      *
      * @return
      */
     @Override
-    public Long countGameEvent() {
+    public Long countGameEvent(Long type) {
         return this.baseMapper.selectCount(
             Wrappers.lambdaQuery(GameEvent.class)
+                .apply(type == 0, "1=1")
+                .apply(type == 1, "start_time > now()")
+                .apply(type == 2, "start_time <= now() and end_time >= now()")
+                .apply(type == 3, "end_time < now()")
         );
     }
 }