当前位置: 首页 > 工具软件 > LiteFlow > 使用案例 >

LiteFlow使用

章睿
2023-12-01
LiteFlow.xml
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<!--预案确认后-->
<chain name="planExecFlowConfirmAfter">
    <!--查询预案信息并组装VO方便一下逻辑运算-->
    <then value="selectPlan"/>
    <!--查看此预案之前是否有其他预案正在执行-->
    <then value="planBeforeStop"/>
    <!--修改预案状态为待执行-->
    <then value="updatePlanReserveDetail"/>
    <!--异步执行 预案设备任务,预案人员任务-->
    <when value="planTaskDevice,planTaskPeople" any="false"/>
    <!--websocket推送任务信息-->
    <then value="websocketTaskDetail"/>
</chain>

LiteComponent接口
package com.metro.modules.plan.liteflow.common;

/**

  • 组件id和名称
    */

     public interface LiteComponent {
    
     interface PlanLite {
     // 执行器名称
     
     String PLAN_EXEC_FLOW_CONFIRM_AFTER="planExecFlowConfirmAfter";
     	
    
     String SELECT_PLAN = "selectPlan";
     String SELECT_PLAN_NAME = "设置预案参数";
    
     String PLAN_RULE = "planRule";
     String PLAN_RULE_NAME = "判断预案规则";
    
     String PLAN_BEFORE = "planBeforeStop";
     String PLAN_BEFORE_NAME = "检查此预案之前是否有其他预案正在执行";
    
     String PLAN_TASK_DEVICE = "planTaskDevice";
     String PLAN_TASK_DEVICE_NAME = "预案设备任务";
    
     String PLAN_TASK_PEOPLE = "planTaskPeople";
     String PLAN_TASK_PEOPLE_NAME = "预案人员任务";
    
     String INSERT_NEW_PLAN_RESERVE_DETAIL = "insertNewPlanReserveDetail";
     String INSERT_NEW_PLAN_RESERVE_DETAIL_NAME = "插入预案手动执行记录";
    
     String INSERT_CONDITION_NEW_PLAN_RESERVE_DETAIL = "insertConditionNewPlanReserveDetail";
     String INSERT_CONDITION_NEW_PLAN_RESERVE_DETAIL_NAME = "插入条件预案执行记录";
    
     String INSERT_TIME_NEW_PLAN_RESERVE_DETAIL = "insertTimePlanReserveDetail";
     String INSERT_TIME_NEW_PLAN_RESERVE_DETAIL_NAME = "插入定时预案执行记录";
    
     String UPDATE_PLAN_RESERVE_DETAIL = "updatePlanReserveDetail";
     String UPDATE_PLAN_RESERVE_DETAIL_NAME = "修改预案状态为待执行";
    
     String WEBSOCKET_TASK_DETAIL = "websocketTaskDetail";
     String WEBSOCKET_TASK_DETAIL_NAME = "websocket推送任务信息";
     }
    

    接口实现

     @GetMapping("/planExecute")
     @ApiOperationSupport(order = 14)
     @ApiOperation(value = "管理端预案确认执行", notes = "管理端预案确认执行")
     public R planExecute(
     	@ApiParam(name = "id", value = "预案ID", required = true) @RequestParam(value = "id") Long id,
     	@ApiParam(name = "dialogTime", value = "web弹窗时间", required = true) 	@RequestParam(value = "dialogTime") Date dialogTime) {
     		
     ExecParams execParams = new ExecParams();
    
     execParams.setId(id);
     execParams.setDialogTime(dialogTime);
     execParams.setUserId(null);
    
     LiteflowResponse<ExecSlot> response = flowExecutor.execute2Resp(LiteComponent.PlanLite.PLAN_EXEC_FLOW_CONFIRM_AFTER,execParams, ExecSlot.class);
     ExecSlot slot = response.getSlot();
    
     log.info("管理端预案确认执行结束: {}", slot.toString());
     if (!slot.isFlag()) {
     	R.fail(500, slot.getMessage());
     }
     return R.success(slot.getMessage());
     }
    

每个类的实现

@Slf4j
@LiteflowComponent(id = LiteComponent.PlanLite.PLAN_BEFORE, name = LiteComponent.PlanLite.PLAN_BEFORE_NAME)
@AllArgsConstructor
public class PlanBeforeStopComponent extends NodeComponent {

private final IPlanReserveDetailService planReserveDetailService;
private final ITaskManageService iTaskManageService;
private final IPlanReserveDetailDeviceService iPlanReserveDetailDeviceService;

@Override
public boolean isAccess() {
    ExecSlot slot = this.getSlot();
    PlanManage planManage = slot.getPlanManage();
    if (PlanConst.Num.num1 == planManage.getPlanCategory()) {
        return true;
    }
    log.info("[执行预案LITE]执行的预案类型!=1,不进行暂停");
    return false;
}

@Override
public void process() {
    log.info("[执行预案LITE]检查此预案之前是否有其他预案正在执行");

    ExecSlot slot = this.getSlot();

	//查询数据
	List<PlanManageTask>  planManageTaskList=planManageTaskervice.list()
	solt.setpPanManageTaskList(planManageTaskList);
  }

ExecSlot data数据

@Data
public class ExecSlot extends AbsSlot {
// 是否执行成功
private boolean flag = true;
// 执行信息反馈
private String message = "执行成功";
// 预案信息
private PlanManage planManage;
// 预案规则信息
private List<PlanManageRule> planManageRuleList;
// 预案任务
private List<PlanManageTask> planManageTaskList;
// 预案任务设施
private Map<Long, List<PlanManageTaskFacility>> planManageTaskFacilityMap;
// 之前预案的设施
private List<PlanManageTaskFacility> previousTaskFacilityList;
// 生成的任务数据
private List<TaskManage> taskManageList;

// 预案执行记录
private PlanReserveDetail planReserveDetail;

public void setFlagAndMessage(boolean flag, String message) {
	this.flag = flag;
	this.message = message;
}

}
 类似资料: