@ApiOperation(value = "获取申请、报销联合节点")
@GetMapping(path = "/def/nodes/union")
public Response auditNodeList(@RequestParam String creator, @RequestParam String agyCode,
@RequestParam Integer fiscal) {
return Response.success().setData(workflowService.auditNodeList(creator, agyCode, fiscal));
}
public List<Map> auditNodeList(String creator, String agyCode, Integer fiscal);
@Override
public List <Map> auditNodeList(String creator, String agyCode, Integer fiscal) {
List <Map> result = new ArrayList <Map>();
List <String> list = new ArrayList <String>();
// 填充申请流程节点
PexWfSetting applyWfSetting = wfSettingService.getWfSetting(agyCode, fiscal, PexConstants.BILL_FUNC_APPLY);
// todo(liubo): 增加tenantId, category
WfDefinition applyWfDefinition = wfDefinitionService.getNodeDefinition(PexConstants.PEX_SYS_ID,
applyWfSetting.getWfId());
List <Map> applyNodes = applyWfDefinition.getNodes().stream().map(node -> {
Map ele = new HashMap();
ele.put("wfId", node.getWfId());
ele.put("exeNodeId", node.getNodeId());
ele.put("title", node.getName());
ele.put("billFunc", PexConstants.BILL_FUNC_APPLY);
ele.put("NodeType", node.getNodeType());//NodeType: UserTask 任务节点 , Event 起止节点 All 全部节点
ele.put("isStart", 0);
ele.put("isEnd", 0);
ele.put("isSecond", 0);
return ele;
}).collect(Collectors.toList());
applyNodes.get(0).put("isStart", 1);
list.add((String) applyNodes.get(0).get("wfId"));
applyNodes.get(applyNodes.size() - 1).put("isEnd", 1);
List<String> applySecondNode=wfRuntimeService.getSecondNode(applyNodes,PexConstants.PEX_SYS_ID,applyWfSetting.getWfId());
for (Map map : applyNodes) {
if(applySecondNode.contains(map.get("exeNodeId"))){
map.put("isSecond", 1);
}
}
result.addAll(applyNodes);
// 填充报销流程节点
PexWfSetting expenseWfSetting = wfSettingService.getWfSetting(agyCode, fiscal, PexConstants.BILL_FUNC_EXPENSE);
WfDefinition expenseWfDefinition = wfDefinitionService.getNodeDefinition(PexConstants.PEX_SYS_ID,
expenseWfSetting.getWfId());
List <Map> expenseNodes = expenseWfDefinition.getNodes().stream().map(node -> {
Map ele = new HashMap();
ele.put("wfId", node.getWfId());
ele.put("exeNodeId", node.getNodeId());
ele.put("title", node.getName());
ele.put("billFunc", PexConstants.BILL_FUNC_EXPENSE);
ele.put("NodeType", node.getNodeType());//NodeType: UserTask 任务节点 , Event 起止节点 All 全部节点
ele.put("isStart", 0);
ele.put("isEnd", 0);
ele.put("isSecond", 0);
return ele;
}).collect(Collectors.toList());
expenseNodes.get(0).put("isStart", 1);
list.add((String) expenseNodes.get(0).get("wfId"));
expenseNodes.get(expenseNodes.size() - 1).put("isEnd", 1);
List<String> expenseSecondNode=wfRuntimeService.getSecondNode(expenseNodes,PexConstants.PEX_SYS_ID,expenseWfSetting.getWfId());
for (Map map : expenseNodes) {
if(expenseSecondNode.contains(map.get("exeNodeId"))){
map.put("isSecond", 1);
}
}
result.addAll(expenseNodes);
//填充借款流程节点
PexWfSetting loanWfSetting = wfSettingService.getWfSetting(agyCode, fiscal, PexConstants.BILL_FUNC_LOAN);
WfDefinition loanWfDefinition = wfDefinitionService.getNodeDefinition(PexConstants.PEX_SYS_ID,
loanWfSetting.getWfId());
List <Map> loanNodes = loanWfDefinition.getNodes().stream().map(node -> {
Map ele = new HashMap();
ele.put("wfId", node.getWfId());
ele.put("exeNodeId", node.getNodeId());
ele.put("title", node.getName());
ele.put("billFunc", PexConstants.BILL_FUNC_LOAN);
ele.put("NodeType", node.getNodeType());//NodeType: UserTask 任务节点 , Event 起止节点 All 全部节点
ele.put("isStart", 0);
ele.put("isEnd", 0);
ele.put("isSecond", 0);
return ele;
}).collect(Collectors.toList());
loanNodes.get(0).put("isStart", 1);
list.add((String) loanNodes.get(0).get("wfId"));
loanNodes.get(loanNodes.size() - 1).put("isEnd", 1);
List<String> loanSecondNode=wfRuntimeService.getSecondNode(loanNodes,PexConstants.PEX_SYS_ID,loanWfSetting.getWfId());
for (Map map : loanNodes) {
if(loanSecondNode.contains(map.get("exeNodeId"))){
map.put("isSecond", 1);
}
}
result.addAll(loanNodes);
Map ele = new HashMap();
ele.put("wfId", (String) applyNodes.get(0).get("wfId") + "," + (String) expenseNodes.get(0).get("wfId") + ","
+ (String) loanNodes.get(0).get("wfId"));
ele.put("title", "历史单据");
ele.put("NodeType", "All");//NodeType: UserTask 任务节点 , Event 起止节点 All 全部节点
ele.put("billFunc", "");
ele.put("isStart", 0);
ele.put("isEnd", 2);
ele.put("isSecond", 0);
result.add(ele);
// 填充节点待审核数据条数
result.parallelStream().forEach(map -> {
PexContentBillVo cond = new PexContentBillVo();
cond.setCreator(creator);
cond.setFiscal(fiscal);
cond.setAgyCode(agyCode);
cond.setExeNodeId((String) map.get("exeNodeId"));
cond.setBillFunc((String) map.get("billFunc"));
cond.setWfId((String) map.get("wfId"));
switch ((int) map.get("isEnd")) {
//指定节点的待审核数据
case 0:
map.put("count", commonInfoService.countToDoByNodeId(cond));
break;
//流程结束节点的审核数据
case 1:
map.put("count", commonInfoService.countDnoeByNodeId(cond));
break;
//流程审核的全部数据
default:
map.put("count", commonInfoService.countAllByNodeId(cond, list));
break;
}
});
return result;
}
@Data
public class WfDefinition {
private String key;
private String name;
private String category;
private List<WfNodeInfo> nodes = new ArrayList<WfNodeInfo>();
public void addNode(WfNodeInfo node) {
nodes.add(node);
}
// 获取首节点
public WfNodeInfo getFirstNode() {
return nodes.get(0);
}
// 判断是否首节点
public Integer isFirstNode(String nodeId) {
boolean isFirst = getFirstNode().getNodeId().equals(nodeId);
return isFirst ? 1 : 0;
}
}
@Override
//获取流程图中流程节点信息(流程图信息展示)
public WfDefinition getNodeDefinition(String tenantId, String key) {
List<WfNodeInfo> nodes =getAllDefinition(tenantId,key);
nodes.remove(0);
WfDefinition result = arrangeDefinition(tenantId, key);
for (WfNodeInfo wfNodeInfo : nodes) {
result.addNode(wfNodeInfo);
}
return result;
}
// TODO(liubo): 在流程重新部署的时候,清除pex_cache, pty_workflow
// @Cacheable(value = "pty_workflow", key = "'pty_workflow_definition_' + #key")
// 获取包括任务节点,起止节点在内的流程图节点信息
public List<WfNodeInfo> getAllDefinition(String tenantId,String key) {
WfDefinition result = new WfDefinition();
List<WfNodeInfo> nodes = new ArrayList<WfNodeInfo>();
WfNodeInfo nodeEnd = new WfNodeInfo();
result.setKey(key);
RepositoryService repositoryService = activitiEngine.getRepositoryService();
ProcessDefinition definition = repositoryService.createProcessDefinitionQuery()
.processDefinitionTenantId(tenantId).processDefinitionKey(key)
.latestVersion().singleResult();
if (definition != null) {
result.setName(definition.getName());
Collection<FlowElement> list=repositoryService.getBpmnModel(definition.getId()).getMainProcess().getFlowElements();
for (FlowElement flowElement : list) {
//假设是任务节点
if(flowElement instanceof UserTask ) {
if(flowElement != null) {
WfNodeInfo node = new WfNodeInfo();
node.setNodeId(flowElement.getId());
node.setName(flowElement.getName());
node.setWfId(key);
node.setNodeType("UserTask");
nodes.add(node);
result.addNode(node);
}
}
/* if(flowElement instanceof StartEvent || flowElement instanceof EndEvent){
if(flowElement != null) {
WfNodeInfo node = new WfNodeInfo();
node.setNodeId(flowElement.getId());
node.setName(flowElement.getName());
node.setWfId(key);
node.setNodeType("Event");
nodes.add(0,node);
}
}*/
if(flowElement instanceof StartEvent){
if(flowElement != null) {
WfNodeInfo node = new WfNodeInfo();
node.setNodeId(flowElement.getId());
node.setName(flowElement.getName());
node.setWfId(key);
node.setNodeType("Event");
nodes.add(0,node);
result.addNode(node);
}
}
if(flowElement instanceof EndEvent){
if(flowElement != null) {
WfNodeInfo node = new WfNodeInfo();
nodeEnd.setNodeId(flowElement.getId());
nodeEnd.setName(flowElement.getName());
nodeEnd.setWfId(key);
nodeEnd.setNodeType("Event");
//nodes.add(node);
result.addNode(node);
}
}
}
nodes.add(nodeEnd);
}
return nodes;
}
public WfDefinition arrangeDefinition(String tenantId, String key) {
ProcessDefinition definition = activitiEngine.getRepositoryService().createProcessDefinitionQuery()
.processDefinitionTenantId(tenantId).processDefinitionKey(key)
.latestVersion().singleResult();
WfDefinition result = new WfDefinition();
if(definition != null){
result.setName(definition.getName());
}
return result;
}
@Override
public List<String> getSecondNode(List<Map> applyNodes,String tenantId,String key) {
List<String> secondNode=new ArrayList<String>();
List<String> gatWaySecondNode=new ArrayList<String>();
String gatWay=null;
WfDefinition result = new WfDefinition();
List<WfNodeInfo> nodes = new ArrayList<WfNodeInfo>();
WfNodeInfo nodeEnd = new WfNodeInfo();
result.setKey(key);
RepositoryService repositoryService = activitiEngine.getRepositoryService();
ProcessDefinition definition = repositoryService.createProcessDefinitionQuery()
.processDefinitionTenantId(tenantId).processDefinitionKey(key)
.latestVersion().singleResult();
if (definition != null) {
result.setName(definition.getName());
Collection<FlowElement> list=repositoryService.getBpmnModel(definition.getId()).getMainProcess().getFlowElements();
String targetRef=null;
for (FlowElement flowElement : list) {
String name=flowElement.getName();
flowElement.getAttributes();
if(flowElement instanceof StartEvent){
if(flowElement != null) {
WfNodeInfo node = new WfNodeInfo();
List<SequenceFlow> listFlow= ((StartEvent) flowElement).getOutgoingFlows();
for (SequenceFlow sequenceFlow : listFlow) {
//获取的流程第一个节点
targetRef= sequenceFlow.getTargetRef();
}
}
}
//获取第一个节点的信息
if(flowElement instanceof UserTask){
if(flowElement.getId().equals(targetRef)){
//第一个节点的所有的出方向的线
List<SequenceFlow> listFlow=((UserTask) flowElement).getOutgoingFlows();
if(listFlow.size()==1){
//第一个任务节点之后的节点信息(任务节点或者网管节点)
secondNode.add(listFlow.get(0).getTargetRef());
}
}
}
//获取网管节点信息
if(flowElement instanceof ExclusiveGateway|| flowElement instanceof ParallelGateway){
//List<SequenceFlow> listFlow= ((UserTask) flowElement).getOutgoingFlows();
gatWay=flowElement.getId();
List<SequenceFlow> listFlow= ((Gateway) flowElement).getOutgoingFlows();
if(secondNode.size()!=0){
if(gatWay.equals(secondNode.get(0))){
for (SequenceFlow sequenceFlow : listFlow) {
gatWaySecondNode.add(sequenceFlow.getTargetRef());
}
}
}
}
}
}
if(gatWaySecondNode.size()==0){
return secondNode;
}else{
return gatWaySecondNode;
}
}
<select id="countToDoByNodeId" parameterType="com.pty.pex.vo.PexContentBillVo" resultType="java.lang.Integer">
select
COUNT(1)
from pex_bill inner join
<include refid="com.pty.workflow.dao.WfTaskDao.todo_node_sql"/>
on pex_bill.bill_id=wf_task.busi_key
WHERE 1=1
<include refid="allColumnCond"/>
</select>
<sql id="todo_node_sql">
(
SELECT
act_ru_execution.ACT_ID_ AS task_node_id,
act_ru_task.ID_ AS wf_task_id,
act_ru_task.IS_RETURN_ AS is_return,
act_hi_procinst.BUSINESS_KEY_ AS busi_key,
act_hi_procinst.PROC_INST_ID_ AS proc_inst_id,
act_hi_procinst.PROC_DEF_ID_ AS proc_def_id
FROM
act_ru_task
INNER JOIN act_ru_execution ON act_ru_task.EXECUTION_ID_=act_ru_execution.ID_
INNER JOIN act_hi_procinst
ON act_hi_procinst.PROC_INST_ID_ = act_ru_task.PROC_INST_ID_
<if test="creator != null and creator != ''">
AND act_hi_procinst.START_USER_ID_=#{creator}
</if>
INNER JOIN act_re_procdef
ON act_hi_procinst.PROC_DEF_ID_ = act_re_procdef.ID_
<if test="wfId != null and wfId !=''">
AND act_re_procdef.KEY_ = #{wfId}
</if>
WHERE 1=1
<if test="exeNodeId != null and exeNodeId != ''">
AND act_ru_execution.ACT_ID_=#{exeNodeId}
</if>
) wf_task
</sql>
<select id="countDnoeByNodeId" parameterType="com.pty.pex.vo.PexContentBillVo" resultType="java.lang.Integer">
select
COUNT(1)
from pex_bill inner join act_hi_procinst
on pex_bill.bill_id=act_hi_procinst.business_key_
AND act_hi_procinst.END_TIME_ is not null
<if test="creator != null and creator != ''">
AND act_hi_procinst.START_USER_ID_=#{creator}
</if>
INNER JOIN act_re_procdef
ON act_hi_procinst.PROC_DEF_ID_ = act_re_procdef.ID_
<if test="wfId != null and wfId !=''">
AND act_re_procdef.KEY_ = #{wfId}
</if>
WHERE 1=1
<include refid="allColumnCond"/>
</select>
<select id="countAllByNodeId" parameterType="java.util.Map" resultType="java.lang.Integer">
select
COUNT(1)
from pex_bill inner join act_hi_procinst
on pex_bill.bill_id=act_hi_procinst.business_key_
<if test="cond.creator != null and cond.creator != ''">
AND act_hi_procinst.START_USER_ID_=#{cond.creator}
</if>
INNER JOIN act_re_procdef
ON act_hi_procinst.PROC_DEF_ID_ = act_re_procdef.ID_
AND act_re_procdef.KEY_ IN
<foreach collection="list" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
WHERE 1=1
and (bill_func ='apply' or bill_func = 'expense' or bill_func = 'loan')
<if test="cond.createdTimeStart != null and cond.createdTimeStart != ''">
AND created_time >=#{cond.createdTimeStart,jdbcType=VARCHAR}
</if>
<if test="cond.createdTimeEnd != null and cond.createdTimeEnd != ''">
AND created_time <=#{cond.createdTimeEnd,jdbcType=VARCHAR}
</if>
<if test="cond.billNo != null and cond.billNo != ''">
AND bill_no=#{cond.billNo,jdbcType=VARCHAR}
</if>
<if test="cond.agyCode != null and cond.agyCode != ''">
AND agy_code=#{cond.agyCode,jdbcType=VARCHAR}
</if>
<if test="cond.fiscal != null">
AND fiscal=#{cond.fiscal,jdbcType=INTEGER}
</if>
<if test="cond.billId != null and cond.billId != ''">
AND bill_id=#{cond.billId,jdbcType=VARCHAR}
</if>
<if test="cond.creator != null and cond.creator != ''">
AND creator=#{cond.creator,jdbcType=VARCHAR}
</if>
<if test="cond.billFunc != null and cond.billFunc != ''">
AND bill_func=#{cond.billFunc,jdbcType=VARCHAR}
</if>
<if test="cond.billType != null and cond.billType != ''">
AND bill_type=#{cond.billType,jdbcType=VARCHAR}
</if>
</select>