Browse Source

feat:流程节点校验接口

xuezizhuo 1 year ago
parent
commit
647cb23af0

+ 11 - 5
ruoyi-admin/src/main/resources/application.yml

@@ -9,13 +9,13 @@ ruoyi:
   # 实例演示开关
   demoEnabled: true
   # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
-  profile: /Users/zrwj/Desktop/ZKQY_LJJ/log/file/
+  profile: D:/ruoyi/uploadPath
   # 获取ip地址开关
   addressEnabled: false
   # 验证码类型 math 数组计算 char 字符验证
   captchaType: math
   # 流程文件存储地址
-  bpmnPath: /Users/zrwj/Desktop/ZKQY_LJJ/log/file/bpmnXML/
+  bpmnPath: D:/ruoyi/uploadPath
 
 
 # 开发环境配置
@@ -87,13 +87,13 @@ spring:
   # redis 配置
   redis:
     # 地址
-    host: 192.168.110.15
+    host: localhost
     # 端口,默认为6379
     port: 6379
     # 数据库索引
     database: 0
     # 密码
-    password:
+    password: 123456
     # 连接超时时间
     timeout: 10s
     lettuce:
@@ -153,4 +153,10 @@ xss:
 parameter:
   ip:
     # 用户下对应的所有角色key
-    MAIN_ROLESKEY_IP: http://127.0.0.1:8080/system/user/roleKeyByUserId/
+    MAIN_ROLESKEY_IP: http://127.0.0.1:8080/system/user/roleKeyByUserId/
+    # CRM项目根据scriptKey获取节点脚本详情地址
+    GET_NODESCRIPT_IP: http://localhost:8080/system/script/selectSysBpmNodeScriptByScriptKey/
+    # crm项目查看角色下是否存在真实用户
+    QUERY_USER_EXISTS_BY_ROLEKEY_IP: http://localhost:8080/system/role/selectUserByRoleKey/
+    # crm项目查看一组用户是否存在真实用户
+    QUERY_USER_EXISTS_BY_USERIDS_IP: http://localhost:8080/system/user/selectUserByUserIds/

+ 0 - 16
ruoyi-common/src/main/java/com/ruoyi/common/config/Bpm/BpmProperties.java

@@ -1,16 +0,0 @@
-package com.ruoyi.common.config.bpm;
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @author hmc
- * @date 2023-11-02 18:07
- * @Description:
- */
-@Configuration
-public class BpmProperties {
-    //根据用户id查询当前用户所具备的角色key的ip地址 MAIN_ROLESKEY_IP
-    @Value("${parameter.ip.MAIN_ROLESKEY_IP}")
-    public static final String mainRolesKeyIp = "";
-}

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

@@ -0,0 +1,58 @@
+package com.ruoyi.common.config.bpm;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author hmc
+ * @date 2023-11-02 18:07
+ * @Description:
+ */
+@Configuration
+public class BpmProperties {
+    //根据用户id查询当前用户所具备的角色key的ip地址 MAIN_ROLESKEY_IP
+    @Value("${parameter.ip.MAIN_ROLESKEY_IP}")
+    public String mainRolesKeyIp;
+
+    /** 根据scriptKey获取节点脚本详情地址 */
+    @Value("${parameter.ip.GET_NODESCRIPT_IP}")
+    public String getNodeScriptIp;
+
+    @Value("${parameter.ip.QUERY_USER_EXISTS_BY_ROLEKEY_IP}")
+    public String queryUserExistsByRoleKeyIp;
+
+    @Value("${parameter.ip.QUERY_USER_EXISTS_BY_USERIDS_IP}")
+    public String queryUserExistsByUserIdsIp;
+
+    public String getMainRolesKeyIp() {
+        return mainRolesKeyIp;
+    }
+
+    public void setMainRolesKeyIp(String mainRolesKeyIp) {
+        this.mainRolesKeyIp = mainRolesKeyIp;
+    }
+
+    public void setGetNodeScriptIp(String getNodeScriptIp) {
+        this.getNodeScriptIp = getNodeScriptIp;
+    }
+
+    public String getGetNodeScriptIp() {
+        return getNodeScriptIp;
+    }
+
+    public String getQueryUserExistsByRoleKeyIp() {
+        return queryUserExistsByRoleKeyIp;
+    }
+
+    public void setQueryUserExistsByRoleKeyIp(String queryUserExistsByRoleKeyIp) {
+        this.queryUserExistsByRoleKeyIp = queryUserExistsByRoleKeyIp;
+    }
+
+    public String getQueryUserExistsByUserIdsIp() {
+        return queryUserExistsByUserIdsIp;
+    }
+
+    public void setQueryUserExistsByUserIdsIp(String queryUserExistsByUserIdsIp) {
+        this.queryUserExistsByUserIdsIp = queryUserExistsByUserIdsIp;
+    }
+}

