码迷,mamicode.com
首页 > 编程语言 > 详细

activiti自己定义流程之Spring整合activiti-modeler实例(七):任务列表展示

时间:2017-08-05 19:52:06      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:pac   data-   fork   获取   display   eve   16px   https   src   

1.通过上一节的操作,能够知道流程启动以后会同一时候生成一个流程实例和用户任务。这个用户任务保存在act_ru_task和act_hi_task表中,从表明能够看出ru是runtime,hi是history。可是须要注意的是,和操作流程使用的service不同。操作正在发生任务不是使用runtimeService,而是专门的taskService。
2.后台业务代码,
  (1)自己定义的任务实体类

[java] view plain copy
 技术分享技术分享
  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.   
  16.     public String getTaskType() {  
  17.         return taskType;  
  18.     }  
  19.   
  20.     public void setTaskType(String taskType) {  
  21.         this.taskType = taskType;  
  22.     }  
  23.   
  24.     public String getId() {  
  25.         return id;  
  26.     }  
  27.   
  28.     public void setId(String id) {  
  29.         this.id = id;  
  30.     }  
  31.   
  32.     public String getName() {  
  33.         return name;  
  34.     }  
  35.   
  36.     public void setName(String name) {  
  37.         this.name = name;  
  38.     }  
  39.   
  40.     public String getProcessInstanceId() {  
  41.         return processInstanceId;  
  42.     }  
  43.   
  44.     public void setProcessInstanceId(String processInstanceId) {  
  45.         this.processInstanceId = processInstanceId;  
  46.     }  
  47.   
  48.     public String getAssignee() {  
  49.         return assignee;  
  50.     }  
  51.   
  52.     public void setAssignee(String assignee) {  
  53.         this.assignee = assignee;  
  54.     }  
  55.   
  56.     public Date getCreateTime() {  
  57.         return createTime;  
  58.     }  
  59.   
  60.     public void setCreateTime(Date createTime) {  
  61.         this.createTime = createTime;  
  62.     }  
  63.   
  64.     public String getNextPerson() {  
  65.         return nextPerson;  
  66.     }  
  67.   
  68.     public void setNextPerson(String nextPerson) {  
  69.         this.nextPerson = nextPerson;  
  70.     }  
  71.   
  72.     public String getCause() {  
  73.         return cause;  
  74.     }  
  75.   
  76.     public void setCause(String cause) {  
  77.         this.cause = cause;  
  78.     }  
  79.   
  80.     public String getContent() {  
  81.         return content;  
  82.     }  
  83.   
  84.     public void setContent(String content) {  
  85.         this.content = content;  
  86.     }  
  87.   
  88.     public String getProcessKey() {  
  89.         return processKey;  
  90.     }  
  91.   
  92.     public void setProcessKey(String processKey) {  
  93.         this.processKey = processKey;  
  94.     }  
  95.   
  96.     public String getProcessDefId() {  
  97.         return processDefId;  
  98.     }  
  99.   
  100.     public void setProcessDefId(String processDefId) {  
  101.         this.processDefId = processDefId;  
  102.     }  
  103.   
  104.     @Override  
  105.     public String toString() {  
  106.         return "TaskModel [id=" + id + ", name=" + name  
  107.                 + ", processInstanceId=" + processInstanceId + ", assignee="  
  108.                 + assignee + ", createTime=" + createTime + ", nextPerson="  
  109.                 + nextPerson + ", cause=" + cause + ", content=" + content  
  110.                 + ", taskType=" + taskType + ", processKey=" + processKey  
  111.                 + ", processDefId=" + processDefId + "]";  
  112.     }  
  113. }  



