互相学习交流
当处理activiti转办问题时,需要做的就是处理审批人和备注问题。
处理的思路是,先将当前环节标志成转办标签,再通过BUSINESS_KEY_找到流程实例的历史记录,找到最新的一条复制一份出来,表示需要转办到的人的历史记录并设置好审批人(默认转办人的环节‘单位领导’也是做转办人的环节名字,如不是则手动处理下),在更换当前流程的审批人,将任务分到转办人那里去,再将原来最新的历史记录处理掉(通过修改endTime改为处理完成,并将主键进行替换,为了将他隔离开,不与复制出来的id冲突,再通过同样的方式进行comment表的处理并将comment表新增的记录与上面的相关)。
代码如下:
代码语言:javascript复制public Boolean giveOther(String taskId, String userCode, String message) {
// 先查任务
Task task = activitiService.loadTaskInfo(taskId);
if (task == null) {
throw new BusinessException("任务不存在");
}
task.setDescription("转办");
taskService.saveTask(task);
boolean result = false;
if (!StringUtils.isEmpty(taskId)) {
// 查询最新的审批记录
List<ActHiTaskInst> list = jt.queryForBeans(ActHiTaskInst.class, " SELECTn"
"ta.* n"
"FROMn"
"t`act_hi_taskinst` AS an"
"tLEFT JOIN act_hi_procinst AS b ON b.PROC_INST_ID_ = a.PROC_INST_ID_ n"
"twhere b.BUSINESS_KEY_ = ?n"
"ORDER BYn"
"ta.START_TIME_ DESC ", taskId);
ActHiTaskInst oldHiTaskInst = list.get(0);
// 复制一份最新的
ActHiTaskInst hiTaskInst = new ActHiTaskInst();
BeanUtils.copyProperties(oldHiTaskInst, hiTaskInst);
hiTaskInst.setASSIGNEE_(userCode);
//hiTaskInst.setNAME_("转办");
hiTaskInst.setASSIGNEE_(userCode);
hiTaskInst.setSTART_TIME_(new Date());
actHiTaskInstRepo.save(hiTaskInst);
// 更换审核人
taskService.setAssignee(taskService.createTaskQuery().processInstanceBusinessKey(taskId).list().get(0).getId(), userCode);
// 先处理原来的
String id = UUIDUtil.getUUID();
oldHiTaskInst.setEND_TIME_(new Date());
oldHiTaskInst.setID_(id);
actHiTaskInstRepo.save(oldHiTaskInst);
// 处理备注
// 查询最新的备注记录
List<ActHiComment> list2 = jt.queryForBeans(ActHiComment.class, " SELECTn"
"ta.* n"
"FROMn"
"t`act_hi_comment` AS an"
"tLEFT JOIN act_hi_taskinst AS b ON a.PROC_INST_ID_ = b.PROC_INST_ID_ n"
"WHEREn"
"ta.TASK_ID_ = ?n"
"ORDER BYn"
"tb.START_TIME_ DESC ", hiTaskInst.getID_());
ActHiComment oldActHiComment = list2.get(0);
// 复制一份备注记录
ActHiComment actHiComment = new ActHiComment();
BeanUtils.copyProperties(oldActHiComment, actHiComment);
actHiComment.setTASK_ID_(id);// 作为老的转办提出人的备注
actHiComment.setMESSAGE_(message);
actHiComment.setTYPE_("comment");
actHiComment.setFULL_MSG_(message.getBytes(StandardCharsets.UTF_8));
actHiCommentRepo.save(actHiComment);
result = true;
}
return result;
}
代码语言:javascript复制@Entity
@Table(name = "act_hi_taskinst")
@DynamicInsert
@DynamicUpdate
@Data
public class ActHiTaskInst {
@Id
@Column(name = "ID_")
private String ID_;
@Column(name = "PROC_DEF_ID_")
private String PROC_DEF_ID_;
@Column(name = "TASK_DEF_KEY_")
private String TASK_DEF_KEY_;
@Column(name = "PROC_INST_ID_")
private String PROC_INST_ID_;
@Column(name = "EXECUTION_ID_")
private String EXECUTION_ID_;
@Column(name = "NAME_")
private String NAME_;
@Column(name = "PARENT_TASK_ID_")
private String PARENT_TASK_ID_;
@Column(name = "DESCRIPTION_")
private String DESCRIPTION_;
@Column(name = "OWNER_")
private String OWNER_;
@Column(name = "ASSIGNEE_")
private String ASSIGNEE_;
@Column(name = "START_TIME_")
private Date START_TIME_;
@Column(name = "CLAIM_TIME_")
private String CLAIM_TIME_;
@Column(name = "END_TIME_")
private Date END_TIME_;
@Column(name = "DURATION_")
private String DURATION_;
@Column(name = "DELETE_REASON_")
private String DELETE_REASON_;
@Column(name = "PRIORITY_")
private String PRIORITY_;
@Column(name = "DUE_DATE_")
private String DUE_DATE_;
@Column(name = "FORM_KEY_")
private String FORM_KEY_;
@Column(name = "CATEGORY_")
private String CATEGORY_;
@Column(name = "TENANT_ID_")
private String TENANT_ID_;
}
save方法是采用jpa的方式,可自行采用项目对应的方式使用。taskService是activiti的api。