package com.zanxiang.game.module.sdk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zanxiang.game.module.mybatis.entity.GameUser;
import com.zanxiang.game.module.mybatis.entity.User;
import com.zanxiang.game.module.mybatis.mapper.GameUserMapper;
import com.zanxiang.game.module.sdk.service.IGameUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author : xufeng
 * @time : 2022-07-06
 */
@Slf4j
@Service
public class GameUserServiceImpl extends ServiceImpl<GameUserMapper, GameUser> implements IGameUserService {

    @Override
    public void createGameUser(User user) {
        //查询玩家信息
        GameUser gameUser = super.getOne(new LambdaQueryWrapper<GameUser>()
                .eq(GameUser::getGameId, user.getGameId())
                .eq(GameUser::getUserId, user.getId()));
        //玩家信息已存在
        if (gameUser != null) {
            return;
        }
        super.save(GameUser.builder()
                .userId(user.getId())
                .gameId(user.getGameId())
                .nickname(user.getNickname())
                .regTime(user.getCreateTime())
                .createTime(LocalDateTime.now())
                .updateTime(LocalDateTime.now())
                .build());
    }
}
