Ver Fonte

优化新增规则引擎、修改规则引擎、规则引擎分页、配置规则、手动触发规则五个接口,去除空间和项目的逻辑;

james há 2 semanas atrás
pai
commit
9b53bc2c80

+ 1 - 2
service-rule/service-rule-biz/src/main/java/com/usky/rule/config/CronTaskManager.java

@@ -29,11 +29,10 @@ public class CronTaskManager {
     private Scheduler scheduler;
     private TriggerDeviceUtil triggerDeviceUtil;
 
-    public void addJob(String jobName, String jobGroup, String cronExpression, Class<? extends Job> jobClass, List<CronConstraint> cronConstraintList, List<DeviceConstraint> deviceConstraints, List<RuleEngineAction> actions, Long ruleEngineId, Long projectId) {
+    public void addJob(String jobName, String jobGroup, String cronExpression, Class<? extends Job> jobClass, List<CronConstraint> cronConstraintList, List<DeviceConstraint> deviceConstraints, List<RuleEngineAction> actions, Long ruleEngineId) {
         JobDataMap jobDataMap = new JobDataMap();
         jobDataMap.put("actions", actions);
         jobDataMap.put("ruleEngineId", ruleEngineId);
-        jobDataMap.put("projectId", projectId);
         JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(jobName, jobGroup).usingJobData(jobDataMap).build();
         CronTrigger cronTrigger = (CronTrigger)TriggerBuilder.newTrigger().withIdentity(jobName, jobGroup).withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build();
 

+ 6 - 6
service-rule/service-rule-biz/src/main/java/com/usky/rule/crons/TriggerCronTask.java

@@ -53,7 +53,7 @@ public class TriggerCronTask implements ApplicationContextAware, InitializingBea
                 if (cronTriggers != null) {
                     cronTriggers = (List)cronTriggers.stream().filter((cronTrigger) -> CronUtil.isCronMatched(cronTrigger.getCron())).collect(Collectors.toList());
                     if (!cronTriggers.isEmpty()) {
-                        this.processCronTask(ruleEngine.getId(), ruleEngine.getProjectId(), ruleEngineDetail, cronTriggers);
+                        this.processCronTask(ruleEngine.getId(), ruleEngineDetail, cronTriggers);
                     }
                 }
 
@@ -75,7 +75,7 @@ public class TriggerCronTask implements ApplicationContextAware, InitializingBea
                 String detail = this.ruleEngineService.getDetail(Long.valueOf(idAndProjectId[0]));
                 if (StringUtils.isNotEmpty(detail)) {
                     RuleEngineDetail ruleEngineDetail = (RuleEngineDetail)JsonUtil.toObject(detail, RuleEngineDetail.class);
-                    this.processCronTask(ruleEngineId, projectId, ruleEngineDetail, list);
+                    this.processCronTask(ruleEngineId, ruleEngineDetail, list);
                 }
 
             });
@@ -117,23 +117,23 @@ public class TriggerCronTask implements ApplicationContextAware, InitializingBea
         }
     }
 
