package com.chinaitop.depot.intelligent.basicdata.service.impl;


import com.chinaitop.depot.intelligent.basicdata.mapper.AlarmPhoneMapper;
import com.chinaitop.depot.intelligent.basicdata.model.MonitorAlarmPhone;
import com.chinaitop.depot.intelligent.basicdata.model.MonitorAlarmPhoneExample;
import com.chinaitop.depot.intelligent.basicdata.service.AlarmService;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;


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

@Service
public class AlarmServiceImpl implements AlarmService {

    @Resource
    private AlarmPhoneMapper alarmPhoneMapper;

    @Override
    public List<MonitorAlarmPhone> getAlarmPhone(MonitorAlarmPhoneExample example) {
        return alarmPhoneMapper.selectByExample(example);
    }

    @Override
    public void saveAlarmPhone(MonitorAlarmPhone monitorSettingPath) {

        if (monitorSettingPath.getId() != null) {
            alarmPhoneMapper.updateByPrimaryKey(monitorSettingPath);
        } else {
            alarmPhoneMapper.insert(monitorSettingPath);
        }

    }

    @Override
    public void deleteAlarmPhone(Integer alarmId) {
        alarmPhoneMapper.deleteByPrimaryKey(alarmId);
    }

    @Override
    public List<MonitorAlarmPhone> getAllAlarmPhone() {
        MonitorAlarmPhoneExample example = new MonitorAlarmPhoneExample();
        return alarmPhoneMapper.selectByExample(example);
    }

    @Override
    public List<MonitorAlarmPhone> queryAlarmPhoneByOrgid(Integer orgid) {
        MonitorAlarmPhoneExample example = new MonitorAlarmPhoneExample();
        MonitorAlarmPhoneExample.Criteria criteria = example.createCriteria();
        if (orgid != null) {
            criteria.andDetectionTypeEqualTo("2");
            criteria.andOrgIdEqualTo(orgid);
            return alarmPhoneMapper.selectByExample(example);

        }
        return null;
    }

    @Override
    public MonitorAlarmPhone getByIdAlarmPhone(Integer alarmId) {
        MonitorAlarmPhone alarmPhone = alarmPhoneMapper.selectByPrimaryKey(alarmId);
        return alarmPhone;
    }

    @Override
    public boolean getByNameOrtpl(String alarmMan, String alarmPhone) {



        MonitorAlarmPhoneExample example = new MonitorAlarmPhoneExample();
        MonitorAlarmPhoneExample.Criteria criteria = example.createCriteria();

        if (StringUtils.isNotEmpty(alarmMan)) {
            criteria.andAlarmManEqualTo(alarmMan);
            criteria.andDetectionTypeEqualTo("2");

            }
            if (StringUtils.isNotEmpty(alarmPhone)) {
                criteria.andAlarmPhoneEqualTo(alarmPhone);
                criteria.andDetectionTypeEqualTo("2");
            }
            List<MonitorAlarmPhone> monitorAlarmPhones = alarmPhoneMapper.selectByExample(example);
            if (monitorAlarmPhones.size() > 0) {
                return true;
            }
                return false;


    }


}
