‘liusuyi’
2023-09-19 c9768346fc8bc1cc6326e06125deaf57ff423eaf
src/main/java/com/ard/alarm/stealelec/service/StealElecAlarmService.java
@@ -10,6 +10,7 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@@ -24,12 +25,15 @@
 */
@Slf4j(topic = "stealAlarm")
@Service
public class StealElecAlarmService{
public class StealElecAlarmService {
    @Resource
    RestTemplate restTemplate;
    @Value("${spring.stealelec.url}")
    private String stealElecUrl;
    List<String> tempList=new ArrayList<>();
    @Value("${spring.stealelec.enabled}")
    private Boolean enabled;
    List<String> tempList = new ArrayList<>();
    /**
     * @描述 获取api数据推送mqtt
     * @参数 []
@@ -39,9 +43,12 @@
     * @修改人和其它信息
     */
    @Async("alarm")
    @Scheduled(cron="0/5 * * * * ?")
    @Scheduled(cron = "0/5 * * * * ?")
    public void alarmHandler() {
        try {
            if (!enabled) {
                return;
            }
            String allAlarmData = restTemplate.getForObject(stealElecUrl, String.class);
            //剔除所有\符号
            String message = allAlarmData.replaceAll("\\\\", "");
@@ -60,11 +67,10 @@
                    String JSONStr = JSON.toJSONString(object);
                    //转成实体对象
                    ArdAlarmStealelec wd = JSON.parseObject(JSONStr, ArdAlarmStealelec.class);
                    if(tempList.contains(wd.getId()))
                    {
                    if (tempList.contains(wd.getId())) {
                        continue;
                    }
                    MqttConsumer.publish(2,false,"stealelec", JSON.toJSONString(wd));
                    MqttConsumer.publish(2, false, "stealelec", JSON.toJSONString(wd));
                    tempList.add(wd.getId());
                }
            }