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;
public class TaskRollbackVersionDTO implements Serializable {
@ApiModelProperty(value = "ID", dataType = "Integer", example = "1", notes = "The identifier of the task")
private Integer id;
private Integer taskId;
@ApiModelProperty(
value = "Version ID",
......
......@@ -23,6 +23,7 @@ import org.dinky.data.dto.TaskVersionConfigureDTO;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
......@@ -84,4 +85,22 @@ public class TaskVersion implements Serializable {
@ApiModelProperty(value = "Create Time", dataType = "Date", notes = "Timestamp when the version was created")
@TableField(value = "create_time")
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> {
* Create a snapshot of a task version.
*
* @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
// sqlExplainResult.getError()));
// }
// }
taskVersionService.createTaskVersionSnapshot(task);
Integer taskVersionId = taskVersionService.createTaskVersionSnapshot(task);
task.setVersionId(taskVersionId);
}
return saveOrUpdate(task.buildTask());
}
......@@ -558,12 +559,12 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
@Override
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");
}
LambdaQueryWrapper<TaskVersion> queryWrapper = new LambdaQueryWrapper<TaskVersion>()
.eq(TaskVersion::getTaskId, dto.getId())
.eq(TaskVersion::getTaskId, dto.getTaskId())
.eq(TaskVersion::getVersionId, dto.getVersionId());
TaskVersion taskVersion = taskVersionService.getOne(queryWrapper);
......
......@@ -52,7 +52,7 @@ public class TaskVersionServiceImpl extends SuperServiceImpl<TaskVersionMapper,
}
@Override
public void createTaskVersionSnapshot(TaskDTO task) {
public Integer createTaskVersionSnapshot(TaskDTO task) {
List<TaskVersion> taskVersions = getTaskVersionByTaskId(task.getId());
List<Integer> versionIds =
taskVersions.stream().map(TaskVersion::getVersionId).collect(Collectors.toList());
......@@ -69,22 +69,22 @@ public class TaskVersionServiceImpl extends SuperServiceImpl<TaskVersionMapper,
taskVersion.setTaskId(taskVersion.getId());
taskVersion.setId(null);
if (Asserts.isNull(task.getVersionId())) {
if (Asserts.isNull(task.getVersionId()) || !versionIds.contains(task.getVersionId())) {
// FIRST RELEASE, ADD NEW VERSION
taskVersion.setVersionId(1);
task.setVersionId(1);
taskVersion.setCreateTime(LocalDateTime.now());
save(taskVersion);
} else {
// Explain that there is a version, you need to determine whether it is an old version after fallback
TaskVersion version = versionMap.get(task.getVersionId());
version.setId(null);
if (versionIds.contains(task.getVersionId()) && !taskVersion.equals(version)) {
taskVersion.setVersionId(Collections.max(versionIds) + 1);
task.setVersionId(Collections.max(versionIds) + 1);
TaskVersion version = versionMap.getOrDefault(task.getVersionId(), new TaskVersion());
// IDs are not involved in the comparison
if (!taskVersion.equals(version)) {
int newVersionId = versionIds.isEmpty() ? 1 : Collections.max(versionIds) + 1;
taskVersion.setVersionId(newVersionId);
taskVersion.setCreateTime(LocalDateTime.now());
save(taskVersion);
}
}
return taskVersion.getVersionId();
}
}
/*
*
* 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
* 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
* 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.
* 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.
*
*/
......@@ -163,6 +163,7 @@ const ConsoleContent = (props: ConsoleProps) => {
onSelect={onSelect}
treeData={[processNode]}
expandedKeys={expandedKeys}
expandAction={"doubleClick"}
onExpand={handleExpand}
/>
) : (
......
/*
*
* 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
* 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
* 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.
* 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 VersionList from '@/components/VersionList';
import { getCurrentData } from '@/pages/DataStudio/function';
import { StateType } from '@/pages/DataStudio/model';
......@@ -111,7 +112,7 @@ const HistoryVersion = (props: any) => {
cancelText: l('button.cancel'),
onOk: async () => {
const TaskVersionRollbackItem = {
id: current?.key,
taskId: row.taskId,
versionId: row.versionId
};
await handleOption(
......
......@@ -39,7 +39,7 @@ const JobVersionTab = (props: JobProps) => {
isLatest: true
};
const [currentVersion, setCurrentVersion] = useState<TaskVersionListItem>();
const [currentVersion, setCurrentVersion] = useState<TaskVersionListItem>(latestVersion);
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