一、
taskList.jsp中有签收入口
<c:if test="${empty task.assignee }">
<a class="claim" href="${ctx }/oa/leave/task/claim/${task.id}">签收</a>
</c:if>
<c:if test="${not empty task.assignee }">
<%-- 此处用tkey记录当前节点的名称 --%>
<a class="handle" tkey='${task.taskDefinitionKey }' tname='${task.name }' href="#">办理</a>
</c:if>
U_TASK的assignee_字段为空才能签收。
二、
然后具体签收做了什么事情呢?在控制层中有
@Controller
@RequestMapping(value = "/oa/leave")
public class LeaveController {
@Autowired
protected TaskService taskService;
/**
* 签收任务
*/
@RequestMapping(value = "task/claim/{id}")
public String claim(@PathVariable("id") String taskId, HttpSession session, RedirectAttributes redirectAttributes) {
String userId = UserUtil.getUserFromSession(session).getId();
taskService.claim(taskId, userId);
redirectAttributes.addFlashAttribute("message", "任务已签收");
return "redirect:/oa/leave/list/task";
}
}
主要就是 taskService.claim(taskId, userId);
那么它做了什么事情呢,我们看打印日志
--- starting ClaimTaskCmd --------------------------------------------------------
Preparing: select * from ACT_RU_TASK where ID_ = ?
Parameters: 17(String)
Preparing: select * from ACT_HI_TASKINST where ID_ = ?
Parameters: 17(String)
Preparing: select * from ACT_RU_EXECUTION where ID_ = ?
Parameters: 12(String)
Preparing: select * from ACT_RU_IDENTITYLINK where PROC_INST_ID_ = ?
Parameters: 12(String)
Preparing: select * from ACT_RE_PROCDEF where ID_ = ?
Parameters: leave:1:20(String)
Preparing: select RES.* from ACT_HI_ACTINST RES WHERE RES.EXECUTION_ID_ = ? and RES.ACT_ID_ = ? and RES.END_TIME_ is null order by RES.ID_ asc LIMIT ? OFFSET ?
Parameters: 12(String), deptLeaderAudit(String), 1(Integer), 0(Integer)
inserting: IdentityLinkEntity[id=20013, type=participant, userId=leaderuser, processInstanceId=12]
Preparing: insert into ACT_RU_IDENTITYLINK (ID_, REV_, TYPE_, USER_ID_, GROUP_ID_, TASK_ID_, PROC_INST_ID_, PROC_DEF_ID_) values (?, 1, ?, ?, ?, ?, ?, ?)
Parameters: 20013(String), participant(String), leaderuser(String), null, null, 12(String), null
inserting: org.activiti.engine.impl.persistence.entity.HistoricIdentityLinkEntity@2203c1
Preparing: insert into ACT_HI_IDENTITYLINK (ID_, TYPE_, USER_ID_, GROUP_ID_, TASK_ID_, PROC_INST_ID_) values (?, ?, ?, ?, ?, ?)
Parameters: 20013(String), participant(String), leaderuser(String), null, null, 12(String)
updating: Task[id=17, name=部门领导审批]
Preparing: update ACT_RU_TASK SET REV_ = ?, NAME_ = ?, PARENT_TASK_ID_ = ?, PRIORITY_ = ?, CREATE_TIME_ = ?, OWNER_ = ?, ASSIGNEE_ = ?, DELEGATION_ = ?, EXECUTION_ID_ = ?, PROC_DEF_ID_ = ?, DESCRIPTION_ = ?, DUE_DATE_ = ?, CATEGORY_ = ?, SUSPENSION_STATE_ = ?, FORM_KEY_ = ? where ID_= ? and REV_ = ?
Parameters: 2(Integer), 部门领导审批(String), null, 50(Integer), 2015-05-05 15:27:45.0(Timestamp), null, leaderuser(String), null, 12(String), leave:1:20(String), null, null, null, 1(Integer), null, 17(String), 1(Integer)
updating: org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity@124aa56
Preparing: update ACT_HI_TASKINST set EXECUTION_ID_ = ?, NAME_ = ?, PARENT_TASK_ID_ = ?, DESCRIPTION_ = ?, OWNER_ = ?, ASSIGNEE_ = ?, CLAIM_TIME_ = ?, END_TIME_ = ?, DURATION_ = ?, DELETE_REASON_ = ?, TASK_DEF_KEY_ = ?, FORM_KEY_ = ?, PRIORITY_ = ?, DUE_DATE_ = ?, CATEGORY_ = ? where ID_ = ?
Parameters: 12(String), 部门领导审批(String), null, null, null, leaderuser(String), 2015-05-07 15:18:16.779(Timestamp), null, null, null, deptLeaderAudit(String), null, 50(Integer), null, null, 17(String)
updating: HistoricActivityInstanceEntity[activityId=deptLeaderAudit, activityName=部门领导审批]
Preparing: update ACT_HI_ACTINST set EXECUTION_ID_ = ?, ASSIGNEE_ = ?, END_TIME_ = ?, DURATION_ = ? where ID_ = ?
Parameters: 12(String), leaderuser(String), null, null, 16(String)
--- ClaimTaskCmd finished --------------------------------------------------------
--- starting TaskQueryImpl --------------------------------------------------------
--- TaskQueryImpl finished --------------------------------------------------------
要点:
往ACT_RU_IDENTITYLINK表中增加一条记录,表示流程实例现在被user_id为leaderuser的用户签收(participant)了;
更新ACT_RU_TASK表中任务记录,主要更新ASSIGNEE_字段值为leaderuser,后面taskList.jsp中就不能再次签收了;
三、反签收unclaim
如果签收了又签收会如何呢? 当然是会报错……而且异常会直接抛出到页面
这里我们稍微调整一下代码
taskList.jsp调整
<c:if test="${empty task.assignee }">
<a class="claim" href="${ctx }/oa/leave/task/claim/${task.id}">签收</a>
</c:if>
<c:if test="${not empty task.assignee }">
<%-- 此处用tkey记录当前节点的名称 --%>
<a class="handle" tkey='${task.taskDefinitionKey }' tname='${task.name }' href="#">办理</a>
<a class="claim" href="${ctx }/oa/leave/task/unclaim/${task.id}">反签收</a>
</c:if>
控制层增加
/**
* 反签收任务
*/
@RequestMapping(value = "task/unclaim/{id}")
public String unclaim(@PathVariable("id") String taskId, HttpSession session, RedirectAttributes redirectAttributes) {
taskService.unclaim(taskId);
redirectAttributes.addFlashAttribute("message", "任务已反签收");
return "redirect:/oa/leave/list/task";
}
这样我们看一下执行日志
--- starting ClaimTaskCmd --------------------------------------------------------
Preparing: select * from ACT_RU_TASK where ID_ = ?
Parameters: 17(String)
Preparing: select * from ACT_HI_TASKINST where ID_ = ?
Parameters: 17(String)
Preparing: select * from ACT_RE_PROCDEF where ID_ = ?
Parameters: leave:1:20(String)
Preparing: select * from ACT_RU_EXECUTION where ID_ = ?
Parameters: 12(String)
Preparing: select RES.* from ACT_HI_ACTINST RES WHERE RES.EXECUTION_ID_ = ? and RES.ACT_ID_ = ? and RES.END_TIME_ is null order by RES.ID_ asc LIMIT ? OFFSET ?
Parameters: 12(String), deptLeaderAudit(String), 1(Integer), 0(Integer)
updating: Task[id=17, name=部门领导审批]
Preparing: update ACT_RU_TASK SET REV_ = ?, NAME_ = ?, PARENT_TASK_ID_ = ?, PRIORITY_ = ?, CREATE_TIME_ = ?, OWNER_ = ?, ASSIGNEE_ = ?, DELEGATION_ = ?, EXECUTION_ID_ = ?, PROC_DEF_ID_ = ?, DESCRIPTION_ = ?, DUE_DATE_ = ?, CATEGORY_ = ?, SUSPENSION_STATE_ = ?, FORM_KEY_ = ? where ID_= ? and REV_ = ?
Parameters: 9(Integer), 部门领导审批(String), null, 50(Integer), 2015-05-05 15:27:45.0(Timestamp), null, null, null, 12(String), leave:1:20(String), null, null, null, 1(Integer), null, 17(String), 8(Integer)
updating: org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity@3a3b6b
Preparing: update ACT_HI_TASKINST set EXECUTION_ID_ = ?, NAME_ = ?, PARENT_TASK_ID_ = ?, DESCRIPTION_ = ?, OWNER_ = ?, ASSIGNEE_ = ?, CLAIM_TIME_ = ?, END_TIME_ = ?, DURATION_ = ?, DELETE_REASON_ = ?, TASK_DEF_KEY_ = ?, FORM_KEY_ = ?, PRIORITY_ = ?, DUE_DATE_ = ?, CATEGORY_ = ? where ID_ = ?
Parameters: 12(String), 部门领导审批(String), null, null, null, null, 2015-05-07 16:03:48.962(Timestamp), null, null, null, deptLeaderAudit(String), null, 50(Integer), null, null, 17(String)
updating: HistoricActivityInstanceEntity[activityId=deptLeaderAudit, activityName=部门领导审批]
Preparing: update ACT_HI_ACTINST set EXECUTION_ID_ = ?, ASSIGNEE_ = ?, END_TIME_ = ?, DURATION_ = ? where ID_ = ?
Parameters: 12(String), null, null, null, 16(String)
--- ClaimTaskCmd finished --------------------------------------------------------
主要是将ACT_RU_TASK表的ASSIGNEE_置为空。
我们发现这个地方没有去删除ACT_RU_IDENTITYLINK表中之前插入的那条记录,这时如果我们再次签收如果用户一样不会影响,如果用户不一样会新增一条记录……所以原来那条记录最好还是手工删除吧,不然感觉怪怪的。同理,ACT_HI_IDENTITYLINK表中的历史记录也应该删除。
很多地方说到了委托,但有时候我们任务分配给某个人之后,还想着能收回给别人来办理,感觉不太一样。