天天看點

activiti自己定義流程之Spring整合activiti-modeler執行個體(七):任務清單展示

1.通過上一節的操作,能夠知道流程啟動以後會同一時候生成一個流程執行個體和使用者任務。這個使用者任務儲存在act_ru_task和act_hi_task表中,從表明能夠看出ru是runtime,hi是history。可是須要注意的是,和操作流程使用的service不同。操作正在發生任務不是使用runtimeService,而是專門的taskService。

2.背景業務代碼,

  (1)自己定義的任務實體類

[java]  view plain  copy  

activiti自己定義流程之Spring整合activiti-modeler執行個體(七):任務清單展示
activiti自己定義流程之Spring整合activiti-modeler執行個體(七):任務清單展示
  1. package model;  
  2. import java.util.Date;  
  3. public class TaskModel {  
  4.     private String id;  
  5.     private String name;  
  6.     private String processInstanceId;  
  7.     private String assignee;  
  8.     private Date createTime;  
  9.     private String nextPerson;  
  10.     private String cause;  
  11.     private String content;  
  12.     private String taskType;  
  13.     private String processKey;  
  14.     private String processDefId;  
  15.     public String getTaskType() {  
  16.         return taskType;  
  17.     }  
  18.     public void setTaskType(String taskType) {  
  19.         this.taskType = taskType;  
  20.     }  
  21.     public String getId() {  
  22.         return id;  
  23.     }  
  24.     public void setId(String id) {  
  25.         this.id = id;  
  26.     }  
  27.     public String getName() {  
  28.         return name;  
  29.     }  
  30.     public void setName(String name) {  
  31.         this.name = name;  
  32.     }  
  33.     public String getProcessInstanceId() {  
  34.         return processInstanceId;  
  35.     }  
  36.     public void setProcessInstanceId(String processInstanceId) {  
  37.         this.processInstanceId = processInstanceId;  
  38.     }  
  39.     public String getAssignee() {  
  40.         return assignee;  
  41.     }  
  42.     public void setAssignee(String assignee) {  
  43.         this.assignee = assignee;  
  44.     }  
  45.     public Date getCreateTime() {  
  46.         return createTime;  
  47.     }  
  48.     public void setCreateTime(Date createTime) {  
  49.         this.createTime = createTime;  
  50.     }  
  51.     public String getNextPerson() {  
  52.         return nextPerson;  
  53.     }  
  54.     public void setNextPerson(String nextPerson) {  
  55.         this.nextPerson = nextPerson;  
  56.     }  
  57.     public String getCause() {  
  58.         return cause;  
  59.     }  
  60.     public void setCause(String cause) {  
  61.         this.cause = cause;  
  62.     }  
  63.     public String getContent() {  
  64.         return content;  
  65.     }  
  66.     public void setContent(String content) {  
  67.         this.content = content;  
  68.     }  
  69.     public String getProcessKey() {  
  70.         return processKey;  
  71.     }  
  72.     public void setProcessKey(String processKey) {  
  73.         this.processKey = processKey;  
  74.     }  
  75.     public String getProcessDefId() {  
  76.         return processDefId;  
  77.     }  
  78.     public void setProcessDefId(String processDefId) {  
  79.         this.processDefId = processDefId;  
  80.     }  
  81.     @Override  
  82.     public String toString() {  
  83.         return "TaskModel [id=" + id + ", name=" + name  
  84.                 + ", processInstanceId=" + processInstanceId + ", assignee="  
  85.                 + assignee + ", createTime=" + createTime + ", nextPerson="  
  86.                 + nextPerson + ", cause=" + cause + ", content=" + content  
  87.                 + ", taskType=" + taskType + ", processKey=" + processKey  
  88.                 + ", processDefId=" + processDefId + "]";  
  89.     }  
  90. }  

(2)業務邏輯:查詢任務使用taskService調用相關的方法來完畢,能夠依據特定的條件,也能夠不加條件查詢全部。能夠傳回task為元素的list。也能夠傳回單獨的task對象,可是須要注意的是,假設要傳回單獨的task對象。則必須确定傳回值是唯一的對象,否則就會抛出異常。下邊的樣例中。我是依據目前登陸的username來查詢出相應的全部task:

