赞
踩
工具:使用idea和安装activity插件 教程可以网上有
/** * 新增一个你的申请 */ @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(); }
/** * 初始化配置,将创建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部署 }
/** * 审核处理方法 */
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(); //还需要自定义申请类的 和已办业务的实体类 和 业务逻辑 然后自己编写
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。