diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-child-node.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-child-node.ts index 5d1d47a24c..130b476f92 100644 --- a/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-child-node.ts +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-child-node.ts @@ -23,7 +23,6 @@ import { queryProcessDefinitionByCode } from '@/service/modules/process-definition' import type { IJsonItem } from '../types' -import { number } from 'echarts' export function useChildNode({ model, diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-relation-custom-params.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-relation-custom-params.ts index ad4c740b0e..b7a2734c88 100644 --- a/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-relation-custom-params.ts +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-relation-custom-params.ts @@ -45,7 +45,6 @@ export function useRelationCustomParams({ } ) }) - console.log(model.relation) return [ { type: 'custom', diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/format-data.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/format-data.ts index 76c8777723..331eea90e6 100644 --- a/dolphinscheduler-ui-next/src/views/projects/task/components/node/format-data.ts +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/format-data.ts @@ -197,6 +197,13 @@ export function formatParams(data: INodeData): { taskParams.switchResult.nextNode = data.nextNode } + if (data.taskType === 'CONDITIONS') { + taskParams.dependence = { + relation: data.relation, + dependTaskList: data.dependTaskList + } + } + const params = { processDefinitionCode: data.processName ? String(data.processName) : '', upstreamCodes: data?.preTasks?.join(','), @@ -339,6 +346,10 @@ export function formatModel(data: ITaskData) { params.nextNode = data.taskParams.switchResult?.nextNode } + if (data.taskParams?.dependence) { + params.dependTaskList = data.taskParams?.dependence.dependTaskList || [] + params.relation = data.taskParams?.dependence.relation + } return params } diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/tasks/use-conditions.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/tasks/use-conditions.ts new file mode 100644 index 0000000000..cccfa30997 --- /dev/null +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/tasks/use-conditions.ts @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ref, reactive, watch } from 'vue' +import { useI18n } from 'vue-i18n' +import * as Fields from '../fields/index' +import type { IJsonItem, INodeData, ITaskData } from '../types' + +export function useConditions({ + projectCode, + from = 0, + readonly, + data +}: { + projectCode: number + from?: number + readonly?: boolean + data?: ITaskData +}) { + const { t } = useI18n() + const taskCodeOptions = ref([] as { label: string; value: number }[]) + const model = reactive({ + taskType: 'CONDITIONS', + name: '', + flag: 'YES', + description: '', + timeoutFlag: false, + localParams: [], + environmentCode: null, + failRetryInterval: 1, + failRetryTimes: 0, + workerGroup: 'default', + delayTime: 0, + timeout: 30, + relation: 'AND', + dependTaskList: [], + preTasks: [] + } as INodeData) + + let extra: IJsonItem[] = [] + if (from === 1) { + extra = [ + Fields.useTaskType(model, readonly), + Fields.useProcessName({ + model, + projectCode, + isCreate: !data?.id, + from, + processName: data?.processName, + code: data?.code + }) + ] + } + + watch( + () => model.preTasks, + () => { + taskCodeOptions.value = + model.preTaskOptions + ?.filter((task: { code: number }) => + model.preTasks?.includes(task.code) + ) + .map((task: { code: number; name: string }) => ({ + value: task.code, + label: task.name + })) || [] + } + ) + + return { + json: [ + Fields.useName(), + ...extra, + Fields.useRunFlag(), + Fields.useDescription(), + Fields.useTaskPriority(), + Fields.useWorkerGroup(), + Fields.useEnvironmentName(model, !data?.id), + ...Fields.useTaskGroup(model, projectCode), + ...Fields.useFailed(), + Fields.useDelayTime(model), + ...Fields.useTimeoutAlarm(model), + ...Fields.useRelationCustomParams({ + model, + children: { + type: 'custom-parameters', + field: 'dependItemList', + span: 18, + children: [ + { + type: 'select', + field: 'depTaskCode', + span: 10, + options: taskCodeOptions + }, + { + type: 'select', + field: 'status', + span: 10, + options: [ + { + value: 'SUCCESS', + label: t('project.node.success') + }, + { + value: 'FAILURE', + label: t('project.node.failed') + } + ] + } + ] + }, + childrenField: 'dependItemList' + }), + Fields.usePreTasks(model) + ] as IJsonItem[], + model + } +} diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/types.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/types.ts index d9a6a9c422..5e5fffed00 100644 --- a/dolphinscheduler-ui-next/src/views/projects/task/components/node/types.ts +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/types.ts @@ -24,6 +24,8 @@ import type { IDataBase } from '@/service/modules/data-source/types' type ProgramType = 'JAVA' | 'SCALA' | 'PYTHON' type SourceType = 'MYSQL' | 'HDFS' | 'HIVE' type ModelType = 'import' | 'export' +type RelationType = 'AND' | 'OR' +type ITaskType = TaskType interface IOption { label: string @@ -48,8 +50,10 @@ interface ILocalParam { } interface IDependTask { - condition: string - nextNode: number + condition?: string + nextNode?: number + relation?: RelationType + dependItemList?: { depTaskCode?: number; status?: 'SUCCESS' | 'FAILURE' }[] } interface ISwitchResult { @@ -145,7 +149,6 @@ interface ISqoopSourceParams { hivePartitionKey?: string hivePartitionValue?: string } - interface ITaskParams { resourceList?: ISourceItem[] mainJar?: ISourceItem @@ -199,14 +202,20 @@ interface ITaskParams { switchResult?: ISwitchResult dependTaskList?: IDependTask[] nextNode?: number + dependence?: { + relation?: RelationType + dependTaskList?: IDependTask[] + } } -type ITaskType = TaskType - interface INodeData extends Omit< ITaskParams, - 'resourceList' | 'mainJar' | 'targetParams' | 'sourceParams' + | 'resourceList' + | 'mainJar' + | 'targetParams' + | 'sourceParams' + | 'dependence' >, ISqoopTargetData, ISqoopSourceData { @@ -228,7 +237,7 @@ interface INodeData workerGroup?: string code?: number name?: string - preTasks?: [] + preTasks?: number[] preTaskOptions?: [] postTaskOptions?: [] resourceList?: number[] @@ -238,6 +247,7 @@ interface INodeData method?: string masterUrl?: string resourceFiles?: { id: number; fullName: string }[] | null + relation?: RelationType } interface ITaskData diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/use-task.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/use-task.ts index 22438a97a3..95d6f1f914 100644 --- a/dolphinscheduler-ui-next/src/views/projects/task/components/node/use-task.ts +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/use-task.ts @@ -28,6 +28,7 @@ import { useProcedure } from './tasks/use-procedure' import { useSqoop } from './tasks/use-sqoop' import { useSeaTunnel } from './tasks/use-sea-tunnel' import { useSwitch } from './tasks/use-switch' +import { useConditions } from './tasks/use-conditions' import { IJsonItem, INodeData, ITaskData } from './types' export function useTask({ @@ -149,5 +150,14 @@ export function useTask({ }) } + if (taskType === 'CONDITIONS') { + node = useConditions({ + projectCode, + from, + readonly, + data + }) + } + return node -} \ No newline at end of file +}