!10 测试周期性发起接口,恢复jsonData定义,对周期性任务发起前做非空校验
Merge pull request !10 from new_new_new/feature/quartz-task-job
This commit is contained in:
+72
-9
@@ -2,6 +2,7 @@ package org.jeecg.modules.quartz.job;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.util.DateUtils;
|
import org.jeecg.common.util.DateUtils;
|
||||||
import org.jeecg.modules.extbpm.process.entity.ExtActProcessForm;
|
import org.jeecg.modules.extbpm.process.entity.ExtActProcessForm;
|
||||||
@@ -14,6 +15,7 @@ import org.jeecg.modules.tasktask.service.impl.TaskTaskServiceImpl;
|
|||||||
import org.quartz.*;
|
import org.quartz.*;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -39,20 +41,81 @@ public class TaskJob implements Job {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||||
|
log.info("--- 周期性遍历taskTask表开始 ---");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
LocalDateTime startDateTime = LocalDateTime.now();
|
||||||
|
|
||||||
log.info(" --- 周期性遍历taskTask表 --- ");
|
// 1. 查询建议:只查询必要的字段,避免 select *
|
||||||
LocalDateTime now = LocalDateTime.now();
|
List<TaskTask> executeTaskTaskList = taskTaskServiceImpl
|
||||||
List<TaskTask> executeTaskTaskList = taskTaskServiceImpl.lambdaQuery().eq(TaskTask::getBpmStatus, 1).eq(TaskTask::getTriggerType, FlowConstants.Strategy.RECURRING_ONLY).lt(TaskTask::getStartTime, now).list();
|
.lambdaQuery()
|
||||||
log.info(" --- 待发起流程为 --- " + executeTaskTaskList.toString());
|
.select(TaskTask::getId, TaskTask::getFlowCode, TaskTask::getJsonData,
|
||||||
for (TaskTask executeTaskTask : executeTaskTaskList) {
|
TaskTask::getFormUrl, TaskTask::getCreateBy)
|
||||||
|
.eq(TaskTask::getBpmStatus, 1)
|
||||||
|
.eq(TaskTask::getTriggerType, FlowConstants.Strategy.RECURRING_ONLY)
|
||||||
|
.lt(TaskTask::getStartTime, startDateTime)
|
||||||
|
.list();
|
||||||
|
|
||||||
|
// 2. 集合判空实践
|
||||||
|
if (CollectionUtils.isEmpty(executeTaskTaskList)) {
|
||||||
|
log.info("--- 无待处理任务,结束执行 ---");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("--- 待发起流程数量: {} ---", executeTaskTaskList.size());
|
||||||
|
|
||||||
|
for (TaskTask task : executeTaskTaskList) {
|
||||||
try {
|
try {
|
||||||
|
// 3. 关键字段校验
|
||||||
|
if(isAnyBlank(task)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
bpmBaseExtApiImpl.startMutilProcess(executeTaskTask.getFlowCode(), executeTaskTask.getId(), executeTaskTask.getFormUrl(), executeTaskTask.getFormUrl(), executeTaskTask.getCreateBy(), JSON.toJSONString(executeTaskTask.getJsonData()));
|
String jsonData = task.getJsonData() != null ? JSON.toJSONString(task.getJsonData()) : "{}";
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
// 4. 执行业务逻辑
|
||||||
|
Result<String> res = bpmBaseExtApiImpl.startMutilProcess(
|
||||||
|
task.getFlowCode(),
|
||||||
|
task.getId(),
|
||||||
|
task.getFormUrl(),
|
||||||
|
task.getFormUrl(),
|
||||||
|
task.getCreateBy(),
|
||||||
|
jsonData
|
||||||
|
);
|
||||||
|
if (res == null || !res.isSuccess()) {
|
||||||
|
log.error("任务ID: {} 发起流程失败,失败原因:{}", task.getId(),
|
||||||
|
res == null ? "返回结果为空" : res.getMessage());
|
||||||
|
} else {
|
||||||
|
log.info("任务ID: {} 发起流程成功", task.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Throwable e) {
|
||||||
|
// 兜底:防止极端异常
|
||||||
|
log.error("任务ID: {} 发起流程异常", task.getId(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info(" --- 执行完毕,时间:" + LocalDateTime.now() + "---");
|
long costTime = System.currentTimeMillis() - startTime;
|
||||||
|
log.info("--- 执行完毕,时间:{} 毫秒 ---", costTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isAnyBlank(TaskTask task) {
|
||||||
|
if (StringUtils.isBlank(task.getFlowCode())) {
|
||||||
|
log.warn("任务ID: {} 缺失 FlowCode,跳过", task.getId());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(task.getId())) {
|
||||||
|
log.warn("任务数据异常:ID为空,跳过");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(task.getFormUrl())) {
|
||||||
|
log.warn("任务ID: {} 缺失 FormUrl,跳过", task.getId());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(task.getCreateBy())) {
|
||||||
|
log.warn("任务ID: {} 缺失 CreateBy,跳过", task.getId());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// jsonData 如果允许为 {} 则不校验,若接口要求必须有内容则需校验
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -235,9 +235,8 @@ public class TaskTask implements Serializable {
|
|||||||
@Schema(description = "表单组件路径")
|
@Schema(description = "表单组件路径")
|
||||||
private java.lang.String formUrl;
|
private java.lang.String formUrl;
|
||||||
/**流程变量*/
|
/**流程变量*/
|
||||||
@Excel(name = "流程变量", width = 15)
|
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||||
@TableField(value = "json_data", typeHandler = FastjsonTypeHandler.class)
|
private Map<String, Object> jsonData;
|
||||||
private List<JSONObject> jsonData;
|
|
||||||
|
|
||||||
@Excel(name = "是否立即发起流程", width = 15)
|
@Excel(name = "是否立即发起流程", width = 15)
|
||||||
@Schema(description = "1立即发起且非周期性发起,2不立即发起但周期性发起,3立即发起且周期性发起")
|
@Schema(description = "1立即发起且非周期性发起,2不立即发起但周期性发起,3立即发起且周期性发起")
|
||||||
|
|||||||
Reference in New Issue
Block a user