Parcourir la source

优化订阅设备信息和采集量两种方式触发告警的逻辑,执行动作可以是触发条件中的设备,也可以是其他设备,推送告警只能是触发条件中的设备

james il y a 1 semaine
Parent
commit
7df6a57f8d

+ 3 - 1
service-rule/service-rule-biz/src/main/java/com/usky/rule/jobs/ConsumptionJob.java

@@ -139,7 +139,9 @@ public class ConsumptionJob implements Job {
 
                             spaceTriggerAction = TriggerDeviceUtil.getBooleanExpressionValue(boolConstraintExp + ")");
                             if (spaceTriggerAction) {
-                                this.triggerDeviceUtil.setTriggerLog(now, ruleEngineDetailLog, device.getId(), device.getName(), TriggerValueTypeEnum.CONSUMPTION.getValue(), TriggerTypeEnum.DEVICE, meetTriggerConditionList, valueMap);
+                                List<SimpleVO> actionDevices = new ArrayList();
+                                actionDevices.add(device);
+                                this.triggerDeviceUtil.setTriggerLog(now, ruleEngineDetailLog, trigger.getProductCode(), actionDevices, TriggerValueTypeEnum.CONSUMPTION.getValue(), TriggerTypeEnum.DEVICE, meetTriggerConditionList, valueMap);
                                 break label77;
                             }
                         }

+ 39 - 6
service-rule/service-rule-biz/src/main/java/com/usky/rule/subscribe/TriggerDeviceUtil.java

