Browse Source

fix : 角色权限修改

bilingfeng 1 year ago
parent
commit
7cad0b0bc7

+ 19 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/controller/GameAuthController.java

@@ -2,6 +2,7 @@ package com.zanxiang.game.module.manage.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.zanxiang.erp.security.annotation.PreAuthorize;
+import com.zanxiang.game.module.manage.enums.GameAuthEnum;
 import com.zanxiang.game.module.manage.pojo.params.*;
 import com.zanxiang.game.module.manage.pojo.vo.GameAuthRoleVO;
 import com.zanxiang.game.module.manage.pojo.vo.GameAuthVO;
@@ -17,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Map;
+
 /**
  * @author : lingfeng
  * @time : 2023-08-17
@@ -97,4 +100,20 @@ public class GameAuthController {
     public ResultVO<IPage<GameAuthRoleVO>> roleListOfPage(@Validated @RequestBody GameAuthRoleListParam param) {
         return ResultVO.ok(gameAuthRoleService.listOfPage(param));
     }
+
+    @ApiOperation(value = "获取权限类型枚举")
+    @GetMapping(value = "/role/auth/type")
+    @PreAuthorize(permissionKey = "manage:gameServer:roleAuthType")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
+    public ResultVO<Map<String, String>> getGameAuthMap() {
+        return ResultVO.ok(GameAuthEnum.getGameAuthMap());
+    }
+
+    @ApiOperation(value = "获取权限类型枚举")
+    @GetMapping(value = "/role/auth/user")
+    @PreAuthorize(permissionKey = "manage:gameServer:roleAuthUser")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
+    public ResultVO<Map<Long, String>> getUserByAuthType(@RequestParam String authType) {
+        return ResultVO.ok(gameAuthRoleService.getUserByAuthType(authType));
+    }
 }

+ 32 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/enums/GameAuthEnum.java

@@ -3,6 +3,10 @@ package com.zanxiang.game.module.manage.enums;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
 /**
  * @author : lingfeng
  * @time : 2023-08-17
@@ -31,4 +35,32 @@ public enum GameAuthEnum {
      * 名称
      */
     private String name;
