activiti自定义流程之Spring整合activiti-modeler5.16实例(九):历史任务查询

注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建
        (2)创建流程模型:activiti自定义流程之Spring整合activiti-modeler5.16实例(二):创建流程模型
        (3)流程模型列表展示:activiti自定义流程之Spring整合activiti-modeler5.16实例(三):流程模型列表展示
        (4)部署流程定义:activiti自定义流程之Spring整合activiti-modeler5.16实例(四):部署流程定义

        (5)流程定义列表:activiti自定义流程之Spring整合activiti-modeler5.16实例(五):流程定义列表

        (6)启动流程:activiti自定义流程之Spring整合activiti-modeler5.16实例(六):启动流程

        (7)任务列表展示:activiti自定义流程之Spring整合activiti-modeler5.16实例(七):任务列表展示

        (8)完成个人任务:activiti自定义流程之Spring整合activiti-modeler5.16实例(八):完成个人任务




1.所有任务完成,流程也就结束了,查询历史任务或历史流程就要操作act_hi_taskinst表,用的都是historyService来调用相关的方法。
本节示例查询历史任务,历史流程便不再专门示例。


2.后台业务代码,
  (1)自定义的任务实体类
package model;
import java.util.Date;

public class HisTaskModel {
	private String id;
	private String name;
	private String assignee;
	private String processInstanceId;
	private Date startTime;
	private Date endTime;
	private String cause;
	private String content;
	private String taskType;

	public String getCause() {
		return cause;
	}

	public void setCause(String cause) {
		this.cause = cause;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getTaskType() {
		return taskType;
	}

	public void setTaskType(String taskType) {
		this.taskType = taskType;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAssignee() {
		return assignee;
	}

	public void setAssignee(String assignee) {
		this.assignee = assignee;
	}

	public String getProcessInstanceId() {
		return processInstanceId;
	}

	public void setProcessInstanceId(String processInstanceId) {
		this.processInstanceId = processInstanceId;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	@Override
	public String toString() {
		return "HisTaskModel [id=" + id + ", name=" + name + ", assignee="
				+ assignee + ", processInstanceId=" + processInstanceId
				+ ", startTime=" + startTime + ", endTime=" + endTime
				+ ", cause=" + cause + ", content=" + content + ", taskType="
				+ taskType + "]";
	}
}


  (2)业务逻辑:
这里需要注意的是,历史表中存在并非是单一类型的数据,就拿历史任务表来说,里边既有已经结束的任务,也有还没有结束的任务。
如果要单独查询结束了的任务,就可以调用finished()方法,查询的就是已经结束的任务。

/**
	 * 查询我的历史任务
	 * 
	 * @author:tuzongxun
	 * @Title: hisTask
	 * @param @param req
	 * @param @return
	 * @return Object
	 * @date Mar 18, 2016 9:12:07 AM
	 * @throws
	 */
	@RequestMapping(value = "/hisTask.do", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
	@ResponseBody
	public Object hisTask(HttpServletRequest req) {
		Map<String, Object> map = new HashMap<String, Object>();
		boolean isLogin = this.isLogin(req);
		if (isLogin) {
			HttpSession session = req.getSession();
			String assignee = (String) session.getAttribute("userName");
			List<HistoricTaskInstance> hisTaskList1 = historyService
					.createHistoricTaskInstanceQuery().taskAssignee(assignee)
					.finished().list();
			List<HisTaskModel> hisTaskList = new ArrayList<HisTaskModel>();
			for (HistoricTaskInstance hisTask : hisTaskList1) {
				HisTaskModel hisModel = new HisTaskModel();
				List<HistoricVariableInstance> hisList = historyService
						.createHistoricVariableInstanceQuery()
						.processInstanceId(hisTask.getProcessInstanceId())
						.list();
				for (HistoricVariableInstance hisVariable : hisList) {
					String name = hisVariable.getVariableName();
					if (name.equals("content")) {
						hisModel.setContent((String) hisVariable.getValue());
					} else if (name.equals("cause")) {
						hisModel.setCause((String) hisVariable.getValue());
					} else if (name.equals("taskType")) {
						hisModel.setTaskType((String) hisVariable.getValue());
					}
				}


				hisModel.setAssignee(hisTask.getAssignee());
				hisModel.setEndTime(hisTask.getEndTime());
				hisModel.setId(hisTask.getId());
				hisModel.setName(hisTask.getName());
				hisModel.setProcessInstanceId(hisTask.getProcessInstanceId());
				hisModel.setStartTime(hisTask.getStartTime());
				hisTaskList.add(hisModel);
			}
			map.put("isLogin", "yes");
			map.put("userName",
					(String) req.getSession().getAttribute("userName"));
			map.put("result", "success");
			map.put("data", hisTaskList);
		} else {
			map.put("isLogin", "no");
		}
		return map;
	}


3.angular js前台代码(前台只是做简单的展示,不多讲):
  (1)app.js中配置路由:
  
$stateProvider  
   .state('hisTask', {  
   url: "/hisTask",  
   views: {  
      'view': {  
       templateUrl: 'activi_views/hisTask.html',  
       controller: 'hisTaskCtr'  
      }  
   }  
  });  
   
  (2)逻辑相关代码:
 
 angular.module('activitiApp')  
.controller('hisTaskCtr', ['$rootScope','$scope','$http','$location', function($rootScope,$scope,$http,$location){  
$scope.init=function(){
        $http.post("./hisTask.do").success(function(result) {
        	if(result.isLogin==="yes"){
        	    console.log(result.data); 
        	    $rootScope.userName=result.userName;
    	        $scope.taskList=result.data;
        	}else{
        		$location.path("/login");
        	}
        });
}
  
}])  

4.对应的填写相关信息的页面:
<div id="logdiv1" ng-init="init();">  
   <p style="font-size:24px;margin-top:10px">历史任务列表</p>
   <center> 
   <table border="1px" style="width:87%;font-size:18px;text-align:center;margin-top:1px;margin-left:2px;position:relative;float:left;" cellSpacing="0px" cellPadding="0px">
      <tr style="background-color:#ccc">
         <td>类型</td>
         <td>ID</td>
         <td>NAME</td>
         <td>流程实例Id</td>
         <td>开始时间</td>
         <td>受理人</td>
         <td>完成时间</td>
         <td>发起原因</td>
         <td>内容</td>
      </tr>
      <tr ng-repeat="task in taskList | orderBy:'id'" >
         <td>{{task.taskType}}</td>
         <td>{{task.id}}</td>
         <td>{{task.name}}</td>
         <td>{{task.processInstanceId}}</td>
         <td>{{task.startTime | date:"yyyy-MM-dd HH:mm:ss"}}</td>
         <td>{{task.assignee}}</td>
         <td>{{task.endTime | date:"yyyy-MM-dd HH:mm:ss"}}</td>
         <td>{{task.cause}}</td>
         <td>{{task.content}}</td>
      </tr>
   </table>  
   </center> 
</div>  


上一篇:Android———从GitHub上下载源码的方法【Written By KillerLegend】


下一篇:《Android 开发入门与实战(第二版)》——6.9节Activity小实例