Pārlūkot izejas kodu

fix : 用户授权接口

bilingfeng 1 gadu atpakaļ
vecāks
revīzija
5fa2c67404

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

@@ -21,7 +21,7 @@ public class ManageApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 <dubbo升级3.0, 解决ip封禁未指定游戏得问题> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 <dubbo升级3.0, 用户授权接口> ( ´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

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

@@ -0,0 +1,65 @@
+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.pojo.params.GameAuthAddParam;
+import com.zanxiang.game.module.manage.pojo.params.GameAuthListParam;
+import com.zanxiang.game.module.manage.pojo.params.GameAuthUpdateParam;
+import com.zanxiang.game.module.manage.pojo.vo.GameAuthVO;
+import com.zanxiang.game.module.manage.service.IGameAuthService;
+import com.zanxiang.module.util.pojo.ResultVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-08-17
+ * @description : 游戏授权
+ */
+@Api(tags = {"游戏授权接口"})
+@RestController
+@RequestMapping("/game/auth")
+@Slf4j
+public class GameAuthController {
+
+    @Autowired
+    private IGameAuthService gameAuthService;
+
+    @ApiOperation(value = "新增用户授权")
+    @PostMapping(value = "/add")
+    @PreAuthorize(permissionKey = "manage:gameAuth:add")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
+    public ResultVO<Boolean> gameAuthAdd(@Validated @RequestBody GameAuthAddParam param) {
+        return ResultVO.ok(gameAuthService.gameAuthAdd(param));
+    }
+
+    @ApiOperation(value = "更新用户授权")
+    @PostMapping(value = "/update")
+    @PreAuthorize(permissionKey = "manage:gameAuth:update")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
+    public ResultVO<Boolean> gameAuthAdd(@Validated @RequestBody GameAuthUpdateParam param) {
+        return ResultVO.ok(gameAuthService.gameAuthUpdate(param));
+    }
+
+    @ApiOperation(value = "游戏授权用户列表")
+    @PostMapping(value = "/list")
+    @PreAuthorize(permissionKey = "manage:gameAuth:list")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameAuthVO.class)})
+    public ResultVO<IPage<GameAuthVO>> listOfPage(@Validated @RequestBody GameAuthListParam param) {
+        return ResultVO.ok(gameAuthService.listOfPage(param));
+    }
+
+    @ApiOperation(value = "游戏授权用户删除")
+    @DeleteMapping(value = "/delete")
+    @PreAuthorize(permissionKey = "manage:gameServer:delete")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
+    public ResultVO<Boolean> deleteById(@RequestParam Long id) {
+        return ResultVO.ok(gameAuthService.deleteById(id));
+    }
+}

+ 49 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/params/GameAuthAddParam.java

@@ -0,0 +1,49 @@
+package com.zanxiang.game.module.manage.pojo.params;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-08-16
+ * @description : 游戏授权添加
+ */
+@Data
+public class GameAuthAddParam {
+
+    /**
+     * 游戏id
+     */
+    @NotNull(message = "游戏id不可为空")
+    @ApiModelProperty(notes = "主键id")
+    private Long gameId;
+
+    /**
+     * 用户列表
+     */
+    @NotEmpty(message = "用户列表不可为空")
+    @ApiModelProperty(notes = "用户列表")
+    private List<GameAuthUserBean> userAuthList;
+
+    @Data
+    public static class GameAuthUserBean {
+
+        /**
+         * 用户id
+         */
+        @NotNull(message = "用户id不可为空")
+        @ApiModelProperty(notes = "用户id")
+        private Long userId;
+
+        /**
+         * 权限类型, 1 : 投手, 2 : 运营
+         */
+        @NotNull(message = "权限类型不可为空")
+        @ApiModelProperty(notes = "权限类型, 1 : 投手, 2 : 运营")
+        private Integer type;
+    }
+}

+ 27 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/params/GameAuthListParam.java

@@ -0,0 +1,27 @@
+package com.zanxiang.game.module.manage.pojo.params;
+
+import com.zanxiang.game.module.mybatis.entity.GameAuth;
+import com.zanxiang.module.web.pojo.BaseListDTO;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-08-16
+ * @description : 游戏授权查询
+ */
+@Data
+public class GameAuthListParam extends BaseListDTO<GameAuth> {
+
+    /**
+     * 游戏id
+     */
+    @ApiModelProperty(notes = "游戏id")
+    private Long gameId;
+
+    /**
+     * 用户id
+     */
+    @ApiModelProperty(notes = "用户id")
+    private Long userId;
+}

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

