Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix-3450][admin] Fix the issue of copying tasks with create time #3472

Merged
merged 3 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dinky-admin/src/main/java/org/dinky/data/model/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class Task extends SuperEntity<Task> {
@ApiModelProperty(value = "Dialect", dataType = "String", notes = "Dialect for the task")
private String dialect;

@TableField(fill = FieldFill.INSERT)
@ApiModelProperty(
value = "Tenant ID",
dataType = "Integer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.dinky.mybatis.handler;

import org.dinky.context.TenantContextHolder;
import org.dinky.mybatis.properties.MybatisPlusFillProperties;

import org.apache.ibatis.reflection.MetaObject;
Expand Down Expand Up @@ -57,7 +58,6 @@ public boolean openUpdateFill() {

@Override
public void insertFill(MetaObject metaObject) {

Object createTime = getFieldValByName(mybatisPlusFillProperties.getCreateTimeField(), metaObject);
Object updateTime = getFieldValByName(mybatisPlusFillProperties.getUpdateTimeField(), metaObject);
if (createTime == null) {
Expand All @@ -83,6 +83,7 @@ private void setFillFieldValue(MetaObject metaObject, int userId) {
Object creator = getFieldValByName(mybatisPlusFillProperties.getCreatorField(), metaObject);
Object updater = getFieldValByName(mybatisPlusFillProperties.getUpdaterField(), metaObject);
Object operator = getFieldValByName(mybatisPlusFillProperties.getOperatorField(), metaObject);
Object tenantId = getFieldValByName(mybatisPlusFillProperties.getTenantIdField(), metaObject);

if (creator == null) {
setFieldValByName(mybatisPlusFillProperties.getCreatorField(), userId, metaObject);
Expand All @@ -93,6 +94,10 @@ private void setFillFieldValue(MetaObject metaObject, int userId) {
if (operator == null) {
setFieldValByName(mybatisPlusFillProperties.getOperatorField(), userId, metaObject);
}
if (tenantId == null) {
int loginTenantId = (Integer) TenantContextHolder.get();
setFieldValByName(mybatisPlusFillProperties.getTenantIdField(), loginTenantId, metaObject);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ public class MybatisPlusFillProperties {
private String updaterField = "updater";

private String operatorField = "operator";

private String tenantIdField = "tenantId";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
*
* 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.
*
*/

package org.dinky.service.catalogue.factory;

import org.dinky.data.enums.JobLifeCycle;
import org.dinky.data.model.Catalogue;
import org.dinky.data.model.Task;

import java.util.Objects;

import org.springframework.stereotype.Component;

import cn.hutool.core.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;

/**
* CatalogueFactory
*
* @since 2024/5/8 19:12
*/
@Slf4j
@Component
public class CatalogueFactory {

public Task getNewTask(Task oldTask, String newTaskName) {
if (Objects.isNull(oldTask)) {
return null;
}
Task newTask = new Task();
BeanUtil.copyProperties(oldTask, newTask);
newTask.setId(null);
newTask.setJobInstanceId(null);
newTask.setName(newTaskName);
// set tasks to be in development status by default
newTask.setStep(JobLifeCycle.DEVELOP.getValue());
newTask.setVersionId(null);

// mybatis auto fill
newTask.setCreateTime(null);
newTask.setUpdateTime(null);
newTask.setCreator(null);
newTask.setUpdater(null);
newTask.setOperator(null);
newTask.setTenantId(null);
return newTask;
}

public Catalogue getNewCatalogue(Catalogue paramCatalogue, Catalogue oldCatalogue, Task newTask) {
Catalogue newCatalogue = new Catalogue();
BeanUtil.copyProperties(paramCatalogue, newCatalogue);
newCatalogue.setName(newTask.getName());
newCatalogue.setIsLeaf(oldCatalogue.getIsLeaf());
newCatalogue.setTaskId(newTask.getId());
newCatalogue.setType(oldCatalogue.getType());
newCatalogue.setParentId(oldCatalogue.getParentId());
newCatalogue.setId(null);

// mybatis auto fill
newCatalogue.setCreateTime(null);
newCatalogue.setUpdateTime(null);
newCatalogue.setCreator(null);
newCatalogue.setUpdater(null);
newCatalogue.setTenantId(null);
return newCatalogue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.dinky.service.MonitorService;
import org.dinky.service.TaskService;
import org.dinky.service.catalogue.CatalogueService;
import org.dinky.service.catalogue.factory.CatalogueFactory;
import org.dinky.service.catalogue.factory.CatalogueTreeSortFactory;
import org.dinky.service.catalogue.strategy.CatalogueTreeSortStrategy;

Expand Down Expand Up @@ -101,6 +102,8 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata

private final CatalogueTreeSortFactory catalogueTreeSortFactory;

private final CatalogueFactory catalogueFactory;

/**
* @return
*/
Expand Down Expand Up @@ -394,29 +397,15 @@ public boolean copyTask(Catalogue catalogue) {
}
// 查询作业名称
int size = taskService.queryAllSizeByName(oldTask.getName());

Task newTask = new Task();
BeanUtil.copyProperties(oldTask, newTask);
newTask.setId(null);
newTask.setJobInstanceId(null);
newTask.setType(oldTask.getType());
// 设置复制后的作业名称为:原名称+自增序列
size = size + 1;
newTask.setName(oldTask.getName() + "-" + size);
newTask.setStep(JobLifeCycle.DEVELOP.getValue());
String newTaskName = oldTask.getName() + "-" + (++size);
Task newTask = catalogueFactory.getNewTask(oldTask, newTaskName);
taskService.save(newTask);

Catalogue singleCatalogue =
this.getOne(new LambdaQueryWrapper<Catalogue>().eq(Catalogue::getTaskId, catalogue.getTaskId()));

catalogue.setName(newTask.getName());
catalogue.setIsLeaf(singleCatalogue.getIsLeaf());
catalogue.setTaskId(newTask.getId());
catalogue.setType(singleCatalogue.getType());
catalogue.setParentId(singleCatalogue.getParentId());
catalogue.setId(null);

return this.save(catalogue);
Catalogue newCatalogue = catalogueFactory.getNewCatalogue(catalogue, singleCatalogue, newTask);
return this.save(newCatalogue);
}

@Override
Expand Down
Loading