package com.td.boss.game.complayers.service;

import com.td.boss.common.service.*;
import com.td.boss.game.complayers.pojo.ComPlayers;
import com.td.boss.game.complayers.vo.ComPlayersVo;
import com.td.boss.game.complayers.repository.ComPlayersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Service
@Transactional
public class ComPlayersServiceImpl extends CommonServiceImpl<ComPlayersVo, ComPlayers, Integer> implements ComPlayersService{

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private ComPlayersRepository comPlayersRepository;

    @Override
    public ComPlayers findByUserId(String userId) {
        return comPlayersRepository.findByUserId(userId).orElse(null);
    }

    @Override
    @Transactional
    public ComPlayers addComPlayers(ComPlayers comPlayers) {
        ComPlayers player =  comPlayersRepository.saveAndFlush(comPlayers);
        return player;
    }
}
