package com.casic.PgInterface.patroler.manager;

import com.casic.PgInterface.core.hibernate.HibernateEntityDao;
import com.casic.PgInterface.core.util.StringUtils;
import com.casic.PgInterface.devTable.manager.PgDeviceManager;
import com.casic.PgInterface.patroler.domain.PgAlarmRule;
import com.casic.PgInterface.patroler.dto.PgAlarmRuleDto;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by yxw on 2017/12/14.
 */
@Service
public class PgAlarmRuleManager extends HibernateEntityDao<PgAlarmRule> {

    @Resource
    private PgDeviceManager pgDeviceManager;

    //根据设备获取设备报警阈值
    public List<PgAlarmRuleDto>  getAlarmRuleDto(String devType) {
        Criteria criteria=createCriteria(PgAlarmRule.class);

        if(StringUtils.isNotBlank(devType))
            criteria.add(Restrictions.eq("devType", devType));
        criteria.addOrder(Order.desc("id"));

        List<PgAlarmRule> pgAlarmRuleList=criteria.list();
        List<PgAlarmRuleDto> pgAlarmRuleDtoList = new ArrayList<>();
        for (PgAlarmRule pgAlarmRule : pgAlarmRuleList) {
            pgAlarmRuleDtoList.add(new PgAlarmRuleDto(pgAlarmRule,pgDeviceManager));
        }
        return pgAlarmRuleDtoList;
    }

}