Переглянути джерело

告警规则同步代码提交

jingyuanchao 1 рік тому
батько
коміт
c4e59432b4

+ 28 - 2
project_data/sql/0.1.1/soc/soc.sql

@@ -126,7 +126,7 @@ BEGIN
                   WHERE table_schema = DATABASE()
                     AND table_name = 'iot_alarm_defence_area'
                     AND column_name = 'category_id') THEN
-        ALTER TABLE `soc`.`iot_alarm_defence_area`
+        ALTER TABLE iot_alarm_defence_area
             DROP COLUMN `category_id`;
     END IF;
 
@@ -1180,7 +1180,7 @@ INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) VALUES (120, 1839945558511747
 
 
 DELETE FROM `sys_menu` WHERE `id`=01840267252212912129;
-INSERT INTO `soc`.`sys_menu` (`id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `platform_type`, `icon`, `image_path`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (01840267252212912129, '多层字典', 1, 0, 'multilayerdict', 'system/multilayerdict/index', NULL, 1, 0, 'C', '0', '0', '', '1', 'dict', NULL, '超级管理员', '2024-09-29 13:50:03', '超级管理员', '2024-09-29 13:50:46', '');
+INSERT INTO `sys_menu` (`id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `platform_type`, `icon`, `image_path`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (01840267252212912129, '多层字典', 1, 0, 'multilayerdict', 'system/multilayerdict/index', NULL, 1, 0, 'C', '0', '0', '', '1', 'dict', NULL, '超级管理员', '2024-09-29 13:50:03', '超级管理员', '2024-09-29 13:50:46', '');
 
 drop table if exists core_notice_rule;
 CREATE TABLE `core_notice_rule` (
@@ -1344,6 +1344,32 @@ BEGIN
             ADD COLUMN `iot_code` varchar(225)  DEFAULT null COMMENT '主机token';
     END IF;
 
+    IF NOT EXISTS (SELECT * FROM information_schema.columns
+                   WHERE table_schema = DATABASE()
+                     AND table_name = 'iot_alarm_rule_source'
+                     AND column_name = 'product_type') THEN
+        ALTER TABLE `iot_alarm_rule_source`
+            CHANGE COLUMN `source_type` `product_type` varchar(225) NULL DEFAULT NULL COMMENT '报警源类型:4:烟雾传感器;5:温湿度采集器;6:水浸,7:门磁:窗磁,8:卷帘门门磁;9:地磁,10:燃气报警器,50:报警防区' AFTER `rule_id`;
+    END IF;
+
+
+    IF NOT EXISTS (SELECT * FROM information_schema.columns
+                   WHERE table_schema = DATABASE()
+                     AND table_name = 'iot_alarm_rule_source'
+                     AND column_name = 'device_code') THEN
+        ALTER TABLE `iot_alarm_rule_source`
+            ADD COLUMN `device_code` varchar(255) NULL COMMENT '设备code' AFTER `product_type`;
+    END IF;
+
+    IF EXISTS (SELECT * FROM information_schema.columns
+                   WHERE table_schema = DATABASE()
+                     AND table_name = 'iot_alarm_rule_express'
+                     AND column_name = 'source_type') THEN
+        ALTER TABLE `iot_alarm_rule_express`
+            DROP COLUMN `source_type`;
+    END IF;
+
+
 
     IF NOT EXISTS (SELECT * FROM information_schema.columns
                    WHERE table_schema = DATABASE()

+ 17 - 12
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/alarm/service/impl/IotAlarmRuleServiceImpl.java

@@ -19,6 +19,7 @@ import com.xunmei.host.websocket.enums.TopicTypeEnums;
 import com.xunmei.host.websocket.service.RouterService;
 import com.xunmei.host.websocket.utils.IotServerUtils;
 import com.xunmei.host.websocket.utils.WebSocketUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -80,14 +81,16 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
         final IotAlarmRule alarmRule = jsb.toJavaObject(IotAlarmRule.class);
 
         final IotAlarmRule iotAlarmRule = JSON.parseObject(JSON.toJSONString(jsb), IotAlarmRule.class);
-        iotAlarmRule.setIotCode(serverInfo.getIotCode());
-        iotAlarmRule.setOrgId(serverInfo.getOrgId());
-        iotAlarmRule.setOrgName(serverInfo.getOrgName());
-        iotAlarmRule.setServerName(serverInfo.getIotName());
+        final IotAlarmRule rule = new IotAlarmRule();
+        BeanUtils.copyProperties(iotAlarmRule, rule);
+        rule.setIotCode(serverInfo.getIotCode());
+        rule.setOrgId(serverInfo.getOrgId());
+        rule.setOrgName(serverInfo.getOrgName());
+        rule.setServerName(serverInfo.getIotName());
         final Object deleted = jsb.get("deleted");
-        iotAlarmRule.setIsdeleted(deleted == null ? null : Integer.parseInt(deleted.toString()));
-        iotAlarmRule.setType("alarm");
-        saveOrUpdate(alarmRule);
+        rule.setIsdeleted(deleted == null ? null : Integer.parseInt(deleted.toString()));
+        rule.setType("alarm");
+        saveOrUpdate(rule);
 
         final Object rs = jsb.get("ruleSourceList");
         final Object re = jsb.get("ruleExpresses");
@@ -95,11 +98,13 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
             final List<JSONObject> list = JSON.parseArray(rs.toString(), JSONObject.class);
             for (JSONObject j : list) {
                 final IotAlarmRuleSource ruleSource = j.toJavaObject(IotAlarmRuleSource.class);
-                ruleSource.setOrgId(serverInfo.getOrgId());
-                ruleSource.setIotCode(serverInfo.getIotCode());
-                ruleSource.setValue(serverInfo.getIotCode() + "_" + ruleSource.getProductType() + "_" + ruleSource.getDeviceCode());
-                ruleSource.setValueType(j.get("sourceType") == null ? "" : j.get("sourceType").toString());
-                ruleSourceService.saveOrUpdate(ruleSource);
+                final IotAlarmRuleSource source = new IotAlarmRuleSource();
+                BeanUtils.copyProperties(ruleSource, source);
+                source.setOrgId(serverInfo.getOrgId());
+                source.setIotCode(serverInfo.getIotCode());
+                source.setValue(serverInfo.getIotCode() + "_" + ruleSource.getProductType() + "_" + ruleSource.getDeviceCode());
+                source.setValueType(j.get("sourceType") == null ? "" : j.get("sourceType").toString());
+                ruleSourceService.saveOrUpdate(source);
             }
         }
         if (re != null) {