feat(ProcessInstance + ProcessDefinition): 流程实例新增批次参数和规格名称

This commit is contained in:
tiezx 2025-05-09 18:09:45 +08:00
parent 593468fb33
commit 0316d84358
9 changed files with 327 additions and 6 deletions

View File

@ -214,6 +214,14 @@ public class WfProcessController extends BaseController {
@PostMapping("/start/{processDefId}")
public R<Void> start(@PathVariable(value = "processDefId") String processDefId, @RequestBody Map<String, Object> variables) {
processService.startProcessByDefId(processDefId, variables);
// 获取所有流程变量
for (Map.Entry<String, Object> entry : variables.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
System.out.println("Key: " + key + ", Value: " + value);
}
return R.ok("流程启动成功");
}

View File

@ -51,7 +51,8 @@ spring:
# rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
# url: jdbc:mysql://localhost:3306/ry_flowable_plus?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
# url: jdbc:mysql://192.168.137.20:3306/ry_flowable_plus?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
url: jdbc:mysql://10.168.1.206:3306/ry_flowable_plus?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
# url: jdbc:mysql://10.168.1.206:3306/ry_flowable_plus?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
url: jdbc:mysql://120.26.251.154:8001/ry_flowable_plus?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
username: remote
password: Tieth@121308
# 从库数据源
@ -107,9 +108,11 @@ spring:
redis:
# 地址
# host: 192.168.137.20
host: 10.168.1.206
#host: 10.168.1.206
host: 120.26.251.154
# 端口默认为6379
port: 6379
#port: 6379
port: 8002
# 数据库索引
database: 10
# 密码(如没有密码请注释掉)

View File

@ -38,4 +38,15 @@ public class ProcessQuery {
* 请求参数
*/
private Map<String, Object> params = new HashMap<>();
/**
* 批次名称
*/
private String specBatch;
/**
* 规格名称
*/
private String specName;
}

View File

@ -9,6 +9,7 @@ import org.flowable.engine.history.HistoricProcessInstanceQuery;
import org.flowable.engine.repository.ProcessDefinitionQuery;
import org.flowable.task.api.TaskQuery;
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import org.flowable.variable.api.history.HistoricVariableInstanceQuery;
import java.util.Map;
@ -30,6 +31,10 @@ public class ProcessUtils {
} else if (query instanceof HistoricProcessInstanceQuery) {
buildHistoricProcessInstanceSearch((HistoricProcessInstanceQuery) query, process);
}
else if (query instanceof HistoricVariableInstanceQuery) {
buildHistoricVariableInstanceSearch((HistoricVariableInstanceQuery) query, process);
}
}
/**
@ -112,4 +117,18 @@ public class ProcessUtils {
}
}
public static void buildHistoricVariableInstanceSearch(HistoricVariableInstanceQuery query, ProcessQuery process) {
Map<String, Object> params = process.getParams();
// 规格批次
if (StringUtils.isNotBlank(process.getSpecBatch())) {
query.variableValueLike("lbl_Batch","%" + process.getSpecBatch() + "%");
}
// 规格名称
if (StringUtils.isNotBlank(process.getSpecName())) {
query.variableValueLike("lbl_name","%" + process.getSpecBatch() + "%");
}
}
}

View File

@ -129,4 +129,14 @@ public class WfTaskVo implements Serializable {
*/
private String processStatus;
/**
* 批次
*/
private String specBatch;
/**
* 规格名称
*/
private String specName;
}

View File

