Commit fc925cd0 by guominglei

插件端工作流保存

parent 961480e6
......@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
......@@ -43,15 +44,77 @@ public class ApiFlowServiceImpl implements ApiFlowService {
@Transactional(rollbackFor = Exception.class)
public void publishFlow(PluginPackage pluginPackage) {
//校验参数
validate(pluginPackage);
Workspace workspace = validate(pluginPackage);
saveFlow(pluginPackage.getFlow(), workspace.getWorkspaceId(), false);
}
/**
* 保存工作流
* @param pluginFlow
* @param isInnner
* @param workspaceId
*/
private void saveFlow(PluginFlow pluginFlow, Integer workspaceId, boolean isInnner) {
Flow flow = new Flow();
flow.setFlowName(pluginFlow.getName());
flow.setIsInner(isInnner ? "0" : "1");
flow.setFlowNodeCount(pluginFlow.getNodeList().size());
flow.setAddTime(new Date());
flow.setAuthor(pluginFlow.getAuthor());
flow.setFlowDesc(pluginFlow.getDesc());
flow.setPrincipal(pluginFlow.getPrincipal());
flow.setStartUp(FlowPropertyEnum.IS_START.getCode());
flow.setExecType(pluginFlow.getConfig().getExecType());
flow.setPriority(pluginFlow.getConfig().getPriority());
flow.setAlarmlAction(pluginFlow.getConfig().getAlarmlAction());
flow.setAlarmEmail(pluginFlow.getConfig().getAlarmEmail());
flow.setRepeatCount(pluginFlow.getConfig().getRepeatCount());
flow.setRemainingCount(pluginFlow.getConfig().getRepeatCount());
flow.setScheduleFollow(pluginFlow.getConfig().getScheduleFollow());
flow.setFlowCron(pluginFlow.getConfig().getFlowCron());
//设置超时时间,未设置默认30分钟
flow.setFlowTimeout(null == pluginFlow.getConfig().getFlowTimeout() ? 1000 * 60 * 30 : pluginFlow.getConfig().getFlowTimeout());
//判断是否是重发
if (pluginFlow.isRePublish()){
Flow oldFlow = flowMapper.getByWorkSpaceAndName(workspaceId, pluginFlow.getName());
String version = oldFlow.getVersionName();
Integer versionTag = Integer.valueOf(version.split(".")[1]);
flow.setFlowId(oldFlow.getFlowId());
flow.setVersionName("V." + (versionTag + 1));
flowMapper.updateByIdSelective(flow);
deleteNodeByFlow(flow.getFlowId());
saveNode(pluginFlow.getNodeList(), flow.getFlowId());
}else {
flow.setVersionName("V.1");
Integer flowId = flowMapper.insertSelective(flow);
saveNode(pluginFlow.getNodeList(), flow.getFlowId());
}
}
/**
* 删除原有工作流下的节点
* @param flowId
*/
private void deleteNodeByFlow(Integer flowId) {
}
/**
* 保存工作流
* @param nodeList
* @param flowId
*/
private void saveNode(List<PluginBaseNode> nodeList, Integer flowId) {
}
/**
* 校验插件端请求参数是否合法
* @param pluginPackage
*/
private void validate(PluginPackage pluginPackage) {
private Workspace validate(PluginPackage pluginPackage) {
ValidationUtil.dataNotBank(pluginPackage.getWorkspaceName(), "工作空间名称不允许为空!");
ValidationUtil.dataNotNull(pluginPackage.getFlow(), "工作流信息不允许为空!");
......@@ -77,6 +140,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
//校验是否存在环路
DagCheckEnum loopCheck = flowDagCheck.checkDag();
ValidationUtil.isTrueValidation(DagCheckEnum.PASS.getCode().equals(loopCheck.getCode()), loopCheck.getMsg());
return workspace;
}
/**
......@@ -136,6 +200,9 @@ public class ApiFlowServiceImpl implements ApiFlowService {
ValidationUtil.dataNotBank(pluginFlow.getConfig().getFlowCron(), "工作流cron表达式不允许为空!");
ValidationUtil.isTrueValidation(CronExpression.isValidExpression(pluginFlow.getConfig().getFlowCron()), "工作流cron表达式不符合规范!");
}
if (!FlowPropertyEnum.NO_ALARML.getCode().equals(pluginFlow.getConfig().getAlarmlAction())){
ValidationUtil.dataNotBank(pluginFlow.getConfig().getAlarmEmail(), "设置告警时机时告警邮箱不允许为空!");
}
Flow flow = flowMapper.getByWorkSpaceAndName(workspaceId, pluginFlow.getName());
//判断是否是重发
//是重发
......
package com.byit.service.impl;
import com.byit.mapper.WorkspaceMapper;
import com.byit.model.Workspace;
import com.byit.service.ApiWorkspaceService;
import com.byit.utils.ValidationUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
/**
* @description: 工作空间操作API的业务逻辑处理实现类
* @author: gml
......@@ -13,8 +19,17 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional(rollbackFor = Exception.class)
public class ApiWorkspaceServiceImpl implements ApiWorkspaceService {
@Resource
private WorkspaceMapper workspaceMapper;
@Override
public void add(String workspaceName) {
ValidationUtil.dataNotBank(workspaceName, "工作空间名称为空!");
Workspace workspace = workspaceMapper.getByName(workspaceName);
ValidationUtil.dataNotNull(workspace, "工作空间已存在!");
workspace = new Workspace();
workspace.setWorkspaceName(workspaceName);
workspace.setAddTime(new Date());
workspaceMapper.insertSelective(workspace);
}
}
......@@ -12,7 +12,11 @@ public enum FlowPropertyEnum {
IS_START("0", "启动"),
NO_START("1", "未启动"),
MANUAL_MODE("2", "手动执行"),
SCHEDULE_MODE("1", "周期执行")
SCHEDULE_MODE("1", "周期执行"),
NO_ALARML("0", "不告警"),
FINISH_ALARML("1", "完成时告警"),
SUCCESS_ALARML("2", "成功时告警"),
FAIL_ALARML("3", "失败时告警"),
;
private String code;
......
......@@ -55,7 +55,7 @@
where flow_id = #{flowId,jdbcType=INTEGER}
</delete>
<insert id="insertSelective" parameterType="com.byit.model.Flow">
<insert id="insertSelective" useGeneratedKeys="true" keyProperty="flowId" parameterType="com.byit.model.Flow">
<!-- generated @mbg.generated date: 2019-12-31 -->
insert into flow
<trim prefix="(" suffix=")" suffixOverrides=",">
......
......@@ -45,4 +45,9 @@ public class PluginFlowConfig {
*/
private String scheduleFollow;
/**
* 工作流的超时时间 毫秒为单位
*/
private Long flowTimeout;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment