activiti整合业务

Activiti整合业务需求

1.流程部署

1.1跳转流程部署首页list

@GetMapping("/deploy")
private String toDeploy(){
     
	return "purchase/deploy";
}

1.2跳转流程图首页Data

//查询以部署的流程	
@ResponseBody
	@GetMapping("/deployData")
	public PageUtils deployData(){
     
		ProcessDefinitionQuery processDefinitionQuery =  repositoryService.createProcessDefinitionQuery();	           
		List<ProcessDefinition> list = processDefinitionQuery.list();
		List<Map> list1 = new ArrayList<>();
		for (ProcessDefinition processDefinition : list) {
     
			HashMap<Object, Object> map = new HashMap<>();
			map.put("deploymentId",processDefinition.getDeploymentId());
			map.put("name",processDefinition.getName());
			map.put("version",processDefinition.getVersion());
			map.put("key",processDefinition.getKey());
			list1.add(map);
		}
		PageUtils pageUtils = new PageUtils(list1, list1.size());
		return pageUtils;
	}

1.3流程图部署form

	//添加流程界面
	@GetMapping("/todeployAdd")
	public String todeployAdd(){
     
		return "purchase/deployAdd";
	}

1.4流程图部署保存

//流程部署保存
	@ResponseBody
	@PostMapping("/deploysave")
	public R deploysave(String processName, MultipartFile processFile){
     
		try {
     
			Deployment deploy = repositoryService.createDeployment()
					//流程图名称
					.name(processName)
					//流程图zip文件
					.addZipInputStream(new ZipInputStream(processFile.getInputStream()))
					.deploy();
			System.out.println("流程部署ID:"+deploy.getId());
			System.out.println("流程部署名称:"+deploy.getName());
			return R.ok();
		} catch (IOException e) {
     
			e.printStackTrace();
			return R.error();
		}
	}

2.流程启动(业务表整合)

2.1流程发起首页

@GetMapping()
	String Purchase(){
     
	    return "purchase/purchase";
	}

2.流程发起首页数据

	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("system:purchase:purchase")
	public PageUtils list(@RequestParam Map<String, Object> params){
     
		//查询列表数据
        Query query = new Query(params);
		List<PurchaseDO> purchaseList = purchaseService.list(query);
		int total = purchaseService.count(query);
		PageUtils pageUtils = new PageUtils(purchaseList, total);
		return pageUtils;
	}

效果图如下:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5x3aP5ME-1603875299652)(D:\开发资料\wangyunshi\工作流笔记\整合业务\typora-user-images\1602140492074.png)]

数据库设计:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-v64hD0LS-1603875299654)(D:\开发资料\wangyunshi\工作流笔记\整合业务\typora-user-images\1602140603252.png)]

2.2流程发起添加页面

@GetMapping("/add")
	String add(){
     
	    return "purchase/add";
	}

2.2流程发起保存(purchase为业务表map里面构造画图时候的设置的变量)

	public int save(PurchaseDO purchase){
     
		UserDO user = ShiroUtils.getUser();
		purchase.setUserId(user.getUserId().toString());
		purchase.setUserName(user.getName());
		purchase.setCreateDate(new Date());
		purchase.setFlag(0);
		int save = purchaseDao.save(purchase); //这里要在mybatis里面配置inster主键回填
		//这里发起工作流,启动流程
		   //业务id,拥于存入工作流表中
		String businessKey=purchase.getId()+"";
		HashMap<String, Object> map = new HashMap<>();
		map.put("userId",purchase.getUserId()); //申请人
		map.put("money",purchase.getMoney()); //金额
		//这里要去查询当前用户的上级id,这里暂时写死,这里可以暂时不用全部构造,要执行下一个几点在构造下一个任务接收人就可以
		map.put("loderUserId",138); //领导审批     lisi
		map.put("managerUserId",139); //经理审批   wangwu
		map.put("financeUserId",140); //财务审批   zhaoliu
		runtimeService.startProcessInstanceByKey("purchase",businessKey,map);
		return save;
	}

3.任务查看

3.1待办事项页面

@GetMapping("/whatToDo")
	public String toWhatToDo(){
     
		return "purchase/whatToDo";
	}

3.2代办事项数据(这里根据当前登录用户去查询自己的待办任务)

	@GetMapping("/whatToDoData")
	public PageUtils whatToDoData(){
     
		List<Task> tasks = taskService.createTaskQuery().taskAssignee(ShiroUtils.getUser().getUserId() + "").list();
		List<Map> lists = new ArrayList<>();
		//构造返回数据(因为里面有二进制数据不能直接序列化为json所有手动构造自己需要的数据)
		for (Task task : tasks) {
     
			Map<String, Object> map = new HashMap<>();
			map.put("id",task.getId()); //任务id
			map.put("name",task.getName());  //流程节点
			UserDO user = ShiroUtils.getUser();
			map.put("assignee",user.getName()); //审批人
			map.put("processId",task.getProcessInstanceId());//流程实例id
			map.put("createDate",task.getCreateTime());//申请时间
			lists.add(map);
		}
		return new PageUtils(lists,lists.size());
	}

