Prechádzať zdrojové kódy

feat : 新增游戏和区服rpc接口

bilingfeng 11 mesiacov pred
rodič
commit
7cfbac57d8

+ 41 - 0
game-module/game-module-base/src/main/java/com/zanxiang/game/module/base/pojo/dto/GameDTO.java

@@ -0,0 +1,41 @@
+package com.zanxiang.game.module.base.pojo.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-05-23
+ * @description : 游戏信息
+ */
+@Data
+public class GameDTO implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 游戏ID
+     */
+    private Long id;
+
+    /**
+     * 游戏名称
+     */
+    private String name;
+
+    /**
+     * 游戏类型
+     */
+    private Long category;
+
+    /**
+     * 父游戏id
+     */
+    private Long parentId;
+
+    /**
+     * 超父游戏id
+     */
+    private Long superGameId;
+}

+ 138 - 0
game-module/game-module-base/src/main/java/com/zanxiang/game/module/base/pojo/dto/GameServerDTO.java

@@ -0,0 +1,138 @@
+package com.zanxiang.game.module.base.pojo.dto;
+
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-05-23
+ * @description : 游戏区服
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class GameServerDTO implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 超父游戏区服列表
+     */
+    public List<SuperGameServerBean> superGameServerList;
+
+    /**
+     * 通过游戏id,区服id获取区服
+     *
+     * @param gameId   : 游戏id
+     * @param serverId : 区服id
+     * @return : 返回区服信息
+     */
+    public GameServerBean getGameServerByGameId(Long gameId, String serverId) {
+        if (CollectionUtils.isEmpty(this.superGameServerList)) {
+            return null;
+        }
+        SuperGameServerBean superGameServer = this.superGameServerList.stream()
+                .filter(superGameServerBean -> superGameServerBean.getGameIdList().contains(gameId))
+                .findFirst().orElse(null);
+        if (superGameServer == null) {
+            return null;
+        }
+        return superGameServer.getSourceGameServerList().stream()
+                .filter(gameServerBean -> Objects.equals(gameServerBean.getServerId(), serverId))
+                .findFirst().orElse(null);
+    }
+
+    /**
+     * 通过游戏id,区服id获取区服
+     *
+     * @param superGameId : 超父游戏id
+     * @param serverId    : 区服id
+     * @return : 返回区服信息
+     */
+    public GameServerBean getGameServerBySupperGameId(Long superGameId, String serverId) {
+        if (CollectionUtils.isEmpty(this.superGameServerList)) {
+            return null;
+        }
+        SuperGameServerBean superGameServer = this.superGameServerList.stream()
+                .filter(superGameServerBean -> Objects.equals(superGameId, superGameServerBean.getSuperGameId()))
+                .findFirst().orElse(null);
+        if (superGameServer == null) {
+            return null;
+        }
+        return superGameServer.getSourceGameServerList().stream()
+                .filter(gameServerBean -> Objects.equals(gameServerBean.getServerId(), serverId))
+                .findFirst().orElse(null);
+    }
+
+    @Data
+    @Builder
+    @NoArgsConstructor
+    @AllArgsConstructor
+    public static class SuperGameServerBean implements Serializable {
+
+        private static final long serialVersionUID = 1L;
+
+        /**
+         * 超父游戏id
+         */
+        private Long superGameId;
+
+        /**
+         * 游戏id列表
+         */
+        private List<Long> gameIdList;
+
+        /**
+         * 原始区服列表
+         */
+        private List<GameServerBean> sourceGameServerList;
+    }
+
+    @Data
+    @Builder
+    @NoArgsConstructor
+    @AllArgsConstructor
+    public static class GameServerBean implements Serializable {
+
+        private static final long serialVersionUID = 1L;
+
+        /**
+         * 主键id
+         */
+        private Long id;
+
+        /**
+         * 游戏id
+         */
+        private Long gameId;
+
+        /**
+         * 区服id
+         */
+        private String serverId;
+
+        /**
+         * 区服名称
+         */
+        private String serverName;
+
+        /**
+         * 区服冠名
+         */
+        private String nickName;
+
+        /**
+         * 开服时间
+         */
+        private LocalDateTime startTime;
+    }
+}

+ 21 - 0
game-module/game-module-base/src/main/java/com/zanxiang/game/module/base/rpc/IGameRpc.java

@@ -0,0 +1,21 @@
+package com.zanxiang.game.module.base.rpc;
+
+import com.zanxiang.game.module.base.pojo.dto.GameDTO;
+import com.zanxiang.module.util.pojo.ResultVO;
+
+import java.util.List;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-05-23
+ * @description : 游戏相关接口
+ */
+public interface IGameRpc {
+
+    /**
+     * 获取所有游戏
+     *
+     * @return : 返回游戏列表
+     */
+    ResultVO<List<GameDTO>> getAllGameList();
+}

+ 19 - 0
game-module/game-module-base/src/main/java/com/zanxiang/game/module/base/rpc/IGameServerRpc.java

