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


import com.gyee.wisdom.common.data.DataUtil;
import com.gyee.wisdom.common.data.alarm.Warning;
import com.gyee.wisdom.common.data.alarm.Warningfj;
import com.gyee.wisdom.dao.alarm.WarningfjDao;
import com.gyee.wisdom.dao.sql.alarm.Entity.WarningfjEntity;
import com.gyee.wisdom.dao.sql.alarm.repository.WarningfjRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import java.util.List;

@Component
public class JpaWarningfjDao implements WarningfjDao {
    @Autowired
    private WarningfjRepository warningfjRepository;
    @Override
    public List<Warningfj> findAll() {
        List<Warningfj> warning=DataUtil.convertDataList(warningfjRepository.findAll());
        return warning;
    }

    @Override
    public Warningfj findById(String id) {
        Warningfj warning=warningfjRepository.findById(id).get().toData();
        return warning;
    }

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


    @Override
    public void save(Warningfj warning) {
        warningfjRepository.save(new WarningfjEntity(warning));
    }

    @Override
    public Warningfj findByprojectId(String id) {
        return warningfjRepository.findAllById(id).toData();
    }

    @Override
    public Warningfj findByEdnavalueAndModelId(int ednavalue,String modelId){
        List<WarningfjEntity> warningfjEntityList = warningfjRepository.findByEdnaValueAndModelId(ednavalue,modelId);
        WarningfjEntity warningfjEntity= new WarningfjEntity();
        if(warningfjEntityList.size() != 0){
            warningfjEntity=warningfjEntityList.get(0);
        }else{
            return null;
        }
            return warningfjEntity.toData();
        }
}
