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

import com.gyee.wisdom.common.data.DataUtil;
import com.gyee.wisdom.common.data.windturbine.Windturbine;
import com.gyee.wisdom.dao.sql.Windturbine.entity.WindturbineEntity;
import com.gyee.wisdom.dao.sql.Windturbine.repsoitory.WindturbineRepository;
import com.gyee.wisdom.dao.sql.Windturbine.repsoitory.PowerStationRepository;
import com.gyee.wisdom.dao.windturbine.IWindturbineDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author songwb<songwb@aliyun.com>
 */
@Component
public class JpaWindturbineDao implements IWindturbineDao {

    @Autowired
    private WindturbineRepository windturbineRepository;
    @Autowired
    private PowerStationRepository powerStationRepository;



    @Override
    public void del(String id) {
        windturbineRepository.deleteById(id);
    }
    //修改暂时不接入
    @Override
    public void save(Windturbine win) {
        WindturbineEntity we=new WindturbineEntity(win);
        windturbineRepository.save(we);
        System.out.println();
    }

    @Override
    public List<Windturbine> find() {
       return DataUtil.convertDataList(windturbineRepository.findAll());
    }


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

    public List<Windturbine> findByStationId(String stationId)
    {
        return DataUtil.convertDataList(windturbineRepository.findByWindPowerStationId(stationId));
    }

    public List<Windturbine> findByProjectId(String projectId)
    {
        return DataUtil.convertDataList(windturbineRepository.findByProjectId(projectId));
    }

    public List<Windturbine> findByLineId(String lineId)
    {
        return DataUtil.convertDataList(windturbineRepository.findByLineId(lineId));
    }

    public List<Windturbine> findByModelId(String modelId)
    {
        return DataUtil.convertDataList(windturbineRepository.findByModelId(modelId));
    }
    public List<Windturbine> findByModelIdIn(String[] modelIds)
    {
        return DataUtil.convertDataList(windturbineRepository.findByModelIdIn(modelIds));
    }

    public List<Windturbine> findByStationIdAndModelId(String stationId, String modelId)
    {
        return DataUtil.convertDataList(windturbineRepository.findByWindPowerStationIdAndModelId(stationId, modelId));
    }


}