[java]  view plain  copy  

activiti自己定義流程之Spring整合activiti-modeler執行個體(七):任務清單展示
activiti自己定義流程之Spring整合activiti-modeler執行個體(七):任務清單展示
  1.     @RequestMapping(value = "/findTask.do", method = RequestMethod.POST, produces = "application/json;charset=utf-8")  
  2.     @ResponseBody  
  3.     public Object findTask(HttpServletRequest req) throws XMLStreamException {  
  4.         Map<String, Object> map = new HashMap<String, Object>();  
  5.         boolean isLogin = this.isLogin(req);  
  6.         if (isLogin) {  
  7.             List<TaskModel> taskList = new ArrayList<TaskModel>();  
  8.             HttpSession session = req.getSession();  
  9.             String assginee = (String) session.getAttribute("userName");  
  10.             List<Task> taskList1 = taskService.createTaskQuery()  
  11.                     .taskAssignee(assginee).list();  
  12.             if (taskList1 != null && taskList1.size() > 0) {  
  13.                 for (Task task : taskList1) {  
  14.                     TaskModel taskModel = new TaskModel();  
  15.                     taskModel.setAssignee(task.getAssignee());  
  16.                     taskModel.setCreateTime(task.getCreateTime());  
  17.                     taskModel.setId(task.getId());  
  18.                     taskModel.setName(task.getName());  
  19.                     taskModel.setProcessInstanceId(task.getProcessInstanceId());  
  20.                     taskModel.setProcessDefId(task.getProcessDefinitionId());  
  21.                     // 擷取流程變量  
  22.                     Map<String, Object> variables = runtimeService  
  23.                             .getVariables(task.getProcessInstanceId());  
  24.                     Set<String> keysSet = variables.keySet();  
  25.                     Iterator<String> keySet = keysSet.iterator();  
  26.                     while (keySet.hasNext()) {  
  27.                         String key = keySet.next();  
  28.                         if (key.endsWith("cause")) {  
  29.                             taskModel.setCause((String) variables.get("cause"));  
  30.                         } else if (key.endsWith("content")) {  
  31.                             taskModel.setContent((String) variables  
  32.                                     .get("content"));  
  33.                         } else if (key.endsWith("taskType")) {  
  34.                             taskModel.setTaskType((String) variables  
  35.                                     .get("taskType"));  
  36.                         } else if (!assginee.equals(variables.get(key))) {  
  37.                             // 想辦法查詢是否還有下一個任務節點  
  38.                             Iterator<FlowElement> iterator = this.findFlow(task  
  39.                                     .getProcessDefinitionId());  
  40.                             while (iterator.hasNext()) {  
  41.                                 FlowElement flowElement = iterator.next();  
  42.                                 String classNames = flowElement.getClass()  
  43.                                         .getSimpleName();  
  44.                                 if (classNames.equals("UserTask")) {  
  45.                                     UserTask userTask = (UserTask) flowElement;  
  46.                                     String assginee11 = userTask.getAssignee();  
  47.                                     String assginee12 = assginee11.substring(  
  48.                                             assginee11.indexOf("{") + 1,  
  49.                                             assginee11.indexOf("}"));  
  50.                                     String assignee13 = (String) variables  
  51.                                             .get(assginee12);  
  52.                                     if (assginee.equals(assignee13)) {  
  53.                                         // 看下下一個節點是什麼  
  54.                                         iterator.next();  
  55.                                         FlowElement flowElement2 = iterator  
  56.                                                 .next();  
  57.                                         String classNames1 = flowElement2  
  58.                                                 .getClass().getSimpleName();  
  59.                                         // 設定下一個任務人  
  60.                                         if (!(classNames1.equals("EndEvent"))) {  
  61.                                             UserTask userTask2 = (UserTask) flowElement2;  
  62.                                             String assginee21 = userTask2  
  63.                                                     .getAssignee();  
  64.                                             String assginee22 = assginee21  
  65.                                                     .substring(  
  66.                                                             assginee21  
  67.                                                                     .indexOf("{") + 1,  
  68.                                                             assginee21  
  69.                                                                     .indexOf("}"));  
  70.                                             String assignee23 = (String) variables  
  71.                                                     .get(assginee22);  
  72.                                             taskModel.setNextPerson(ToolUtils  
  73.                                                     .isEmpty(assignee23));  
  74.                                         }  
  75.                                     }  
  76.                                 }  
  77.                             }  
  78.                             // //  
  79.                         }  
  80.                     }  
  81.                     taskList.add(taskModel);  
  82.                 }  
  83.             }  
  84.             map.put("isLogin", "yes");  
  85.             map.put("userName",  
  86.                     (String) req.getSession().getAttribute("userName"));  
  87.             map.put("result", "success");  
  88.             map.put("data", taskList);  
  89.         } else {  
  90.             map.put("isLogin", "no");  
  91.         }  
  92.         return map;  
  93.     }  

