RemoteAlarmService.java 4.39 KB
package cn.com.glsx.admin.modules.remote;

import cn.com.glsx.admin.modules.utils.StringUtil;
import cn.com.glsx.alarm.api.AlarmFeignClient;
import cn.com.glsx.alarm.services.model.*;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.glsx.plat.core.web.R;
import com.google.common.collect.Lists;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * AlarmFeignClient 服务的处理层
 *
 * @author yll
 */
@Slf4j
@Service
public class RemoteAlarmService {

    @Autowired
    private AlarmFeignClient alarmFeignClient;

    public Integer getPowerOffAlertCount(List<String> sns, String startTime, String endTime) {
        Integer powerOffAlertCount = 0;
        if (CollectionUtil.isEmpty(sns)) {
            return powerOffAlertCount;
        }

        PowerOffBo powerOffBo = new PowerOffBo();
        powerOffBo.setSns(sns);
        powerOffBo.setStartTime(startTime);
        powerOffBo.setEndTime(endTime);
        R<Integer> powerOffAlertCountR = alarmFeignClient.getPowerOffAlertCount(powerOffBo);
        powerOffAlertCount = powerOffAlertCountR.getData(Integer.class);
        if (powerOffAlertCount == null) {
            powerOffAlertCount = 0;
        }
        return powerOffAlertCount;
    }

    public Integer getTearDownAlarmCount(List<String> sns, String startTime, String endTime) {
        Integer tearDownAlarmCount = 0;
        if (CollectionUtil.isEmpty(sns)) {
            return tearDownAlarmCount;
        }

        TearDownBo tearDownBo = new TearDownBo();
        tearDownBo.setSns(sns);
        tearDownBo.setStartTime(startTime);
        tearDownBo.setEndTime(endTime);
        R<Integer> tearDownAlarmCountR = alarmFeignClient.getTearDownAlarmCount(tearDownBo);
        tearDownAlarmCount = tearDownAlarmCountR.getData(Integer.class);
        if (tearDownAlarmCount == null) {
            tearDownAlarmCount = 0;
        }
        return tearDownAlarmCount;
    }

    /**
     * 通过设备号获取报警类型获取报警数据
     *
     * @param sn 设备号
     * @return 最近一条报警数据
     */
    public List<CommonAlarmDto> listCommonAlarmDtoBySn(String sn, Integer alarmType) {
        CommonAlarmBo commonAlarmBo = new CommonAlarmBo();
        commonAlarmBo.setSnList(Lists.newArrayList(sn));
        // 只展示生效
        commonAlarmBo.setDelflag(0);
        commonAlarmBo.setAlarmType(alarmType);
        R<List<CommonAlarmDto>> searchR = alarmFeignClient.getTheLastThreeAlarms(commonAlarmBo);
        if (searchR.getCode() != 200 || !searchR.getMessage().equalsIgnoreCase("success")) {
            log.info(sn + "find fial.code:" + searchR.getCode() + ";message:" + searchR.getMessage());
            return null;
        }
        List<CommonAlarmDto> alarmList = searchR.getDataList(new TypeToken<List<CommonAlarmDto>>() {
        }.getType());
        return alarmList;
    }

    /**
     * 通过设备号统计警情数量
     *
     * @param snList    设备号集合
     * @param alarmType 警情类型
     * @return 警情数量
     */
    public Integer countAlarmRec(List<String> snList, Integer alarmType) {
        Integer countAlarmRecCount = 0;
        if (CollectionUtil.isEmpty(snList)) {
            return countAlarmRecCount;
        }
        AlarmTrackRecQueryDTO alarmTrackRecQueryDTO = new AlarmTrackRecQueryDTO();
        alarmTrackRecQueryDTO.setSns(snList);
        alarmTrackRecQueryDTO.setAlarmType(alarmType);
        R<Integer> countAlarmRecR = alarmFeignClient.countAlarmRec(alarmTrackRecQueryDTO);
        countAlarmRecCount = countAlarmRecR.getData(Integer.class);
        if (countAlarmRecCount == null) {
            countAlarmRecCount = 0;
        }
        return countAlarmRecCount;
    }

    public List<CommonAlarmDto> selectLatestAlarmOfEachType(List<String> snList) {
        R<List<CommonAlarmDto>> searchR = alarmFeignClient.selectLatestAlarmOfEachType(snList);
        if (searchR.getCode() != 200 || !searchR.getMessage().equalsIgnoreCase("success")) {
            log.info(JSON.toJSONString(snList) + "find final.code:" + searchR.getCode() + ";message:" + searchR.getMessage());
            return null;
        }
        List<CommonAlarmDto> alarmList = searchR.getDataList(new TypeToken<List<CommonAlarmDto>>() {
        }.getType());
        return alarmList;
    }
}