refactor: 新建流程加入busynesskey=批次---规格
新建流程加入busynesskey=批次---规格 查询流程时用busynesskey 办公管理/全部流程修改完毕
This commit is contained in:
parent
0316d84358
commit
4abd0682a9
@ -78,5 +78,19 @@ public class ProcessConstants {
|
|||||||
*/
|
*/
|
||||||
public static final String FLOWABLE_SKIP_EXPRESSION_ENABLED = "_FLOWABLE_SKIP_EXPRESSION_ENABLED";
|
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 = "---";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -99,6 +99,8 @@ public class ProcessUtils {
|
|||||||
*/
|
*/
|
||||||
public static void buildHistoricProcessInstanceSearch(HistoricProcessInstanceQuery query, ProcessQuery process) {
|
public static void buildHistoricProcessInstanceSearch(HistoricProcessInstanceQuery query, ProcessQuery process) {
|
||||||
Map<String, Object> params = process.getParams();
|
Map<String, Object> params = process.getParams();
|
||||||
|
|
||||||
|
/*
|
||||||
// 流程标识
|
// 流程标识
|
||||||
if (StringUtils.isNotBlank(process.getProcessKey())) {
|
if (StringUtils.isNotBlank(process.getProcessKey())) {
|
||||||
query.processDefinitionKey(process.getProcessKey());
|
query.processDefinitionKey(process.getProcessKey());
|
||||||
@ -107,7 +109,26 @@ public class ProcessUtils {
|
|||||||
if (StringUtils.isNotBlank(process.getProcessName())) {
|
if (StringUtils.isNotBlank(process.getProcessName())) {
|
||||||
query.processDefinitionName(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())) {
|
if (StringUtils.isNotBlank(process.getCategory())) {
|
||||||
query.processDefinitionCategory(process.getCategory());
|
query.processDefinitionCategory(process.getCategory());
|
||||||
}
|
}
|
||||||
@ -119,7 +140,6 @@ public class ProcessUtils {
|
|||||||
|
|
||||||
|
|
||||||
public static void buildHistoricVariableInstanceSearch(HistoricVariableInstanceQuery query, ProcessQuery process) {
|
public static void buildHistoricVariableInstanceSearch(HistoricVariableInstanceQuery query, ProcessQuery process) {
|
||||||
Map<String, Object> params = process.getParams();
|
|
||||||
// 规格批次
|
// 规格批次
|
||||||
if (StringUtils.isNotBlank(process.getSpecBatch())) {
|
if (StringUtils.isNotBlank(process.getSpecBatch())) {
|
||||||
query.variableValueLike("lbl_Batch","%" + process.getSpecBatch() + "%");
|
query.variableValueLike("lbl_Batch","%" + process.getSpecBatch() + "%");
|
||||||
|
|||||||
@ -138,5 +138,4 @@ public class WfTaskVo implements Serializable {
|
|||||||
* 规格名称
|
* 规格名称
|
||||||
*/
|
*/
|
||||||
private String specName;
|
private String specName;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,6 @@ public interface IWfProcessService {
|
|||||||
*/
|
*/
|
||||||
TableDataInfo<WfTaskVo> selectPageAllProcessList(ProcessQuery processQuery, PageQuery pageQuery);
|
TableDataInfo<WfTaskVo> selectPageAllProcessList(ProcessQuery processQuery, PageQuery pageQuery);
|
||||||
TableDataInfo<WfTaskVo> selectPageAllProcessList1(ProcessQuery processQuery, PageQuery pageQuery);
|
TableDataInfo<WfTaskVo> selectPageAllProcessList1(ProcessQuery processQuery, PageQuery pageQuery);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询我的流程列表
|
* 查询我的流程列表
|
||||||
* @param pageQuery 分页参数
|
* @param pageQuery 分页参数
|
||||||
|
|||||||
@ -171,7 +171,21 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
|
|||||||
List<WfTaskVo> taskVoList = new ArrayList<>();
|
List<WfTaskVo> taskVoList = new ArrayList<>();
|
||||||
for (HistoricProcessInstance hisIns : historicProcessInstances) {
|
for (HistoricProcessInstance hisIns : historicProcessInstances) {
|
||||||
WfTaskVo taskVo = new WfTaskVo();
|
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()
|
HistoricVariableInstance processStatusVariable = historyService.createHistoricVariableInstanceQuery()
|
||||||
.processInstanceId(hisIns.getId())
|
.processInstanceId(hisIns.getId())
|
||||||
.variableName(ProcessConstants.PROCESS_STATUS_KEY)
|
.variableName(ProcessConstants.PROCESS_STATUS_KEY)
|
||||||
@ -180,6 +194,8 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
|
|||||||
if (ObjectUtil.isNotNull(processStatusVariable)) {
|
if (ObjectUtil.isNotNull(processStatusVariable)) {
|
||||||
processStatus = Convert.toStr(processStatusVariable.getValue());
|
processStatus = Convert.toStr(processStatusVariable.getValue());
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// 兼容旧流程
|
// 兼容旧流程
|
||||||
if (processStatus == null) {
|
if (processStatus == null) {
|
||||||
processStatus = ObjectUtil.isNull(hisIns.getEndTime()) ? ProcessStatus.RUNNING.getStatus() : ProcessStatus.COMPLETED.getStatus();
|
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.setFinishTime(hisIns.getEndTime());
|
||||||
taskVo.setProcInsId(hisIns.getId());
|
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();
|
Object var3Value = variablesMap.get(ProcessConstants.PROCESS_SPEC_NAME); // 规格名称
|
||||||
historicTaskInstanceQuery.taskVariableNotExists("lbl_Batch");
|
String specName = Convert.toStr(var3Value);
|
||||||
historicTaskInstanceQuery.processVariableValueEquals("lbl_Batch","333");
|
taskVo.setSpecName(specName);
|
||||||
|
|
||||||
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())) {
|
if (Objects.nonNull(hisIns.getEndTime())) {
|
||||||
@ -733,7 +734,12 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
|
|||||||
try {
|
try {
|
||||||
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
||||||
.processDefinitionId(procDefId).singleResult();
|
.processDefinitionId(procDefId).singleResult();
|
||||||
startProcess(processDefinition, variables);
|
|
||||||
|
// 启动流程实例并设置流程实例的 Business_key,后续就可以用 Business_key 来检索所需要的流程实例了。
|
||||||
|
String procBusynessKey = getBusynessKey(variables);
|
||||||
|
startProcess(processDefinition, variables,procBusynessKey);
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new ServiceException("流程启动错误");
|
throw new ServiceException("流程启动错误");
|
||||||
@ -751,13 +757,29 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
|
|||||||
try {
|
try {
|
||||||
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
||||||
.processDefinitionKey(procDefKey).latestVersion().singleResult();
|
.processDefinitionKey(procDefKey).latestVersion().singleResult();
|
||||||
startProcess(processDefinition, variables);
|
|
||||||
|
// 启动流程实例并设置流程实例的名称
|
||||||
|
String procBusynessKey = getBusynessKey(variables);
|
||||||
|
|
||||||
|
startProcess(processDefinition, variables,procBusynessKey);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new ServiceException("流程启动错误");
|
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
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteProcessByIds(String[] instanceIds) {
|
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()) {
|
if (ObjectUtil.isNotNull(procDef) && procDef.isSuspended()) {
|
||||||
throw new ServiceException("流程已被挂起,请先激活流程");
|
throw new ServiceException("流程已被挂起,请先激活流程");
|
||||||
}
|
}
|
||||||
@ -838,7 +860,7 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
|
|||||||
// 设置流程状态为进行中
|
// 设置流程状态为进行中
|
||||||
variables.put(ProcessConstants.PROCESS_STATUS_KEY, ProcessStatus.RUNNING.getStatus());
|
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);
|
wfTaskService.startFirstTask(processInstance, variables);
|
||||||
}
|
}
|
||||||
@ -1157,38 +1179,47 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
|
|||||||
Page<WfTaskVo> page = new Page<>();
|
Page<WfTaskVo> page = new Page<>();
|
||||||
|
|
||||||
HistoricVariableInstanceQuery historicVariableInstanceQuery = historyService.createHistoricVariableInstanceQuery()
|
HistoricVariableInstanceQuery historicVariableInstanceQuery = historyService.createHistoricVariableInstanceQuery()
|
||||||
.orderByVariableName()
|
.orderByProcessInstanceId()
|
||||||
.desc();
|
.desc();
|
||||||
|
|
||||||
// 构建搜索条件
|
// 构建搜索条件
|
||||||
|
//processQuery.setSpecBatch("4");
|
||||||
|
|
||||||
ProcessUtils.buildProcessSearch(historicVariableInstanceQuery, processQuery);
|
ProcessUtils.buildProcessSearch(historicVariableInstanceQuery, processQuery);
|
||||||
int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);
|
int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);
|
||||||
|
|
||||||
List<HistoricVariableInstance> historicVariableInstance = historicVariableInstanceQuery
|
List<HistoricVariableInstance> historicVariableInstance = historicVariableInstanceQuery
|
||||||
.listPage(offset, pageQuery.getPageSize());
|
.listPage(offset, pageQuery.getPageSize());
|
||||||
page.setTotal(historicVariableInstance.stream().count());
|
|
||||||
|
|
||||||
List<WfTaskVo> taskVoList = new ArrayList<>();
|
HashSet<HistoricProcessInstance> historicProcessInstances = new HashSet<HistoricProcessInstance>();
|
||||||
|
|
||||||
for (HistoricVariableInstance hisVarIns : historicVariableInstance) {
|
for (HistoricVariableInstance hisVarIns : historicVariableInstance) {
|
||||||
WfTaskVo taskVo = new WfTaskVo();
|
|
||||||
|
|
||||||
// 获取流程实例
|
|
||||||
HistoricProcessInstance hisIns = historyService.createHistoricProcessInstanceQuery()
|
HistoricProcessInstance hisIns = historyService.createHistoricProcessInstanceQuery()
|
||||||
.processInstanceId(hisVarIns.getProcessInstanceId())
|
.processInstanceId(hisVarIns.getProcessInstanceId())
|
||||||
.includeProcessVariables()
|
.includeProcessVariables()
|
||||||
.singleResult();
|
.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()
|
Object var1Value = variablesMap.get(ProcessConstants.PROCESS_STATUS_KEY);
|
||||||
.processInstanceId(hisVarIns.getProcessInstanceId())
|
String processStatus = Convert.toStr(var1Value);
|
||||||
.variableName(ProcessConstants.PROCESS_STATUS_KEY)
|
|
||||||
.singleResult();
|
|
||||||
|
|
||||||
hisVarIns.getProcessInstanceId();
|
|
||||||
String processStatus = null;
|
|
||||||
if (ObjectUtil.isNotNull(processStatusVariable)) {
|
|
||||||
processStatus = Convert.toStr(processStatusVariable.getValue());
|
|
||||||
}
|
|
||||||
// 兼容旧流程
|
// 兼容旧流程
|
||||||
if (processStatus == null) {
|
if (processStatus == null) {
|
||||||
processStatus = ObjectUtil.isNull(hisIns.getEndTime()) ? ProcessStatus.RUNNING.getStatus() : ProcessStatus.COMPLETED.getStatus();
|
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.setFinishTime(hisIns.getEndTime());
|
||||||
taskVo.setProcInsId(hisIns.getId());
|
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();
|
Object var3Value = variablesMap.get("lbl_name");
|
||||||
historicTaskInstanceQuery.taskVariableNotExists("lbl_Batch");
|
String specName = Convert.toStr(var3Value);
|
||||||
historicTaskInstanceQuery.processVariableValueEquals("lbl_Batch","333");
|
taskVo.setSpecBatch(specName);
|
||||||
|
|
||||||
List<HistoricVariableInstance> historicProcessInstances1 =
|
hisIns.getName();
|
||||||
//HistoricVariableInstance processStatusVariable1 =
|
hisIns.getProcessDefinitionName();
|
||||||
|
|
||||||
historyService.createHistoricVariableInstanceQuery()
|
// String spec[] = new String[2];
|
||||||
//.processInstanceId(hisIns.getId())
|
// getHistSpecInfo(hisIns.getId(),spec);
|
||||||
.variableValueLike("lbl_Batch","%")
|
// taskVo.setSpecBatch(spec[0]);
|
||||||
.list();
|
// 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())) {
|
if (Objects.nonNull(hisIns.getEndTime())) {
|
||||||
@ -1242,6 +1267,13 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
|
|||||||
}
|
}
|
||||||
taskVoList.add(taskVo);
|
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);
|
page.setRecords(taskVoList);
|
||||||
return TableDataInfo.build(page);
|
return TableDataInfo.build(page);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user