diff --git a/README.md b/README.md index 61938265..36f105f5 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,6 @@ -## 若依前后端分离交流群 +## 业务记录 -QQ群: [![加入QQ群](https://img.shields.io/badge/已满-937441-blue.svg)](https://jq.qq.com/?_wv=1027&k=5bVB1og) [![加入QQ群](https://img.shields.io/badge/已满-887144332-blue.svg)](https://jq.qq.com/?_wv=1027&k=5eiA4DH) [![加入QQ群](https://img.shields.io/badge/已满-180251782-blue.svg)](https://jq.qq.com/?_wv=1027&k=5AxMKlC) [![加入QQ群](https://img.shields.io/badge/已满-104180207-blue.svg)](https://jq.qq.com/?_wv=1027&k=51G72yr) [![加入QQ群](https://img.shields.io/badge/已满-186866453-blue.svg)](https://jq.qq.com/?_wv=1027&k=VvjN2nvu) [![加入QQ群](https://img.shields.io/badge/已满-201396349-blue.svg)](https://jq.qq.com/?_wv=1027&k=5vYAqA05) [![加入QQ群](https://img.shields.io/badge/已满-101456076-blue.svg)](https://jq.qq.com/?_wv=1027&k=kOIINEb5) [![加入QQ群](https://img.shields.io/badge/101539465-blue.svg)](https://jq.qq.com/?_wv=1027&k=UKtX5jhs) 点击按钮入群。 \ No newline at end of file +1、建立每个设备的轮询iot_modbus_job任务之前会查看是否存在设备任务iot_device_job; \ No newline at end of file diff --git a/fastbee-iot-data/src/main/java/com/fastbee/iot/data/consumer/DevicePropFetchConsumer.java b/fastbee-iot-data/src/main/java/com/fastbee/iot/data/consumer/DevicePropFetchConsumer.java index 321fbec2..631a6b71 100644 --- a/fastbee-iot-data/src/main/java/com/fastbee/iot/data/consumer/DevicePropFetchConsumer.java +++ b/fastbee-iot-data/src/main/java/com/fastbee/iot/data/consumer/DevicePropFetchConsumer.java @@ -113,8 +113,8 @@ public class DevicePropFetchConsumer { log.info("=>TCP-线程=[{}],轮询指令:[{}]", Thread.currentThread().getName(), command); break; } - //指令间隔时间 - Thread.sleep(1000); + // 指令间隔时间 + Thread.sleep(3000); } } catch (Exception e) { diff --git a/fastbee-iot-data/src/main/java/com/fastbee/iot/data/service/impl/DeviceJobServiceImpl.java b/fastbee-iot-data/src/main/java/com/fastbee/iot/data/service/impl/DeviceJobServiceImpl.java index cde358c5..b5123ff1 100644 --- a/fastbee-iot-data/src/main/java/com/fastbee/iot/data/service/impl/DeviceJobServiceImpl.java +++ b/fastbee-iot-data/src/main/java/com/fastbee/iot/data/service/impl/DeviceJobServiceImpl.java @@ -10,6 +10,7 @@ import com.fastbee.iot.service.IDeviceJobService; import com.fastbee.quartz.domain.SysJob; import com.fastbee.quartz.mapper.SysJobMapper; import com.fastbee.quartz.util.CronUtils; +import com.fastbee.quartz.util.ScheduleUtils; import lombok.extern.slf4j.Slf4j; import org.quartz.JobDataMap; import org.quartz.JobKey; @@ -58,7 +59,7 @@ public class DeviceJobServiceImpl implements IDeviceJobService { // 系统定时任务 List sysJobList = sysJobMapper.selectJobAll(); for (SysJob job : sysJobList) { - com.fastbee.quartz.util.ScheduleUtils.createScheduleJob(scheduler, job); + ScheduleUtils.createScheduleJob(scheduler, job); } } 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 28f9cd65..1614b353 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 @@ -199,6 +199,10 @@ public class DeviceServiceImpl implements IDeviceService { device.setSlaveId(modbusParams.getSlaveId()); } device.setCanConfigPoll(0 == modbusParams.getPollType()); + } else { + if (device.getDeviceType() == DeviceType.GATEWAY.getCode()) { + device.setCanConfigPoll(true); + } } } return device; diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/ModbusJobServiceImpl.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/ModbusJobServiceImpl.java index 63f9ae32..88ed1e41 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/ModbusJobServiceImpl.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/ModbusJobServiceImpl.java @@ -106,7 +106,8 @@ public class ModbusJobServiceImpl implements IModbusJobService { // 查询关联的网关设备 DeviceAndProtocol deviceAndProtocol = deviceService.selectProtocolBySerialNumber(modbusJob.getSubSerialNumber()); // 如果是网关子设备 - if (deviceAndProtocol.getDeviceType() == DeviceType.SUB_GATEWAY.getCode()) { + if (deviceAndProtocol.getDeviceType() == DeviceType.SUB_GATEWAY.getCode() || + deviceAndProtocol.getDeviceType() == DeviceType.GATEWAY.getCode()) { // 如果有绑定网关 if (!Objects.isNull(deviceAndProtocol.getGwDeviceId())) { DeviceJob deviceJob = new DeviceJob(); @@ -141,51 +142,23 @@ public class ModbusJobServiceImpl implements IModbusJobService { DeviceJob job = list.get(0); modbusJob.setJobId(job.getJobId()); } - } else { + } else if (deviceAndProtocol.getDeviceType() == DeviceType.GATEWAY.getCode()) { + // 网关直接轮询,在网关自身上创建 DeviceJob + DeviceJob deviceJob = new DeviceJob(); + deviceJob.setDeviceId(deviceAndProtocol.getDeviceId()); // 用网关自己的deviceId + buildSaveDeviceJob(modbusJob, deviceAndProtocol, deviceJob); + } else { throw new ServiceException("请先绑定网关"); } - modbusJob.setCreateTime(DateUtils.getNowDate()); - modbusJob.setDeviceType(deviceAndProtocol.getDeviceType()); - return modbusJobMapper.insertModbusJob(modbusJob); } else { // 直连设备 DeviceJob deviceJob = new DeviceJob(); deviceJob.setDeviceId(modbusJob.getSubDeviceId()); - deviceJob.setRemark(modbusJob.getRemark()); - deviceJob.setJobType(5); - List list = deviceJobService.selectJobList(deviceJob); - if (CollectionUtils.isEmpty(list)) { - // 创建定时任务 - // 如果不存在定时任务则新建(设备创建定时任务之前会创建一个) - deviceJob.setJobName("modbus poll"); - deviceJob.setJobGroup("MODBUS"); - deviceJob.setMisfirePolicy("2"); - deviceJob.setConcurrent("1"); - deviceJob.setIsAdvance(0); - deviceJob.setStatus("0"); - deviceJob.setSerialNumber(deviceAndProtocol.getSerialNumber()); - deviceJob.setProductId(deviceAndProtocol.getProductId()); - deviceJob.setCreateTime(DateUtils.getNowDate()); - // 处理时间转换 - // 检查是否是设备上电触发(使用 cycleType 判断) - if (isPowerOnTrigger(modbusJob.getCycleType())) { - // 设备上电触发不需要 cron 表达式,设置为null - // DeviceJobServiceImpl.insertJob 会检查并跳过创建定时任务 - deviceJob.setCronExpression(null); - } else { - SceneModelTagCycleVO sceneModelTagCycleVO = JobCronUtils.handleCronCycle(1, deviceJob.getRemark()); - deviceJob.setCronExpression(sceneModelTagCycleVO.getCron()); - } - deviceJobService.insertJob(deviceJob); - modbusJob.setJobId(deviceJob.getJobId()); - } else { - DeviceJob job = list.get(0); - modbusJob.setJobId(job.getJobId()); - } - modbusJob.setCreateTime(DateUtils.getNowDate()); - modbusJob.setDeviceType(deviceAndProtocol.getDeviceType()); - return modbusJobMapper.insertModbusJob(modbusJob); + buildSaveDeviceJob(modbusJob, deviceAndProtocol, deviceJob); } + modbusJob.setCreateTime(DateUtils.getNowDate()); + modbusJob.setDeviceType(deviceAndProtocol.getDeviceType()); + return modbusJobMapper.insertModbusJob(modbusJob); } catch (Exception e) { throw new ServiceException(e.getMessage()); } @@ -270,10 +243,55 @@ public class ModbusJobServiceImpl implements IModbusJobService { // 网关设备需要查询所有子设备的modbus任务 List subDeviceList = subGatewayService.getSubDeviceListByGw(serialNumber); List serialNumberList = subDeviceList.stream().map(SubDeviceBo::getSubDeviceNo).collect(Collectors.toList()); + // 把网关自身SN也加入查询 + serialNumberList.add(serialNumber); modbusJob.setSubDeviceList(serialNumberList); return this.selectModbusJobList(modbusJob); default: return new ArrayList<>(); } } + + /** + * 组装并保存设备任务 + * @param modbusJob 待新增的modbus任务 + * @param deviceAndProtocol 设备协议 + * @param deviceJob 设备任务 + */ + private void buildSaveDeviceJob(ModbusJob modbusJob, DeviceAndProtocol deviceAndProtocol, DeviceJob deviceJob) { + deviceJob.setRemark(modbusJob.getRemark()); + deviceJob.setJobType(5); + List list = deviceJobService.selectJobList(deviceJob); + if (CollectionUtils.isEmpty(list)) { + // 如果不存在定时任务则新建 + deviceJob.setJobName("modbus poll"); + deviceJob.setJobGroup("MODBUS"); + deviceJob.setMisfirePolicy("2"); + deviceJob.setConcurrent("1"); + deviceJob.setIsAdvance(0); + deviceJob.setStatus("0"); + deviceJob.setSerialNumber(deviceAndProtocol.getSerialNumber()); // 网关自己的SN + deviceJob.setProductId(deviceAndProtocol.getProductId()); + deviceJob.setCreateTime(DateUtils.getNowDate()); + // 检查是否是设备上电触发(使用 cycleType 判断) + if (isPowerOnTrigger(modbusJob.getCycleType())) { + // 设备上电触发不需要 cron 表达式,设置为null + // DeviceJobServiceImpl.insertJob 会检查并跳过创建定时任务 + deviceJob.setCronExpression(null); + } else { + // 处理时间转换 + SceneModelTagCycleVO sceneModelTagCycleVO = JobCronUtils.handleCronCycle(1, deviceJob.getRemark()); + deviceJob.setCronExpression(sceneModelTagCycleVO.getCron()); + } + try { + deviceJobService.insertJob(deviceJob); + } catch (Exception e) { + throw new ServiceException(e.getMessage()); + } + modbusJob.setJobId(deviceJob.getJobId()); + } else { + DeviceJob job = list.get(0); + modbusJob.setJobId(job.getJobId()); + } + } } diff --git a/yack-web/src/views/iot/device/device-edit.vue b/yack-web/src/views/iot/device/device-edit.vue index a1f485d8..96abaf03 100644 --- a/yack-web/src/views/iot/device/device-edit.vue +++ b/yack-web/src/views/iot/device/device-edit.vue @@ -175,17 +175,6 @@ - - - {{$t('device.device-edit.subDevicePollingManage')}} - - - {{ $t('device.device-edit.148398-44') }} @@ -386,7 +375,6 @@ import deviceInlineVideo from './device-inline-video'; import deviceFuncLog from './device-functionlog'; import deviceSub from './device-sub'; import deviceThingsModel from './device-things-model.vue'; -import gwSubModbusTask from './gw-sub-modbus-task'; import vueQr from 'vue-qr'; import {loadMap} from '@/utils/map.js'; import { @@ -436,7 +424,6 @@ export default { deviceModbusTask, deviceInlineVideo, deviceThingsModel, - gwSubModbusTask, }, watch: { activeName(val) { diff --git a/yack-web/src/views/iot/device/device-modbus-task.vue b/yack-web/src/views/iot/device/device-modbus-task.vue index 12d6ea96..516a4a9d 100644 --- a/yack-web/src/views/iot/device/device-modbus-task.vue +++ b/yack-web/src/views/iot/device/device-modbus-task.vue @@ -1,5 +1,45 @@