@@ -0,0 +1,43 @@
+package com.zanxiang.game.module.manage.pojo.params;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-08-16
+ * @description : 游戏授权更新
+ */
+@Data
+public class GameAuthUpdateParam {
+
+    /**
+     * 主键id
+     */
+    @NotNull(message = "主键id不可为空")
+    @ApiModelProperty(notes = "主键id")
+    private Long id;
+
+    /**
+     * 游戏id
+     */
+    @NotNull(message = "游戏id不可为空")
+    @ApiModelProperty(notes = "用户id")
+    private Long gameId;
+
+    /**
+     * 用户id
+     */
+    @NotNull(message = "用户id不可为空")
+    @ApiModelProperty(notes = "用户id")
+    private Long userId;
+
+    /**
+     * 类型
+     */
+    @NotNull(message = "类型不可为空")
+    @ApiModelProperty(notes = "类型")
+    private Integer type;
+}

+ 63 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/vo/GameAuthVO.java

@@ -0,0 +1,63 @@
+package com.zanxiang.game.module.manage.pojo.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-08-16
+ * @description : 游戏授权
+ */
+@Data
+public class GameAuthVO {
+
+    /**
+     * 主键id
+     */
+    @ApiModelProperty(notes = "主键id")
+    private Long id;
+
+    /**
+     * 游戏id
+     */
+    @ApiModelProperty(notes = "游戏id")
+    private Long gameId;
+
+    /**
+     * 游戏名称
+     */
+    @ApiModelProperty(notes = "游戏名称")
+    private String gameName;
+
+    /**
+     * 用户id
+     */
+    @ApiModelProperty(notes = "用户id")
+    private Long userId;
+
+    /**
+     * 用户名称
+     */
+    @ApiModelProperty(notes = "用户名称")
+    private String userName;
+
+    /**
+     * 类型
+     */
+    @ApiModelProperty(notes = "类型")
+    private Integer type;
+
+    /**
+     * 创建时间
+     */
+    @ApiModelProperty(notes = "创建时间")
+    private LocalDateTime createTime;
+
+    /**
+     * 更新时间
+     */
+    @ApiModelProperty(notes = "更新时间")
+    private LocalDateTime updateTime;
+}

+ 49 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IGameAuthService.java

@@ -0,0 +1,49 @@
+package com.zanxiang.game.module.manage.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zanxiang.game.module.manage.pojo.params.GameAuthAddParam;
+import com.zanxiang.game.module.manage.pojo.params.GameAuthListParam;
+import com.zanxiang.game.module.manage.pojo.params.GameAuthUpdateParam;
+import com.zanxiang.game.module.manage.pojo.vo.GameAuthVO;
+import com.zanxiang.game.module.mybatis.entity.GameAuth;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-08-16
+ * @description : 游戏授权
+ */
+public interface IGameAuthService extends IService<GameAuth> {
+
+    /**
+     * 游戏身份验证添加
+     *
+     * @param param 参数
+     * @return boolean
+     */
+    boolean gameAuthAdd(GameAuthAddParam param);
+
+    /**
+     * 游戏身份验证更新
+     *
+     * @param param 参数
+     * @return boolean
+     */
+    boolean gameAuthUpdate(GameAuthUpdateParam param);
+
+    /**
+     * 列表页面
+     *
+     * @param param 参数
+     * @return {@link IPage}<{@link GameAuthVO}>
+     */
+    IPage<GameAuthVO> listOfPage(GameAuthListParam param);
+
+    /**
+     * 删除通过id
+     *
+     * @param id id
+     * @return boolean
+     */
+    boolean deleteById(Long id);
+}

+ 131 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameAuthServiceImpl.java

