feat(workflow): 添加工作流强制终止和自定义步骤功能

- 新增状态码998用于强制终止工作流
- 实现handleForceTerminate方法处理强制终止逻辑
- 添加other特殊步骤类型支持自定义参数
- 实现handleOtherStep方法处理自定义步骤参数保存
- 扩展TaskLogE、TaskFlowE等实体类支持otherParams和componentName字段
- 优化canProceedToNext方法移除冗余注释和特殊步骤检查逻辑
- 更新数据传输对象添加相关字段映射
- 修复nextStep方法参数传递问题
master
fangjiakai 2026-03-20 11:14:35 +08:00
parent b1e94239d7
commit 3b772a7628
8 changed files with 113 additions and 7 deletions

View File

@ -99,11 +99,20 @@ public class TaskLogUpdateExe {
*
* @param cmd
*/
/** 强制终止状态码 */
private static final Integer FORCE_TERMINATE_STATUS = 998;
@Transactional(rollbackFor = Exception.class)
public void nextStep(TaskLogNextCmd cmd) {
log.info("开始处理步骤流转: workId={}, stepId={}, status={}",
cmd.getWorkId(), cmd.getStepId(), cmd.getStatus());
// 强制终止检查status为998时强制结束工作流
if (FORCE_TERMINATE_STATUS.equals(cmd.getStatus())) {
handleForceTerminate(cmd);
return;
}
List<TaskLogE> logs = taskLogGateway.listAllByWorkId(cmd.getWorkId());
List<TaskLogDO> actionLogs = new ArrayList<>();
@ -201,7 +210,7 @@ public class TaskLogUpdateExe {
* -
*/
private boolean canProceedToNext(TaskLogE currentLog, List<TaskLogE> logs, TaskLogNextCmd cmd) {
// 1. 多人签字步骤:需要所有人都签字
// 多人签字步骤:需要所有人都签字
if (MULTIPLE_FLAG.equals(currentLog.getMultipleFlag())) {
long pendingSigns = logs.stream()
.filter(log -> log.getStepId().equals(currentLog.getStepId())
@ -215,11 +224,6 @@ public class TaskLogUpdateExe {
}
}
// 2. 检查是否为特殊步骤
if (StringUtils.isNotBlank(currentLog.getSpecialStepCode())) {
// 特殊步骤的流转判断在 handleSpecialStepIfNeeded 中处理
}
return true;
}
@ -228,6 +232,7 @@ public class TaskLogUpdateExe {
* - delay:
* - measures:
* - gas:
* - other:
*
* @return
*/
@ -247,6 +252,8 @@ public class TaskLogUpdateExe {
return handleMeasuresStep(currentLog, cmd, actionLogs);
case "gas":
return handleGasDetectionStep(currentLog, cmd, actionLogs);
case "other":
return handleOtherStep(currentLog, cmd, actionLogs);
default:
log.warn("未知的特殊步骤类型: {}", specialStepCode);
return true;
@ -344,6 +351,23 @@ public class TaskLogUpdateExe {
return false;
}
/**
*
* otherParams task_log info
*/
private boolean handleOtherStep(TaskLogE currentLog, TaskLogNextCmd cmd, List<TaskLogDO> actionLogs) {
log.info("处理其他自定义步骤");
if (cmd.getOthers() != null && cmd.getOthers().containsKey("otherParams")) {
String otherParams = cmd.getOthers().getString("otherParams");
currentLog.setOtherParams(otherParams);
addActionLog(actionLogs, currentLog);
log.info("自定义参数已保存: otherParams={}", otherParams);
}
return true;
}
/**
*
* steps.measuresStepFlag == 1
@ -546,6 +570,51 @@ public class TaskLogUpdateExe {
);
}
/**
*
* status998998
*/
private void handleForceTerminate(TaskLogNextCmd cmd) {
log.info("强制终止工作流: workId={}, stepId={}", cmd.getWorkId(), cmd.getStepId());
List<TaskLogE> allLogs = taskLogGateway.listAllByWorkId(cmd.getWorkId());
List<TaskLogDO> actionLogs = new ArrayList<>();
// 查找当前步骤并标记为已通过
TaskLogE currentLog = findCurrentLog(allLogs, cmd.getId());
if (currentLog != null) {
currentLog.setStatus(TaskLogStatus.APPROVED.getCode());
if (SIGN_STEP_FLAG.equals(currentLog.getSignStepFlag())) {
currentLog.setSignPath(cmd.getSignPath());
}
addActionLog(actionLogs, currentLog);
sendTodoCompleteEvent(currentLog.getId());
}
// 将所有未开始的步骤设置为跳过状态
for (TaskLogE log : allLogs) {
if (TaskLogStatus.NOT_STARTED.equalsCode(log.getStatus())) {
log.setStatus(TaskLogStatus.SKIPPED.getCode());
addActionLog(actionLogs, log);
}
}
// 批量更新 task_log
taskLogRepository.updateBatchById(actionLogs);
// 更新 eightworkInfo.info只更新本次变化的步骤
updateEightworkInfo(cmd.getWorkId(), actionLogs);
// 更新主表状态为998
eightworkInfoRepository.updateWorkStatus(
cmd.getWorkId(),
"已强制终止",
FORCE_TERMINATE_STATUS
);
log.info("工作流已强制终止: workId={}, skippedSteps={}", cmd.getWorkId(), actionLogs.size() - 1);
}
/**
*
*
@ -717,6 +786,15 @@ public class TaskLogUpdateExe {
if (source.getCurrentFillTimes() != null) {
target.setCurrentFillTimes(source.getCurrentFillTimes());
}
if (source.getOtherParams() != null) {
target.setOtherParams(source.getOtherParams());
}
if (source.getLatitude() != null) {
target.setLatitude(source.getLatitude());
}
if (source.getLongitude() != null) {
target.setLongitude(source.getLongitude());
}
}
/**
@ -771,6 +849,17 @@ public class TaskLogUpdateExe {
stepInfo.put("location", location);
}
// 其他自定义步骤,添加 otherParams
if (StringUtils.isNotBlank(logDO.getOtherParams())) {
try {
JSONObject otherParams = JSONObject.parseObject(logDO.getOtherParams());
stepInfo.put("otherParams", otherParams);
} catch (Exception e) {
// 如果不是JSON格式直接存储字符串
stepInfo.put("otherParams", logDO.getOtherParams());
}
}
infoJson.put("step_" + logDO.getStepId(), stepInfo);
}

View File

@ -55,7 +55,7 @@ public class TaskLogServiceImpl implements TaskLogServiceI {
TaskLogNextCmd taskLogNextCmd = new TaskLogNextCmd(commitTaskLogDO.getId(),
commitTaskLogDO.getWorkId(),
commitTaskLogDO.getStepId(),
TaskLogStatus.APPROVED.getCode(),null,null,null,cmd.getOthers());
TaskLogStatus.APPROVED.getCode(),null,null,null,cmd.getOthers(),null,null);
taskLogUpdateExe.nextStep(taskLogNextCmd);
return SingleResponse.buildSuccess();

View File

@ -86,4 +86,7 @@ public class TaskFlowCO extends ClientObject {
//持续步骤阻塞的步骤ID必须填写足够次数后才能激活的步骤
@ApiModelProperty(value = "持续步骤阻塞的步骤ID必须填写足够次数后才能激活的步骤")
private Long blockingStepId;
//手机端组件名称special_step_code==other 时使用)
@ApiModelProperty(value = "手机端组件名称")
private String componentName;
}

View File

@ -136,6 +136,9 @@ public class TaskLogCO extends ClientObject {
//经度
@ApiModelProperty(value = "经度")
private String longitude;
//其他参数special_step_code==other 时使用)
@ApiModelProperty(value = "其他参数")
private String otherParams;
@ApiModelProperty(value = "当前步骤需设置的签字人")
List<TaskLogCO> settingSignSteps;

View File

@ -64,5 +64,7 @@ public class TaskFlowE extends BaseE {
private Integer minFillTimes;
//持续步骤阻塞的步骤ID必须填写足够次数后才能激活的步骤
private Long blockingStepId;
//手机端组件名称special_step_code==other 时使用)
private String componentName;
}

View File

@ -93,6 +93,8 @@ public class TaskLogE extends BaseE {
private String latitude;
//经度
private String longitude;
//其他参数special_step_code==other 时使用)
private String otherParams;
public TaskLogE(TaskLogE log) {
this.taskLogId = log.getTaskLogId();
@ -128,6 +130,7 @@ public class TaskLogE extends BaseE {
this.currentFillTimes = log.getCurrentFillTimes();
this.latitude = log.getLatitude();
this.longitude = log.getLongitude();
this.otherParams = log.getOtherParams();
}

View File

@ -89,6 +89,9 @@ public class TaskFlowDO extends BaseDO {
//持续步骤阻塞的步骤ID必须填写足够次数后才能激活的步骤
@ApiModelProperty(value = "持续步骤阻塞的步骤ID必须填写足够次数后才能激活的步骤")
private Long blockingStepId;
//手机端组件名称special_step_code==other 时使用)
@ApiModelProperty(value = "手机端组件名称")
private String componentName;
}

View File

@ -134,6 +134,9 @@ public class TaskLogDO extends BaseDO {
//经度
@ApiModelProperty(value = "经度")
private String longitude;
//其他参数special_step_code==other 时使用)
@ApiModelProperty(value = "其他参数")
private String otherParams;
public TaskLogDO(String taskLogId) {
this.taskLogId = taskLogId;