From 77d1bc79748c2a66d637be5ab108e3131a0b3b37 Mon Sep 17 00:00:00 2001 From: 田源 <lastanimals@163.com> Date: 星期五, 04 八月 2023 17:33:04 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowExecutionEndListener.java | 102 ++++++++++++++++++++++++ Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowExecutionStartListener.java | 88 ++++++++++++++++++++- Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowStatusListener.java | 8 +- 3 files changed, 185 insertions(+), 13 deletions(-) diff --git a/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowExecutionEndListener.java b/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowExecutionEndListener.java index 2d19f54..d1a818d 100644 --- a/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowExecutionEndListener.java +++ b/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowExecutionEndListener.java @@ -1,19 +1,115 @@ package com.vci.ubcs.flow.engine.envent; +import com.vci.ubcs.flow.core.dto.FlowStatusDTO; +import com.vci.ubcs.flow.engine.constant.FlowEngineConstant; +import com.vci.ubcs.flow.engine.utils.FlowableUtils; +import com.vci.ubcs.starter.exception.VciBaseException; +import com.vci.ubcs.starter.web.util.LangBaseUtil; +import com.vci.ubcs.starter.web.util.VciBaseUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.flowable.engine.HistoryService; +import org.flowable.engine.TaskService; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; +import org.flowable.engine.impl.el.FixedValue; +import org.springblade.core.jwt.JwtUtil; +import org.springblade.core.launch.constant.TokenConstant; +import org.springblade.core.tool.utils.WebUtil; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; +import java.util.List; import java.util.Map; @Slf4j @Component -public class FlowExecutionEndListener implements ExecutionListener { +public class FlowExecutionEndListener implements ExecutionListener, ApplicationContextAware { + + /** + * 杩滅▼璋冪敤鍦板潃銆傚垏璁帮細鍚嶇О瑕佷笌娴佺▼涓畾涔夌殑涓�鏍� + */ + private FixedValue remoteMethod; + + /** + * 鐘舵�佸�笺�傚垏璁帮細鍚嶇О瑕佷笌娴佺▼涓畾涔夌殑涓�鏍� + */ + private FixedValue statusValue; + + private static ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext arg0) throws BeansException { + applicationContext = arg0; + } @Override public void notify(DelegateExecution execution) { - Map var = execution.getVariableInstances(); - log.info("鎵ц娴佺▼FlowExecutionEndListener",var); + Map variables = execution.getVariables(); + String restURL = remoteMethod.getExpressionText(); + String status = statusValue.getExpressionText(); + //鑾峰彇涓氬姟鏁版嵁淇℃伅 + List<String> oids = (List<String>) variables.get(FlowEngineConstant.OIDS); + String btmType = (String) variables.get(FlowEngineConstant.BTMTYPE); + + variables.put(FlowEngineConstant.REMOTE_METHOD,restURL); + variables.put(FlowEngineConstant.STATUS_VALUE,status); + + if(CollectionUtils.isEmpty(oids)){ + throw new VciBaseException("鎵ц鐘舵�佷慨鏀逛簨浠舵椂锛屼笟鍔℃暟鎹畂id涓虹┖锛�"); + } + if(StringUtils.isEmpty(btmType)){ + throw new VciBaseException("鎵ц鐘舵�佷慨鏀逛簨浠舵椂锛屼笟鍔$被鍨媌tmType涓虹┖锛�"); + } + if(StringUtils.isEmpty(restURL)){ + throw new VciBaseException("鎵ц鐘舵�佷慨鏀逛簨浠舵椂锛岃繙绋嬭皟鐢ㄥ湴鍧�涓虹┖锛�"); + } + if(StringUtils.isEmpty(status)){ + throw new VciBaseException("鎵ц鐘舵�佷慨鏀逛簨浠舵椂锛岀姸鎬佷负绌猴紒"); + } + + HistoryService historyService = applicationContext.getBean(HistoryService.class); + TaskService taskService = applicationContext.getBean(TaskService.class); + + FlowStatusDTO flowStatusDTO = new FlowStatusDTO(); + flowStatusDTO.setBtmType(btmType); + flowStatusDTO.setOids(oids); + flowStatusDTO.setVariableMap(variables); + flowStatusDTO.setTaskHisVOList(FlowableUtils.listTaskHistory(execution.getProcessInstanceId(),historyService,taskService)); + + String token = JwtUtil.getToken(WebUtil.getRequest().getHeader(TokenConstant.HEADER)); + + HttpComponentsClientHttpRequestFactory requestFactory=new HttpComponentsClientHttpRequestFactory(); + requestFactory.setReadTimeout(300000); + requestFactory.setConnectionRequestTimeout(300000); + requestFactory.setConnectTimeout(300000); + RestTemplate restTemplate = new RestTemplate(requestFactory); + HttpHeaders headers = new HttpHeaders(); + headers.add(TokenConstant.HEADER,token); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity httpEntity = new HttpEntity<>(flowStatusDTO,headers); + Map<String, Object> result = null; + try { + result = restTemplate.postForObject(restURL, httpEntity, Map.class); + } catch (HttpClientErrorException e) { + throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{},e); + }catch (Throwable e){ + throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{},e); + } + if(result == null){ + throw new VciBaseException("涓氬姟浜嬩欢鏃跺�欐病鏈夎繑鍥炲�硷紝涓嶇‘瀹氭槸鍚︽墽琛屾垚鍔�"); + } + if(CollectionUtils.isEmpty(result) && !(Boolean) result.get("success")){ + throw new VciBaseException((String) result.get("message")); + } } } diff --git a/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowExecutionStartListener.java b/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowExecutionStartListener.java index 7cf0d5e..85cf487 100644 --- a/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowExecutionStartListener.java +++ b/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowExecutionStartListener.java @@ -1,25 +1,101 @@ package com.vci.ubcs.flow.engine.envent; import com.vci.ubcs.code.feign.IFlowEventClient; +import com.vci.ubcs.flow.core.dto.FlowStatusDTO; +import com.vci.ubcs.flow.engine.constant.FlowEngineConstant; +import com.vci.ubcs.starter.exception.VciBaseException; +import com.vci.ubcs.starter.web.util.LangBaseUtil; +import com.vci.ubcs.starter.web.util.VciBaseUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; +import org.flowable.engine.impl.el.FixedValue; +import org.springblade.core.jwt.JwtUtil; +import org.springblade.core.launch.constant.TokenConstant; +import org.springblade.core.tool.utils.WebUtil; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; +import java.util.List; import java.util.Map; @Slf4j -//@Component +@Component public class FlowExecutionStartListener implements ExecutionListener { - @Autowired(required = false) - private IFlowEventClient iFlowEventClient; + + /** + * 杩滅▼璋冪敤鍦板潃銆傚垏璁帮細鍚嶇О瑕佷笌娴佺▼涓畾涔夌殑涓�鏍� + */ + private FixedValue remoteMethod; + + /** + * 鐘舵�佸�笺�傚垏璁帮細鍚嶇О瑕佷笌娴佺▼涓畾涔夌殑涓�鏍� + */ + private FixedValue statusValue; @Override public void notify(DelegateExecution execution) { - Map var = execution.getVariableInstances(); - iFlowEventClient.flowStart(var); - log.info("鎵ц娴佺▼FlowExecutionStartListener",var); + Map variables = execution.getVariables(); + + String restURL = remoteMethod.getExpressionText(); + String status = statusValue.getExpressionText(); + //鑾峰彇涓氬姟鏁版嵁淇℃伅 + List<String> oids = (List<String>) variables.get(FlowEngineConstant.OIDS); + String btmType = (String) variables.get(FlowEngineConstant.BTMTYPE); + + variables.put(FlowEngineConstant.REMOTE_METHOD,restURL); + variables.put(FlowEngineConstant.STATUS_VALUE,status); + + if(CollectionUtils.isEmpty(oids)){ + throw new VciBaseException("鎵ц鐘舵�佷慨鏀逛簨浠舵椂锛屼笟鍔℃暟鎹畂id涓虹┖锛�"); + } + if(StringUtils.isEmpty(btmType)){ + throw new VciBaseException("鎵ц鐘舵�佷慨鏀逛簨浠舵椂锛屼笟鍔$被鍨媌tmType涓虹┖锛�"); + } + if(StringUtils.isEmpty(restURL)){ + throw new VciBaseException("鎵ц鐘舵�佷慨鏀逛簨浠舵椂锛岃繙绋嬭皟鐢ㄥ湴鍧�涓虹┖锛�"); + } + if(StringUtils.isEmpty(status)){ + throw new VciBaseException("鎵ц鐘舵�佷慨鏀逛簨浠舵椂锛岀姸鎬佷负绌猴紒"); + } + + FlowStatusDTO flowStatusDTO = new FlowStatusDTO(); + flowStatusDTO.setBtmType(btmType); + flowStatusDTO.setOids(oids); + flowStatusDTO.setVariableMap(variables); + + String token = JwtUtil.getToken(WebUtil.getRequest().getHeader(TokenConstant.HEADER)); + HttpComponentsClientHttpRequestFactory requestFactory=new HttpComponentsClientHttpRequestFactory(); + requestFactory.setReadTimeout(300000); + requestFactory.setConnectionRequestTimeout(300000); + requestFactory.setConnectTimeout(300000); + RestTemplate restTemplate = new RestTemplate(requestFactory); + HttpHeaders headers = new HttpHeaders(); + headers.add(TokenConstant.HEADER,token); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity httpEntity = new HttpEntity<>(flowStatusDTO,headers); + Map<String, Object> result = null; + try { + result = restTemplate.postForObject(restURL, httpEntity, Map.class); + } catch (HttpClientErrorException e) { + throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{},e); + }catch (Throwable e){ + throw new VciBaseException(LangBaseUtil.getErrorMsg(e),new String[]{},e); + } + if(result == null){ + throw new VciBaseException("涓氬姟浜嬩欢鏃跺�欐病鏈夎繑鍥炲�硷紝涓嶇‘瀹氭槸鍚︽墽琛屾垚鍔�"); + } + if(CollectionUtils.isEmpty(result) && !(Boolean) result.get("success")){ + throw new VciBaseException((String) result.get("message")); + } } } diff --git a/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowStatusListener.java b/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowStatusListener.java index f932e49..ffe275d 100644 --- a/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowStatusListener.java +++ b/Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/engine/envent/FlowStatusListener.java @@ -29,6 +29,7 @@ import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; +import java.util.List; import java.util.Map; @Slf4j @@ -62,13 +63,13 @@ String restURL = remoteMethod.getExpressionText(); String status = statusValue.getExpressionText(); //鑾峰彇涓氬姟鏁版嵁淇℃伅 - String oids = (String) taskVariable.get(FlowEngineConstant.OIDS); + List<String> oids = (List<String>) taskVariable.get(FlowEngineConstant.OIDS); String btmType = (String) taskVariable.get(FlowEngineConstant.BTMTYPE); taskVariable.put(FlowEngineConstant.REMOTE_METHOD,restURL); taskVariable.put(FlowEngineConstant.STATUS_VALUE,status); - if(StringUtils.isEmpty(oids)){ + if(CollectionUtils.isEmpty(oids)){ throw new VciBaseException("鎵ц鐘舵�佷慨鏀逛簨浠舵椂锛屼笟鍔℃暟鎹畂id涓虹┖锛�"); } if(StringUtils.isEmpty(btmType)){ @@ -86,7 +87,7 @@ FlowStatusDTO flowStatusDTO = new FlowStatusDTO(); flowStatusDTO.setBtmType(btmType); - flowStatusDTO.setOids(VciBaseUtil.str2List(oids)); + flowStatusDTO.setOids(oids); flowStatusDTO.setVariableMap(taskVariable); flowStatusDTO.setTaskHisVOList(FlowableUtils.listTaskHistory(delegateTask.getProcessInstanceId(),historyService,taskService)); @@ -115,7 +116,6 @@ if(CollectionUtils.isEmpty(result) && !(Boolean) result.get("success")){ throw new VciBaseException((String) result.get("message")); } - } } -- Gitblit v1.9.3