| | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ard.alarm.stealelec.domain.ArdAlarmStealelec; |
| | | import com.ard.utils.http.HttpUtils; |
| | | import com.ard.utils.mqtt.MqttConsumer; |
| | | 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 org.springframework.web.client.RestTemplate; |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | */ |
| | | @Slf4j(topic = "stealAlarm") |
| | | @Service |
| | | public class StealElecAlarmService{ |
| | | @Resource |
| | | RestTemplate restTemplate; |
| | | public class StealElecAlarmService { |
| | | |
| | | @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 |
| | | * @参数 [] |
| | |
| | | * @修改人和其它信息 |
| | | */ |
| | | @Async("alarm") |
| | | // @Scheduled(cron="0/5 * * * * ?") |
| | | @Scheduled(cron = "0/5 * * * * ?") |
| | | public void alarmHandler() { |
| | | try { |
| | | String allAlarmData = restTemplate.getForObject(stealElecUrl, String.class); |
| | | if (!enabled) { |
| | | return; |
| | | } |
| | | String allAlarmData = HttpUtils.sendGet(stealElecUrl); |
| | | //剔除所有\符号 |
| | | String message = allAlarmData.replaceAll("\\\\", ""); |
| | | //剔除整个字符串首尾双引号 |
| | |
| | | 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()); |
| | | } |
| | | } |