@@ -0,0 +1,131 @@
+package com.zanxiang.game.module.manage.service.impl;
+
+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.extension.service.impl.ServiceImpl;
+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.pojo.dto.GameDTO;
+import com.zanxiang.game.module.manage.pojo.params.GameAuthAddParam;
+import com.zanxiang.game.module.manage.pojo.params.GameAuthListParam;
+import com.zanxiang.game.module.manage.pojo.params.GameAuthUpdateParam;
+import com.zanxiang.game.module.manage.pojo.vo.GameAuthVO;
+import com.zanxiang.game.module.manage.service.IGameAuthService;
+import com.zanxiang.game.module.manage.service.IGameService;
+import com.zanxiang.game.module.mybatis.entity.GameAuth;
+import com.zanxiang.game.module.mybatis.mapper.GameAuthMapper;
+import com.zanxiang.module.util.bean.BeanUtil;
+import com.zanxiang.module.util.exception.BaseException;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDateTime;
+import java.util.*;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-08-16
+ * @description : 游戏授权
+ */
+@Slf4j
+@Service
+public class GameAuthServiceImpl extends ServiceImpl<GameAuthMapper, GameAuth> implements IGameAuthService {
+
+    @Autowired
+    private IGameService gameService;
+
+    @DubboReference(providedBy = ErpServer.SERVER_DUBBO_NAME)
+    private ISysUserRpc sysUserRpc;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean gameAuthAdd(GameAuthAddParam param) {
+        //游戏id
+        Long gameId = param.getGameId();
+        List<GameAuthAddParam.GameAuthUserBean> userAuthList = param.getUserAuthList();
+        List<GameAuth> addList = new ArrayList<>();
+        userAuthList.forEach(userAuth -> {
+            //判断提交的参数数据是否已经存在
+            if (super.count(new LambdaQueryWrapper<GameAuth>()
+                    .eq(GameAuth::getGameId, gameId)
+                    .eq(GameAuth::getUserId, userAuth.getUserId())
+                    .eq(GameAuth::getType, userAuth.getType())
+            ) > 0) {
+                return;
+            }
+            addList.add(this.transform(gameId, userAuth));
+        });
+        if (addList.isEmpty()) {
+            return Boolean.FALSE;
+        }
+        return super.saveBatch(addList);
+    }
+
+    private GameAuth transform(Long gameId, GameAuthAddParam.GameAuthUserBean gameAuthUserBean) {
+        return GameAuth.builder()
+                .gameId(gameId)
+                .userId(gameAuthUserBean.getUserId())
+                .type(gameAuthUserBean.getType())
+                .isDelete(DeleteEnum.NO.getCode())
+                .createBy(SecurityUtil.getUserId())
+                .createTime(LocalDateTime.now())
+                .updateBy(SecurityUtil.getUserId())
+                .updateTime(LocalDateTime.now())
+                .build();
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean gameAuthUpdate(GameAuthUpdateParam param) {
+        //判断提交的参数数据是否已经存在
+        if (super.count(new LambdaQueryWrapper<GameAuth>()
+                .eq(GameAuth::getGameId, param.getGameId())
+                .eq(GameAuth::getUserId, param.getUserId())
+                .eq(GameAuth::getType, param.getType())
+        ) > 0) {
+            throw new BaseException("参数错误, 要修改的数据已经存在相同数据");
+        }
+        //修改
+        return super.update(new LambdaUpdateWrapper<GameAuth>()
+                .set(GameAuth::getGameId, param.getGameId())
+                .set(GameAuth::getUserId, param.getUserId())
+                .set(GameAuth::getType, param.getType())
+                .set(GameAuth::getUpdateBy, SecurityUtil.getUserId())
+                .set(GameAuth::getUpdateTime, LocalDateTime.now())
+                .eq(GameAuth::getId, param.getId()));
+    }
+
+    @Override
+    public IPage<GameAuthVO> listOfPage(GameAuthListParam param) {
+        return page(param.toPage(), new QueryWrapper<GameAuth>().lambda()
+                .eq(param.getGameId() != null, GameAuth::getGameId, param.getGameId())
+                .eq(param.getUserId() != null, GameAuth::getUserId, param.getUserId())
+                .orderByDesc(GameAuth::getUpdateTime)
+        ).convert(this::toVo);
+    }
+
+    private GameAuthVO toVo(GameAuth gameAuth) {
+        if (Objects.isNull(gameAuth)) {
+            return null;
+        }
+        GameAuthVO gameAuthVO = BeanUtil.copy(gameAuth, GameAuthVO.class);
+        GameDTO gameDTO = gameService.getById(gameAuthVO.getGameId());
+        gameAuthVO.setGameName(gameDTO == null ? null : gameDTO.getName());
+        Map<Long, String> userMap = sysUserRpc.getUserNameByIds(Collections.singletonList(gameAuthVO.getUserId())).getData();
+        gameAuthVO.setUserName(userMap.get(gameAuthVO.getUserId()));
+        return gameAuthVO;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean deleteById(Long id) {
+        return super.removeById(id);
+    }
+}

+ 76 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/GameAuth.java

@@ -0,0 +1,76 @@
+package com.zanxiang.game.module.mybatis.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.*;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-08-16
+ * @description : 游戏授权
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@ToString
+@Builder
+@TableName("t_game_auth")
+public class GameAuth implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    public static final int TYPE_PITCHER = 1;
+    public static final int TYPE_OPERATE = 2;
+
+    /**
+     * 主键id
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 用户id
+     */
+    private Long gameId;
+
+    /**
+     * 用户id
+     */
+    private Long userId;
+
+    /**
+     * 类型
+     */
+    private Integer type;
+
+    /**
+     * 1 删除  0 正常
+     */
+    @TableLogic
+    private Integer isDelete;
+
+    /**
+     * 创建者
+     */
+    private Long createBy;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新者
+     */
+    private Long updateBy;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+}

+ 12 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/mapper/GameAuthMapper.java

@@ -0,0 +1,12 @@
+package com.zanxiang.game.module.mybatis.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zanxiang.game.module.mybatis.entity.GameAuth;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-08-16
+ * @description : 游戏授权
+ */
+public interface GameAuthMapper extends BaseMapper<GameAuth> {
+}