|
@@ -8,13 +8,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.zanxiang.common.enums.GameCategoryEnum;
|
|
|
import com.zanxiang.common.utils.bean.BeanUtils;
|
|
|
import com.zanxiang.manage.domain.dto.GameDTO;
|
|
|
-import com.zanxiang.manage.domain.params.GameAddParam;
|
|
|
-import com.zanxiang.manage.domain.params.GameListParam;
|
|
|
-import com.zanxiang.manage.domain.params.GameUpdateParam;
|
|
|
+import com.zanxiang.manage.domain.params.*;
|
|
|
import com.zanxiang.manage.domain.vo.*;
|
|
|
import com.zanxiang.manage.service.*;
|
|
|
import com.zanxiang.mybatis.entity.Cp;
|
|
|
import com.zanxiang.mybatis.entity.Game;
|
|
|
+import com.zanxiang.mybatis.entity.GameApplet;
|
|
|
+import com.zanxiang.mybatis.entity.GameCategory;
|
|
|
import com.zanxiang.mybatis.mapper.GameMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -49,6 +49,182 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements Ga
|
|
|
@Autowired
|
|
|
private CpService cpService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private GameAppletService gameAppletService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取游戏对接参数
|
|
|
+ *
|
|
|
+ * @param id : 游戏id
|
|
|
+ * @return : 信息展示
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public GameDockVO getGameDock(Long id) {
|
|
|
+ Game game = super.getById(id);
|
|
|
+ GameDockVO gameDockVO = BeanUtils.copy(game, GameDockVO.class);
|
|
|
+ if (gameDockVO == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Cp cp = cpService.getById(gameDockVO.getCpId());
|
|
|
+ if (cp != null) {
|
|
|
+ gameDockVO.setCpName(cp.getCpName());
|
|
|
+ }
|
|
|
+ GameApplet gameApplet = gameAppletService.getOne(new LambdaQueryWrapper<GameApplet>().eq(GameApplet::getGameId, gameDockVO.getId()));
|
|
|
+ if (gameApplet != null) {
|
|
|
+ gameDockVO.setAppId(gameApplet.getAppId());
|
|
|
+ gameDockVO.setAppSecret(gameApplet.getAppSecret());
|
|
|
+ }
|
|
|
+ return gameDockVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 参数对接更新
|
|
|
+ *
|
|
|
+ * @param param : 对接参数
|
|
|
+ * @return : 返回更新结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean gameDockUpdate(GameDockParam param) {
|
|
|
+ if (Strings.isNotBlank(param.getAppKey())) {
|
|
|
+ super.update(new LambdaUpdateWrapper<Game>()
|
|
|
+ .set(Game::getAppKey, param.getAppKey())
|
|
|
+ .set(Game::getUpdateTime, LocalDateTime.now())
|
|
|
+ .eq(Game::getId, param.getId()));
|
|
|
+ }
|
|
|
+ if (Strings.isBlank(param.getAppId()) && Strings.isBlank(param.getAppSecret())) {
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+ GameApplet gameApplet = gameAppletService.getOne(new LambdaQueryWrapper<GameApplet>()
|
|
|
+ .eq(GameApplet::getGameId, param.getId()));
|
|
|
+ if (gameApplet == null) {
|
|
|
+ gameApplet = GameApplet.builder()
|
|
|
+ .gameId(param.getId())
|
|
|
+ .createTime(LocalDateTime.now())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+ gameApplet.setUpdateTime(LocalDateTime.now());
|
|
|
+ if (Strings.isNotBlank(param.getAppId())) {
|
|
|
+ gameApplet.setAppId(param.getAppId());
|
|
|
+ }
|
|
|
+ if (Strings.isNotBlank(param.getAppSecret())) {
|
|
|
+ gameApplet.setAppSecret(param.getAppSecret());
|
|
|
+ }
|
|
|
+ return gameAppletService.saveOrUpdate(gameApplet);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取游戏关联信息
|
|
|
+ *
|
|
|
+ * @param id : 游戏id
|
|
|
+ * @return : 返回游戏关联信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public GameRelationVO getGameRelation(Long id) {
|
|
|
+ Game game = super.getById(id);
|
|
|
+ GameRelationVO gameRelationVO = BeanUtils.copy(game, GameRelationVO.class);
|
|
|
+ if (gameRelationVO == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Map<Long, Game> gameMap = this.getGameRelationMap(Collections.singletonList(game));
|
|
|
+ //没有关联游戏
|
|
|
+ if (gameMap.isEmpty()) {
|
|
|
+ return gameRelationVO;
|
|
|
+ }
|
|
|
+ //设置关联游戏名字
|
|
|
+ if (Objects.equals(gameRelationVO.getParentId(), 0L)) {
|
|
|
+ gameRelationVO.setParentId(game.getId());
|
|
|
+ gameRelationVO.setParentName(game.getName());
|
|
|
+ gameRelationVO.setParentCategoryId(game.getCategory());
|
|
|
+ } else {
|
|
|
+ //非主游戏
|
|
|
+ if (gameRelationVO.getParentId() != null && gameMap.containsKey(gameRelationVO.getParentId())) {
|
|
|
+ gameRelationVO.setParentName(gameMap.get(gameRelationVO.getParentId()).getName());
|
|
|
+ gameRelationVO.setParentCategoryId(gameMap.get(gameRelationVO.getParentId()).getCategory());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (gameRelationVO.getGuideGameId() != null && gameMap.containsKey(gameRelationVO.getGuideGameId())) {
|
|
|
+ gameRelationVO.setGuideGameName(gameMap.get(gameRelationVO.getGuideGameId()).getName());
|
|
|
+ gameRelationVO.setGuideCategoryId(gameMap.get(gameRelationVO.getGuideGameId()).getCategory());
|
|
|
+ }
|
|
|
+ if (gameRelationVO.getH5GameId() != null && gameMap.containsKey(gameRelationVO.getH5GameId())) {
|
|
|
+ gameRelationVO.setH5GameName(gameMap.get(gameRelationVO.getH5GameId()).getName());
|
|
|
+ }
|
|
|
+ //设置关联游戏应用类型名字
|
|
|
+ Set<Long> categoryIdSet = new HashSet<>();
|
|
|
+ if (gameRelationVO.getParentCategoryId() != null) {
|
|
|
+ categoryIdSet.add(gameRelationVO.getParentCategoryId());
|
|
|
+ }
|
|
|
+ if (gameRelationVO.getGuideCategoryId() != null) {
|
|
|
+ categoryIdSet.add(gameRelationVO.getGuideCategoryId());
|
|
|
+ }
|
|
|
+ Map<Long, GameCategory> categoryMap = gameCategoryService.listByIds(categoryIdSet).stream()
|
|
|
+ .collect(Collectors.toMap(GameCategory::getId, Function.identity()));
|
|
|
+ if (gameRelationVO.getParentCategoryId() != null && categoryMap.containsKey(gameRelationVO.getParentCategoryId())) {
|
|
|
+ gameRelationVO.setParentCategoryName(categoryMap.get(gameRelationVO.getParentCategoryId()).getName());
|
|
|
+ }
|
|
|
+ if (gameRelationVO.getGuideCategoryId() != null && categoryMap.containsKey(gameRelationVO.getGuideCategoryId())) {
|
|
|
+ gameRelationVO.setGuideCategoryName(categoryMap.get(gameRelationVO.getGuideCategoryId()).getName());
|
|
|
+ }
|
|
|
+ return gameRelationVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取游戏的关联map
|
|
|
+ *
|
|
|
+ * @param gameList : 游戏列表
|
|
|
+ * @return : 返回游戏列表
|
|
|
+ */
|
|
|
+ private Map<Long, Game> getGameRelationMap(List<Game> gameList) {
|
|
|
+ Set<Long> gameIdSet = new HashSet<>();
|
|
|
+ gameList.forEach(game -> {
|
|
|
+ if (game.getParentId() != null && !Objects.equals(game.getParentId(), 0L)) {
|
|
|
+ gameIdSet.add(game.getParentId());
|
|
|
+ }
|
|
|
+ if (game.getH5GameId() != null) {
|
|
|
+ gameIdSet.add(game.getH5GameId());
|
|
|
+ }
|
|
|
+ if (game.getGuideGameId() != null) {
|
|
|
+ gameIdSet.add(game.getGuideGameId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (gameIdSet.isEmpty()) {
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+ return super.listByIds(gameIdSet).stream().collect(Collectors.toMap(Game::getId, Function.identity()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导量游戏更新
|
|
|
+ *
|
|
|
+ * @param param : 关联游戏更新参数
|
|
|
+ * @return : 返回更新结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean guideGameUpdateUpdate(GuideGameUpdateParam param) {
|
|
|
+ return super.update(new LambdaUpdateWrapper<Game>()
|
|
|
+ .set(param.getGuideGameId() != null, Game::getGuideGameId, param.getGuideGameId())
|
|
|
+ .set(Game::getUpdateTime, LocalDateTime.now())
|
|
|
+ .eq(Game::getId, param.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关联游戏更新
|
|
|
+ *
|
|
|
+ * @param param : 关联游戏更新参数
|
|
|
+ * @return : 返回更新结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean relationGameUpdate(RelationGameUpdateParam param) {
|
|
|
+ if (param.getParentId() == null && param.getH5GameId() == null) {
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+ return super.update(new LambdaUpdateWrapper<Game>()
|
|
|
+ .set(param.getParentId() != null, Game::getParentId, param.getParentId())
|
|
|
+ .set(param.getH5GameId() != null, Game::getH5GameId, param.getH5GameId())
|
|
|
+ .set(Game::getUpdateTime, LocalDateTime.now())
|
|
|
+ .eq(Game::getId, param.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取游戏基本信息
|
|
|
*
|
|
@@ -78,29 +254,37 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements Ga
|
|
|
GameCategoryVO gameCategoryVO = gameCategoryService.getById(game.getCategory());
|
|
|
gameInfoVO.setCategory(BeanUtils.copy(gameCategoryVO, GameCategoryParentVO.class));
|
|
|
}
|
|
|
- //游戏名字
|
|
|
- List<Long> gameIdList = new ArrayList<>();
|
|
|
+ //是否主游戏
|
|
|
+ gameInfoVO.setIsParentGame(Objects.equals(gameInfoVO.getParentId(), 0L));
|
|
|
+ //关联游戏查询
|
|
|
+ Map<Long, Game> gameMap = this.getGameRelationMap(Collections.singletonList(game));
|
|
|
+ //没有关联游戏
|
|
|
+ if (gameMap.isEmpty()) {
|
|
|
+ return gameInfoVO;
|
|
|
+ }
|
|
|
+ //设置关联游戏名字
|
|
|
if (gameInfoVO.getParentId() != null && !Objects.equals(gameInfoVO.getParentId(), 0L)) {
|
|
|
- gameIdList.add(gameInfoVO.getParentId());
|
|
|
+ gameInfoVO.setParentName(gameMap.get(gameInfoVO.getParentId()).getName());
|
|
|
+ } else {
|
|
|
+ gameInfoVO.setParentId(game.getId());
|
|
|
+ gameInfoVO.setParentName(game.getName());
|
|
|
}
|
|
|
if (gameInfoVO.getH5GameId() != null) {
|
|
|
- gameIdList.add(gameInfoVO.getH5GameId());
|
|
|
+ gameInfoVO.setH5GameName(gameMap.get(gameInfoVO.getH5GameId()).getName());
|
|
|
}
|
|
|
if (gameInfoVO.getGuideGameId() != null) {
|
|
|
- gameIdList.add(gameInfoVO.getGuideGameId());
|
|
|
+ gameInfoVO.setGuideGameName(gameMap.get(gameInfoVO.getGuideGameId()).getName());
|
|
|
}
|
|
|
- List<Game> gameList = super.listByIds(gameIdList);
|
|
|
-
|
|
|
-
|
|
|
return gameInfoVO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取游戏基本信息
|
|
|
+ * 游戏基本信息更新
|
|
|
*
|
|
|
* @param param : 游戏更新参数
|
|
|
* @return : 返回更新结果
|
|
|
*/
|
|
|
+ @Override
|
|
|
public Boolean updateGameInfo(GameUpdateParam param) {
|
|
|
//游戏分类处理
|
|
|
List<Long> classifyList = param.getClassifyList();
|
|
@@ -112,7 +296,9 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements Ga
|
|
|
.set(Strings.isNotBlank(map.get("classifyParent")), Game::getClassifyParent, map.get("classifyParent"))
|
|
|
.set(param.getCategory() != null, Game::getCategory, param.getCategory())
|
|
|
.set(param.getShareScale() != null, Game::getShareScale, param.getShareScale())
|
|
|
- .set(param.getParentId() != null, Game::getParentId, param.getParentId())
|
|
|
+ .set(Objects.equals(param.getIsParentGame(), Boolean.TRUE), Game::getParentId, 0L)
|
|
|
+ .set(!Objects.equals(param.getIsParentGame(), Boolean.TRUE) && param.getParentId() != null,
|
|
|
+ Game::getParentId, param.getParentId())
|
|
|
.set(param.getH5GameId() != null, Game::getH5GameId, param.getH5GameId())
|
|
|
.set(param.getGuideGameId() != null, Game::getGuideGameId, param.getGuideGameId())
|
|
|
.set(Strings.isNotBlank(param.getPublicity()), Game::getPublicity, param.getPublicity())
|
|
@@ -124,7 +310,6 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements Ga
|
|
|
.eq(Game::getId, param.getId()));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 新增游戏
|
|
|
*
|
|
@@ -240,7 +425,7 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements Ga
|
|
|
*/
|
|
|
@Override
|
|
|
public List<GameChoiceVO> choiceList() {
|
|
|
- List<Game> gameList = super.list(new LambdaQueryWrapper<Game>().select(Game::getId, Game::getName));
|
|
|
+ List<Game> gameList = super.list(new LambdaQueryWrapper<Game>().select(Game::getId, Game::getName, Game::getCategory));
|
|
|
return BeanUtils.copyList(gameList, GameChoiceVO.class);
|
|
|
}
|
|
|
|