工具:使用idea和安装activity插件 教程可以网上有
流程:1.创建bpmn插件,绘制一个流程图,可以从最简单的只有一个受理人开始,注意assigine最好指定为参数创建,格式为 #{参数名} 。
2.编写审批的类,控制层加入新增申请,任务详情,处理申请等接口
/** * 新增一个你的申请 */ @PostMapping public AjaxResult add(@RequestBody 你的申请类 对象 ) { logger.info(JSON.toJSONString(对象)); Long userid = getUserId(); 对象.setUserId(userid); //审批编号 Date dt = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss"); String data = sdf.format(dt) + userid; 对象.setApNo(data); 回想.insert申请的mapper方法(对象); 申请的类把原实体类的修改方法 比如修改时间和编号的逻辑 long bussniseeKey = 对象.getId(); Authentication.setAuthenticatedUserId(userid.toString()); //开始工作流、监听 Map<String, Object> variables = new HashMap<>(); //这里只用了一个审批受理人 variables.put("这里是自定义的流程受理人的name", 对象.受理人.toString()); //采用key来启动流程定义并设置流程变量,返回流程实例 ProcessInstance pi = runtimeService.startProcessInstanceByKey("这里是自定义流程的id", String.valueOf(bussniseeKey), variables); logger.info("流程部署id:" + pi.getDeploymentId()); logger.info("流程定义id:" + pi.getProcessDefinitionId()); logger.info("流程实例id:" + pi.getProcessInstanceId()); 对象.setProcessId(pi.getProcessInstanceId()); 对象.更新申请方法(对象); return AjaxResult.success(); }
3.项目启动时和流程运行初始化时必须要将审批申请保存到activity的数据库表中
/** * 初始化配置,将创建28张表 * * @return */ @Bean public StandaloneProcessEngineConfiguration processEngineConfiguration() { /*ProcessEngineConfiguration pec = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration(); pec.setJdbcDriver("oracle.jdbc.driver.OracleDriver"); pec.setJdbcUrl("jdbc:oracle:thin:@这里是自定义你的ip"); pec.setJdbcUsername("用户名"); pec.setJdbcPassword("自定义的密码"); pec.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); //pec.setDatabaseSchema("FLOWABLE"); pec.setDatabaseTablePrefix("flow"); ProcessEngine processEngine = pec.buildProcessEngine();*/ StandaloneProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration(); configuration.setDataSource(dataSource); configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); configuration.setDbIdentityUsed(false); configuration.setAsyncExecutorActivate(false); configuration.setActivityFontName("宋体"); configuration.setAnnotationFontName("宋体"); configuration.setLabelFontName("宋体"); return configuration; } @Bean public ProcessEngine processEngine() { return processEngineConfiguration().buildProcessEngine(); } @Bean public RepositoryService repositoryService() { return processEngine().getRepositoryService(); } @Bean public RuntimeService runtimeService() { return processEngine().getRuntimeService(); } @Bean public TaskService taskService() { return processEngine().getTaskService(); } @Bean public HistoryService historyService() { return processEngine().getHistoryService(); } /** * 部署流程 * * @throws IOException */ @PostConstruct public void initProcess() throws IOException { DeploymentBuilder deploymentBuilder10 = repositoryService().createDeployment(); Resource spec10 = resourceLoader.getResource("classpath:/processes/kekao/reliability.bpmn"); //加载流程图资源文件 deploymentBuilder10.enableDuplicateFiltering().addInputStream(spec10.getFilename(), spec10.getInputStream()).name("你的申请名称").deploy();//按流程id部署 }
4.查看已经申请的内容、代办内容、流转详情以及处理流程的逻辑
/** * 审核处理方法 */
Map<String, Object> param = new HashMap<>(); param.put("submitType", devTask.getSubmitType()); ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); TaskService taskService = processEngine.getTaskService();
//使用任务服务完成任务(提交任务) String taskId = devTask.getTaskId(); // 使用任务id,获取任务对象,获取流程实例id Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); logger.info("Assignee:" + task.getAssignee()); //利用任务对象,获取流程实例id String processInstancesId = task.getProcessInstanceId(); System.out.println(processInstancesId); //认领任务 processEngine.getTaskService()// .claim(taskId, getUserId().toString()); // Authentication.setAuthenticatedUserId("cmc"); // 添加批注时候的审核人 if (devTask.getComment() == null) { devTask.setComment(""); } taskService.addComment(taskId, processInstancesId, devTask.getComment()); taskService.complete(taskId, param);
//再加上自己的业务处理逻辑
/** * 我的待办列表 */ @GetMapping("/backlogList") public TableDataInfo backlogList(@RequestParam Map<String, Object> params) { ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); List<Task> taskList = processEngine.getTaskService()//获取任务service .createTaskQuery()//创建查询对象 .taskAssignee(getUserId().toString()).orderByTaskCreateTime().desc()//参与者,组任务查询 .listPage(Integer.parseInt((String) params.get("pageNum")) - 1, Integer.parseInt((String) params.get("pageSize"))); //分页数据 Long count = processEngine.getTaskService().createTaskQuery().taskCandidateUser(getUserId().toString()).count(); List<DevTask> list = new ArrayList<>(); if (taskList.size() > 0) { for (Task task : taskList) { ProcessInstance pi = processEngine.getRuntimeService()/**表示正在执行的流程实例和执行对象*/ .createProcessInstanceQuery()/**创建流程实例查询*/ .processInstanceId(task.getProcessInstanceId())/**使用流程实例ID查询*/ .singleResult(); logger.info("待办任务ID:" + task.getId()); logger.info("待办任务name:" + task.getName()); logger.info("待办任务创建时间:" + task.getCreateTime()); logger.info("待办任务办理人:" + task.getAssignee()); logger.info("流程实例ID:" + task.getProcessInstanceId()); logger.info("执行对象ID:" + task.getExecutionId()); logger.info(task.getTenantId()); logger.info(task.getCategory()); logger.info(task.getFormKey()); logger.info("流程实例Name:" + pi.getProcessDefinitionName()); //还需要自定义申请类的 和我的待办的实体类 和 业务逻辑 然后自己编写
/** * 已办任务列表 */ @GetMapping("/doneTaskList") public TableDataInfo doneTaskList(@RequestParam Map<String, Object> params) { ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); List<HistoricTaskInstance> taskList = historyService.createHistoricTaskInstanceQuery() .taskAssignee(getUserId().toString()) .finished().orderByHistoricTaskInstanceEndTime().desc() .listPage(Integer.parseInt((String) params.get("pageNum")) - 1, Integer.parseInt((String) params.get("pageSize"))); //分页数据 Long count = historyService.createHistoricTaskInstanceQuery() .taskAssignee(getUserId().toString()) .finished().count(); logger.info(JSON.toJSONString(taskList)); List<DevProcess> list = new ArrayList<>(); if (taskList.size() > 0) { for (HistoricTaskInstance h : taskList) { //logger.info("HistoricTaskInstance:" + JSON.toJSONString(h)); HistoricProcessInstance pi = processEngine.getHistoryService() .createHistoricProcessInstanceQuery().processInstanceId(h.getProcessInstanceId()).singleResult(); logger.info(JSON.toJSONString(pi)); if (pi == null) { continue; } DevProcess devProcess = new DevProcess(); //还需要自定义申请类的 和已办业务的实体类 和 业务逻辑 然后自己编写
5. 前台页面就是调接口编写表格或表单显示申请的数据,自定义即可
相关文章
暂无评论...