Commit d38fa189 by huangfusuper

参数包装

parent cf9123a9
......@@ -1338,8 +1338,10 @@ public class ApiFlowServiceImpl implements ApiFlowService {
if(CollectionUtil.isEmpty(publicParamMap)){
publicParamMap = new HashMap<>(8);
}
publicParamMap.put(PlaceholderEnum.DATE_PLACEHOLDER.getName(), repairTime);
publicParamMap.put(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName(), repairTime);
publicParamMap.put(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName(), DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
flowExtendedConfiguration.setPublicParam(JSON.toJSONString(publicParamMap));
waitingRecord.setExtendedConfiguration(JSON.toJSONString(flowExtendedConfiguration));
//需要按着时间先后来设置时间
......@@ -1423,22 +1425,6 @@ public class ApiFlowServiceImpl implements ApiFlowService {
}
String nowDateFormatPlaceholder = placeholder.get(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName());
if(StringUtils.isBlank(nowDateFormatPlaceholder)) {
nowDateFormatPlaceholder = "yyyyMMdd";
}
String nowDateFormatParam = param.get(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName());
if(StringUtils.isBlank(nowDateFormatPlaceholder)) {
nowDateFormatPlaceholder = "yyyyMMdd";
}
param.put(PlaceholderEnum.DATE_PLACEHOLDER.getName(), repairTime);
param.put(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName(), DateUtil.format(new Date(),nowDateFormatParam));
placeholder.put(PlaceholderEnum.DATE_PLACEHOLDER.getName(), repairTime);
placeholder.put(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName(), DateUtil.format(new Date(),nowDateFormatPlaceholder));
scriptParamAndPlaceholderDto.setParam(param);
scriptParamAndPlaceholderDto.setPlaceholder(placeholder);
WaitingTask waitingTaskCopy = new WaitingTask();
......
package com.byit.strategy.task;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.byit.annotations.MythRankOrder;
import com.byit.dto.executor.RunParamWrapped;
import com.byit.dto.executor.ScriptParamAndPlaceholderDto;
import com.byit.dto.plugin.FlowExtendedConfiguration;
import com.byit.enums.NodeTypeEnum;
import com.byit.enums.PlaceholderEnum;
import com.byit.enums.ScheduleTypeEnum;
import com.byit.mapper.RunRecordingMapper;
import com.byit.model.JobTaskSchedule;
import com.byit.model.RunRecording;
import com.byit.strategy.TaskRunTheLifeCycleCallback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.Map;
/**
* @author huangfu
*/
@Component
@Slf4j
@MythRankOrder(2)
public class MakeUpScriptTaskCallbackRunTheLifeCycleCallback implements TaskRunTheLifeCycleCallback {
public static final String SCRIPT = "SCRIPT";
private final RunRecordingMapper runRecordingService;
public MakeUpScriptTaskCallbackRunTheLifeCycleCallback(RunRecordingMapper runRecordingService) {
this.runRecordingService = runRecordingService;
}
/**
* 判断是否匹配类型
*
* @param jobTaskSchedule 任务对象
* @return 是否匹配本次的执行对象
*/
@Override
public boolean matchType(JobTaskSchedule jobTaskSchedule) {
String jobType = jobTaskSchedule.getJobType();
NodeTypeEnum typeByCode = NodeTypeEnum.getTypeByCode(jobType);
if (typeByCode == null) {
throw new RuntimeException(String.format("调度暂不支持此种类型的任务:%s", jobType));
}
//是否是脚本类型的
boolean isScript = typeByCode.getType().equals(SCRIPT);
//是否是重跑或者补批
boolean isNormal = ScheduleTypeEnum.REPEAT.getCode().equals(jobTaskSchedule.getScheduleType()) || ScheduleTypeEnum.REPAIR.getCode().equals(jobTaskSchedule.getScheduleType());
return isScript && isNormal;
}
/**
* 实例执行前
*
* @param jobTaskSchedule 任务对象
*/
@Override
public void postProcessAfterInitialization(JobTaskSchedule jobTaskSchedule) {
String runId = jobTaskSchedule.getRunId();
String flowName = jobTaskSchedule.getFlowName();
RunRecording runRecording = runRecordingService.findAllByRunIDAndFlowName(runId, flowName);
String extendedConfiguration = runRecording.getExtendedConfiguration();
FlowExtendedConfiguration flowExtendedConfiguration = JSON.parseObject(extendedConfiguration, FlowExtendedConfiguration.class);
String publicParam = flowExtendedConfiguration.getPublicParam();
Map<String,String> publicParamMap = JSON.parseObject(publicParam, Map.class);
String runParam = jobTaskSchedule.getRunParam();
RunParamWrapped runParamWrapped = JSON.parseObject(runParam, RunParamWrapped.class);
String privateParam = runParamWrapped.getPrivateParam();
ScriptParamAndPlaceholderDto scriptParamAndPlaceholderDto = JSON.parseObject(privateParam, ScriptParamAndPlaceholderDto.class);
Map<String, String> param = scriptParamAndPlaceholderDto.getParam();
Map<String, String> placeholder = scriptParamAndPlaceholderDto.getPlaceholder();
String nowDateFormatPh = "yyyyMMdd";
String nowDateFormatPr = "yyyyMMdd";
if (param.containsKey(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName())) {
nowDateFormatPr = param.get(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName());
param.remove(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName());
}
if (placeholder.containsKey(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName())) {
nowDateFormatPh = param.get(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName());
placeholder.remove(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName());
}
//获取公共参数里面的biz_date
String bizDateStr = publicParamMap.get(PlaceholderEnum.DATE_PLACEHOLDER.getName());
param.put(PlaceholderEnum.DATE_PLACEHOLDER.getName(), bizDateStr);
placeholder.put(PlaceholderEnum.DATE_PLACEHOLDER.getName(), bizDateStr);
//生成 now_date
param.put(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName(), DateUtil.format(new Date(), nowDateFormatPr));
placeholder.put(PlaceholderEnum.NOW_DATE_PLACEHOLDER.getName(), DateUtil.format(new Date(), nowDateFormatPh));
//设置参数
scriptParamAndPlaceholderDto.setParam(param);
scriptParamAndPlaceholderDto.setPlaceholder(placeholder);
runParamWrapped.setPrivateParam(JSON.toJSONString(scriptParamAndPlaceholderDto));
jobTaskSchedule.setRunParam(JSON.toJSONString(runParamWrapped));
}
}
package com.byit.strategy.task;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.byit.annotations.MythRankOrder;
import com.byit.dto.executor.RunParamWrapped;
import com.byit.dto.executor.ScriptParamAndPlaceholderDto;
import com.byit.model.JobTaskSchedule;
import com.byit.strategy.TaskRunTheLifeCycleCallback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* 参数对象包装
*
......@@ -28,7 +33,26 @@ public class ParamWrappedCallback implements TaskRunTheLifeCycleCallback {
public void postProcessAfterInitialization(JobTaskSchedule jobTaskSchedule) {
String runParam = jobTaskSchedule.getRunParam();
RunParamWrapped runParamWrapped = new RunParamWrapped();
runParamWrapped.setPrivateParam(runParam);
runParamWrapped.setPublicParamMap(new HashMap<>(8));
ScriptParamAndPlaceholderDto scriptParamAndPlaceholderDto = JSON.parseObject(runParam, ScriptParamAndPlaceholderDto.class);
if(scriptParamAndPlaceholderDto == null) {
scriptParamAndPlaceholderDto = new ScriptParamAndPlaceholderDto();
}
Map<String, String> placeholder = scriptParamAndPlaceholderDto.getPlaceholder();
Map<String, String> param = scriptParamAndPlaceholderDto.getParam();
if(CollectionUtil.isEmpty(placeholder)){
placeholder = new HashMap<>(8);
}
if(CollectionUtil.isEmpty(param)){
param = new HashMap<>(8);
}
scriptParamAndPlaceholderDto.setPlaceholder(placeholder);
scriptParamAndPlaceholderDto.setParam(param);
runParamWrapped.setPrivateParam(JSON.toJSONString(scriptParamAndPlaceholderDto));
jobTaskSchedule.setRunParam(JSON.toJSONString(runParamWrapped));
}
......
......@@ -30,7 +30,7 @@ import java.util.Map;
*/
@Component
@Slf4j
@MythRankOrder(2)
@MythRankOrder(3)
public class ScriptSpecialParametersTaskRunTheLifeCycleCallback implements TaskRunTheLifeCycleCallback {
/**
* 脚本类型的数据
......
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