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

import com.gyee.wisdom.common.data.alarm.Alerthistory;
import com.gyee.wisdom.common.data.alarm.Warningrecords;
import com.gyee.wisdom.dao.alarm.WarningrecordsDao;
import com.gyee.wisdom.dao.sql.alarm.Entity.AlerthistoryEntity;
import com.gyee.wisdom.dao.sql.alarm.Entity.WarningrecordsEntity;
import com.gyee.wisdom.dao.sql.alarm.repository.WarningrecordsRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

/**
 * @Auther: ruyuan
 * @Date: 2019-05-06 11:11
 * @Description:
 */
@Component
@Slf4j
public class JpaWarningrecordsDao implements WarningrecordsDao {

    @Autowired
    private WarningrecordsRepository warningrecordsRepository;

    @Override
    public void saveList(Warningrecords warningrecords) {
        try {
            warningrecordsRepository.saveAndFlush(new WarningrecordsEntity(warningrecords));
        }catch (Exception e){
            log.error("--------warningrecordsRepository信息error--------{}",e.getMessage());
        }
    }

    @Override
    public void batchSave(List<Warningrecords> lst) {
        ArrayList<WarningrecordsEntity> entities = new ArrayList<>();
        for(Warningrecords his : lst) {
            WarningrecordsEntity et = new WarningrecordsEntity(his);
            entities.add(et);
        }
        try {
            warningrecordsRepository.saveAll(entities);
            warningrecordsRepository.flush();
        }catch (Exception e){
            log.error("--------保存报警历史信息error--------{}",e.getMessage());
        }
    }

}