-    private void processCronTask(Long id, Long projectId, RuleEngineDetail engineDetail, List<CronTrigger> cronTriggers) {
+    private void processCronTask(Long id, RuleEngineDetail engineDetail, List<CronTrigger> cronTriggers) {
         List<CronConstraint> cronConstraints = this.ruleEngineService.getCronConstraints(engineDetail.getConstraints());
         List<DeviceConstraint> deviceConstraints = this.ruleEngineService.getDeviceConstraints(engineDetail.getConstraints());
         List<RuleEngineAction> actions = this.ruleEngineService.getActions(engineDetail.getActions());
         if (actions != null && !actions.isEmpty()) {
-            addCronJob(id, projectId, cronTriggers, cronConstraints, deviceConstraints, actions, this.cronTaskManager);
+            addCronJob(id, cronTriggers, cronConstraints, deviceConstraints, actions, this.cronTaskManager);
         }
 
     }
 
-    public static void addCronJob(Long ruleEngineId, Long projectId, List<CronTrigger> cronTriggers, List<CronConstraint> cronConstraints, List<DeviceConstraint> deviceConstraints, List<RuleEngineAction> actions, CronTaskManager cronTaskManager) {
+    public static void addCronJob(Long ruleEngineId, List<CronTrigger> cronTriggers, List<CronConstraint> cronConstraints, List<DeviceConstraint> deviceConstraints, List<RuleEngineAction> actions, CronTaskManager cronTaskManager) {
         String jobGroup = RuleEngineUtil.getJobGroup(ruleEngineId);
 
         for(int i = 0; i < cronTriggers.size(); ++i) {
             CronTrigger cronTrigger = (CronTrigger)cronTriggers.get(i);
             String jobName = RuleEngineUtil.getTriggerCronJobName(i);
-            cronTaskManager.addJob(jobName, jobGroup, cronTrigger.getCron(), CommonJob.class, cronConstraints, deviceConstraints, actions, ruleEngineId, projectId);
+            cronTaskManager.addJob(jobName, jobGroup, cronTrigger.getCron(), CommonJob.class, cronConstraints, deviceConstraints, actions, ruleEngineId);
         }
 
     }

+ 0 - 4
service-rule/service-rule-biz/src/main/java/com/usky/rule/domain/RuleEngine.java

@@ -15,7 +15,6 @@ import java.util.Date;
 @Data
 public class RuleEngine implements Serializable {
     private Long id;
-    private Long projectId;
     private String name;
     /** 规则状态 1:启用 0:停用 */
     private Integer status;
@@ -33,7 +32,4 @@ public class RuleEngine implements Serializable {
      * 租户号
      */
     private Integer tenantId;
-
-    @TableField(exist = false)
-    private String spaceName;
 }

+ 0 - 1
service-rule/service-rule-biz/src/main/java/com/usky/rule/domain/RuleEngineLog.java

@@ -12,7 +12,6 @@ import java.util.Date;
 @Data
 public class RuleEngineLog {
     private Long id;
-    private Long projectId;
     private Long ruleEngineId;
     private String ruleEngineName;
     /** 自动触发 0:否 1:是 */

+ 1 - 2
service-rule/service-rule-biz/src/main/java/com/usky/rule/jobs/CommonJob.java

@@ -29,7 +29,6 @@ public class CommonJob implements Job {
     public void execute(JobExecutionContext context) {
         JobDataMap dataMap = context.getJobDetail().getJobDataMap();
         Long ruleEngineId = (Long)dataMap.get("ruleEngineId");
-        Long projectId = (Long)dataMap.get("projectId");
         List<RuleEngineAction> actions = (List)dataMap.get("actions");
         RuleEngineDetailLog detail = (RuleEngineDetailLog)context.get("detail");
         if (detail == null) {
@@ -38,6 +37,6 @@ public class CommonJob implements Job {
         }
         log.info("commonJob start ruleEngineId: {}, detail: {}", ruleEngineId, detail);
 
-        this.ruleEngineUtil.performMultipleDevicesControl(ruleEngineId, true, TriggerTypeEnum.CRON.getType(), projectId, actions, detail);
+        this.ruleEngineUtil.performMultipleDevicesControl(ruleEngineId, true, TriggerTypeEnum.CRON.getType(), actions, detail);
     }
 }

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

@@ -157,7 +157,7 @@ public class ConsumptionJob implements Job {
                     if (cronOk && deviceOk) {
 
                         log.info("ConsumptionJob constraints satisfied engineId: {}, actions: {}", engineId, actions);
-                        this.ruleEngineUtil.performMultipleDevicesControl(engineId, true, TriggerTypeEnum.DEVICE.getType(), ruleEngine.getProjectId(), actions, ruleEngineDetailLog);
+                        this.ruleEngineUtil.performMultipleDevicesControl(engineId, true, TriggerTypeEnum.DEVICE.getType(), actions, ruleEngineDetailLog);
                     }
                 }
             }

+ 4 - 4
service-rule/service-rule-biz/src/main/java/com/usky/rule/service/impl/RuleEngineDetailServiceImpl.java

@@ -55,13 +55,13 @@ public class RuleEngineDetailServiceImpl implements RuleEngineDetailService {
         if (cronTriggers != null) {
             List<CronConstraint> cronConstraints = this.ruleEngineService.getCronConstraints(ruleEngineDetail.getConstraints());
             List<DeviceConstraint> deviceConstraints = this.ruleEngineService.getDeviceConstraints(ruleEngineDetail.getConstraints());
-            this.addRuleEngineJobs(dto.getId(), dto.getProjectId(), actions, cronTriggers, cronConstraints, deviceConstraints);
+            this.addRuleEngineJobs(dto.getId(), actions, cronTriggers, cronConstraints, deviceConstraints);
         }
 
     }
 
-    private void addRuleEngineJobs(Long id, Long projectId, List<RuleEngineAction> actions, List<CronTrigger> cronTriggers, List<CronConstraint> cronConstraints, List<DeviceConstraint> deviceConstraints) {
-        TriggerCronTask.addCronJob(id, projectId, cronTriggers, cronConstraints, deviceConstraints, actions, this.cronTaskManager);
+    private void addRuleEngineJobs(Long id, List<RuleEngineAction> actions, List<CronTrigger> cronTriggers, List<CronConstraint> cronConstraints, List<DeviceConstraint> deviceConstraints) {
+        TriggerCronTask.addCronJob(id, cronTriggers, cronConstraints, deviceConstraints, actions, this.cronTaskManager);
     }
 
     public Boolean update(RuleEngineDTO dto) {
@@ -84,7 +84,7 @@ public class RuleEngineDetailServiceImpl implements RuleEngineDetailService {
         } else {
             List<RuleEngineAction> actions = this.ruleEngineService.getActions(ruleEngineDetail.getActions());
             if (actions != null && !actions.isEmpty()) {
-                this.ruleEngineUtil.performMultipleDevicesControl(id, false, TriggerTypeEnum.DEVICE.getType(), ruleEngine.getProjectId(), actions, new RuleEngineDetailLog());
+                this.ruleEngineUtil.performMultipleDevicesControl(id, false, TriggerTypeEnum.DEVICE.getType(), actions, new RuleEngineDetailLog());
                 return true;
             } else {
                 return true;

+ 0 - 2
service-rule/service-rule-biz/src/main/java/com/usky/rule/service/impl/RuleEngineServiceImpl.java

@@ -185,7 +185,6 @@ public class RuleEngineServiceImpl extends AbstractCrudService<RuleEngineMapper,
         RuleEngineDTO engineDTO = new RuleEngineDTO();
         engineDTO.setId(id);
         engineDTO.setStatus(engine.getStatus() == 1 ? 0 : 1);
-        engineDTO.setProjectId(engine.getProjectId());
         engineDTO.setName(engine.getName());
         engineDTO.setDetail(engine.getDetail());
         getBaseMapper().updateStatus(id, status);
@@ -271,7 +270,6 @@ public class RuleEngineServiceImpl extends AbstractCrudService<RuleEngineMapper,
 
             RuleEngineDTO engineDTO = new RuleEngineDTO();
             engineDTO.setId(rule.getId());
-            engineDTO.setProjectId(rule.getProjectId());
             engineDTO.setName(rule.getName());
             engineDTO.setStatus(rule.getStatus());
             engineDTO.setDetail(rule.getDetail());

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

@@ -124,7 +124,7 @@ public class TriggerDeviceUtil {
                                         boolean deviceOk = this.meetConstraintAction(deviceConstraints, ruleEngineDetailLog);
                                         if (cronOk && deviceOk) {
                                             log.info("ruleEngineId={} constraints satisfied, executing actions", ruleEngineId);
-                                            this.ruleEngineUtil.performMultipleDevicesControl(ruleEngineId, true, TriggerTypeEnum.DEVICE.getType(), ruleEngine.getProjectId(), actions, ruleEngineDetailLog);
+                                            this.ruleEngineUtil.performMultipleDevicesControl(ruleEngineId, true, TriggerTypeEnum.DEVICE.getType(), actions, ruleEngineDetailLog);
                                             this.clearMeetConditionCache(ruleEngineId, deviceId, meetMinuteExpressionMap);
                                             this.deviceAcqTriggerCooldownCache.startCooldown(ruleEngineId, deviceId, this.deviceAcqCooldownSeconds);
                                         } else if (!cronOk) {

+ 3 - 5
service-rule/service-rule-biz/src/main/java/com/usky/rule/util/RuleEngineUtil.java

@@ -54,7 +54,7 @@ public class RuleEngineUtil {
         return "job-" + index;
     }
 
-    public void performMultipleDevicesControl(Long ruleEngineId, boolean isAuto, String triggerType, Long projectId, List<RuleEngineAction> actionList, RuleEngineDetailLog ruleEngineDetail) {
+    public void performMultipleDevicesControl(Long ruleEngineId, boolean isAuto, String triggerType, List<RuleEngineAction> actionList, RuleEngineDetailLog ruleEngineDetail) {
         List<BaseLog> baseLogs = new ArrayList();
         ruleEngineDetail.setActions(baseLogs);
         LocalDateTime now = LocalDateTime.now();
@@ -75,7 +75,7 @@ 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, projectId, Collections.singletonList(ruleEngineAction));
+                this.generateAlarmEvent(ruleEngineId, ruleEngineName, Collections.singletonList(ruleEngineAction));
                 deviceActionTypes.add("alarmEvent");
                 BaseLog baseLog = new BaseLog();
                 baseLog.setType(ActionTypeEnum.ALARM_EVENT.getType());
@@ -89,7 +89,6 @@ public class RuleEngineUtil {
         ruleEngineLog.setRuleEngineId(ruleEngineId);
         ruleEngineLog.setRuleEngineName(ruleEngineName);
         ruleEngineLog.setAutoTrigger((byte) (isAuto ? 1 : 0));
-        ruleEngineLog.setProjectId(projectId);
         ruleEngineLog.setAction(String.join(",", deviceActionTypes));
         ruleEngineLog.setTriggerType(triggerType);
         ruleEngineLog.setUpdateTime(now);
@@ -124,10 +123,9 @@ public class RuleEngineUtil {
      * 推送告警
      * @param ruleEngineId
      * @param ruleEngineName
-     * @param projectId
      * @param actions
      */
-    public void generateAlarmEvent(Long ruleEngineId, String ruleEngineName, Long projectId, List<RuleEngineAction> actions) {
+    public void generateAlarmEvent(Long ruleEngineId, String ruleEngineName, List<RuleEngineAction> actions) {
         for(RuleEngineAction ruleEngineAction : actions) {
             AlarmEventAction alarmEventAction = (AlarmEventAction)ruleEngineAction;
             List<AlarmSimpleVO> devices = alarmEventAction.getDevices();

+ 2 - 25
service-rule/service-rule-biz/src/main/java/com/usky/rule/vo/RuleEngineDTO.java

@@ -19,8 +19,6 @@ public class RuleEngineDTO implements Serializable {
             groups = {GroupUpdate.class},
             message = "id不能为空"
     ) Long id;
-    @ApiModelProperty("项目ID")
-    private Long projectId;
     @ApiModelProperty("名称")
     private @NotEmpty(
             groups = {GroupUpdate.class, GroupInsert.class},
@@ -48,10 +46,6 @@ public class RuleEngineDTO implements Serializable {
         return this.id;
     }
 
-    public Long getProjectId() {
-        return this.projectId;
-    }
-
     public String getName() {
         return this.name;
     }
@@ -76,10 +70,6 @@ public class RuleEngineDTO implements Serializable {
         this.id = id;
     }
 
-    public void setProjectId(final Long projectId) {
-        this.projectId = projectId;
-    }
-
     public void setName(final String name) {
         this.name = name;
     }
@@ -120,16 +110,6 @@ public class RuleEngineDTO implements Serializable {
                     return false;
                 }
 
-                Object this$projectId = this.getProjectId();
-                Object other$projectId = other.getProjectId();
-                if (this$projectId == null) {
-                    if (other$projectId != null) {
-                        return false;
-                    }
-                } else if (!this$projectId.equals(other$projectId)) {
-                    return false;
-                }
-
                 Object this$status = this.getStatus();
                 Object other$status = other.getStatus();
                 if (this$status == null) {
@@ -184,8 +164,6 @@ public class RuleEngineDTO implements Serializable {
         int result = 1;
         Object $id = this.getId();
         result = result * 59 + ($id == null ? 43 : $id.hashCode());
-        Object $projectId = this.getProjectId();
-        result = result * 59 + ($projectId == null ? 43 : $projectId.hashCode());
         Object $status = this.getStatus();
         result = result * 59 + ($status == null ? 43 : $status.hashCode());
         Object $name = this.getName();
@@ -198,7 +176,7 @@ public class RuleEngineDTO implements Serializable {
     }
 
     public String toString() {
-        return "RuleEngineDTO(id=" + this.getId() + ", projectId=" + this.getProjectId() + ", name=" + this.getName() + ", status=" + this.getStatus() + ", descr=" + this.getDescr() + ", detail=" + this.getDetail() + ")";
+        return "RuleEngineDTO(id=" + this.getId() + ", name=" + this.getName() + ", status=" + this.getStatus() + ", descr=" + this.getDescr() + ", detail=" + this.getDetail() + ")";
     }
 
     public RuleEngineDTO(final @NotNull(
@@ -209,7 +187,6 @@ public class RuleEngineDTO implements Serializable {
             message = "空间不能为空"
     )  Integer status, final String descr, final String detail) {
         this.id = id;
-        this.projectId = projectId;
         this.name = name;
         this.status = status;
         this.descr = descr;
@@ -271,7 +248,7 @@ public class RuleEngineDTO implements Serializable {
         }
 
         public String toString() {
-            return "RuleEngineDTO.RuleEngineDTOBuilder(id=" + this.id + ", projectId=" + this.projectId + ", name=" + this.name + ", status=" + this.status + ", descr=" + this.descr + ", detail=" + this.detail + ")";
+            return "RuleEngineDTO.RuleEngineDTOBuilder(id=" + this.id + ", name=" + this.name + ", status=" + this.status + ", descr=" + this.descr + ", detail=" + this.detail + ")";
         }
     }
 }

+ 0 - 1
service-rule/service-rule-biz/src/main/java/com/usky/rule/vo/RuleEnginePageRequest.java

@@ -9,7 +9,6 @@ import lombok.Data;
 public class RuleEnginePageRequest {
     private Integer pageNum = 1;
     private Integer pageSize = 10;
-    private Long projectId;
     /** 名称模糊 */
     private String name;
     /** 状态 0/1 */

+ 2 - 2
service-rule/service-rule-biz/src/main/resources/mapper/RuleEngineCronMapper.xml

@@ -26,8 +26,8 @@
         <result column="name" property="ruleEngineName"/>
     </resultMap>
     <select id="getTurnedOnCron" resultMap="TurnedOnCronVO">
-        SELECT rec.id, rec.rule_engine_id, rec.cron, re.project_id, re.space_id, re.name, re.detail
+        SELECT rec.id, rec.rule_engine_id, rec.cron, re.name, re.detail
         FROM rule_engine_cron rec
-        JOIN (SELECT id, name, detail, project_id, space_id FROM rule_engine WHERE status = 1) re ON rec.rule_engine_id = re.id
+        JOIN (SELECT id, name, detail FROM rule_engine WHERE status = 1) re ON rec.rule_engine_id = re.id
     </select>
 </mapper>

+ 2 - 3
service-rule/service-rule-biz/src/main/resources/mapper/RuleEngineLogMapper.xml

@@ -3,7 +3,6 @@
 <mapper namespace="com.usky.rule.mapper.RuleEngineLogMapper">
     <resultMap id="Base" type="com.usky.rule.domain.RuleEngineLog">
         <id column="id" property="id"/>
-        <result column="project_id" property="projectId"/>
         <result column="rule_engine_id" property="ruleEngineId"/>
         <result column="rule_engine_name" property="ruleEngineName"/>
         <result column="auto_trigger" property="autoTrigger"/>
@@ -20,8 +19,8 @@
     </resultMap>
 
     <insert id="insert" useGeneratedKeys="true" keyProperty="id">
-        INSERT INTO rule_engine_log (project_id, rule_engine_id, rule_engine_name, auto_trigger, trigger_type, action, detail, content, time, created_by, create_time, updated_by, update_time, tenant_id)
-        VALUES (#{projectId}, #{ruleEngineId}, #{ruleEngineName}, #{autoTrigger}, #{triggerType}, #{action}, #{detail}, #{content}, #{time}, #{createdBy}, NOW(), #{updatedBy}, NOW(), #{tenantId})
+        INSERT INTO rule_engine_log (rule_engine_id, rule_engine_name, auto_trigger, trigger_type, action, detail, content, time, created_by, create_time, updated_by, update_time, tenant_id)
+        VALUES (#{ruleEngineId}, #{ruleEngineName}, #{autoTrigger}, #{triggerType}, #{action}, #{detail}, #{content}, #{time}, #{createdBy}, NOW(), #{updatedBy}, NOW(), #{tenantId})
     </insert>
     <update id="updateById">
         UPDATE rule_engine_log SET content=#{content}, detail=#{detail}, updated_by=#{updatedBy}, update_time=NOW() WHERE id=#{id}