(2)业务逻辑:查询任务使用taskService调用相关的方法来完毕,能够依据特定的条件,也能够不加条件查询全部。能够返回task为元素的list。也能够返回单独的task对象,可是须要注意的是,假设要返回单独的task对象。则必须确定返回值是唯一的对象,否则就会抛出异常。下边的样例中。我是依据当前登陆的username来查询出相应的全部task:
[java] view plain copy
 技术分享技术分享
  1. /** 
  2.      * @throws XMLStreamException 
  3.      *             查询个人任务 
  4.      *  
  5.      * @author:tuzongxun 
  6.      * @Title: findTask 
  7.      * @param @return 
  8.      * @return Object 
  9.      * @date Mar 17, 2016 2:44:11 PM 
  10.      * @throws 
  11.      */  
  12.     @RequestMapping(value = "/findTask.do", method = RequestMethod.POST, produces = "application/json;charset=utf-8")  
  13.     @ResponseBody  
  14.     public Object findTask(HttpServletRequest req) throws XMLStreamException {  
  15.         Map<String, Object> map = new HashMap<String, Object>();  
  16.         boolean isLogin = this.isLogin(req);  
  17.         if (isLogin) {  
  18.             List<TaskModel> taskList = new ArrayList<TaskModel>();  
  19.             HttpSession session = req.getSession();  
  20.             String assginee = (String) session.getAttribute("userName");  
  21.             List<Task> taskList1 = taskService.createTaskQuery()  
  22.                     .taskAssignee(assginee).list();  
  23.             if (taskList1 != null && taskList1.size() > 0) {  
  24.                 for (Task task : taskList1) {  
  25.                     TaskModel taskModel = new TaskModel();  
  26.                     taskModel.setAssignee(task.getAssignee());  
  27.                     taskModel.setCreateTime(task.getCreateTime());  
  28.                     taskModel.setId(task.getId());  
  29.                     taskModel.setName(task.getName());  
  30.                     taskModel.setProcessInstanceId(task.getProcessInstanceId());  
  31.                     taskModel.setProcessDefId(task.getProcessDefinitionId());  
  32.                     // 获取流程变量  
  33.                     Map<String, Object> variables = runtimeService  
  34.                             .getVariables(task.getProcessInstanceId());  
  35.                     Set<String> keysSet = variables.keySet();  
  36.                     Iterator<String> keySet = keysSet.iterator();  
  37.                     while (keySet.hasNext()) {  
  38.                         String key = keySet.next();  
  39.                         if (key.endsWith("cause")) {  
  40.                             taskModel.setCause((String) variables.get("cause"));  
  41.                         } else if (key.endsWith("content")) {  
  42.                             taskModel.setContent((String) variables  
  43.                                     .get("content"));  
  44.                         } else if (key.endsWith("taskType")) {  
  45.                             taskModel.setTaskType((String) variables  
  46.                                     .get("taskType"));  
  47.                         } else if (!assginee.equals(variables.get(key))) {  
  48.                             // 想办法查询是否还有下一个任务节点  
  49.                             Iterator<FlowElement> iterator = this.findFlow(task  
  50.                                     .getProcessDefinitionId());  
  51.                             while (iterator.hasNext()) {  
  52.                                 FlowElement flowElement = iterator.next();  
  53.                                 String classNames = flowElement.getClass()  
  54.                                         .getSimpleName();  
  55.                                 if (classNames.equals("UserTask")) {  
  56.                                     UserTask userTask = (UserTask) flowElement;  
  57.                                     String assginee11 = userTask.getAssignee();  
  58.                                     String assginee12 = assginee11.substring(  
  59.                                             assginee11.indexOf("{") + 1,  
  60.                                             assginee11.indexOf("}"));  
  61.                                     String assignee13 = (String) variables  
  62.                                             .get(assginee12);  
  63.                                     if (assginee.equals(assignee13)) {  
  64.                                         // 看下下一个节点是什么  
  65.                                         iterator.next();  
  66.                                         FlowElement flowElement2 = iterator  
  67.                                                 .next();  
  68.                                         String classNames1 = flowElement2  
  69.                                                 .getClass().getSimpleName();  
  70.                                         // 设置下一个任务人  
  71.                                         if (!(classNames1.equals("EndEvent"))) {  
  72.                                             UserTask userTask2 = (UserTask) flowElement2;  
  73.                                             String assginee21 = userTask2  
  74.                                                     .getAssignee();  
  75.                                             String assginee22 = assginee21  
  76.                                                     .substring(  
  77.                                                             assginee21  
  78.                                                                     .indexOf("{") + 1,  
  79.                                                             assginee21  
  80.                                                                     .indexOf("}"));  
  81.                                             String assignee23 = (String) variables  
  82.                                                     .get(assginee22);  
  83.                                             taskModel.setNextPerson(ToolUtils  
  84.                                                     .isEmpty(assignee23));  
  85.                                         }  
  86.                                     }  
  87.   
  88.   
  89.                                 }  
  90.                             }  
  91.                             // //////////  
  92.                         }  
  93.                     }  
  94.                     taskList.add(taskModel);  
  95.                 }  
  96.             }  
  97.             map.put("isLogin""yes");  
  98.             map.put("userName",  
  99.                     (String) req.getSession().getAttribute("userName"));  
  100.             map.put("result""success");  
  101.             map.put("data", taskList);  
  102.         } else {  
  103.             map.put("isLogin""no");  
  104.         }  
  105.         return map;  
  106.     }  




3.angular js前台代码(前台仅仅是做简单的展示,不多讲):
  (1)app.js中配置路由:
   
  
[javascript] view plain copy
 技术分享技术分享
  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
 技术分享技术分享
  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.         
  21.     
  22. }])    



4.相应的填写相关信息的页面:

[html] view plain copy
 技术分享技术分享
  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>申请内容activiti自己定义流程之Spring整合activiti-modeler实例(七):任务列表展示

    标签:pac   data-   fork   获取   display   eve   16px   https   src   

    原文地址:http://www.cnblogs.com/yxysuanfa/p/7291038.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!