|  | @@ -2,24 +2,28 @@ package com.zanxiang.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.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.vo.*;
 | 
	
		
			
				|  |  | -import com.zanxiang.manage.service.GameCategoryService;
 | 
	
		
			
				|  |  | -import com.zanxiang.manage.service.GamePayWayService;
 | 
	
		
			
				|  |  | -import com.zanxiang.manage.service.GameService;
 | 
	
		
			
				|  |  | -import com.zanxiang.manage.service.GameStrategyService;
 | 
	
		
			
				|  |  | +import com.zanxiang.manage.service.*;
 | 
	
		
			
				|  |  | +import com.zanxiang.mybatis.entity.Cp;
 | 
	
		
			
				|  |  |  import com.zanxiang.mybatis.entity.Game;
 | 
	
		
			
				|  |  |  import com.zanxiang.mybatis.mapper.GameMapper;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | +import org.apache.logging.log4j.util.Strings;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import org.springframework.util.CollectionUtils;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import java.time.LocalDateTime;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  |  import java.util.function.Function;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
	
		
			
				|  | @@ -42,6 +46,141 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements Ga
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private GameCategoryService gameCategoryService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private CpService cpService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 获取游戏基本信息
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param gameId : 游戏id
 | 
	
		
			
				|  |  | +     * @return : 返回游戏信息
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public GameInfoVO getGameInfo(Long gameId) {
 | 
	
		
			
				|  |  | +        Game game = super.getById(gameId);
 | 
	
		
			
				|  |  | +        GameInfoVO gameInfoVO = BeanUtils.copy(game, GameInfoVO.class);
 | 
	
		
			
				|  |  | +        if (gameInfoVO == null) {
 | 
	
		
			
				|  |  | +            return null;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (gameInfoVO.getCpId() != null) {
 | 
	
		
			
				|  |  | +            Cp cp = cpService.getById(gameInfoVO.getCpId());
 | 
	
		
			
				|  |  | +            if (cp != null) {
 | 
	
		
			
				|  |  | +                gameInfoVO.setCpName(cp.getCpName());
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (Strings.isNotBlank(game.getClassify())) {
 | 
	
		
			
				|  |  | +            String[] split = game.getClassify().split(",");
 | 
	
		
			
				|  |  | +            List<Long> idList = Arrays.stream(split).map(Long::valueOf).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +            List<GameCategoryVO> gameCategoryList = gameCategoryService.listByIdList(idList, GameCategoryEnum.GAME_LABEL.getCategoryType());
 | 
	
		
			
				|  |  | +            gameInfoVO.setClassifyList(BeanUtils.copyList(gameCategoryList, GameCategoryParentVO.class));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (game.getCategory() != null) {
 | 
	
		
			
				|  |  | +            GameCategoryVO gameCategoryVO = gameCategoryService.getById(game.getCategory());
 | 
	
		
			
				|  |  | +            gameInfoVO.setCategory(BeanUtils.copy(gameCategoryVO, GameCategoryParentVO.class));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //游戏名字
 | 
	
		
			
				|  |  | +        List<Long> gameIdList = new ArrayList<>();
 | 
	
		
			
				|  |  | +        if (gameInfoVO.getParentId() != null && !Objects.equals(gameInfoVO.getParentId(), 0L)) {
 | 
	
		
			
				|  |  | +            gameIdList.add(gameInfoVO.getParentId());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (gameInfoVO.getH5GameId() != null) {
 | 
	
		
			
				|  |  | +            gameIdList.add(gameInfoVO.getH5GameId());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (gameInfoVO.getGuideGameId() != null) {
 | 
	
		
			
				|  |  | +            gameIdList.add(gameInfoVO.getGuideGameId());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        List<Game> gameList = super.listByIds(gameIdList);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return gameInfoVO;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 获取游戏基本信息
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param param : 游戏更新参数
 | 
	
		
			
				|  |  | +     * @return : 返回更新结果
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public Boolean updateGameInfo(GameUpdateParam param) {
 | 
	
		
			
				|  |  | +        //游戏分类处理
 | 
	
		
			
				|  |  | +        List<Long> classifyList = param.getClassifyList();
 | 
	
		
			
				|  |  | +        Map<String, String> map = this.getClassifyMap(classifyList);
 | 
	
		
			
				|  |  | +        return super.update(new LambdaUpdateWrapper<Game>()
 | 
	
		
			
				|  |  | +                .set(Strings.isNotBlank(param.getName()), Game::getName, param.getName())
 | 
	
		
			
				|  |  | +                .set(param.getCpId() != null, Game::getCpId, param.getCpId())
 | 
	
		
			
				|  |  | +                .set(Strings.isNotBlank(map.get("classify")), Game::getClassify, map.get("classify"))
 | 
	
		
			
				|  |  | +                .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(param.getH5GameId() != null, Game::getH5GameId, param.getH5GameId())
 | 
	
		
			
				|  |  | +                .set(param.getGuideGameId() != null, Game::getGuideGameId, param.getGuideGameId())
 | 
	
		
			
				|  |  | +                .set(Strings.isNotBlank(param.getPublicity()), Game::getPublicity, param.getPublicity())
 | 
	
		
			
				|  |  | +                .set(Strings.isNotBlank(param.getDescription()), Game::getDescription, param.getDescription())
 | 
	
		
			
				|  |  | +                .set(Strings.isNotBlank(param.getVersion()), Game::getVersion, param.getVersion())
 | 
	
		
			
				|  |  | +                .set(Strings.isNotBlank(param.getGameUrl()), Game::getGameUrl, param.getGameUrl())
 | 
	
		
			
				|  |  | +                .set(Strings.isNotBlank(param.getCpPaybackUrl()), Game::getCpPaybackUrl, param.getCpPaybackUrl())
 | 
	
		
			
				|  |  | +                .set(Game::getUpdateTime, LocalDateTime.now())
 | 
	
		
			
				|  |  | +                .eq(Game::getId, param.getId()));
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 新增游戏
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param param : 游戏新增参数
 | 
	
		
			
				|  |  | +     * @return : 返回添加结果
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public Boolean gameAdd(GameAddParam param) {
 | 
	
		
			
				|  |  | +        //游戏分类处理
 | 
	
		
			
				|  |  | +        List<Long> classifyList = param.getClassifyList();
 | 
	
		
			
				|  |  | +        Map<String, String> map = this.getClassifyMap(classifyList);
 | 
	
		
			
				|  |  | +        Game game = Game.builder()
 | 
	
		
			
				|  |  | +                .cpId(param.getCpId())
 | 
	
		
			
				|  |  | +                .name(param.getName())
 | 
	
		
			
				|  |  | +                .shareScale(param.getShareScale())
 | 
	
		
			
				|  |  | +                .category(param.getCategory())
 | 
	
		
			
				|  |  | +                .classify(map.get("classify"))
 | 
	
		
			
				|  |  | +                .classifyParent(map.get("classifyParent"))
 | 
	
		
			
				|  |  | +                .createTime(LocalDateTime.now())
 | 
	
		
			
				|  |  | +                .updateTime(LocalDateTime.now())
 | 
	
		
			
				|  |  | +                .build();
 | 
	
		
			
				|  |  | +        if (!Objects.equals(param.getIsParentGame(), Boolean.TRUE) && param.getParentGameId() != null) {
 | 
	
		
			
				|  |  | +            game.setParentId(param.getParentGameId());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return super.save(game);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 分类处理
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param classifyList : 选的游戏分类列表
 | 
	
		
			
				|  |  | +     * @return : 返回分类信息
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private Map<String, String> getClassifyMap(List<Long> classifyList) {
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(classifyList)) {
 | 
	
		
			
				|  |  | +            return Collections.emptyMap();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        List<GameCategoryVO> gameCategoryVOList = gameCategoryService.listByIdList(classifyList, GameCategoryEnum.GAME_LABEL.getCategoryType());
 | 
	
		
			
				|  |  | +        Set<Long> classifySet = new HashSet<>();
 | 
	
		
			
				|  |  | +        Set<Long> classifyParentSet = new HashSet<>();
 | 
	
		
			
				|  |  | +        gameCategoryVOList.forEach(vo -> {
 | 
	
		
			
				|  |  | +            classifySet.add(vo.getId());
 | 
	
		
			
				|  |  | +            if (Objects.equals(vo.getParentId(), 0L)) {
 | 
	
		
			
				|  |  | +                classifyParentSet.add(vo.getId());
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +        Map<String, String> map = new HashMap<>(2);
 | 
	
		
			
				|  |  | +        if (!classifySet.isEmpty()) {
 | 
	
		
			
				|  |  | +            map.put("classify", StringUtils.join(classifySet, ","));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (!classifyParentSet.isEmpty()) {
 | 
	
		
			
				|  |  | +            map.put("classifyParent", StringUtils.join(classifySet, ","));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return map;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 查询游戏列表
 | 
	
		
			
				|  |  |       *
 | 
	
	
		
			
				|  | @@ -50,11 +189,6 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements Ga
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public IPage<GameListVO> gameList(GameListParam param) {
 | 
	
		
			
				|  |  | -        //查询游戏类别
 | 
	
		
			
				|  |  | -        List<GameCategoryVO> gameCategoryVOList = new ArrayList<>();
 | 
	
		
			
				|  |  | -        if (Objects.equals(param.getIsParentClassify(), Boolean.TRUE)) {
 | 
	
		
			
				|  |  | -            gameCategoryVOList = gameCategoryService.listById(param.getGameClassifyId(), GameCategoryEnum.GAME_LABEL.getCategoryType());
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  |          //执行查询
 | 
	
		
			
				|  |  |          return page(param.toPage(), new QueryWrapper<Game>().lambda()
 | 
	
		
			
				|  |  |                  .eq(param.getCpId() != null, Game::getCpId, param.getCpId())
 | 
	
	
		
			
				|  | @@ -64,8 +198,10 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements Ga
 | 
	
		
			
				|  |  |                  .eq(param.getGameCategoryId() != null, Game::getCategory, param.getGameCategoryId())
 | 
	
		
			
				|  |  |                  .eq(param.getH5GameId() != null, Game::getH5GameId, param.getH5GameId())
 | 
	
		
			
				|  |  |                  .eq(param.getGuideGameId() != null, Game::getGuideGameId, param.getGuideGameId())
 | 
	
		
			
				|  |  | -                .eq(param.getGameClassifyId() != null && !Objects.equals(param.getIsParentClassify(), Boolean.TRUE), Game::getClassify, param.getGameClassifyId())
 | 
	
		
			
				|  |  | -                .in(param.getGameClassifyId() != null && !gameCategoryVOList.isEmpty(), Game::getClassify, param.getGameClassifyId())
 | 
	
		
			
				|  |  | +                .apply(param.getGameClassifyId() != null && !Objects.equals(param.getIsParentClassify(), Boolean.TRUE),
 | 
	
		
			
				|  |  | +                        "FIND_IN_SET({0}, classify)", String.valueOf(param.getGameClassifyId()))
 | 
	
		
			
				|  |  | +                .apply(param.getGameClassifyId() != null && Objects.equals(param.getIsParentClassify(), Boolean.TRUE),
 | 
	
		
			
				|  |  | +                        "FIND_IN_SET({0}, classifyParent)", String.valueOf(param.getGameClassifyId()))
 | 
	
		
			
				|  |  |                  .eq(param.getStatus() != null, Game::getStatus, param.getStatus())
 | 
	
		
			
				|  |  |                  .orderByDesc(Game::getCreateTime)
 | 
	
		
			
				|  |  |          ).convert(this::toVo);
 | 
	
	
		
			
				|  | @@ -78,17 +214,22 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements Ga
 | 
	
		
			
				|  |  |       * @return : 返回展示对象
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      private GameListVO toVo(Game game) {
 | 
	
		
			
				|  |  | -        if (Objects.isNull(game)) {
 | 
	
		
			
				|  |  | +        GameListVO gameListVO = BeanUtils.copy(game, GameListVO.class);
 | 
	
		
			
				|  |  | +        if (gameListVO == null) {
 | 
	
		
			
				|  |  |              return null;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        GameListVO gameListVO = BeanUtils.copy(game, GameListVO.class);
 | 
	
		
			
				|  |  | -        gameListVO.setIsParentGame(Objects.equals(game.getParentId(), 0L));
 | 
	
		
			
				|  |  | +        //游戏是主游戏
 | 
	
		
			
				|  |  | +        if (Objects.equals(game.getParentId(), 0L)) {
 | 
	
		
			
				|  |  | +            gameListVO.setIsParentGame(Boolean.TRUE);
 | 
	
		
			
				|  |  | +            gameListVO.setParentId(game.getId());
 | 
	
		
			
				|  |  | +            gameListVO.setParentName(game.getName());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          //查询支付方式列表
 | 
	
		
			
				|  |  |          List<GamePayWayVO> gamePayWayVOList = gamePayWayService.getByGameId(game.getId());
 | 
	
		
			
				|  |  | -        gameListVO.setGamePayWayVOList(gamePayWayVOList);
 | 
	
		
			
				|  |  | +        gameListVO.setGamePayWayList(gamePayWayVOList);
 | 
	
		
			
				|  |  |          //查询规则配置列表
 | 
	
		
			
				|  |  |          List<GameStrategyVO> gameStrategyVOList = gameStrategyService.getByGameId(game.getId());
 | 
	
		
			
				|  |  | -        gameListVO.setGameStrategyVOList(gameStrategyVOList);
 | 
	
		
			
				|  |  | +        gameListVO.setGameStrategyList(gameStrategyVOList);
 | 
	
		
			
				|  |  |          return gameListVO;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -146,8 +287,7 @@ public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements Ga
 | 
	
		
			
				|  |  |       * @param gameCategoryId : 分类id
 | 
	
		
			
				|  |  |       * @return : 返回游戏信息列表, null 标识未匹配到游戏, 空表示没有条件
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    @Override
 | 
	
		
			
				|  |  | -    public List<GameDTO> getGameList(Long cpId, Long gameId, Long gameCategoryId) {
 | 
	
		
			
				|  |  | +    private List<GameDTO> getGameList(Long cpId, Long gameId, Long gameCategoryId) {
 | 
	
		
			
				|  |  |          if (cpId == null && gameId == null && gameCategoryId == null) {
 | 
	
		
			
				|  |  |              return Collections.emptyList();
 | 
	
		
			
				|  |  |          }
 |