@@ -104,6 +104,7 @@ public class TriggerDeviceUtil {
                             if (deviceTriggers != null) {
                                 deviceTriggers = (List)deviceTriggers.stream().filter((deviceTrigger) -> deviceTrigger.getMethod().equals("acq")).filter((deviceTrigger) -> deviceTrigger.getProductId().equals(productId)).filter((deviceTrigger) -> deviceTrigger.getDevices().stream().anyMatch((device) -> StringUtils.equals(device.getId(), deviceId) || StringUtils.isNotBlank(deviceUuId) && StringUtils.equals(device.getDeviceUuid(), deviceUuId))).collect(Collectors.toList());
                                 if (!deviceTriggers.isEmpty()) {
+                                    this.putProductCodeIntoValueMapIfAbsent(map_data, valueMap, deviceTriggers);
                                     log.info("enter deviceTriggers {}",deviceTriggers);
                                     RuleEngineDetailLog ruleEngineDetailLog = new RuleEngineDetailLog();
                                     List<Condition> meetTriggerConditionList = new ArrayList();
@@ -117,7 +118,11 @@ public class TriggerDeviceUtil {
                                             return;
                                         }
                                         log.info("triggerAction is true");
-                                        this.setTriggerLog(now, ruleEngineDetailLog, deviceId, deviceTriggers.get(0).getDevices().get(0).getName(), TriggerValueTypeEnum.ACQ.getValue(), TriggerTypeEnum.DEVICE, meetTriggerConditionList, valueMap);
+                                        List<SimpleVO> triggerDevices = deviceTriggers.get(0).getDevices().stream()
+                                                .filter((device) -> StringUtils.equals(device.getId(), deviceId)
+                                                        || (StringUtils.isNotBlank(deviceUuId) && StringUtils.equals(device.getDeviceUuid(), deviceUuId)))
+                                                .collect(Collectors.toList());
+                                        this.setTriggerLog(now, ruleEngineDetailLog, deviceTriggers.get(0).getProductCode(), triggerDevices, TriggerValueTypeEnum.ACQ.getValue(), TriggerTypeEnum.DEVICE, meetTriggerConditionList, valueMap);
                                         List<CronConstraint> cronConstraints = this.ruleEngineService.getCronConstraints(ruleEngineDetail.getConstraints());
                                         List<DeviceConstraint> deviceConstraints = this.ruleEngineService.getDeviceConstraints(ruleEngineDetail.getConstraints());
                                         boolean cronOk = this.meetCronConstraintAction(cronConstraints, ruleEngineDetailLog, currDataTime);
@@ -148,12 +153,39 @@ public class TriggerDeviceUtil {
 
     }
 
-    public void setTriggerLog(LocalDateTime now, RuleEngineDetailLog ruleEngineDetailLog, String deviceId, String deviceName, String method, TriggerTypeEnum triggerTypeEnum, List<Condition> meetTriggerConditionList, Map<String, String> valueMap) {
+    /**
+     * 将产品编码写入本次上报的 valueMap(键 {@code productcode},与 metrics 小写键一致):优先上报 JSON 的 productCode / product_code,
+     * 否则使用已与当前设备、产品匹配的触发器配置中的 {@link DeviceTrigger#getProductCode()}。
+     */
+    private void putProductCodeIntoValueMapIfAbsent(Map map_data, Map<String, String> valueMap, List<DeviceTrigger> matchedTriggers) {
+        if (map_data != null) {
+            Object pc = map_data.get("productCode");
+            if (pc == null) {
+                pc = map_data.get("product_code");
+            }
+            if (pc != null) {
+                String s = pc.toString().trim();
+                if (StringUtils.isNotBlank(s)) {
+                    valueMap.putIfAbsent("productcode", s);
+                }
+            }
+        }
+        if (matchedTriggers != null) {
+            for (DeviceTrigger t : matchedTriggers) {
+                if (t != null && StringUtils.isNotBlank(t.getProductCode())) {
+                    valueMap.putIfAbsent("productcode", t.getProductCode().trim());
+                    break;
+                }
+            }
+        }
+    }
+
+    public void setTriggerLog(LocalDateTime now, RuleEngineDetailLog ruleEngineDetailLog, String productCode, List<SimpleVO> devices, String method, TriggerTypeEnum triggerTypeEnum, List<Condition> meetTriggerConditionList, Map<String, String> valueMap) {
         DeviceTriggerLog deviceTriggerLog = new DeviceTriggerLog();
-        deviceTriggerLog.setId(deviceId);
-        deviceTriggerLog.setName(deviceName);
         deviceTriggerLog.setMethod(method);
         deviceTriggerLog.setTime(DateTimeUtil.format(now));
+        deviceTriggerLog.setProductCode(productCode);
+        deviceTriggerLog.setDevices(devices);
         deviceTriggerLog.setConditions(meetTriggerConditionList);
 
         for(Condition condition : meetTriggerConditionList) {
@@ -351,11 +383,12 @@ public class TriggerDeviceUtil {
             for(DeviceConstraint deviceConstraint : deviceConstraints) {
                 String deviceId = ((SimpleVO)deviceConstraint.getDevices().get(0)).getId();
                 String deviceUuid = deviceConstraint.getDevices().get(0).getDeviceUuid();
+                SimpleVO constraintDevice = deviceConstraint.getDevices().get(0);
                 DeviceTriggerLog deviceTriggerLog = new DeviceTriggerLog();
                 List<Condition> meetConstraintConditionList = new ArrayList();
-                deviceTriggerLog.setId(deviceId);
                 deviceTriggerLog.setMethod("acq");
-                deviceTriggerLog.setName(deviceConstraint.getDevices().get(0).getName());
+                deviceTriggerLog.setTime(DateTimeUtil.format(LocalDateTime.now()));
+                deviceTriggerLog.setDevices(Collections.singletonList(constraintDevice));
                 deviceTriggerLog.setConditions(meetConstraintConditionList);
                 deviceTriggerLogs.add(deviceTriggerLog);
                 List<Condition> identifierConditions = deviceConstraint.getConditions();

+ 35 - 13
service-rule/service-rule-biz/src/main/java/com/usky/rule/util/RuleEngineUtil.java

@@ -75,13 +75,14 @@ public class RuleEngineUtil {
                 baseLogs.add(baseLog);
                 ruleEngineLog.setTenantId(deviceControlAction.getDevices().get(0).getTenantId());
             } else if (ActionTypeEnum.ALARM_EVENT.getType().equals(ruleEngineAction.getType())) {
-                this.generateAlarmEvent(ruleEngineId, ruleEngineName, Collections.singletonList(ruleEngineAction));
+                List<SimpleVO> triggerDevices = extractDeviceTriggerLogDevices(ruleEngineDetail);
+                this.generateAlarmEvent(ruleEngineId, ruleEngineName, ((DeviceTriggerLog) ruleEngineDetail.getTriggers().get(0).getDetail()).getProductCode(), triggerDevices, Collections.singletonList(ruleEngineAction));
                 deviceActionTypes.add("alarmEvent");
                 BaseLog baseLog = new BaseLog();
                 baseLog.setType(ActionTypeEnum.ALARM_EVENT.getType());
-                baseLog.setDetail(getAlarmActionLog(now, (AlarmEventAction)ruleEngineAction));
+                baseLog.setDetail(getAlarmActionLog(now, triggerDevices, (AlarmEventAction)ruleEngineAction));
                 baseLogs.add(baseLog);
-                ruleEngineLog.setTenantId(((AlarmEventAction) ruleEngineAction).getDevices().get(0).getTenantId());
+                ruleEngineLog.setTenantId(triggerDevices.get(0).getTenantId());
             }
         }
 
@@ -106,13 +107,13 @@ public class RuleEngineUtil {
     }
 
     @NotNull
-    private static AlarmActionLog getAlarmActionLog(LocalDateTime now, AlarmEventAction ruleEngineAction) {
+    private static AlarmActionLog getAlarmActionLog(LocalDateTime now, List<SimpleVO> triggerDevices, AlarmEventAction ruleEngineAction) {
         AlarmActionLog alarmActionLog = new AlarmActionLog();
         List<AlarmEventLog> alarmEventLogs = new ArrayList();
         alarmActionLog.setAlarms(alarmEventLogs);
         alarmActionLog.setTime(DateTimeUtil.format(now));
         AlarmEventLog alarmEventLog = new AlarmEventLog();
-        alarmEventLog.setNotifiers(ruleEngineAction.getDevices());
+        alarmEventLog.setNotifiers(triggerDevices);
         alarmEventLog.setLevel(String.valueOf(ruleEngineAction.getAlarmGrade()));
         alarmEventLog.setMethod(ruleEngineAction.getAlarmAttribute());
         alarmEventLogs.add(alarmEventLog);
@@ -125,11 +126,10 @@ public class RuleEngineUtil {
      * @param ruleEngineName
      * @param actions
      */
-    public void generateAlarmEvent(Long ruleEngineId, String ruleEngineName, List<RuleEngineAction> actions) {
+    public void generateAlarmEvent(Long ruleEngineId, String ruleEngineName, String productCode, List<SimpleVO> triggerDevices, List<RuleEngineAction> actions) {
         for(RuleEngineAction ruleEngineAction : actions) {
             AlarmEventAction alarmEventAction = (AlarmEventAction)ruleEngineAction;
-            List<AlarmSimpleVO> devices = alarmEventAction.getDevices();
-            if (devices != null && !devices.isEmpty()) {
+            if (!triggerDevices.isEmpty()) {
                 JSONObject jsonObject = new JSONObject();
                 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                 LocalDateTime now = LocalDateTime.now();
@@ -140,11 +140,11 @@ public class RuleEngineUtil {
                 jsonObject.put("alarmAttribute",alarmEventAction.getAlarmAttribute());
                 jsonObject.put("alarmContent",alarmEventAction.getAlarmAttribute());
                 jsonObject.put("alarmGrade",alarmEventAction.getAlarmGrade());
-                jsonObject.put("productCode",alarmEventAction.getProductCode());
-                for (AlarmSimpleVO device : devices) {
-                    jsonObject.put("deviceId",device.getDeviceId());
-                    jsonObject.put("alarmObject",device.getName());
-                    jsonObject.put("alarmAddress",device.getCommAddress());
+                jsonObject.put("productCode", productCode);
+                for (SimpleVO device : triggerDevices) {
+                    jsonObject.put("deviceId", device.getId());
+                    jsonObject.put("alarmObject", device.getName());
+                    jsonObject.put("alarmAddress", device.getCommAddress());
 
                     HttpClientUtils.doPostJson(alarmUrl,jsonObject.toJSONString());
                 }
@@ -153,6 +153,28 @@ public class RuleEngineUtil {
 
     }
 
+    /**
+     * 从规则执行日志的触发器明细中取出设备触发记录里的设备列表({@link DeviceTriggerLog#getDevices()})。
+     */
+    private static List<SimpleVO> extractDeviceTriggerLogDevices(RuleEngineDetailLog ruleEngineDetail) {
+        if (ruleEngineDetail == null || ruleEngineDetail.getTriggers() == null) {
+            return Collections.emptyList();
+        }
+        for (BaseLog triggerLog : ruleEngineDetail.getTriggers()) {
+            if (triggerLog == null) {
+                continue;
+            }
+            Object detail = triggerLog.getDetail();
+            if (detail instanceof DeviceTriggerLog) {
+                List<SimpleVO> devices = ((DeviceTriggerLog) detail).getDevices();
+                if (devices != null && !devices.isEmpty()) {
+                    return devices;
+                }
+            }
+        }
+        return Collections.emptyList();
+    }
+
     /**
      * 从 JSON 数组字符串中,根据 value 值获取对应的 name 值
      * @param jsonArrayStr JSON数组字符串(如:[{"name":"开","value":"1"},{"name":"关","value":"2"}])

+ 2 - 48
service-rule/service-rule-biz/src/main/java/com/usky/rule/vo/action/AlarmEventAction.java

@@ -9,14 +9,10 @@ import java.util.List;
 public class AlarmEventAction implements RuleEngineAction {
     @JsonProperty("alarmGrade")
     private Integer alarmGrade;
-    @JsonProperty("productCode")
-    private String productCode;
     @JsonProperty("alarmType")
     private String alarmType;
     @JsonProperty("alarmAttribute")
     private String alarmAttribute;
-    @JsonProperty("devices")
-    private List<AlarmSimpleVO> devices;
 
     public String getType() {
         return ActionTypeEnum.ALARM_EVENT.getType();
@@ -29,10 +25,6 @@ public class AlarmEventAction implements RuleEngineAction {
         return this.alarmGrade;
     }
 
-    public String getProductCode() {
-        return this.productCode;
-    }
-
     public String getAlarmType() {
         return this.alarmType;
     }
@@ -41,20 +33,11 @@ public class AlarmEventAction implements RuleEngineAction {
         return this.alarmAttribute;
     }
 
-    public List<AlarmSimpleVO> getDevices() {
-        return this.devices;
-    }
-
     @JsonProperty("alarmGrade")
     public void setAlarmGrade(final Integer alarmGrade) {
         this.alarmGrade = alarmGrade;
     }
 
-    @JsonProperty("productCode")
-    public void setProductCode(final String productCode) {
-        this.productCode = productCode;
-    }
-
     @JsonProperty("alarmType")
     public void setAlarmType(final String alarmType) {
         this.alarmType = alarmType;
@@ -65,11 +48,6 @@ public class AlarmEventAction implements RuleEngineAction {
         this.alarmAttribute = alarmAttribute;
     }
 
-    @JsonProperty("devices")
-    public void setDevices(final List<AlarmSimpleVO> devices) {
-        this.devices = devices;
-    }
-
     public boolean equals(final Object o) {
         if (o == this) {
             return true;
@@ -90,16 +68,6 @@ public class AlarmEventAction implements RuleEngineAction {
                     return false;
                 }
 
-                Object this$productCode = this.getProductCode();
-                Object other$productCode = other.getProductCode();
-                if (this$productCode == null) {
-                    if (other$productCode != null) {
-                        return false;
-                    }
-                } else if (!this$productCode.equals(other$productCode)) {
-                    return false;
-                }
-
                 Object this$alarmType = this.getAlarmType();
                 Object other$alarmType = other.getAlarmType();
                 if (this$alarmType == null) {
@@ -120,16 +88,6 @@ public class AlarmEventAction implements RuleEngineAction {
                     return false;
                 }
 
-                Object this$devices = this.getDevices();
-                Object other$devices = other.getDevices();
-                if (this$devices == null) {
-                    if (other$devices != null) {
-                        return false;
-                    }
-                } else if (!this$devices.equals(other$devices)) {
-                    return false;
-                }
-
                 return true;
             }
         }
@@ -144,20 +102,16 @@ public class AlarmEventAction implements RuleEngineAction {
         int result = 1;
         Object $alarmGrade = this.getAlarmGrade();
         result = result * 59 + ($alarmGrade == null ? 43 : $alarmGrade.hashCode());
-        Object $productCode = this.getProductCode();
-        result = result * 59 + ($productCode == null ? 43 : $productCode.hashCode());
         Object $alarmType = this.getAlarmType();
         result = result * 59 + ($alarmType == null ? 43 : $alarmType.hashCode());
         Object $alarmAttribute = this.getAlarmAttribute();
         result = result * 59 + ($alarmAttribute == null ? 43 : $alarmAttribute.hashCode());
-        Object $devices = this.getDevices();
-        result = result * 59 + ($devices == null ? 43 : $devices.hashCode());
         return result;
     }
 
     public String toString() {
-        return "AlarmEventAction(alarmGrade=" + this.getAlarmGrade() + ", productCode=" + this.getProductCode()
+        return "AlarmEventAction(alarmGrade=" + this.getAlarmGrade()
             + ", alarmType="
-            + this.getAlarmType() + ", alarmAttribute=" + this.getAlarmAttribute() + ", devices=" + this.getDevices() + ")";
+            + this.getAlarmType() + ", alarmAttribute=" + this.getAlarmAttribute() + ")";
     }
 }

+ 3 - 2
service-rule/service-rule-biz/src/main/java/com/usky/rule/vo/log/ActionAlarmEventSerialization.java

@@ -5,6 +5,7 @@ import java.util.Map;
 
 import com.usky.rule.util.JsonUtil;
 import com.usky.rule.vo.visualization.AlarmSimpleVO;
+import com.usky.rule.vo.visualization.SimpleVO;
 import org.springframework.util.CollectionUtils;
 
 public class ActionAlarmEventSerialization implements RuleEngineLogSerialization<AlarmEventLog> {
@@ -39,13 +40,13 @@ public class ActionAlarmEventSerialization implements RuleEngineLogSerialization
                 }
 
                 builder.append(initStr);
-                List<AlarmSimpleVO> notifiers = alarmEventLog.getNotifiers();
+                List<SimpleVO> notifiers = alarmEventLog.getNotifiers();
                 if (!CollectionUtils.isEmpty(notifiers)) {
                     builder.append(",告警设备:");
                 }
 
                 for(int i = 0; i < notifiers.size(); ++i) {
-                    AlarmSimpleVO notifier = (AlarmSimpleVO)notifiers.get(i);
+                    SimpleVO notifier = (SimpleVO)notifiers.get(i);
                     if (i > 0 && i < notifiers.size() - 1) {
                         builder.append("、");
                     }

+ 4 - 3
service-rule/service-rule-biz/src/main/java/com/usky/rule/vo/log/AlarmEventLog.java

@@ -1,13 +1,14 @@
 package com.usky.rule.vo.log;
 
 import com.usky.rule.vo.visualization.AlarmSimpleVO;
+import com.usky.rule.vo.visualization.SimpleVO;
 
 import java.util.List;
 
 public class AlarmEventLog {
     private String level;
     private String method;
-    private List<AlarmSimpleVO> notifiers;
+    private List<SimpleVO> notifiers;
 
     public AlarmEventLog() {
     }
@@ -20,7 +21,7 @@ public class AlarmEventLog {
         return this.method;
     }
 
-    public List<AlarmSimpleVO> getNotifiers() {
+    public List<SimpleVO> getNotifiers() {
         return this.notifiers;
     }
 
@@ -32,7 +33,7 @@ public class AlarmEventLog {
         this.method = method;
     }
 
-    public void setNotifiers(final List<AlarmSimpleVO> notifiers) {
+    public void setNotifiers(final List<SimpleVO> notifiers) {
         this.notifiers = notifiers;
     }
 

+ 27 - 42
service-rule/service-rule-biz/src/main/java/com/usky/rule/vo/log/DeviceTriggerLog.java

@@ -1,30 +1,30 @@
 package com.usky.rule.vo.log;
 
 import com.usky.rule.vo.Condition;
+import com.usky.rule.vo.visualization.SimpleVO;
+import lombok.Data;
+
 import java.util.List;
 
+@Data
 public class DeviceTriggerLog {
-    private String id;
-    private String name;
     private String method;
+    private String productCode;
+    private List<SimpleVO> devices;
     private List<Condition> conditions;
     private String time;
 
     public DeviceTriggerLog() {
     }
 
-    public String getId() {
-        return this.id;
-    }
-
-    public String getName() {
-        return this.name;
-    }
-
     public String getMethod() {
         return this.method;
     }
 
+    public List<SimpleVO> getDevices() {
+        return this.devices;
+    }
+
     public List<Condition> getConditions() {
         return this.conditions;
     }
@@ -33,18 +33,14 @@ public class DeviceTriggerLog {
         return this.time;
     }
 
-    public void setId(final String id) {
-        this.id = id;
-    }
-
-    public void setName(final String name) {
-        this.name = name;
-    }
-
     public void setMethod(final String method) {
         this.method = method;
     }
 
+    public void setDevices(final List<SimpleVO> devices) {
+        this.devices = devices;
+    }
+
     public void setConditions(final List<Condition> conditions) {
         this.conditions = conditions;
     }
@@ -63,25 +59,6 @@ public class DeviceTriggerLog {
             if (!other.canEqual(this)) {
                 return false;
             } else {
-                Object this$id = this.getId();
-                Object other$id = other.getId();
-                if (this$id == null) {
-                    if (other$id != null) {
-                        return false;
-                    }
-                } else if (!this$id.equals(other$id)) {
-                    return false;
-                }
-
-                Object this$name = this.getName();
-                Object other$name = other.getName();
-                if (this$name == null) {
-                    if (other$name != null) {
-                        return false;
-                    }
-                } else if (!this$name.equals(other$name)) {
-                    return false;
-                }
 
                 Object this$method = this.getMethod();
                 Object other$method = other.getMethod();
@@ -93,6 +70,16 @@ public class DeviceTriggerLog {
                     return false;
                 }
 
+                Object this$devices = this.getDevices();
+                Object other$devices = other.getDevices();
+                if (this$devices == null) {
+                    if (other$devices != null) {
+                        return false;
+                    }
+                } else if (!this$devices.equals(other$devices)) {
+                    return false;
+                }
+
                 Object this$conditions = this.getConditions();
                 Object other$conditions = other.getConditions();
                 if (this$conditions == null) {
@@ -125,12 +112,10 @@ public class DeviceTriggerLog {
     public int hashCode() {
         int PRIME = 59;
         int result = 1;
-        Object $id = this.getId();
-        result = result * 59 + ($id == null ? 43 : $id.hashCode());
-        Object $name = this.getName();
-        result = result * 59 + ($name == null ? 43 : $name.hashCode());
         Object $method = this.getMethod();
         result = result * 59 + ($method == null ? 43 : $method.hashCode());
+        Object $devices = this.getDevices();
+        result = result * 59 + ($devices == null ? 43 : $devices.hashCode());
         Object $conditions = this.getConditions();
         result = result * 59 + ($conditions == null ? 43 : $conditions.hashCode());
         Object $time = this.getTime();
@@ -139,6 +124,6 @@ public class DeviceTriggerLog {
     }
 
     public String toString() {
-        return "DeviceTriggerLog(id=" + this.getId() + ", name=" + this.getName() + ", method=" + this.getMethod() + ", conditions=" + this.getConditions() + ", time=" + this.getTime() + ")";
+        return "DeviceTriggerLog(method=" + this.getMethod() + ", devices=" + this.getDevices() + ", conditions=" + this.getConditions() + ", time=" + this.getTime() + ")";
     }
 }

+ 11 - 1
service-rule/service-rule-biz/src/main/java/com/usky/rule/vo/log/TriggerDeviceSerialization.java

@@ -6,8 +6,10 @@ import com.usky.rule.vo.Expression;
 import com.usky.rule.vo.TimeRange;
 import com.usky.rule.vo.log.Content;
 import com.usky.rule.vo.log.DeviceTriggerLog;
+import com.usky.rule.vo.visualization.SimpleVO;
 import java.util.List;
 import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.util.CollectionUtils;
 
 public class TriggerDeviceSerialization implements RuleEngineLogSerialization<DeviceTriggerLog> {
@@ -31,7 +33,15 @@ public class TriggerDeviceSerialization implements RuleEngineLogSerialization<De
 
     static Content getContent(DeviceTriggerLog deviceTriggerLog) {
         Content content = new Content();
-        StringBuilder stringBuilder = (new StringBuilder(deviceTriggerLog.getName())).append(":");
+        String label = "设备";
+        List<SimpleVO> devices = deviceTriggerLog.getDevices();
+        if (!CollectionUtils.isEmpty(devices)) {
+            SimpleVO first = devices.get(0);
+            if (first != null && StringUtils.isNotBlank(first.getName())) {
+                label = first.getName();
+            }
+        }
+        StringBuilder stringBuilder = new StringBuilder(label).append(":");
         List<Condition> conditions = deviceTriggerLog.getConditions();
         String time = deviceTriggerLog.getTime();
         if (!CollectionUtils.isEmpty(conditions)) {

+ 24 - 1
service-rule/service-rule-biz/src/main/java/com/usky/rule/vo/trigger/DeviceTrigger.java

@@ -8,6 +8,8 @@ import java.util.List;
 public class DeviceTrigger {
     @JsonProperty("productId")
     private Long productId;
+    @JsonProperty("productCode")
+    private String productCode;
     @JsonProperty("method")
     private String method;
     @JsonProperty("conditions")
@@ -22,6 +24,10 @@ public class DeviceTrigger {
         return this.productId;
     }
 
+    public String getProductCode() {
+        return this.productCode;
+    }
+
     public String getMethod() {
         return this.method;
     }
@@ -39,6 +45,11 @@ public class DeviceTrigger {
         this.productId = productId;
     }
 
+    @JsonProperty("productCode")
+    public void setProductCode(final String productCode) {
+        this.productCode = productCode;
+    }
+
     @JsonProperty("method")
     public void setMethod(final String method) {
         this.method = method;
@@ -74,6 +85,16 @@ public class DeviceTrigger {
                     return false;
                 }
 
+                Object this$productCode = this.getProductCode();
+                Object other$productCode = other.getProductCode();
+                if (this$productCode == null) {
+                    if (other$productCode != null) {
+                        return false;
+                    }
+                } else if (!this$productCode.equals(other$productCode)) {
+                    return false;
+                }
+
                 Object this$method = this.getMethod();
                 Object other$method = other.getMethod();
                 if (this$method == null) {
@@ -118,6 +139,8 @@ public class DeviceTrigger {
         int result = 1;
         Object $productId = this.getProductId();
         result = result * 59 + ($productId == null ? 43 : $productId.hashCode());
+        Object $productCode = this.getProductCode();
+        result = result * 59 + ($productCode == null ? 43 : $productCode.hashCode());
         Object $method = this.getMethod();
         result = result * 59 + ($method == null ? 43 : $method.hashCode());
         Object $conditions = this.getConditions();
@@ -128,6 +151,6 @@ public class DeviceTrigger {
     }
 
     public String toString() {
-        return "DeviceTrigger(productId=" + this.getProductId() + ", method=" + this.getMethod() + ", conditions=" + this.getConditions() + ", devices=" + this.getDevices() + ")";
+        return "DeviceTrigger(productId=" + this.getProductId() + ", productCode=" + this.getProductCode() + ", method=" + this.getMethod() + ", conditions=" + this.getConditions() + ", devices=" + this.getDevices() + ")";
     }
 }