@ -13,6 +13,8 @@ import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* 发布规格事件监听类
*
@ -31,11 +33,20 @@ public class PublishSpecificationListener implements ExecutionListener {
@Override
public void notify(DelegateExecution delegateExecution) {
WfDetailVo wfDetailVo = processService.queryProcessDetail(delegateExecution.getProcessInstanceId(), delegateExecution.getId());
// 获取所有流程变量
Map<String, Object> allVariables = delegateExecution.getVariables();
for (Map.Entry<String, Object> entry : allVariables.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
System.out.println("Key: " + key + ", Value: " + value);
}
//WfDetailVo wfDetailVo = processService.queryProcessDetail(delegateExecution.getProcessInstanceId(), delegateExecution.getId());
SysNotice notice = new SysNotice();
notice.setNoticeTitle(BusinessConstants.NOTICE_TITLE);
notice.setNoticeType(NoticeType.DESIGN_PUBLISH.getType());
notice.setNoticeContent(JsonUtils.toJsonString(wfDetailVo.getProcessFormList()));
//notice.setNoticeContent(JsonUtils.toJsonString(wfDetailVo.getProcessFormList()));
log.info("参数详情:{}", delegateExecution.getProcessInstanceId());
log.info("插入通知内容:{}", notice);
noticeService.insertNotice(notice);
}

View File

@ -0,0 +1,52 @@
package net.ferrum.workflow.listener;
import cn.hutool.extra.spring.SpringUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.ferrum.common.constant.BusinessConstants;
import net.ferrum.common.enums.NoticeType;
import net.ferrum.flowable.utils.ProcessFormUtils;
import net.ferrum.system.domain.SysNotice;
import net.ferrum.system.service.ISysNoticeService;
import net.ferrum.workflow.service.IWfProcessService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.form.api.FormInfo;
import org.flowable.form.model.FormField;
import org.flowable.form.model.SimpleFormModel;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
* 发布规格事件监听类
*
* @author 26554
* @version 1.0.0
* @since 2025/2/18
*/
@Slf4j
@Component("TestListener")
@RequiredArgsConstructor
public class TestListener implements ExecutionListener {
private final IWfProcessService processService;
private final ISysNoticeService noticeService;
@Override
public void notify(DelegateExecution delegateExecution) {
//System.out.println("设定 lbl_Core_weight = 2");
//delegateExecution.setVariable("lbl_Core_weight", "2");
// 获取所有流程变量
Map<String, Object> allVariables = delegateExecution.getVariables();
for (Map.Entry<String, Object> entry : allVariables.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
System.out.println("Key: " + key + ", Value: " + value);
}
}
}

View File

@ -36,6 +36,7 @@ public interface IWfProcessService {
* @return TableDataInfo<WfTaskVo>
*/
TableDataInfo<WfTaskVo> selectPageAllProcessList(ProcessQuery processQuery, PageQuery pageQuery);
TableDataInfo<WfTaskVo> selectPageAllProcessList1(ProcessQuery processQuery, PageQuery pageQuery);
/**
* 查询我的流程列表

View File

@ -56,6 +56,7 @@ import org.flowable.task.api.TaskQuery;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import org.flowable.variable.api.history.HistoricVariableInstance;
import org.flowable.variable.api.history.HistoricVariableInstanceQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -188,6 +189,29 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
taskVo.setFinishTime(hisIns.getEndTime());
taskVo.setProcInsId(hisIns.getId());
//add for test --tzx
HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery();
historicTaskInstanceQuery.taskVariableNotExists("lbl_Batch");
historicTaskInstanceQuery.processVariableValueEquals("lbl_Batch","333");
List<HistoricVariableInstance> historicProcessInstances1 =
//HistoricVariableInstance processStatusVariable1 =
historyService.createHistoricVariableInstanceQuery()
//.processInstanceId(hisIns.getId())
.variableValueLike("lbl_Batch","%")
.list();
//String sTemp = Convert.toStr(processStatusVariable1.getValue());
String spec[] = new String[2];
getHistSpecInfo(hisIns.getId(),spec);
taskVo.setSpecBatch(spec[0]);
taskVo.setSpecName(spec[1]);
//add end for test --tzx
// 计算耗时
if (Objects.nonNull(hisIns.getEndTime())) {
taskVo.setDuration(DateUtils.getDatePoor(hisIns.getEndTime(), hisIns.getStartTime()));
@ -247,6 +271,14 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
taskVo.setFinishTime(hisIns.getEndTime());
taskVo.setProcInsId(hisIns.getId());
//add for test --tzx
String spec[] = new String[2];
getHistSpecInfo(hisIns.getId(),spec);
taskVo.setSpecBatch(spec[0]);
taskVo.setSpecName(spec[1]);
//add end for test --tzx
// 计算耗时
if (Objects.nonNull(hisIns.getEndTime())) {
taskVo.setDuration(DateUtils.getDatePoor(hisIns.getEndTime(), hisIns.getStartTime()));
@ -302,6 +334,15 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
taskVo.setProcDefName(hisIns.getProcessDefinitionName());
taskVo.setProcDefVersion(hisIns.getProcessDefinitionVersion());
taskVo.setCategory(deployment.getCategory());
//add for test --tzx
String spec[] = new String[2];
getHistSpecInfo(hisIns.getId(),spec);
taskVo.setSpecBatch(spec[0]);
taskVo.setSpecName(spec[1]);
//add end for test --tzx
// 当前所处流程
List<Task> taskList = taskService.createTaskQuery().processInstanceId(hisIns.getId()).includeIdentityLinks().list();
if (CollUtil.isNotEmpty(taskList)) {
@ -353,6 +394,14 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
flowTask.setStartUserId(userId);
flowTask.setStartUserName(nickName);
//add for test --tzx
String spec[] = new String[2];
getHistSpecInfo(task.getProcessInstanceId(),spec);
flowTask.setSpecBatch(spec[0]);
flowTask.setSpecName(spec[1]);
//add end for test --tzx
// 流程变量
flowTask.setProcVars(task.getProcessVariables());
@ -400,6 +449,14 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
taskVo.setStartUserId(userId);
taskVo.setStartUserName(nickName);
//add for test --tzx
String spec[] = new String[2];
getHistSpecInfo(task.getProcessInstanceId(),spec);
taskVo.setSpecBatch(spec[0]);
taskVo.setSpecName(spec[1]);
//add end for test --tzx
taskVoList.add(taskVo);
}
return taskVoList;
@ -446,6 +503,14 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
flowTask.setStartUserId(userId);
flowTask.setStartUserName(nickName);
//add for test --tzx
String spec[] = new String[2];
getHistSpecInfo(task.getProcessInstanceId(),spec);
flowTask.setSpecBatch(spec[0]);
flowTask.setSpecName(spec[1]);
//add end for test --tzx
flowList.add(flowTask);
}
page.setRecords(flowList);
@ -490,6 +555,14 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
flowTask.setStartUserId(userId);
flowTask.setStartUserName(nickName);
//add for test --tzx
String spec[] = new String[2];
getHistSpecInfo(task.getProcessInstanceId(),spec);
flowTask.setSpecBatch(spec[0]);
flowTask.setSpecName(spec[1]);
//add end for test --tzx
flowList.add(flowTask);
}
return flowList;
@ -543,6 +616,14 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
// 流程变量
flowTask.setProcVars(histTask.getProcessVariables());
//add for test --tzx
String spec[] = new String[2];
getHistSpecInfo(histTask.getId(),spec);
flowTask.setSpecBatch(spec[0]);
flowTask.setSpecName(spec[1]);
//add end for test --tzx
hisTaskList.add(flowTask);
}
page.setTotal(taskInstanceQuery.count());
@ -599,6 +680,14 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
// 流程变量
flowTask.setProcVars(histTask.getProcessVariables());
//add for test --tzx
String spec[] = new String[2];
getHistSpecInfo(histTask.getId(),spec);
flowTask.setSpecBatch(spec[0]);
flowTask.setSpecName(spec[1]);
//add end for test --tzx
hisTaskList.add(flowTask);
}
return hisTaskList;
@ -1040,4 +1129,121 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
Set<String> rejectedSet = FlowableUtils.dfsFindRejects(bpmnModel, unfinishedTaskSet, finishedSequenceFlowSet, finishedTaskSet);
return new WfViewerVo(finishedTaskSet, finishedSequenceFlowSet, unfinishedTaskSet, rejectedSet);
}
private void getHistSpecInfo(String processId, String spec[]){
spec[0] = "";
spec[1] = "";
List<HistoricVariableInstance> list = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(processId)
.list();
if (list != null && list.size() > 0) {
boolean flag1=false, flag2=false;
for (HistoricVariableInstance hvi : list) {
if ("lbl_Batch".equals(hvi.getVariableName())){
spec[0] = Convert.toStr(hvi.getValue());
flag1 = true;
}
if ("lbl_name".equals(hvi.getVariableName())){
spec[1] = Convert.toStr(hvi.getValue());
flag2 = true;
}
if(flag1 == true && flag2 == true){ break;}
}
}
}
@Override
public TableDataInfo<WfTaskVo> selectPageAllProcessList1(ProcessQuery processQuery, PageQuery pageQuery) {
Page<WfTaskVo> page = new Page<>();
HistoricVariableInstanceQuery historicVariableInstanceQuery = historyService.createHistoricVariableInstanceQuery()
.orderByVariableName()
.desc();
// 构建搜索条件
ProcessUtils.buildProcessSearch(historicVariableInstanceQuery, processQuery);
int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);
List<HistoricVariableInstance> historicVariableInstance = historicVariableInstanceQuery
.listPage(offset, pageQuery.getPageSize());
page.setTotal(historicVariableInstance.stream().count());
List<WfTaskVo> taskVoList = new ArrayList<>();
for (HistoricVariableInstance hisVarIns : historicVariableInstance) {
WfTaskVo taskVo = new WfTaskVo();
// 获取流程实例
HistoricProcessInstance hisIns = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(hisVarIns.getProcessInstanceId())
.includeProcessVariables()
.singleResult();
// 获取流程状态
HistoricVariableInstance processStatusVariable = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(hisVarIns.getProcessInstanceId())
.variableName(ProcessConstants.PROCESS_STATUS_KEY)
.singleResult();
hisVarIns.getProcessInstanceId();
String processStatus = null;
if (ObjectUtil.isNotNull(processStatusVariable)) {
processStatus = Convert.toStr(processStatusVariable.getValue());
}
// 兼容旧流程
if (processStatus == null) {
processStatus = ObjectUtil.isNull(hisIns.getEndTime()) ? ProcessStatus.RUNNING.getStatus() : ProcessStatus.COMPLETED.getStatus();
}
taskVo.setProcessStatus(processStatus);
taskVo.setCreateTime(hisIns.getStartTime());
taskVo.setFinishTime(hisIns.getEndTime());
taskVo.setProcInsId(hisIns.getId());
//add for test --tzx
HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery();
historicTaskInstanceQuery.taskVariableNotExists("lbl_Batch");
historicTaskInstanceQuery.processVariableValueEquals("lbl_Batch","333");
List<HistoricVariableInstance> historicProcessInstances1 =
//HistoricVariableInstance processStatusVariable1 =
historyService.createHistoricVariableInstanceQuery()
//.processInstanceId(hisIns.getId())
.variableValueLike("lbl_Batch","%")
.list();
//String sTemp = Convert.toStr(processStatusVariable1.getValue());
String spec[] = new String[2];
getHistSpecInfo(hisIns.getId(),spec);
taskVo.setSpecBatch(spec[0]);
taskVo.setSpecName(spec[1]);
//add end for test --tzx
// 计算耗时
if (Objects.nonNull(hisIns.getEndTime())) {
taskVo.setDuration(DateUtils.getDatePoor(hisIns.getEndTime(), hisIns.getStartTime()));
} else {
taskVo.setDuration(DateUtils.getDatePoor(DateUtils.getNowDate(), hisIns.getStartTime()));
}
// 流程部署实例信息
Deployment deployment = repositoryService.createDeploymentQuery()
.deploymentId(hisIns.getDeploymentId()).singleResult();
taskVo.setDeployId(hisIns.getDeploymentId());
taskVo.setProcDefId(hisIns.getProcessDefinitionId());
taskVo.setProcDefName(hisIns.getProcessDefinitionName());
taskVo.setProcDefVersion(hisIns.getProcessDefinitionVersion());
taskVo.setCategory(deployment.getCategory());
// 当前所处流程
List<Task> taskList = taskService.createTaskQuery().processInstanceId(hisIns.getId()).includeIdentityLinks().list();
if (CollUtil.isNotEmpty(taskList)) {
taskVo.setTaskName(taskList.stream().map(Task::getName).filter(StringUtils::isNotEmpty).collect(Collectors.joining(",")));
}
taskVoList.add(taskVo);
}
page.setRecords(taskVoList);
return TableDataInfo.build(page);
}
}