效果如图:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3iae3hyC-1603875299656)(D:\开发资料\wangyunshi\工作流笔记\整合业务\typora-user-images\1602141301264.png)]

4.任务处理在加一张处理记录表

4.1处理按钮点击后跳转的form(这里id就是任务列表的当前行id)

//任务处理页面
	@GetMapping("/taskHandle/{id}")
	public String taskHandle(@PathVariable("id") Integer id,Model model){
     
		PurchaseDO purchaseDO = purchaseService.getTaskManager(id);
		model.addAttribute("purchase", purchaseDO);
		model.addAttribute("taskid",id);
		return "purchase/taskHandle";
	}

4.1.1 service层业务代码 taskid----->流程实例id , 流程实例id--------->业务表id

	//这里要根据id去act_ru_task表中查找任务执行表act_ru_execution的流程id,在通过任务执行表的流程id去查找业务表id去查询业务信息
		//表:act_ru_task   id---------->PROC_INST_ID----------->
		//表:act_ru_execution    PROC_INST_ID------》BUSINESS_KEY
	@Override
	public PurchaseDO getTaskManager(Integer id) {
     
		/**
		 * 表:act_ru_task   id---------->PROC_INST_ID----------->
		 * 表:act_ru_execution    PROC_INST_ID------》BUSINESS_KEY
		 * */
		//通过传过来的任务id去查找流程实例id
		Task task = taskService.createTaskQuery().taskId(id.toString()).singleResult();
		//流程实例id
		String processid = task.getProcessInstanceId();
		//通过流程实例id获取业务idB   USINESS_KEY
		ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processid).singleResult();
		//这里拿到了业务表id采购信息
		String businessKey = processInstance.getBusinessKey();
		//去查采购信息
		PurchaseDO purchaseDO = purchaseDao.get(Integer.parseInt(businessKey));
		return purchaseDO;
	}

4.2任务处理from提交(同意,驳回)4.1的model.addAttribute一定要记得放入进去任务id

	//任务处理(同意,驳回),记录处理信息
	@ResponseBody
	@PostMapping("/taskHandleSave")
	public R taskHandleSave(@RequestParam("taskid")String taskid, PurchasedetilDO purchasedetilDO){
     
		UserDO user = ShiroUtils.getUser();
		purchasedetilDO.setUserId(user.getUserId().toString());
		purchasedetilDO.setUserName(user.getName());
		purchasedetilDO.setCreateTime(new Date());
		if(purchasedetilService.save(purchasedetilDO,taskid)>0){
     
			return R.ok();
		}
		return R.error();
	}

4.2.1service业务层

	public int save(PurchasedetilDO purchasedetil,String taskid){
     
		int save = purchasedetilDao.save(purchasedetil);
		//执行工作流任务处理如果是0同意1驳回构造数据
		HashMap<String, Object> map = new HashMap<>();
		map.put("flag",purchasedetil.getState()==0?false:true);
		taskService.complete(taskid,map);
		return save;
	}
处理记录表如图

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1CG9Alhe-1603875299657)(D:\开发资料\wangyunshi\工作流笔记\整合业务\typora-user-images\1602143315662.png)]

4.2.2前台页面

<form class="form-horizontal m-t" id="signupForm">
  <div class="form-group">
       <label class="col-sm-3 control-label">任务标题:label>
        <div class="col-sm-8">
            
         div>
  div>
  <div class="form-group">
       <label class="col-sm-3 control-label">金额:label>
        <div class="col-sm-8">
            <input id="money" name="money" th:value="${purchase.money}"                                  class="form-control" type="text" disabled="disabled" readonly="readonly">
        div>
   div>
   <div class="form-group">
         <label class="col-sm-3 control-label">备注:label>
         <div class="col-sm-8">
            <input id="content" name="content" th:value="${purchase.content}"                           class="form- control" type="text" disabled="disabled" readonly="readonly">
         div>
   div>
    <h5>审批意见------上面是用来回显任务说明的,下面才是提交的用意见----------------h5>
    <div class="form-group">
         <label class="col-sm-3 control-label">意见:label>
             <div class="col-sm-8">
                  <input id="opinion" name="opinion" class="form-control" type="text">
              div>
    div>
     <div>
          <input type="hidden" id="state" name="state">
          
          <input type="hidden" id="taskid" name="taskid" th:value="${taskid}">
        <div class="form-group">
         <div class="col-sm-8 col-sm-offset-3">
            <button type="submit" class="btn btn-primary" onclick="pass(1)">同意button>
         div>
      div>
     <div class="form-group">
          <div class="col-sm-8 col-sm-offset-3">
            <button type="submit" class="btn btn-primary" onclick="pass(0)">驳回button>
         div>
       div>
     div>
form>
最后附上一张流程图

ass(1)">同意




驳回


```
最后附上一张流程图

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-63LmFfO7-1603875299658)(D:\开发资料\wangyunshi\工作流笔记\整合业务\typora-user-images\1602143629559.png)]

你可能感兴趣的:(Activiti)