feat(REQ-4624) - 调整获取模版文档的内部逻辑

This commit is contained in:
wangli 2025-08-08 18:05:13 +08:00
parent 28c6c6031c
commit 75858d7aea

View File

@ -6,21 +6,26 @@ import cn.axzo.workflow.common.model.dto.TermNodePausingDTO;
import cn.axzo.workflow.core.common.utils.SpringContextUtils;
import cn.axzo.workflow.core.conf.SupportRefreshProperties;
import cn.axzo.workflow.core.listener.Alter;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.ManagementService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.job.service.JobHandler;
import org.flowable.job.service.TimerJobService;
import org.flowable.job.service.impl.persistence.entity.JobEntity;
import org.flowable.job.service.impl.persistence.entity.TimerJobEntity;
import org.flowable.task.api.Task;
import org.flowable.variable.api.delegate.VariableScope;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.Date;
import java.util.List;
import static cn.axzo.workflow.common.constant.BpmnConstants.BIZ_NODE_ALTER;
@ -71,7 +76,23 @@ public class AsyncTermNodeAlterJobHandler extends AbstractJobHandler implements
if (CollectionUtils.isEmpty(tasks) || tasks.size() > 1 || hasAssignee(tasks.get(0).getAssignee())) {
return;
}
if (DateUtil.compare(DateUtil.date(), DateUtil.offsetMinute(tasks.get(0).getCreateTime(), refreshProperties.getPauseDelay())) <= 0) {
if (DateUtil.compare(DateUtil.date(), getDateTime(tasks.get(0).getCreateTime())) <= 0) {
ManagementService managementService = processEngineConfiguration.getManagementService();
managementService.executeCommand(context -> {
TimerJobService timerJobService = CommandContextUtil.getTimerJobService();
TimerJobEntity timerJobEntity = timerJobService.createTimerJob();
timerJobEntity.setJobType("timer");
timerJobEntity.setJobHandlerType(AsyncTermNodeAlterJobHandler.TYPE); // 这里填写你自定义的 JobHandler 类型
timerJobEntity.setProcessInstanceId(dto.getProcessInstanceId());
timerJobEntity.setExecutionId(null);
timerJobEntity.setDuedate(getDateTime(new Date())); // 立即执行
timerJobEntity.setRepeat(null); // 不重复
timerJobEntity.setRetries(1);
timerJobEntity.setJobHandlerConfiguration(dto.getActivityId()); // 可选传递参数
timerJobService.scheduleTimerJob(timerJobEntity);
return null;
});
return;
}
@ -101,6 +122,22 @@ public class AsyncTermNodeAlterJobHandler extends AbstractJobHandler implements
}
}
private DateTime getDateTime(Date date) {
DateTime dateTime;
switch (refreshProperties.getAlterIntervalUnit()) {
case MINUTES:
dateTime = DateUtil.offsetMinute(date, refreshProperties.getPauseDelay());
break;
case HOURS:
dateTime = DateUtil.offsetHour(date, refreshProperties.getPauseDelay());
break;
default:
dateTime = DateUtil.offsetSecond(date, refreshProperties.getPauseDelay());
break;
}
return dateTime;
}
private void incRetries(JobEntity job, TermNodePausingDTO dto, RuntimeService runtimeService, String activityId) {
dto.setRetries(dto.getRetries() + 1);
runtimeService.setVariable(job.getProcessInstanceId(), BIZ_NODE_ALTER + activityId, dto);