Unverified Commit e2070b74 authored by suxinshuo's avatar suxinshuo Committed by GitHub

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

parent 38049f46
...@@ -55,6 +55,7 @@ public class Task extends SuperEntity<Task> { ...@@ -55,6 +55,7 @@ public class Task extends SuperEntity<Task> {
@ApiModelProperty(value = "Dialect", dataType = "String", notes = "Dialect for the task") @ApiModelProperty(value = "Dialect", dataType = "String", notes = "Dialect for the task")
private String dialect; private String dialect;
@TableField(fill = FieldFill.INSERT)
@ApiModelProperty( @ApiModelProperty(
value = "Tenant ID", value = "Tenant ID",
dataType = "Integer", dataType = "Integer",
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.dinky.mybatis.handler; package org.dinky.mybatis.handler;
import org.dinky.context.TenantContextHolder;
import org.dinky.mybatis.properties.MybatisPlusFillProperties; import org.dinky.mybatis.properties.MybatisPlusFillProperties;
import org.apache.ibatis.reflection.MetaObject; import org.apache.ibatis.reflection.MetaObject;
...@@ -57,7 +58,6 @@ public class DateMetaObjectHandler implements MetaObjectHandler { ...@@ -57,7 +58,6 @@ public class DateMetaObjectHandler implements MetaObjectHandler {
@Override @Override
public void insertFill(MetaObject metaObject) { public void insertFill(MetaObject metaObject) {
Object createTime = getFieldValByName(mybatisPlusFillProperties.getCreateTimeField(), metaObject); Object createTime = getFieldValByName(mybatisPlusFillProperties.getCreateTimeField(), metaObject);
Object updateTime = getFieldValByName(mybatisPlusFillProperties.getUpdateTimeField(), metaObject); Object updateTime = getFieldValByName(mybatisPlusFillProperties.getUpdateTimeField(), metaObject);
if (createTime == null) { if (createTime == null) {
...@@ -83,6 +83,7 @@ public class DateMetaObjectHandler implements MetaObjectHandler { ...@@ -83,6 +83,7 @@ public class DateMetaObjectHandler implements MetaObjectHandler {
Object creator = getFieldValByName(mybatisPlusFillProperties.getCreatorField(), metaObject); Object creator = getFieldValByName(mybatisPlusFillProperties.getCreatorField(), metaObject);
Object updater = getFieldValByName(mybatisPlusFillProperties.getUpdaterField(), metaObject); Object updater = getFieldValByName(mybatisPlusFillProperties.getUpdaterField(), metaObject);
Object operator = getFieldValByName(mybatisPlusFillProperties.getOperatorField(), metaObject); Object operator = getFieldValByName(mybatisPlusFillProperties.getOperatorField(), metaObject);
Object tenantId = getFieldValByName(mybatisPlusFillProperties.getTenantIdField(), metaObject);
if (creator == null) { if (creator == null) {
setFieldValByName(mybatisPlusFillProperties.getCreatorField(), userId, metaObject); setFieldValByName(mybatisPlusFillProperties.getCreatorField(), userId, metaObject);
...@@ -93,6 +94,10 @@ public class DateMetaObjectHandler implements MetaObjectHandler { ...@@ -93,6 +94,10 @@ public class DateMetaObjectHandler implements MetaObjectHandler {
if (operator == null) { if (operator == null) {
setFieldValByName(mybatisPlusFillProperties.getOperatorField(), userId, metaObject); setFieldValByName(mybatisPlusFillProperties.getOperatorField(), userId, metaObject);
} }
if (tenantId == null) {
int loginTenantId = (Integer) TenantContextHolder.get();
setFieldValByName(mybatisPlusFillProperties.getTenantIdField(), loginTenantId, metaObject);
}
} }
@Override @Override
......
...@@ -49,4 +49,6 @@ public class MybatisPlusFillProperties { ...@@ -49,4 +49,6 @@ public class MybatisPlusFillProperties {
private String updaterField = "updater"; private String updaterField = "updater";
private String operatorField = "operator"; private String operatorField = "operator";
private String tenantIdField = "tenantId";
} }
/*
*
* 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;
}
}
...@@ -49,6 +49,7 @@ import org.dinky.service.JobInstanceService; ...@@ -49,6 +49,7 @@ import org.dinky.service.JobInstanceService;
import org.dinky.service.MonitorService; import org.dinky.service.MonitorService;
import org.dinky.service.TaskService; import org.dinky.service.TaskService;
import org.dinky.service.catalogue.CatalogueService; 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.factory.CatalogueTreeSortFactory;
import org.dinky.service.catalogue.strategy.CatalogueTreeSortStrategy; import org.dinky.service.catalogue.strategy.CatalogueTreeSortStrategy;
...@@ -101,6 +102,8 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata ...@@ -101,6 +102,8 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
private final CatalogueTreeSortFactory catalogueTreeSortFactory; private final CatalogueTreeSortFactory catalogueTreeSortFactory;
private final CatalogueFactory catalogueFactory;
/** /**
* @return * @return
*/ */
...@@ -394,29 +397,15 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata ...@@ -394,29 +397,15 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
} }
// 查询作业名称 // 查询作业名称
int size = taskService.queryAllSizeByName(oldTask.getName()); 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; String newTaskName = oldTask.getName() + "-" + (++size);
newTask.setName(oldTask.getName() + "-" + size); Task newTask = catalogueFactory.getNewTask(oldTask, newTaskName);
newTask.setStep(JobLifeCycle.DEVELOP.getValue());
taskService.save(newTask); taskService.save(newTask);
Catalogue singleCatalogue = Catalogue singleCatalogue =
this.getOne(new LambdaQueryWrapper<Catalogue>().eq(Catalogue::getTaskId, catalogue.getTaskId())); this.getOne(new LambdaQueryWrapper<Catalogue>().eq(Catalogue::getTaskId, catalogue.getTaskId()));
Catalogue newCatalogue = catalogueFactory.getNewCatalogue(catalogue, singleCatalogue, newTask);
catalogue.setName(newTask.getName()); return this.save(newCatalogue);
catalogue.setIsLeaf(singleCatalogue.getIsLeaf());
catalogue.setTaskId(newTask.getId());
catalogue.setType(singleCatalogue.getType());
catalogue.setParentId(singleCatalogue.getParentId());
catalogue.setId(null);
return this.save(catalogue);
} }
@Override @Override
......
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