+ 86 - 0
ruoyi-process-execution/src/main/java/com/ruoyi/execution/produce/dispersed/service/impl/utils/VerifyExecutionProcess.java

@@ -1,6 +1,21 @@
 package com.ruoyi.execution.produce.dispersed.service.impl.utils;
 
+import com.ruoyi.common.config.bpm.BpmProperties;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.execution.produce.RunImplementationClass;
+import com.ruoyi.system.entity.BpmNodeHandleUser;
+import com.ruoyi.system.entity.BpmNodeScriptRelevance;
+import com.ruoyi.system.entity.BpmProcessConfiguration;
+import com.ruoyi.system.service.IBpmNodeHandleUserService;
+import com.ruoyi.system.service.IBpmNodeScriptRelevanceService;
+import com.ruoyi.system.service.IBpmProcessConfigurationService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author hanzihang
@@ -10,7 +25,78 @@ import org.springframework.stereotype.Component;
 @Component
 public class VerifyExecutionProcess {
 
+    @Autowired
+    private IBpmProcessConfigurationService bpmProcessConfigurationService;
+
+    @Autowired
+    private IBpmNodeScriptRelevanceService bpmNodeScriptRelevanceService;
+
+    @Autowired
+    private IBpmNodeHandleUserService bpmNodeHandleUserService;
+
+    @Autowired
+    private RunImplementationClass runImplementationClass;
+
+    @Autowired
+    private BpmProperties bpmProperties;
+
+    /*
+      判断是否有开始结束节点,有,循环判断每一个节点是否包含自动执行脚本,并且脚本是否存在,
+      节点是否绑定角色权限,真实角色下是否存在可处理用户,虚拟角色下用户是否都真实存在
+    */
     public boolean VerifyProcessData(String processKey) {
+        RestTemplate restTemplate = new RestTemplate();
+        // 根据流程编号(node_process_key)查询流程配置表(bpm_process_configuration)得到该流程所有节点信息
+        BpmProcessConfiguration bpmProcessConfiguration = new BpmProcessConfiguration();
+        bpmProcessConfiguration.setNodeProcessKey(processKey);
+        List<BpmProcessConfiguration> bpmProcessConfigurationList = bpmProcessConfigurationService.selectBpmProcessConfigurationList(bpmProcessConfiguration);
+        // 定义变量开始节点(startNode),结束节点(endNode)
+        int startNode = 0;
+        int endNode = 0;
+        for (BpmProcessConfiguration b : bpmProcessConfigurationList) {
+            //判断节点前后是否执行自动脚本,并且脚本是否存在
+            if (b.getNodeBefore().equals("true") || b.getNodeAfter().equals("true")) {
+                // 查询自动执行脚本
+                BpmNodeScriptRelevance bpmNodeScriptRelevance = bpmNodeScriptRelevanceService.selectAutoScriptByNodeKey(b.getNodeKey());
+                 if (bpmNodeScriptRelevance != null) {
+                     // 获取执行脚本名称,判断脚本是否存在
+                     AjaxResult ajaxResult = restTemplate.getForObject(bpmProperties.getNodeScriptIp + bpmNodeScriptRelevance.getScriptKey(), AjaxResult.class);
+                     if(Long.valueOf(ajaxResult.get("code").toString()) != 200L){
+                         return false;
+                     }
+                     Map<String,Object> map = (Map<String,Object>)ajaxResult.get("data");
+                     runImplementationClass.isVerificationMethod(map.get("scriptFunctionName").toString());
+                 }else {
+                     return false;
+                 }
+            }else {
+                return false;
+            }
+            //判断节点是否绑定角色权限,真实角色下是否存在可处理用户,虚拟角色下用户是否都真实存在
+            if (StringUtils.isNotEmpty(b.getNodeRolePermission())) {
+                BpmNodeHandleUser bpmNodeHandleUser = bpmNodeHandleUserService.selectBpmNodeHandleUserByVirtuallyRole(b.getNodeRolePermission());
+                // 真实角色不为空查询真实角色下是否存在可处理用户
+                if (StringUtils.isNotEmpty(bpmNodeHandleUser.getRealRole())) {
+                    AjaxResult ajaxResult = restTemplate.getForObject(bpmProperties.queryUserExistsByRoleKeyIp + bpmNodeHandleUser.getRealRole(),AjaxResult.class);
+                    Long count = Long.valueOf(ajaxResult.get("data").toString());
+                    if (count <= 0) {
+                        return false;
+                    }
+                }
+                // 虚拟角色下用户是否都真实存在
+                if(StringUtils.isNotEmpty(bpmNodeHandleUser.getExecuteUserNo())){
+                    AjaxResult ajaxResult = restTemplate.getForObject(bpmProperties.queryUserExistsByUserIdsIp + bpmNodeHandleUser.getExecuteUserNo(),AjaxResult.class);
+                    Long count = Long.valueOf(ajaxResult.get("data").toString());
+                    if (count <= 0) {
+                        return false;
+                    }
+                }
+            }else {
+                return false;
+            }
+            if (b.getNodeType().equals("startEvent")) startNode++;
+            if (b.getNodeType().equals("endEvent")) endNode++;
+        }
         return true;
     }
 

+ 7 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/BpmNodeHandleUserMapper.java

@@ -58,4 +58,11 @@ public interface BpmNodeHandleUserMapper
      * @return 结果
      */
     public int deleteBpmNodeHandleUserByIds(Long[] ids);
+
+    /**
+     * 根据虚拟角色查询节点处理用户
+     * @param virtuallyRole
+     * @return
+     */
+    BpmNodeHandleUser selectBpmNodeHandleUserByVirtuallyRole(String virtuallyRole);
 }

