‘liusuyi’
2024-03-15 53a5de311a6ea00c4f299d1ee855a816fd9dacb3
src/main/java/com/ard/alarm/stealelec/service/StealElecAlarmService.java
@@ -2,14 +2,16 @@
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ard.alarm.stealelec.config.StealElecConfiguration;
import com.ard.alarm.stealelec.domain.ArdAlarmStealelec;
import com.ard.utils.http.HttpUtils;
import com.ard.utils.mqtt.MqttConsumer;
import com.ard.utils.mqtt.MqttProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@@ -26,10 +28,8 @@
@Service
public class StealElecAlarmService {
    @Value("${spring.stealelec.url}")
    private String stealElecUrl;
    @Value("${spring.stealelec.enabled}")
    private Boolean enabled;
@Resource
    StealElecConfiguration stealElecConfig;
    List<String> tempList = new ArrayList<>();
    /**
@@ -44,10 +44,10 @@
    @Scheduled(cron = "0/5 * * * * ?")
    public void alarmHandler() {
        try {
            if (!enabled) {
            if (!stealElecConfig.getEnabled()) {
                return;
            }
            String allAlarmData = HttpUtils.sendGet(stealElecUrl);
            String allAlarmData = HttpUtils.sendGet(stealElecConfig.getUrl());
            //剔除所有\符号
            String message = allAlarmData.replaceAll("\\\\", "");
            //剔除整个字符串首尾双引号
@@ -68,7 +68,7 @@
                    if (tempList.contains(wd.getId())) {
                        continue;
                    }
                    MqttConsumer.publish(2, false, "stealelec", JSON.toJSONString(wd));
                    MqttProducer.publish(2, false, "stealelec", JSON.toJSONString(wd));
                    tempList.add(wd.getId());
                }
            }