From 1e685a7e4b622c583939041a722da5ac987832b1 Mon Sep 17 00:00:00 2001
From: "1437892690@qq.com" <1437892690@qq.com>
Date: Fri, 21 Jun 2024 12:11:28 +0800
Subject: [PATCH 1/8] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-?=
=?UTF-8?q?=E6=96=B0=E8=87=AA=E5=8A=A8=E5=8C=96=E8=8A=82=E7=82=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
#[1181690880294912]后端-新自动化节点 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1181690880294912
---
.../api/process/CreateJobStepTestApi.java | 70 ++
.../CreateJobProcessStepHandlerType.java | 52 +
.../process/dto/CreateJobConfigConfigVo.java | 152 +++
.../process/dto/CreateJobConfigFilterVo.java | 84 ++
.../dto/CreateJobConfigMappingGroupVo.java | 60 +
.../process/dto/CreateJobConfigMappingVo.java | 77 ++
.../process/dto/CreateJobConfigVo.java | 52 +
.../CreateJobProcessComponent.java | 586 +++++++++
.../CreateJobProcessUtilHandler.java | 249 ++++
.../util/ParseCreateJobConfigUtil.java | 1118 +++++++++++++++++
10 files changed, 2500 insertions(+)
create mode 100644 src/main/java/neatlogic/module/autoexec/api/process/CreateJobStepTestApi.java
create mode 100644 src/main/java/neatlogic/module/autoexec/process/constvalue/CreateJobProcessStepHandlerType.java
create mode 100644 src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigConfigVo.java
create mode 100644 src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigFilterVo.java
create mode 100644 src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigMappingGroupVo.java
create mode 100644 src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigMappingVo.java
create mode 100644 src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigVo.java
create mode 100644 src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessComponent.java
create mode 100644 src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessUtilHandler.java
create mode 100644 src/main/java/neatlogic/module/autoexec/process/util/ParseCreateJobConfigUtil.java
diff --git a/src/main/java/neatlogic/module/autoexec/api/process/CreateJobStepTestApi.java b/src/main/java/neatlogic/module/autoexec/api/process/CreateJobStepTestApi.java
new file mode 100644
index 00000000..66c4e9ed
--- /dev/null
+++ b/src/main/java/neatlogic/module/autoexec/api/process/CreateJobStepTestApi.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.module.autoexec.api.process;
+
+import com.alibaba.fastjson.JSONObject;
+import neatlogic.framework.autoexec.dto.job.AutoexecJobVo;
+import neatlogic.framework.common.constvalue.ApiParamType;
+import neatlogic.framework.process.dto.ProcessTaskStepVo;
+import neatlogic.framework.restful.annotation.Input;
+import neatlogic.framework.restful.annotation.OperationType;
+import neatlogic.framework.restful.annotation.Output;
+import neatlogic.framework.restful.annotation.Param;
+import neatlogic.framework.restful.constvalue.OperationTypeEnum;
+import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase;
+import neatlogic.module.autoexec.process.dto.CreateJobConfigConfigVo;
+import neatlogic.module.autoexec.process.util.ParseCreateJobConfigUtil;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@OperationType(type = OperationTypeEnum.SEARCH)
+public class CreateJobStepTestApi extends PrivateApiComponentBase {
+ @Override
+ public String getName() {
+ return "测试新自动化节点";
+ }
+
+ @Input({
+ @Param(name = "processTaskId", type = ApiParamType.LONG, isRequired = true, desc = "工单ID"),
+ @Param(name = "createJobConfigConfig", type = ApiParamType.JSONOBJECT, isRequired = true, desc = "配置信息")
+ })
+ @Output({
+ @Param(name = "Return", type = ApiParamType.JSONOBJECT)
+ })
+ @Override
+ public Object myDoService(JSONObject paramObj) throws Exception {
+ Long processTaskId = paramObj.getLong("processTaskId");
+ JSONObject createJobConfigConfig = paramObj.getJSONObject("createJobConfigConfig");
+ ProcessTaskStepVo processTaskStepVo = new ProcessTaskStepVo();
+ processTaskStepVo.setProcessTaskId(processTaskId);
+ processTaskStepVo.setId(1L);
+ CreateJobConfigConfigVo createJobConfigConfigVo = createJobConfigConfig.toJavaObject(CreateJobConfigConfigVo.class);
+ List autoexecJobList = ParseCreateJobConfigUtil.createAutoexecJobList(processTaskStepVo, createJobConfigConfigVo);
+ System.out.println("autoexecJobList = " + JSONObject.toJSONString(autoexecJobList));
+ JSONObject resultObj = new JSONObject();
+ resultObj.put("autoexecJobList", autoexecJobList);
+ return resultObj;
+ }
+
+ @Override
+ public String getToken() {
+ return "create/job/step/test";
+ }
+}
diff --git a/src/main/java/neatlogic/module/autoexec/process/constvalue/CreateJobProcessStepHandlerType.java b/src/main/java/neatlogic/module/autoexec/process/constvalue/CreateJobProcessStepHandlerType.java
new file mode 100644
index 00000000..66056845
--- /dev/null
+++ b/src/main/java/neatlogic/module/autoexec/process/constvalue/CreateJobProcessStepHandlerType.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.module.autoexec.process.constvalue;
+
+import neatlogic.framework.process.stephandler.core.IProcessStepHandlerType;
+
+/**
+ * @author linbq
+ * @since 2021/9/2 14:40
+ **/
+public enum CreateJobProcessStepHandlerType implements IProcessStepHandlerType {
+ CREATE_JOB("createjob", "process", "创建作业"),
+ ;
+ private String handler;
+ private String name;
+ private String type;
+
+ CreateJobProcessStepHandlerType(String handler, String type, String name) {
+ this.handler = handler;
+ this.name = name;
+ this.type = type;
+ }
+ @Override
+ public String getHandler() {
+ return handler;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+}
diff --git a/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigConfigVo.java b/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigConfigVo.java
new file mode 100644
index 00000000..32e6c51f
--- /dev/null
+++ b/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigConfigVo.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.module.autoexec.process.dto;
+
+import java.util.List;
+
+public class CreateJobConfigConfigVo {
+
+// private Long id;
+ private Long combopId;
+
+ private String combopName;
+
+ private String createPolicy;
+
+ private String jobNamePrefixMappingValue;
+
+ private String jobName;
+
+ private String formTag;
+
+// private CreateJobConfigMappingGroupVo runnerGroupMappingGroup;
+
+ private List jopParamMappingGroupList;
+
+ private List executeParamMappingGroupList;
+
+ private CreateJobConfigMappingVo batchDataSourceMapping;
+
+ private List formAttributeMappingGroupList;
+
+ private List scenarioParamMappingGroupList;
+
+// public Long getId() {
+// return id;
+// }
+//
+// public void setId(Long id) {
+// this.id = id;
+// }
+
+ public Long getCombopId() {
+ return combopId;
+ }
+
+ public void setCombopId(Long combopId) {
+ this.combopId = combopId;
+ }
+
+ public String getCombopName() {
+ return combopName;
+ }
+
+ public void setCombopName(String combopName) {
+ this.combopName = combopName;
+ }
+
+ public String getCreatePolicy() {
+ return createPolicy;
+ }
+
+ public void setCreatePolicy(String createPolicy) {
+ this.createPolicy = createPolicy;
+ }
+
+ public String getJobNamePrefixMappingValue() {
+ return jobNamePrefixMappingValue;
+ }
+
+ public void setJobNamePrefixMappingValue(String jobNamePrefixMappingValue) {
+ this.jobNamePrefixMappingValue = jobNamePrefixMappingValue;
+ }
+
+ public String getJobName() {
+ return jobName;
+ }
+
+ public void setJobName(String jobName) {
+ this.jobName = jobName;
+ }
+
+// public CreateJobConfigMappingGroupVo getRunnerGroupMappingGroup() {
+// return runnerGroupMappingGroup;
+// }
+//
+// public void setRunnerGroupMappingGroup(CreateJobConfigMappingGroupVo runnerGroupMappingGroup) {
+// this.runnerGroupMappingGroup = runnerGroupMappingGroup;
+// }
+
+ public List getJopParamMappingGroupList() {
+ return jopParamMappingGroupList;
+ }
+
+ public void setJopParamMappingGroupList(List jopParamMappingGroupList) {
+ this.jopParamMappingGroupList = jopParamMappingGroupList;
+ }
+
+ public List getExecuteParamMappingGroupList() {
+ return executeParamMappingGroupList;
+ }
+
+ public void setExecuteParamMappingGroupList(List executeParamMappingGroupList) {
+ this.executeParamMappingGroupList = executeParamMappingGroupList;
+ }
+
+ public CreateJobConfigMappingVo getBatchDataSourceMapping() {
+ return batchDataSourceMapping;
+ }
+
+ public void setBatchDataSourceMapping(CreateJobConfigMappingVo batchDataSourceMapping) {
+ this.batchDataSourceMapping = batchDataSourceMapping;
+ }
+
+ public List getFormAttributeMappingGroupList() {
+ return formAttributeMappingGroupList;
+ }
+
+ public void setFormAttributeMappingGroupList(List formAttributeMappingGroupList) {
+ this.formAttributeMappingGroupList = formAttributeMappingGroupList;
+ }
+
+ public List getScenarioParamMappingGroupList() {
+ return scenarioParamMappingGroupList;
+ }
+
+ public void setScenarioParamMappingGroupList(List scenarioParamMappingGroupList) {
+ this.scenarioParamMappingGroupList = scenarioParamMappingGroupList;
+ }
+
+ public String getFormTag() {
+ return formTag;
+ }
+
+ public void setFormTag(String formTag) {
+ this.formTag = formTag;
+ }
+}
diff --git a/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigFilterVo.java b/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigFilterVo.java
new file mode 100644
index 00000000..b41dc227
--- /dev/null
+++ b/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigFilterVo.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.module.autoexec.process.dto;
+
+public class CreateJobConfigFilterVo {
+ private String leftMappingMode;
+ private String leftValue;
+ private String leftColumn;
+ private String expression;
+ private String rightMappingMode;
+ private String rightValue;
+ private String rightColumn;
+
+ public String getLeftMappingMode() {
+ return leftMappingMode;
+ }
+
+ public void setLeftMappingMode(String leftMappingMode) {
+ this.leftMappingMode = leftMappingMode;
+ }
+
+ public String getLeftValue() {
+ return leftValue;
+ }
+
+ public void setLeftValue(String leftValue) {
+ this.leftValue = leftValue;
+ }
+
+ public String getLeftColumn() {
+ return leftColumn;
+ }
+
+ public void setLeftColumn(String leftColumn) {
+ this.leftColumn = leftColumn;
+ }
+
+ public String getExpression() {
+ return expression;
+ }
+
+ public void setExpression(String expression) {
+ this.expression = expression;
+ }
+
+ public String getRightMappingMode() {
+ return rightMappingMode;
+ }
+
+ public void setRightMappingMode(String rightMappingMode) {
+ this.rightMappingMode = rightMappingMode;
+ }
+
+ public String getRightValue() {
+ return rightValue;
+ }
+
+ public void setRightValue(String rightValue) {
+ this.rightValue = rightValue;
+ }
+
+ public String getRightColumn() {
+ return rightColumn;
+ }
+
+ public void setRightColumn(String rightColumn) {
+ this.rightColumn = rightColumn;
+ }
+}
diff --git a/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigMappingGroupVo.java b/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigMappingGroupVo.java
new file mode 100644
index 00000000..033ac03a
--- /dev/null
+++ b/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigMappingGroupVo.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.module.autoexec.process.dto;
+
+import java.util.List;
+
+public class CreateJobConfigMappingGroupVo {
+ private String key;
+ private String name;
+ private String type;
+ private List mappingList;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public List getMappingList() {
+ return mappingList;
+ }
+
+ public void setMappingList(List mappingList) {
+ this.mappingList = mappingList;
+ }
+
+}
diff --git a/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigMappingVo.java b/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigMappingVo.java
new file mode 100644
index 00000000..efc0fbd6
--- /dev/null
+++ b/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigMappingVo.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.module.autoexec.process.dto;
+
+import java.util.List;
+
+public class CreateJobConfigMappingVo {
+ private String mappingMode;
+ private Object value;
+ private String column;
+ private List filterList;
+ private Boolean distinct;
+ private List limit;
+
+ public String getMappingMode() {
+ return mappingMode;
+ }
+
+ public void setMappingMode(String mappingMode) {
+ this.mappingMode = mappingMode;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ public String getColumn() {
+ return column;
+ }
+
+ public void setColumn(String column) {
+ this.column = column;
+ }
+
+ public List getFilterList() {
+ return filterList;
+ }
+
+ public void setFilterList(List filterList) {
+ this.filterList = filterList;
+ }
+
+ public Boolean getDistinct() {
+ return distinct;
+ }
+
+ public void setDistinct(Boolean distinct) {
+ this.distinct = distinct;
+ }
+
+ public List getLimit() {
+ return limit;
+ }
+
+ public void setLimit(List limit) {
+ this.limit = limit;
+ }
+}
diff --git a/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigVo.java b/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigVo.java
new file mode 100644
index 00000000..ae2135c6
--- /dev/null
+++ b/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigVo.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.module.autoexec.process.dto;
+
+import java.util.List;
+
+public class CreateJobConfigVo {
+ private Integer rerunStepToCreateNewJob;
+
+ private String failPolicy;
+
+ private List configList;
+
+ public Integer getRerunStepToCreateNewJob() {
+ return rerunStepToCreateNewJob;
+ }
+
+ public void setRerunStepToCreateNewJob(Integer rerunStepToCreateNewJob) {
+ this.rerunStepToCreateNewJob = rerunStepToCreateNewJob;
+ }
+
+ public String getFailPolicy() {
+ return failPolicy;
+ }
+
+ public void setFailPolicy(String failPolicy) {
+ this.failPolicy = failPolicy;
+ }
+
+ public List getConfigList() {
+ return configList;
+ }
+
+ public void setConfigList(List configList) {
+ this.configList = configList;
+ }
+}
diff --git a/src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessComponent.java b/src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessComponent.java
new file mode 100644
index 00000000..87289e55
--- /dev/null
+++ b/src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessComponent.java
@@ -0,0 +1,586 @@
+/*
+ * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.module.autoexec.process.stephandler;
+
+import com.alibaba.fastjson.*;
+import neatlogic.framework.asynchronization.threadlocal.UserContext;
+import neatlogic.framework.autoexec.constvalue.JobStatus;
+import neatlogic.framework.autoexec.constvalue.ParamMappingMode;
+import neatlogic.framework.autoexec.dao.mapper.AutoexecJobMapper;
+import neatlogic.framework.autoexec.dto.combop.ParamMappingVo;
+import neatlogic.framework.autoexec.dto.job.AutoexecJobEnvVo;
+import neatlogic.framework.autoexec.dto.job.AutoexecJobVo;
+import neatlogic.framework.crossover.CrossoverServiceFactory;
+import neatlogic.framework.dao.mapper.runner.RunnerMapper;
+import neatlogic.framework.dto.runner.RunnerGroupVo;
+import neatlogic.framework.form.dto.AttributeDataVo;
+import neatlogic.framework.form.dto.FormAttributeVo;
+import neatlogic.framework.process.constvalue.*;
+import neatlogic.framework.process.crossover.*;
+import neatlogic.framework.process.dto.ProcessTaskFormAttributeDataVo;
+import neatlogic.framework.process.dto.ProcessTaskStepDataVo;
+import neatlogic.framework.process.dto.ProcessTaskStepVo;
+import neatlogic.framework.process.dto.ProcessTaskStepWorkerVo;
+import neatlogic.framework.process.exception.processtask.ProcessTaskException;
+import neatlogic.framework.process.exception.processtask.ProcessTaskNoPermissionException;
+import neatlogic.framework.process.stephandler.core.IProcessStepHandler;
+import neatlogic.framework.process.stephandler.core.ProcessStepHandlerBase;
+import neatlogic.framework.process.stephandler.core.ProcessStepThread;
+import neatlogic.module.autoexec.constvalue.FailPolicy;
+import neatlogic.module.autoexec.dao.mapper.AutoexecScenarioMapper;
+import neatlogic.module.autoexec.process.constvalue.CreateJobProcessStepHandlerType;
+import neatlogic.module.autoexec.process.dto.CreateJobConfigConfigVo;
+import neatlogic.module.autoexec.process.dto.CreateJobConfigMappingGroupVo;
+import neatlogic.module.autoexec.process.dto.CreateJobConfigMappingVo;
+import neatlogic.module.autoexec.process.dto.CreateJobConfigVo;
+import neatlogic.module.autoexec.process.util.ParseCreateJobConfigUtil;
+import neatlogic.module.autoexec.service.AutoexecJobActionService;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author linbq
+ * @since 2021/9/2 14:22
+ **/
+@Service
+public class CreateJobProcessComponent extends ProcessStepHandlerBase {
+
+ private final static Logger logger = LoggerFactory.getLogger(CreateJobProcessComponent.class);
+
+ private final String FORM_EXTEND_ATTRIBUTE_TAG = "common";
+ @Resource
+ private AutoexecJobMapper autoexecJobMapper;
+
+ @Resource
+ private AutoexecJobActionService autoexecJobActionService;
+
+ @Resource
+ private AutoexecScenarioMapper autoexecScenarioMapper;
+
+ @Resource
+ private RunnerMapper runnerMapper;
+
+
+ @Override
+ public String getHandler() {
+ return CreateJobProcessStepHandlerType.CREATE_JOB.getHandler();
+ }
+
+ @Override
+ public JSONObject getChartConfig() {
+ return new JSONObject() {
+ {
+ this.put("icon", "tsfont-zidonghua");
+ this.put("shape", "L-rectangle:R-rectangle");
+ this.put("width", 68);
+ this.put("height", 40);
+ }
+ };
+ }
+
+ @Override
+ public String getType() {
+ return CreateJobProcessStepHandlerType.CREATE_JOB.getType();
+ }
+
+ @Override
+ public ProcessStepMode getMode() {
+ return ProcessStepMode.MT;
+ }
+
+ @Override
+ public String getName() {
+ return CreateJobProcessStepHandlerType.CREATE_JOB.getName();
+ }
+
+ @Override
+ public int getSort() {
+ return 10;
+ }
+
+ @Override
+ public boolean isAsync() {
+ return false;
+ }
+
+ @Override
+ public Boolean isAllowStart() {
+ return false;
+ }
+
+ @Override
+ protected int myActive(ProcessTaskStepVo currentProcessTaskStepVo) throws ProcessTaskException {
+ IProcessTaskCrossoverMapper processTaskCrossoverMapper = CrossoverServiceFactory.getApi(IProcessTaskCrossoverMapper.class);
+ ISelectContentByHashCrossoverMapper selectContentByHashCrossoverMapper = CrossoverServiceFactory.getApi(ISelectContentByHashCrossoverMapper.class);
+ IProcessTaskStepDataCrossoverMapper processTaskStepDataCrossoverMapper = CrossoverServiceFactory.getApi(IProcessTaskStepDataCrossoverMapper.class);
+ try {
+ String configHash = currentProcessTaskStepVo.getConfigHash();
+ if (StringUtils.isBlank(configHash)) {
+ ProcessTaskStepVo processTaskStepVo = processTaskCrossoverMapper.getProcessTaskStepBaseInfoById(currentProcessTaskStepVo.getId());
+ configHash = processTaskStepVo.getConfigHash();
+ currentProcessTaskStepVo.setProcessStepUuid(processTaskStepVo.getProcessStepUuid());
+ }
+ // 获取工单当前步骤配置信息
+ String config = selectContentByHashCrossoverMapper.getProcessTaskStepConfigByHash(configHash);
+ if (StringUtils.isBlank(config)) {
+ return 0;
+ }
+ JSONObject createJobConfig = (JSONObject) JSONPath.read(config, "createJobConfig");
+ if (MapUtils.isEmpty(createJobConfig)) {
+ return 0;
+ }
+ CreateJobConfigVo createJobConfigVo = createJobConfig.toJavaObject(CreateJobConfigVo.class);
+ // rerunStepToCreateNewJob为1时表示重新激活自动化步骤时创建新作业,rerunStepToCreateNewJob为0时表示重新激活自动化步骤时不创建新作业,也不重跑旧作业,即什么都不做
+ Integer rerunStepToCreateNewJob = createJobConfigVo.getRerunStepToCreateNewJob();
+ if (!Objects.equals(rerunStepToCreateNewJob, 1)) {
+ Long autoexecJobId = autoexecJobMapper.getJobIdByInvokeIdLimitOne(currentProcessTaskStepVo.getId());
+ if (autoexecJobId != null) {
+ return 1;
+ }
+ }
+ autoexecJobMapper.deleteAutoexecJobByProcessTaskStepId(currentProcessTaskStepVo.getId());
+ // 删除上次创建作业的报错信息
+ ProcessTaskStepDataVo processTaskStepData = new ProcessTaskStepDataVo();
+ processTaskStepData.setProcessTaskId(currentProcessTaskStepVo.getProcessTaskId());
+ processTaskStepData.setProcessTaskStepId(currentProcessTaskStepVo.getId());
+ processTaskStepData.setType("autoexecCreateJobError");
+ processTaskStepDataCrossoverMapper.deleteProcessTaskStepData(processTaskStepData);
+ List configList = createJobConfigVo.getConfigList();
+ if (CollectionUtils.isEmpty(configList)) {
+ return 0;
+ }
+ List jobList = new ArrayList<>();
+ for (CreateJobConfigConfigVo createJobConfigConfigVo : configList) {
+ if (createJobConfigConfigVo == null) {
+ continue;
+ }
+ // 根据配置信息创建AutoexecJobVo对象
+ List list = ParseCreateJobConfigUtil.createAutoexecJobList(currentProcessTaskStepVo, createJobConfigConfigVo);
+ jobList.addAll(list);
+
+ }
+ JSONArray errorMessageList = new JSONArray();
+ boolean flag = false;
+ List jobIdList = new ArrayList<>();
+ for (AutoexecJobVo jobVo : jobList) {
+ try {
+ autoexecJobActionService.validateCreateJob(jobVo);
+ autoexecJobMapper.insertAutoexecJobProcessTaskStep(jobVo.getId(), currentProcessTaskStepVo.getId());
+ jobIdList.add(jobVo.getId());
+ } catch (Exception e) {
+ // 增加提醒
+ logger.error(e.getMessage(), e);
+ JSONObject errorMessageObj = new JSONObject();
+ errorMessageObj.put("jobId", jobVo.getId());
+ errorMessageObj.put("jobName", jobVo.getName());
+ errorMessageObj.put("error", e.getMessage());
+ errorMessageList.add(errorMessageObj);
+ flag = true;
+ }
+ }
+ // 如果有一个作业创建有异常,则根据失败策略执行操作
+ if (flag) {
+ ProcessTaskStepDataVo processTaskStepDataVo = new ProcessTaskStepDataVo();
+ processTaskStepDataVo.setProcessTaskId(currentProcessTaskStepVo.getProcessTaskId());
+ processTaskStepDataVo.setProcessTaskStepId(currentProcessTaskStepVo.getId());
+ processTaskStepDataVo.setType("autoexecCreateJobError");
+ JSONObject dataObj = new JSONObject();
+ dataObj.put("errorList", errorMessageList);
+ processTaskStepDataVo.setData(dataObj.toJSONString());
+ processTaskStepDataVo.setFcu(UserContext.get().getUserUuid());
+ processTaskStepDataCrossoverMapper.replaceProcessTaskStepData(processTaskStepDataVo);
+ String failPolicy = createJobConfigVo.getFailPolicy();
+ if (FailPolicy.KEEP_ON.getValue().equals(failPolicy)) {
+ if (CollectionUtils.isNotEmpty(jobIdList)) {
+ int running = 0;
+ List autoexecJobList = autoexecJobMapper.getJobListByIdList(jobIdList);
+ for (AutoexecJobVo autoexecJobVo : autoexecJobList) {
+ if (JobStatus.isRunningStatus(autoexecJobVo.getStatus())) {
+ running++;
+ }
+ }
+ if (running == 0) {
+ processTaskStepComplete(currentProcessTaskStepVo.getId(), null);
+ }
+ } else {
+ processTaskStepComplete(currentProcessTaskStepVo.getId(), null);
+ }
+ }
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new ProcessTaskException(e.getMessage());
+ }
+ return 1;
+ }
+
+
+
+ /**
+ * 获取执行器组的值
+ *
+ * @param mappingGroupVo
+ * @param jobParamJson 作业参数的值
+ */
+ private ParamMappingVo parseRunnerGroupMapping(CreateJobConfigMappingGroupVo mappingGroupVo, JSONObject jobParamJson) {
+ //执行器组
+ ParamMappingVo runnerGroup = new ParamMappingVo();
+ List mappingList = mappingGroupVo.getMappingList();
+ if (CollectionUtils.isEmpty(mappingList)) {
+ return runnerGroup;
+ }
+ for (CreateJobConfigMappingVo mappingVo : mappingList) {
+ if (mappingVo != null) {
+ String mappingMode = mappingVo.getMappingMode();
+ long runnerGroupId = -1L;
+ String mappingValue = null;
+ mappingValue = mappingVo.getValue().toString();
+ runnerGroup.setMappingMode(ParamMappingMode.CONSTANT.getValue());
+ if (Objects.equals(mappingMode, "runtimeparam")) {
+ mappingValue = jobParamJson.getString(mappingValue);
+ try {
+ JSONObject jsonObject = JSON.parseObject(mappingValue);
+ mappingValue = jsonObject.getString("value");
+ } catch (RuntimeException ignored) {
+ }
+ }
+ try {
+ runnerGroupId = Long.parseLong(mappingValue);
+ RunnerGroupVo runnerGroupVo = runnerMapper.getRunnerGroupById(runnerGroupId);
+ if (runnerGroupVo == null) {
+ runnerGroupVo = runnerMapper.getRunnerGroupByName(mappingValue);
+ if (runnerGroupVo != null) {
+ runnerGroupId = runnerGroupVo.getId();
+ }
+ }
+ } catch (NumberFormatException ex) {
+ RunnerGroupVo runnerGroupVo = runnerMapper.getRunnerGroupByName(mappingValue);
+ if (runnerGroupVo != null) {
+ runnerGroupId = runnerGroupVo.getId();
+ }
+ }
+ runnerGroup.setValue(runnerGroupId);
+ }
+ }
+
+ return runnerGroup;
+ }
+
+
+
+ private void processTaskStepComplete(Long processTaskStepId, Long autoexecJobId) {
+ IProcessTaskCrossoverMapper processTaskCrossoverMapper = CrossoverServiceFactory.getApi(IProcessTaskCrossoverMapper.class);
+ ISelectContentByHashCrossoverMapper selectContentByHashCrossoverMapper = CrossoverServiceFactory.getApi(ISelectContentByHashCrossoverMapper.class);
+ List toProcessTaskStepIdList = processTaskCrossoverMapper.getToProcessTaskStepIdListByFromIdAndType(processTaskStepId, ProcessFlowDirection.FORWARD.getValue());
+ if (toProcessTaskStepIdList.size() == 1) {
+ Long nextStepId = toProcessTaskStepIdList.get(0);
+ try {
+ List hidecomponentList = new ArrayList<>();
+ JSONArray formAttributeDataList = new JSONArray();
+ ProcessTaskStepVo processTaskStepVo = processTaskCrossoverMapper.getProcessTaskStepBaseInfoById(processTaskStepId);
+ String config = selectContentByHashCrossoverMapper.getProcessTaskStepConfigByHash(processTaskStepVo.getConfigHash());
+ if (StringUtils.isNotBlank(config)) {
+ JSONArray formAttributeList = (JSONArray) JSONPath.read(config, "autoexecConfig.formAttributeList");
+ if (CollectionUtils.isNotEmpty(formAttributeList)) {
+ Map autoexecJobEnvMap = new HashMap<>();
+ if (autoexecJobId != null) {
+ List autoexecJobEnvList = autoexecJobMapper.getAutoexecJobEnvListByJobId(autoexecJobId);
+ for (AutoexecJobEnvVo autoexecJobEnvVo : autoexecJobEnvList) {
+ autoexecJobEnvMap.put(autoexecJobEnvVo.getName(), autoexecJobEnvVo.getValue());
+ }
+ }
+ Map formAttributeNewDataMap = new HashMap<>();
+ for (int i = 0; i < formAttributeList.size(); i++) {
+ JSONObject formAttributeObj = formAttributeList.getJSONObject(i);
+ String key = formAttributeObj.getString("key");
+ String value = formAttributeObj.getString("value");
+ formAttributeNewDataMap.put(key, autoexecJobEnvMap.get(value));
+ }
+ IProcessTaskCrossoverService processTaskCrossoverService = CrossoverServiceFactory.getApi(IProcessTaskCrossoverService.class);
+ List processTaskFormAttributeDataList = processTaskCrossoverService.getProcessTaskFormAttributeDataListByProcessTaskId(processTaskStepVo.getProcessTaskId());
+ for (ProcessTaskFormAttributeDataVo processTaskFormAttributeDataVo : processTaskFormAttributeDataList) {
+ JSONObject formAttributeDataObj = new JSONObject();
+ String attributeUuid = processTaskFormAttributeDataVo.getAttributeUuid();
+ formAttributeDataObj.put("attributeUuid", attributeUuid);
+ formAttributeDataObj.put("handler", processTaskFormAttributeDataVo.getHandler());
+ Object newData = formAttributeNewDataMap.get(attributeUuid);
+ if (newData != null) {
+ formAttributeDataObj.put("dataList", newData);
+ } else {
+ formAttributeDataObj.put("dataList", processTaskFormAttributeDataVo.getDataObj());
+ hidecomponentList.add(attributeUuid);
+ }
+ formAttributeDataList.add(formAttributeDataObj);
+ }
+ }
+ }
+ JSONObject paramObj = processTaskStepVo.getParamObj();
+ paramObj.put("nextStepId", nextStepId);
+ paramObj.put("action", ProcessTaskOperationType.STEP_COMPLETE.getValue());
+ if (CollectionUtils.isNotEmpty(formAttributeDataList)) {
+ paramObj.put("formAttributeDataList", formAttributeDataList);
+ }
+ if (CollectionUtils.isNotEmpty(hidecomponentList)) {
+ paramObj.put("hidecomponentList", hidecomponentList);
+ }
+ /* 自动处理 **/
+ IProcessStepHandler handler = this;
+ doNext(ProcessTaskOperationType.STEP_COMPLETE, new ProcessStepThread(processTaskStepVo) {
+ @Override
+ public void myExecute() {
+ handler.autoComplete(processTaskStepVo);
+ }
+ });
+ } catch (ProcessTaskNoPermissionException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+ }
+
+
+ @Override
+ protected int myAssign(ProcessTaskStepVo currentProcessTaskStepVo, Set workerSet) throws ProcessTaskException {
+ return defaultAssign(currentProcessTaskStepVo, workerSet);
+ }
+
+ @Override
+ protected int myHang(ProcessTaskStepVo currentProcessTaskStepVo) {
+ return 0;
+ }
+
+ @Override
+ protected int myHandle(ProcessTaskStepVo currentProcessTaskStepVo) throws ProcessTaskException {
+ return 0;
+ }
+
+ @Override
+ protected int myStart(ProcessTaskStepVo currentProcessTaskStepVo) throws ProcessTaskException {
+ return 0;
+ }
+
+ @Override
+ protected int myComplete(ProcessTaskStepVo currentProcessTaskStepVo) throws ProcessTaskException {
+ return 10;
+ }
+
+ @Override
+ protected int myBeforeComplete(ProcessTaskStepVo currentProcessTaskStepVo) throws ProcessTaskException {
+ IProcessTaskCrossoverMapper processTaskCrossoverMapper = CrossoverServiceFactory.getApi(IProcessTaskCrossoverMapper.class);
+ ISelectContentByHashCrossoverMapper selectContentByHashCrossoverMapper = CrossoverServiceFactory.getApi(ISelectContentByHashCrossoverMapper.class);
+ Long processTaskStepId = currentProcessTaskStepVo.getId();
+ ProcessTaskStepVo processTaskStepVo = processTaskCrossoverMapper.getProcessTaskStepBaseInfoById(processTaskStepId);
+ String config = selectContentByHashCrossoverMapper.getProcessTaskStepConfigByHash(processTaskStepVo.getConfigHash());
+ if (StringUtils.isBlank(config)) {
+ return 0;
+ }
+ JSONArray configList = (JSONArray) JSONPath.read(config, "autoexecConfig.configList");
+ if (CollectionUtils.isEmpty(configList)) {
+ return 0;
+ }
+ List jobIdList = autoexecJobMapper.getJobIdListByProcessTaskStepId(processTaskStepId);
+ if (CollectionUtils.isEmpty(jobIdList)) {
+ return 0;
+ }
+ List autoexecJobEnvVoList = autoexecJobMapper.getAutoexecJobEnvListByJobIdList(jobIdList);
+
+ Map> autoexecJobEnvMap = new HashMap<>();
+ for (AutoexecJobEnvVo autoexecJobEnvVo : autoexecJobEnvVoList) {
+ autoexecJobEnvMap.computeIfAbsent(autoexecJobEnvVo.getName(), k -> new ArrayList<>()).add(autoexecJobEnvVo.getValue());
+ }
+ Map> formAttributeNewDataMap = new HashMap<>();
+ for (int j = 0; j < configList.size(); j++) {
+ JSONObject configObj = configList.getJSONObject(j);
+ if (MapUtils.isEmpty(configObj)) {
+ continue;
+ }
+ JSONArray formAttributeList = configObj.getJSONArray("formAttributeList");
+ if (CollectionUtils.isEmpty(formAttributeList)) {
+ continue;
+ }
+ for (int i = 0; i < formAttributeList.size(); i++) {
+ JSONObject formAttributeObj = formAttributeList.getJSONObject(i);
+ String key = formAttributeObj.getString("key");
+ if (StringUtils.isBlank(key)) {
+ continue;
+ }
+ String value = formAttributeObj.getString("value");
+ if (StringUtils.isBlank(value)) {
+ continue;
+ }
+ List newValue = autoexecJobEnvMap.get(value);
+ if (newValue != null) {
+ formAttributeNewDataMap.put(key, newValue);
+ }
+ }
+ }
+ if (MapUtils.isEmpty(formAttributeNewDataMap)) {
+ return 0;
+ }
+ IProcessTaskCrossoverService processTaskCrossoverService = CrossoverServiceFactory.getApi(IProcessTaskCrossoverService.class);
+ List formAttributeList = processTaskCrossoverService.getFormAttributeListByProcessTaskId(processTaskStepVo.getProcessTaskId());
+ if (CollectionUtils.isEmpty(formAttributeList)) {
+ return 0;
+ }
+
+
+ Map formAttributeMap = formAttributeList.stream().collect(Collectors.toMap(e -> e.getUuid(), e -> e));
+ JSONObject paramObj = currentProcessTaskStepVo.getParamObj();
+ JSONArray formAttributeDataList = paramObj.getJSONArray("formAttributeDataList");
+ if (formAttributeDataList == null) {
+ formAttributeDataList = new JSONArray();
+ List hidecomponentList = formAttributeList.stream().map(FormAttributeVo::getUuid).collect(Collectors.toList());
+ paramObj.put("hidecomponentList", hidecomponentList);
+ List processTaskFormAttributeDataList = processTaskCrossoverService.getProcessTaskFormAttributeDataListByProcessTaskId(processTaskStepVo.getProcessTaskId());
+ Map processTaskFormAttributeDataMap = processTaskFormAttributeDataList.stream().collect(Collectors.toMap(AttributeDataVo::getAttributeUuid, e -> e));
+ for (Map.Entry entry : processTaskFormAttributeDataMap.entrySet()) {
+ ProcessTaskFormAttributeDataVo processTaskFormAttributeDataVo = entry.getValue();
+ JSONObject formAttributeDataObj = new JSONObject();
+ formAttributeDataObj.put("attributeUuid", processTaskFormAttributeDataVo.getAttributeUuid());
+ formAttributeDataObj.put("handler", processTaskFormAttributeDataVo.getHandler());
+ formAttributeDataObj.put("dataList", processTaskFormAttributeDataVo.getDataObj());
+ formAttributeDataList.add(formAttributeDataObj);
+ }
+ }
+
+ for (Map.Entry> entry : formAttributeNewDataMap.entrySet()) {
+ String attributeUuid = entry.getKey();
+ FormAttributeVo formAttributeVo = formAttributeMap.get(attributeUuid);
+ if (formAttributeVo == null) {
+ continue;
+ }
+ List newDataList = entry.getValue();
+ if (CollectionUtils.isEmpty(newDataList)) {
+ continue;
+ }
+
+ JSONObject formAttributeDataObj = null;
+ for (int i = 0; i < formAttributeDataList.size(); i++) {
+ JSONObject tempObj = formAttributeDataList.getJSONObject(i);
+ if (Objects.equals(tempObj.getString("attributeUuid"), attributeUuid)) {
+ formAttributeDataObj = tempObj;
+ }
+ }
+ if (formAttributeDataObj == null) {
+ formAttributeDataObj = new JSONObject();
+ formAttributeDataList.add(formAttributeDataObj);
+ }
+ formAttributeDataObj.put("attributeUuid", attributeUuid);
+ formAttributeDataObj.put("handler", formAttributeVo.getHandler());
+ if (newDataList.size() == 1) {
+ // 如果只有一个元素,把唯一的元素取出来赋值给表单组件
+ formAttributeDataObj.put("dataList", newDataList.get(0));
+ } else {
+ // 如果有多个元素,分为两种情况
+ // 1.元素也是一个数组,需要把所有元素(数组)平摊成一个大一维数组
+ // 2.元素不是一个数组,不需要特殊处理
+ JSONArray newDataArray = new JSONArray();
+ for (String newData : newDataList) {
+ try {
+ JSONArray array = JSON.parseArray(newData);
+ newDataArray.addAll(array);
+ } catch (JSONException e) {
+ newDataArray.add(newData);
+ }
+ }
+ formAttributeDataObj.put("dataList", JSON.toJSONString(newDataArray));
+ }
+ }
+ paramObj.put("formAttributeDataList", formAttributeDataList);
+ return 0;
+ }
+
+ @Override
+ protected int myCompleteAudit(ProcessTaskStepVo currentProcessTaskStepVo) {
+ if (StringUtils.isNotBlank(currentProcessTaskStepVo.getError())) {
+ currentProcessTaskStepVo.getParamObj().put(ProcessTaskAuditDetailType.CAUSE.getParamName(), currentProcessTaskStepVo.getError());
+ }
+ /** 处理历史记录 **/
+ String action = currentProcessTaskStepVo.getParamObj().getString("action");
+ IProcessStepHandlerCrossoverUtil processStepHandlerCrossoverUtil = CrossoverServiceFactory.getApi(IProcessStepHandlerCrossoverUtil.class);
+ processStepHandlerCrossoverUtil.audit(currentProcessTaskStepVo, ProcessTaskAuditType.getProcessTaskAuditType(action));
+ return 1;
+ }
+
+ @Override
+ protected int myReapproval(ProcessTaskStepVo currentProcessTaskStepVo) throws ProcessTaskException {
+ return 0;
+ }
+
+ @Override
+ protected int myReapprovalAudit(ProcessTaskStepVo currentProcessTaskStepVo) {
+ return 0;
+ }
+
+ @Override
+ protected int myRetreat(ProcessTaskStepVo currentProcessTaskStepVo) throws ProcessTaskException {
+ return 0;
+ }
+
+ @Override
+ protected int myAbort(ProcessTaskStepVo currentProcessTaskStepVo) {
+ return 0;
+ }
+
+ @Override
+ protected int myRecover(ProcessTaskStepVo currentProcessTaskStepVo) {
+ return 0;
+ }
+
+ @Override
+ protected int myPause(ProcessTaskStepVo currentProcessTaskStepVo) throws ProcessTaskException {
+ return 0;
+ }
+
+ @Override
+ protected int myTransfer(ProcessTaskStepVo currentProcessTaskStepVo, List workerList) throws ProcessTaskException {
+ return 0;
+ }
+
+ @Override
+ protected int myBack(ProcessTaskStepVo currentProcessTaskStepVo) throws ProcessTaskException {
+ return 0;
+ }
+
+ @Override
+ protected int mySaveDraft(ProcessTaskStepVo processTaskStepVo) throws ProcessTaskException {
+ return 0;
+ }
+
+ @Override
+ protected int myStartProcess(ProcessTaskStepVo processTaskStepVo) throws ProcessTaskException {
+ return 0;
+ }
+
+ @Override
+ protected Set myGetNext(ProcessTaskStepVo currentProcessTaskStepVo, List nextStepIdList, Long nextStepId) throws ProcessTaskException {
+ return defaultGetNext(nextStepIdList, nextStepId);
+ }
+
+ @Override
+ protected int myRedo(ProcessTaskStepVo currentProcessTaskStepVo) throws ProcessTaskException {
+ return 0;
+ }
+}
diff --git a/src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessUtilHandler.java b/src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessUtilHandler.java
new file mode 100644
index 00000000..1a5be7be
--- /dev/null
+++ b/src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessUtilHandler.java
@@ -0,0 +1,249 @@
+/*
+ * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.module.autoexec.process.stephandler;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import neatlogic.framework.autoexec.constvalue.JobStatus;
+import neatlogic.framework.autoexec.dao.mapper.AutoexecJobMapper;
+import neatlogic.framework.autoexec.dto.job.AutoexecJobPhaseVo;
+import neatlogic.framework.autoexec.dto.job.AutoexecJobVo;
+import neatlogic.framework.crossover.CrossoverServiceFactory;
+import neatlogic.framework.notify.crossover.INotifyServiceCrossoverService;
+import neatlogic.framework.notify.dto.InvokeNotifyPolicyConfigVo;
+import neatlogic.framework.process.constvalue.ProcessTaskOperationType;
+import neatlogic.framework.process.crossover.IProcessTaskStepDataCrossoverMapper;
+import neatlogic.framework.process.dto.ProcessTaskStepDataVo;
+import neatlogic.framework.process.dto.ProcessTaskStepVo;
+import neatlogic.framework.process.dto.processconfig.ActionConfigVo;
+import neatlogic.framework.process.stephandler.core.ProcessStepInternalHandlerBase;
+import neatlogic.framework.process.util.ProcessConfigUtil;
+import neatlogic.module.autoexec.notify.handler.AutoexecCombopNotifyPolicyHandler;
+import neatlogic.module.autoexec.process.constvalue.CreateJobProcessStepHandlerType;
+import neatlogic.module.autoexec.service.AutoexecJobService;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.*;
+
+/**
+ * @author linbq
+ * @since 2021/9/2 14:30
+ **/
+@Service
+public class CreateJobProcessUtilHandler extends ProcessStepInternalHandlerBase {
+
+ @Resource
+ private AutoexecJobMapper autoexecJobMapper;
+
+ @Resource
+ AutoexecJobService autoexecJobService;
+
+ @Override
+ public String getHandler() {
+ return CreateJobProcessStepHandlerType.CREATE_JOB.getHandler();
+ }
+
+ @Override
+ public Object getStartStepInfo(ProcessTaskStepVo currentProcessTaskStepVo) {
+ return getNonStartStepInfo(currentProcessTaskStepVo);
+ }
+
+ @Override
+ public Object getNonStartStepInfo(ProcessTaskStepVo currentProcessTaskStepVo) {
+ JSONObject resultObj = new JSONObject();
+ List jobIdList = autoexecJobMapper.getJobIdListByInvokeId(currentProcessTaskStepVo.getId());
+ if (CollectionUtils.isNotEmpty(jobIdList)) {
+ int completed = 0, failed = 0, running = 0;
+ Map> jobIdToAutoexecJobPhaseListMap = new HashMap<>();
+ List jobPhaseList = autoexecJobMapper.getJobPhaseListWithGroupByJobIdList(jobIdList);
+ for (AutoexecJobPhaseVo autoexecJobPhaseVo : jobPhaseList) {
+ jobIdToAutoexecJobPhaseListMap.computeIfAbsent(autoexecJobPhaseVo.getJobId(), key -> new ArrayList<>()).add(autoexecJobPhaseVo);
+ }
+ List autoexecJobList = autoexecJobMapper.getJobListByIdList(jobIdList);
+ for (AutoexecJobVo autoexecJobVo : autoexecJobList) {
+ List jobPhaseVoList = jobIdToAutoexecJobPhaseListMap.get(autoexecJobVo.getId());
+ autoexecJobVo.setPhaseList(jobPhaseVoList);
+ if (JobStatus.isRunningStatus(autoexecJobVo.getStatus())) {
+ running++;
+ } else if (JobStatus.isCompletedStatus(autoexecJobVo.getStatus())) {
+ completed++;
+ } else if (JobStatus.isFailedStatus(autoexecJobVo.getStatus())) {
+ failed++;
+ }
+ }
+
+ if (running > 0) {
+ resultObj.put("status", JobStatus.RUNNING.getValue());
+ } else if (failed > 0) {
+ resultObj.put("status", JobStatus.FAILED.getValue());
+ } else if (completed > 0) {
+ resultObj.put("status", JobStatus.COMPLETED.getValue());
+ }
+ resultObj.put("jobList", autoexecJobList);
+ }
+ IProcessTaskStepDataCrossoverMapper processTaskStepDataCrossoverMapper = CrossoverServiceFactory.getApi(IProcessTaskStepDataCrossoverMapper.class);
+ ProcessTaskStepDataVo searchVo = new ProcessTaskStepDataVo();
+ searchVo.setProcessTaskId(currentProcessTaskStepVo.getProcessTaskId());
+ searchVo.setProcessTaskStepId(currentProcessTaskStepVo.getId());
+ searchVo.setType("autoexecCreateJobError");
+ ProcessTaskStepDataVo processTaskStepDataVo = processTaskStepDataCrossoverMapper.getProcessTaskStepData(searchVo);
+ if (processTaskStepDataVo != null) {
+ JSONObject dataObj = processTaskStepDataVo.getData();
+ if (MapUtils.isNotEmpty(dataObj)) {
+ JSONArray errorList = dataObj.getJSONArray("errorList");
+ if (CollectionUtils.isNotEmpty(errorList)) {
+ resultObj.put("errorList", errorList);
+ }
+ }
+ }
+ return resultObj;
+ }
+
+
+ @Override
+ public void updateProcessTaskStepUserAndWorker(Long processTaskId, Long processTaskStepId) {
+
+ }
+
+ @Override
+ public JSONObject makeupConfig(JSONObject configObj) {
+ if (configObj == null) {
+ configObj = new JSONObject();
+ }
+ JSONObject resultObj = new JSONObject();
+
+ /* 授权 **/
+ ProcessTaskOperationType[] stepActions = {
+ ProcessTaskOperationType.STEP_VIEW,
+ ProcessTaskOperationType.STEP_TRANSFER
+ };
+ JSONArray authorityList = configObj.getJSONArray("authorityList");
+ JSONArray authorityArray = ProcessConfigUtil.regulateAuthorityList(authorityList, stepActions);
+ resultObj.put("authorityList", authorityArray);
+
+ /* 按钮映射 **/
+ ProcessTaskOperationType[] stepButtons = {
+ ProcessTaskOperationType.STEP_COMPLETE,
+ ProcessTaskOperationType.STEP_BACK,
+ ProcessTaskOperationType.PROCESSTASK_TRANSFER,
+ ProcessTaskOperationType.STEP_ACCEPT
+ };
+ JSONArray customButtonList = configObj.getJSONArray("customButtonList");
+ JSONArray customButtonArray = ProcessConfigUtil.regulateCustomButtonList(customButtonList, stepButtons);
+ resultObj.put("customButtonList", customButtonArray);
+ /* 状态映射列表 **/
+ JSONArray customStatusList = configObj.getJSONArray("customStatusList");
+ JSONArray customStatusArray = ProcessConfigUtil.regulateCustomStatusList(customStatusList);
+ resultObj.put("customStatusList", customStatusArray);
+
+ /* 可替换文本列表 **/
+ resultObj.put("replaceableTextList", ProcessConfigUtil.regulateReplaceableTextList(configObj.getJSONArray("replaceableTextList")));
+ return resultObj;
+ }
+
+ @Override
+ public JSONObject regulateProcessStepConfig(JSONObject configObj) {
+ if (configObj == null) {
+ configObj = new JSONObject();
+ }
+ JSONObject resultObj = new JSONObject();
+
+ /* 授权 **/
+ ProcessTaskOperationType[] stepActions = {
+ ProcessTaskOperationType.STEP_VIEW,
+ ProcessTaskOperationType.STEP_TRANSFER
+ };
+ JSONArray authorityList = null;
+ Integer enableAuthority = configObj.getInteger("enableAuthority");
+ if (Objects.equals(enableAuthority, 1)) {
+ authorityList = configObj.getJSONArray("authorityList");
+ } else {
+ enableAuthority = 0;
+ }
+ resultObj.put("enableAuthority", enableAuthority);
+ JSONArray authorityArray = ProcessConfigUtil.regulateAuthorityList(authorityList, stepActions);
+ resultObj.put("authorityList", authorityArray);
+
+ /* 通知 **/
+ JSONObject notifyPolicyConfig = configObj.getJSONObject("notifyPolicyConfig");
+ INotifyServiceCrossoverService notifyServiceCrossoverService = CrossoverServiceFactory.getApi(INotifyServiceCrossoverService.class);
+ InvokeNotifyPolicyConfigVo invokeNotifyPolicyConfigVo = notifyServiceCrossoverService.regulateNotifyPolicyConfig(notifyPolicyConfig, AutoexecCombopNotifyPolicyHandler.class);
+ resultObj.put("notifyPolicyConfig", invokeNotifyPolicyConfigVo);
+
+ /** 动作 **/
+ JSONObject actionConfig = configObj.getJSONObject("actionConfig");
+ ActionConfigVo actionConfigVo = JSONObject.toJavaObject(actionConfig, ActionConfigVo.class);
+ if (actionConfigVo == null) {
+ actionConfigVo = new ActionConfigVo();
+ }
+ actionConfigVo.setHandler(AutoexecCombopNotifyPolicyHandler.class.getName());
+ resultObj.put("actionConfig", actionConfigVo);
+
+ /* 按钮映射列表 **/
+ ProcessTaskOperationType[] stepButtons = {
+ ProcessTaskOperationType.STEP_COMPLETE,
+ ProcessTaskOperationType.STEP_BACK,
+ ProcessTaskOperationType.PROCESSTASK_TRANSFER,
+ ProcessTaskOperationType.STEP_ACCEPT
+ };
+ JSONArray customButtonList = configObj.getJSONArray("customButtonList");
+ JSONArray customButtonArray = ProcessConfigUtil.regulateCustomButtonList(customButtonList, stepButtons);
+ resultObj.put("customButtonList", customButtonArray);
+ /* 状态映射列表 **/
+ JSONArray customStatusList = configObj.getJSONArray("customStatusList");
+ JSONArray customStatusArray = ProcessConfigUtil.regulateCustomStatusList(customStatusList);
+ resultObj.put("customStatusList", customStatusArray);
+
+ /* 可替换文本列表 **/
+ resultObj.put("replaceableTextList", ProcessConfigUtil.regulateReplaceableTextList(configObj.getJSONArray("replaceableTextList")));
+
+ /* 自动化配置 **/
+ JSONObject createJobConfig = configObj.getJSONObject("createJobConfig");
+ JSONObject createJobConfigObj = regulateCreateJobConfig(createJobConfig);
+ resultObj.put("createJobConfig", createJobConfigObj);
+
+ /** 分配处理人 **/
+ JSONObject workerPolicyConfig = configObj.getJSONObject("workerPolicyConfig");
+ JSONObject workerPolicyObj = ProcessConfigUtil.regulateWorkerPolicyConfig(workerPolicyConfig);
+ resultObj.put("workerPolicyConfig", workerPolicyObj);
+
+ JSONArray tagList = configObj.getJSONArray("tagList");
+ if (tagList == null) {
+ tagList = new JSONArray();
+ }
+ resultObj.put("tagList", tagList);
+ /** 表单场景 **/
+ String formSceneUuid = configObj.getString("formSceneUuid");
+ String formSceneName = configObj.getString("formSceneName");
+ resultObj.put("formSceneUuid", formSceneUuid == null ? "" : formSceneUuid);
+ resultObj.put("formSceneName", formSceneName == null ? "" : formSceneName);
+ return resultObj;
+ }
+
+ private JSONObject regulateCreateJobConfig(JSONObject createJobConfig) {
+ JSONObject createJobConfigObj = new JSONObject();
+ if (createJobConfig == null) {
+ createJobConfig = new JSONObject();
+ }
+ createJobConfigObj.putAll(createJobConfig);
+ return createJobConfigObj;
+ }
+}
diff --git a/src/main/java/neatlogic/module/autoexec/process/util/ParseCreateJobConfigUtil.java b/src/main/java/neatlogic/module/autoexec/process/util/ParseCreateJobConfigUtil.java
new file mode 100644
index 00000000..6d1748fc
--- /dev/null
+++ b/src/main/java/neatlogic/module/autoexec/process/util/ParseCreateJobConfigUtil.java
@@ -0,0 +1,1118 @@
+/*
+ * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.module.autoexec.process.util;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONException;
+import com.alibaba.fastjson.JSONObject;
+import neatlogic.framework.autoexec.constvalue.CombopOperationType;
+import neatlogic.framework.autoexec.constvalue.ParamType;
+import neatlogic.framework.autoexec.crossover.IAutoexecScenarioCrossoverMapper;
+import neatlogic.framework.autoexec.dto.combop.AutoexecCombopExecuteConfigVo;
+import neatlogic.framework.autoexec.dto.combop.AutoexecCombopExecuteNodeConfigVo;
+import neatlogic.framework.autoexec.dto.combop.ParamMappingVo;
+import neatlogic.framework.autoexec.dto.job.AutoexecJobVo;
+import neatlogic.framework.autoexec.dto.node.AutoexecNodeVo;
+import neatlogic.framework.autoexec.dto.scenario.AutoexecScenarioVo;
+import neatlogic.framework.cmdb.crossover.IResourceAccountCrossoverMapper;
+import neatlogic.framework.cmdb.dto.resourcecenter.AccountProtocolVo;
+import neatlogic.framework.cmdb.enums.FormHandler;
+import neatlogic.framework.common.constvalue.Expression;
+import neatlogic.framework.common.constvalue.SystemUser;
+import neatlogic.framework.crossover.CrossoverServiceFactory;
+import neatlogic.framework.form.attribute.core.FormAttributeDataConversionHandlerFactory;
+import neatlogic.framework.form.attribute.core.IFormAttributeDataConversionHandler;
+import neatlogic.framework.form.dto.FormAttributeVo;
+import neatlogic.framework.process.condition.core.ProcessTaskConditionFactory;
+import neatlogic.framework.process.constvalue.AutoExecJobProcessSource;
+import neatlogic.framework.process.constvalue.ConditionProcessTaskOptions;
+import neatlogic.framework.process.crossover.IProcessTaskCrossoverService;
+import neatlogic.framework.process.dto.ProcessTaskFormAttributeDataVo;
+import neatlogic.framework.process.dto.ProcessTaskStepVo;
+import neatlogic.framework.util.FormUtil;
+import neatlogic.module.autoexec.process.dto.CreateJobConfigConfigVo;
+import neatlogic.module.autoexec.process.dto.CreateJobConfigFilterVo;
+import neatlogic.module.autoexec.process.dto.CreateJobConfigMappingGroupVo;
+import neatlogic.module.autoexec.process.dto.CreateJobConfigMappingVo;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class ParseCreateJobConfigUtil {
+
+ /**
+ * 根据工单步骤配置信息创建AutoexecJobVo对象
+ *
+ * @param currentProcessTaskStepVo
+ * @param createJobConfigConfigVo
+ * @return
+ */
+ public static List createAutoexecJobList(ProcessTaskStepVo currentProcessTaskStepVo, CreateJobConfigConfigVo createJobConfigConfigVo) {
+ Long processTaskId = currentProcessTaskStepVo.getProcessTaskId();
+ // 如果工单有表单信息,则查询出表单配置及数据
+ Map formAttributeDataMap = new HashMap<>();
+ Map originalFormAttributeDataMap = new HashMap<>();
+ IProcessTaskCrossoverService processTaskCrossoverService = CrossoverServiceFactory.getApi(IProcessTaskCrossoverService.class);
+ List formAttributeList = processTaskCrossoverService.getFormAttributeListByProcessTaskIdAngTag(processTaskId, createJobConfigConfigVo.getFormTag());
+ if (CollectionUtils.isNotEmpty(formAttributeList)) {
+ List processTaskFormAttributeDataList = processTaskCrossoverService.getProcessTaskFormAttributeDataListByProcessTaskIdAndTag(processTaskId, createJobConfigConfigVo.getFormTag());
+ for (ProcessTaskFormAttributeDataVo attributeDataVo : processTaskFormAttributeDataList) {
+ originalFormAttributeDataMap.put(attributeDataVo.getAttributeUuid(), attributeDataVo.getDataObj());
+ // 放入表单普通组件数据
+ if (!Objects.equals(attributeDataVo.getHandler(), neatlogic.framework.form.constvalue.FormHandler.FORMTABLEINPUTER.getHandler())
+ && !Objects.equals(attributeDataVo.getHandler(), neatlogic.framework.form.constvalue.FormHandler.FORMSUBASSEMBLY.getHandler())
+ && !Objects.equals(attributeDataVo.getHandler(), neatlogic.framework.form.constvalue.FormHandler.FORMTABLESELECTOR.getHandler())) {
+ formAttributeDataMap.put(attributeDataVo.getAttributeUuid(), attributeDataVo.getDataObj());
+ }
+ }
+ // 添加表格组件中的子组件到组件列表中
+ List allDownwardFormAttributeList = new ArrayList<>();
+ for (FormAttributeVo formAttributeVo : formAttributeList) {
+ JSONObject componentObj = new JSONObject();
+ componentObj.put("handler", formAttributeVo.getHandler());
+ componentObj.put("uuid", formAttributeVo.getUuid());
+ componentObj.put("label", formAttributeVo.getLabel());
+ componentObj.put("config", formAttributeVo.getConfig());
+ componentObj.put("type", formAttributeVo.getType());
+ List downwardFormAttributeList = FormUtil.getFormAttributeList(componentObj, null);
+ for (FormAttributeVo downwardFormAttribute : downwardFormAttributeList) {
+ if (Objects.equals(formAttributeVo.getUuid(), downwardFormAttribute.getUuid())) {
+ continue;
+ }
+ allDownwardFormAttributeList.add(downwardFormAttribute);
+ }
+ }
+ formAttributeList.addAll(allDownwardFormAttributeList);
+ }
+
+ JSONObject processTaskParam = ProcessTaskConditionFactory.getConditionParamData(Arrays.stream(ConditionProcessTaskOptions.values()).map(ConditionProcessTaskOptions::getValue).collect(Collectors.toList()), currentProcessTaskStepVo);
+ // 作业策略createJobPolicy为single时表示单次创建作业,createJobPolicy为batch时表示批量创建作业
+ String createPolicy = createJobConfigConfigVo.getCreatePolicy();
+ if (Objects.equals(createPolicy, "single")) {
+ AutoexecJobVo jobVo = createSingleAutoexecJobVo(currentProcessTaskStepVo, createJobConfigConfigVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+// jobVo.setRunnerGroup(getRunnerGroup(jobVo.getParam(), autoexecConfig));
+ List resultList = new ArrayList<>();
+ resultList.add(jobVo);
+ return resultList;
+ } else if (Objects.equals(createPolicy, "batch")) {
+ List jobVoList = createBatchAutoexecJobVo(currentProcessTaskStepVo, createJobConfigConfigVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+// if (CollectionUtils.isNotEmpty(jobVoList)) {
+// jobVoList.forEach(jobVo -> jobVo.setRunnerGroup(getRunnerGroup(jobVo.getParam(), autoexecConfig)));
+// }
+ return jobVoList;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * 单次创建作业
+ *
+ * @param currentProcessTaskStepVo
+ * @param createJobConfigConfigVo
+ * @param formAttributeList
+ * @param originalFormAttributeDataMap
+ * @param formAttributeDataMap
+ * @param processTaskParam
+ * @return
+ */
+ private static AutoexecJobVo createSingleAutoexecJobVo(
+ ProcessTaskStepVo currentProcessTaskStepVo,
+ CreateJobConfigConfigVo createJobConfigConfigVo,
+ List formAttributeList,
+ Map originalFormAttributeDataMap,
+ Map formAttributeDataMap,
+ JSONObject processTaskParam) {
+ AutoexecJobVo jobVo = new AutoexecJobVo();
+ // 组合工具ID
+ Long combopId = createJobConfigConfigVo.getCombopId();
+ // 作业名称
+ String jobName = createJobConfigConfigVo.getJobName();
+ // 场景
+ List scenarioParamMappingList = createJobConfigConfigVo.getScenarioParamMappingGroupList();
+ if (CollectionUtils.isNotEmpty(scenarioParamMappingList)) {
+ Long scenarioId = getScenarioId(scenarioParamMappingList.get(0), formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ jobVo.setScenarioId(scenarioId);
+ }
+ // 作业参数赋值列表
+ List runtimeParamMappingGroupList = createJobConfigConfigVo.getJopParamMappingGroupList();
+ if (CollectionUtils.isNotEmpty(runtimeParamMappingGroupList)) {
+ JSONObject param = new JSONObject();
+ for(CreateJobConfigMappingGroupVo mappingGroupVo : runtimeParamMappingGroupList) {
+ Object value = parseRuntimeParamMapping(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ param.put(mappingGroupVo.getKey(), value);
+ }
+ jobVo.setParam(param);
+ }
+ // 目标参数赋值列表
+// JSONArray executeParamList = autoexecConfig.getJSONArray("executeParamList");
+ List executeParamMappingGroupList = createJobConfigConfigVo.getExecuteParamMappingGroupList();
+ if (CollectionUtils.isNotEmpty(executeParamMappingGroupList)) {
+ AutoexecCombopExecuteConfigVo executeConfig = new AutoexecCombopExecuteConfigVo();
+// AutoexecCombopExecuteConfigVo executeConfig = getAutoexecCombopExecuteConfig(executeParamList, formAttributeMap, processTaskFormAttributeDataMap);
+ for (CreateJobConfigMappingGroupVo mappingGroupVo : executeParamMappingGroupList) {
+ String key = mappingGroupVo.getKey();
+ if (Objects.equals(key, "executeNodeConfig")) {
+ Object value = parseExecuteNodeConfigMapping(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ } else if (Objects.equals(key, "protocolId")) {
+ Object value = parseProtocolIdMapping(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ } else if (Objects.equals(key, "executeUser")) {
+ Object value = parseExecuteUserParamMapping(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ } else if (Objects.equals(key, "roundCount")) {
+ Object value = parseRoundCountMapping(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ }
+ }
+ jobVo.setExecuteConfig(executeConfig);
+ }
+// String jobNamePrefixKey = autoexecConfig.getString("jobNamePrefix");
+
+ String jobNamePrefixMappingKey = createJobConfigConfigVo.getJobNamePrefixMappingValue();
+ String jobNamePrefixValue = getJobNamePrefixValue(jobNamePrefixMappingKey, jobVo.getExecuteConfig(), jobVo.getParam());
+
+// CreateJobConfigMappingGroupVo runnerGroupMapping = createJobConfigConfigVo.getRunnerGroupMappingGroup();
+// ParamMappingVo runnerGroupMappingVo = parseRunnerGroupMapping(runnerGroupMapping, jobVo.getParam());
+ jobVo.setSource(AutoExecJobProcessSource.ITSM.getValue());
+ jobVo.setRoundCount(32);
+ jobVo.setOperationId(combopId);
+ jobVo.setName(jobNamePrefixValue + jobName);
+ jobVo.setOperationType(CombopOperationType.COMBOP.getValue());
+ jobVo.setInvokeId(currentProcessTaskStepVo.getId());
+ jobVo.setRouteId(currentProcessTaskStepVo.getId().toString());
+ jobVo.setIsFirstFire(1);
+ jobVo.setAssignExecUser(SystemUser.SYSTEM.getUserUuid());
+// jobVo.setRunnerGroup(runnerGroupMappingVo);
+ return jobVo;
+ }
+
+
+ private static Integer parseRoundCountMapping(
+ CreateJobConfigMappingGroupVo mappingGroupVo,
+ List formAttributeList,
+ Map originalFormAttributeDataMap,
+ Map formAttributeDataMap,
+ JSONObject processTaskParam
+ ) {
+ Integer roundCount = null;
+ List mappingList = mappingGroupVo.getMappingList();
+ if (CollectionUtils.isEmpty(mappingList)) {
+ return null;
+ }
+ for (CreateJobConfigMappingVo mappingVo : mappingList) {
+ String mappingMode = mappingVo.getMappingMode();
+ Object value = mappingVo.getValue();
+ if (Objects.equals(mappingMode, "formTableComponent")) {
+ // 映射模式为表单表格组件
+
+ } else if (Objects.equals(mappingMode, "formCommonComponent")) {
+ // 映射模式为表单普通组件
+ Object obj = formAttributeDataMap.get(value);
+ roundCount = Integer.getInteger(obj.toString());
+ } else if (Objects.equals(mappingMode, "constant")) {
+ // 映射模式为常量
+ roundCount = Integer.getInteger(value.toString());
+ } else if (Objects.equals(mappingMode, "runtimeparam")) {
+ // 映射模式为作业参数,只读
+
+ }
+ }
+ return roundCount;
+ }
+
+ private static ParamMappingVo parseExecuteUserParamMapping(
+ CreateJobConfigMappingGroupVo mappingGroupVo,
+ List formAttributeList,
+ Map originalFormAttributeDataMap,
+ Map formAttributeDataMap,
+ JSONObject processTaskParam
+ ) {
+ List mappingList = mappingGroupVo.getMappingList();
+ if (CollectionUtils.isEmpty(mappingList)) {
+ return null;
+ }
+ for (CreateJobConfigMappingVo mappingVo : mappingList) {
+ String mappingMode = mappingVo.getMappingMode();
+ Object value = mappingVo.getValue();
+ if (Objects.equals(mappingMode, "formTableComponent")) {
+ // 映射模式为表单表格组件
+
+ } else if (Objects.equals(mappingMode, "formCommonComponent")) {
+ // 映射模式为表单普通组件
+ Object obj = formAttributeDataMap.get(value);
+ if (obj != null) {
+ ParamMappingVo paramMappingVo = new ParamMappingVo();
+ paramMappingVo.setMappingMode("constant");
+ paramMappingVo.setValue(obj);
+ return paramMappingVo;
+ }
+ } else if (Objects.equals(mappingMode, "constant")) {
+ // 映射模式为常量
+ ParamMappingVo paramMappingVo = new ParamMappingVo();
+ paramMappingVo.setMappingMode("constant");
+ paramMappingVo.setValue(value);
+ return paramMappingVo;
+ } else if (Objects.equals(mappingMode, "runtimeparam")) {
+ // 映射模式为作业参数,只读
+ ParamMappingVo paramMappingVo = new ParamMappingVo();
+ paramMappingVo.setMappingMode("runtimeparam");
+ paramMappingVo.setValue(value);
+ return paramMappingVo;
+ }
+ }
+ return null;
+ }
+
+ private static Long parseProtocolIdMapping(
+ CreateJobConfigMappingGroupVo mappingGroupVo,
+ List formAttributeList,
+ Map originalFormAttributeDataMap,
+ Map formAttributeDataMap,
+ JSONObject processTaskParam
+ ) {
+ Long protocolId = null;
+ List mappingList = mappingGroupVo.getMappingList();
+ if (CollectionUtils.isEmpty(mappingList)) {
+ return protocolId;
+ }
+ for (CreateJobConfigMappingVo mappingVo : mappingList) {
+ String mappingMode = mappingVo.getMappingMode();
+ Object value = mappingVo.getValue();
+ if (Objects.equals(mappingMode, "formTableComponent")) {
+ // 映射模式为表单表格组件
+
+ } else if (Objects.equals(mappingMode, "formCommonComponent")) {
+ // 映射模式为表单普通组件
+ Object obj = formAttributeDataMap.get(value);
+ try {
+ protocolId = Long.valueOf(obj.toString());
+ } catch (NumberFormatException ex) {
+ IResourceAccountCrossoverMapper resourceAccountCrossoverMapper = CrossoverServiceFactory.getApi(IResourceAccountCrossoverMapper.class);
+ AccountProtocolVo protocolVo = resourceAccountCrossoverMapper.getAccountProtocolVoByProtocolName(obj.toString());
+ if (protocolVo != null) {
+ protocolId = protocolVo.getId();
+ }
+ }
+ } else if (Objects.equals(mappingMode, "constant")) {
+ // 映射模式为常量
+ protocolId = Long.valueOf(value.toString());
+ } else if (Objects.equals(mappingMode, "runtimeparam")) {
+ // 映射模式为作业参数,只读
+
+ }
+ }
+ return protocolId;
+ }
+
+ private static AutoexecCombopExecuteNodeConfigVo parseExecuteNodeConfigMapping(
+ CreateJobConfigMappingGroupVo mappingGroupVo,
+ List formAttributeList,
+ Map originalFormAttributeDataMap,
+ Map formAttributeDataMap,
+ JSONObject processTaskParam
+ ) {
+ List formTextAttributeList = new ArrayList<>();
+ formTextAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMTEXT.getHandler());
+ formTextAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMTEXTAREA.getHandler());
+ List mappingList = mappingGroupVo.getMappingList();
+ if (CollectionUtils.isEmpty(mappingList)) {
+ return null;
+ }
+ for (CreateJobConfigMappingVo mappingVo : mappingList) {
+ String mappingMode = mappingVo.getMappingMode();
+ Object value = mappingVo.getValue();
+ if (Objects.equals(mappingMode, "formTableComponent")) {
+ // 映射模式为表单表格组件
+ JSONArray array = parseFormTableComponentMappingMode(mappingVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ if (CollectionUtils.isNotEmpty(array)) {
+ AutoexecCombopExecuteNodeConfigVo executeNodeConfigVo = new AutoexecCombopExecuteNodeConfigVo();
+ List inputNodeList = new ArrayList<>();
+ for (int i = 0; i < array.size(); i++) {
+ String str = array.getString(i);
+ inputNodeList.add(new AutoexecNodeVo(str));
+ }
+ executeNodeConfigVo.setInputNodeList(inputNodeList);
+ return executeNodeConfigVo;
+ }
+ } else if (Objects.equals(mappingMode, "formCommonComponent")) {
+ // 映射模式为表单普通组件
+ Object dataObj = formAttributeDataMap.get(value);
+ if (dataObj != null) {
+ AutoexecCombopExecuteNodeConfigVo executeNodeConfigVo = new AutoexecCombopExecuteNodeConfigVo();
+ String handler = null;
+ Optional first = formAttributeList.stream().filter(e -> Objects.equals(e.getUuid(), value)).findFirst();
+ if (first.isPresent()) {
+ FormAttributeVo formAttributeVo = first.get();
+ handler = formAttributeVo.getHandler();
+ }
+ if (Objects.equals(handler, FormHandler.FORMRESOURECES.getHandler())) {
+ // 映射的表单组件是执行目标
+ executeNodeConfigVo = ((JSONObject) dataObj).toJavaObject(AutoexecCombopExecuteNodeConfigVo.class);
+ } else if (formTextAttributeList.contains(handler)) {
+ // 映射的表单组件是文本框
+ String dataStr = dataObj.toString();
+ try {
+ List inputNodeList = new ArrayList<>();
+ JSONArray array = JSONArray.parseArray(dataStr);
+ for (int j = 0; j < array.size(); j++) {
+ String str = array.getString(j);
+ inputNodeList.add(new AutoexecNodeVo(str));
+ }
+ executeNodeConfigVo.setInputNodeList(inputNodeList);
+ } catch (JSONException e) {
+ List inputNodeList = new ArrayList<>();
+ inputNodeList.add(new AutoexecNodeVo(dataObj.toString()));
+ executeNodeConfigVo.setInputNodeList(inputNodeList);
+ }
+ } else {
+ // 映射的表单组件不是执行目标
+ List inputNodeList = new ArrayList<>();
+ inputNodeList.add(new AutoexecNodeVo(dataObj.toString()));
+ executeNodeConfigVo.setInputNodeList(inputNodeList);
+ }
+ return executeNodeConfigVo;
+ }
+ } else if (Objects.equals(mappingMode, "constant")) {
+ // 映射模式为常量
+// value;
+ } else if (Objects.equals(mappingMode, "runtimeparam")) {
+ // 映射模式为作业参数,只读
+// if (Objects.equals(key, "executeUser")) {
+// ParamMappingVo paramMappingVo = new ParamMappingVo();
+// paramMappingVo.setMappingMode("runtimeparam");
+// paramMappingVo.setValue(value);
+// executeConfig.put(key, paramMappingVo);
+// }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * 批量创建作业
+ *
+ * @param currentProcessTaskStepVo
+ * @param createJobConfigConfigVo
+ * @param formAttributeList
+ * @param originalFormAttributeDataMap
+ * @param formAttributeDataMap
+ * @param processTaskParam
+ * @return
+ */
+ private static List createBatchAutoexecJobVo(
+ ProcessTaskStepVo currentProcessTaskStepVo,
+ CreateJobConfigConfigVo createJobConfigConfigVo,
+ List formAttributeList,
+ Map originalFormAttributeDataMap,
+ Map formAttributeDataMap,
+ JSONObject processTaskParam) {
+
+ List resultList = new ArrayList<>();
+ // 批量遍历表格
+ CreateJobConfigMappingVo batchDataSourceMapping = createJobConfigConfigVo.getBatchDataSourceMapping();
+ if (batchDataSourceMapping == null) {
+ return resultList;
+ }
+ JSONArray tbodyList = parseFormTableComponentMappingMode(batchDataSourceMapping, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ if (CollectionUtils.isEmpty(tbodyList)) {
+ return resultList;
+ }
+ // 遍历表格数据,创建AutoexecJobVo对象列表
+ for (Object obj : tbodyList) {
+ formAttributeDataMap.put(batchDataSourceMapping.getValue().toString(), Collections.singletonList(obj));
+ AutoexecJobVo jobVo = createSingleAutoexecJobVo(currentProcessTaskStepVo, createJobConfigConfigVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ resultList.add(jobVo);
+ }
+ return resultList;
+ }
+
+ /**
+ * 获取场景ID
+ *
+ * @param mappingGroupVo
+ * @param formAttributeList
+ * @param originalFormAttributeDataMap
+ * @param formAttributeDataMap
+ * @param processTaskParam
+ * @return
+ */
+ private static Long getScenarioId(CreateJobConfigMappingGroupVo mappingGroupVo,
+ List formAttributeList,
+ Map originalFormAttributeDataMap,
+ Map formAttributeDataMap,
+ JSONObject processTaskParam) {
+
+ String key = mappingGroupVo.getKey();
+ if (StringUtils.isBlank(key)) {
+ return null;
+ }
+ String type = mappingGroupVo.getType();
+ List mappingList = mappingGroupVo.getMappingList();
+ if (CollectionUtils.isEmpty(mappingList)) {
+ return null;
+ }
+ for (CreateJobConfigMappingVo mappingVo : mappingList) {
+ Object value = mappingVo.getValue();
+ if (value == null) {
+ return null;
+ }
+ Object scenario = null;
+ String mappingMode = mappingVo.getMappingMode();
+ if (Objects.equals(mappingMode, "formTableComponent")) {
+ scenario = parseFormTableComponentMappingMode(mappingVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ } else if (Objects.equals(mappingMode, "formCommonComponent")) {
+ scenario = formAttributeDataMap.get(value);
+ } else if (Objects.equals(mappingMode, "constant")) {
+ scenario = value;
+ }
+ if (scenario != null) {
+ if (scenario instanceof List) {
+ List scenarioList = (List) scenario;
+ if (CollectionUtils.isNotEmpty(scenarioList)) {
+ scenario = scenarioList.get(0);
+ }
+ }
+ IAutoexecScenarioCrossoverMapper autoexecScenarioCrossoverMapper = CrossoverServiceFactory.getApi(IAutoexecScenarioCrossoverMapper.class);
+ if (scenario instanceof String) {
+ String scenarioName = (String) scenario;
+ AutoexecScenarioVo scenarioVo = autoexecScenarioCrossoverMapper.getScenarioByName(scenarioName);
+ if (scenarioVo != null) {
+ return scenarioVo.getId();
+ } else {
+ try {
+ Long scenarioId = Long.valueOf(scenarioName);
+ if (autoexecScenarioCrossoverMapper.getScenarioById(scenarioId) != null) {
+ return scenarioId;
+ }
+ } catch (NumberFormatException ignored) {
+
+ }
+ }
+ } else if (scenario instanceof Long) {
+ Long scenarioId = (Long) scenario;
+ if (autoexecScenarioCrossoverMapper.getScenarioById(scenarioId) != null) {
+ return scenarioId;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 根据设置找到作业名称前缀值
+ *
+ * @param jobNamePrefixKey 作业名称前缀key
+ * @param executeConfig 目标参数
+ * @param param 作业参数
+ * @return 返回作业名称前缀值
+ */
+ private static String getJobNamePrefixValue2(String jobNamePrefixKey, AutoexecCombopExecuteConfigVo executeConfig, JSONObject param) {
+ String jobNamePrefixValue = StringUtils.EMPTY;
+ if (StringUtils.isBlank(jobNamePrefixKey)) {
+ return jobNamePrefixValue;
+ }
+ if (Objects.equals(jobNamePrefixKey, "executeNodeConfig")) {
+ AutoexecCombopExecuteNodeConfigVo executeNodeConfig = executeConfig.getExecuteNodeConfig();
+ List inputNodeList = executeNodeConfig.getInputNodeList();
+ List selectNodeList = executeNodeConfig.getSelectNodeList();
+ List paramList = executeNodeConfig.getParamList();
+ if (CollectionUtils.isNotEmpty(inputNodeList)) {
+ List list = new ArrayList<>();
+ for (AutoexecNodeVo node : inputNodeList) {
+ list.add(node.toString());
+ }
+ jobNamePrefixValue = String.join("", list);
+ } else if (CollectionUtils.isNotEmpty(selectNodeList)) {
+ List list = new ArrayList<>();
+ for (AutoexecNodeVo node : selectNodeList) {
+ list.add(node.toString());
+ }
+ jobNamePrefixValue = String.join("", list);
+ } else if (CollectionUtils.isNotEmpty(paramList)) {
+ List list = new ArrayList<>();
+ for (String paramKey : paramList) {
+ Object value = param.get(paramKey);
+ if (value != null) {
+ if (value instanceof String) {
+ list.add((String) value);
+ } else {
+ list.add(JSONObject.toJSONString(value));
+ }
+ }
+ }
+ jobNamePrefixValue = String.join("", list);
+ }
+ } else if (Objects.equals(jobNamePrefixKey, "executeUser")) {
+ ParamMappingVo executeUser = executeConfig.getExecuteUser();
+ if (executeUser != null) {
+ Object value = executeUser.getValue();
+ if (value != null) {
+ if (Objects.equals(executeUser.getMappingMode(), "runtimeparam")) {
+ value = param.get(value);
+ }
+ if (value != null) {
+ if (value instanceof String) {
+ jobNamePrefixValue = (String) value;
+ } else {
+ jobNamePrefixValue = JSONObject.toJSONString(value);
+ }
+ }
+ }
+ }
+ } else if (Objects.equals(jobNamePrefixKey, "protocolId")) {
+ Long protocolId = executeConfig.getProtocolId();
+ if (protocolId != null) {
+ jobNamePrefixValue = protocolId.toString();
+ }
+ } else if (Objects.equals(jobNamePrefixKey, "roundCount")) {
+ Integer roundCount = executeConfig.getRoundCount();
+ if (roundCount != null) {
+ jobNamePrefixValue = roundCount.toString();
+ }
+ } else {
+ Object jobNamePrefixObj = param.get(jobNamePrefixKey);
+ if (jobNamePrefixObj instanceof String) {
+ jobNamePrefixValue = (String) jobNamePrefixObj;
+ } else {
+ jobNamePrefixValue = JSONObject.toJSONString(jobNamePrefixObj);
+ }
+ }
+ if (StringUtils.isBlank(jobNamePrefixValue)) {
+ return StringUtils.EMPTY;
+ } else if (jobNamePrefixValue.length() > 32) {
+ return jobNamePrefixValue.substring(0, 32);
+ }
+ return jobNamePrefixValue;
+ }
+
+ /**
+ * 根据设置找到作业名称前缀值
+ *
+ * @param jobNamePrefixKey 作业名称前缀key
+ * @param executeConfig 目标参数
+ * @param param 作业参数
+ * @return 返回作业名称前缀值
+ */
+ private static String getJobNamePrefixValue(String jobNamePrefixKey, AutoexecCombopExecuteConfigVo executeConfig, JSONObject param) {
+ String jobNamePrefixValue = StringUtils.EMPTY;
+ if (StringUtils.isBlank(jobNamePrefixKey)) {
+ return jobNamePrefixValue;
+ }
+ if (Objects.equals(jobNamePrefixKey, "executeNodeConfig")) {
+ AutoexecCombopExecuteNodeConfigVo executeNodeConfig = executeConfig.getExecuteNodeConfig();
+ List inputNodeList = executeNodeConfig.getInputNodeList();
+ List selectNodeList = executeNodeConfig.getSelectNodeList();
+ List paramList = executeNodeConfig.getParamList();
+ if (CollectionUtils.isNotEmpty(inputNodeList)) {
+ List list = new ArrayList<>();
+ for (AutoexecNodeVo node : inputNodeList) {
+ list.add(node.toString());
+ }
+ jobNamePrefixValue = String.join("", list);
+ } else if (CollectionUtils.isNotEmpty(selectNodeList)) {
+ List list = new ArrayList<>();
+ for (AutoexecNodeVo node : selectNodeList) {
+ list.add(node.toString());
+ }
+ jobNamePrefixValue = String.join("", list);
+ } else if (CollectionUtils.isNotEmpty(paramList)) {
+ List list = new ArrayList<>();
+ for (String paramKey : paramList) {
+ Object value = param.get(paramKey);
+ if (value != null) {
+ if (value instanceof String) {
+ list.add((String) value);
+ } else {
+ list.add(JSONObject.toJSONString(value));
+ }
+ }
+ }
+ jobNamePrefixValue = String.join("", list);
+ }
+ } else if (Objects.equals(jobNamePrefixKey, "executeUser")) {
+ ParamMappingVo executeUser = executeConfig.getExecuteUser();
+ if (executeUser != null) {
+ Object value = executeUser.getValue();
+ if (value != null) {
+ if (Objects.equals(executeUser.getMappingMode(), "runtimeparam")) {
+ value = param.get(value);
+ }
+ if (value != null) {
+ if (value instanceof String) {
+ jobNamePrefixValue = (String) value;
+ } else {
+ jobNamePrefixValue = JSONObject.toJSONString(value);
+ }
+ }
+ }
+ }
+ } else if (Objects.equals(jobNamePrefixKey, "protocolId")) {
+ Long protocolId = executeConfig.getProtocolId();
+ if (protocolId != null) {
+ jobNamePrefixValue = protocolId.toString();
+ }
+ } else if (Objects.equals(jobNamePrefixKey, "roundCount")) {
+ Integer roundCount = executeConfig.getRoundCount();
+ if (roundCount != null) {
+ jobNamePrefixValue = roundCount.toString();
+ }
+ } else {
+ Object jobNamePrefixObj = param.get(jobNamePrefixKey);
+ if (jobNamePrefixObj instanceof String) {
+ jobNamePrefixValue = (String) jobNamePrefixObj;
+ } else {
+ jobNamePrefixValue = JSONObject.toJSONString(jobNamePrefixObj);
+ }
+ }
+ if (StringUtils.isBlank(jobNamePrefixValue)) {
+ return StringUtils.EMPTY;
+ } else if (jobNamePrefixValue.length() > 32) {
+ return jobNamePrefixValue.substring(0, 32);
+ }
+ return jobNamePrefixValue;
+ }
+
+ private static Object parseRuntimeParamMapping(CreateJobConfigMappingGroupVo mappingGroupVo,
+ List formAttributeList,
+ Map originalFormAttributeDataMap,
+ Map formAttributeDataMap,
+ JSONObject processTaskParam) {
+ List formSelectAttributeList = new ArrayList<>();
+ formSelectAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMSELECT.getHandler());
+ formSelectAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMCHECKBOX.getHandler());
+ formSelectAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMRADIO.getHandler());
+ List formTextAttributeList = new ArrayList<>();
+ formTextAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMTEXT.getHandler());
+ formTextAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMTEXTAREA.getHandler());
+ String key = mappingGroupVo.getKey();
+ if (StringUtils.isBlank(key)) {
+ return null;
+ }
+ String type = mappingGroupVo.getType();
+ List mappingList = mappingGroupVo.getMappingList();
+ if (CollectionUtils.isEmpty(mappingList)) {
+ return null;
+ }
+ JSONArray resultList = new JSONArray();
+ for (CreateJobConfigMappingVo mappingVo : mappingList) {
+ Object value = mappingVo.getValue();
+ if (value == null) {
+ continue;
+ }
+ String mappingMode = mappingVo.getMappingMode();
+ if (Objects.equals(mappingMode, "formTableComponent")) {
+ resultList.add(parseFormTableComponentMappingMode(mappingVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam));
+ } else if (Objects.equals(mappingMode, "formCommonComponent")) {
+ Object obj = formAttributeDataMap.get(value);
+ if (obj != null) {
+ String handler = null;
+ FormAttributeVo formAttributeVo = getFormAttributeVo(formAttributeList, value.toString());
+ if (formAttributeVo != null) {
+ handler = formAttributeVo.getHandler();
+ }
+ if (formTextAttributeList.contains(handler)) {
+ resultList.add(convertDateType(type, (String) obj));
+ } else if (formSelectAttributeList.contains(handler)) {
+ if (obj instanceof String) {
+ resultList.add(convertDateType(type, (String) obj));
+ } else if (obj instanceof JSONArray) {
+ resultList.add(convertDateType(type, JSONObject.toJSONString(obj)));
+ }
+ }
+ }
+ } else if (Objects.equals(mappingMode, "constant")) {
+ resultList.add(value);
+ } else if (Objects.equals(mappingMode, "processTaskParam")) {
+ resultList.add(processTaskParam.get(value));
+ } else if (Objects.equals(mappingMode, "expression")) {
+ if (value instanceof JSONArray) {
+ resultList.add(parseExpression((JSONArray) value, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam));
+ }
+ }
+ }
+ if (mappingList.size() == 1) {
+ return resultList.get(0);
+ }
+ return resultList;
+ }
+
+ /**
+ * 解析表单表格组件映射模式,得到映射结果
+ * @param mappingVo
+ * @param formAttributeList
+ * @param originalFormAttributeDataMap
+ * @param formAttributeDataMap
+ * @param processTaskParam
+ * @return
+ */
+ private static JSONArray parseFormTableComponentMappingMode(CreateJobConfigMappingVo mappingVo,
+ List formAttributeList,
+ Map originalFormAttributeDataMap,
+ Map formAttributeDataMap,
+ Map processTaskParam) {
+ JSONArray resultList = new JSONArray();
+ List mainTableDataList = getFormTableComponentData(formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, mappingVo.getValue().toString());
+ if (CollectionUtils.isEmpty(mainTableDataList)) {
+ return resultList;
+ }
+ List filterList = mappingVo.getFilterList();
+ if (CollectionUtils.isNotEmpty(filterList)) {
+ List totalDerivedTableDataList = new ArrayList<>();
+ for (JSONObject rowData : mainTableDataList) {
+ JSONObject newRowData = new JSONObject();
+ for (Map.Entry entry : rowData.entrySet()) {
+ newRowData.put(mappingVo.getValue() + "." + entry.getKey(), entry.getValue());
+ }
+ totalDerivedTableDataList.add(newRowData);
+ }
+ for (CreateJobConfigFilterVo filterVo : filterList) {
+ if (CollectionUtils.isEmpty(totalDerivedTableDataList)) {
+ break;
+ }
+ List derivedTableDataList = new ArrayList<>();
+ if (Objects.equals(filterVo.getLeftMappingMode() ,"formTableComponent")) {
+ if (Objects.equals(filterVo.getRightMappingMode() ,"formTableComponent")) {
+ boolean flag = false;
+ for (JSONObject rowData : totalDerivedTableDataList) {
+ if (rowData.containsKey(filterVo.getRightValue() + ".")) {
+ flag = true;
+ break;
+ }
+ }
+ if (!flag) {
+ List rightTableDataList = getFormTableComponentData(formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, filterVo.getRightValue());
+ if (CollectionUtils.isNotEmpty(rightTableDataList)) {
+ for (JSONObject rowData : totalDerivedTableDataList) {
+ Object leftData = rowData.get(filterVo.getLeftValue() + "." + filterVo.getLeftColumn());
+ for (JSONObject rightRowData : rightTableDataList) {
+ Object rightData = rightRowData.get(filterVo.getRightColumn());
+ if (expressionAssert(leftData, filterVo.getExpression(), rightData)) {
+ JSONObject newRowData = new JSONObject();
+ newRowData.putAll(rowData);
+ for (Map.Entry entry : rightRowData.entrySet()) {
+ newRowData.put(filterVo.getRightValue() + "." + entry.getKey(), entry.getValue());
+ }
+ derivedTableDataList.add(newRowData);
+ }
+ }
+ }
+ }
+ } else {
+ for (JSONObject rowData : totalDerivedTableDataList) {
+ Object leftData = rowData.get(filterVo.getLeftValue() + "." + filterVo.getLeftColumn());
+ Object rightData = rowData.get(filterVo.getRightValue() + "." + filterVo.getRightColumn());
+ if (expressionAssert(leftData, filterVo.getExpression(), rightData)) {
+ derivedTableDataList.add(rowData);
+ }
+ }
+ }
+ } else if (Objects.equals(filterVo.getRightMappingMode() ,"formCommonComponent")) {
+ Object rightData = formAttributeDataMap.get(filterVo.getRightValue());
+ for (JSONObject rowData : totalDerivedTableDataList) {
+ Object leftData = rowData.get(filterVo.getLeftValue() + "." + filterVo.getLeftColumn());
+ if (expressionAssert(leftData, filterVo.getExpression(), rightData)) {
+ derivedTableDataList.add(rowData);
+ }
+ }
+ } else if (Objects.equals(filterVo.getRightMappingMode() ,"constant")) {
+ Object rightData = filterVo.getRightValue();
+ for (JSONObject rowData : totalDerivedTableDataList) {
+ Object leftData = rowData.get(filterVo.getLeftValue() + "." + filterVo.getLeftColumn());
+ if (expressionAssert(leftData, filterVo.getExpression(), rightData)) {
+ derivedTableDataList.add(rowData);
+ }
+ }
+ } else if (Objects.equals(filterVo.getRightMappingMode() ,"processTaskParam")) {
+ Object rightData = processTaskParam.get(filterVo.getRightValue());
+ for (JSONObject rowData : totalDerivedTableDataList) {
+ Object leftData = rowData.get(filterVo.getLeftValue() + "." + filterVo.getLeftColumn());
+ if (expressionAssert(leftData, filterVo.getExpression(), rightData)) {
+ derivedTableDataList.add(rowData);
+ }
+ }
+ } else if (Objects.equals(filterVo.getRightMappingMode() ,"expression")) {
+ Object rightData = filterVo.getRightValue();
+ for (JSONObject rowData : totalDerivedTableDataList) {
+ Object leftData = rowData.get(filterVo.getLeftValue() + "." + filterVo.getLeftColumn());
+ if (expressionAssert(leftData, filterVo.getExpression(), rightData)) {
+ derivedTableDataList.add(rowData);
+ }
+ }
+ }
+ }
+ totalDerivedTableDataList = derivedTableDataList;
+ }
+ if (CollectionUtils.isEmpty(totalDerivedTableDataList)) {
+ return resultList;
+ }
+ List derivedTableDataList = new ArrayList<>();
+ for (JSONObject rowData : totalDerivedTableDataList) {
+ JSONObject newRowData = new JSONObject();
+ String prefix = mappingVo.getValue().toString() + ".";
+ for (Map.Entry entry : rowData.entrySet()) {
+ String key = entry.getKey();
+ if (key.startsWith(prefix)) {
+ key = key.substring(prefix.length());
+ newRowData.put(key, entry.getValue());
+ }
+ }
+ if (!derivedTableDataList.contains(newRowData)) {// TODO 这里需要验证HashMap的equals方法
+ derivedTableDataList.add(newRowData);
+ }
+ }
+ mainTableDataList = derivedTableDataList;
+ }
+ if (StringUtils.isNotBlank(mappingVo.getColumn())) {
+ for (JSONObject rowData : mainTableDataList) {
+ Object obj = rowData.get(mappingVo.getColumn());
+ if (obj != null) {
+ resultList.add(obj);
+ }
+ }
+ } else {
+ resultList.addAll(mainTableDataList);
+ }
+ if (Boolean.TRUE.equals(mappingVo.getDistinct())) {
+ JSONArray tempList = new JSONArray();
+ for (Object obj : resultList) {
+ if (!tempList.contains(obj)) {
+ tempList.add(obj);
+ }
+ }
+ resultList = tempList;
+ }
+ if (CollectionUtils.isNotEmpty(mappingVo.getLimit())) {
+ Integer fromIndex = mappingVo.getLimit().get(0);
+ int toIndex = resultList.size();
+ if (mappingVo.getLimit().size() > 1) {
+ Integer pageSize = mappingVo.getLimit().get(1);
+ toIndex = fromIndex + pageSize;
+ if (toIndex > resultList.size()) {
+ toIndex = resultList.size();
+ }
+ }
+ JSONArray tempList = new JSONArray();
+ for (int i = 0; i < resultList.size(); i++) {
+ if (i >= fromIndex && i < toIndex) {
+ tempList.add(resultList.get(i));
+ }
+ }
+ resultList = tempList;
+ }
+ return resultList;
+ }
+
+ private static boolean expressionAssert(Object leftValue, String expression, Object rightValue) {
+ if (Objects.equals(expression, Expression.EQUAL.getExpression())) {
+ if (Objects.equals(leftValue, rightValue) || Objects.equals(JSONObject.toJSONString(leftValue).toLowerCase(), JSONObject.toJSONString(rightValue).toLowerCase())) {
+ return true;
+ }
+ } else if (Objects.equals(expression, Expression.UNEQUAL.getExpression())) {
+ if (!Objects.equals(leftValue, rightValue) && !Objects.equals(JSONObject.toJSONString(leftValue).toLowerCase(), JSONObject.toJSONString(rightValue).toLowerCase())) {
+ return true;
+ }
+ } else if (Objects.equals(expression, Expression.LIKE.getExpression())) {
+ if (leftValue == null || rightValue == null) {
+ return false;
+ }
+ String leftValueStr = JSONObject.toJSONString(leftValue).toLowerCase();
+ String rightValueStr = JSONObject.toJSONString(rightValue).toLowerCase();
+ if (leftValueStr.contains(rightValueStr)) {
+ return true;
+ }
+ } else if (Objects.equals(expression, Expression.NOTLIKE.getExpression())) {
+ if (leftValue == null || rightValue == null) {
+ return false;
+ }
+ String leftValueStr = JSONObject.toJSONString(leftValue).toLowerCase();
+ String rightValueStr = JSONObject.toJSONString(rightValue).toLowerCase();
+ if (!leftValueStr.contains(rightValueStr)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ /**
+ * 获取表单表格组件的数据
+ * @param formAttributeList
+ * @param originalFormAttributeDataMap
+ * @param attributeUuid
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ private static List getFormTableComponentData(
+ List formAttributeList,
+ Map originalFormAttributeDataMap,
+ Map formAttributeDataMap,
+ String attributeUuid) {
+ List resultList = new ArrayList<>();
+ Object object = formAttributeDataMap.get(attributeUuid);
+ if (object != null) {
+ return (List) object;
+ }
+ Object obj = originalFormAttributeDataMap.get(attributeUuid);
+ if (obj == null) {
+ return resultList;
+ }
+ if (!(obj instanceof JSONArray)) {
+ return resultList;
+ }
+ JSONArray array = (JSONArray) obj;
+ if (CollectionUtils.isEmpty(array)) {
+ return resultList;
+ }
+
+ for (int i = 0; i < array.size(); i++) {
+ JSONObject newJsonObj = array.getJSONObject(i);
+ JSONObject jsonObj = array.getJSONObject(i);
+ for (Map.Entry entry : jsonObj.entrySet()) {
+ String key = entry.getKey();
+ Object value = entry.getValue();
+ FormAttributeVo formAttributeVo = getFormAttributeVo(formAttributeList, key);
+ if (formAttributeVo != null) {
+ IFormAttributeDataConversionHandler handler = FormAttributeDataConversionHandlerFactory.getHandler(formAttributeVo.getHandler());
+ if (handler != null) {
+ value = handler.getSimpleValue(value);
+ }
+ }
+ newJsonObj.put(key, value);
+ }
+ resultList.add(newJsonObj);
+ }
+ return resultList;
+ }
+
+ private static FormAttributeVo getFormAttributeVo(List formAttributeList, String uuid) {
+ if (CollectionUtils.isNotEmpty(formAttributeList)) {
+ for (FormAttributeVo formAttributeVo : formAttributeList) {
+ if (Objects.equals(formAttributeVo.getUuid(), uuid)) {
+ return formAttributeVo;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 解析出表达式的值
+ * @param valueList
+ * @param formAttributeList
+ * @param originalFormAttributeDataMap
+ * @param formAttributeDataMap
+ * @param processTaskParam
+ * @return
+ */
+ private static String parseExpression(JSONArray valueList,
+ List formAttributeList,
+ Map originalFormAttributeDataMap,
+ Map formAttributeDataMap,
+ JSONObject processTaskParam) {
+ StringBuilder stringBuilder = new StringBuilder();
+ List mappingList = valueList.toJavaList(CreateJobConfigMappingVo.class);
+ for (CreateJobConfigMappingVo mappingVo : mappingList) {
+ String value = mappingVo.getValue().toString();
+ String mappingMode = mappingVo.getMappingMode();
+ if (Objects.equals(mappingMode, "formTableComponent")) {
+ JSONArray array = parseFormTableComponentMappingMode(mappingVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ List list = new ArrayList<>();
+ for (int j = 0; j < array.size(); j++) {
+ list.add(array.getString(j));
+ }
+ stringBuilder.append(String.join(",", list));
+ } else if (Objects.equals(mappingMode, "formCommonComponent")) {
+ Object obj = formAttributeDataMap.get(value);
+ if (obj != null) {
+ if (obj instanceof JSONArray) {
+ List list = new ArrayList<>();
+ JSONArray dataObjectArray = (JSONArray) obj;
+ for (int j = 0; j < dataObjectArray.size(); j++) {
+ list.add(dataObjectArray.getString(j));
+ }
+ stringBuilder.append(String.join(",", list));
+ } else {
+ stringBuilder.append(obj);
+ }
+ }
+ } else if (Objects.equals(mappingMode, "constant")) {
+ stringBuilder.append(value);
+ } else if (Objects.equals(mappingMode, "processTaskParam")) {
+ stringBuilder.append(processTaskParam.get(value));
+ }
+ }
+ return stringBuilder.toString();
+ }
+
+ /**
+ * 把表单表格组件中某列数据集合转换成作业参数对应的数据
+ *
+ * @param paramType 作业参数类型
+ * @param sourceList 某列数据集合
+ * @return
+ */
+ private static Object convertDateType(String paramType, List sourceList) {
+ if (Objects.equals(paramType, ParamType.NODE.getValue())) {
+ if (CollectionUtils.isNotEmpty(sourceList)) {
+ JSONArray inputNodeList = new JSONArray();
+ for (String str : sourceList) {
+ if (StringUtils.isNotBlank(str)) {
+ JSONArray inputNodeArray = (JSONArray) convertDateType(paramType, str);
+ inputNodeList.addAll(inputNodeArray);
+ }
+ }
+ return inputNodeList;
+ }
+ }
+ return sourceList;
+ }
+
+ /**
+ * 把表单文本框组件数据转换成作业参数对应的数据
+ *
+ * @param paramType 作业参数类型
+ * @param source 数据
+ * @return Object
+ */
+ private static Object convertDateType(String paramType, String source) {
+ if (Objects.equals(paramType, ParamType.NODE.getValue())) {
+ if (StringUtils.isNotBlank(source)) {
+ JSONArray inputNodeList = new JSONArray();
+ if (source.startsWith("[") && source.endsWith("]")) {
+ JSONArray array = JSON.parseArray(source);
+ for (int i = 0; i < array.size(); i++) {
+ String str = array.getString(i);
+ inputNodeList.add(new AutoexecNodeVo(str));
+ }
+ } else if (source.contains("\n")) {
+ String[] split = source.split("\n");
+ for (String str : split) {
+ inputNodeList.add(new AutoexecNodeVo(str));
+ }
+ } else {
+ inputNodeList.add(new AutoexecNodeVo(source));
+ }
+ return inputNodeList;
+ }
+ }
+ return source;
+ }
+}
--
Gitee
From 2eabcad88293ff6ec2b0e229603396b800e73dab Mon Sep 17 00:00:00 2001
From: "1437892690@qq.com" <1437892690@qq.com>
Date: Tue, 25 Jun 2024 11:30:04 +0800
Subject: [PATCH 2/8] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-?=
=?UTF-8?q?=E6=96=B0=E8=87=AA=E5=8A=A8=E5=8C=96=E8=8A=82=E7=82=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
#[1181690880294912]后端-新自动化节点 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1181690880294912
---
.../api/process/CreateJobStepTestApi.java | 44 +-
.../CreateJobProcessComponent.java | 24 +-
.../util/ParseCreateJobConfigUtil.java | 1056 +++++++++--------
3 files changed, 618 insertions(+), 506 deletions(-)
diff --git a/src/main/java/neatlogic/module/autoexec/api/process/CreateJobStepTestApi.java b/src/main/java/neatlogic/module/autoexec/api/process/CreateJobStepTestApi.java
index 66c4e9ed..02aeb469 100644
--- a/src/main/java/neatlogic/module/autoexec/api/process/CreateJobStepTestApi.java
+++ b/src/main/java/neatlogic/module/autoexec/api/process/CreateJobStepTestApi.java
@@ -17,8 +17,12 @@
package neatlogic.module.autoexec.api.process;
+import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
+import neatlogic.framework.autoexec.dto.combop.AutoexecCombopVersionVo;
import neatlogic.framework.autoexec.dto.job.AutoexecJobVo;
+import neatlogic.framework.autoexec.exception.AutoexecCombopActiveVersionNotFoundException;
+import neatlogic.framework.autoexec.exception.AutoexecCombopVersionNotFoundException;
import neatlogic.framework.common.constvalue.ApiParamType;
import neatlogic.framework.process.dto.ProcessTaskStepVo;
import neatlogic.framework.restful.annotation.Input;
@@ -27,15 +31,22 @@ import neatlogic.framework.restful.annotation.Output;
import neatlogic.framework.restful.annotation.Param;
import neatlogic.framework.restful.constvalue.OperationTypeEnum;
import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase;
+import neatlogic.module.autoexec.dao.mapper.AutoexecCombopVersionMapper;
import neatlogic.module.autoexec.process.dto.CreateJobConfigConfigVo;
import neatlogic.module.autoexec.process.util.ParseCreateJobConfigUtil;
+import neatlogic.module.autoexec.service.AutoexecCombopService;
import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
import java.util.List;
@Service
@OperationType(type = OperationTypeEnum.SEARCH)
public class CreateJobStepTestApi extends PrivateApiComponentBase {
+ @Resource
+ private AutoexecCombopVersionMapper autoexecCombopVersionMapper;
+ @Resource
+ private AutoexecCombopService autoexecCombopService;
@Override
public String getName() {
return "测试新自动化节点";
@@ -56,10 +67,37 @@ public class CreateJobStepTestApi extends PrivateApiComponentBase {
processTaskStepVo.setProcessTaskId(processTaskId);
processTaskStepVo.setId(1L);
CreateJobConfigConfigVo createJobConfigConfigVo = createJobConfigConfig.toJavaObject(CreateJobConfigConfigVo.class);
- List autoexecJobList = ParseCreateJobConfigUtil.createAutoexecJobList(processTaskStepVo, createJobConfigConfigVo);
- System.out.println("autoexecJobList = " + JSONObject.toJSONString(autoexecJobList));
+ Long activeVersionId = autoexecCombopVersionMapper.getAutoexecCombopActiveVersionIdByCombopId(createJobConfigConfigVo.getCombopId());
+ if (activeVersionId == null) {
+ throw new AutoexecCombopActiveVersionNotFoundException(createJobConfigConfigVo.getCombopId());
+ }
+ AutoexecCombopVersionVo autoexecCombopVersionVo = autoexecCombopService.getAutoexecCombopVersionById(activeVersionId);
+ if (autoexecCombopVersionVo == null) {
+ throw new AutoexecCombopVersionNotFoundException(activeVersionId);
+ }
+ List autoexecJobList = ParseCreateJobConfigUtil.createAutoexecJobList(processTaskStepVo, createJobConfigConfigVo, autoexecCombopVersionVo);
+ JSONArray jobArray = new JSONArray();
+ for (AutoexecJobVo jobVo : autoexecJobList) {
+ JSONObject jobObj = new JSONObject();
+ jobObj.put("param", jobVo.getParam());
+ jobObj.put("scenarioId", jobVo.getScenarioId());
+ jobObj.put("executeConfig", jobVo.getExecuteConfig());
+ jobObj.put("runnerGroup", jobVo.getRunnerGroup());
+ jobObj.put("id", jobVo.getId());
+ jobObj.put("name", jobVo.getName());
+ jobObj.put("source", jobVo.getSource());
+ jobObj.put("roundCount", jobVo.getRoundCount());
+ jobObj.put("operationId", jobVo.getOperationId());
+ jobObj.put("operationType", jobVo.getOperationType());
+ jobObj.put("invokeId", jobVo.getInvokeId());
+ jobObj.put("routeId", jobVo.getRouteId());
+ jobObj.put("isFirstFire", jobVo.getIsFirstFire());
+ jobObj.put("assignExecUser", jobVo.getAssignExecUser());
+ jobArray.add(jobObj);
+ }
+ System.out.println("autoexecJobList = " + jobArray.toJSONString());
JSONObject resultObj = new JSONObject();
- resultObj.put("autoexecJobList", autoexecJobList);
+ resultObj.put("autoexecJobList", jobArray);
return resultObj;
}
diff --git a/src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessComponent.java b/src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessComponent.java
index 87289e55..b446dac4 100644
--- a/src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessComponent.java
+++ b/src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessComponent.java
@@ -22,9 +22,12 @@ import neatlogic.framework.asynchronization.threadlocal.UserContext;
import neatlogic.framework.autoexec.constvalue.JobStatus;
import neatlogic.framework.autoexec.constvalue.ParamMappingMode;
import neatlogic.framework.autoexec.dao.mapper.AutoexecJobMapper;
+import neatlogic.framework.autoexec.dto.combop.AutoexecCombopVersionVo;
import neatlogic.framework.autoexec.dto.combop.ParamMappingVo;
import neatlogic.framework.autoexec.dto.job.AutoexecJobEnvVo;
import neatlogic.framework.autoexec.dto.job.AutoexecJobVo;
+import neatlogic.framework.autoexec.exception.AutoexecCombopActiveVersionNotFoundException;
+import neatlogic.framework.autoexec.exception.AutoexecCombopVersionNotFoundException;
import neatlogic.framework.crossover.CrossoverServiceFactory;
import neatlogic.framework.dao.mapper.runner.RunnerMapper;
import neatlogic.framework.dto.runner.RunnerGroupVo;
@@ -42,13 +45,14 @@ import neatlogic.framework.process.stephandler.core.IProcessStepHandler;
import neatlogic.framework.process.stephandler.core.ProcessStepHandlerBase;
import neatlogic.framework.process.stephandler.core.ProcessStepThread;
import neatlogic.module.autoexec.constvalue.FailPolicy;
-import neatlogic.module.autoexec.dao.mapper.AutoexecScenarioMapper;
+import neatlogic.module.autoexec.dao.mapper.AutoexecCombopVersionMapper;
import neatlogic.module.autoexec.process.constvalue.CreateJobProcessStepHandlerType;
import neatlogic.module.autoexec.process.dto.CreateJobConfigConfigVo;
import neatlogic.module.autoexec.process.dto.CreateJobConfigMappingGroupVo;
import neatlogic.module.autoexec.process.dto.CreateJobConfigMappingVo;
import neatlogic.module.autoexec.process.dto.CreateJobConfigVo;
import neatlogic.module.autoexec.process.util.ParseCreateJobConfigUtil;
+import neatlogic.module.autoexec.service.AutoexecCombopService;
import neatlogic.module.autoexec.service.AutoexecJobActionService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
@@ -69,8 +73,6 @@ import java.util.stream.Collectors;
public class CreateJobProcessComponent extends ProcessStepHandlerBase {
private final static Logger logger = LoggerFactory.getLogger(CreateJobProcessComponent.class);
-
- private final String FORM_EXTEND_ATTRIBUTE_TAG = "common";
@Resource
private AutoexecJobMapper autoexecJobMapper;
@@ -78,10 +80,12 @@ public class CreateJobProcessComponent extends ProcessStepHandlerBase {
private AutoexecJobActionService autoexecJobActionService;
@Resource
- private AutoexecScenarioMapper autoexecScenarioMapper;
+ private RunnerMapper runnerMapper;
@Resource
- private RunnerMapper runnerMapper;
+ private AutoexecCombopVersionMapper autoexecCombopVersionMapper;
+ @Resource
+ private AutoexecCombopService autoexecCombopService;
@Override
@@ -177,8 +181,16 @@ public class CreateJobProcessComponent extends ProcessStepHandlerBase {
if (createJobConfigConfigVo == null) {
continue;
}
+ Long activeVersionId = autoexecCombopVersionMapper.getAutoexecCombopActiveVersionIdByCombopId(createJobConfigConfigVo.getCombopId());
+ if (activeVersionId == null) {
+ throw new AutoexecCombopActiveVersionNotFoundException(createJobConfigConfigVo.getCombopId());
+ }
+ AutoexecCombopVersionVo autoexecCombopVersionVo = autoexecCombopService.getAutoexecCombopVersionById(activeVersionId);
+ if (autoexecCombopVersionVo == null) {
+ throw new AutoexecCombopVersionNotFoundException(activeVersionId);
+ }
// 根据配置信息创建AutoexecJobVo对象
- List list = ParseCreateJobConfigUtil.createAutoexecJobList(currentProcessTaskStepVo, createJobConfigConfigVo);
+ List list = ParseCreateJobConfigUtil.createAutoexecJobList(currentProcessTaskStepVo, createJobConfigConfigVo, autoexecCombopVersionVo);
jobList.addAll(list);
}
diff --git a/src/main/java/neatlogic/module/autoexec/process/util/ParseCreateJobConfigUtil.java b/src/main/java/neatlogic/module/autoexec/process/util/ParseCreateJobConfigUtil.java
index 6d1748fc..7df5104a 100644
--- a/src/main/java/neatlogic/module/autoexec/process/util/ParseCreateJobConfigUtil.java
+++ b/src/main/java/neatlogic/module/autoexec/process/util/ParseCreateJobConfigUtil.java
@@ -19,21 +19,21 @@ package neatlogic.module.autoexec.process.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
+import neatlogic.framework.autoexec.constvalue.CombopNodeSpecify;
import neatlogic.framework.autoexec.constvalue.CombopOperationType;
import neatlogic.framework.autoexec.constvalue.ParamType;
+import neatlogic.framework.autoexec.crossover.IAutoexecCombopCrossoverService;
import neatlogic.framework.autoexec.crossover.IAutoexecScenarioCrossoverMapper;
-import neatlogic.framework.autoexec.dto.combop.AutoexecCombopExecuteConfigVo;
-import neatlogic.framework.autoexec.dto.combop.AutoexecCombopExecuteNodeConfigVo;
-import neatlogic.framework.autoexec.dto.combop.ParamMappingVo;
+import neatlogic.framework.autoexec.dto.combop.*;
import neatlogic.framework.autoexec.dto.job.AutoexecJobVo;
import neatlogic.framework.autoexec.dto.node.AutoexecNodeVo;
import neatlogic.framework.autoexec.dto.scenario.AutoexecScenarioVo;
import neatlogic.framework.cmdb.crossover.IResourceAccountCrossoverMapper;
import neatlogic.framework.cmdb.dto.resourcecenter.AccountProtocolVo;
-import neatlogic.framework.cmdb.enums.FormHandler;
+import neatlogic.framework.cmdb.dto.resourcecenter.AccountVo;
import neatlogic.framework.common.constvalue.Expression;
+import neatlogic.framework.common.constvalue.GroupSearch;
import neatlogic.framework.common.constvalue.SystemUser;
import neatlogic.framework.crossover.CrossoverServiceFactory;
import neatlogic.framework.form.attribute.core.FormAttributeDataConversionHandlerFactory;
@@ -65,7 +65,7 @@ public class ParseCreateJobConfigUtil {
* @param createJobConfigConfigVo
* @return
*/
- public static List createAutoexecJobList(ProcessTaskStepVo currentProcessTaskStepVo, CreateJobConfigConfigVo createJobConfigConfigVo) {
+ public static List createAutoexecJobList(ProcessTaskStepVo currentProcessTaskStepVo, CreateJobConfigConfigVo createJobConfigConfigVo, AutoexecCombopVersionVo autoexecCombopVersionVo) {
Long processTaskId = currentProcessTaskStepVo.getProcessTaskId();
// 如果工单有表单信息,则查询出表单配置及数据
Map formAttributeDataMap = new HashMap<>();
@@ -75,12 +75,12 @@ public class ParseCreateJobConfigUtil {
if (CollectionUtils.isNotEmpty(formAttributeList)) {
List processTaskFormAttributeDataList = processTaskCrossoverService.getProcessTaskFormAttributeDataListByProcessTaskIdAndTag(processTaskId, createJobConfigConfigVo.getFormTag());
for (ProcessTaskFormAttributeDataVo attributeDataVo : processTaskFormAttributeDataList) {
- originalFormAttributeDataMap.put(attributeDataVo.getAttributeUuid(), attributeDataVo.getDataObj());
+ originalFormAttributeDataMap.put(attributeDataVo.getAttributeKey(), attributeDataVo.getDataObj());
// 放入表单普通组件数据
if (!Objects.equals(attributeDataVo.getHandler(), neatlogic.framework.form.constvalue.FormHandler.FORMTABLEINPUTER.getHandler())
&& !Objects.equals(attributeDataVo.getHandler(), neatlogic.framework.form.constvalue.FormHandler.FORMSUBASSEMBLY.getHandler())
&& !Objects.equals(attributeDataVo.getHandler(), neatlogic.framework.form.constvalue.FormHandler.FORMTABLESELECTOR.getHandler())) {
- formAttributeDataMap.put(attributeDataVo.getAttributeUuid(), attributeDataVo.getDataObj());
+ formAttributeDataMap.put(attributeDataVo.getAttributeKey(), attributeDataVo.getDataObj());
}
}
// 添加表格组件中的子组件到组件列表中
@@ -107,22 +107,57 @@ public class ParseCreateJobConfigUtil {
// 作业策略createJobPolicy为single时表示单次创建作业,createJobPolicy为batch时表示批量创建作业
String createPolicy = createJobConfigConfigVo.getCreatePolicy();
if (Objects.equals(createPolicy, "single")) {
- AutoexecJobVo jobVo = createSingleAutoexecJobVo(currentProcessTaskStepVo, createJobConfigConfigVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
-// jobVo.setRunnerGroup(getRunnerGroup(jobVo.getParam(), autoexecConfig));
+ AutoexecJobVo jobVo = createSingleAutoexecJobVo(currentProcessTaskStepVo, createJobConfigConfigVo, autoexecCombopVersionVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
List resultList = new ArrayList<>();
resultList.add(jobVo);
return resultList;
} else if (Objects.equals(createPolicy, "batch")) {
- List jobVoList = createBatchAutoexecJobVo(currentProcessTaskStepVo, createJobConfigConfigVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
-// if (CollectionUtils.isNotEmpty(jobVoList)) {
-// jobVoList.forEach(jobVo -> jobVo.setRunnerGroup(getRunnerGroup(jobVo.getParam(), autoexecConfig)));
-// }
+ List jobVoList = createBatchAutoexecJobVo(currentProcessTaskStepVo, createJobConfigConfigVo, autoexecCombopVersionVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
return jobVoList;
} else {
return null;
}
}
+ /**
+ * 批量创建作业
+ *
+ * @param currentProcessTaskStepVo
+ * @param createJobConfigConfigVo
+ * @param formAttributeList
+ * @param originalFormAttributeDataMap
+ * @param formAttributeDataMap
+ * @param processTaskParam
+ * @return
+ */
+ private static List createBatchAutoexecJobVo(
+ ProcessTaskStepVo currentProcessTaskStepVo,
+ CreateJobConfigConfigVo createJobConfigConfigVo,
+ AutoexecCombopVersionVo autoexecCombopVersionVo,
+ List formAttributeList,
+ Map originalFormAttributeDataMap,
+ Map formAttributeDataMap,
+ JSONObject processTaskParam) {
+
+ List resultList = new ArrayList<>();
+ // 批量遍历表格
+ CreateJobConfigMappingVo batchDataSourceMapping = createJobConfigConfigVo.getBatchDataSourceMapping();
+ if (batchDataSourceMapping == null) {
+ return resultList;
+ }
+ JSONArray tbodyList = parseFormTableComponentMappingMode(batchDataSourceMapping, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ if (CollectionUtils.isEmpty(tbodyList)) {
+ return resultList;
+ }
+ // 遍历表格数据,创建AutoexecJobVo对象列表
+ for (Object obj : tbodyList) {
+ formAttributeDataMap.put(batchDataSourceMapping.getValue().toString(), Collections.singletonList(obj));
+ AutoexecJobVo jobVo = createSingleAutoexecJobVo(currentProcessTaskStepVo, createJobConfigConfigVo, autoexecCombopVersionVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ resultList.add(jobVo);
+ }
+ return resultList;
+ }
+
/**
* 单次创建作业
*
@@ -137,6 +172,7 @@ public class ParseCreateJobConfigUtil {
private static AutoexecJobVo createSingleAutoexecJobVo(
ProcessTaskStepVo currentProcessTaskStepVo,
CreateJobConfigConfigVo createJobConfigConfigVo,
+ AutoexecCombopVersionVo autoexecCombopVersionVo,
List formAttributeList,
Map originalFormAttributeDataMap,
Map formAttributeDataMap,
@@ -146,49 +182,147 @@ public class ParseCreateJobConfigUtil {
Long combopId = createJobConfigConfigVo.getCombopId();
// 作业名称
String jobName = createJobConfigConfigVo.getJobName();
+ AutoexecCombopVersionConfigVo versionConfig = autoexecCombopVersionVo.getConfig();
// 场景
- List scenarioParamMappingList = createJobConfigConfigVo.getScenarioParamMappingGroupList();
- if (CollectionUtils.isNotEmpty(scenarioParamMappingList)) {
- Long scenarioId = getScenarioId(scenarioParamMappingList.get(0), formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
- jobVo.setScenarioId(scenarioId);
+ if (CollectionUtils.isNotEmpty(versionConfig.getScenarioList())) {
+ List scenarioParamMappingGroupList = createJobConfigConfigVo.getScenarioParamMappingGroupList();
+ if (CollectionUtils.isNotEmpty(scenarioParamMappingGroupList)) {
+ JSONArray jsonArray = parseCreateJobConfigMappingGroup(scenarioParamMappingGroupList.get(0), formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ Long scenarioId = getScenarioId(jsonArray);
+ jobVo.setScenarioId(scenarioId);
+ }
}
- // 作业参数赋值列表
- List runtimeParamMappingGroupList = createJobConfigConfigVo.getJopParamMappingGroupList();
- if (CollectionUtils.isNotEmpty(runtimeParamMappingGroupList)) {
- JSONObject param = new JSONObject();
- for(CreateJobConfigMappingGroupVo mappingGroupVo : runtimeParamMappingGroupList) {
- Object value = parseRuntimeParamMapping(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
- param.put(mappingGroupVo.getKey(), value);
+ if (CollectionUtils.isNotEmpty(versionConfig.getRuntimeParamList())) {
+ // 作业参数赋值列表
+ List runtimeParamMappingGroupList = createJobConfigConfigVo.getJopParamMappingGroupList();
+ if (CollectionUtils.isNotEmpty(runtimeParamMappingGroupList)) {
+ JSONObject param = new JSONObject();
+ for (CreateJobConfigMappingGroupVo mappingGroupVo : runtimeParamMappingGroupList) {
+ JSONArray jsonArray = parseCreateJobConfigMappingGroup(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ if (CollectionUtils.isEmpty(jsonArray)) {
+ continue;
+ }
+ Object value = convertDateType(mappingGroupVo.getType(), jsonArray);
+ param.put(mappingGroupVo.getKey(), value);
+ }
+ jobVo.setParam(param);
}
- jobVo.setParam(param);
}
+
// 目标参数赋值列表
-// JSONArray executeParamList = autoexecConfig.getJSONArray("executeParamList");
+ Map executeParamMappingGroupMap = new HashMap<>();
List executeParamMappingGroupList = createJobConfigConfigVo.getExecuteParamMappingGroupList();
if (CollectionUtils.isNotEmpty(executeParamMappingGroupList)) {
- AutoexecCombopExecuteConfigVo executeConfig = new AutoexecCombopExecuteConfigVo();
-// AutoexecCombopExecuteConfigVo executeConfig = getAutoexecCombopExecuteConfig(executeParamList, formAttributeMap, processTaskFormAttributeDataMap);
- for (CreateJobConfigMappingGroupVo mappingGroupVo : executeParamMappingGroupList) {
- String key = mappingGroupVo.getKey();
- if (Objects.equals(key, "executeNodeConfig")) {
- Object value = parseExecuteNodeConfigMapping(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
- } else if (Objects.equals(key, "protocolId")) {
- Object value = parseProtocolIdMapping(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
- } else if (Objects.equals(key, "executeUser")) {
- Object value = parseExecuteUserParamMapping(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
- } else if (Objects.equals(key, "roundCount")) {
- Object value = parseRoundCountMapping(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ executeParamMappingGroupMap = executeParamMappingGroupList.stream().collect(Collectors.toMap(CreateJobConfigMappingGroupVo::getKey, e -> e));
+ }
+ IAutoexecCombopCrossoverService autoexecCombopCrossoverService = CrossoverServiceFactory.getApi(IAutoexecCombopCrossoverService.class);
+ autoexecCombopCrossoverService.needExecuteConfig(autoexecCombopVersionVo);
+ // 流程图自动化节点是否需要设置执行用户,只有当有某个非runner类型的阶段,没有设置执行用户时,needExecuteUser=true
+ boolean needExecuteUser = autoexecCombopVersionVo.getNeedExecuteUser();
+ // 流程图自动化节点是否需要设置连接协议,只有当有某个非runner类型的阶段,没有设置连接协议时,needProtocol=true
+ boolean needProtocol = autoexecCombopVersionVo.getNeedProtocol();
+ // 流程图自动化节点是否需要设置执行目标,只有当有某个非runner类型的阶段,没有设置执行目标时,needExecuteNode=true
+ boolean needExecuteNode = autoexecCombopVersionVo.getNeedExecuteNode();
+ // 流程图自动化节点是否需要设置分批数量,只有当有某个非runner类型的阶段,没有设置分批数量时,needRoundCount=true
+ boolean needRoundCount = autoexecCombopVersionVo.getNeedRoundCount();
+ AutoexecCombopExecuteConfigVo combopExecuteConfig = versionConfig.getExecuteConfig();
+ AutoexecCombopExecuteConfigVo executeConfig = new AutoexecCombopExecuteConfigVo();
+ if (needExecuteNode) {
+ String whenToSpecify = combopExecuteConfig.getWhenToSpecify();
+ if (Objects.equals(CombopNodeSpecify.NOW.getValue(), whenToSpecify)) {
+ AutoexecCombopExecuteNodeConfigVo executeNodeConfig = combopExecuteConfig.getExecuteNodeConfig();
+ if (executeNodeConfig != null) {
+ executeConfig.setExecuteNodeConfig(executeNodeConfig);
+ }
+ } else if (Objects.equals(CombopNodeSpecify.RUNTIMEPARAM.getValue(), whenToSpecify)) {
+ AutoexecCombopExecuteNodeConfigVo executeNodeConfig = combopExecuteConfig.getExecuteNodeConfig();
+ if (executeNodeConfig != null) {
+ List paramList = executeNodeConfig.getParamList();
+ if (CollectionUtils.isNotEmpty(paramList)) {
+ List inputNodeList = new ArrayList<>();
+ JSONObject paramObj = jobVo.getParam();
+ for (String paramKey : paramList) {
+ JSONArray jsonArray = paramObj.getJSONArray(paramKey);
+ if (CollectionUtils.isNotEmpty(jsonArray)) {
+ List list = jsonArray.toJavaList(AutoexecNodeVo.class);
+ inputNodeList.addAll(list);
+ }
+ }
+ if (CollectionUtils.isNotEmpty(inputNodeList)) {
+ AutoexecCombopExecuteNodeConfigVo executeNodeConfigVo = new AutoexecCombopExecuteNodeConfigVo();
+ executeNodeConfigVo.setInputNodeList(inputNodeList);
+ executeConfig.setExecuteNodeConfig(executeNodeConfigVo);
+ }
+ }
+ }
+ } else if (Objects.equals(CombopNodeSpecify.RUNTIME.getValue(), whenToSpecify)) {
+ CreateJobConfigMappingGroupVo mappingGroupVo = executeParamMappingGroupMap.get("executeNodeConfig");
+ if (mappingGroupVo != null) {
+ JSONArray jsonArray = parseCreateJobConfigMappingGroup(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ List inputNodeList = getInputNodeList(jsonArray);
+ if (CollectionUtils.isNotEmpty(inputNodeList)) {
+ AutoexecCombopExecuteNodeConfigVo executeNodeConfigVo = new AutoexecCombopExecuteNodeConfigVo();
+ executeNodeConfigVo.setInputNodeList(inputNodeList);
+ executeConfig.setExecuteNodeConfig(executeNodeConfigVo);
+ }
+ }
+ }
+ }
+ if (needProtocol) {
+ if (combopExecuteConfig.getProtocolId() != null) {
+ executeConfig.setProtocolId(combopExecuteConfig.getProtocolId());
+ } else {
+ CreateJobConfigMappingGroupVo mappingGroupVo = executeParamMappingGroupMap.get("protocolId");
+ if (mappingGroupVo != null) {
+ JSONArray jsonArray = parseCreateJobConfigMappingGroup(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ Long protocolId = getProtocolId(jsonArray);
+ executeConfig.setProtocolId(protocolId);
}
}
- jobVo.setExecuteConfig(executeConfig);
}
-// String jobNamePrefixKey = autoexecConfig.getString("jobNamePrefix");
+ if (needExecuteUser) {
+ ParamMappingVo executeUserMappingVo = combopExecuteConfig.getExecuteUser();
+ if (executeUserMappingVo != null && StringUtils.isNotBlank((String) executeUserMappingVo.getValue())) {
+ executeConfig.setExecuteUser(executeUserMappingVo);
+ } else {
+ CreateJobConfigMappingGroupVo mappingGroupVo = executeParamMappingGroupMap.get("executeUser");
+ if (mappingGroupVo != null) {
+ JSONArray jsonArray = parseCreateJobConfigMappingGroup(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ String executeUser = getFirstNotBlankString(jsonArray);
+ if (StringUtils.isNotBlank(executeUser)) {
+ ParamMappingVo paramMappingVo = new ParamMappingVo();
+ paramMappingVo.setMappingMode("constant");
+ paramMappingVo.setValue(executeUser);
+ executeConfig.setExecuteUser(paramMappingVo);
+ }
+ }
+ }
+ }
+ if (needRoundCount) {
+ if (combopExecuteConfig.getRoundCount() != null) {
+ executeConfig.setRoundCount(combopExecuteConfig.getRoundCount());
+ } else {
+ CreateJobConfigMappingGroupVo mappingGroupVo = executeParamMappingGroupMap.get("roundCount");
+ if (mappingGroupVo != null) {
+ JSONArray jsonArray = parseCreateJobConfigMappingGroup(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
+ Integer roundCount = getFirstNotBlankInteger(jsonArray);
+ if (roundCount != null) {
+ executeConfig.setRoundCount(roundCount);
+ }
+ }
+ }
+ }
+ jobVo.setExecuteConfig(executeConfig);
+
+ // 执行器组
+ ParamMappingVo runnerGroup = combopExecuteConfig.getRunnerGroup();
+ if (runnerGroup != null) {
+ jobVo.setRunnerGroup(runnerGroup);
+ }
- String jobNamePrefixMappingKey = createJobConfigConfigVo.getJobNamePrefixMappingValue();
- String jobNamePrefixValue = getJobNamePrefixValue(jobNamePrefixMappingKey, jobVo.getExecuteConfig(), jobVo.getParam());
+ String jobNamePrefixMappingValue = createJobConfigConfigVo.getJobNamePrefixMappingValue();
+ String jobNamePrefixValue = getJobNamePrefix(jobNamePrefixMappingValue, jobVo.getExecuteConfig(), jobVo.getParam());
-// CreateJobConfigMappingGroupVo runnerGroupMapping = createJobConfigConfigVo.getRunnerGroupMappingGroup();
-// ParamMappingVo runnerGroupMappingVo = parseRunnerGroupMapping(runnerGroupMapping, jobVo.getParam());
jobVo.setSource(AutoExecJobProcessSource.ITSM.getValue());
jobVo.setRoundCount(32);
jobVo.setOperationId(combopId);
@@ -198,425 +332,201 @@ public class ParseCreateJobConfigUtil {
jobVo.setRouteId(currentProcessTaskStepVo.getId().toString());
jobVo.setIsFirstFire(1);
jobVo.setAssignExecUser(SystemUser.SYSTEM.getUserUuid());
-// jobVo.setRunnerGroup(runnerGroupMappingVo);
- return jobVo;
- }
-
-
- private static Integer parseRoundCountMapping(
- CreateJobConfigMappingGroupVo mappingGroupVo,
- List formAttributeList,
- Map originalFormAttributeDataMap,
- Map formAttributeDataMap,
- JSONObject processTaskParam
- ) {
- Integer roundCount = null;
- List mappingList = mappingGroupVo.getMappingList();
- if (CollectionUtils.isEmpty(mappingList)) {
- return null;
- }
- for (CreateJobConfigMappingVo mappingVo : mappingList) {
- String mappingMode = mappingVo.getMappingMode();
- Object value = mappingVo.getValue();
- if (Objects.equals(mappingMode, "formTableComponent")) {
- // 映射模式为表单表格组件
-
- } else if (Objects.equals(mappingMode, "formCommonComponent")) {
- // 映射模式为表单普通组件
- Object obj = formAttributeDataMap.get(value);
- roundCount = Integer.getInteger(obj.toString());
- } else if (Objects.equals(mappingMode, "constant")) {
- // 映射模式为常量
- roundCount = Integer.getInteger(value.toString());
- } else if (Objects.equals(mappingMode, "runtimeparam")) {
- // 映射模式为作业参数,只读
- }
- }
- return roundCount;
+ return jobVo;
}
- private static ParamMappingVo parseExecuteUserParamMapping(
- CreateJobConfigMappingGroupVo mappingGroupVo,
- List formAttributeList,
- Map originalFormAttributeDataMap,
- Map formAttributeDataMap,
- JSONObject processTaskParam
- ) {
- List mappingList = mappingGroupVo.getMappingList();
- if (CollectionUtils.isEmpty(mappingList)) {
+ private static Long getScenarioId(JSONArray jsonArray) {
+ if (CollectionUtils.isEmpty(jsonArray)) {
return null;
}
- for (CreateJobConfigMappingVo mappingVo : mappingList) {
- String mappingMode = mappingVo.getMappingMode();
- Object value = mappingVo.getValue();
- if (Objects.equals(mappingMode, "formTableComponent")) {
- // 映射模式为表单表格组件
-
- } else if (Objects.equals(mappingMode, "formCommonComponent")) {
- // 映射模式为表单普通组件
- Object obj = formAttributeDataMap.get(value);
- if (obj != null) {
- ParamMappingVo paramMappingVo = new ParamMappingVo();
- paramMappingVo.setMappingMode("constant");
- paramMappingVo.setValue(obj);
- return paramMappingVo;
+ IAutoexecScenarioCrossoverMapper autoexecScenarioCrossoverMapper = CrossoverServiceFactory.getApi(IAutoexecScenarioCrossoverMapper.class);
+ for (Object obj : jsonArray) {
+ if (obj instanceof Long) {
+ Long scenarioId = (Long) obj;
+ if (autoexecScenarioCrossoverMapper.getScenarioById(scenarioId) != null) {
+ return scenarioId;
}
- } else if (Objects.equals(mappingMode, "constant")) {
- // 映射模式为常量
- ParamMappingVo paramMappingVo = new ParamMappingVo();
- paramMappingVo.setMappingMode("constant");
- paramMappingVo.setValue(value);
- return paramMappingVo;
- } else if (Objects.equals(mappingMode, "runtimeparam")) {
- // 映射模式为作业参数,只读
- ParamMappingVo paramMappingVo = new ParamMappingVo();
- paramMappingVo.setMappingMode("runtimeparam");
- paramMappingVo.setValue(value);
- return paramMappingVo;
- }
- }
- return null;
- }
-
- private static Long parseProtocolIdMapping(
- CreateJobConfigMappingGroupVo mappingGroupVo,
- List formAttributeList,
- Map originalFormAttributeDataMap,
- Map formAttributeDataMap,
- JSONObject processTaskParam
- ) {
- Long protocolId = null;
- List mappingList = mappingGroupVo.getMappingList();
- if (CollectionUtils.isEmpty(mappingList)) {
- return protocolId;
- }
- for (CreateJobConfigMappingVo mappingVo : mappingList) {
- String mappingMode = mappingVo.getMappingMode();
- Object value = mappingVo.getValue();
- if (Objects.equals(mappingMode, "formTableComponent")) {
- // 映射模式为表单表格组件
-
- } else if (Objects.equals(mappingMode, "formCommonComponent")) {
- // 映射模式为表单普通组件
- Object obj = formAttributeDataMap.get(value);
+ } else if (obj instanceof String) {
+ String scenario = (String) obj;
try {
- protocolId = Long.valueOf(obj.toString());
- } catch (NumberFormatException ex) {
- IResourceAccountCrossoverMapper resourceAccountCrossoverMapper = CrossoverServiceFactory.getApi(IResourceAccountCrossoverMapper.class);
- AccountProtocolVo protocolVo = resourceAccountCrossoverMapper.getAccountProtocolVoByProtocolName(obj.toString());
- if (protocolVo != null) {
- protocolId = protocolVo.getId();
+ Long scenarioId = Long.valueOf(scenario);
+ if (autoexecScenarioCrossoverMapper.getScenarioById(scenarioId) != null) {
+ return scenarioId;
+ }
+ } catch (NumberFormatException ignored) {
+ AutoexecScenarioVo scenarioVo = autoexecScenarioCrossoverMapper.getScenarioByName(scenario);
+ if (scenarioVo != null) {
+ return scenarioVo.getId();
}
}
- } else if (Objects.equals(mappingMode, "constant")) {
- // 映射模式为常量
- protocolId = Long.valueOf(value.toString());
- } else if (Objects.equals(mappingMode, "runtimeparam")) {
- // 映射模式为作业参数,只读
-
+ } else if (obj instanceof JSONArray) {
+ JSONArray array = (JSONArray) obj;
+ Long scenarioId = getScenarioId(array);
+ if (scenarioId != null) {
+ return scenarioId;
+ }
}
}
- return protocolId;
+ return null;
}
- private static AutoexecCombopExecuteNodeConfigVo parseExecuteNodeConfigMapping(
- CreateJobConfigMappingGroupVo mappingGroupVo,
- List formAttributeList,
- Map originalFormAttributeDataMap,
- Map formAttributeDataMap,
- JSONObject processTaskParam
- ) {
- List formTextAttributeList = new ArrayList<>();
- formTextAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMTEXT.getHandler());
- formTextAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMTEXTAREA.getHandler());
- List mappingList = mappingGroupVo.getMappingList();
- if (CollectionUtils.isEmpty(mappingList)) {
+ private static Long getProtocolId(JSONArray jsonArray) {
+ if (CollectionUtils.isEmpty(jsonArray)) {
return null;
}
- for (CreateJobConfigMappingVo mappingVo : mappingList) {
- String mappingMode = mappingVo.getMappingMode();
- Object value = mappingVo.getValue();
- if (Objects.equals(mappingMode, "formTableComponent")) {
- // 映射模式为表单表格组件
- JSONArray array = parseFormTableComponentMappingMode(mappingVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
- if (CollectionUtils.isNotEmpty(array)) {
- AutoexecCombopExecuteNodeConfigVo executeNodeConfigVo = new AutoexecCombopExecuteNodeConfigVo();
- List inputNodeList = new ArrayList<>();
- for (int i = 0; i < array.size(); i++) {
- String str = array.getString(i);
- inputNodeList.add(new AutoexecNodeVo(str));
- }
- executeNodeConfigVo.setInputNodeList(inputNodeList);
- return executeNodeConfigVo;
+ IResourceAccountCrossoverMapper resourceAccountCrossoverMapper = CrossoverServiceFactory.getApi(IResourceAccountCrossoverMapper.class);
+ for (Object obj : jsonArray) {
+ if (obj instanceof Long) {
+ Long protocolId = (Long) obj;
+ AccountProtocolVo accountProtocolVo = resourceAccountCrossoverMapper.getAccountProtocolVoByProtocolId(protocolId);
+ if (accountProtocolVo != null) {
+ return protocolId;
}
- } else if (Objects.equals(mappingMode, "formCommonComponent")) {
- // 映射模式为表单普通组件
- Object dataObj = formAttributeDataMap.get(value);
- if (dataObj != null) {
- AutoexecCombopExecuteNodeConfigVo executeNodeConfigVo = new AutoexecCombopExecuteNodeConfigVo();
- String handler = null;
- Optional first = formAttributeList.stream().filter(e -> Objects.equals(e.getUuid(), value)).findFirst();
- if (first.isPresent()) {
- FormAttributeVo formAttributeVo = first.get();
- handler = formAttributeVo.getHandler();
+ } else if (obj instanceof String) {
+ String protocol = (String) obj;
+ try {
+ Long protocolId = Long.valueOf(protocol);
+ AccountProtocolVo accountProtocolVo = resourceAccountCrossoverMapper.getAccountProtocolVoByProtocolId(protocolId);
+ if (accountProtocolVo != null) {
+ return protocolId;
}
- if (Objects.equals(handler, FormHandler.FORMRESOURECES.getHandler())) {
- // 映射的表单组件是执行目标
- executeNodeConfigVo = ((JSONObject) dataObj).toJavaObject(AutoexecCombopExecuteNodeConfigVo.class);
- } else if (formTextAttributeList.contains(handler)) {
- // 映射的表单组件是文本框
- String dataStr = dataObj.toString();
- try {
- List inputNodeList = new ArrayList<>();
- JSONArray array = JSONArray.parseArray(dataStr);
- for (int j = 0; j < array.size(); j++) {
- String str = array.getString(j);
- inputNodeList.add(new AutoexecNodeVo(str));
- }
- executeNodeConfigVo.setInputNodeList(inputNodeList);
- } catch (JSONException e) {
- List inputNodeList = new ArrayList<>();
- inputNodeList.add(new AutoexecNodeVo(dataObj.toString()));
- executeNodeConfigVo.setInputNodeList(inputNodeList);
- }
- } else {
- // 映射的表单组件不是执行目标
- List inputNodeList = new ArrayList<>();
- inputNodeList.add(new AutoexecNodeVo(dataObj.toString()));
- executeNodeConfigVo.setInputNodeList(inputNodeList);
+ } catch (NumberFormatException ex) {
+ AccountProtocolVo accountProtocolVo = resourceAccountCrossoverMapper.getAccountProtocolVoByProtocolName(protocol);
+ if (accountProtocolVo != null) {
+ return accountProtocolVo.getId();
}
- return executeNodeConfigVo;
}
- } else if (Objects.equals(mappingMode, "constant")) {
- // 映射模式为常量
-// value;
- } else if (Objects.equals(mappingMode, "runtimeparam")) {
- // 映射模式为作业参数,只读
-// if (Objects.equals(key, "executeUser")) {
-// ParamMappingVo paramMappingVo = new ParamMappingVo();
-// paramMappingVo.setMappingMode("runtimeparam");
-// paramMappingVo.setValue(value);
-// executeConfig.put(key, paramMappingVo);
-// }
+ } else if (obj instanceof JSONArray) {
+ JSONArray array = (JSONArray) obj;
+ Long protocolId = getProtocolId(array);
+ if (protocolId != null) {
+ return protocolId;
+ }
}
}
-
return null;
}
- /**
- * 批量创建作业
- *
- * @param currentProcessTaskStepVo
- * @param createJobConfigConfigVo
- * @param formAttributeList
- * @param originalFormAttributeDataMap
- * @param formAttributeDataMap
- * @param processTaskParam
- * @return
- */
- private static List createBatchAutoexecJobVo(
- ProcessTaskStepVo currentProcessTaskStepVo,
- CreateJobConfigConfigVo createJobConfigConfigVo,
- List formAttributeList,
- Map originalFormAttributeDataMap,
- Map formAttributeDataMap,
- JSONObject processTaskParam) {
-
- List resultList = new ArrayList<>();
- // 批量遍历表格
- CreateJobConfigMappingVo batchDataSourceMapping = createJobConfigConfigVo.getBatchDataSourceMapping();
- if (batchDataSourceMapping == null) {
- return resultList;
- }
- JSONArray tbodyList = parseFormTableComponentMappingMode(batchDataSourceMapping, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
- if (CollectionUtils.isEmpty(tbodyList)) {
- return resultList;
- }
- // 遍历表格数据,创建AutoexecJobVo对象列表
- for (Object obj : tbodyList) {
- formAttributeDataMap.put(batchDataSourceMapping.getValue().toString(), Collections.singletonList(obj));
- AutoexecJobVo jobVo = createSingleAutoexecJobVo(currentProcessTaskStepVo, createJobConfigConfigVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
- resultList.add(jobVo);
- }
- return resultList;
- }
-
- /**
- * 获取场景ID
- *
- * @param mappingGroupVo
- * @param formAttributeList
- * @param originalFormAttributeDataMap
- * @param formAttributeDataMap
- * @param processTaskParam
- * @return
- */
- private static Long getScenarioId(CreateJobConfigMappingGroupVo mappingGroupVo,
- List formAttributeList,
- Map originalFormAttributeDataMap,
- Map formAttributeDataMap,
- JSONObject processTaskParam) {
-
- String key = mappingGroupVo.getKey();
- if (StringUtils.isBlank(key)) {
+ private static Long getAccountId(JSONArray jsonArray) {
+ if (CollectionUtils.isEmpty(jsonArray)) {
return null;
}
- String type = mappingGroupVo.getType();
- List mappingList = mappingGroupVo.getMappingList();
- if (CollectionUtils.isEmpty(mappingList)) {
- return null;
- }
- for (CreateJobConfigMappingVo mappingVo : mappingList) {
- Object value = mappingVo.getValue();
- if (value == null) {
- return null;
- }
- Object scenario = null;
- String mappingMode = mappingVo.getMappingMode();
- if (Objects.equals(mappingMode, "formTableComponent")) {
- scenario = parseFormTableComponentMappingMode(mappingVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam);
- } else if (Objects.equals(mappingMode, "formCommonComponent")) {
- scenario = formAttributeDataMap.get(value);
- } else if (Objects.equals(mappingMode, "constant")) {
- scenario = value;
- }
- if (scenario != null) {
- if (scenario instanceof List) {
- List scenarioList = (List) scenario;
- if (CollectionUtils.isNotEmpty(scenarioList)) {
- scenario = scenarioList.get(0);
- }
+ IResourceAccountCrossoverMapper resourceAccountCrossoverMapper = CrossoverServiceFactory.getApi(IResourceAccountCrossoverMapper.class);
+ for (Object obj : jsonArray) {
+ if (obj instanceof Long) {
+ Long accountId = (Long) obj;
+ AccountVo accountVo = resourceAccountCrossoverMapper.getAccountById(accountId);
+ if (accountVo != null) {
+ return accountId;
}
- IAutoexecScenarioCrossoverMapper autoexecScenarioCrossoverMapper = CrossoverServiceFactory.getApi(IAutoexecScenarioCrossoverMapper.class);
- if (scenario instanceof String) {
- String scenarioName = (String) scenario;
- AutoexecScenarioVo scenarioVo = autoexecScenarioCrossoverMapper.getScenarioByName(scenarioName);
- if (scenarioVo != null) {
- return scenarioVo.getId();
- } else {
- try {
- Long scenarioId = Long.valueOf(scenarioName);
- if (autoexecScenarioCrossoverMapper.getScenarioById(scenarioId) != null) {
- return scenarioId;
- }
- } catch (NumberFormatException ignored) {
-
- }
+ } else if (obj instanceof String) {
+ String account = (String) obj;
+ try {
+ Long accountId = Long.valueOf(account);
+ AccountVo accountVo = resourceAccountCrossoverMapper.getAccountById(accountId);
+ if (accountVo != null) {
+ return accountId;
}
- } else if (scenario instanceof Long) {
- Long scenarioId = (Long) scenario;
- if (autoexecScenarioCrossoverMapper.getScenarioById(scenarioId) != null) {
- return scenarioId;
+ } catch (NumberFormatException ex) {
+ AccountVo accountVo = resourceAccountCrossoverMapper.getPublicAccountByName(account);
+ if (accountVo != null) {
+ return accountVo.getId();
}
}
+ } else if (obj instanceof JSONArray) {
+ JSONArray array = (JSONArray) obj;
+ Long accountId = getAccountId(array);
+ if (accountId != null) {
+ return accountId;
+ }
}
}
return null;
}
- /**
- * 根据设置找到作业名称前缀值
- *
- * @param jobNamePrefixKey 作业名称前缀key
- * @param executeConfig 目标参数
- * @param param 作业参数
- * @return 返回作业名称前缀值
- */
- private static String getJobNamePrefixValue2(String jobNamePrefixKey, AutoexecCombopExecuteConfigVo executeConfig, JSONObject param) {
- String jobNamePrefixValue = StringUtils.EMPTY;
- if (StringUtils.isBlank(jobNamePrefixKey)) {
- return jobNamePrefixValue;
+ private static List getInputNodeList(JSONArray jsonArray) {
+ List resultList = new ArrayList<>();
+ if (CollectionUtils.isEmpty(jsonArray)) {
+ return resultList;
}
- if (Objects.equals(jobNamePrefixKey, "executeNodeConfig")) {
- AutoexecCombopExecuteNodeConfigVo executeNodeConfig = executeConfig.getExecuteNodeConfig();
- List inputNodeList = executeNodeConfig.getInputNodeList();
- List selectNodeList = executeNodeConfig.getSelectNodeList();
- List paramList = executeNodeConfig.getParamList();
- if (CollectionUtils.isNotEmpty(inputNodeList)) {
- List list = new ArrayList<>();
- for (AutoexecNodeVo node : inputNodeList) {
- list.add(node.toString());
- }
- jobNamePrefixValue = String.join("", list);
- } else if (CollectionUtils.isNotEmpty(selectNodeList)) {
- List list = new ArrayList<>();
- for (AutoexecNodeVo node : selectNodeList) {
- list.add(node.toString());
- }
- jobNamePrefixValue = String.join("", list);
- } else if (CollectionUtils.isNotEmpty(paramList)) {
- List list = new ArrayList<>();
- for (String paramKey : paramList) {
- Object value = param.get(paramKey);
- if (value != null) {
- if (value instanceof String) {
- list.add((String) value);
- } else {
- list.add(JSONObject.toJSONString(value));
+ for (Object obj : jsonArray) {
+ if (obj instanceof String) {
+ String str = (String) obj;
+ if (str.startsWith("{") && str.endsWith("}")) {
+ JSONObject jsonObj = JSON.parseObject(str);
+ String ip = jsonObj.getString("ip");
+ if (StringUtils.isNotBlank(ip)) {
+ Long id = jsonObj.getLong("id");
+ Integer port = jsonObj.getInteger("port");
+ String name = jsonObj.getString("name");
+ AutoexecNodeVo autoexecNodeVo = new AutoexecNodeVo();
+ autoexecNodeVo.setIp(ip);
+ if (id != null) {
+ autoexecNodeVo.setId(id);
+ }
+ if (port != null) {
+ autoexecNodeVo.setPort(port);
+ }
+ if (StringUtils.isNotBlank(name)) {
+ autoexecNodeVo.setName(name);
}
+ resultList.add(autoexecNodeVo);
}
+ } else if (str.startsWith("[") && str.endsWith("]")) {
+ JSONArray array = JSON.parseArray(str);
+ List list = getInputNodeList(array);
+ if (CollectionUtils.isNotEmpty(list)) {
+ resultList.addAll(list);
+ }
+ } else if (str.contains("\n")) {
+ String[] split = str.split("\n");
+ for (String e : split) {
+ resultList.add(new AutoexecNodeVo(e));
+ }
+ } else {
+ resultList.add(new AutoexecNodeVo(str));
}
- jobNamePrefixValue = String.join("", list);
- }
- } else if (Objects.equals(jobNamePrefixKey, "executeUser")) {
- ParamMappingVo executeUser = executeConfig.getExecuteUser();
- if (executeUser != null) {
- Object value = executeUser.getValue();
- if (value != null) {
- if (Objects.equals(executeUser.getMappingMode(), "runtimeparam")) {
- value = param.get(value);
+ } else if (obj instanceof JSONObject) {
+ JSONObject jsonObj = (JSONObject) obj;
+ String ip = jsonObj.getString("ip");
+ if (StringUtils.isNotBlank(ip)) {
+ Integer port = jsonObj.getInteger("port");
+ String name = jsonObj.getString("name");
+ AutoexecNodeVo autoexecNodeVo = new AutoexecNodeVo();
+ autoexecNodeVo.setIp(ip);
+ if (port != null) {
+ autoexecNodeVo.setPort(port);
}
- if (value != null) {
- if (value instanceof String) {
- jobNamePrefixValue = (String) value;
- } else {
- jobNamePrefixValue = JSONObject.toJSONString(value);
- }
+ if (StringUtils.isNotBlank(name)) {
+ autoexecNodeVo.setName(name);
}
}
- }
- } else if (Objects.equals(jobNamePrefixKey, "protocolId")) {
- Long protocolId = executeConfig.getProtocolId();
- if (protocolId != null) {
- jobNamePrefixValue = protocolId.toString();
- }
- } else if (Objects.equals(jobNamePrefixKey, "roundCount")) {
- Integer roundCount = executeConfig.getRoundCount();
- if (roundCount != null) {
- jobNamePrefixValue = roundCount.toString();
- }
- } else {
- Object jobNamePrefixObj = param.get(jobNamePrefixKey);
- if (jobNamePrefixObj instanceof String) {
- jobNamePrefixValue = (String) jobNamePrefixObj;
- } else {
- jobNamePrefixValue = JSONObject.toJSONString(jobNamePrefixObj);
+ } else if (obj instanceof JSONArray) {
+ JSONArray array = (JSONArray) obj;
+ List list = getInputNodeList(array);
+ if (CollectionUtils.isNotEmpty(list)) {
+ resultList.addAll(list);
+ }
}
}
- if (StringUtils.isBlank(jobNamePrefixValue)) {
- return StringUtils.EMPTY;
- } else if (jobNamePrefixValue.length() > 32) {
- return jobNamePrefixValue.substring(0, 32);
- }
- return jobNamePrefixValue;
+ return resultList;
}
/**
* 根据设置找到作业名称前缀值
*
- * @param jobNamePrefixKey 作业名称前缀key
+ * @param jobNamePrefixMappingValue 作业名称前缀映射值
* @param executeConfig 目标参数
* @param param 作业参数
* @return 返回作业名称前缀值
*/
- private static String getJobNamePrefixValue(String jobNamePrefixKey, AutoexecCombopExecuteConfigVo executeConfig, JSONObject param) {
+ private static String getJobNamePrefix(String jobNamePrefixMappingValue, AutoexecCombopExecuteConfigVo executeConfig, JSONObject param) {
String jobNamePrefixValue = StringUtils.EMPTY;
- if (StringUtils.isBlank(jobNamePrefixKey)) {
+ if (StringUtils.isBlank(jobNamePrefixMappingValue)) {
return jobNamePrefixValue;
}
- if (Objects.equals(jobNamePrefixKey, "executeNodeConfig")) {
+ if (Objects.equals(jobNamePrefixMappingValue, "executeNodeConfig")) {
AutoexecCombopExecuteNodeConfigVo executeNodeConfig = executeConfig.getExecuteNodeConfig();
List inputNodeList = executeNodeConfig.getInputNodeList();
List selectNodeList = executeNodeConfig.getSelectNodeList();
@@ -647,7 +557,7 @@ public class ParseCreateJobConfigUtil {
}
jobNamePrefixValue = String.join("", list);
}
- } else if (Objects.equals(jobNamePrefixKey, "executeUser")) {
+ } else if (Objects.equals(jobNamePrefixMappingValue, "executeUser")) {
ParamMappingVo executeUser = executeConfig.getExecuteUser();
if (executeUser != null) {
Object value = executeUser.getValue();
@@ -664,18 +574,18 @@ public class ParseCreateJobConfigUtil {
}
}
}
- } else if (Objects.equals(jobNamePrefixKey, "protocolId")) {
+ } else if (Objects.equals(jobNamePrefixMappingValue, "protocolId")) {
Long protocolId = executeConfig.getProtocolId();
if (protocolId != null) {
jobNamePrefixValue = protocolId.toString();
}
- } else if (Objects.equals(jobNamePrefixKey, "roundCount")) {
+ } else if (Objects.equals(jobNamePrefixMappingValue, "roundCount")) {
Integer roundCount = executeConfig.getRoundCount();
if (roundCount != null) {
jobNamePrefixValue = roundCount.toString();
}
} else {
- Object jobNamePrefixObj = param.get(jobNamePrefixKey);
+ Object jobNamePrefixObj = param.get(jobNamePrefixMappingValue);
if (jobNamePrefixObj instanceof String) {
jobNamePrefixValue = (String) jobNamePrefixObj;
} else {
@@ -690,28 +600,16 @@ public class ParseCreateJobConfigUtil {
return jobNamePrefixValue;
}
- private static Object parseRuntimeParamMapping(CreateJobConfigMappingGroupVo mappingGroupVo,
- List formAttributeList,
- Map originalFormAttributeDataMap,
- Map formAttributeDataMap,
- JSONObject processTaskParam) {
- List formSelectAttributeList = new ArrayList<>();
- formSelectAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMSELECT.getHandler());
- formSelectAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMCHECKBOX.getHandler());
- formSelectAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMRADIO.getHandler());
- List formTextAttributeList = new ArrayList<>();
- formTextAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMTEXT.getHandler());
- formTextAttributeList.add(neatlogic.framework.form.constvalue.FormHandler.FORMTEXTAREA.getHandler());
- String key = mappingGroupVo.getKey();
- if (StringUtils.isBlank(key)) {
- return null;
- }
- String type = mappingGroupVo.getType();
+ private static JSONArray parseCreateJobConfigMappingGroup(CreateJobConfigMappingGroupVo mappingGroupVo,
+ List formAttributeList,
+ Map originalFormAttributeDataMap,
+ Map formAttributeDataMap,
+ JSONObject processTaskParam) {
+ JSONArray resultList = new JSONArray();
List mappingList = mappingGroupVo.getMappingList();
if (CollectionUtils.isEmpty(mappingList)) {
- return null;
+ return resultList;
}
- JSONArray resultList = new JSONArray();
for (CreateJobConfigMappingVo mappingVo : mappingList) {
Object value = mappingVo.getValue();
if (value == null) {
@@ -721,23 +619,7 @@ public class ParseCreateJobConfigUtil {
if (Objects.equals(mappingMode, "formTableComponent")) {
resultList.add(parseFormTableComponentMappingMode(mappingVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam));
} else if (Objects.equals(mappingMode, "formCommonComponent")) {
- Object obj = formAttributeDataMap.get(value);
- if (obj != null) {
- String handler = null;
- FormAttributeVo formAttributeVo = getFormAttributeVo(formAttributeList, value.toString());
- if (formAttributeVo != null) {
- handler = formAttributeVo.getHandler();
- }
- if (formTextAttributeList.contains(handler)) {
- resultList.add(convertDateType(type, (String) obj));
- } else if (formSelectAttributeList.contains(handler)) {
- if (obj instanceof String) {
- resultList.add(convertDateType(type, (String) obj));
- } else if (obj instanceof JSONArray) {
- resultList.add(convertDateType(type, JSONObject.toJSONString(obj)));
- }
- }
- }
+ resultList.add(formAttributeDataMap.get(value));
} else if (Objects.equals(mappingMode, "constant")) {
resultList.add(value);
} else if (Objects.equals(mappingMode, "processTaskParam")) {
@@ -748,9 +630,6 @@ public class ParseCreateJobConfigUtil {
}
}
}
- if (mappingList.size() == 1) {
- return resultList.get(0);
- }
return resultList;
}
@@ -874,7 +753,7 @@ public class ParseCreateJobConfigUtil {
newRowData.put(key, entry.getValue());
}
}
- if (!derivedTableDataList.contains(newRowData)) {// TODO 这里需要验证HashMap的equals方法
+ if (!derivedTableDataList.contains(newRowData)) {
derivedTableDataList.add(newRowData);
}
}
@@ -956,7 +835,7 @@ public class ParseCreateJobConfigUtil {
* 获取表单表格组件的数据
* @param formAttributeList
* @param originalFormAttributeDataMap
- * @param attributeUuid
+ * @param attributeKey
* @return
*/
@SuppressWarnings("unchecked")
@@ -964,13 +843,13 @@ public class ParseCreateJobConfigUtil {
List formAttributeList,
Map originalFormAttributeDataMap,
Map formAttributeDataMap,
- String attributeUuid) {
+ String attributeKey) {
List resultList = new ArrayList<>();
- Object object = formAttributeDataMap.get(attributeUuid);
+ Object object = formAttributeDataMap.get(attributeKey);
if (object != null) {
return (List) object;
}
- Object obj = originalFormAttributeDataMap.get(attributeUuid);
+ Object obj = originalFormAttributeDataMap.get(attributeKey);
if (obj == null) {
return resultList;
}
@@ -983,19 +862,21 @@ public class ParseCreateJobConfigUtil {
}
for (int i = 0; i < array.size(); i++) {
- JSONObject newJsonObj = array.getJSONObject(i);
+ JSONObject newJsonObj = new JSONObject();
JSONObject jsonObj = array.getJSONObject(i);
for (Map.Entry entry : jsonObj.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
- FormAttributeVo formAttributeVo = getFormAttributeVo(formAttributeList, key);
- if (formAttributeVo != null) {
- IFormAttributeDataConversionHandler handler = FormAttributeDataConversionHandlerFactory.getHandler(formAttributeVo.getHandler());
+ FormAttributeVo formAttributeVo2 = getFormAttributeVo(formAttributeList, key);
+ if (formAttributeVo2 != null) {
+ IFormAttributeDataConversionHandler handler = FormAttributeDataConversionHandlerFactory.getHandler(formAttributeVo2.getHandler());
if (handler != null) {
value = handler.getSimpleValue(value);
}
+ newJsonObj.put(formAttributeVo2.getKey(), value);
+ } else {
+ newJsonObj.put(key, value);
}
- newJsonObj.put(key, value);
}
resultList.add(newJsonObj);
}
@@ -1013,6 +894,22 @@ public class ParseCreateJobConfigUtil {
return null;
}
+ private static FormAttributeVo getFormAttributeVoByKeyAndParentUuid(List formAttributeList, String key, String parentUuid) {
+ if (CollectionUtils.isNotEmpty(formAttributeList)) {
+ for (FormAttributeVo formAttributeVo : formAttributeList) {
+ if (Objects.equals(formAttributeVo.getKey(), key)) {
+ if (parentUuid == null) {
+ return formAttributeVo;
+ }
+ if (formAttributeVo.getParent() != null && Objects.equals(formAttributeVo.getParent().getUuid(), parentUuid)) {
+ return formAttributeVo;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
/**
* 解析出表达式的值
* @param valueList
@@ -1066,53 +963,218 @@ public class ParseCreateJobConfigUtil {
* 把表单表格组件中某列数据集合转换成作业参数对应的数据
*
* @param paramType 作业参数类型
- * @param sourceList 某列数据集合
+ * @param jsonArray 某列数据集合
* @return
*/
- private static Object convertDateType(String paramType, List sourceList) {
- if (Objects.equals(paramType, ParamType.NODE.getValue())) {
- if (CollectionUtils.isNotEmpty(sourceList)) {
- JSONArray inputNodeList = new JSONArray();
- for (String str : sourceList) {
- if (StringUtils.isNotBlank(str)) {
- JSONArray inputNodeArray = (JSONArray) convertDateType(paramType, str);
- inputNodeList.addAll(inputNodeArray);
+ private static Object convertDateType(String paramType, JSONArray jsonArray) {
+ if (CollectionUtils.isEmpty(jsonArray)) {
+ return null;
+ }
+ if (Objects.equals(paramType, ParamType.TEXT.getValue())) {
+ return String.join(",", getStringList(jsonArray));
+ } else if (Objects.equals(paramType, ParamType.PASSWORD.getValue())) {
+ return String.join(",", getStringList(jsonArray));
+ } else if (Objects.equals(paramType, ParamType.FILE.getValue())) {
+ // 多选
+ return jsonArray;
+ } else if (Objects.equals(paramType, ParamType.DATE.getValue())) {
+ return getFirstNotBlankString(jsonArray);
+ } else if (Objects.equals(paramType, ParamType.DATETIME.getValue())) {
+ return getFirstNotBlankString(jsonArray);
+ } else if (Objects.equals(paramType, ParamType.TIME.getValue())) {
+ return getFirstNotBlankString(jsonArray);
+ } else if (Objects.equals(paramType, ParamType.JSON.getValue())) {
+ if (jsonArray.size() == 1) {
+ return jsonArray.get(0);
+ } else {
+ return jsonArray;
+ }
+ } else if (Objects.equals(paramType, ParamType.SELECT.getValue())) {
+ return getFirstNotNullObject(jsonArray);
+ } else if (Objects.equals(paramType, ParamType.MULTISELECT.getValue())) {
+ return getObjectList(jsonArray);
+ } else if (Objects.equals(paramType, ParamType.RADIO.getValue())) {
+ return getFirstNotNullObject(jsonArray);
+ } else if (Objects.equals(paramType, ParamType.CHECKBOX.getValue())) {
+ return getObjectList(jsonArray);
+ } else if (Objects.equals(paramType, ParamType.NODE.getValue())) {
+ return getInputNodeList(jsonArray);
+ } else if (Objects.equals(paramType, ParamType.ACCOUNT.getValue())) {
+ // 账号id,单选
+ return getAccountId(jsonArray);
+ } else if (Objects.equals(paramType, ParamType.USERSELECT.getValue())) {
+ // 单选或多选都是数组
+ List resultList = new ArrayList<>();
+ for (Object obj : jsonArray) {
+ if (obj == null) {
+ continue;
+ }
+ if (obj instanceof JSONArray) {
+ JSONArray array = (JSONArray) obj;
+ for (Object obj2 : array) {
+ String str = obj2.toString();
+ if (str.length() == 37) {
+ if (str.startsWith(GroupSearch.USER.getValuePlugin())
+ || str.startsWith(GroupSearch.TEAM.getValuePlugin())
+ || str.startsWith(GroupSearch.ROLE.getValuePlugin())) {
+ resultList.add(str);
+ }
+ }
+ }
+ } else {
+ String str = obj.toString();
+ if (str.length() == 37) {
+ if (str.startsWith(GroupSearch.USER.getValuePlugin())
+ || str.startsWith(GroupSearch.TEAM.getValuePlugin())
+ || str.startsWith(GroupSearch.ROLE.getValuePlugin())) {
+ resultList.add(str);
+ }
}
}
- return inputNodeList;
}
+ return resultList;
+ } else if (Objects.equals(paramType, ParamType.TEXTAREA.getValue())) {
+ return String.join(",", getStringList(jsonArray));
+ } else if (Objects.equals(paramType, ParamType.PHASE.getValue())) {
+ // 阶段名称,单选
+ return getFirstNotBlankString(jsonArray);
+ } else if (Objects.equals(paramType, ParamType.SWITCH.getValue())) {
+ // true或false
+ Boolean bool = getFirstNotNullBoolean(jsonArray);
+ if (Boolean.TRUE == bool) {
+ return Boolean.TRUE;
+ } else {
+ return Boolean.FALSE;
+ }
+ } else if (Objects.equals(paramType, ParamType.FILEPATH.getValue())) {
+ return getFirstNotBlankString(jsonArray);
+ } else if (Objects.equals(paramType, ParamType.RUNNERGROUP.getValue())) {
+ // 组id,单选
+ return getFirstNotNullObject(jsonArray);
}
- return sourceList;
+ return null;
}
- /**
- * 把表单文本框组件数据转换成作业参数对应的数据
- *
- * @param paramType 作业参数类型
- * @param source 数据
- * @return Object
- */
- private static Object convertDateType(String paramType, String source) {
- if (Objects.equals(paramType, ParamType.NODE.getValue())) {
- if (StringUtils.isNotBlank(source)) {
- JSONArray inputNodeList = new JSONArray();
- if (source.startsWith("[") && source.endsWith("]")) {
- JSONArray array = JSON.parseArray(source);
- for (int i = 0; i < array.size(); i++) {
- String str = array.getString(i);
- inputNodeList.add(new AutoexecNodeVo(str));
- }
- } else if (source.contains("\n")) {
- String[] split = source.split("\n");
- for (String str : split) {
- inputNodeList.add(new AutoexecNodeVo(str));
+ private static List getStringList(JSONArray jsonArray) {
+ List resultList = new ArrayList<>();
+ for (Object obj : jsonArray) {
+ if (obj == null) {
+ continue;
+ }
+ if (obj instanceof JSONArray) {
+ JSONArray array = (JSONArray) obj;
+ resultList.addAll(getStringList(array));
+ } else {
+ resultList.add(obj.toString());
+ }
+ }
+ return resultList;
+ }
+
+ private static List