activiti 工作流

最近用到jeesite工作流,记录一下

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;


import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Comment;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import com.google.common.collect.Maps;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.act.entity.Act;
import com.thinkgem.jeesite.modules.act.service.ActTaskService;
import com.thinkgem.jeesite.modules.act.utils.ActUtils;
import com.thinkgem.jeesite.modules.oa.entity.TestAudit;
import com.thinkgem.jeesite.modules.sys.dao.UserDao;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;

//获取流程历史

public List<Comment> getActHis(HgZsglInvestigation hgZsglInvestigation) {
// 获取历史
List<Comment> historyCommnets = new ArrayList<Comment>();
// 1) 获取流程实例的ID
Task task2 = this.taskService.createTaskQuery().taskId(hgZsglInvestigation.getAct().getTaskId()).singleResult();
ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(task2.getProcessInstanceId())
.singleResult();
// 2)通过流程实例查询所有的(用户任务类型)历史活动
List<HistoricActivityInstance> hais = historyService.createHistoricActivityInstanceQuery()
.processInstanceId(pi.getId()).activityType("userTask").list();
// 3)查询每个历史任务的批注
for (HistoricActivityInstance hai : hais) {
String historytaskId = hai.getTaskId();
List<Comment> comments = taskService.getTaskComments(historytaskId);
// 4)如果当前任务有批注信息,添加到集合中
if (comments != null && comments.size() > 0) {
historyCommnets.addAll(comments);
}
}
sortClass sort = new sortClass();
Collections.sort(historyCommnets, sort);
// 5)返回
return historyCommnets;

}

// 启动流程
@Transactional(readOnly = false)
public void mkSubmit_kc(HgZsglInvestigation hgZsglInvestigation) {
// 登陆用户
String userid = UserUtils.getUser().getId();
hgZsglInvestigation.setTypesp("2"); 下一个业务环节知管审批
hgZsglInvestigation.preUpdate();
super.save(hgZsglInvestigation);
// 启动流程 先给节点赋值
identityService.setAuthenticatedUserId(hgZsglInvestigation.getCurrentUser().getLoginName());
Map<String, Object> vars = Maps.newHashMap();
vars.put("usertask1", "知识管理审批");//知管
vars.put("usertask2", "人力审批");//人力审批
vars.put("usertask3", "财务审批");//财务
vars.put("usertask4", "安全审批");//安全审批
vars.put("usertask5", "常务副总审批");//常务副总
vars.put("usertask6", "提交");//创建人
vars.put("usertask7", "知识管理审核");//知管审核
vars.put("usertask8", "知管入库");//知管入库
vars.put("modify", hgZsglInvestigation.getCreateBy().getLoginName());//创建人修改
actTaskService.startProcess(ActUtils.PD_HG_INVESTIGATION_KC[0], ActUtils.PD_HG_INVESTIGATION_KC[1],

hgZsglInvestigation.getId(), hgZsglInvestigation.getRemarks(), vars);

}

//获取流程实例
public Act getAct(HgZsglInvestigation hgZsglInvestigation) {


Task task = taskService.createTaskQuery().processInstanceId(hgZsglInvestigation.getProcInsId()).active()
.singleResult();
// 工作流Entity
Act act = new Act();
// 任务定义Key(任务环节标识)
act.setTaskDefKey(task.getTaskDefinitionKey());
// 流程实例ID
act.setProcInsId(hgZsglInvestigation.getProcInsId());
// 任务编号
act.setTaskId(task.getId());
// 任务对象
act.setTask(task);


return act;

}

//审批流经各个节点

