Explorar el Código

feat:查询异常脚本信息接口

xuezizhuo hace 1 año
padre
commit
0e75cf4085

+ 2 - 0
ruoyi-admin/src/main/resources/application.yml

@@ -166,3 +166,5 @@ parameter:
     FORM_COMMON_GETINFO_IP: http://localhost:8088/dragform/common/getInfo/
     # form项目共通新增接口
     FORM_COMMON_BATCHINSERT_IP: http://localhost:8088/dragform/common/batchInsert
+    # CRM项目根据scriptKeys获取节点脚本详情地址
+    GET_NODESCRIPTS_IP: http://localhost:8080/system/script/selectSysBpmNodeScriptByScriptKeys

+ 11 - 0
ruoyi-common/src/main/java/com/ruoyi/common/config/bpm/BpmProperties.java

@@ -35,6 +35,9 @@ public class BpmProperties {
     @Value("${parameter.ip.FORM_COMMON_BATCHINSERT_IP}")
     public String formCommonBatchInsertIp;
 
+    @Value("${parameter.ip.GET_NODESCRIPTS_IP}")
+    public String getNodeScriptsIp;
+
 
     public String getMainRolesKeyIp() {
         return mainRolesKeyIp;
@@ -91,4 +94,12 @@ public class BpmProperties {
     public void setFormCommonBatchInsertIp(String formCommonBatchInsertIp) {
         this.formCommonBatchInsertIp = formCommonBatchInsertIp;
     }
+
+    public String getGetNodeScriptsIp() {
+        return getNodeScriptsIp;
+    }
+
+    public void setGetNodeScriptsIp(String getNodeScriptsIp) {
+        this.getNodeScriptsIp = getNodeScriptsIp;
+    }
 }

+ 17 - 9
ruoyi-common/src/main/java/com/ruoyi/common/utils/http/sending.java

@@ -19,7 +19,7 @@ public class sending<T> {
     // 创建RestTemplate实例
     RestTemplate restTemplate = new RestTemplate();
 
-    public HttpStatus sendCommonPOST(String url, T param) {
+    public ResponseEntity sendCommonPOST(String url, T param) {
         // 得到当前用户的token  下发流程请求需要携带
         String token = SecurityUtils.getLoginUser().getToken();
         // 设置请求头
@@ -32,21 +32,29 @@ public class sending<T> {
         // 发送POST请求
         ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
         // 处理响应
-        if (response.getStatusCode().is2xxSuccessful()) {
-            String responseBody = response.getBody();
-            System.err.println("Response: " + responseBody);
-            return response.getStatusCode();
-        } else {
-            return response.getStatusCode();
-        }
+        return response;
+//        if (response.getStatusCode().is2xxSuccessful()) {
+//            String responseBody = response.getBody();
+//            System.err.println("Response: " + responseBody);
+//            return response;
+//        } else {
+//            return response.getStatusCode();
+//        }
     }
 
 
     /**
      * 执行流程排产
      */
-    public HttpStatus sendCommonUpdate(T param) {
+    public ResponseEntity sendCommonUpdate(T param) {
         return this.sendCommonPOST(bpmProperties.formCommonUpdateIp, param);
     }
 
+    /**
+     * 根据脚本key得到所有异常脚本信息
+     */
+    public ResponseEntity sendGetScriptInfo(T param) {
+        return this.sendCommonPOST(bpmProperties.getNodeScriptsIp, param);
+    }
+
 }

+ 1 - 1
ruoyi-process-execution/src/main/java/com/ruoyi/execution/produce/dispersed/controller/BpmExecuteProcessController.java

@@ -40,7 +40,7 @@ public class BpmExecuteProcessController extends BaseController {
      */
     // @PreAuthorize("@ss.hasPermi('system:process:list')")
     @GetMapping("/list")
-    public TableDataInfo list(BpmExecuteProcess bpmExecuteProcess) {
+    public TableDataInfo list(BpmExecuteProcess bpmExecuteProcess) throws Exception {
         startPage();
         return getDataTable(bpmExecuteProcessService.selectBpmExecuteProcessList(bpmExecuteProcess));
     }

+ 74 - 29
ruoyi-process-execution/src/main/java/com/ruoyi/execution/produce/dispersed/enetity/runbpm/SysBpmNodeScriptVO.java

@@ -1,9 +1,14 @@
 package com.ruoyi.execution.produce.dispersed.enetity.runbpm;
 
+import com.ruoyi.common.core.domain.BaseEntity;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
 /**
  * 流程节点脚本类
  */
-public class SysBpmNodeScriptVO {
+public class SysBpmNodeScriptVO  extends BaseEntity {
+
 
     /** 编号 */
     private Long id;
@@ -29,62 +34,77 @@ public class SysBpmNodeScriptVO {
     /** 行业分类 */
     private String industryType;
 
-    public Long getId() {
-        return id;
-    }
+    /** 删除标志(0:否;1:是) */
+    private String delFlag;
 
-    public void setId(Long id) {
+    public void setId(Long id)
+    {
         this.id = id;
     }
 
-    public String getScriptKey() {
-        return scriptKey;
+    public Long getId()
+    {
+        return id;
     }
-
-    public void setScriptKey(String scriptKey) {
+    public void setScriptKey(String scriptKey)
+    {
         this.scriptKey = scriptKey;
     }
 
-    public String getScriptFunctionName() {
-        return scriptFunctionName;
+    public String getScriptKey()
+    {
+        return scriptKey;
     }
-
-    public void setScriptFunctionName(String scriptFunctionName) {
+    public void setScriptFunctionName(String scriptFunctionName)
+    {
         this.scriptFunctionName = scriptFunctionName;
     }
 
-    public String getScriptName() {
-        return scriptName;
+    public String getScriptFunctionName()
+    {
+        return scriptFunctionName;
     }
-
-    public void setScriptName(String scriptName) {
+    public void setScriptName(String scriptName)
+    {
         this.scriptName = scriptName;
     }
 
-    public String getScriptFunctionCode() {
-        return scriptFunctionCode;
+    public String getScriptName()
+    {
+        return scriptName;
     }
-
-    public void setScriptFunctionCode(String scriptFunctionCode) {
+    public void setScriptFunctionCode(String scriptFunctionCode)
+    {
         this.scriptFunctionCode = scriptFunctionCode;
     }
 
-    public Long getScriptType() {
-        return scriptType;
+    public String getScriptFunctionCode()
+    {
+        return scriptFunctionCode;
     }
-
-    public void setScriptType(Long scriptType) {
+    public void setScriptType(Long scriptType)
+    {
         this.scriptType = scriptType;
     }
 
-    public String getScriptDescription() {
-        return scriptDescription;
+    public Long getScriptType()
+    {
+        return scriptType;
     }
-
-    public void setScriptDescription(String scriptDescription) {
+    public void setScriptDescription(String scriptDescription)
+    {
         this.scriptDescription = scriptDescription;
     }
 
+    public String getScriptDescription()
+    {
+        return scriptDescription;
+    }
+    public void setDelFlag(String delFlag)
+    {
+        this.delFlag = delFlag;
+    }
+
     public String getIndustryType() {
         return industryType;
     }
@@ -92,4 +112,29 @@ public class SysBpmNodeScriptVO {
     public void setIndustryType(String industryType) {
         this.industryType = industryType;
     }
+
+    public String getDelFlag()
+    {
+        return delFlag;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+                .append("id", getId())
+                .append("scriptKey", getScriptKey())
+                .append("scriptFunctionName", getScriptFunctionName())
+                .append("scriptName", getScriptName())
+                .append("scriptFunctionCode", getScriptFunctionCode())
+                .append("scriptType", getScriptType())
+                .append("scriptDescription", getScriptDescription())
+                .append("industryType",getIndustryType())
+                .append("delFlag", getDelFlag())
+                .append("createBy", getCreateBy())
+                .append("createTime", getCreateTime())
+                .append("updateBy", getUpdateBy())
+                .append("updateTime", getUpdateTime())
+                .toString();
+    }
+
 }

+ 9 - 0
ruoyi-process-execution/src/main/java/com/ruoyi/execution/produce/dispersed/service/IBpmExecuteNodeMiddleService.java

@@ -1,6 +1,7 @@
 package com.ruoyi.execution.produce.dispersed.service;
 
 import com.ruoyi.execution.produce.dispersed.enetity.BpmExecuteNodeMiddle;
+import com.ruoyi.system.entity.CommonEntity;
 
 import java.util.List;
 
@@ -59,4 +60,12 @@ public interface IBpmExecuteNodeMiddleService
      * @return 结果
      */
     public int deleteBpmExecuteNodeMiddleById(Long id);
+
+    /**
+     * 添加异常脚本信息
+     * @param commonEntityList
+     * @return
+     */
+    List<CommonEntity> addExceptionScript(List<CommonEntity> commonEntityList) throws Exception;
+
 }

+ 1 - 1
ruoyi-process-execution/src/main/java/com/ruoyi/execution/produce/dispersed/service/IBpmExecuteProcessService.java

@@ -28,7 +28,7 @@ public interface IBpmExecuteProcessService {
      * @param bpmExecuteProcess 流程执行任务
      * @return 流程执行任务集合
      */
-    public List<CommonEntity> selectBpmExecuteProcessList(BpmExecuteProcess bpmExecuteProcess);
+     List<CommonEntity> selectBpmExecuteProcessList(BpmExecuteProcess bpmExecuteProcess) throws Exception;
 
     /**
      * 新增流程执行任务

+ 75 - 22
ruoyi-process-execution/src/main/java/com/ruoyi/execution/produce/dispersed/service/impl/BpmExecuteNodeMiddleServiceImpl.java

@@ -1,95 +1,148 @@
 package com.ruoyi.execution.produce.dispersed.service.impl;
 
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ruoyi.common.config.bpm.BpmProperties;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.http.sending;
 import com.ruoyi.execution.produce.dispersed.enetity.BpmExecuteNodeMiddle;
+import com.ruoyi.execution.produce.dispersed.enetity.runbpm.SysBpmNodeScriptVO;
+import com.ruoyi.system.entity.CommonEntity;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 import com.ruoyi.execution.produce.dispersed.mapper.BpmExecuteNodeMiddleMapper;
 
 import com.ruoyi.execution.produce.dispersed.service.IBpmExecuteNodeMiddleService;
+import org.springframework.web.client.RestTemplate;
 
 /**
  * 执行流程用户、节点关联脚本中间Service业务层处理
- * 
+ *
  * @author hzh
  * @date 2023-11-01
  */
 @Service
-public class BpmExecuteNodeMiddleServiceImpl implements IBpmExecuteNodeMiddleService 
-{
+public class BpmExecuteNodeMiddleServiceImpl implements IBpmExecuteNodeMiddleService {
     @Autowired
     private BpmExecuteNodeMiddleMapper bpmExecuteNodeMiddleMapper;
 
+    @Autowired
+    private BpmProperties bpmProperties;
+    @Autowired
+    private sending sending;
+    // 创建RestTemplate实例
+    RestTemplate restTemplate = new RestTemplate();
+
     /**
      * 查询执行流程用户、节点关联脚本中间
-     * 
+     *
      * @param id 执行流程用户、节点关联脚本中间主键
      * @return 执行流程用户、节点关联脚本中间
      */
     @Override
-    public BpmExecuteNodeMiddle selectBpmExecuteNodeMiddleById(Long id)
-    {
+    public BpmExecuteNodeMiddle selectBpmExecuteNodeMiddleById(Long id) {
         return bpmExecuteNodeMiddleMapper.selectBpmExecuteNodeMiddleById(id);
     }
 
     /**
      * 查询执行流程用户、节点关联脚本中间列表
-     * 
+     *
      * @param bpmExecuteNodeMiddle 执行流程用户、节点关联脚本中间
      * @return 执行流程用户、节点关联脚本中间
      */
     @Override
-    public List<BpmExecuteNodeMiddle> selectBpmExecuteNodeMiddleList(BpmExecuteNodeMiddle bpmExecuteNodeMiddle)
-    {
+    public List<BpmExecuteNodeMiddle> selectBpmExecuteNodeMiddleList(BpmExecuteNodeMiddle bpmExecuteNodeMiddle) {
         return bpmExecuteNodeMiddleMapper.selectBpmExecuteNodeMiddleList(bpmExecuteNodeMiddle);
     }
 
     /**
      * 新增执行流程用户、节点关联脚本中间
-     * 
+     *
      * @param bpmExecuteNodeMiddle 执行流程用户、节点关联脚本中间
      * @return 结果
      */
     @Override
-    public int insertBpmExecuteNodeMiddle(BpmExecuteNodeMiddle bpmExecuteNodeMiddle)
-    {
+    public int insertBpmExecuteNodeMiddle(BpmExecuteNodeMiddle bpmExecuteNodeMiddle) {
         return bpmExecuteNodeMiddleMapper.insertBpmExecuteNodeMiddle(bpmExecuteNodeMiddle);
     }
 
     /**
      * 修改执行流程用户、节点关联脚本中间
-     * 
+     *
      * @param bpmExecuteNodeMiddle 执行流程用户、节点关联脚本中间
      * @return 结果
      */
     @Override
-    public int updateBpmExecuteNodeMiddle(BpmExecuteNodeMiddle bpmExecuteNodeMiddle)
-    {
+    public int updateBpmExecuteNodeMiddle(BpmExecuteNodeMiddle bpmExecuteNodeMiddle) {
         return bpmExecuteNodeMiddleMapper.updateBpmExecuteNodeMiddle(bpmExecuteNodeMiddle);
     }
 
     /**
      * 批量删除执行流程用户、节点关联脚本中间
-     * 
+     *
      * @param ids 需要删除的执行流程用户、节点关联脚本中间主键
      * @return 结果
      */
     @Override
-    public int deleteBpmExecuteNodeMiddleByIds(Long[] ids)
-    {
+    public int deleteBpmExecuteNodeMiddleByIds(Long[] ids) {
         return bpmExecuteNodeMiddleMapper.deleteBpmExecuteNodeMiddleByIds(ids);
     }
 
     /**
      * 删除执行流程用户、节点关联脚本中间信息
-     * 
+     *
      * @param id 执行流程用户、节点关联脚本中间主键
      * @return 结果
      */
     @Override
-    public int deleteBpmExecuteNodeMiddleById(Long id)
-    {
+    public int deleteBpmExecuteNodeMiddleById(Long id) {
         return bpmExecuteNodeMiddleMapper.deleteBpmExecuteNodeMiddleById(id);
     }
+
+    @Override
+    public List<CommonEntity> addExceptionScript(List<CommonEntity> commonEntityList) throws Exception {
+        //循环得到所有异常脚本key
+        Set<String> scriptKeys = new LinkedHashSet<>();
+        commonEntityList.forEach(m -> {
+            scriptKeys.addAll(Arrays.asList(m.getResultMap().get("benmTaskArtificialScriptKey").toString().split(",")));
+        });
+        if(scriptKeys.size() == 0){
+            return commonEntityList;
+        }
+        //根据异常脚本key得到所有异常脚本信息
+        ResponseEntity responseEntity;
+        try {
+             responseEntity = sending.sendGetScriptInfo(scriptKeys);
+        }catch (Exception e){
+            throw new Exception("网络错误");
+        }
+        if (responseEntity.getStatusCode().is2xxSuccessful()) {
+            ObjectMapper objectMapper = new ObjectMapper();
+            Map<String, Object> map = objectMapper.readValue(responseEntity.getBody().toString(),Map.class);
+            List<Object> sysBpmNodeScriptVOList = (List<Object>) map.get("data");
+            return commonEntityList.stream().map(m -> {
+                List<String> scriptKeyList = Arrays.asList(m.getResultMap().get("benmTaskArtificialScriptKey").toString().split(","));
+                List<SysBpmNodeScriptVO> exceptionScriptList = new ArrayList<>();
+                sysBpmNodeScriptVOList.forEach(s -> {
+                    SysBpmNodeScriptVO sysBpmNodeScriptVO= JSONObject.parseObject(JSON.toJSONString(s),SysBpmNodeScriptVO.class);
+                    if (scriptKeyList.contains(sysBpmNodeScriptVO.getScriptKey())) {
+                        exceptionScriptList.add(sysBpmNodeScriptVO);
+                    }
+                });
+                m.getResultMap().put("exceptionScriptList", exceptionScriptList);
+                return m;
+            }).collect(Collectors.toList());
+        } else {
+            return commonEntityList;
+        }
+
+    }
 }

+ 10 - 5
ruoyi-process-execution/src/main/java/com/ruoyi/execution/produce/dispersed/service/impl/BpmExecuteProcessServiceImpl.java

@@ -9,11 +9,14 @@ import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.execution.produce.dispersed.runbpm.PreExecutionToolClass;
 import com.ruoyi.execution.produce.dispersed.enetity.BpmExecuteProcess;
 import com.ruoyi.execution.produce.dispersed.mapper.BpmExecuteProcessMapper;
+import com.ruoyi.execution.produce.dispersed.service.IBpmExecuteNodeMiddleService;
 import com.ruoyi.system.entity.CommonEntity;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.execution.produce.dispersed.service.IBpmExecuteProcessService;
 
+import javax.annotation.Resource;
+
 /**
  * 流程执行任务Service业务层处理
  *
@@ -29,6 +32,9 @@ public class BpmExecuteProcessServiceImpl implements IBpmExecuteProcessService {
     @Autowired
     private PreExecutionToolClass ipreExecutionToolClass;
 
+    @Resource
+    private IBpmExecuteNodeMiddleService bpmExecuteNodeMiddleService;
+
     /**
      * 查询流程执行任务
      *
@@ -47,7 +53,7 @@ public class BpmExecuteProcessServiceImpl implements IBpmExecuteProcessService {
      * @return 流程执行任务
      */
     @Override
-    public List<CommonEntity> selectBpmExecuteProcessList(BpmExecuteProcess bpmExecuteProcess) {
+    public List<CommonEntity> selectBpmExecuteProcessList(BpmExecuteProcess bpmExecuteProcess) throws Exception {
         List<SysRole> sysRoles = SecurityUtils.getLoginUser().getUser().getRoles();
 
         List<String> roles = new ArrayList<>();
@@ -62,11 +68,10 @@ public class BpmExecuteProcessServiceImpl implements IBpmExecuteProcessService {
         objectMap.put("userId", SecurityUtils.getUserId());
         // 得到当前发起请求的用户角色列表
         objectMap.put("taskRealRoleList", roles);
-        System.out.println(objectMap.toString());
-
-
         // 首先根据当前登陆用户得到他可以执行的所有节点
-        return runBpmExecuteProcessMapper.queryExecuteProcess(objectMap);
+        List<CommonEntity> commonEntities = runBpmExecuteProcessMapper.queryExecuteProcess(objectMap);
+        // 查询异常脚本信息
+        return bpmExecuteNodeMiddleService.addExceptionScript(commonEntities);
     }
 
     /**