Unverified Commit 9d39c02c authored by gaoyan's avatar gaoyan Committed by GitHub

Fix task version bug (#2496)

* Optimize the process * fix task version bug * fix task version bug * fix task version bug
parent 9edfac5e
...@@ -31,7 +31,7 @@ import lombok.Data; ...@@ -31,7 +31,7 @@ import lombok.Data;
public class TaskRollbackVersionDTO implements Serializable { public class TaskRollbackVersionDTO implements Serializable {
@ApiModelProperty(value = "ID", dataType = "Integer", example = "1", notes = "The identifier of the task") @ApiModelProperty(value = "ID", dataType = "Integer", example = "1", notes = "The identifier of the task")
private Integer id; private Integer taskId;
@ApiModelProperty( @ApiModelProperty(
value = "Version ID", value = "Version ID",
......
...@@ -23,6 +23,7 @@ import org.dinky.data.dto.TaskVersionConfigureDTO; ...@@ -23,6 +23,7 @@ import org.dinky.data.dto.TaskVersionConfigureDTO;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Objects;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
...@@ -84,4 +85,22 @@ public class TaskVersion implements Serializable { ...@@ -84,4 +85,22 @@ public class TaskVersion implements Serializable {
@ApiModelProperty(value = "Create Time", dataType = "Date", notes = "Timestamp when the version was created") @ApiModelProperty(value = "Create Time", dataType = "Date", notes = "Timestamp when the version was created")
@TableField(value = "create_time") @TableField(value = "create_time")
private LocalDateTime createTime; private LocalDateTime createTime;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TaskVersion that = (TaskVersion) o;
return Objects.equals(taskId, that.taskId)
&& Objects.equals(versionId, that.versionId)
&& Objects.equals(statement, that.statement)
&& Objects.equals(dialect, that.dialect)
&& Objects.equals(type, that.type)
&& Objects.equals(taskConfigure, that.taskConfigure);
}
@Override
public int hashCode() {
return Objects.hash(taskId, versionId, statement, dialect, type, taskConfigure);
}
} }
...@@ -38,6 +38,7 @@ public interface TaskVersionService extends ISuperService<TaskVersion> { ...@@ -38,6 +38,7 @@ public interface TaskVersionService extends ISuperService<TaskVersion> {
* Create a snapshot of a task version. * Create a snapshot of a task version.
* *
* @param task A {@link TaskDTO} object representing the task to create a snapshot for. * @param task A {@link TaskDTO} object representing the task to create a snapshot for.
* @return
*/ */
void createTaskVersionSnapshot(TaskDTO task); Integer createTaskVersionSnapshot(TaskDTO task);
} }
...@@ -436,7 +436,8 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -436,7 +436,8 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
// sqlExplainResult.getError())); // sqlExplainResult.getError()));
// } // }
// } // }
taskVersionService.createTaskVersionSnapshot(task); Integer taskVersionId = taskVersionService.createTaskVersionSnapshot(task);
task.setVersionId(taskVersionId);
} }
return saveOrUpdate(task.buildTask()); return saveOrUpdate(task.buildTask());
} }
...@@ -558,12 +559,12 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -558,12 +559,12 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
@Override @Override
public boolean rollbackTask(TaskRollbackVersionDTO dto) { public boolean rollbackTask(TaskRollbackVersionDTO dto) {
if (Asserts.isNull(dto.getVersionId()) || Asserts.isNull(dto.getId())) { if (Asserts.isNull(dto.getVersionId()) || Asserts.isNull(dto.getTaskId())) {
throw new BusException("the version is error"); throw new BusException("the version is error");
} }
LambdaQueryWrapper<TaskVersion> queryWrapper = new LambdaQueryWrapper<TaskVersion>() LambdaQueryWrapper<TaskVersion> queryWrapper = new LambdaQueryWrapper<TaskVersion>()
.eq(TaskVersion::getTaskId, dto.getId()) .eq(TaskVersion::getTaskId, dto.getTaskId())
.eq(TaskVersion::getVersionId, dto.getVersionId()); .eq(TaskVersion::getVersionId, dto.getVersionId());
TaskVersion taskVersion = taskVersionService.getOne(queryWrapper); TaskVersion taskVersion = taskVersionService.getOne(queryWrapper);
......
...@@ -52,7 +52,7 @@ public class TaskVersionServiceImpl extends SuperServiceImpl<TaskVersionMapper, ...@@ -52,7 +52,7 @@ public class TaskVersionServiceImpl extends SuperServiceImpl<TaskVersionMapper,
} }
@Override @Override
public void createTaskVersionSnapshot(TaskDTO task) { public Integer createTaskVersionSnapshot(TaskDTO task) {
List<TaskVersion> taskVersions = getTaskVersionByTaskId(task.getId()); List<TaskVersion> taskVersions = getTaskVersionByTaskId(task.getId());
List<Integer> versionIds = List<Integer> versionIds =
taskVersions.stream().map(TaskVersion::getVersionId).collect(Collectors.toList()); taskVersions.stream().map(TaskVersion::getVersionId).collect(Collectors.toList());
...@@ -69,22 +69,22 @@ public class TaskVersionServiceImpl extends SuperServiceImpl<TaskVersionMapper, ...@@ -69,22 +69,22 @@ public class TaskVersionServiceImpl extends SuperServiceImpl<TaskVersionMapper,
taskVersion.setTaskId(taskVersion.getId()); taskVersion.setTaskId(taskVersion.getId());
taskVersion.setId(null); taskVersion.setId(null);
if (Asserts.isNull(task.getVersionId())) { if (Asserts.isNull(task.getVersionId()) || !versionIds.contains(task.getVersionId())) {
// FIRST RELEASE, ADD NEW VERSION // FIRST RELEASE, ADD NEW VERSION
taskVersion.setVersionId(1); taskVersion.setVersionId(1);
task.setVersionId(1);
taskVersion.setCreateTime(LocalDateTime.now()); taskVersion.setCreateTime(LocalDateTime.now());
save(taskVersion); save(taskVersion);
} else { } else {
// Explain that there is a version, you need to determine whether it is an old version after fallback // Explain that there is a version, you need to determine whether it is an old version after fallback
TaskVersion version = versionMap.get(task.getVersionId()); TaskVersion version = versionMap.getOrDefault(task.getVersionId(), new TaskVersion());
version.setId(null); // IDs are not involved in the comparison
if (versionIds.contains(task.getVersionId()) && !taskVersion.equals(version)) { if (!taskVersion.equals(version)) {
taskVersion.setVersionId(Collections.max(versionIds) + 1); int newVersionId = versionIds.isEmpty() ? 1 : Collections.max(versionIds) + 1;
task.setVersionId(Collections.max(versionIds) + 1); taskVersion.setVersionId(newVersionId);
taskVersion.setCreateTime(LocalDateTime.now()); taskVersion.setCreateTime(LocalDateTime.now());
save(taskVersion); save(taskVersion);
} }
} }
return taskVersion.getVersionId();
} }
} }
/* /*
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * 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 not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
*/ */
...@@ -163,6 +163,7 @@ const ConsoleContent = (props: ConsoleProps) => { ...@@ -163,6 +163,7 @@ const ConsoleContent = (props: ConsoleProps) => {
onSelect={onSelect} onSelect={onSelect}
treeData={[processNode]} treeData={[processNode]}
expandedKeys={expandedKeys} expandedKeys={expandedKeys}
expandAction={"doubleClick"}
onExpand={handleExpand} onExpand={handleExpand}
/> />
) : ( ) : (
......
/* /*
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * 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 not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
*/ */
import VersionList from '@/components/VersionList'; import VersionList from '@/components/VersionList';
import { getCurrentData } from '@/pages/DataStudio/function'; import { getCurrentData } from '@/pages/DataStudio/function';
import { StateType } from '@/pages/DataStudio/model'; import { StateType } from '@/pages/DataStudio/model';
...@@ -111,7 +112,7 @@ const HistoryVersion = (props: any) => { ...@@ -111,7 +112,7 @@ const HistoryVersion = (props: any) => {
cancelText: l('button.cancel'), cancelText: l('button.cancel'),
onOk: async () => { onOk: async () => {
const TaskVersionRollbackItem = { const TaskVersionRollbackItem = {
id: current?.key, taskId: row.taskId,
versionId: row.versionId versionId: row.versionId
}; };
await handleOption( await handleOption(
......
...@@ -39,7 +39,7 @@ const JobVersionTab = (props: JobProps) => { ...@@ -39,7 +39,7 @@ const JobVersionTab = (props: JobProps) => {
isLatest: true isLatest: true
}; };
const [currentVersion, setCurrentVersion] = useState<TaskVersionListItem>(); const [currentVersion, setCurrentVersion] = useState<TaskVersionListItem>(latestVersion);
const versionList = useRequest( const versionList = useRequest(
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment