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 0000000000000000000000000000000000000000..20313bacf41338fc494464e2ca84358df54123fc --- /dev/null +++ b/src/main/java/neatlogic/module/autoexec/api/process/CreateJobStepTestApi.java @@ -0,0 +1,88 @@ +/* + * 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.combop.AutoexecCombopVersionVo; +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; +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.dao.mapper.AutoexecCombopVersionMapper; +import neatlogic.module.autoexec.process.dto.AutoexecJobBuilder; +import neatlogic.module.autoexec.process.dto.CreateJobConfigConfigVo; +import neatlogic.module.autoexec.process.util.CreateJobConfigUtil; +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 "测试新自动化节点"; + } + + @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); + 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 builderList = CreateJobConfigUtil.createAutoexecJobBuilderList(processTaskStepVo, createJobConfigConfigVo, autoexecCombopVersionVo); + System.out.println("builderList = " + JSONObject.toJSONString(builderList)); + JSONObject resultObj = new JSONObject(); + resultObj.put("builderList", builderList); + 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 0000000000000000000000000000000000000000..660568458168a77a6a6418b1b87a295d5c830699 --- /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/AutoexecJobBuilder.java b/src/main/java/neatlogic/module/autoexec/process/dto/AutoexecJobBuilder.java new file mode 100644 index 0000000000000000000000000000000000000000..8b1ca91ae79dd2aee9494700c56ab327c302b55d --- /dev/null +++ b/src/main/java/neatlogic/module/autoexec/process/dto/AutoexecJobBuilder.java @@ -0,0 +1,133 @@ +/* + * 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 com.alibaba.fastjson.JSONObject; +import neatlogic.framework.autoexec.constvalue.CombopOperationType; +import neatlogic.framework.autoexec.dto.combop.AutoexecCombopExecuteConfigVo; +import neatlogic.framework.autoexec.dto.combop.ParamMappingVo; +import neatlogic.framework.autoexec.dto.job.AutoexecJobVo; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.common.constvalue.SystemUser; +import neatlogic.framework.process.constvalue.AutoExecJobProcessSource; +import neatlogic.framework.restful.annotation.EntityField; + +public class AutoexecJobBuilder { + @EntityField(name = "工单步骤id", type = ApiParamType.LONG) + private final Long processTaskStepId; + @EntityField(name = "组合工具id", type = ApiParamType.LONG) + private final Long combopId; + @EntityField(name = "作业名称(唯一标识)", type = ApiParamType.STRING) + private String jobName; + + @EntityField(name = "场景id", type = ApiParamType.LONG) + private Long scenarioId; + + @EntityField(name = "作业执行参数", type = ApiParamType.JSONOBJECT) + private AutoexecCombopExecuteConfigVo executeConfig; + + @EntityField(name = "runner执行组", type = ApiParamType.JSONOBJECT) + private ParamMappingVo runnerGroup; + + @EntityField(name = "并发线程数", type = ApiParamType.INTEGER) + private Integer roundCount; + + @EntityField(name = "作业参数数据", type = ApiParamType.JSONOBJECT) + private JSONObject param; + + public Long getProcessTaskStepId() { + return processTaskStepId; + } + + public Long getCombopId() { + return combopId; + } + + public String getJobName() { + return jobName; + } + + public void setJobName(String jobName) { + this.jobName = jobName; + } + + public Long getScenarioId() { + return scenarioId; + } + + public void setScenarioId(Long scenarioId) { + this.scenarioId = scenarioId; + } + + public AutoexecCombopExecuteConfigVo getExecuteConfig() { + return executeConfig; + } + + public void setExecuteConfig(AutoexecCombopExecuteConfigVo executeConfig) { + this.executeConfig = executeConfig; + } + + public ParamMappingVo getRunnerGroup() { + return runnerGroup; + } + + public void setRunnerGroup(ParamMappingVo runnerGroup) { + this.runnerGroup = runnerGroup; + } + + public Integer getRoundCount() { + return roundCount; + } + + public void setRoundCount(Integer roundCount) { + this.roundCount = roundCount; + } + + public JSONObject getParam() { + return param; + } + + public void setParam(JSONObject param) { + this.param = param; + } + + public AutoexecJobBuilder(Long processTaskStepId, Long combopId) { + this.processTaskStepId = processTaskStepId; + this.combopId = combopId; + } + + public AutoexecJobVo build() { + AutoexecJobVo jobVo = new AutoexecJobVo(); + jobVo.setParam(param); + jobVo.setRunnerGroup(runnerGroup); + jobVo.setScenarioId(scenarioId); + jobVo.setExecuteConfig(executeConfig); + if (roundCount != null) { + jobVo.setRoundCount(roundCount); + } + jobVo.setName(jobName); + jobVo.setOperationId(combopId); + jobVo.setInvokeId(processTaskStepId); + jobVo.setRouteId(processTaskStepId.toString()); + jobVo.setSource(AutoExecJobProcessSource.ITSM.getValue()); + jobVo.setOperationType(CombopOperationType.COMBOP.getValue()); + jobVo.setIsFirstFire(1); + jobVo.setAssignExecUser(SystemUser.SYSTEM.getUserUuid()); + return jobVo; + } +} 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 0000000000000000000000000000000000000000..2cf3dd12ac099e89b8f0b612784ad057c3ee9120 --- /dev/null +++ b/src/main/java/neatlogic/module/autoexec/process/dto/CreateJobConfigConfigVo.java @@ -0,0 +1,136 @@ +/* + * 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 com.alibaba.fastjson.JSONArray; + +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 List jobParamMappingGroupList; + + private List executeParamMappingGroupList; + + private CreateJobConfigMappingVo batchDataSourceMapping; + + private JSONArray formAttributeMappingList; + + private List scenarioParamMappingGroupList; + + 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 List getJobParamMappingGroupList() { + return jobParamMappingGroupList; + } + + public void setJobParamMappingGroupList(List jobParamMappingGroupList) { + this.jobParamMappingGroupList = jobParamMappingGroupList; + } + + 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 JSONArray getFormAttributeMappingList() { + return formAttributeMappingList; + } + + public void setFormAttributeMappingList(JSONArray formAttributeMappingList) { + this.formAttributeMappingList = formAttributeMappingList; + } + + 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 0000000000000000000000000000000000000000..b41dc227b2035cfa6a164d44402857317e288b72 --- /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 0000000000000000000000000000000000000000..033ac03a0ccd1dd87ed2bc2f7eb039b025bfe73a --- /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 0000000000000000000000000000000000000000..efc0fbd655373137e3fd38b8b4bdce247ce72922 --- /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 0000000000000000000000000000000000000000..ae2135c6f9b0f46ac130ba3fb0522f3e32d7bf3f --- /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 0000000000000000000000000000000000000000..58a2b9cd36608fb461d7d85404b5895d56cfaabe --- /dev/null +++ b/src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessComponent.java @@ -0,0 +1,503 @@ +/* + * 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.dao.mapper.AutoexecJobMapper; +import neatlogic.framework.autoexec.dto.combop.AutoexecCombopVersionVo; +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.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.AutoexecCombopVersionMapper; +import neatlogic.module.autoexec.process.constvalue.CreateJobProcessStepHandlerType; +import neatlogic.module.autoexec.process.dto.AutoexecJobBuilder; +import neatlogic.module.autoexec.process.dto.CreateJobConfigConfigVo; +import neatlogic.module.autoexec.process.dto.CreateJobConfigVo; +import neatlogic.module.autoexec.process.util.CreateJobConfigUtil; +import neatlogic.module.autoexec.service.AutoexecCombopService; +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); + @Resource + private AutoexecJobMapper autoexecJobMapper; + + @Resource + private AutoexecJobActionService autoexecJobActionService; + + @Resource + private AutoexecCombopVersionMapper autoexecCombopVersionMapper; + @Resource + private AutoexecCombopService autoexecCombopService; + + + @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 builderList = new ArrayList<>(); + for (CreateJobConfigConfigVo createJobConfigConfigVo : configList) { + 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); + } + // 根据配置信息创建AutoexecJobBuilder对象 + List list = CreateJobConfigUtil.createAutoexecJobBuilderList(currentProcessTaskStepVo, createJobConfigConfigVo, autoexecCombopVersionVo); + for (AutoexecJobBuilder builder : list) { + System.out.println("builder = " + JSON.toJSONString(builder)); + } + builderList.addAll(list); + + } + JSONArray errorMessageList = new JSONArray(); + boolean flag = false; + List jobIdList = new ArrayList<>(); + for (AutoexecJobBuilder builder : builderList) { + AutoexecJobVo jobVo = builder.build(); + try { + autoexecJobActionService.validateCreateJob(jobVo); + autoexecJobMapper.insertAutoexecJobProcessTaskStep(jobVo.getId(), currentProcessTaskStepVo.getId()); + jobIdList.add(jobVo.getId()); + } catch (Exception e) { + // 增加提醒 + logger.error(e.getMessage(), e); + logger.error(JSON.toJSONString(builder)); + JSONObject errorMessageObj = new JSONObject(); + errorMessageObj.put("jobId", jobVo.getId()); + errorMessageObj.put("jobName", jobVo.getName()); + errorMessageObj.put("error", e.getMessage() + " jobVo=" + JSON.toJSONString(builder)); + 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()); + } + } else { + processTaskStepComplete(currentProcessTaskStepVo.getId()); + } + } + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new ProcessTaskException(e.getMessage()); + } + return 1; + } + + private void processTaskStepComplete(Long processTaskStepId) { + IProcessTaskCrossoverMapper processTaskCrossoverMapper = CrossoverServiceFactory.getApi(IProcessTaskCrossoverMapper.class); + List toProcessTaskStepIdList = processTaskCrossoverMapper.getToProcessTaskStepIdListByFromIdAndType(processTaskStepId, ProcessFlowDirection.FORWARD.getValue()); + if (toProcessTaskStepIdList.size() == 1) { + Long nextStepId = toProcessTaskStepIdList.get(0); + try { + ProcessTaskStepVo processTaskStepVo = processTaskCrossoverMapper.getProcessTaskStepBaseInfoById(processTaskStepId); + JSONObject paramObj = processTaskStepVo.getParamObj(); + paramObj.put("nextStepId", nextStepId); + paramObj.put("action", ProcessTaskOperationType.STEP_COMPLETE.getValue()); + /* 自动处理 **/ + 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; + } + JSONObject createJobConfig = (JSONObject) JSONPath.read(config, "createJobConfig"); + if (MapUtils.isEmpty(createJobConfig)) { + return 0; + } + CreateJobConfigVo createJobConfigVo = createJobConfig.toJavaObject(CreateJobConfigVo.class); + List configList = createJobConfigVo.getConfigList(); +// JSONArray configList = (JSONArray) JSONPath.read(config, "createJobConfig.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 (CreateJobConfigConfigVo createJobConfigConfigVo : configList) { +// JSONObject configObj = configList.getJSONObject(j); +// if (MapUtils.isEmpty(configObj)) { +// continue; +// } +// JSONArray formAttributeList = configObj.getJSONArray("formAttributeList"); + JSONArray formAttributeList = createJobConfigConfigVo.getFormAttributeMappingList(); + 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(FormAttributeVo::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 0000000000000000000000000000000000000000..77a176b74267a11a19d5b61483de7914656097bc --- /dev/null +++ b/src/main/java/neatlogic/module/autoexec/process/stephandler/CreateJobProcessUtilHandler.java @@ -0,0 +1,248 @@ +/* + * 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.process.dto.CreateJobConfigVo; +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"); + CreateJobConfigVo createJobConfigVo = regulateCreateJobConfig(createJobConfig); + resultObj.put("createJobConfig", createJobConfigVo); + + /** 分配处理人 **/ + 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 CreateJobConfigVo regulateCreateJobConfig(JSONObject createJobConfig) { + if (createJobConfig == null) { + createJobConfig = new JSONObject(); + } + return createJobConfig.toJavaObject(CreateJobConfigVo.class); + } +} diff --git a/src/main/java/neatlogic/module/autoexec/process/util/CreateJobConfigUtil.java b/src/main/java/neatlogic/module/autoexec/process/util/CreateJobConfigUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..77a18b0f4fb00b3ac7ec480436eaca36c73ce2e7 --- /dev/null +++ b/src/main/java/neatlogic/module/autoexec/process/util/CreateJobConfigUtil.java @@ -0,0 +1,1351 @@ +/* + * 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.JSONObject; +import neatlogic.framework.autoexec.constvalue.CombopNodeSpecify; +import neatlogic.framework.autoexec.constvalue.ParamType; +import neatlogic.framework.autoexec.crossover.IAutoexecCombopCrossoverService; +import neatlogic.framework.autoexec.dto.AutoexecParamVo; +import neatlogic.framework.autoexec.dto.combop.*; +import neatlogic.framework.autoexec.dto.node.AutoexecNodeVo; +import neatlogic.framework.cmdb.crossover.IResourceAccountCrossoverMapper; +import neatlogic.framework.cmdb.dto.resourcecenter.AccountProtocolVo; +import neatlogic.framework.cmdb.dto.resourcecenter.AccountVo; +import neatlogic.framework.common.constvalue.Expression; +import neatlogic.framework.common.constvalue.GroupSearch; +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.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.*; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; + +import java.util.*; +import java.util.stream.Collectors; + +public class CreateJobConfigUtil { + + /** + * 根据工单步骤配置信息创建AutoexecJobVo对象 + * + * @param currentProcessTaskStepVo + * @param createJobConfigConfigVo + * @return + */ + public static List createAutoexecJobBuilderList(ProcessTaskStepVo currentProcessTaskStepVo, CreateJobConfigConfigVo createJobConfigConfigVo, AutoexecCombopVersionVo autoexecCombopVersionVo) { + 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()); + System.out.println("processTaskFormAttributeDataList = " + JSON.toJSONString(processTaskFormAttributeDataList)); + 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())) { + IFormAttributeDataConversionHandler handler = FormAttributeDataConversionHandlerFactory.getHandler(attributeDataVo.getHandler()); + if (handler != null) { + formAttributeDataMap.put(attributeDataVo.getAttributeUuid(), handler.getSimpleValue(attributeDataVo.getDataObj())); + } else { + 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")) { + AutoexecJobBuilder builder = createSingleAutoexecJobBuilder(currentProcessTaskStepVo, createJobConfigConfigVo, autoexecCombopVersionVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam); + List builderList = new ArrayList<>(); + builderList.add(builder); + return builderList; + } else if (Objects.equals(createPolicy, "batch")) { + List builderList = createBatchAutoexecJobBuilder(currentProcessTaskStepVo, createJobConfigConfigVo, autoexecCombopVersionVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam); + return builderList; + } else { + return null; + } + } + + /** + * 批量创建作业 + * + * @param currentProcessTaskStepVo + * @param createJobConfigConfigVo + * @param formAttributeList + * @param originalFormAttributeDataMap + * @param formAttributeDataMap + * @param processTaskParam + * @return + */ + private static List createBatchAutoexecJobBuilder( + 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)); + AutoexecJobBuilder builder = createSingleAutoexecJobBuilder(currentProcessTaskStepVo, createJobConfigConfigVo, autoexecCombopVersionVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam); + resultList.add(builder); + } + return resultList; + } + + /** + * 单次创建作业 + * + * @param currentProcessTaskStepVo + * @param createJobConfigConfigVo + * @param formAttributeList + * @param originalFormAttributeDataMap + * @param formAttributeDataMap + * @param processTaskParam + * @return + */ + private static AutoexecJobBuilder createSingleAutoexecJobBuilder( + ProcessTaskStepVo currentProcessTaskStepVo, + CreateJobConfigConfigVo createJobConfigConfigVo, + AutoexecCombopVersionVo autoexecCombopVersionVo, + List formAttributeList, + Map originalFormAttributeDataMap, + Map formAttributeDataMap, + JSONObject processTaskParam) { + // 组合工具ID + Long combopId = createJobConfigConfigVo.getCombopId(); + AutoexecJobBuilder builder = new AutoexecJobBuilder(currentProcessTaskStepVo.getId(), combopId); + // 作业名称 + String jobName = createJobConfigConfigVo.getJobName(); + AutoexecCombopVersionConfigVo versionConfig = autoexecCombopVersionVo.getConfig(); + // 场景 + 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, versionConfig.getScenarioList()); + builder.setScenarioId(scenarioId); + } + } + if (CollectionUtils.isNotEmpty(versionConfig.getRuntimeParamList())) { + List jobParamList = versionConfig.getRuntimeParamList(); + Map jobParamMap = jobParamList.stream().collect(Collectors.toMap(AutoexecParamVo::getKey, e -> e)); + // 作业参数赋值列表 + List jopParamMappingGroupList = createJobConfigConfigVo.getJobParamMappingGroupList(); + if (CollectionUtils.isNotEmpty(jopParamMappingGroupList)) { + JSONObject param = new JSONObject(); + for (CreateJobConfigMappingGroupVo mappingGroupVo : jopParamMappingGroupList) { + AutoexecParamVo autoexecParamVo = jobParamMap.get(mappingGroupVo.getKey()); + if (autoexecParamVo == null) { + continue; + } + JSONArray jsonArray = parseCreateJobConfigMappingGroup(mappingGroupVo, formAttributeList, originalFormAttributeDataMap, formAttributeDataMap, processTaskParam); + if (CollectionUtils.isEmpty(jsonArray)) { + continue; + } + Object value = convertDateType(autoexecParamVo, jsonArray); + param.put(mappingGroupVo.getKey(), value); + } + builder.setParam(param); + } + } + + // 目标参数赋值列表 + Map executeParamMappingGroupMap = new HashMap<>(); + List executeParamMappingGroupList = createJobConfigConfigVo.getExecuteParamMappingGroupList(); + if (CollectionUtils.isNotEmpty(executeParamMappingGroupList)) { + 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) { + executeConfig.setExecuteNodeConfig(executeNodeConfig); +// 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); + AutoexecCombopExecuteNodeConfigVo executeNodeConfigVo = getExecuteNodeConfig(jsonArray); + if (executeNodeConfigVo != null) { + executeConfig.setExecuteNodeConfig(executeNodeConfigVo); + } +// 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); + } + } + } + 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) { + builder.setRoundCount(roundCount); + } + } + } + } + builder.setExecuteConfig(executeConfig); + + // 执行器组 + ParamMappingVo runnerGroup = combopExecuteConfig.getRunnerGroup(); + if (runnerGroup != null) { + builder.setRunnerGroup(runnerGroup); + } + + String jobNamePrefixMappingValue = createJobConfigConfigVo.getJobNamePrefixMappingValue(); + String jobNamePrefixValue = getJobNamePrefix(jobNamePrefixMappingValue, builder.getExecuteConfig(), builder.getParam()); + builder.setJobName(jobNamePrefixValue + jobName); + return builder; + } + + private static Long getScenarioId(JSONArray jsonArray, List scenarioList) { + if (CollectionUtils.isEmpty(jsonArray)) { + return null; + } + List scenarioIdList = new ArrayList<>(); + Map scenarioNameToIdMap = new HashMap<>(); + for (AutoexecCombopScenarioVo combopScenarioVo : scenarioList) { + scenarioIdList.add(combopScenarioVo.getScenarioId()); + scenarioNameToIdMap.put(combopScenarioVo.getScenarioName(), combopScenarioVo.getScenarioId()); + } + for (Object obj : jsonArray) { + if (obj instanceof Long) { + Long scenarioId = (Long) obj; + if (scenarioIdList.contains(scenarioId)) { + return scenarioId; + } + } else if (obj instanceof String) { + String scenario = (String) obj; + try { + Long scenarioId = Long.valueOf(scenario); + if (scenarioIdList.contains(scenarioId)) { + return scenarioId; + } + } catch (NumberFormatException ignored) { + Long scenarioId = scenarioNameToIdMap.get(scenario); + if (scenarioId != null) { + return scenarioId; + } + } + } else if (obj instanceof JSONArray) { + JSONArray array = (JSONArray) obj; + Long scenarioId = getScenarioId(array, scenarioList); + if (scenarioId != null) { + return scenarioId; + } + } + } + return null; + } + + private static Long getProtocolId(JSONArray jsonArray) { + if (CollectionUtils.isEmpty(jsonArray)) { + return null; + } + 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 (obj instanceof String) { + String protocol = (String) obj; + try { + Long protocolId = Long.valueOf(protocol); + AccountProtocolVo accountProtocolVo = resourceAccountCrossoverMapper.getAccountProtocolVoByProtocolId(protocolId); + if (accountProtocolVo != null) { + return protocolId; + } + } catch (NumberFormatException ex) { + AccountProtocolVo accountProtocolVo = resourceAccountCrossoverMapper.getAccountProtocolVoByProtocolName(protocol); + if (accountProtocolVo != null) { + return accountProtocolVo.getId(); + } + } + } else if (obj instanceof JSONArray) { + JSONArray array = (JSONArray) obj; + Long protocolId = getProtocolId(array); + if (protocolId != null) { + return protocolId; + } + } + } + return null; + } + + private static Long getAccountId(JSONArray jsonArray) { + if (CollectionUtils.isEmpty(jsonArray)) { + return null; + } + 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; + } + } 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; + } + } catch (NumberFormatException ex) { + AccountVo accountVo = resourceAccountCrossoverMapper.getPublicAccountByName(account); + if (accountVo != null) { + return accountVo.getId(); + } + } + } else if (obj instanceof JSONObject) { + JSONObject jsonObj = (JSONObject) obj; + Long accountId = jsonObj.getLong("accountId"); + AccountVo accountVo = resourceAccountCrossoverMapper.getAccountById(accountId); + if (accountVo != null) { + return accountId; + } + } else if (obj instanceof JSONArray) { + JSONArray array = (JSONArray) obj; + Long accountId = getAccountId(array); + if (accountId != null) { + return accountId; + } + } + } + return null; + } + + private static AutoexecCombopExecuteNodeConfigVo getExecuteNodeConfig(JSONArray jsonArray) { + if (CollectionUtils.isEmpty(jsonArray)) { + return null; + } + AutoexecCombopExecuteNodeConfigVo executeNodeConfigVo = new AutoexecCombopExecuteNodeConfigVo(); + List selectNodeList = new ArrayList<>(); + List inputNodeList = new ArrayList<>(); + JSONObject filter = new JSONObject(); + 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)) { + inputNodeList.add(convertToAutoexecNodeVo(jsonObj)); + } + } else if (str.startsWith("[") && str.endsWith("]")) { + JSONArray array = JSON.parseArray(str); + List list = getInputNodeList(array); + if (CollectionUtils.isNotEmpty(list)) { + inputNodeList.addAll(list); + } + } else if (str.contains("\n")) { + String[] split = str.split("\n"); + for (String e : split) { + inputNodeList.add(new AutoexecNodeVo(e)); + } + } else { + inputNodeList.add(new AutoexecNodeVo(str)); + } + } else if (obj instanceof JSONObject) { + JSONObject jsonObj = (JSONObject) obj; + JSONArray selectNodeArray = jsonObj.getJSONArray("selectNodeList"); + if (CollectionUtils.isNotEmpty(selectNodeArray)) { + selectNodeList.addAll(selectNodeArray.toJavaList(AutoexecNodeVo.class)); + } + JSONArray inputNodeArray = jsonObj.getJSONArray("inputNodeList"); + if (CollectionUtils.isNotEmpty(inputNodeArray)) { + inputNodeList.addAll(inputNodeArray.toJavaList(AutoexecNodeVo.class)); + } + JSONObject filterObj = jsonObj.getJSONObject("filter"); + if (MapUtils.isNotEmpty(filterObj)) { + filter.putAll(filterObj); + } + String ip = jsonObj.getString("ip"); + if (StringUtils.isNotBlank(ip)) { + inputNodeList.add(convertToAutoexecNodeVo(jsonObj)); + } + } else if (obj instanceof JSONArray) { + JSONArray array = (JSONArray) obj; + List list = getInputNodeList(array); + if (CollectionUtils.isNotEmpty(list)) { + inputNodeList.addAll(list); + } + } + } + executeNodeConfigVo.setSelectNodeList(selectNodeList); + executeNodeConfigVo.setInputNodeList(inputNodeList); + executeNodeConfigVo.setFilter(filter); + return executeNodeConfigVo; + } + + private static List getInputNodeList(JSONArray jsonArray) { + List resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(jsonArray)) { + return resultList; + } + 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)) { + resultList.add(convertToAutoexecNodeVo(jsonObj)); + } + } 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)); + } + } else if (obj instanceof JSONObject) { + JSONObject jsonObj = (JSONObject) obj; + JSONArray selectNodeArray = jsonObj.getJSONArray("selectNodeList"); + if (CollectionUtils.isNotEmpty(selectNodeArray)) { + resultList.addAll(selectNodeArray.toJavaList(AutoexecNodeVo.class)); + } + JSONArray inputNodeArray = jsonObj.getJSONArray("inputNodeList"); + if (CollectionUtils.isNotEmpty(inputNodeArray)) { + resultList.addAll(inputNodeArray.toJavaList(AutoexecNodeVo.class)); + } + String ip = jsonObj.getString("ip"); + if (StringUtils.isNotBlank(ip)) { + resultList.add(convertToAutoexecNodeVo(jsonObj)); + } + } else if (obj instanceof JSONArray) { + JSONArray array = (JSONArray) obj; + List list = getInputNodeList(array); + if (CollectionUtils.isNotEmpty(list)) { + resultList.addAll(list); + } + } + } + return resultList; + } + + private static AutoexecNodeVo convertToAutoexecNodeVo(JSONObject jsonObj) { + Long id = jsonObj.getLong("id"); + String ip = jsonObj.getString("ip"); + 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); + } + return autoexecNodeVo; + } + + /** + * 根据设置找到作业名称前缀值 + * + * @param jobNamePrefixMappingValue 作业名称前缀映射值 + * @param executeConfig 目标参数 + * @param param 作业参数 + * @return 返回作业名称前缀值 + */ + private static String getJobNamePrefix(String jobNamePrefixMappingValue, AutoexecCombopExecuteConfigVo executeConfig, JSONObject param) { + String jobNamePrefixValue = StringUtils.EMPTY; + if (StringUtils.isBlank(jobNamePrefixMappingValue)) { + return jobNamePrefixValue; + } + if (Objects.equals(jobNamePrefixMappingValue, "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(jobNamePrefixMappingValue, "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(jobNamePrefixMappingValue, "protocolId")) { + Long protocolId = executeConfig.getProtocolId(); + if (protocolId != null) { + jobNamePrefixValue = protocolId.toString(); + } + } else if (Objects.equals(jobNamePrefixMappingValue, "roundCount")) { + Integer roundCount = executeConfig.getRoundCount(); + if (roundCount != null) { + jobNamePrefixValue = roundCount.toString(); + } + } else { + Object jobNamePrefixObj = param.get(jobNamePrefixMappingValue); + 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 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 resultList; + } + 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")) { + resultList.add(formAttributeDataMap.get(value)); + } 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)); + } + } + } + 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)) { + 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 = 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()); + if (handler != null) { + value = handler.getSimpleValue(value); + } + newJsonObj.put(key, value); + } else { + 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; + } + + 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 + * @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 autoexecParamVo 作业参数信息 + * @param jsonArray 某列数据集合 + * @return + */ + private static Object convertDateType(AutoexecParamVo autoexecParamVo, JSONArray jsonArray) { + if (CollectionUtils.isEmpty(jsonArray)) { + return null; + } + String paramType = autoexecParamVo.getType(); + 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 getFileInfo(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())) { + return getJSONObjectOrJSONArray(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())) { + // 单选或多选都是数组 + return getUserSelectInfo(jsonArray); + } 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 null; + } + + 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 getObjectList(JSONArray jsonArray) { + List resultList = new ArrayList<>(); + for (Object obj : jsonArray) { + if (obj == null) { + continue; + } + if (obj instanceof JSONArray) { + JSONArray array = (JSONArray) obj; + resultList.addAll(getObjectList(array)); + } else { + resultList.add(obj); + } + } + return resultList; + } + + private static Integer getFirstNotBlankInteger(JSONArray jsonArray) { + for (Object obj : jsonArray) { + if (obj == null) { + continue; + } + if (obj instanceof JSONArray) { + JSONArray array = (JSONArray) obj; + Integer integer = getFirstNotBlankInteger(array); + if (integer != null) { + return integer; + } + } else if (obj instanceof Integer) { + return (Integer) obj; + } else { + String str = obj.toString(); + if (StringUtils.isNotBlank(str)) { + try { + return Integer.valueOf(str); + } catch (NumberFormatException e) { + + } + } + } + } + return null; + } + + private static String getFirstNotBlankString(JSONArray jsonArray) { + for (Object obj : jsonArray) { + if (obj == null) { + continue; + } + if (obj instanceof JSONArray) { + JSONArray array = (JSONArray) obj; + String str = getFirstNotBlankString(array); + if (StringUtils.isNotBlank(str)) { + return str; + } + } else { + String str = obj.toString(); + if (StringUtils.isNotBlank(str)) { + return str; + } + } + } + return null; + } + + private static Object getFirstNotNullObject(JSONArray jsonArray) { + for (Object obj : jsonArray) { + if (obj == null) { + continue; + } + if (obj instanceof JSONArray) { + JSONArray array = (JSONArray) obj; + Object obj2 = getFirstNotNullObject(array); + if (obj2 != null) { + return obj2; + } + } else { + return obj; + } + } + return null; + } + + private static Boolean getFirstNotNullBoolean(JSONArray jsonArray) { + for (Object obj : jsonArray) { + if (obj == null) { + continue; + } + if (obj instanceof JSONArray) { + JSONArray array = (JSONArray) obj; + Boolean bool = getFirstNotNullBoolean(array); + if (bool != null) { + return bool; + } + } else if (obj instanceof Boolean) { + return (Boolean) obj; + } else { + String str = obj.toString(); + if (Objects.equals(str, Boolean.TRUE.toString())) { + return Boolean.TRUE; + } else if (Objects.equals(str, Boolean.FALSE.toString())) { + return Boolean.FALSE; + } + } + } + return null; + } + + private static Object getJSONObjectOrJSONArray(JSONArray jsonArray) { + JSONArray jsonList = new JSONArray(); + for (Object obj : jsonArray) { + if (obj instanceof JSONObject) { + jsonList.add(obj); + } else if (obj instanceof JSONArray) { + jsonList.add(obj); + } else if (obj instanceof Number) { + jsonList.add(obj); + } else { + String str = obj.toString(); + if (str.startsWith("{") && str.endsWith("}")) { + JSONObject jsonObj = JSON.parseObject(str); + jsonList.add(jsonObj); + } else if (str.startsWith("[") && str.endsWith("]")) { + JSONArray array = JSON.parseArray(str); + jsonList.add(array); + } else { + jsonList.add(str); + } + } + } + if (jsonList.size() == 1) { + Object obj = jsonList.get(0); + if (obj instanceof JSONObject) { + return obj; + } + } + return jsonList; + } + + private static JSONObject getFileInfo(JSONArray jsonArray) { + JSONObject resultObj = new JSONObject(); + JSONArray fileIdList = new JSONArray(); + JSONArray fileList = new JSONArray(); + for (Object obj : jsonArray) { + if (obj == null) { + continue; + } + if (obj instanceof JSONObject) { + JSONObject jsonObj = (JSONObject) obj; + JSONArray fileIdArray = jsonObj.getJSONArray("fileIdList"); + if (CollectionUtils.isNotEmpty(fileIdArray)) { + fileIdList.addAll(fileIdArray); + } + JSONArray fileArray = jsonObj.getJSONArray("fileList"); + if (CollectionUtils.isNotEmpty(fileArray)) { + fileList.addAll(fileArray); + } + } else if (obj instanceof JSONArray) { + JSONArray array = (JSONArray) obj; + JSONObject jsonObj = getFileInfo(array); + JSONArray fileIdArray = jsonObj.getJSONArray("fileIdList"); + if (CollectionUtils.isNotEmpty(fileIdArray)) { + fileIdList.addAll(fileIdArray); + } + JSONArray fileArray = jsonObj.getJSONArray("fileList"); + if (CollectionUtils.isNotEmpty(fileArray)) { + fileList.addAll(fileArray); + } + } else { + String str = obj.toString(); + if (str.startsWith("{") && str.endsWith("}")) { + JSONObject jsonObj = JSONObject.parseObject(str); + JSONArray fileIdArray = jsonObj.getJSONArray("fileIdList"); + if (CollectionUtils.isNotEmpty(fileIdArray)) { + fileIdList.addAll(fileIdArray); + } + JSONArray fileArray = jsonObj.getJSONArray("fileList"); + if (CollectionUtils.isNotEmpty(fileArray)) { + fileList.addAll(fileArray); + } + } else if (str.startsWith("[") && str.endsWith("]")) { + JSONArray array = JSONArray.parseArray(str); + JSONObject jsonObj = getFileInfo(array); + JSONArray fileIdArray = jsonObj.getJSONArray("fileIdList"); + if (CollectionUtils.isNotEmpty(fileIdArray)) { + fileIdList.addAll(fileIdArray); + } + JSONArray fileArray = jsonObj.getJSONArray("fileList"); + if (CollectionUtils.isNotEmpty(fileArray)) { + fileList.addAll(fileArray); + } + } + } + } + resultObj.put("fileIdList", fileIdList); + resultObj.put("fileList", fileList); + return resultObj; + } + + private static List getUserSelectInfo(JSONArray jsonArray) { + 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 resultList; + } +}