package com.gyee.alarm.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gyee.alarm.init.CacheContext;
import com.gyee.alarm.mapper.auto.ProEconAlarmConfigurationMapper;
import com.gyee.alarm.mapper.auto.ProEconAlarmSwitchMapper;
import com.gyee.alarm.model.auto.ProEconAlarmSwitch;
import com.gyee.alarm.model.auto.ProEconInputOrOutputSpeed;
import com.gyee.alarm.model.vo.AlarmConfigurationVo;
import com.gyee.alarm.service.RuleUpdateEventService;
import com.gyee.alarm.service.auto.IProEconAlarmConfigurationService;
import com.gyee.alarm.service.auto.IProEconAlarmSwitchService;
import com.gyee.alarm.util.SnowflakeGenerator;
import com.gyee.alarm.util.StringUtils;
import org.springframework.stereotype.Service;

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


@Service
public class AlarmSwitchService {

    @Resource
    private IProEconAlarmSwitchService proEconAlarmSwitchService;

    @Resource
    private ProEconAlarmSwitchMapper proEconAlarmSwitchMapper;



    public boolean saveAndUpdateAlertrule(ProEconAlarmSwitch alarmRule) throws Exception {

        boolean result =false;

        if (StringUtils.notEmp(alarmRule)) {


            if (StringUtils.notEmp(alarmRule.getId())) {
                  result = proEconAlarmSwitchService.updateById(alarmRule);

            }else
            {
                alarmRule.setId(String.valueOf(SnowflakeGenerator.generateId()));
                result = proEconAlarmSwitchService.save(alarmRule);
            }

        }else
        {
            alarmRule.setId(String.valueOf(SnowflakeGenerator.generateId()));
            result = proEconAlarmSwitchService.save(alarmRule);
        }

        return result;
    }

    public boolean deleteAlertrule(String id) {
        return proEconAlarmSwitchService.removeById(id);
    }



    public List<ProEconAlarmSwitch> queryAll() {

        QueryWrapper<ProEconAlarmSwitch> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("alarm_level");
        List<ProEconAlarmSwitch> vos=proEconAlarmSwitchMapper.selectList(queryWrapper);

        return vos;
    }
}
