feat(workflow): 添加工作流强制终止和自定义步骤功能
- 新增状态码998用于强制终止工作流 - 实现handleForceTerminate方法处理强制终止逻辑 - 添加other特殊步骤类型支持自定义参数 - 实现handleOtherStep方法处理自定义步骤参数保存 - 扩展TaskLogE、TaskFlowE等实体类支持otherParams和componentName字段 - 优化canProceedToNext方法移除冗余注释和特殊步骤检查逻辑 - 更新数据传输对象添加相关字段映射 - 修复nextStep方法参数传递问题master
parent
b1e94239d7
commit
3b772a7628
|
|
@ -99,11 +99,20 @@ public class TaskLogUpdateExe {
|
||||||
*
|
*
|
||||||
* @param cmd 步骤流转命令
|
* @param cmd 步骤流转命令
|
||||||
*/
|
*/
|
||||||
|
/** 强制终止状态码 */
|
||||||
|
private static final Integer FORCE_TERMINATE_STATUS = 998;
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void nextStep(TaskLogNextCmd cmd) {
|
public void nextStep(TaskLogNextCmd cmd) {
|
||||||
log.info("开始处理步骤流转: workId={}, stepId={}, status={}",
|
log.info("开始处理步骤流转: workId={}, stepId={}, status={}",
|
||||||
cmd.getWorkId(), cmd.getStepId(), cmd.getStatus());
|
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<TaskLogE> logs = taskLogGateway.listAllByWorkId(cmd.getWorkId());
|
||||||
List<TaskLogDO> actionLogs = new ArrayList<>();
|
List<TaskLogDO> actionLogs = new ArrayList<>();
|
||||||
|
|
||||||
|
|
@ -201,7 +210,7 @@ public class TaskLogUpdateExe {
|
||||||
* - 检查特殊步骤是否允许流转
|
* - 检查特殊步骤是否允许流转
|
||||||
*/
|
*/
|
||||||
private boolean canProceedToNext(TaskLogE currentLog, List<TaskLogE> logs, TaskLogNextCmd cmd) {
|
private boolean canProceedToNext(TaskLogE currentLog, List<TaskLogE> logs, TaskLogNextCmd cmd) {
|
||||||
// 1. 多人签字步骤:需要所有人都签字
|
// 多人签字步骤:需要所有人都签字
|
||||||
if (MULTIPLE_FLAG.equals(currentLog.getMultipleFlag())) {
|
if (MULTIPLE_FLAG.equals(currentLog.getMultipleFlag())) {
|
||||||
long pendingSigns = logs.stream()
|
long pendingSigns = logs.stream()
|
||||||
.filter(log -> log.getStepId().equals(currentLog.getStepId())
|
.filter(log -> log.getStepId().equals(currentLog.getStepId())
|
||||||
|
|
@ -215,11 +224,6 @@ public class TaskLogUpdateExe {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 检查是否为特殊步骤
|
|
||||||
if (StringUtils.isNotBlank(currentLog.getSpecialStepCode())) {
|
|
||||||
// 特殊步骤的流转判断在 handleSpecialStepIfNeeded 中处理
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -228,6 +232,7 @@ public class TaskLogUpdateExe {
|
||||||
* - delay: 延时监火转交
|
* - delay: 延时监火转交
|
||||||
* - measures: 安全措施确认
|
* - measures: 安全措施确认
|
||||||
* - gas: 气体检测记录
|
* - gas: 气体检测记录
|
||||||
|
* - other: 其他自定义步骤
|
||||||
*
|
*
|
||||||
* @return 是否允许继续流转到下一步
|
* @return 是否允许继续流转到下一步
|
||||||
*/
|
*/
|
||||||
|
|
@ -247,6 +252,8 @@ public class TaskLogUpdateExe {
|
||||||
return handleMeasuresStep(currentLog, cmd, actionLogs);
|
return handleMeasuresStep(currentLog, cmd, actionLogs);
|
||||||
case "gas":
|
case "gas":
|
||||||
return handleGasDetectionStep(currentLog, cmd, actionLogs);
|
return handleGasDetectionStep(currentLog, cmd, actionLogs);
|
||||||
|
case "other":
|
||||||
|
return handleOtherStep(currentLog, cmd, actionLogs);
|
||||||
default:
|
default:
|
||||||
log.warn("未知的特殊步骤类型: {}", specialStepCode);
|
log.warn("未知的特殊步骤类型: {}", specialStepCode);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -344,6 +351,23 @@ public class TaskLogUpdateExe {
|
||||||
return false;
|
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 时,允许添加其他安全措施
|
* 当 steps.measuresStepFlag == 1 时,允许添加其他安全措施
|
||||||
|
|
@ -546,6 +570,51 @@ public class TaskLogUpdateExe {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理强制终止工作流
|
||||||
|
* status为998时强制结束,设置主表为998,剩余流程设为跳过(不发送待办)
|
||||||
|
*/
|
||||||
|
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) {
|
if (source.getCurrentFillTimes() != null) {
|
||||||
target.setCurrentFillTimes(source.getCurrentFillTimes());
|
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);
|
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);
|
infoJson.put("step_" + logDO.getStepId(), stepInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ public class TaskLogServiceImpl implements TaskLogServiceI {
|
||||||
TaskLogNextCmd taskLogNextCmd = new TaskLogNextCmd(commitTaskLogDO.getId(),
|
TaskLogNextCmd taskLogNextCmd = new TaskLogNextCmd(commitTaskLogDO.getId(),
|
||||||
commitTaskLogDO.getWorkId(),
|
commitTaskLogDO.getWorkId(),
|
||||||
commitTaskLogDO.getStepId(),
|
commitTaskLogDO.getStepId(),
|
||||||
TaskLogStatus.APPROVED.getCode(),null,null,null,cmd.getOthers());
|
TaskLogStatus.APPROVED.getCode(),null,null,null,cmd.getOthers(),null,null);
|
||||||
|
|
||||||
taskLogUpdateExe.nextStep(taskLogNextCmd);
|
taskLogUpdateExe.nextStep(taskLogNextCmd);
|
||||||
return SingleResponse.buildSuccess();
|
return SingleResponse.buildSuccess();
|
||||||
|
|
|
||||||
|
|
@ -86,4 +86,7 @@ public class TaskFlowCO extends ClientObject {
|
||||||
//持续步骤阻塞的步骤ID(必须填写足够次数后才能激活的步骤)
|
//持续步骤阻塞的步骤ID(必须填写足够次数后才能激活的步骤)
|
||||||
@ApiModelProperty(value = "持续步骤阻塞的步骤ID(必须填写足够次数后才能激活的步骤)")
|
@ApiModelProperty(value = "持续步骤阻塞的步骤ID(必须填写足够次数后才能激活的步骤)")
|
||||||
private Long blockingStepId;
|
private Long blockingStepId;
|
||||||
|
//手机端组件名称(special_step_code==other 时使用)
|
||||||
|
@ApiModelProperty(value = "手机端组件名称")
|
||||||
|
private String componentName;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,9 @@ public class TaskLogCO extends ClientObject {
|
||||||
//经度
|
//经度
|
||||||
@ApiModelProperty(value = "经度")
|
@ApiModelProperty(value = "经度")
|
||||||
private String longitude;
|
private String longitude;
|
||||||
|
//其他参数(special_step_code==other 时使用)
|
||||||
|
@ApiModelProperty(value = "其他参数")
|
||||||
|
private String otherParams;
|
||||||
|
|
||||||
@ApiModelProperty(value = "当前步骤需设置的签字人")
|
@ApiModelProperty(value = "当前步骤需设置的签字人")
|
||||||
List<TaskLogCO> settingSignSteps;
|
List<TaskLogCO> settingSignSteps;
|
||||||
|
|
|
||||||
|
|
@ -64,5 +64,7 @@ public class TaskFlowE extends BaseE {
|
||||||
private Integer minFillTimes;
|
private Integer minFillTimes;
|
||||||
//持续步骤阻塞的步骤ID(必须填写足够次数后才能激活的步骤)
|
//持续步骤阻塞的步骤ID(必须填写足够次数后才能激活的步骤)
|
||||||
private Long blockingStepId;
|
private Long blockingStepId;
|
||||||
|
//手机端组件名称(special_step_code==other 时使用)
|
||||||
|
private String componentName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,8 @@ public class TaskLogE extends BaseE {
|
||||||
private String latitude;
|
private String latitude;
|
||||||
//经度
|
//经度
|
||||||
private String longitude;
|
private String longitude;
|
||||||
|
//其他参数(special_step_code==other 时使用)
|
||||||
|
private String otherParams;
|
||||||
|
|
||||||
public TaskLogE(TaskLogE log) {
|
public TaskLogE(TaskLogE log) {
|
||||||
this.taskLogId = log.getTaskLogId();
|
this.taskLogId = log.getTaskLogId();
|
||||||
|
|
@ -128,6 +130,7 @@ public class TaskLogE extends BaseE {
|
||||||
this.currentFillTimes = log.getCurrentFillTimes();
|
this.currentFillTimes = log.getCurrentFillTimes();
|
||||||
this.latitude = log.getLatitude();
|
this.latitude = log.getLatitude();
|
||||||
this.longitude = log.getLongitude();
|
this.longitude = log.getLongitude();
|
||||||
|
this.otherParams = log.getOtherParams();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,9 @@ public class TaskFlowDO extends BaseDO {
|
||||||
//持续步骤阻塞的步骤ID(必须填写足够次数后才能激活的步骤)
|
//持续步骤阻塞的步骤ID(必须填写足够次数后才能激活的步骤)
|
||||||
@ApiModelProperty(value = "持续步骤阻塞的步骤ID(必须填写足够次数后才能激活的步骤)")
|
@ApiModelProperty(value = "持续步骤阻塞的步骤ID(必须填写足够次数后才能激活的步骤)")
|
||||||
private Long blockingStepId;
|
private Long blockingStepId;
|
||||||
|
//手机端组件名称(special_step_code==other 时使用)
|
||||||
|
@ApiModelProperty(value = "手机端组件名称")
|
||||||
|
private String componentName;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,9 @@ public class TaskLogDO extends BaseDO {
|
||||||
//经度
|
//经度
|
||||||
@ApiModelProperty(value = "经度")
|
@ApiModelProperty(value = "经度")
|
||||||
private String longitude;
|
private String longitude;
|
||||||
|
//其他参数(special_step_code==other 时使用)
|
||||||
|
@ApiModelProperty(value = "其他参数")
|
||||||
|
private String otherParams;
|
||||||
|
|
||||||
public TaskLogDO(String taskLogId) {
|
public TaskLogDO(String taskLogId) {
|
||||||
this.taskLogId = taskLogId;
|
this.taskLogId = taskLogId;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue