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

import com.gyee.wisdom.common.data.DataUtil;
import com.gyee.wisdom.common.data.windturbine.Project;
import com.gyee.wisdom.dao.windturbine.IProjectDao;
import com.gyee.wisdom.dao.sql.Windturbine.entity.ProjectEntity;
import com.gyee.wisdom.dao.sql.Windturbine.repsoitory.ProjectRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class JpaProjectDao implements IProjectDao {
    @Autowired
    private ProjectRepository projectRepository;

    @Override
    public void delete(String id) {
        projectRepository.deleteById(id);
    }

    @Override
    public void save(Project project) {
        projectRepository.save(new ProjectEntity(project));
    }

    @Override
    public List<Project> findAll() {
        return DataUtil.convertDataList(projectRepository.findAll());
    }

    @Override
    public Project findbyid(String id) {
        return projectRepository.findById(id).get().toData();
    }

    @Override
    public List<Project> findbyStationId(String stationId) {
        List<ProjectEntity> lpe=projectRepository.findByStationIdEquals(stationId);
        return DataUtil.convertDataList(
                projectRepository.findByStationIdEquals(stationId)
        );
    }
}
