Merge remote-tracking branch 'origin/master'
# Conflicts: # jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/tasktask/entity/TaskTask.java
This commit is contained in:
+72
-9
@@ -2,6 +2,7 @@ package org.jeecg.modules.quartz.job;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@@ -39,20 +41,81 @@ public class TaskJob implements Job {
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
log.info("--- 周期性遍历taskTask表开始 ---");
|
||||
long startTime = System.currentTimeMillis();
|
||||
LocalDateTime startDateTime = LocalDateTime.now();
|
||||
|
||||
log.info(" --- 周期性遍历taskTask表 --- ");
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
List<TaskTask> executeTaskTaskList = taskTaskServiceImpl.lambdaQuery().eq(TaskTask::getBpmStatus, 1).eq(TaskTask::getTriggerType, FlowConstants.Strategy.RECURRING_ONLY).lt(TaskTask::getStartTime, now).list();
|
||||
log.info(" --- 待发起流程为 --- " + executeTaskTaskList.toString());
|
||||
for (TaskTask executeTaskTask : executeTaskTaskList) {
|
||||
// 1. 查询建议:只查询必要的字段,避免 select *
|
||||
List<TaskTask> executeTaskTaskList = taskTaskServiceImpl
|
||||
.lambdaQuery()
|
||||
.select(TaskTask::getId, TaskTask::getFlowCode, TaskTask::getJsonData,
|
||||
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 {
|
||||
// 3. 关键字段校验
|
||||
if(isAnyBlank(task)){
|
||||
continue;
|
||||
}
|
||||
|
||||
bpmBaseExtApiImpl.startMutilProcess(executeTaskTask.getFlowCode(), executeTaskTask.getId(), executeTaskTask.getFormUrl(), executeTaskTask.getFormUrl(), executeTaskTask.getCreateBy(), JSON.toJSONString(executeTaskTask.getJsonData()));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
String jsonData = task.getJsonData() != null ? JSON.toJSONString(task.getJsonData()) : "{}";
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
@@ -10,8 +10,10 @@ import java.net.URLDecoder;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import liquibase.pro.packaged.E;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.system.query.QueryRuleEnum;
|
||||
@@ -37,6 +39,7 @@ import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
@@ -192,6 +195,17 @@ public class TaskTaskController extends JeecgController<TaskTask, ITaskTaskServi
|
||||
return Result.OK(taskTask);
|
||||
}
|
||||
|
||||
//@AutoLog(value = "事项任务计划表(发起流程)-通过id查询")
|
||||
@Operation(summary = "事项任务计划表(发起流程)-通过businessId查询")
|
||||
@GetMapping(value = "/queryByBusinessId")
|
||||
public Result<List<TaskTask>> queryByBusinessId(@RequestParam(name = "businessId", required = true) String businessId) throws Exception {
|
||||
List<TaskTask> taskTaskList = taskTaskService.getTaskTaskListByBusinessId(businessId);
|
||||
if (CollectionUtils.isEmpty(taskTaskList)) {
|
||||
return Result.error("未找到对应数据");
|
||||
}
|
||||
return Result.OK(taskTaskList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
|
||||
+2
-3
@@ -235,9 +235,8 @@ public class TaskTask implements Serializable {
|
||||
@Schema(description = "表单组件路径")
|
||||
private java.lang.String formUrl;
|
||||
/**流程变量*/
|
||||
@Excel(name = "流程变量", width = 15)
|
||||
@TableField(value = "json_data", typeHandler = JacksonTypeHandler.class)
|
||||
private Map<String,Object> jsonData;
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private Map<String, Object> jsonData;
|
||||
|
||||
@Excel(name = "是否立即发起流程", width = 15)
|
||||
@Schema(description = "1立即发起且非周期性发起,2不立即发起但周期性发起,3立即发起且周期性发起")
|
||||
|
||||
+3
@@ -4,6 +4,8 @@ import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.modules.tasktask.entity.TaskTask;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 事项任务计划表(发起流程)
|
||||
* @Author: jeecg-boot
|
||||
@@ -14,4 +16,5 @@ public interface ITaskTaskService extends IService<TaskTask> {
|
||||
boolean singleFlowStart(TaskTask taskTask,String userName) throws Exception;
|
||||
boolean multiFlowStart(TaskTask taskTask,String userName,Integer intervalType, Integer startCount) throws Exception;
|
||||
Result<?> handleFlowStart(TaskTask taskTask, String username, Integer intervalType, Integer startCount)throws Exception;
|
||||
List<TaskTask> getTaskTaskListByBusinessId(String businessId) throws Exception;
|
||||
}
|
||||
|
||||
+10
@@ -1,6 +1,7 @@
|
||||
package org.jeecg.modules.tasktask.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.util.Assert;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
@@ -121,4 +122,13 @@ public class TaskTaskServiceImpl extends ServiceImpl<TaskTaskMapper, TaskTask> i
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
public List<TaskTask> getTaskTaskListByBusinessId(String businessId) throws Exception{
|
||||
if (StringUtils.isBlank(businessId)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
LambdaQueryWrapper<TaskTask> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TaskTask::getBusinessId, businessId);
|
||||
// 2. 查询不到数据 → MP 本身会返回空集合,不是 null
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user