码迷,mamicode.com
首页 > 其他好文 > 详细

【整合篇】JBPM4.4业务与流程整合之查询

时间:2015-02-06 11:22:34      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:


    我们都知道在应用工作流的过程中业务与流程的整合必不可少,那么查询时流程结合业务的查询就更是在所难免了,如何实现这种效果呢,方式有多种,下面我先简单介绍一二(目前有3种方式解决,先简单介绍一种,剩下的两种会结合Activiti再来说明)。

 

第一种方式:


Application(申请实体):

package com.hjy.ssh.beans;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

public class Application {

	/** 状态常量:审批中 */
	public static final String STATUS_RUNNING = "审批中";

	/** 状态常量:已通过 */
	public static final String STATUS_APPROVED = "已通过";

	/** 状态常量:未通过 */
	public static final String STATUS_REJECTED = "未通过";

	private Long id;
	private Set<ApproveInfo> approveInfos = new HashSet<ApproveInfo>();
	private User applicant;// 申请人

	private String processDefinitionKey;//所使用的流程key
	public String getProcessDefinitionKey() {
		return processDefinitionKey;
	}

	public void setProcessDefinitionKey(String processDefinitionKey) {
		this.processDefinitionKey = processDefinitionKey;
	}

	private String title;// 标题
	private String applyTime;// 申请时间
	private String status; // 当前的状态
	private String reason;
	private String executeId;//当前启动的工作流实例id
	
	public String getExecuteId() {
		return executeId;
	}

	public void setExecuteId(String executeId) {
		this.executeId = executeId;
	}

	public String getReason() {
		return reason;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public User getApplicant() {
		return applicant;
	}

	public void setApplicant(User applicant) {
		this.applicant = applicant;
	}

	public String getApplyTime() {
		return applyTime;
	}

	public void setApplyTime(String string) {
		this.applyTime = string;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;		

	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Set<ApproveInfo> getApproveInfos() {
		return approveInfos;
	}

	public void setApproveInfos(Set<ApproveInfo> approveInfos) {
		this.approveInfos = approveInfos;
	}

}

ApproveInfo(审批实体):

package com.hjy.ssh.beans;


/**
 * 审批信息
 * 
 * @author hjy
 * 
 */
public class ApproveInfo {
	private Long id;
	private Application application; // 
	private User approver;// 审批人

	private String approveTime;// 审批时间
	private boolean approval; // 是否通过
	private String comment; // 审批意见

	public Long getId() {
		return id;
	}

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

	public User getApprover() {
		return approver;
	}

	public void setApprover(User approver) {
		this.approver = approver;
	}

	public String getApproveTime() {
		return approveTime;
	}

	public void setApproveTime(String approveTime) {
		this.approveTime = approveTime;
	}

	public Application getApplication() {
		return application;
	}

	public void setApplication(Application application) {
		this.application = application;
	}

	public boolean isApproval() {
		return approval;
	}

	public void setApproval(boolean approval) {
		this.approval = approval;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

}

TaskView(组合实体):

package com.hjy.ssh.beans;

import org.jbpm.api.task.Task;

public class TaskView {

	private Task task;
	private Application application;

	public TaskView(Task task, Application application) {
		this.task = task;
		this.application = application;
	}

	public Task getTask() {
		return task;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	public Application getApplication() {
		return application;
	}

	public void setApplication(Application application) {
		this.application = application;
	}

}

查询我的待办任务:

/** 待我审批(我的任务列表) */
public String myTaskList() throws Exception {
			
	List<TaskView> taskViewList = applicationService.getMyTaskViewList(getCurrentUser());
	//List<TaskView> taskViewList = applicationService.getMyTaskViewList(user);
	ActionContext.getContext().put("taskViewList", taskViewList);
	return "myTaskList";
}

public List<TaskView> getMyTaskViewList(User currentUser) {
	// 查询我的任务列表
	String userId = currentUser.getUsername(); // 约定使用loginName作为JBPM用的用户标识符
	List<Task> taskList = processEngine.getTaskService().findPersonalTasks(userId);
		
	// 找出每个任务对应的申请信息
	List<TaskView> resultList = new ArrayList<TaskView>();
	for (Task task : taskList) {
		
		Application application = (Application) processEngine.getTaskService().getVariable(task.getId(), "application");
		resultList.add(new TaskView(task, application));
	}

	// 返回“任务--申请信息”的结果
	return resultList;
}

此处的返回值为TaskView,这个TaskVie的既包含了业务的内容也包括流程的内容,获取启动流程时存入的流程变量,根据taskidmapkey值来查找即可!

 

我的任务列表:

<!--显示数据列表-->
        <tbody id="TableData" class="dataContainer" datakey="formList">
		
		 <s:iterator value="#taskViewList">
			<tr class="TableDetail1 template" align="CENTER">
				<td>${application.title}</td>
				<td>${application.applicant.username} </td>
				<td>${task.activityName} </td>				
				<td>${application.applyTime} </td>
				<td>
					<s:a action="flowAction_approveUI?applicationId=%{application.id}&taskId=%{task.id}">审批处理</s:a>
					<s:a action="flowAction_approveHistory?applicationId=%{application.id}">查看流转记录</s:a>					
				</td>
			</tr>
		</s:iterator>	
			
        </tbody>


总结:

 

    当然以上也仅仅是给我们提供了一种思路,这种结合的方式有多种,这些跟工作流不工作流没有什么关系,只需要我们在日常做项目的过程中,多多积累,所有的这些其实都是通用的,而且在项目中也很常见,所以还是要靠我们日常的积累!





【整合篇】JBPM4.4业务与流程整合之查询

标签:

原文地址:http://blog.csdn.net/hejingyuan6/article/details/42916211

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