From eb45296a5777108c08db1a15d40fadf98c97383d Mon Sep 17 00:00:00 2001 From: George Date: Sat, 28 Mar 2026 11:24:59 +0800 Subject: [PATCH] =?UTF-8?q?20260328:=E6=95=B0=E6=8D=AE=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fastbee/common/enums/DataLevelEnum.java | 6 +- .../iot/data/push/ThingsModelPushHandler.java | 2 +- sql/iot_things_model_push.sql | 13 ---- yack-web/src/views/iot/push/index.vue | 65 ++++++++++--------- 4 files changed, 40 insertions(+), 46 deletions(-) diff --git a/fastbee-common/src/main/java/com/fastbee/common/enums/DataLevelEnum.java b/fastbee-common/src/main/java/com/fastbee/common/enums/DataLevelEnum.java index 7be892b8..c34174b6 100644 --- a/fastbee-common/src/main/java/com/fastbee/common/enums/DataLevelEnum.java +++ b/fastbee-common/src/main/java/com/fastbee/common/enums/DataLevelEnum.java @@ -8,9 +8,9 @@ package com.fastbee.common.enums; */ public enum DataLevelEnum { - GREEN(1, "正常", "#009900"), - YELLOW(2, "告警", "#FF9900"), - RED(3, "警报", "#FF0000"); + GREEN(1, "绿色(正常)", "#009900"), + YELLOW(2, "黄色(告警)", "#FF9900"), + RED(3, "红色(警报)", "#FF0000"); private final int code; private final String label; diff --git a/fastbee-iot-data/src/main/java/com/fastbee/iot/data/push/ThingsModelPushHandler.java b/fastbee-iot-data/src/main/java/com/fastbee/iot/data/push/ThingsModelPushHandler.java index 7b083e00..ea2df679 100644 --- a/fastbee-iot-data/src/main/java/com/fastbee/iot/data/push/ThingsModelPushHandler.java +++ b/fastbee-iot-data/src/main/java/com/fastbee/iot/data/push/ThingsModelPushHandler.java @@ -203,7 +203,7 @@ public class ThingsModelPushHandler { } } - // 与 WeChatPushServiceImpl 保持一致的 map 迭代方式 + // 与微信模板消息要求保持一致的 map 迭代方式 Map sendMap = new LinkedHashMap<>(); for (Map.Entry m : map.entrySet()) { sendMap.put(m.getKey(), new TemplateDataVo(m.getValue(), level.getColor())); diff --git a/sql/iot_things_model_push.sql b/sql/iot_things_model_push.sql index 53398505..2f02a208 100644 --- a/sql/iot_things_model_push.sql +++ b/sql/iot_things_model_push.sql @@ -75,16 +75,3 @@ VALUES (3434, '推送配置删除', 3430, 4, '#', '', NULL, 1, 0, 'F', '0', '0', INSERT INTO `sys_menu` (menu_id, menu_name, parent_id, order_num, `path`, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) VALUES (3435, '手动立即推送', 3430, 5, '#', '', NULL, 1, 0, 'F', '0', '0', 'iot:push:push', '#', 'admin', now(), 'admin', now(), ''); --- ============================================================ --- 升级脚本:如已执行过旧版本建表,执行以下语句迁移字段 --- ============================================================ -ALTER TABLE `iot_things_model_push_config` - ADD COLUMN IF NOT EXISTS `template_id` BIGINT DEFAULT NULL COMMENT '通知模板ID(关联 notify_template.id)' AFTER `serial_number`, - ADD INDEX IF NOT EXISTS `idx_template_id` (`template_id`); - --- 迁移完成后可删除旧字段(按需执行): --- ALTER TABLE `iot_things_model_push_config` --- DROP COLUMN IF EXISTS `channel_id`, --- DROP COLUMN IF EXISTS `wx_template_id`, --- DROP COLUMN IF EXISTS `wx_msg_content`, --- DROP COLUMN IF EXISTS `redirect_url`; diff --git a/yack-web/src/views/iot/push/index.vue b/yack-web/src/views/iot/push/index.vue index a09182a5..98c8b05d 100644 --- a/yack-web/src/views/iot/push/index.vue +++ b/yack-web/src/views/iot/push/index.vue @@ -13,7 +13,7 @@ clearable @keyup.enter.native="handleQuery" style="width:160px" /> - + @@ -91,9 +91,8 @@ - @@ -212,7 +211,7 @@ import { listPushConfig, getPushConfig, addPushConfig, updatePushConfig, changePushConfigStatus, delPushConfig, manualPush } from '@/api/iot/pushConfig'; -import { listDevice } from '@/api/iot/device'; +import { listDeviceShort } from '@/api/iot/device'; import { listModel } from '@/api/iot/model'; import { listTemplate } from '@/api/notify/template'; import { listUser } from '@/api/system/user'; @@ -250,7 +249,7 @@ export default { pushInterval: [{ required: true, message: '请填写推送间隔', trigger: 'blur' }] }, deviceOptions: [], - deviceSearchLoading: false, + deviceOptionsLoading: false, templateOptions: [], thingsModelOptions: [], userOptions: [] @@ -276,25 +275,33 @@ export default { this.getList(); }, - remoteSearchDevice(keyword) { - if (!keyword) return; - this.deviceSearchLoading = true; - const baseQuery = { pageNum: 1, pageSize: 30 }; - // 关键字同时匹配 deviceName 和 serialNumber - const byName = listDevice({ ...baseQuery, deviceType: null, deviceName: keyword }); - const bySn = listDevice({ ...baseQuery, deviceType: null, serialNumber: keyword }); - Promise.all([byName, bySn]).then(([r1, r2]) => { - const rows1 = r1.rows || []; - const rows2 = r2.rows || []; - // 合并去重(以 deviceId 为 key),只保留直连(1)和网关(2)设备 + /** + * 弹窗打开时拉取设备列表。必须用 shortList:/iot/device/list 的 SQL 不查 device_type, + * 返回的 deviceType 恒为 null,前端按 1/2 过滤会清空列表(远程搜索同样会失效)。 + * shortList 与设备首页一致,含产品 device_type;entrance=1 排除网关子设备类产品(4)。 + */ + loadDeviceOptions(mergeDevice) { + this.deviceOptions = []; + this.deviceOptionsLoading = true; + listDeviceShort({ + pageNum: 1, + pageSize: 500, + entrance: 1, + showChild: true + }).then(res => { const map = new Map(); - [...rows1, ...rows2].forEach(d => { - if ((d.deviceType === 1 || d.deviceType === 2) && !map.has(d.deviceId)) { + (res.rows || []).forEach(d => { + if ((d.deviceType === 1 || d.deviceType === 2) && d.deviceId != null && !map.has(d.deviceId)) { map.set(d.deviceId, d); } }); + if (mergeDevice && mergeDevice.deviceId != null && !map.has(mergeDevice.deviceId)) { + map.set(mergeDevice.deviceId, mergeDevice); + } this.deviceOptions = Array.from(map.values()); - }).finally(() => { this.deviceSearchLoading = false; }); + }).catch(() => { + this.$message.error('加载设备列表失败,请确认拥有设备查询权限'); + }).finally(() => { this.deviceOptionsLoading = false; }); }, deviceLabel(d) { @@ -352,10 +359,10 @@ export default { handleAdd() { this.form = emptyForm(); - this.deviceOptions = []; this.thingsModelOptions = []; this.dialogTitle = '新增推送配置'; this.dialogOpen = true; + this.loadDeviceOptions(); this.$nextTick(() => this.resetForm('form')); }, handleUpdate(row) { @@ -366,14 +373,14 @@ export default { userIds: data.userIds || [], items: data.items || [] }; - if (data.deviceId) { - this.deviceOptions = [{ - deviceId: data.deviceId, - deviceName: data.deviceName || data.serialNumber, - serialNumber: data.serialNumber || '', - deviceType: data.deviceType || 1 - }]; - } + const mergeDev = data.deviceId ? { + deviceId: data.deviceId, + deviceName: data.deviceName || data.serialNumber, + serialNumber: data.serialNumber || '', + deviceType: data.deviceType || 1, + productId: data.productId + } : null; + this.loadDeviceOptions(mergeDev); if (data.productId) { listModel({ productId: data.productId, type: 1, pageNum: 1, pageSize: 500 }).then(r => { this.thingsModelOptions = r.rows || [];