|
@@ -0,0 +1,112 @@
|
|
|
+package com.zanxiang.game.module.sdk.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.zanxiang.game.module.base.pojo.enums.ShellControlEnum;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.GameAppletShell;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.GameExt;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.GameUserRole;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.User;
|
|
|
+import com.zanxiang.game.module.mybatis.mapper.GameAppletShellMapper;
|
|
|
+import com.zanxiang.game.module.sdk.enums.ShellSwitchEnum;
|
|
|
+import com.zanxiang.game.module.sdk.service.IGameAppletShellService;
|
|
|
+import com.zanxiang.game.module.sdk.service.IGameExtService;
|
|
|
+import com.zanxiang.game.module.sdk.service.IGameUserRoleService;
|
|
|
+import com.zanxiang.module.util.JsonUtil;
|
|
|
+import com.zanxiang.module.util.exception.BaseException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+
|
|
|
+ * @author : lingfeng
|
|
|
+ * @time : 2023-07-06
|
|
|
+ * @description : 壳包控制
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class GameAppletShellServiceImpl extends ServiceImpl<GameAppletShellMapper, GameAppletShell> implements IGameAppletShellService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGameExtService gameExtService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGameUserRoleService gameUserRoleService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer getShellSwitch(String appId, String version) {
|
|
|
+ GameExt gameExt = gameExtService.getByGameAppId(appId);
|
|
|
+ if (gameExt == null) {
|
|
|
+ throw new BaseException("参数错误, 游戏信息不存在");
|
|
|
+ }
|
|
|
+ GameAppletShell gameAppletShell = super.getOne(new LambdaQueryWrapper<GameAppletShell>()
|
|
|
+ .eq(GameAppletShell::getGameId, gameExt.getGameId()));
|
|
|
+ if (gameAppletShell == null) {
|
|
|
+ throw new BaseException("参数错误, 游戏设置信息不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.equals(gameAppletShell.getArraignVersion(), version)) {
|
|
|
+ return ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.equals(gameAppletShell.getProVersion(), version)) {
|
|
|
+
|
|
|
+ if (Objects.equals(gameAppletShell.getIsAppeal(), Boolean.TRUE)) {
|
|
|
+ return ShellSwitchEnum.SHELL_SWITCH_APPEAL.getShellSwitch();
|
|
|
+ }
|
|
|
+
|
|
|
+ return ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
|
|
|
+ }
|
|
|
+ log.error("版本信息不存在, appId : {}, version : {}", appId, version);
|
|
|
+ throw new BaseException("参数错误, 版本信息不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer getUserShellSwitch(User user, boolean register) {
|
|
|
+ GameAppletShell gameAppletShell = super.getOne(new LambdaQueryWrapper<GameAppletShell>()
|
|
|
+ .eq(GameAppletShell::getGameId, user.getGameId()));
|
|
|
+
|
|
|
+ if (gameAppletShell == null) {
|
|
|
+ return ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer proControlType = gameAppletShell.getProControlType();
|
|
|
+
|
|
|
+ if (Objects.equals(proControlType, ShellControlEnum.SHELL_CONTROL_CLOSE.getShellControl())) {
|
|
|
+ return ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.equals(proControlType, ShellControlEnum.SHELL_CONTROL_OPEN.getShellControl())) {
|
|
|
+ return ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.equals(proControlType, ShellControlEnum.SHELL_CONTROL_NEW_USER_OPEN.getShellControl())) {
|
|
|
+ return register ? ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch() : ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.equals(proControlType, ShellControlEnum.SHELL_CONTROL_LOW_LEVEL_OPEN.getShellControl())) {
|
|
|
+
|
|
|
+ List<GameUserRole> gameUserRoleList = gameUserRoleService.list(new LambdaQueryWrapper<GameUserRole>()
|
|
|
+ .eq(GameUserRole::getUserId, user.getId())
|
|
|
+ .eq(GameUserRole::getGameId, user.getGameId()));
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(gameUserRoleList)) {
|
|
|
+ return ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch();
|
|
|
+ }
|
|
|
+
|
|
|
+ GameUserRole gameUserRole = gameUserRoleList.stream().max(Comparator.comparing(GameUserRole::getRoleLevel)).orElse(null);
|
|
|
+
|
|
|
+ if (gameUserRole == null || gameUserRole.getRoleLevel() <= gameAppletShell.getProControlLevel()) {
|
|
|
+ return ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch();
|
|
|
+ }
|
|
|
+ return ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
|
|
|
+ }
|
|
|
+ log.error("版本信息不存在, userId : {}, gameAppletShell : {}", user.getId(), JsonUtil.toString(gameAppletShell));
|
|
|
+ throw new BaseException("参数错误, 游戏参数设置错误");
|
|
|
+ }
|
|
|
+}
|