diff --git a/fastbee-common/src/main/java/com/fastbee/common/core/mq/DeviceReportBo.java b/fastbee-common/src/main/java/com/fastbee/common/core/mq/DeviceReportBo.java index 2841be67..86f3c676 100644 --- a/fastbee-common/src/main/java/com/fastbee/common/core/mq/DeviceReportBo.java +++ b/fastbee-common/src/main/java/com/fastbee/common/core/mq/DeviceReportBo.java @@ -77,4 +77,14 @@ public class DeviceReportBo { private String sources; + /** + * 网关子设备BO + */ + private GwDeviceBo gwDeviceBo; + + /** + * 设备名称 + */ + private String deviceName; + } diff --git a/fastbee-iot-data/src/main/java/com/fastbee/iot/data/service/impl/DataHandlerImpl.java b/fastbee-iot-data/src/main/java/com/fastbee/iot/data/service/impl/DataHandlerImpl.java index a4194903..8a9546bb 100644 --- a/fastbee-iot-data/src/main/java/com/fastbee/iot/data/service/impl/DataHandlerImpl.java +++ b/fastbee-iot-data/src/main/java/com/fastbee/iot/data/service/impl/DataHandlerImpl.java @@ -109,8 +109,13 @@ public class DataHandlerImpl implements IDataHandler { pushObj.put("sources", bo.getSources()); messageBo.setMessage(JSON.toJSONString(pushObj)); remoteManager.pushCommon(messageBo); - if (!Objects.isNull(bo.getGwDeviceBo())) { + if (!Objects.isNull(bo.getGwDeviceBo()) + && !bo.getSerialNumber().equalsIgnoreCase(bo.getGwDeviceBo().getSerialNumber())) { + pushObj.put("subSerialNumber", bo.getSerialNumber()); + pushObj.put("subDeviceName", bo.getDeviceName()); + pushObj.put("subSlaveId", bo.getSlaveId()); messageBo.setTopic(topicsUtils.buildTopic(bo.getGwDeviceBo().getProductId(), bo.getGwDeviceBo().getSerialNumber(), TopicType.WS_SERVICE_INVOKE)); + messageBo.setMessage(JSON.toJSONString(pushObj)); remoteManager.pushCommon(messageBo); } // 上报属性给小度音箱,接入小度音箱后可放开 diff --git a/fastbee-iot-data/src/main/java/com/fastbee/iot/data/service/impl/DeviceReportMessageServiceImpl.java b/fastbee-iot-data/src/main/java/com/fastbee/iot/data/service/impl/DeviceReportMessageServiceImpl.java index d677e0b1..e425368f 100644 --- a/fastbee-iot-data/src/main/java/com/fastbee/iot/data/service/impl/DeviceReportMessageServiceImpl.java +++ b/fastbee-iot-data/src/main/java/com/fastbee/iot/data/service/impl/DeviceReportMessageServiceImpl.java @@ -16,14 +16,12 @@ import com.fastbee.common.core.redis.RedisKeyBuilder; import com.fastbee.common.enums.*; import com.fastbee.common.exception.ServiceException; import com.fastbee.common.utils.DateUtils; -import com.fastbee.common.utils.StringUtils; import com.fastbee.common.utils.gateway.mq.TopicsUtils; import com.fastbee.iot.cache.IOtaTaskCache; import com.fastbee.iot.data.executor.PowerOnTriggerTaskExecutor; import com.fastbee.iot.data.service.IDataHandler; import com.fastbee.iot.data.service.IDeviceReportMessageService; import com.fastbee.iot.data.service.IFirmwareTaskDetailService; -import com.fastbee.iot.domain.Device; import com.fastbee.iot.domain.FunctionLog; import com.fastbee.iot.domain.Product; import com.fastbee.iot.domain.ProductAuthorize; @@ -43,8 +41,6 @@ import io.netty.buffer.Unpooled; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -297,6 +293,7 @@ public class DeviceReportMessageServiceImpl implements IDeviceReportMessageServi report.setUserId(message.getUserId()); report.setUserName(message.getUserName()); report.setDeviceName(message.getDeviceName()); + report.setSlaveId(message.getSlaveId()); report.setSources(message.getSources()); report.setGwDeviceBo(message.getGwDeviceBo()); // 属性上报执行规则引擎 diff --git a/fastbee-protocol/fastbee-protocol-collect/src/main/java/com/fastbee/hp/ModbusToJsonHPProtocolService.java b/fastbee-protocol/fastbee-protocol-collect/src/main/java/com/fastbee/hp/ModbusToJsonHPProtocolService.java index 78bff357..0138735b 100644 --- a/fastbee-protocol/fastbee-protocol-collect/src/main/java/com/fastbee/hp/ModbusToJsonHPProtocolService.java +++ b/fastbee-protocol/fastbee-protocol-collect/src/main/java/com/fastbee/hp/ModbusToJsonHPProtocolService.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject; import com.fastbee.common.annotation.SysProtocol; import com.fastbee.common.constant.FastBeeConstant; import com.fastbee.common.core.mq.DeviceReport; +import com.fastbee.common.core.mq.GwDeviceBo; import com.fastbee.common.core.mq.MQSendMessageBo; import com.fastbee.common.core.mq.SubDeviceBo; import com.fastbee.common.core.mq.message.DeviceData; @@ -111,6 +112,10 @@ public class ModbusToJsonHPProtocolService implements IProtocol { result.add(simpleItem); } } else { + GwDeviceBo gwDeviceBo = new GwDeviceBo(); + gwDeviceBo.setProductId(deviceData.getProductId()); + gwDeviceBo.setSerialNumber(deviceData.getSerialNumber()); + reportMessage.setGwDeviceBo(gwDeviceBo); for (Map.Entry entry : values.entrySet()) { String slaveKey = entry.getKey(); Integer slaveId = StringUtils.matcherNum(slaveKey); @@ -146,6 +151,8 @@ public class ModbusToJsonHPProtocolService implements IProtocol { report.setSerialNumber(vo.getSubDeviceNo()); report.setProductId(vo.getSubProductId()); report.setClientId(vo.getSubDeviceNo()); + report.setDeviceName(vo.getSubDeviceName()); + report.setSlaveId(vo.getSlaveId()); break; } } diff --git a/fastbee-protocol/fastbee-protocol-collect/src/main/java/com/fastbee/modbus/codec/ModbusProtocol.java b/fastbee-protocol/fastbee-protocol-collect/src/main/java/com/fastbee/modbus/codec/ModbusProtocol.java index 0f61bd44..129f6762 100644 --- a/fastbee-protocol/fastbee-protocol-collect/src/main/java/com/fastbee/modbus/codec/ModbusProtocol.java +++ b/fastbee-protocol/fastbee-protocol-collect/src/main/java/com/fastbee/modbus/codec/ModbusProtocol.java @@ -391,6 +391,8 @@ public class ModbusProtocol implements IProtocol { report.setSubDeviceBo(vo); report.setSerialNumber(vo.getSubDeviceNo()); report.setProductId(vo.getSubProductId()); + report.setDeviceName(vo.getSubDeviceName()); + report.setSlaveId(vo.getSlaveId()); break; } } diff --git a/fastbee-protocol/fastbee-protocol-collect/src/main/java/com/fastbee/modbustcp/codec/ModbusTcpProtocol.java b/fastbee-protocol/fastbee-protocol-collect/src/main/java/com/fastbee/modbustcp/codec/ModbusTcpProtocol.java index f56584df..3abc418f 100644 --- a/fastbee-protocol/fastbee-protocol-collect/src/main/java/com/fastbee/modbustcp/codec/ModbusTcpProtocol.java +++ b/fastbee-protocol/fastbee-protocol-collect/src/main/java/com/fastbee/modbustcp/codec/ModbusTcpProtocol.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONObject; import com.fastbee.common.annotation.SysProtocol; import com.fastbee.common.constant.FastBeeConstant; import com.fastbee.common.core.mq.DeviceReport; +import com.fastbee.common.core.mq.GwDeviceBo; import com.fastbee.common.core.mq.MQSendMessageBo; import com.fastbee.common.core.mq.SubDeviceBo; import com.fastbee.common.core.mq.message.DeviceData; @@ -76,6 +77,10 @@ public class ModbusTcpProtocol implements IProtocol { // report.setSources(hexDump); // return report; // } + GwDeviceBo gwDeviceBo = new GwDeviceBo(); + gwDeviceBo.setProductId(deviceData.getProductId()); + gwDeviceBo.setSerialNumber(deviceData.getSerialNumber()); + report.setGwDeviceBo(gwDeviceBo); matchSubDev(report, deviceData.getSerialNumber(), slaveId); String serialNumber = report.getSerialNumber(); Long productId = report.getProductId(); @@ -366,6 +371,8 @@ public class ModbusTcpProtocol implements IProtocol { report.setSubDeviceBo(vo); report.setSerialNumber(vo.getSubDeviceNo()); report.setProductId(vo.getSubProductId()); + report.setDeviceName(vo.getSubDeviceName()); + report.setSlaveId(vo.getSlaveId()); break; } } diff --git a/fastbee-server/iot-server-core/src/main/java/com/fastbee/server/handler/DispatcherHandler.java b/fastbee-server/iot-server-core/src/main/java/com/fastbee/server/handler/DispatcherHandler.java index ca23ce4d..945d04d1 100644 --- a/fastbee-server/iot-server-core/src/main/java/com/fastbee/server/handler/DispatcherHandler.java +++ b/fastbee-server/iot-server-core/src/main/java/com/fastbee/server/handler/DispatcherHandler.java @@ -142,12 +142,16 @@ public class DispatcherHandler extends ChannelInboundHandlerAdapter { reportBo.setThingsModelSimpleItem(report.getThingsModelSimpleItem()); reportBo.setPlatformDate(DateUtils.getNowDate()); reportBo.setSerialNumber(report.getClientId()); + reportBo.setProductId(report.getProductId()); reportBo.setServerType(ServerType.TCP); reportBo.setReplyMessage(report.getReplyMessage()); reportBo.setIsReply(report.getIsReply()); reportBo.setStatus(report.getStatus()); reportBo.setProtocolCode(FastBeeConstant.PROTOCOL.ModbusRtu); reportBo.setSources(report.getSources()); + reportBo.setSlaveId(report.getSlaveId()); + reportBo.setGwDeviceBo(report.getGwDeviceBo()); + reportBo.setDeviceName(report.getDeviceName()); MessageProducer.sendPublishMsg(reportBo); } diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/domain/Device.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/domain/Device.java index 3e7041b8..dcdb8045 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/domain/Device.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/domain/Device.java @@ -2,16 +2,14 @@ package com.fastbee.iot.domain; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; -import com.fasterxml.jackson.annotation.JsonFormat; import com.fastbee.common.annotation.Excel; import com.fastbee.common.core.domain.BaseEntity; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; import org.springframework.data.annotation.Transient; import java.math.BigDecimal; @@ -239,6 +237,11 @@ public class Device extends BaseEntity { @TableField(exist = false) private Boolean showChild; + @Transient + @ApiModelProperty("查询入口(1=设备管理列表 2=数据中心 3=全部设备)") + @TableField(exist = false) + private Integer entrance; + @TableField(exist = false) private List subDeviceList; diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/enums/DeviceEntrance.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/enums/DeviceEntrance.java new file mode 100644 index 00000000..d1192fd0 --- /dev/null +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/enums/DeviceEntrance.java @@ -0,0 +1,42 @@ +package com.fastbee.iot.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 设备查询入口枚举,由前端传入,控制不同页面的设备过滤策略 + */ +@AllArgsConstructor +@Getter +public enum DeviceEntrance { + + /** + * 设备管理列表 —— 过滤子设备(device_type=4),只展示直连/网关/监控设备 + */ + DEVICE_MANAGE(1, "设备管理列表"), + + /** + * 数据中心(历史数据) —— 主设备下拉,子设备通过网关接口单独加载 + */ + DATA_CENTER(2, "数据中心"), + + /** + * 设备全量查询 —— 不做任何过滤,返回所有设备 + */ + DEVICE_ALL(3, "全部设备"); + + private final int code; + private final String name; + + public static DeviceEntrance fromCode(Integer code) { + if (code == null) { + return null; + } + for (DeviceEntrance value : DeviceEntrance.values()) { + if (value.code == code) { + return value; + } + } + return null; + } +} diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/DeviceServiceImpl.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/DeviceServiceImpl.java index db55871e..28f9cd65 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/DeviceServiceImpl.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/DeviceServiceImpl.java @@ -1125,66 +1125,8 @@ public class DeviceServiceImpl implements IDeviceService { } } } else if (DeviceType.GATEWAY.getCode() == device.getDeviceType()) { -// LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); -// queryWrapper.eq(ProductSubGateway::getGwProductId, product.getProductId()); - // 处理子设备添加和子设备轮询 - ProductSubGateway productSubGateway = new ProductSubGateway(); - productSubGateway.setGwProductId(product.getProductId()); - List productSubGatewayList = productSubGatewayMapper.selectListVO(productSubGateway); - if (CollectionUtils.isEmpty(productSubGatewayList)) { - return; - } - productSubGatewayList.sort(Comparator.comparing(ProductSubGatewayVO::getSlaveId)); - List subProductIdList = productSubGatewayList.stream().map(ProductSubGatewayVO::getSubProductId) - .collect(Collectors.toList()); - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.in(ProductModbusJob::getProductId, subProductIdList); - List productModbusJobList = productModbusJobMapper.selectList(queryWrapper); - Map> productModbusJobMap = productModbusJobList.stream() - .collect(Collectors.groupingBy(ProductModbusJob::getProductId)); - // 新增子设备、绑定子设备、子设备生成轮询 - for (ProductSubGatewayVO productSubGatewayVO : productSubGatewayList) { - Device addDevice = new Device(); - addDevice.setDeviceName( - productSubGatewayVO.getSubProductName() + "_" + productSubGatewayVO.getSlaveId()); - addDevice.setProductId(productSubGatewayVO.getSubProductId()); - addDevice.setProductName(productSubGatewayVO.getSubProductName()); - String serialNumber = this.generationDeviceNum(1); - addDevice.setSerialNumber(serialNumber); - addDevice.setTenantId(device.getTenantId()); - addDevice.setTenantName(device.getTenantName()); - addDevice.setCreateBy(device.getCreateBy()); - addDevice.setFirmwareVersion(new BigDecimal(1)); - addDevice.setRssi(0); - addDevice.setIsShadow(0); - addDevice.setLocationWay(productSubGatewayVO.getSubLocationWay()); - addDevice.setImgUrl(product.getImgUrl()); - addDevice.setCreateTime(new Date()); - deviceMapper.insertDevice(addDevice); - SubGateway subGateway = new SubGateway(); - subGateway.setGwDeviceId(device.getDeviceId()); - subGateway.setSubDeviceId(addDevice.getDeviceId()); - subGateway.setSlaveId(productSubGatewayVO.getSlaveId()); - subGateway.setCreateBy(addDevice.getCreateBy()); - subGateway.setCreateTime(new Date()); - subGatewayMapper.insertGateway(subGateway); - List productModbusList = productModbusJobMap - .get(productSubGatewayVO.getSubProductId()); - if (!CollectionUtils.isEmpty(productModbusList)) { - for (ProductModbusJob productModbusJob : productModbusList) { - ModbusJob modbusJob = new ModbusJob(); - modbusJob.setJobName(productModbusJob.getJobName()); - modbusJob.setSubDeviceId(addDevice.getDeviceId()); - modbusJob.setSubSerialNumber(addDevice.getSerialNumber()); - modbusJob.setCommand(productModbusJob.getCommand()); - modbusJob.setStatus(productModbusJob.getStatus()); - modbusJob.setRemark(productModbusJob.getRemark()); - modbusJobService.insertModbusJob(modbusJob); - if (FastBeeConstant.PROTOCOL.ModbusTcp.equals(product.getProtocolCode())) { - redisCache.getCacheModbusTcpId(device.getSerialNumber()); - } - } - } + if (FastBeeConstant.PROTOCOL.ModbusTcp.equals(product.getProtocolCode())) { + redisCache.getCacheModbusTcpId(device.getSerialNumber()); } } diff --git a/fastbee-service/fastbee-iot-service/src/main/resources/mapper/iot/DeviceMapper.xml b/fastbee-service/fastbee-iot-service/src/main/resources/mapper/iot/DeviceMapper.xml index 53bb3997..3cc25b70 100644 --- a/fastbee-service/fastbee-iot-service/src/main/resources/mapper/iot/DeviceMapper.xml +++ b/fastbee-service/fastbee-iot-service/src/main/resources/mapper/iot/DeviceMapper.xml @@ -398,6 +398,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join iot_device_group g on g.device_id=d.device_id and d.gw_dev_code is null + + and (p.device_type is null or p.device_type != 4) + and g.group_id = #{groupId} and d.device_name like concat('%', #{deviceName}, '%') and d.product_id = #{productId} @@ -881,6 +884,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join iot_device_group g on g.device_id=d.device_id and d.gw_dev_code is null + + and (p.device_type is null or p.device_type != 4) + and g.group_id = #{groupId} and d.device_name like concat('%', #{deviceName}, '%') and d.product_id = #{productId} diff --git a/yack-web/src/lang/en-US/device.json b/yack-web/src/lang/en-US/device.json index 3f9f1e99..e5c3c8e6 100644 --- a/yack-web/src/lang/en-US/device.json +++ b/yack-web/src/lang/en-US/device.json @@ -104,6 +104,7 @@ "device.device-edit.148398-75": "video surveillance", "device.device-edit.148398-76": "Data debugging", "device.device-edit.148398-77": "Polling task", + "device.device-edit.subDevicePollingManage": "Polling management", "device.device-edit.148398-78": "Gateway", "device.device-edit.148398-79": "Cloud recording", "device.device-edit.148398-80": "Alert user", diff --git a/yack-web/src/lang/zh-CN/device.json b/yack-web/src/lang/zh-CN/device.json index 82780b8b..054c4dbf 100644 --- a/yack-web/src/lang/zh-CN/device.json +++ b/yack-web/src/lang/zh-CN/device.json @@ -104,6 +104,7 @@ "device.device-edit.148398-75": "视频监控", "device.device-edit.148398-76": "数据调试", "device.device-edit.148398-77": "轮询任务", + "device.device-edit.subDevicePollingManage": "轮询管理", "device.device-edit.148398-78": "网关", "device.device-edit.148398-79": "云端录像", "device.device-edit.148398-80": "告警用户", diff --git a/yack-web/src/views/dataCenter/history.vue b/yack-web/src/views/dataCenter/history.vue index 07e3b092..55808aeb 100644 --- a/yack-web/src/views/dataCenter/history.vue +++ b/yack-web/src/views/dataCenter/history.vue @@ -10,6 +10,11 @@ + + + + + @@ -148,6 +153,7 @@ + + diff --git a/yack-web/src/views/iot/device/index.vue b/yack-web/src/views/iot/device/index.vue index 509026c6..af4ff516 100644 --- a/yack-web/src/views/iot/device/index.vue +++ b/yack-web/src/views/iot/device/index.vue @@ -356,6 +356,7 @@ export default { pageNum: 1, pageSize: 12, showChild: true, + entrance: 1, deviceName: null, productId: null, groupId: null, @@ -423,7 +424,7 @@ export default { if (pageNum != null) { this.queryParams.pageNum = Number(pageNum); } - + const time = this.$route.query.t; if (time != null && time != this.uniqueId) { this.uniqueId = time; diff --git a/yack-web/src/views/iot/device/instruction-parsing.vue b/yack-web/src/views/iot/device/instruction-parsing.vue index e8a96b21..39590abd 100644 --- a/yack-web/src/views/iot/device/instruction-parsing.vue +++ b/yack-web/src/views/iot/device/instruction-parsing.vue @@ -21,6 +21,9 @@
{{ item.type == 0 ? $t('device.instruction-parsing.830424-1') : item.type == 1 ? $t('device.instruction-parsing.830424-2') : $t('device.instruction-parsing.830424-3') }}
+ + {{ item.subDeviceName }} (从机{{ item.subSlaveId }}) +
{{ item.time }}
{{ $t('device.instruction-parsing.830424-4') }} @@ -534,6 +537,9 @@ export default { analysis: false, //解析的数据数组 analysisList: data.message, + subDeviceName: data.subDeviceName || '', + subSerialNumber: data.subSerialNumber || '', + subSlaveId: data.subSlaveId, }); } }, diff --git a/yack-web/src/views/iot/device/sub-device-create.vue b/yack-web/src/views/iot/device/sub-device-create.vue index 8280c305..2919d02e 100644 --- a/yack-web/src/views/iot/device/sub-device-create.vue +++ b/yack-web/src/views/iot/device/sub-device-create.vue @@ -54,7 +54,7 @@ :disabled="!item.enabled" size="small" @change="onCountChange(index)" - @input.native="onCountInput(index, $event)" + @keyup.native="onCountKeyup(index, $event)" />
@@ -194,10 +194,12 @@ export default { onCountChange(index) { this.rebuildDevices(index); }, - onCountInput(index, e) { - this.$nextTick(() => { - this.rebuildDevices(index); - }); + onCountKeyup(index, e) { + if (!e.target || e.target.tagName !== 'INPUT') return; + const val = parseInt(e.target.value); + if (isNaN(val) || val < 1 || val > 10) return; + this.subProductList[index].count = val; + this.rebuildDevices(index); }, rebuildDevices(index) { const item = this.subProductList[index];