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

import com.td.boss.common.service.*;
import com.td.boss.game.comusers.pojo.ComUsers;
import com.td.boss.game.comusers.vo.ComUsersVo;
import com.td.boss.game.comusers.repository.ComUsersRepository;
import com.td.boss.util.CopyUtil;
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;
import java.util.Optional;

@Service
@Transactional
public class ComUsersServiceImpl extends CommonServiceImpl<ComUsersVo, ComUsers, String> implements ComUsersService{

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private ComUsersRepository comUsersRepository;


    @Override
    public ComUsersVo findByUserId(String userId) {
        Optional<ComUsers>  comUsers =  comUsersRepository.findById(userId);
        if(comUsers == null){
            return null;
        }else{
            return CopyUtil.copy(comUsers.get(), ComUsersVo.class);
        }
    }
}
