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

bugfix: 作业模板更新后,调试时使用的变量不是最新模板中的值 #1519 #1585

Merged
merged 1 commit into from
Dec 5, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ public interface TaskVariableDAO {
*/
boolean deleteVariableById(long parentId, long id);

/**
* 根据 父资源ID 删除变量信息
*
* @param parentId 父资源ID
* @return 是否删除成功
*/
int deleteVariableByParentId(long parentId);

/**
* 保留变量 ID 批量插入变量信息
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ public boolean deleteVariableById(long parentId, long id) {
return 1 == context.deleteFrom(TABLE).where(conditions).limit(1).execute();
}

@Override
public int deleteVariableByParentId(long parentId) {
List<Condition> conditions = new ArrayList<>();
conditions.add(TABLE.PLAN_ID.eq(ULong.valueOf(parentId)));
return context.deleteFrom(TABLE).where(conditions).execute();
}

@Override
public boolean batchInsertVariableWithId(List<TaskVariableDTO> variableList) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ public boolean deleteVariableById(long parentId, long id) {
return 1 == context.deleteFrom(TABLE).where(conditions).limit(1).execute();
}

@Override
public int deleteVariableByParentId(long parentId) {
List<Condition> conditions = new ArrayList<>();
conditions.add(TABLE.TEMPLATE_ID.eq(ULong.valueOf(parentId)));
return context.deleteFrom(TABLE).where(conditions).execute();
}

@Override
public boolean batchInsertVariableWithId(List<TaskVariableDTO> variableList) {
InsertValuesStep8<TaskTemplateVariableRecord, ULong, ULong, String, UByte, String, String, UByte,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ public boolean deleteVariableById(Long parentId, Long id) {
return taskVariableDAO.deleteVariableById(parentId, id);
}

/**
* 根据 父资源ID 删除变量
*
* @param parentId 父资源 ID
* @return 删除的数据条数
*/
public int deleteVariableByParentId(Long parentId) {
return taskVariableDAO.deleteVariableByParentId(parentId);
}

/**
* 根据变量 ID 拉取变量信息
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ public class TaskPlanServiceImpl implements TaskPlanService {
private final TaskPlanDAO taskPlanDAO;
private final MessageI18nService i18nService;
private final CronJobService cronJobService;
private AbstractTaskStepService taskPlanStepService;
private AbstractTaskVariableService taskPlanVariableService;
private final AbstractTaskStepService taskPlanStepService;
private final AbstractTaskVariableService taskTemplateVariableService;
private final AbstractTaskVariableService taskPlanVariableService;

@Autowired
private TaskTemplateService taskTemplateService;
Expand All @@ -92,11 +93,13 @@ public class TaskPlanServiceImpl implements TaskPlanService {
public TaskPlanServiceImpl(
TaskPlanDAO taskPlanDAO,
@Qualifier("TaskPlanStepServiceImpl") AbstractTaskStepService taskPlanStepService,
@Qualifier("TaskTemplateVariableServiceImpl") AbstractTaskVariableService taskTemplateVariableService,
@Qualifier("TaskPlanVariableServiceImpl") AbstractTaskVariableService taskPlanVariableService,
MessageI18nService i18nService, CronJobService cronJobService
) {
this.taskPlanDAO = taskPlanDAO;
this.taskPlanStepService = taskPlanStepService;
this.taskTemplateVariableService = taskTemplateVariableService;
this.taskPlanVariableService = taskPlanVariableService;
this.i18nService = i18nService;
this.cronJobService = cronJobService;
Expand Down Expand Up @@ -296,9 +299,22 @@ public TaskPlanInfoDTO getDebugTaskPlan(String username, Long appId, Long templa
}
if (taskPlan != null) {
if (!taskTemplateInfo.getVersion().equals(taskPlan.getVersion())) {
// 作业模板有更新,需要同步到调试执行方案(不含变量)
taskPlanService.sync(appId, templateId, taskPlan.getId(), taskTemplateInfo.getVersion());
taskPlan = taskPlanDAO.getDebugTaskPlan(appId, templateId);
}
List<TaskVariableDTO> templateVariableList =
taskTemplateVariableService.listVariablesByParentId(taskPlan.getTemplateId());
// 始终使用模板最新变量作为执行方案变量并更新到DB
setPlanIdForVariables(taskPlan.getId(), templateVariableList);
int deletedVarNum = taskPlanVariableService.deleteVariableByParentId(taskPlan.getId());
List<Long> insertedVarIds = taskPlanVariableService.batchInsertVariable(templateVariableList);
log.debug(
"sync template variable to debug plan:{} taskPlan variable deleted, {} variable inserted:{}",
deletedVarNum,
insertedVarIds.size(),
insertedVarIds
);
taskPlan.setStepList(taskPlanStepService.listStepsByParentId(taskPlan.getId()));
taskPlan.setVariableList(taskPlanVariableService.listVariablesByParentId(taskPlan.getId()));
return taskPlan;
Expand Down Expand Up @@ -330,6 +346,13 @@ public TaskPlanInfoDTO getDebugTaskPlan(String username, Long appId, Long templa
return taskPlan;
}

private void setPlanIdForVariables(Long planId, List<TaskVariableDTO> variableList) {
if (CollectionUtils.isEmpty(variableList)) {
return;
}
variableList.forEach(variable -> variable.setPlanId(planId));
}

@Override
public List<TaskPlanInfoDTO> listPlanBasicInfoByIds(Long appId, List<Long> planIdList) {
List<TaskPlanInfoDTO> taskPlanInfoList = taskPlanDAO.listTaskPlanByIds(
Expand Down