基于若依的ruoyi-nbcio流程管理系统自定义业务实现一种简单的动态任务标题需求

简介: 基于若依的ruoyi-nbcio流程管理系统自定义业务实现一种简单的动态任务标题需求

更多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://218.75.87.38: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、对于待办任务的标题也需要进行后续动态更新。

相关文章
|
2月前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统修复自定义业务表单的收回功能
基于若依的ruoyi-nbcio流程管理系统修复自定义业务表单的收回功能
25 1
|
2月前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统自定义业务流程出现多个时相应的流程选择问题(二)
基于若依的ruoyi-nbcio流程管理系统自定义业务流程出现多个时相应的流程选择问题(二)
30 3
|
2月前
|
XML JSON 数据格式
基于若依的ruoyi-nbcio流程管理系统增加仿钉钉流程设计(五)
基于若依的ruoyi-nbcio流程管理系统增加仿钉钉流程设计(五)
30 2
|
2月前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统自定义业务实现一种简单的动态任务标题(续)
基于若依的ruoyi-nbcio流程管理系统自定义业务实现一种简单的动态任务标题(续)
22 1
|
2月前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统中自定义业务流程发布动态更新业务流程关联信息
基于若依的ruoyi-nbcio流程管理系统中自定义业务流程发布动态更新业务流程关联信息
68 2
|
2月前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统一种简单的动态表单模拟测试实现(三)
基于若依的ruoyi-nbcio流程管理系统一种简单的动态表单模拟测试实现(三)
22 2
|
2月前
|
JSON 移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统一种简单的动态表单模拟测试实现(二)
基于若依的ruoyi-nbcio流程管理系统一种简单的动态表单模拟测试实现(二)
30 2
|
2月前
|
搜索推荐
基于若依的ruoyi-nbcio流程管理系统增加待办通知个性化设置
基于若依的ruoyi-nbcio流程管理系统增加待办通知个性化设置
36 2
|
2月前
|
前端开发 数据库
基于若依的ruoyi-nbcio流程管理系统增加流程节点配置(二)
基于若依的ruoyi-nbcio流程管理系统增加流程节点配置(二)
32 1
|
2月前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统自定义业务回写状态的一种新方法(二)
基于若依的ruoyi-nbcio流程管理系统自定义业务回写状态的一种新方法(二)
26 2