das接口修改
This commit is contained in:
parent
2d1594ea8c
commit
62aac9e519
@ -23,5 +23,7 @@ public interface SysEquipmentMapper extends BaseMapperPlus<SysEquipment, SysEqui
|
||||
|
||||
Long queryChildEquipmentCount(@Param("id")Long id);
|
||||
|
||||
void updateIotAddr(Long id, String iotAddr);
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,28 @@
|
||||
package com.das.modules.node.command;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.das.common.utils.AdminRedisTemplate;
|
||||
import com.das.modules.node.domain.bo.TerminalMessage;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AnalogDataCommand implements BaseCommand{
|
||||
public static final String YC_KEY_NAME = "RDB:YC:VALUES";
|
||||
|
||||
@Autowired
|
||||
AdminRedisTemplate adminRedisTemplate;
|
||||
@Override
|
||||
public void doCommand(TerminalMessage data) {
|
||||
JsonNode jsonNode = data.getData();
|
||||
Map<String, Object> values = Map.of(
|
||||
"deviceId", jsonNode.get("deviceId").asLong(),
|
||||
"dataTime", data.getTime(),
|
||||
"values", ListUtil.toList(jsonNode.get("value").asText())
|
||||
);
|
||||
adminRedisTemplate.set(YC_KEY_NAME, values);
|
||||
|
||||
// 存入td库
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,37 @@
|
||||
package com.das.modules.node.command;
|
||||
|
||||
import com.das.common.utils.AdminRedisTemplate;
|
||||
import com.das.common.utils.StringUtils;
|
||||
import com.das.modules.node.domain.bo.TerminalMessage;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class HeartbeatCommand implements BaseCommand{
|
||||
|
||||
@Autowired
|
||||
AdminRedisTemplate adminRedisTemplate;
|
||||
@Override
|
||||
public void doCommand(TerminalMessage data) {
|
||||
JsonNode dataInfo = data.getData();
|
||||
if (!dataInfo.isEmpty()) {
|
||||
JsonNode linkNode = data.getData().get("links");
|
||||
if (linkNode != null && linkNode.isArray()) {
|
||||
for (JsonNode fruitNode : linkNode) {
|
||||
String linkId = fruitNode.get("linkId").asText();
|
||||
String online = fruitNode.get("online").asText();
|
||||
|
||||
if (StringUtils.isEmpty(online)) {
|
||||
adminRedisTemplate.set(linkId, 0);
|
||||
} else {
|
||||
if ("true".equals(online)) {
|
||||
adminRedisTemplate.set(linkId, 1);
|
||||
} else {
|
||||
adminRedisTemplate.set(linkId, 0);
|
||||
}
|
||||
}
|
||||
adminRedisTemplate.expire(linkId, 300L);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,6 @@ import com.das.modules.node.domain.bo.TerminalMessage;
|
||||
public class HistoryStateDataCommand implements BaseCommand{
|
||||
@Override
|
||||
public void doCommand(TerminalMessage data) {
|
||||
|
||||
// 更新td数据库
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,27 @@
|
||||
package com.das.modules.node.command;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.das.common.utils.AdminRedisTemplate;
|
||||
import com.das.modules.node.domain.bo.TerminalMessage;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class StateDataCommand implements BaseCommand{
|
||||
|
||||
public static final String YM_KEY_NAME = "RDB:YM:VALUES";
|
||||
|
||||
@Autowired
|
||||
AdminRedisTemplate adminRedisTemplate;
|
||||
@Override
|
||||
public void doCommand(TerminalMessage data) {
|
||||
|
||||
JsonNode jsonNode = data.getData();
|
||||
Map<String, Object> values = Map.of(
|
||||
"deviceId", jsonNode.get("deviceId").asLong(),
|
||||
"dataTime", data.getTime(),
|
||||
"values", ListUtil.toList(jsonNode.get("value").asText())
|
||||
);
|
||||
adminRedisTemplate.set(YM_KEY_NAME, values);
|
||||
}
|
||||
}
|
||||
|
@ -6,14 +6,8 @@ import com.das.common.constant.SysAuthorityIds;
|
||||
import com.das.common.exceptions.ServiceException;
|
||||
import com.das.common.result.R;
|
||||
import com.das.common.utils.PageDataInfo;
|
||||
import com.das.modules.node.domain.dto.BindEquipmentDto;
|
||||
import com.das.modules.node.domain.dto.SysCommunicationLinkDto;
|
||||
import com.das.modules.node.domain.dto.SysImptabmappingDto;
|
||||
import com.das.modules.node.domain.dto.SysNodeDto;
|
||||
import com.das.modules.node.domain.vo.ProtocolTypeVo;
|
||||
import com.das.modules.node.domain.vo.SysCommunicationLinkVo;
|
||||
import com.das.modules.node.domain.vo.SysImptabmappingVo;
|
||||
import com.das.modules.node.domain.vo.SysNodeVo;
|
||||
import com.das.modules.node.domain.dto.*;
|
||||
import com.das.modules.node.domain.vo.*;
|
||||
import com.das.modules.node.service.SysNodeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -165,7 +159,7 @@ public class SysNodeController {
|
||||
if (sysImptabmappingDto.getLinkId() == null) {
|
||||
throw new ServiceException("参数缺失");
|
||||
}
|
||||
List<SysImptabmappingVo> list = sysNodeService.getMappingList(sysImptabmappingDto.getLinkId());
|
||||
List<ImptabmappingVo> list = sysNodeService.getMappingList(sysImptabmappingDto);
|
||||
return R.success(list);
|
||||
}
|
||||
|
||||
@ -197,5 +191,18 @@ public class SysNodeController {
|
||||
sysNodeService.bindDeviceMeas(bindEquipmentDto.getEquipmentId(), bindEquipmentDto.getLinkId());
|
||||
return R.success();
|
||||
}
|
||||
|
||||
/** 保存测点信息 */
|
||||
@PostMapping("/link/saveMappingList")
|
||||
public R<Void> saveMappingList(@RequestBody List<ImptabmappingDto> impList) {
|
||||
|
||||
//判断是否有权限
|
||||
boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_DEVICE_MGR.toString());
|
||||
if(!hasPermission){
|
||||
return R.fail("没有节点管理权限");
|
||||
}
|
||||
sysNodeService.saveMappingList(impList);
|
||||
return R.success();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.das.modules.node.domain.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@ -7,7 +9,8 @@ import java.util.List;
|
||||
@Data
|
||||
public class BindEquipmentDto {
|
||||
|
||||
private List<Long> equipmentId;
|
||||
private List<BindEquipmentInfoDto> equipmentId;
|
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long linkId;
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.das.modules.node.domain.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class BindEquipmentInfoDto {
|
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long equipmentId;
|
||||
|
||||
private String iotAddr;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.das.modules.node.domain.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ImptabmappingDto implements Serializable {
|
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long linkId;
|
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long equipmentId;
|
||||
|
||||
private Integer type;
|
||||
|
||||
private Object params;
|
||||
}
|
@ -11,4 +11,6 @@ public class SysImptabmappingDto implements Serializable {
|
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long linkId;
|
||||
|
||||
private Integer type;
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package com.das.modules.node.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ConfigUpdateVo {
|
||||
|
||||
public Integer version;
|
||||
|
||||
private Long createTime;
|
||||
|
||||
private String nodeId;
|
||||
|
||||
private List<LinkVo> links;
|
||||
|
||||
private List equipments;
|
||||
|
||||
public ConfigUpdateVo() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.das.modules.node.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class EquipmentVo {
|
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
private String addr;
|
||||
|
||||
private List<IotModelVo> attrs;
|
||||
|
||||
private List<IotModelVo> services;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.das.modules.node.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* 映射表前端回显
|
||||
*
|
||||
* @author guchengwei
|
||||
*/
|
||||
@Data
|
||||
public class ImptabmappingVo {
|
||||
|
||||
private String name;
|
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long equipmentId;
|
||||
|
||||
private String equipmentName;
|
||||
private Integer porder;
|
||||
|
||||
private String params;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.das.modules.node.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* 映射表前端回显
|
||||
*
|
||||
* @author guchengwei
|
||||
*/
|
||||
@Data
|
||||
public class IotModelVo {
|
||||
|
||||
private String name;
|
||||
|
||||
private String type;
|
||||
|
||||
private Object params;
|
||||
}
|
20
das/src/main/java/com/das/modules/node/domain/vo/LinkVo.java
Normal file
20
das/src/main/java/com/das/modules/node/domain/vo/LinkVo.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.das.modules.node.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LinkVo {
|
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long linkId;
|
||||
|
||||
private String linkName;
|
||||
//协议号
|
||||
private Integer protocol;
|
||||
//协议参数
|
||||
private Object params;
|
||||
|
||||
private String[] devices;
|
||||
}
|
@ -30,7 +30,7 @@ public class SysCommunicationLinkVo {
|
||||
/**
|
||||
* 协议参数
|
||||
*/
|
||||
private String params;
|
||||
private Object params;
|
||||
|
||||
/**
|
||||
* 所属系统节点
|
||||
|
@ -61,7 +61,7 @@ public class SysImptabmapping extends BaseEntity {
|
||||
/**
|
||||
* 对应设备服务
|
||||
*/
|
||||
@TableField("equipmentService")
|
||||
@TableField("equipment_service")
|
||||
private String equipmentService;
|
||||
|
||||
@TableField("porder")
|
||||
|
@ -32,6 +32,7 @@ public class NodeMessageHandler extends TextWebSocketHandler {
|
||||
String remoteIp = (String) session.getAttributes().getOrDefault(NodeConstant.REMOTE_IP, "");
|
||||
Long nodeId = (Long)session.getAttributes().get(NodeConstant.NODE_ID);
|
||||
Long version = (Long)session.getAttributes().get(NodeConstant.VERSION);
|
||||
long time = System.currentTimeMillis();
|
||||
log.debug("IP: {} 请求连接. sessionId: {}", remoteIp, session.getId());
|
||||
if (onlineSessions.containsKey(nodeId)){
|
||||
//如果终端节点已在线,则拒绝新的终端连接
|
||||
@ -51,12 +52,11 @@ public class NodeMessageHandler extends TextWebSocketHandler {
|
||||
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
|
||||
TerminalMessage msg = JsonUtils.parseObject(message.getPayload(), TerminalMessage.class);
|
||||
String nodeId = session.getAttributes().get(NodeConstant.NODE_ID).toString();
|
||||
String version = session.getAttributes().get(NodeConstant.VERSION).toString();
|
||||
Long version = (Long)session.getAttributes().get(NodeConstant.VERSION);
|
||||
String cmdId = msg.getCmdId();
|
||||
String cmd = msg.getCmd();
|
||||
long time = msg.getTime();
|
||||
JsonNode data = msg.getData();
|
||||
// 如果version是0,则需要调用一次configUpdate配置更新
|
||||
log.info("收到 Node:{} 命令: {}", nodeId, cmd);
|
||||
log.debug("内容: {}", data.toString());
|
||||
if (dataService == null){
|
||||
@ -65,6 +65,17 @@ public class NodeMessageHandler extends TextWebSocketHandler {
|
||||
if (dataService != null){
|
||||
dataService.pushMessage(msg);
|
||||
}
|
||||
// 如果version是0,则需要调用一次configUpdate配置更新
|
||||
if (version == 0){
|
||||
JsonNode configUpdateData = dataService.getConfigUpdateInfo(Long.valueOf(nodeId));
|
||||
TerminalMessage configUpdate = TerminalMessage.builder()
|
||||
.cmd("configUpdate")
|
||||
.cmdId(nodeId)
|
||||
.time(time)
|
||||
.data(configUpdateData)
|
||||
.build();
|
||||
sendActionMessage(Long.valueOf(nodeId), configUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -136,7 +147,8 @@ public class NodeMessageHandler extends TextWebSocketHandler {
|
||||
WebSocketSession session = onlineSessions.get(nodeId);
|
||||
if (session != null){
|
||||
try {
|
||||
session.sendMessage(new TextMessage(message.toString()));
|
||||
session.sendMessage(new TextMessage(message.toJsonString()));
|
||||
log.info("发送的消息为:{}", message.toJsonString());
|
||||
}
|
||||
catch (Exception exception){
|
||||
log.error(String.format("发送消息失败: NodeId: %s", nodeId), exception);
|
||||
|
@ -9,10 +9,14 @@ import com.das.modules.node.entity.SysCommunicationLink;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysCommunicationLinkMapper extends BaseMapper<SysCommunicationLink> {
|
||||
IPage<SysCommunicationLinkVo> querySysCommunicationLinkList(IPage<SysCommunicationLinkVo> page, @Param("info") SysCommunicationLinkDto sysCommunicationLinkDto);
|
||||
|
||||
Long querySysCommunicationLinkCount(@Param("nodeId") Long nodeId);
|
||||
|
||||
List<SysCommunicationLinkVo> querySysCommunicationLink(@Param("nodeId") Long nodeId);
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.das.modules.auth.mapper.BaseMapperPlus;
|
||||
import com.das.modules.node.domain.dto.SysCommunicationLinkDto;
|
||||
import com.das.modules.node.domain.vo.ImptabmappingVo;
|
||||
import com.das.modules.node.domain.vo.IotModelVo;
|
||||
import com.das.modules.node.domain.vo.SysCommunicationLinkVo;
|
||||
import com.das.modules.node.domain.vo.SysImptabmappingVo;
|
||||
import com.das.modules.node.entity.SysCommunicationLink;
|
||||
@ -16,9 +18,23 @@ import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysImptabmappingMapper extends BaseMapperPlus<SysImptabmapping, SysImptabmapping> {
|
||||
List<SysImptabmappingVo> getMappingList(Long linkId);
|
||||
List<ImptabmappingVo> getMappingList(Long linkId, Integer type);
|
||||
|
||||
List<ImptabmappingVo> getMappingControlList(Long linkId, Integer type);
|
||||
|
||||
List<SysImptabmappingVo> getBindDevice(Long linkId);
|
||||
|
||||
void deleteBindDevice(Long linkId);
|
||||
|
||||
List<Long> getEquipmentId(Long linkId);
|
||||
|
||||
List<IotModelVo> getIotModelFieldByEquipmentId(Long equipmentId);
|
||||
|
||||
List<IotModelVo> getIotModelServiceByEquipmentId(Long equipmentId);
|
||||
|
||||
String getIotAddrByEquipmentId(Long equipmentId);
|
||||
|
||||
String getAttributeCode(Long equipmentId, Integer type);
|
||||
|
||||
String getServiceCode(Long equipmentId, Integer type);
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.das.modules.node.service;
|
||||
|
||||
import com.das.modules.node.domain.bo.TerminalMessage;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
public interface DataService {
|
||||
|
||||
void pushMessage(TerminalMessage msg);
|
||||
|
||||
JsonNode getConfigUpdateInfo(Long nodeId);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.das.modules.node.service;
|
||||
|
||||
import com.das.common.utils.PageDataInfo;
|
||||
import com.das.modules.node.domain.dto.SysCommunicationLinkDto;
|
||||
import com.das.modules.node.domain.dto.SysNodeDto;
|
||||
import com.das.modules.node.domain.dto.*;
|
||||
import com.das.modules.node.domain.vo.ImptabmappingVo;
|
||||
import com.das.modules.node.domain.vo.SysCommunicationLinkVo;
|
||||
import com.das.modules.node.domain.vo.SysImptabmappingVo;
|
||||
import com.das.modules.node.domain.vo.SysNodeVo;
|
||||
@ -26,9 +26,10 @@ public interface SysNodeService {
|
||||
|
||||
void deleteSysCommunicationLink(Long id);
|
||||
|
||||
List<SysImptabmappingVo> getMappingList(Long linkId);
|
||||
List<ImptabmappingVo> getMappingList(SysImptabmappingDto sysImptabmappingDto);
|
||||
|
||||
List<SysImptabmappingVo> getBindDeviceTree(Long linkId);
|
||||
void bindDeviceMeas(List<Long> equipmentId, Long linkId);
|
||||
void bindDeviceMeas(List<BindEquipmentInfoDto> equipmentId, Long linkId);
|
||||
|
||||
void saveMappingList(List<ImptabmappingDto> impList);
|
||||
}
|
||||
|
@ -3,7 +3,12 @@ package com.das.modules.node.service.impl;
|
||||
import com.das.modules.node.disruptor.MessageEventFactory;
|
||||
import com.das.modules.node.disruptor.TerminalMessageEventHandler;
|
||||
import com.das.modules.node.domain.bo.TerminalMessage;
|
||||
import com.das.modules.node.domain.vo.*;
|
||||
import com.das.modules.node.mapper.SysCommunicationLinkMapper;
|
||||
import com.das.modules.node.mapper.SysImptabmappingMapper;
|
||||
import com.das.modules.node.service.DataService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.lmax.disruptor.RingBuffer;
|
||||
import com.lmax.disruptor.dsl.Disruptor;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
@ -11,7 +16,11 @@ import jakarta.annotation.PreDestroy;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@ -25,6 +34,12 @@ public class DataServiceImpl implements DataService {
|
||||
@Resource
|
||||
TerminalMessageEventHandler terminalMessageEventHandler;
|
||||
|
||||
@Resource
|
||||
SysCommunicationLinkMapper sysCommunicationLinkMapper;
|
||||
|
||||
@Resource
|
||||
SysImptabmappingMapper sysImptabmappingMapper;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
//初始化高性能队列
|
||||
@ -66,4 +81,69 @@ public class DataServiceImpl implements DataService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode getConfigUpdateInfo(Long nodeId) {
|
||||
ConfigUpdateVo configUpdateVo = new ConfigUpdateVo();
|
||||
List<LinkVo> links = new ArrayList<>();
|
||||
List<EquipmentVo> equipments = new ArrayList<>();
|
||||
List<Long> equipmentList = new ArrayList<>();
|
||||
// 获取所有的链路信息
|
||||
List<SysCommunicationLinkVo> sysCommunicationLinkVoList = sysCommunicationLinkMapper.querySysCommunicationLink(nodeId);
|
||||
for (SysCommunicationLinkVo sysCommunicationLinkVo : sysCommunicationLinkVoList) {
|
||||
LinkVo linkVo = new LinkVo();
|
||||
linkVo.setLinkId(sysCommunicationLinkVo.getId());
|
||||
linkVo.setLinkName(sysCommunicationLinkVo.getLinkName());
|
||||
linkVo.setParams(sysCommunicationLinkVo.getParams());
|
||||
linkVo.setProtocol(sysCommunicationLinkVo.getProtocol());
|
||||
List<String> stringList = new ArrayList<>();
|
||||
// 获取关联的设备Id
|
||||
equipmentList = sysImptabmappingMapper.getEquipmentId(sysCommunicationLinkVo.getId());
|
||||
for (Long equipmentId : equipmentList) {
|
||||
stringList.add(String.valueOf(equipmentId));
|
||||
}
|
||||
String[] stringArray = stringList.toArray(new String[0]);
|
||||
linkVo.setDevices(stringArray);
|
||||
links.add(linkVo);
|
||||
}
|
||||
for (Long equipmentId : equipmentList) {
|
||||
List<IotModelVo> newIotModelFieldList = new ArrayList<>();
|
||||
List<IotModelVo> newIotModelServiceList = new ArrayList<>();
|
||||
// 获取设备IOT地址
|
||||
String iotAddr = sysImptabmappingMapper.getIotAddrByEquipmentId(equipmentId);
|
||||
// 根据设备Id获取对应的物模型属性和动作
|
||||
List<IotModelVo> iotModelFieldList = sysImptabmappingMapper.getIotModelFieldByEquipmentId(equipmentId);
|
||||
if (!CollectionUtils.isEmpty(iotModelFieldList)) {
|
||||
for (IotModelVo info : iotModelFieldList) {
|
||||
if(info.getParams() != null){
|
||||
// info.setParams();
|
||||
}
|
||||
newIotModelFieldList.add(info);
|
||||
}
|
||||
}
|
||||
List<IotModelVo> iotModelServiceList = sysImptabmappingMapper.getIotModelServiceByEquipmentId(equipmentId);
|
||||
if (!CollectionUtils.isEmpty(iotModelServiceList)) {
|
||||
for (IotModelVo info : iotModelServiceList) {
|
||||
// if(!StringUtils.hasText(info.getParams())){
|
||||
// info.setParams("{}");
|
||||
// }
|
||||
newIotModelServiceList.add(info);
|
||||
}
|
||||
}
|
||||
EquipmentVo equipment = new EquipmentVo();
|
||||
equipment.setAddr(iotAddr);
|
||||
equipment.setId(equipmentId);
|
||||
equipment.setAttrs(newIotModelFieldList);
|
||||
equipment.setServices(newIotModelServiceList);
|
||||
equipments.add(equipment);
|
||||
}
|
||||
configUpdateVo.setCreateTime(System.currentTimeMillis());
|
||||
configUpdateVo.setNodeId(String.valueOf(nodeId));
|
||||
configUpdateVo.setVersion(1);
|
||||
configUpdateVo.setLinks(links);
|
||||
configUpdateVo.setEquipments(equipments);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode jsonNode = mapper.valueToTree(configUpdateVo);
|
||||
return jsonNode;
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,9 @@ import com.das.common.utils.SequenceUtils;
|
||||
import com.das.modules.auth.domain.vo.SysUserVo;
|
||||
import com.das.modules.auth.entity.SysOrg;
|
||||
import com.das.modules.auth.mapper.SysOrgMapper;
|
||||
import com.das.modules.node.domain.dto.SysCommunicationLinkDto;
|
||||
import com.das.modules.node.domain.dto.SysNodeDto;
|
||||
import com.das.modules.equipment.mapper.SysEquipmentMapper;
|
||||
import com.das.modules.node.domain.dto.*;
|
||||
import com.das.modules.node.domain.vo.ImptabmappingVo;
|
||||
import com.das.modules.node.domain.vo.SysCommunicationLinkVo;
|
||||
import com.das.modules.node.domain.vo.SysImptabmappingVo;
|
||||
import com.das.modules.node.domain.vo.SysNodeVo;
|
||||
@ -48,6 +49,9 @@ public class SysNodeServiceImpl implements SysNodeService {
|
||||
@Autowired
|
||||
private SysImptabmappingMapper sysImptabmappingMapper;
|
||||
|
||||
@Autowired
|
||||
private SysEquipmentMapper sysEquipmentMapper;
|
||||
|
||||
@Override
|
||||
public List<SysNodeVo> querySysNodeList() {
|
||||
List<SysNodeVo> sysNodeVoList = sysNodeMapper.querySysNodeList();
|
||||
@ -157,8 +161,16 @@ public class SysNodeServiceImpl implements SysNodeService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysImptabmappingVo> getMappingList(Long linkId) {
|
||||
List<SysImptabmappingVo> list = sysImptabmappingMapper.getMappingList(linkId);
|
||||
public List<ImptabmappingVo> getMappingList(SysImptabmappingDto sysImptabmappingDto) {
|
||||
// 138模拟量 139累积量 140离散量 146遥调 147遥控
|
||||
Integer type = sysImptabmappingDto.getType();
|
||||
List<ImptabmappingVo> list = new ArrayList<>();
|
||||
if (type == 138 || type == 139 || type == 140) {
|
||||
list = sysImptabmappingMapper.getMappingList(sysImptabmappingDto.getLinkId(), type);
|
||||
}else if (type == 146 || type == 147) {
|
||||
list = sysImptabmappingMapper.getMappingControlList(sysImptabmappingDto.getLinkId(), type);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -169,7 +181,7 @@ public class SysNodeServiceImpl implements SysNodeService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindDeviceMeas(List<Long> equipmentId, Long linkId) {
|
||||
public void bindDeviceMeas(List<BindEquipmentInfoDto> equipmentId, Long linkId) {
|
||||
List<SysImptabmapping> addList = new ArrayList<>();
|
||||
//获取已经绑定的设备
|
||||
List<SysImptabmappingVo> bindDeviceList = sysImptabmappingMapper.getBindDevice(linkId);
|
||||
@ -187,10 +199,48 @@ public class SysNodeServiceImpl implements SysNodeService {
|
||||
|
||||
}
|
||||
|
||||
private static void addSysImptabmapping(List<Long> equipmentId, Long linkId, SysUserVo sysUserVo, List<SysImptabmapping> addList) {
|
||||
for (int i = 0; i< equipmentId.size(); i++) {
|
||||
@Override
|
||||
public void saveMappingList(List<ImptabmappingDto> impList) {
|
||||
if (!CollectionUtils.isEmpty(impList)) {
|
||||
List<SysImptabmapping> list = new ArrayList<>();
|
||||
int index = 0;
|
||||
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
|
||||
for (ImptabmappingDto imp : impList) {
|
||||
SysImptabmapping sysImptabmapping = new SysImptabmapping();
|
||||
if (imp.getType() == 138 || imp.getType() == 139 || imp.getType() == 140) {
|
||||
// 获取属性编码
|
||||
String code = sysImptabmappingMapper.getAttributeCode(imp.getEquipmentId(), imp.getType());
|
||||
sysImptabmapping.setEquipmentAttribute(code);
|
||||
}else if (imp.getType() == 146 || imp.getType() == 147) {
|
||||
// 获取动作编码
|
||||
String code = sysImptabmappingMapper.getServiceCode(imp.getEquipmentId(), imp.getType());
|
||||
sysImptabmapping.setEquipmentService(code);
|
||||
}
|
||||
index++;
|
||||
sysImptabmapping.setCreatedTime(new Date());
|
||||
sysImptabmapping.setUpdatedTime(new Date());
|
||||
sysImptabmapping.setCreatedBy(sysUserVo.getAccount());
|
||||
sysImptabmapping.setUpdatedBy(sysUserVo.getAccount());
|
||||
sysImptabmapping.setLinkId(imp.getLinkId());
|
||||
sysImptabmapping.setEquipmentId(imp.getEquipmentId());
|
||||
sysImptabmapping.setId(SequenceUtils.generateId());
|
||||
sysImptabmapping.setPorder(index);
|
||||
sysImptabmapping.setParams(String.valueOf(imp.getParams()));
|
||||
sysImptabmapping.setRevision(1);
|
||||
list.add(sysImptabmapping);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(list)){
|
||||
sysImptabmappingMapper.insertBatch(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addSysImptabmapping(List<BindEquipmentInfoDto> equipmentId, Long linkId, SysUserVo sysUserVo, List<SysImptabmapping> addList) {
|
||||
int index = 0;
|
||||
for (BindEquipmentInfoDto info : equipmentId) {
|
||||
index++;
|
||||
SysImptabmapping sysImptabmapping = new SysImptabmapping();
|
||||
sysImptabmapping.setEquipmentId(equipmentId.get(i));
|
||||
sysImptabmapping.setEquipmentId(info.getEquipmentId());
|
||||
sysImptabmapping.setLinkId(linkId);
|
||||
sysImptabmapping.setId(SequenceUtils.generateId());
|
||||
sysImptabmapping.setCreatedTime(new Date());
|
||||
@ -198,8 +248,10 @@ public class SysNodeServiceImpl implements SysNodeService {
|
||||
sysImptabmapping.setCreatedBy(sysUserVo.getAccount());
|
||||
sysImptabmapping.setUpdatedBy(sysUserVo.getAccount());
|
||||
sysImptabmapping.setRevision(1);
|
||||
sysImptabmapping.setPorder(i + 1);
|
||||
sysImptabmapping.setPorder(index);
|
||||
addList.add(sysImptabmapping);
|
||||
// 更新设备表里面的设备地址
|
||||
sysEquipmentMapper.updateIotAddr(info.getEquipmentId(), info.getIotAddr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,8 @@
|
||||
select count(1) from sys_communicationlink sc where sc.node_id = #{nodeId}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="querySysCommunicationLink" resultType="com.das.modules.node.domain.vo.SysCommunicationLinkVo">
|
||||
select sc.id,sc.link_name,sc.protocol,to_json(sc.params::json) AS params from sys_communicationlink sc where sc.node_id = #{nodeId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
@ -111,5 +111,9 @@
|
||||
select count(1) from sys_equipment where parent_equipment_id = #{id}
|
||||
</select>
|
||||
|
||||
<update id="updateIotAddr" >
|
||||
update sys_equipment set iot_addr = #{iotAddr} where id = #{id}
|
||||
</update>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
@ -15,9 +15,32 @@
|
||||
<result property="revision" column="revision" jdbcType="INTEGER"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="getMappingList" resultMap="SysImptabmappingMap">
|
||||
select si.*, sc.link_name as linkName, se."name" as equipmentName from sys_imptabmapping si left join sys_communicationlink sc on si.link_id = sc.id
|
||||
left join sys_equipment se on si.equipment_id = se.id where si.link_id = #{linkId}
|
||||
<resultMap type="com.das.modules.node.domain.vo.ImptabmappingVo" id="ImptabmappingMap">
|
||||
<result property="equipmentName" column="equipmentName" jdbcType="VARCHAR"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="equipmentId" column="equipment_id" jdbcType="BIGINT"/>
|
||||
<result property="params" column="params" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.das.modules.node.domain.vo.IotModelVo" id="IotModelMap">
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="type" column="type" jdbcType="VARCHAR"/>
|
||||
<result property="params" column="params" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="getMappingList" resultMap="ImptabmappingMap">
|
||||
select se."name" as equipmentName, simf.attribute_name as name,si.params,se.id as equipment_id from sys_imptabmapping si
|
||||
left join sys_equipment se on si.equipment_id = se.id
|
||||
left join sys_iot_model_field simf on se.iot_model_id = simf.iot_model_id
|
||||
where si.link_id = #{linkId} and simf.attribute_type = #{type}
|
||||
order by si.porder
|
||||
</select>
|
||||
|
||||
<select id="getMappingControlList" resultMap="ImptabmappingMap">
|
||||
select se."name" as equipmentName, sims.service_name as name,si.params,se.id as equipment_id from sys_imptabmapping si
|
||||
left join sys_equipment se on si.equipment_id = se.id
|
||||
left join sys_iot_model_service sims on se.iot_model_id = sims.iot_model_id
|
||||
where si.link_id = #{linkId} and sims.service_type = #{type}
|
||||
order by si.porder
|
||||
</select>
|
||||
|
||||
@ -33,7 +56,41 @@
|
||||
</delete>
|
||||
|
||||
|
||||
<select id="getEquipmentId" resultType="java.lang.Long">
|
||||
select si.equipment_id from sys_imptabmapping si
|
||||
left join sys_communicationlink sc on sc.id = si.link_id
|
||||
where sc.id = #{linkId}
|
||||
</select>
|
||||
|
||||
<select id="getIotModelFieldByEquipmentId" resultType="com.das.modules.node.domain.vo.IotModelVo">
|
||||
select simf.attribute_name as name,simf.attribute_type as type,to_json(si.params::json) as params from sys_imptabmapping si
|
||||
left join sys_equipment se on si.equipment_id = se.id
|
||||
left join sys_iot_model_field simf on se.iot_model_id = simf.iot_model_id
|
||||
where si.equipment_id = #{equipmentId}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getIotModelServiceByEquipmentId" resultType="com.das.modules.node.domain.vo.IotModelVo">
|
||||
select sims.service_name as name ,sims.service_type as type ,to_json(si.params::json) AS params from sys_imptabmapping si
|
||||
left join sys_equipment se on si.equipment_id = se.id
|
||||
left join sys_iot_model_service sims on se.iot_model_id = sims.iot_model_id
|
||||
where si.equipment_id = #{equipmentId}
|
||||
</select>
|
||||
|
||||
<select id="getIotAddrByEquipmentId" resultType="java.lang.String">
|
||||
select se.iot_addr from sys_equipment se where se.id = #{equipmentId}
|
||||
</select>
|
||||
|
||||
<select id="getAttributeCode" resultType="java.lang.String">
|
||||
select distinct simf.attribute_code from sys_iot_model_field simf
|
||||
left join sys_equipment se on simf.iot_model_id = se.iot_model_id
|
||||
where se.id = #{equipmentId} and simf.attribute_type = #{type}
|
||||
</select>
|
||||
|
||||
<select id="getServiceCode" resultType="java.lang.String">
|
||||
select distinct sims.service_code from sys_iot_model_service sims
|
||||
left join sys_equipment se on sims.iot_model_id = se.iot_model_id
|
||||
where se.id = #{equipmentId} and sims.service_type = #{type}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
Loading…
Reference in New Issue
Block a user