+ 7 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/BpmNodeScriptRelevanceMapper.java

@@ -58,4 +58,11 @@ public interface BpmNodeScriptRelevanceMapper
      * @return 结果
      */
     public int deleteBpmNodeScriptRelevanceByIds(Long[] ids);
+
+    /**
+     * 查询自动执行脚本
+     * @param nodeKey 节点key
+     * @return
+     */
+    BpmNodeScriptRelevance selectAutoScriptByNodeKey(String nodeKey);
 }

+ 7 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IBpmNodeHandleUserService.java

@@ -58,4 +58,11 @@ public interface IBpmNodeHandleUserService
      * @return 结果
      */
     public int deleteBpmNodeHandleUserById(Long id);
+
+    /**
+     * 根据虚拟角色查询节点处理用户
+     * @param virtuallyRole
+     * @return
+     */
+    BpmNodeHandleUser selectBpmNodeHandleUserByVirtuallyRole(String virtuallyRole);
 }

+ 7 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IBpmNodeScriptRelevanceService.java

@@ -58,4 +58,11 @@ public interface IBpmNodeScriptRelevanceService {
      * @return 结果
      */
     public int deleteBpmNodeScriptRelevanceById(Long id);
+
+    /**
+     * 查询自动执行脚本
+     * @param nodeKey 节点key
+     * @return
+     */
+    BpmNodeScriptRelevance selectAutoScriptByNodeKey(String nodeKey);
 }