3.angular js前台代碼(前台僅僅是做簡單的展示,不多講):

  (1)app.js中配置路由:

   [javascript]  view plain  copy  

activiti自己定義流程之Spring整合activiti-modeler執行個體(七):任務清單展示
activiti自己定義流程之Spring整合activiti-modeler執行個體(七):任務清單展示
  1. $stateProvider    
  2.   .state('taskList', {    
  3.   url: "/taskList",    
  4.   views: {    
  5.      'view': {    
  6.       templateUrl: 'activi_views/taskList.html',    
  7.       controller: 'taskCtr'    
  8.      }    
  9.   }    
  10.  });    

  (2)邏輯相關代碼:

    [javascript]  view plain  copy  

activiti自己定義流程之Spring整合activiti-modeler執行個體(七):任務清單展示
activiti自己定義流程之Spring整合activiti-modeler執行個體(七):任務清單展示
  1.   angular.module('activitiApp')    
  2. .controller('taskCtr', ['$rootScope','$scope','$http','$location','$state', function($rootScope,$scope,$http,$location,$state){    
  3. $scope.init=function(){  
  4.         $http.post("./findTask.do").success(function(result) {  
  5.             if(result.isLogin==="yes"){  
  6.             console.log(result.data);   
  7.             $rootScope.userName=result.userName;  
  8.             $scope.taskList=result.data;  
  9.             }else{  
  10.                 $location.path("/login");  
  11.             }  
  12.         });  
  13. }      
  14.         $scope.completeTaskTo=function(task){  
  15.             console.log(task);  
  16.             $rootScope.task=task;  
  17.             //$location.path("/completeTaskTo");  
  18.             $location.path("/completeTaskTo1");  
  19.         }  
  20. }])    

4.相應的填寫相關資訊的頁面:

[html]  view plain  copy  

activiti自己定義流程之Spring整合activiti-modeler執行個體(七):任務清單展示
activiti自己定義流程之Spring整合activiti-modeler執行個體(七):任務清單展示
  1. <div id="logdiv1" ng-init="init();">    
  2.    <p style="font-size:22px;margin-top:10px">目前任務清單</p>  
  3.    <center>   
  4.    <table border="1px" style="width:87%;font-size:14px;text-align:center;margin-top:1px;margin-left:2px;position:relative;float:left;" cellSpacing="0px" cellPadding="0px">  
  5.       <tr style="background-color:#ccc">  
  6.          <td>類型</td>  
  7.          <td>ID</td>  
  8.          <td>NAME</td>  
  9.          <td>ProcessIntanceId</td>  
  10.          <td>ProcessDefId</td>  
  11.          <td>建立時間</td>  
  12.          <td>申請人</td>  
  13.          <td>受理人</td>  
  14.          <td>申請原因</td>  
  15.          <td>申請内容

posted @ 2017-08-05 18:32  yxysuanfa 閱讀( ...) 評論( ...) 編輯 收藏

轉載于:https://www.cnblogs.com/yxysuanfa/p/7291038.html