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

import com.td.boss.common.pojo.Result;
import com.td.boss.common.service.*;
import com.td.boss.game.comsnbfreeze.pojo.ComSnbFreeze;
import com.td.boss.game.comsnbfreeze.vo.ComSnbFreezeVo;
import com.td.boss.game.comsnbfreeze.repository.ComSnbFreezeRepository;
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 ComSnbFreezeServiceImpl extends CommonServiceImpl<ComSnbFreezeVo, ComSnbFreeze, String> implements ComSnbFreezeService {

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private ComSnbFreezeRepository comSnbFreezeRepository;


    @Override
    public ComSnbFreezeVo findByUserId(String userId) {
        Optional<ComSnbFreezeVo> comSnbFreezeVo =  comSnbFreezeRepository.findByUserId(userId);
        if(comSnbFreezeVo.orElse(null) == null){
            return null;
        }else{
            return CopyUtil.copy(comSnbFreezeVo.get(), ComSnbFreezeVo.class);
        }
    }


    @Override
    public ComSnbFreezeVo findById(String id) {
        Optional<ComSnbFreeze> comSnbFreeze =  comSnbFreezeRepository.findById(id);
        if(comSnbFreeze.orElse(null) == null){
            return null;
        }else{
            return CopyUtil.copy(comSnbFreeze.get(), ComSnbFreezeVo.class);
        }
    }

    @Override
    public ComSnbFreeze AddByUserId(ComSnbFreeze comSnbFreeze) {
        ComSnbFreeze _comSnbFreeze =  comSnbFreezeRepository.saveAndFlush(comSnbFreeze);
        return _comSnbFreeze;
    }

}
