Commit fc85e8b2 authored by 李秀明's avatar 李秀明

feat: 系统图支持拖设备绑定多个测点

parent c6eaf6fb
package com.yeejoin.equipmanage.listener; package com.yeejoin.equipmanage.listener;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.sun.org.apache.xpath.internal.operations.Bool; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex; import com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex;
import com.yeejoin.equipmanage.common.enums.ConfigPageTopicEnum; import com.yeejoin.equipmanage.common.enums.ConfigPageTopicEnum;
import com.yeejoin.equipmanage.service.IEquipmentSpecificIndexSerivce; import com.yeejoin.equipmanage.service.IEquipmentSpecificIndexSerivce;
import com.yeejoin.equipmanage.service.IEquipmentSpecificSerivce;
import com.yeejoin.equipmanage.service.IFireFightingSystemService; import com.yeejoin.equipmanage.service.IFireFightingSystemService;
import javafx.concurrent.Task;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.sis.util.Static;
import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage; import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.json.JSONString;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.component.emq.EmqKeeper; import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.component.emq.EmqxListener; import org.typroject.tyboot.component.emq.EmqxListener;
import java.sql.Time;
import java.util.*; import java.util.*;
import java.util.concurrent.ScheduledExecutorService; import java.util.stream.Collectors;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/** /**
* @author DELL * @author DELL
*/ */
@Component
@Slf4j @Slf4j
@Component
public class IntegratePageDataListener extends EmqxListener { public class IntegratePageDataListener extends EmqxListener {
@Autowired @Autowired
IFireFightingSystemService fireFightingSystemService; IFireFightingSystemService fireFightingSystemService;
@Autowired
IEquipmentSpecificSerivce equipmentSpecificService;
@Autowired @Autowired
IEquipmentSpecificIndexSerivce equipmentSpecificIndexSerivce; IEquipmentSpecificIndexSerivce equipmentSpecificIndexService;
@Autowired @Autowired
EmqKeeper emqKeeper; EmqKeeper emqKeeper;
private boolean initialized = Boolean.TRUE;
@Override @Override
public void processMessage(String topic, MqttMessage message) throws Exception { public void processMessage(String topic, MqttMessage message) throws Exception {
if(log.isInfoEnabled()){ if (log.isInfoEnabled()) {
log.info("收到消息主题:{},消息内容:{}",topic, message.toString()); log.info("收到消息主题:{},消息内容:{}", topic, message.toString());
} }
Map msg = JSON.parseObject(message.toString()); Map<String, Object> msg = JSON.parseObject(message.toString());
Timer timer = new Timer(); if (msg.containsKey("request")) {
if(msg.containsKey("request")){ String split = "/";
String split = "/"; if (topic.contains(split)) {
if(topic.contains(split)){
String code = topic.substring(topic.indexOf(split) + 1); String code = topic.substring(topic.indexOf(split) + 1);
fireFightingSystemService.integrationPageSysData(code, false); fireFightingSystemService.integrationPageSysData(code, false);
} }
} else if (ConfigPageTopicEnum.SYSTEMDETAIL.getTopic().equalsIgnoreCase(topic) && initialized) { } else if (ConfigPageTopicEnum.SYSTEMDETAIL.getTopic().equalsIgnoreCase(topic)) {
if (!ObjectUtils.isEmpty(msg.get("codes"))) { this.initializeIntegrationPageData(topic, msg);
List<String> list = JSON.parseArray(String.valueOf(msg.get("codes")), String.class); }
list.parallelStream().forEach(x -> { }
EquipmentSpecificIndex indexEntity = equipmentSpecificIndexSerivce.getById(x);
Map<String, String> map = new HashMap<>(); private void initializeIntegrationPageData(String topic, Map<String, Object> message) {
map.put("code", String.valueOf(indexEntity.getId())); Object multiIndicator = message.get("multiIndicator");
map.put("value", indexEntity.getValue()); Object codes = message.get("codes");
map.put("status", indexEntity.getValue());
try { if (ObjectUtils.isEmpty(codes)) {
emqKeeper.getMqttClient().publish(topic, JSON.toJSONString(map).getBytes(), 1, false); return;
} catch (MqttException e) { }
e.printStackTrace();
} // 判断是否是设备绑定多测点
}); boolean isDeviceBindMultiIndicator = Objects.nonNull(multiIndicator) && Boolean.parseBoolean(String.valueOf(multiIndicator));
List<String> ids = JSON.parseArray(String.valueOf(codes), String.class);
// 设备绑定多测点:codes为"equipment_specific_id"
if (isDeviceBindMultiIndicator) {
List<EquipmentSpecificIndex> indices = equipmentSpecificIndexService.list(
Wrappers.<EquipmentSpecificIndex>lambdaQuery()
.select(EquipmentSpecificIndex::getEquipmentSpecificId, EquipmentSpecificIndex::getEquipmentIndexKey, EquipmentSpecificIndex::getValue)
.in(EquipmentSpecificIndex::getEquipmentSpecificId, ids)
.isNotNull(EquipmentSpecificIndex::getValue)
.ne(EquipmentSpecificIndex::getValue, "false")
.ne(EquipmentSpecificIndex::getValue, "")
.orderByDesc(EquipmentSpecificIndex::getEmergencyLevel)
);
Map<Long, List<EquipmentSpecificIndex>> groupedIndices = indices.stream().collect(Collectors.groupingBy(EquipmentSpecificIndex::getEquipmentSpecificId));
JSONObject emqMessage;
for (Map.Entry<Long, List<EquipmentSpecificIndex>> entry : groupedIndices.entrySet()) {
Long equipmentSpecificId = entry.getKey();
List<EquipmentSpecificIndex> valuedIndexes = entry.getValue();
List<HashMap<String, String>> indexKey = valuedIndexes.stream().map(index -> new HashMap<String, String>() {{
put("key", index.getEquipmentIndexKey());
put("value", index.getValue());
}}).collect(Collectors.toList());
emqMessage = new JSONObject() {{
this.put("code", String.valueOf(equipmentSpecificId));
this.put("indexKey", indexKey);
}};
try {
emqKeeper.getMqttClient().publish(topic, JSON.toJSONString(emqMessage).getBytes(), 1, false);
} catch (MqttException e) {
log.error("发布消息失败", e);
}
} }
initialized = Boolean.FALSE;
} }
// 单测点:codes为"equipment_specific_index_id"
else {
List<EquipmentSpecificIndex> indices = equipmentSpecificIndexService.list(
Wrappers.<EquipmentSpecificIndex>lambdaQuery()
.select(EquipmentSpecificIndex::getId, EquipmentSpecificIndex::getEquipmentIndexKey, EquipmentSpecificIndex::getValue)
.in(EquipmentSpecificIndex::getId, ids)
);
JSONObject emqMessage;
for (EquipmentSpecificIndex index : indices) {
emqMessage = new JSONObject() {{
this.put("code", String.valueOf(index.getId()));
this.put("value", index.getValue());
this.put("status", index.getValue());
}};
TimerTask timerTask = new TimerTask() { try {
@Override emqKeeper.getMqttClient().publish(topic, JSON.toJSONString(emqMessage).getBytes(), 1, false);
public void run() { } catch (MqttException e) {
initialized = Boolean.TRUE; log.error("发布消息失败", e);
} }
}; }
timer.schedule(timerTask, 3000); }
} }
} }
...@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray; ...@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey; import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils; import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.component.influxdb.InfluxDbConnection; import com.yeejoin.amos.component.influxdb.InfluxDbConnection;
...@@ -2686,12 +2687,26 @@ public class MqttReceiveServiceImpl implements MqttReceiveService { ...@@ -2686,12 +2687,26 @@ public class MqttReceiveServiceImpl implements MqttReceiveService {
} }
} }
private void pushDataToIntegrationPage(List<EquipmentSpecificIndex> specificIndices) {
@Async
public void pushDataToIntegrationPage(List<EquipmentSpecificIndex> specificIndices) {
for (EquipmentSpecificIndex specificIndex : specificIndices) { for (EquipmentSpecificIndex specificIndex : specificIndices) {
Long equipmentSpecificId = specificIndex.getEquipmentSpecificId();
List<EquipmentSpecificIndex> equipmentSpecificIndices = equipmentSpecificIndexMapper.selectList(
Wrappers.<EquipmentSpecificIndex>lambdaQuery()
.eq(EquipmentSpecificIndex::getEquipmentSpecificId, equipmentSpecificId)
.isNotNull(EquipmentSpecificIndex::getValue)
.ne(EquipmentSpecificIndex::getValue, "")
);
List<HashMap<String, String>> indexKey = equipmentSpecificIndices.stream().map(index -> new HashMap<String, String>() {{
put("key", index.getEquipmentIndexKey());
put("value", index.getValue());
}}).collect(Collectors.toList());
JSONObject message = new JSONObject() {{ JSONObject message = new JSONObject() {{
put("code", String.valueOf(specificIndex.getId())); put("code", String.valueOf(specificIndex.getId()));
put("status", specificIndex.getValue()); put("status", specificIndex.getValue());
put("value", specificIndex.getValue()); put("value", specificIndex.getValue());
put("indexKey", indexKey);
}}; }};
mqttSendGateway.sendToMqtt(ConfigPageTopicEnum.SYSTEMDETAIL.getTopic(), message.toJSONString()); mqttSendGateway.sendToMqtt(ConfigPageTopicEnum.SYSTEMDETAIL.getTopic(), message.toJSONString());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment