更多ruoyi-nbcio功能请看演示系统
gitee源代码地址
前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio
演示地址:RuoYi-Nbcio后台管理系统
更多nbcio-boot功能请看演示系统
gitee源代码地址
后端代码: https://gitee.com/nbacheng/nbcio-boot
前端代码:https://gitee.com/nbacheng/nbcio-vue.git
在线演示(包括H5) : http://122.227.135.243:9888
之前主要是发送消息的标题处理,今天就待办的任务标题也做一个处理。
1、在获取待办的时候动态进行处理
分页获取待办列表的方法修改如下:
@Override
public TableDataInfo<WfTaskVo> selectPageTodoProcessList(ProcessQuery processQuery, PageQuery pageQuery) {
Page<WfTaskVo> page = new Page<>();
TaskQuery taskQuery = taskService.createTaskQuery()
.active()
.includeProcessVariables()
.taskCandidateOrAssigned(TaskUtils.getUserName())
.taskCandidateGroupIn(TaskUtils.getCandidateGroup())
.orderByTaskCreateTime().desc();
// 构建搜索条件
ProcessUtils.buildProcessSearch(taskQuery, processQuery);
page.setTotal(taskQuery.count());
int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);
List<Task> taskList = taskQuery.listPage(offset, pageQuery.getPageSize());
List<WfTaskVo> flowList = new ArrayList<>();
for (Task task : taskList) {
WfTaskVo flowTask = new WfTaskVo();
// 当前流程信息
flowTask.setTaskId(task.getId());
flowTask.setTaskDefKey(task.getTaskDefinitionKey());
flowTask.setCreateTime(task.getCreateTime());
flowTask.setProcDefId(task.getProcessDefinitionId());
//下面主要是获取全局动态任务标题变量
Map<String, Object> processVariables = task.getProcessVariables();
String taskTitle ="";
if(ObjectUtils.isNotEmpty(processVariables) && ObjectUtils.isNotEmpty(processVariables.get("taskTitle"))) {
taskTitle = processVariables.get("taskTitle").toString();
}
if(StringUtils.isNotEmpty(taskTitle)) {
flowTask.setTaskName(task.getName()+"("+taskTitle+")");
}
else {
flowTask.setTaskName(task.getName());
}
// 流程定义信息
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery()
.processDefinitionId(task.getProcessDefinitionId())
.singleResult();
flowTask.setDeployId(pd.getDeploymentId());
flowTask.setProcDefName(pd.getName());
flowTask.setProcDefVersion(pd.getVersion());
flowTask.setProcInsId(task.getProcessInstanceId());
// 流程发起人信息
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(task.getProcessInstanceId())
.singleResult();
String userId = historicProcessInstance.getStartUserId();
String nickName = sysUserService.selectUserByUserName(userId).getNickName();
flowTask.setStartUserId(userId);
flowTask.setStartUserName(nickName);
// 流程变量
flowTask.setProcVars(task.getProcessVariables());
flowList.add(flowTask);
}
page.setRecords(flowList);
return TableDataInfo.build(page);
}
注意在流程启动的时候也要进行处理。
2、流程启动修改部分
if(StringUtils.isNotEmpty(dataId)) {//自定义业务表单
//设置自定义表单dataid的数据
WfMyBusiness flowmybusiness = wfMyBusinessServiceImpl.getByDataId(variables.get("dataId").toString());
String serviceImplName = flowmybusiness.getServiceImplName();
WfCallBackServiceI flowCallBackService = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplName);
if (flowCallBackService!=null){
Object businessDataById = flowCallBackService.getBusinessDataById(variables.get("dataId").toString());
variables.put("formData",businessDataById);
//作为动态根据Document表达式来处理任务标题用变量
variables.put("taskTitle","发起人");
}
}
3、任务完成也要做修改处理
@Transactional(rollbackFor = Exception.class)
@Override
public void complete(WfTaskBo taskBo) {
Task task = taskService.createTaskQuery().taskId(taskBo.getTaskId()).singleResult();
TaskEntity taskEntity = (TaskEntity) taskService.createTaskQuery().taskId(taskBo.getTaskId()).singleResult();
if (Objects.isNull(task)) {
throw new ServiceException("任务不存在");
}
//获取流程当前节点设置的扩展属性值,需要的时候可以使用
//Map<String, Object> flowProperties = getFlowProperties(taskBo.getProcInsId());
// 获取 bpmn 模型
BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
if (DelegationState.PENDING.equals(task.getDelegationState())) {
taskService.addComment(taskBo.getTaskId(), taskBo.getProcInsId(), FlowComment.DELEGATE.getType(), taskBo.getComment());
taskService.resolveTask(taskBo.getTaskId());
} else {
taskService.addComment(taskBo.getTaskId(), taskBo.getProcInsId(), FlowComment.NORMAL.getType(), taskBo.getComment());
taskService.setAssignee(taskBo.getTaskId(), TaskUtils.getUserName());
if (ObjectUtil.isNotEmpty(taskBo.getVariables())) {
// 获取模型信息
String localScopeValue = ModelUtils.getUserTaskAttributeValue(bpmnModel, task.getTaskDefinitionKey(), ProcessConstants.PROCESS_FORM_LOCAL_SCOPE);
boolean localScope = Convert.toBool(localScopeValue, false);
taskService.complete(taskBo.getTaskId(), taskBo.getVariables(), localScope);
} else {
String field = task.getDescription();
if(StringUtils.isNotEmpty(field)) {
field = field.substring(field.lastIndexOf("{") + 1, field.lastIndexOf("}"));
}
if(StringUtils.isNotEmpty(field)) {//获取动态的任务标题,同时放入全局变量里
String taskTitle = commonService.getTaskTitle(taskBo.getDataId(), field);
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("taskTitle", taskTitle);
taskService.complete(taskBo.getTaskId(),variables,false);
}
else {
taskService.complete(taskBo.getTaskId());
}
}
}
// 设置任务节点名称
taskBo.setTaskName(task.getName());
// 处理下一级审批人
if (StringUtils.isNotBlank(taskBo.getNextUserIds())) {
this.assignNextUsers(bpmnModel, taskBo.getProcInsId(), taskBo.getNextUserIds());
}
//加签处理
addSignForComplete(taskBo,taskEntity);
// 处理抄送用户
if (!copyService.makeCopy(taskBo)) {
throw new RuntimeException("抄送任务失败");
}
}
4、效果图如下: