refactor: 新建流程加入busynesskey=批次---规格

新建流程加入busynesskey=批次---规格
查询流程时用busynesskey
办公管理/全部流程修改完毕
This commit is contained in:
tiezx 2025-05-10 20:48:03 +08:00
parent 0316d84358
commit 4abd0682a9
5 changed files with 128 additions and 64 deletions

View File

@ -78,5 +78,19 @@ public class ProcessConstants {
*/
public static final String FLOWABLE_SKIP_EXPRESSION_ENABLED = "_FLOWABLE_SKIP_EXPRESSION_ENABLED";
/**
* 自定义属性 批次
*/
public static final String PROCESS_BATCH = "lbl_Batch";
/**
* 自定义属性 规格名称
*/
public static final String PROCESS_SPEC_NAME = "lbl_name";
/**
* 自定义属性 生成Busynesskey时需要将批次与格名称连接起来这外作为连接字符
*/
public static final String PROCESS_BUSYNESSKEY_ConnString = "---";
}

View File

@ -99,6 +99,8 @@ public class ProcessUtils {
*/
public static void buildHistoricProcessInstanceSearch(HistoricProcessInstanceQuery query, ProcessQuery process) {
Map<String, Object> params = process.getParams();
/*
// 流程标识
if (StringUtils.isNotBlank(process.getProcessKey())) {
query.processDefinitionKey(process.getProcessKey());
@ -107,7 +109,26 @@ public class ProcessUtils {
if (StringUtils.isNotBlank(process.getProcessName())) {
query.processDefinitionName(process.getProcessName());
}
// 流程名称
*/
String sKey = null;
//批次
if (StringUtils.isNotBlank(process.getSpecBatch())) {
sKey = "%" + process.getSpecBatch();
}
//规格名称
if (StringUtils.isNotBlank(process.getSpecName())) {
if(sKey == null){
sKey = "%" + process.getSpecName() + "%";
}else{
sKey += "%" + process.getSpecName() + "%";
}
}
if(sKey != null) {
query.processInstanceBusinessKeyLike(sKey);
}
// 流程类别
if (StringUtils.isNotBlank(process.getCategory())) {
query.processDefinitionCategory(process.getCategory());
}
@ -119,7 +140,6 @@ 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() + "%");

View File

@ -138,5 +138,4 @@ public class WfTaskVo implements Serializable {
* 规格名称
*/
private String specName;
}

View File

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

View File

@ -171,7 +171,21 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
List<WfTaskVo> taskVoList = new ArrayList<>();
for (HistoricProcessInstance hisIns : historicProcessInstances) {
WfTaskVo taskVo = new WfTaskVo();
// 获取流程 Variables , 为了方便查询将其放入 Map
List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(hisIns.getId())
.list();
Map<String, Object> variablesMap = new HashMap<>();
for (HistoricVariableInstance hvi : historicVariableInstances) {
variablesMap.put(hvi.getVariableName(), hvi.getValue());
}
// 获取流程状态
Object var1Value = variablesMap.get(ProcessConstants.PROCESS_STATUS_KEY);
String processStatus = Convert.toStr(var1Value);
/*
HistoricVariableInstance processStatusVariable = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(hisIns.getId())
.variableName(ProcessConstants.PROCESS_STATUS_KEY)
@ -180,6 +194,8 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
if (ObjectUtil.isNotNull(processStatusVariable)) {
processStatus = Convert.toStr(processStatusVariable.getValue());
}
*/
// 兼容旧流程
if (processStatus == null) {
processStatus = ObjectUtil.isNull(hisIns.getEndTime()) ? ProcessStatus.RUNNING.getStatus() : ProcessStatus.COMPLETED.getStatus();
@ -189,28 +205,13 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
taskVo.setFinishTime(hisIns.getEndTime());
taskVo.setProcInsId(hisIns.getId());
//add for test --tzx
Object var2Value = variablesMap.get(ProcessConstants.PROCESS_BATCH ); //批次
String specBatch = Convert.toStr(var2Value);
taskVo.setSpecBatch(specBatch);
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
Object var3Value = variablesMap.get(ProcessConstants.PROCESS_SPEC_NAME); // 规格名称
String specName = Convert.toStr(var3Value);
taskVo.setSpecName(specName);
// 计算耗时
if (Objects.nonNull(hisIns.getEndTime())) {
@ -733,7 +734,12 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
try {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionId(procDefId).singleResult();
startProcess(processDefinition, variables);
// 启动流程实例并设置流程实例的 Business_key,后续就可以用 Business_key 来检索所需要的流程实例了
String procBusynessKey = getBusynessKey(variables);
startProcess(processDefinition, variables,procBusynessKey);
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException("流程启动错误");
@ -751,13 +757,29 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
try {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey(procDefKey).latestVersion().singleResult();
startProcess(processDefinition, variables);
// 启动流程实例并设置流程实例的名称
String procBusynessKey = getBusynessKey(variables);
startProcess(processDefinition, variables,procBusynessKey);
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException("流程启动错误");
}
}
/**
* 从流程变量生成 BusynessKey
* @param variables 流程的变量
*/
String getBusynessKey(Map<String, Object> variables){
String batch = Convert.toStr(variables.get(ProcessConstants.PROCESS_BATCH));
String name = Convert.toStr(variables.get(ProcessConstants.PROCESS_SPEC_NAME));
String procBusynessKey = batch + ProcessConstants.PROCESS_BUSYNESSKEY_ConnString + name;
return procBusynessKey;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteProcessByIds(String[] instanceIds) {
@ -827,7 +849,7 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
/**
* 启动流程实例
*/
private void startProcess(ProcessDefinition procDef, Map<String, Object> variables) {
private void startProcess(ProcessDefinition procDef, Map<String, Object> variables,String procName) {
if (ObjectUtil.isNotNull(procDef) && procDef.isSuspended()) {
throw new ServiceException("流程已被挂起,请先激活流程");
}
@ -838,7 +860,7 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
// 设置流程状态为进行中
variables.put(ProcessConstants.PROCESS_STATUS_KEY, ProcessStatus.RUNNING.getStatus());
// 发起流程实例
ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDef.getId(), variables);
ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDef.getId(),procName, variables);
// 第一个用户任务为发起人则自动完成任务
wfTaskService.startFirstTask(processInstance, variables);
}
@ -1157,38 +1179,47 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
Page<WfTaskVo> page = new Page<>();
HistoricVariableInstanceQuery historicVariableInstanceQuery = historyService.createHistoricVariableInstanceQuery()
.orderByVariableName()
.orderByProcessInstanceId()
.desc();
// 构建搜索条件
//processQuery.setSpecBatch("4");
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<>();
HashSet<HistoricProcessInstance> historicProcessInstances = new HashSet<HistoricProcessInstance>();
for (HistoricVariableInstance hisVarIns : historicVariableInstance) {
WfTaskVo taskVo = new WfTaskVo();
// 获取流程实例
HistoricProcessInstance hisIns = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(hisVarIns.getProcessInstanceId())
.includeProcessVariables()
.singleResult();
historicProcessInstances.add(hisIns);
}
page.setTotal(historicProcessInstances.size());
List<WfTaskVo> taskVoList = new ArrayList<>();
for (HistoricProcessInstance hisIns : historicProcessInstances) {
WfTaskVo taskVo = new WfTaskVo();
// 获取流程实例
List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(hisIns.getProcessDefinitionId())
.list();
Map<String, Object> variablesMap = new HashMap<>();
for (HistoricVariableInstance hvi : historicVariableInstances) {
variablesMap.put(hvi.getVariableName(), hvi.getValue());
}
// 获取流程状态
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());
}
Object var1Value = variablesMap.get(ProcessConstants.PROCESS_STATUS_KEY);
String processStatus = Convert.toStr(var1Value);
// 兼容旧流程
if (processStatus == null) {
processStatus = ObjectUtil.isNull(hisIns.getEndTime()) ? ProcessStatus.RUNNING.getStatus() : ProcessStatus.COMPLETED.getStatus();
@ -1198,28 +1229,22 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
taskVo.setFinishTime(hisIns.getEndTime());
taskVo.setProcInsId(hisIns.getId());
//add for test --tzx
Object var2Value = variablesMap.get("lbl_Batch");
String specBatch = Convert.toStr(var2Value);
taskVo.setSpecBatch(specBatch);
HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery();
historicTaskInstanceQuery.taskVariableNotExists("lbl_Batch");
historicTaskInstanceQuery.processVariableValueEquals("lbl_Batch","333");
Object var3Value = variablesMap.get("lbl_name");
String specName = Convert.toStr(var3Value);
taskVo.setSpecBatch(specName);
List<HistoricVariableInstance> historicProcessInstances1 =
//HistoricVariableInstance processStatusVariable1 =
hisIns.getName();
hisIns.getProcessDefinitionName();
historyService.createHistoricVariableInstanceQuery()
//.processInstanceId(hisIns.getId())
.variableValueLike("lbl_Batch","%")
.list();
// String spec[] = new String[2];
// getHistSpecInfo(hisIns.getId(),spec);
// taskVo.setSpecBatch(spec[0]);
// taskVo.setSpecName(spec[1]);
//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())) {
@ -1242,6 +1267,13 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
}
taskVoList.add(taskVo);
}
Collections.sort(taskVoList, new Comparator<WfTaskVo>() {
@Override
public int compare(WfTaskVo o1, WfTaskVo o2) {
return o2.getCreateTime().compareTo(o1.getCreateTime());
}
});
page.setRecords(taskVoList);
return TableDataInfo.build(page);
}