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

import com.gyee.wisdom.common.data.DataUtil;
import com.gyee.wisdom.common.data.windturbine.Line;
import com.gyee.wisdom.dao.windturbine.ILineDao;
import com.gyee.wisdom.dao.sql.Windturbine.entity.LineEntity;
import com.gyee.wisdom.dao.sql.Windturbine.repsoitory.LineRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class JpaLineDao implements ILineDao{
    @Autowired
    private LineRepository lineRepository;
    @Override
    public List<Line> findAll() {
        List<Line> listline=DataUtil.convertDataList(lineRepository.findAll());
        return listline;
    }

    @Override
    public Line findById(String id) {
        Line line=lineRepository.findById(id).get().toData();
        return line;
    }

    @Override
    public void deletebyid(String id) {
        lineRepository.deleteById(id);
    }

    @Override
    public void save(Line line) {
        lineRepository.save(new LineEntity(line));
    }

    @Override
    public List<Line> findByprojectId(String id) {
        return DataUtil.convertDataList(lineRepository.findFirstByProjectId(id));
    }
}
