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

import com.td.WaDa.common.service.*;
import com.td.WaDa.game.comusers.pojo.ComUsers;
import com.td.WaDa.game.comusers.vo.ComUsersVo;
import com.td.WaDa.game.comusers.repository.ComUsersRepository;
import com.td.WaDa.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.orElse(null) == null){
            return null;
        }else{
            return CopyUtil.copy(comUsers.get(), ComUsersVo.class);
        }
    }


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

    /**
     * 统一交易double snb 操作
     * @param tranSnb
     * @param userId
     * @return
     */
    @Override
    public ComUsersVo tranSNBByUserId(Double tranSnb, String userId) {

        return null;
    }

    @Override
    public Long findAllCount() {
        return comUsersRepository.count();
    }

    @Override
    public Long newToday() {
        return comUsersRepository.newToday();
    }
}