+ 5 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BpmNodeHandleUserServiceImpl.java

@@ -91,4 +91,9 @@ public class BpmNodeHandleUserServiceImpl implements IBpmNodeHandleUserService {
     public int deleteBpmNodeHandleUserById(Long id) {
         return bpmNodeHandleUserMapper.deleteBpmNodeHandleUserById(id);
     }
+
+    @Override
+    public BpmNodeHandleUser selectBpmNodeHandleUserByVirtuallyRole(String virtuallyRole) {
+        return bpmNodeHandleUserMapper.selectBpmNodeHandleUserByVirtuallyRole(virtuallyRole);
+    }
 }

+ 5 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BpmNodeScriptRelevanceServiceImpl.java

@@ -90,4 +90,9 @@ public class BpmNodeScriptRelevanceServiceImpl implements IBpmNodeScriptRelevanc
     public int deleteBpmNodeScriptRelevanceById(Long id) {
         return bpmNodeScriptRelevanceMapper.deleteBpmNodeScriptRelevanceById(id);
     }
+
+    @Override
+    public BpmNodeScriptRelevance selectAutoScriptByNodeKey(String nodeKey) {
+        return bpmNodeScriptRelevanceMapper.selectAutoScriptByNodeKey(nodeKey);
+    }
 }

+ 17 - 13
ruoyi-system/src/main/resources/mapper/bpm/BpmNodeHandleUserMapper.xml

@@ -49,17 +49,21 @@
         where id = #{id}
     </update>
 
-<delete id="deleteBpmNodeHandleUserById" parameterType="Long">
-update
-    bpm_node_handle_user
-set del_flag = '2'
-where id = #{id}
-</delete>
+    <delete id="deleteBpmNodeHandleUserById" parameterType="Long">
+        delete from bpm_node_handle_user
+        where id = #{id}
+    </delete>
+
+    <delete id="deleteBpmNodeHandleUserByIds" parameterType="String">
+        delete from bpm_node_handle_user where id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+
+    <select id="selectBpmNodeHandleUserByVirtuallyRole" parameterType="String" resultMap="BpmNodeHandleUserResult">
+        <include refid="selectBpmNodeHandleUserVo"/>
+        where virtually_role = #{virtuallyKole}
+    </select>
 
-<delete id="deleteBpmNodeHandleUserByIds" parameterType="String">
-update bpm_node_handle_user set del_flag = '2' where id in
-<foreach item="id" collection="array" open="(" separator="," close=")">
-    #{id}
-</foreach>
-</delete>
-        </mapper>
+</mapper>

+ 8 - 3
ruoyi-system/src/main/resources/mapper/bpm/BpmNodeScriptRelevanceMapper.xml

@@ -51,15 +51,20 @@
     </update>
 
     <delete id="deleteBpmNodeScriptRelevanceById" parameterType="Long">
-        update bpm_node_script_relevance
-        set del_flag = '2'
+        delete from bpm_node_script_relevance
         where id = #{id}
     </delete>
 
     <delete id="deleteBpmNodeScriptRelevanceByIds" parameterType="String">
-        update bpm_node_script_relevance set del_flag = '2' where id in
+        delete from bpm_node_script_relevance where id in
         <foreach item="id" collection="array" open="(" separator="," close=")">
             #{id}
         </foreach>
     </delete>
+
+    <select id="selectAutoScriptByNodeKey" resultMap="BpmNodeScriptRelevanceResult">
+        <include refid="selectBpmNodeScriptRelevanceVo"/>
+        where node_key = #{nodeKey} and script_trigger_type = 1
+    </select>
+
 </mapper>