+
+    /**
+     * 根据值获取枚举对象
+     *
+     * @param value 价值
+     * @return {@link GameAuthEnum}
+     */
+    public static GameAuthEnum getByValue(String value) {
+        for (GameAuthEnum gameAuthEnum : GameAuthEnum.values()) {
+            if (Objects.equals(value, gameAuthEnum.getValue())) {
+                return gameAuthEnum;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 获取枚举映射
+     *
+     * @return {@link Map}<{@link String}, {@link String}>
+     */
+    public static Map<String, String> getGameAuthMap() {
+        Map<String, String> gameAuthMap = new HashMap<>(GameAuthEnum.values().length);
+        for (GameAuthEnum gameAuthEnum : GameAuthEnum.values()) {
+            gameAuthMap.put(gameAuthEnum.getValue(), gameAuthEnum.getName());
+        }
+        return gameAuthMap;
+    }
 }

+ 0 - 7
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/params/GameAuthUpdateParam.java

@@ -33,11 +33,4 @@ public class GameAuthUpdateParam {
     @NotNull(message = "用户id不可为空")
     @ApiModelProperty(notes = "用户id")
     private Long userId;
-
-    /**
-     * 类型
-     */
-    @NotNull(message = "类型不可为空")
-    @ApiModelProperty(notes = "类型")
-    private Integer type;
 }

+ 4 - 3
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/vo/GameAuthVO.java

@@ -1,5 +1,6 @@
 package com.zanxiang.game.module.manage.pojo.vo;
 
+import com.zanxiang.game.module.manage.enums.GameAuthEnum;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
@@ -44,10 +45,10 @@ public class GameAuthVO {
     private String userName;
 
     /**
-     * 类型
+     * 权限类型
      */
-    @ApiModelProperty(notes = "类型")
-    private Integer type;
+    @ApiModelProperty(notes = "权限类型")
+    private GameAuthEnum authType;
 
     /**
      * 创建时间

+ 10 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IGameAuthRoleService.java

@@ -8,6 +8,8 @@ import com.zanxiang.game.module.manage.pojo.params.GameAuthRoleUpdateParam;
 import com.zanxiang.game.module.manage.pojo.vo.GameAuthRoleVO;
 import com.zanxiang.game.module.mybatis.entity.GameAuthRole;
 
+import java.util.Map;
+
 /**
  * @author : lingfeng
  * @time : 2023-08-17
@@ -15,6 +17,14 @@ import com.zanxiang.game.module.mybatis.entity.GameAuthRole;
  */
 public interface IGameAuthRoleService extends IService<GameAuthRole> {
 
+    /**
+     * 获取用户身份验证类型
+     *
+     * @param authType 身份验证类型
+     * @return {@link Map}<{@link Long}, {@link String}>
+     */
+    Map<Long, String> getUserByAuthType(String authType);
+
     /**
      * 游戏身份验证角色添加
      *

+ 14 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameAuthRoleServiceImpl.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zanxiang.erp.base.ErpServer;
 import com.zanxiang.erp.base.rpc.ISysUserRpc;
@@ -24,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.time.LocalDateTime;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author : lingfeng
@@ -37,6 +39,18 @@ public class GameAuthRoleServiceImpl extends ServiceImpl<GameAuthRoleMapper, Gam
     @DubboReference(providedBy = ErpServer.SERVER_DUBBO_NAME)
     private ISysUserRpc sysUserRpc;
 
+    @Override
+    public Map<Long, String> getUserByAuthType(String authType) {
+        List<GameAuthRole> authRoleList = super.list(new LambdaQueryWrapper<GameAuthRole>()
+                .eq(GameAuthRole::getAuthType, authType));
+        if (CollectionUtils.isEmpty(authRoleList)) {
+            return Collections.emptyMap();
+        }
+        //查询相关人得名字
+        return sysUserRpc.getUserNameByIds(authRoleList.stream()
+                .map(GameAuthRole::getUserId).collect(Collectors.toList())).getData();
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean gameAuthRoleAdd(GameAuthRoleAddParam param) {

+ 4 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameAuthServiceImpl.java

@@ -9,6 +9,7 @@ import com.zanxiang.erp.base.ErpServer;
 import com.zanxiang.erp.base.rpc.ISysUserRpc;
 import com.zanxiang.erp.security.util.SecurityUtil;
 import com.zanxiang.game.module.base.pojo.enums.DeleteEnum;
+import com.zanxiang.game.module.manage.enums.GameAuthEnum;
 import com.zanxiang.game.module.manage.pojo.dto.GameDTO;
 import com.zanxiang.game.module.manage.pojo.params.GameAuthAddParam;
 import com.zanxiang.game.module.manage.pojo.params.GameAuthListParam;
@@ -106,7 +107,6 @@ public class GameAuthServiceImpl extends ServiceImpl<GameAuthMapper, GameAuth> i
         //修改
         return super.update(new LambdaUpdateWrapper<GameAuth>()
                 .set(GameAuth::getGameId, param.getGameId())
-                .set(GameAuth::getUserId, param.getUserId())
                 .set(GameAuth::getUpdateBy, SecurityUtil.getUserId())
                 .set(GameAuth::getUpdateTime, LocalDateTime.now())
                 .eq(GameAuth::getId, param.getId()));
@@ -130,6 +130,9 @@ public class GameAuthServiceImpl extends ServiceImpl<GameAuthMapper, GameAuth> i
         gameAuthVO.setGameName(gameDTO == null ? null : gameDTO.getName());
         Map<Long, String> userMap = sysUserRpc.getUserNameByIds(Collections.singletonList(gameAuthVO.getUserId())).getData();
         gameAuthVO.setUserName(userMap.get(gameAuthVO.getUserId()));
+        GameAuthRole gameAuthRole = gameAuthRoleService.getOne(new LambdaQueryWrapper<GameAuthRole>()
+                .eq(GameAuthRole::getUserId, gameAuthVO.getUserId()));
+        gameAuthVO.setAuthType(GameAuthEnum.getByValue(gameAuthRole.getAuthType()));
         return gameAuthVO;
     }