¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.vci.ubcs.flow.engine.envent; |
| | | |
| | | import com.vci.ubcs.flow.core.constant.ProcessConstant; |
| | | 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.TaskListener; |
| | | import org.flowable.engine.impl.el.FixedValue; |
| | | import org.flowable.task.service.delegate.DelegateTask; |
| | | 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 FlowStatusListener implements TaskListener, 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(DelegateTask delegateTask) { |
| | | Map taskVariable = delegateTask.getVariables(); |
| | | boolean pass = (boolean) taskVariable.get(ProcessConstant.PASS_KEY); |
| | | |
| | | //è·åç¶æä¿®æ¹ä¿¡æ¯ |
| | | if(pass){ |
| | | String restURL = remoteMethod.getExpressionText(); |
| | | String status = statusValue.getExpressionText(); |
| | | //è·åä¸å¡æ°æ®ä¿¡æ¯ |
| | | 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(CollectionUtils.isEmpty(oids)){ |
| | | throw new VciBaseException("æ§è¡ç¶æä¿®æ¹äºä»¶æ¶ï¼ä¸å¡æ°æ®oid为空ï¼"); |
| | | } |
| | | if(StringUtils.isEmpty(btmType)){ |
| | | throw new VciBaseException("æ§è¡ç¶æä¿®æ¹äºä»¶æ¶ï¼ä¸å¡ç±»åbtmType为空ï¼"); |
| | | } |
| | | 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(taskVariable); |
| | | flowStatusDTO.setTaskHisVOList(FlowableUtils.listTaskHistory(delegateTask.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")); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |