更多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、全局任务创建监听如下修改
/**
* 全局监听-工作流待办消息提醒
*
* @author nbacheng
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class TaskCreateListener implements FlowableEventListener {
private final TaskService taskService;
@Resource
private CommonService commonService;
@Resource
protected RepositoryService repositoryService;
@Resource
protected HistoryService historyService;
@Override
public void onEvent(FlowableEvent flowableEvent) {
FlowableEventType type = flowableEvent.getType();
if (type == FlowableEngineEventType.TASK_ASSIGNED) {
if(flowableEvent instanceof org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl ) {
TaskEntity taskEntity = (TaskEntity) ((org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl) flowableEvent).getEntity();
String taskId = taskEntity.getId();
String procInsId = taskEntity.getProcessInstanceId();
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(procInsId)
.singleResult();
List<Task> listtask = taskService.createTaskQuery().processInstanceId(procInsId).active().list();
String dataId = historicProcessInstance.getBusinessKey();
String deployId = historicProcessInstance.getDeploymentId();
String startUserId = historicProcessInstance.getStartUserId();
//获取任务接收人
String receiver = taskEntity.getAssignee();
if (StringUtils.isNotEmpty(receiver)) {
//发送提醒消息
String category = "";
if(taskService.getVariables(taskId).get("category") != null) {
category = taskService.getVariables(taskId).get("category").toString();
}
LoginUser loginUser = commonService.getLoginUser();
String taskMessageUrl;
if(StringUtils.isNotBlank(dataId)) {
taskMessageUrl = "<a href=" + commonService.getBaseUrl() + procInsId + "?taskId="
+ taskId + "&businessKey=" + dataId + "&category="
+ category + "&processed=true" + ">点击这个进行处理</a>" ;
}
else {
taskMessageUrl = "<a href=" + commonService.getBaseUrl() + procInsId + "?taskId="
+ taskId + "&businessKey" + "&category="
+ category + "&processed=true" + ">点击这个进行处理</a>" ;
}
String msgContent = "流程待办通知" + taskMessageUrl;
if(!StringUtils.equals((loginUser.getUserId()).toString(),receiver)) {//发起人或登录人自己不发送
String taskTitle = "";
if( ObjectUtils.isNotEmpty(listtask)) {
String field = listtask.get(0).getDescription();
field = field.substring(field.lastIndexOf("{") + 1, field.lastIndexOf("}"));
taskTitle = commonService.getTaskTitle(dataId, field);
}
log.info("任务标题:" + taskTitle);
log.info("流程待办通知给:" + receiver);
commonService.sendSysNotice(loginUser.getUserId().toString(), receiver, taskTitle+"流程待办通知", msgContent, Constants.MSG_CATEGORY_3);//setMsgCategory=3是待办
}
}
}
}
}
@Override
public boolean isFailOnException() {
return false;
}
@Override
public boolean isFireOnTransactionLifecycleEvent() {
return false;
}
@Override
public String getOnTransaction() {
return null;
}
}
2、其中上面的getTaskTitle如下:
public String getTaskTitle(String dataId, String field) {
//设置自定义表单dataid的数据
WfMyBusiness flowmybusiness = wfMyBusinessServiceImpl.getByDataId(dataId);
String serviceImplName = flowmybusiness.getServiceImplName();
WfCallBackServiceI flowCallBackService = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplName);
if (flowCallBackService!=null){
return flowCallBackService.getFieldBydataId(dataId, field);
}
return null;
}
3、上面的getFieldBydataId调用了自定义业务的实际类
@Override
public String getFieldBydataId(String dataId, String field) {
return baseMapper.getFieldBydataId(dataId, field);
}
public interface WfDemoMapper extends BaseMapperPlus<WfDemoMapper, WfDemo, WfDemoVo> {
Page<WfDemoVo> myPage(Page<WfDemoVo> page, @Param(Constants.WRAPPER) QueryWrapper<WfDemoVo> queryWrapper);
@Select("select ${field} from wf_demo where demo_id = #{dataId}")
String getFieldBydataId(@Param("dataId") String dataId, @Param("field") String field);
}
4、流程定义
这里做了一个测试例子,用了wf_demo里的字段user_name
5、效果图
6、当然上面对于多实例并发,子流程等还没有进行测试,以后需要进一步修改确认。
7、对于待办任务的标题也需要进行后续动态更新。