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

import com.td.boss.common.service.*;
import com.td.boss.game.comfruit.pojo.ComFruit;
import com.td.boss.game.comfruit.vo.ComFruitVo;
import com.td.boss.game.comfruit.repository.ComFruitRepository;
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.List;
import java.util.Optional;

@Service
@Transactional
public class ComFruitServiceImpl extends CommonServiceImpl<ComFruitVo, ComFruit, Integer> implements ComFruitService{

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private ComFruitRepository comFruitRepository;

    @Override
    public ComFruitVo findById(Integer id) {
        Optional<ComFruit> comMallSeed = comFruitRepository.findById(id);
        if(comMallSeed.orElse(null) == null){
            return null;
        }else{
            return CopyUtil.copy(comMallSeed.get(), ComFruitVo.class);
        }
    }


    @Override
    public List<ComFruit> findFruitAll() {
        return comFruitRepository.findAll();
    }
}
