|  | @@ -1,17 +1,25 @@
 | 
	
		
			
				|  |  |  package com.zanxiang.manage.service.Impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  | +import com.zanxiang.common.enums.CategoryTypeEnum;
 | 
	
		
			
				|  |  |  import com.zanxiang.common.utils.bean.BeanUtils;
 | 
	
		
			
				|  |  | +import com.zanxiang.manage.domain.dto.GameDTO;
 | 
	
		
			
				|  |  |  import com.zanxiang.manage.domain.params.GamePictureParam;
 | 
	
		
			
				|  |  |  import com.zanxiang.manage.domain.vo.GamePictureVO;
 | 
	
		
			
				|  |  |  import com.zanxiang.manage.service.GamePictureService;
 | 
	
		
			
				|  |  | +import com.zanxiang.manage.service.GameService;
 | 
	
		
			
				|  |  | +import com.zanxiang.mybatis.entity.Game;
 | 
	
		
			
				|  |  |  import com.zanxiang.mybatis.entity.GamePicture;
 | 
	
		
			
				|  |  |  import com.zanxiang.mybatis.mapper.GamePictureMapper;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  | +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.Objects;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * @author : lingfeng
 | 
	
	
		
			
				|  | @@ -22,6 +30,9 @@ import java.time.LocalDateTime;
 | 
	
		
			
				|  |  |  @Service
 | 
	
		
			
				|  |  |  public class GamePictureServiceImpl extends ServiceImpl<GamePictureMapper, GamePicture> implements GamePictureService {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private GameService gameService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 根据游戏id查询
 | 
	
		
			
				|  |  |       *
 | 
	
	
		
			
				|  | @@ -34,7 +45,11 @@ public class GamePictureServiceImpl extends ServiceImpl<GamePictureMapper, GameP
 | 
	
		
			
				|  |  |          if (gamePicture == null) {
 | 
	
		
			
				|  |  |              gamePicture = GamePicture.builder().gameId(gameId).build();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        return BeanUtils.copy(gamePicture, GamePictureVO.class);
 | 
	
		
			
				|  |  | +        GamePictureVO gamePictureVO = BeanUtils.copy(gamePicture, GamePictureVO.class);
 | 
	
		
			
				|  |  | +        GameDTO gameDTO = gameService.getById(gameId);
 | 
	
		
			
				|  |  | +        gamePictureVO.setNeedAuth(gameDTO.getNeedAuth());
 | 
	
		
			
				|  |  | +        gamePictureVO.setDownloadCount(gameDTO.getDownloadCount());
 | 
	
		
			
				|  |  | +        return gamePictureVO;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -45,6 +60,63 @@ public class GamePictureServiceImpl extends ServiceImpl<GamePictureMapper, GameP
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public Boolean addOrUpdate(GamePictureParam param) {
 | 
	
		
			
				|  |  | +        GameDTO gameDTO = gameService.getById(param.getGameId());
 | 
	
		
			
				|  |  | +        //微信小游戏更新
 | 
	
		
			
				|  |  | +        if (Objects.equals(gameDTO.getCategory(), CategoryTypeEnum.CATEGORY_TYPE_WX.getCategoryType())) {
 | 
	
		
			
				|  |  | +            return this.appletGameAddOrUpdate(param);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //h5游戏更新
 | 
	
		
			
				|  |  | +        if (Objects.equals(gameDTO.getCategory(), CategoryTypeEnum.CATEGORY_TYPE_H5.getCategoryType())) {
 | 
	
		
			
				|  |  | +            return this.h5GameAddOrUpdate(param);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return Boolean.FALSE;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 微信小游戏图片添加或更新
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param param : 游戏图片参数
 | 
	
		
			
				|  |  | +     * @return : 返回更新结果
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
 | 
	
		
			
				|  |  | +    public Boolean h5GameAddOrUpdate(GamePictureParam param) {
 | 
	
		
			
				|  |  | +        Long gameId = param.getGameId();
 | 
	
		
			
				|  |  | +        GamePicture gamePicture = super.getOne(new LambdaQueryWrapper<GamePicture>().eq(GamePicture::getGameId, gameId));
 | 
	
		
			
				|  |  | +        if (gamePicture == null) {
 | 
	
		
			
				|  |  | +            gamePicture = GamePicture.builder()
 | 
	
		
			
				|  |  | +                    .gameId(gameId)
 | 
	
		
			
				|  |  | +                    .avatarImg(param.getAvatarImg())
 | 
	
		
			
				|  |  | +                    .gamePictureImg(param.getGamePictureImg())
 | 
	
		
			
				|  |  | +                    .loginBackGroundImg(param.getLoginBackGroundImg())
 | 
	
		
			
				|  |  | +                    .createTime(LocalDateTime.now())
 | 
	
		
			
				|  |  | +                    .updateTime(LocalDateTime.now())
 | 
	
		
			
				|  |  | +                    .build();
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            gamePicture.setAvatarImg(param.getAvatarImg());
 | 
	
		
			
				|  |  | +            gamePicture.setGamePictureImg(param.getGamePictureImg());
 | 
	
		
			
				|  |  | +            gamePicture.setLoginBackGroundImg(param.getLoginBackGroundImg());
 | 
	
		
			
				|  |  | +            gamePicture.setUpdateTime(LocalDateTime.now());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //游戏图片信息更新
 | 
	
		
			
				|  |  | +        super.saveOrUpdate(gamePicture);
 | 
	
		
			
				|  |  | +        //游戏信息更新
 | 
	
		
			
				|  |  | +        if (param.getNeedAuth() != null || param.getDownloadCount() != null) {
 | 
	
		
			
				|  |  | +            gameService.update(new LambdaUpdateWrapper<Game>()
 | 
	
		
			
				|  |  | +                    .set(Game::getNeedAuth, param.getNeedAuth())
 | 
	
		
			
				|  |  | +                    .set(Game::getDownloadCount, param.getDownloadCount())
 | 
	
		
			
				|  |  | +                    .set(Game::getUpdateTime, LocalDateTime.now())
 | 
	
		
			
				|  |  | +                    .eq(Game::getId, gameId));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return Boolean.TRUE;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 微信小游戏图片添加或更新
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param param : 游戏图片参数
 | 
	
		
			
				|  |  | +     * @return : 返回更新结果
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private Boolean appletGameAddOrUpdate(GamePictureParam param) {
 | 
	
		
			
				|  |  |          Long gameId = param.getGameId();
 | 
	
		
			
				|  |  |          GamePicture gamePicture = super.getOne(new LambdaQueryWrapper<GamePicture>().eq(GamePicture::getGameId, gameId));
 | 
	
		
			
				|  |  |          if (gamePicture == null) {
 |