package com.gyee.wisdom.dao.sql.feature;

import com.gyee.wisdom.common.data.feature.FeatureStat;
import com.gyee.wisdom.dao.feature.IFeatureStatDao;
import com.gyee.wisdom.dao.sql.feature.entity.FeatureStatEntity;
import com.gyee.wisdom.dao.sql.feature.repository.FeatureStatRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @descrition:
 * @author:Wanghs
 * @date:2019-11-18
 */
@Component
public class FeatureStatDao implements IFeatureStatDao {

    @Autowired
    private FeatureStatRepository featureStatRepository;

    @Override
    public List<FeatureStat> getAll() {

        List<FeatureStat> resultList = new ArrayList<>();
        List<FeatureStatEntity> lst = featureStatRepository.findAll();
        for (FeatureStatEntity entity : lst) {
            resultList.add(entity.toData());
        }
        return resultList;
    }

    @Override
    public void save(FeatureStat stat) {
        featureStatRepository.save(new FeatureStatEntity(stat));
    }
}