public void investigatione_kcsp(HgZsglInvestigation hgZsglInvestigation) {
// 登陆用户
String userid = UserUtils.getUser().getId();
// 设置意见
hgZsglInvestigation.getAct()
.setComment(("yes".equals(hgZsglInvestigation.getAct().getFlag()) ? "[同意] " : "[驳回] ")
+ hgZsglInvestigation.getAct().getComment());
hgZsglInvestigation.preUpdate();
// 对不同环节的业务逻辑进行操作
String taskDefKey = hgZsglInvestigation.getAct().getTaskDefKey();
String str = hgZsglInvestigation.getAct().getComment();
// 审核环节
// 知管审批
if ("usertask1".equals(taskDefKey)) {
hgZsglInvestigation.setKnowledgesp(hgZsglInvestigation.getAct().getComment());
dao.updateknowledgesp(hgZsglInvestigation);
if (str.indexOf("同意") >= 0) {
// 人力审批
hgZsglInvestigation.setTypesp("3");
} else {
// 被驳回
hgZsglInvestigation.setTypesp("0");
}
super.save(hgZsglInvestigation);
} else if ("usertask2".equals(taskDefKey)) {
hgZsglInvestigation.setHumansp(hgZsglInvestigation.getAct().getComment());
dao.updateHumansp(hgZsglInvestigation);
if (str.indexOf("同意") >= 0) {
// 财务审批
hgZsglInvestigation.setTypesp("4");
} else {
// 被驳回
hgZsglInvestigation.setTypesp("0");
}
super.save(hgZsglInvestigation);
}
// 安全审批
else if ("usertask3".equals(taskDefKey)) {
hgZsglInvestigation.setFinancesp(hgZsglInvestigation.getAct().getComment());
dao.updateFinancesp(hgZsglInvestigation);
if (str.indexOf("同意") >= 0) {
// 安全审批
hgZsglInvestigation.setTypesp("5");
} else {
// 被驳回
hgZsglInvestigation.setTypesp("0");
}
super.save(hgZsglInvestigation);
}
// 常务副总审批
else if ("usertask4".equals(taskDefKey)) {
hgZsglInvestigation.setSecuritysp(hgZsglInvestigation.getAct().getComment());
dao.updatesecuritysp(hgZsglInvestigation);
if (str.indexOf("同意") >= 0) {
// 常务副总审批
hgZsglInvestigation.setTypesp("6");
} else {
// 被驳回
hgZsglInvestigation.setTypesp("0");
}
super.save(hgZsglInvestigation);
} else if ("usertask5".equals(taskDefKey)) {
hgZsglInvestigation.setStandingsp(hgZsglInvestigation.getAct().getComment());
dao.updateStandingsp(hgZsglInvestigation);
if (str.indexOf("同意") >= 0) {
// 提交
hgZsglInvestigation.setTypesp("7");
} else {
// 被驳回
hgZsglInvestigation.setTypesp("0");
}
super.save(hgZsglInvestigation);


} else if ("usertask6".equals(taskDefKey)) {
hgZsglInvestigation.setStandingsp(hgZsglInvestigation.getAct().getComment());
dao.updateStandingsp(hgZsglInvestigation);
if (str.indexOf("同意") >= 0) {
// 知管审批
hgZsglInvestigation.setTypesp("8");

super.save(hgZsglInvestigation);


} else if ("usertask7".equals(taskDefKey)) {
hgZsglInvestigation.setStandingsp(hgZsglInvestigation.getAct().getComment());
dao.updateStandingsp(hgZsglInvestigation);
if (str.indexOf("同意") >= 0) {
// 知管入库
hgZsglInvestigation.setTypesp("9");
} else {
// 被驳回
hgZsglInvestigation.setTypesp("7");
}
super.save(hgZsglInvestigation);


} else if ("usertask8".equals(taskDefKey)) {
hgZsglInvestigation.setStandingsp(hgZsglInvestigation.getAct().getComment());
dao.updateStandingsp(hgZsglInvestigation);
if (str.indexOf("同意") >= 0) {
// 知管入库
hgZsglInvestigation.setTypesp("10");
}
super.save(hgZsglInvestigation);


} else if ("modify".equals(taskDefKey)) {
if (str.indexOf("同意") >= 0) {
// 审批流程结束
hgZsglInvestigation.setTypesp("2");
} else {
super.delete(hgZsglInvestigation);
}
super.save(hgZsglInvestigation);
}


// 未知环节,直接返回
else {
return;
}
// 提交流程任务
Map<String, Object> vars = Maps.newHashMap();
vars.put("pass", "yes".equals(hgZsglInvestigation.getAct().getFlag()) ? "0" : "1");
actTaskService.complete(hgZsglInvestigation.getAct().getTaskId(), hgZsglInvestigation.getAct().getProcInsId(),
hgZsglInvestigation.getAct().getComment(), vars);

}

// 比较器
class sortClass implements Comparator {
public int compare(Object arg0, Object arg1) {
Comment comment0 = (Comment) arg0;
Comment Comment1 = (Comment) arg1;
int flag = comment0.getTime().compareTo(Comment1.getTime());
return flag;
}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Activiti工作流是一个开源的工作流引擎,用于管理和执行业务流程。它提供了一套完整的工作流管理功能,包括流程定义、流程实例、任务管理、流程变量等。\[1\]在Activiti工作流的定义和执行是通过Activiti表来实现的。这些表包括ACT_RE、ACT_RU、ACT_HI和ACT_GE等,分别用于存储流程定义和资源、运行时数据、历史数据和通用数据。\[2\]Activiti还提供了一系列的服务接口,用于创建和管理工作流引擎。这些服务接口可以通过不同的方式进行创建,包括默认创建方式和一般创建方式。\[2\]在工作流,流程图符号用于表示不同的流程节点和流程控制逻辑。常见的流程图符号包括排他网关、并行网关、包含网关和事件网关等。\[3\]此外,Activiti还可以与Spring和Spring Boot进行整合开发,以便更好地集成到现有的应用程序。\[3\] #### 引用[.reference_title] - *1* [Activiti工作流引擎](https://blog.csdn.net/weixin_45477140/article/details/121146748)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [Activiti工作流](https://blog.csdn.net/Mr_97xu/article/details/112899079)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值