@@ -0,0 +1,19 @@
+package com.zanxiang.game.module.base.rpc;
+
+import com.zanxiang.game.module.base.pojo.dto.GameServerDTO;
+import com.zanxiang.module.util.pojo.ResultVO;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-05-23
+ * @description : 游戏区服
+ */
+public interface IGameServerRpc {
+
+    /**
+     * 获取游戏所有区服
+     *
+     * @return : 返回游戏区服对象
+     */
+    ResultVO<GameServerDTO> getAllServerList();
+}

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java

@@ -23,7 +23,7 @@ public class ManageApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 < (角色操作表新增字段´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 < (新增游戏和区服rpc接口´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 36 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/rpc/impl/GameRpcImpl.java

@@ -0,0 +1,36 @@
+package com.zanxiang.game.module.manage.rpc.impl;
+
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.zanxiang.game.module.base.pojo.dto.GameDTO;
+import com.zanxiang.game.module.base.rpc.IGameRpc;
+import com.zanxiang.game.module.manage.service.IGameService;
+import com.zanxiang.game.module.mybatis.entity.Game;
+import com.zanxiang.module.util.bean.BeanUtil;
+import com.zanxiang.module.util.pojo.ResultVO;
+import org.apache.dubbo.config.annotation.DubboService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-05-23
+ * @description : 游戏相关接口
+ */
+@DubboService
+public class GameRpcImpl implements IGameRpc {
+
+    @Autowired
+    private IGameService gameService;
+
+    @Override
+    public ResultVO<List<GameDTO>> getAllGameList() {
+        List<Game> gameList = gameService.list();
+        if (CollectionUtils.isEmpty(gameList)) {
+            return ResultVO.ok(Collections.emptyList());
+        }
+        return ResultVO.ok(gameList.stream().map(game -> BeanUtil.copy(game, GameDTO.class)).collect(Collectors.toList()));
+    }
+}

+ 67 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/rpc/impl/GameServerRpcImpl.java

@@ -0,0 +1,67 @@
+package com.zanxiang.game.module.manage.rpc.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.zanxiang.game.module.base.pojo.dto.GameServerDTO;
+import com.zanxiang.game.module.base.rpc.IGameServerRpc;
+import com.zanxiang.game.module.manage.service.IGameServerService;
+import com.zanxiang.game.module.manage.service.IGameService;
+import com.zanxiang.game.module.manage.service.IGameSupperService;
+import com.zanxiang.game.module.mybatis.entity.Game;
+import com.zanxiang.game.module.mybatis.entity.GameServer;
+import com.zanxiang.game.module.mybatis.entity.GameSupper;
+import com.zanxiang.module.util.bean.BeanUtil;
+import com.zanxiang.module.util.pojo.ResultVO;
+import org.apache.dubbo.config.annotation.DubboService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author : lingfeng
+ * @time : 2024-05-23
+ * @description : 游戏区服接口
+ */
+@DubboService
+public class GameServerRpcImpl implements IGameServerRpc {
+
+    @Autowired
+    private IGameSupperService gameSupperService;
+
+    @Autowired
+    private IGameService gameService;
+
+    @Autowired
+    private IGameServerService gameServerService;
+
+    @Override
+    public ResultVO<GameServerDTO> getAllServerList() {
+        //超父游戏列表
+        List<Long> supperGameIdList = gameSupperService.list(new LambdaQueryWrapper<GameSupper>()
+                .select(GameSupper::getId)
+        ).stream().map(GameSupper::getId).collect(Collectors.toList());
+        //区服列表
+        List<GameServerDTO.SuperGameServerBean> superGameServerList = new ArrayList<>();
+        supperGameIdList.forEach(supperGameId -> {
+            //查询超父对应的子游戏
+            List<Long> gameIdList = gameService.list(new LambdaQueryWrapper<Game>()
+                    .select(Game::getId)
+                    .eq(Game::getSuperGameId, supperGameId)
+            ).stream().map(Game::getId).collect(Collectors.toList());
+            //超父对应的区服
+            List<GameServerDTO.GameServerBean> gameServerBeanList = gameServerService.list(new LambdaQueryWrapper<GameServer>()
+                    .eq(GameServer::getGameId, supperGameId)
+                    .eq(GameServer::getIsSourceServer, Boolean.TRUE)
+            ).stream().map(gameServer -> BeanUtil.copy(gameServer, GameServerDTO.GameServerBean.class)).collect(Collectors.toList());
+            //添加到集合
+            superGameServerList.add(GameServerDTO.SuperGameServerBean.builder()
+                    .superGameId(supperGameId)
+                    .gameIdList(gameIdList)
+                    .sourceGameServerList(gameServerBeanList)
+                    .build());
+        });
+        //返回
+        return ResultVO.ok(GameServerDTO.builder().superGameServerList(superGameServerList).build());
+    }
+}