Przeglądaj źródła

提供其他数据库递归查询语句

caixiaofeng 5 miesięcy temu
rodzic
commit
525a9f84db

+ 27 - 12
flow-app/src/main/resources/mapper/system/DeptDao.xml

@@ -14,21 +14,36 @@
         <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
     </resultMap>
 
-    <select id="getList" resultMap="BaseResultMap">
+    <sql id="getList_mysql">
         with recursive cte as (
-            select * from sys_dept
-            <where>
-                <if test="deptQuery.pid != null and deptQuery.pid != ''">
-                    and pid = #{deptQuery.pid}
-                </if>
-                <if test="deptQuery.name != null and deptQuery.name != ''">
-                    and name like concat('%',#{deptQuery.name},'%')
-                </if>
-            </where>
-            UNION
-            select sm.* from sys_dept sm, cte where sm.id = cte.pid
+        select * from sys_dept
+        <where>
+            <include refid="deptWheres"></include>
+        </where>
+        UNION
+        select sm.* from sys_dept sm, cte where sm.id = cte.pid
         )
         select * from cte order by sort asc
+    </sql>
+
+    <sql id="getList_oracle">
+        SELECT * FROM SYS_DEPT
+        START WITH
+        <include refid="deptWheres"></include>
+        CONNECT BY PRIOR pid = id
+    </sql>
+
+    <sql id="deptWheres">
+        <if test="deptQuery.pid != null and deptQuery.pid != ''">
+            and pid = #{deptQuery.pid}
+        </if>
+        <if test="deptQuery.name != null and deptQuery.name != ''">
+            and name like concat('%',#{deptQuery.name},'%')
+        </if>
+    </sql>
+
+    <select id="getList" resultMap="BaseResultMap">
+        <include refid="getList_mysql"></include>
     </select>
 
 

+ 22 - 7
flow-app/src/main/resources/mapper/system/MenuDao.xml

@@ -24,21 +24,36 @@
         <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
     </resultMap>
 
-    <select id="getTree" resultMap="BaseResultMap">
+    <sql id="menuWheres">
+        <if test="menuQuery.pid != null and menuQuery.pid != ''">
+            and pid = #{menuQuery.pid}
+        </if>
+        <if test="menuQuery.title != null and menuQuery.title != ''">
+            and title like concat('%',#{menuQuery.title},'%')
+        </if>
+    </sql>
+
+    <sql id="getTree_mysql">
         with recursive cte as (
             select * from sys_menu
             <where>
-                <if test="menuQuery.pid != null and menuQuery.pid != ''">
-                    and pid = #{menuQuery.pid}
-                </if>
-                <if test="menuQuery.title != null and menuQuery.title != ''">
-                    and title like concat('%',#{menuQuery.title},'%')
-                </if>
+                <include refid="menuWheres"></include>
             </where>
             UNION
             select sm.* from sys_menu sm, cte where sm.id = cte.pid
         )
         select * from cte order by sort asc
+    </sql>
+
+    <sql id="getTree_oracle">
+        SELECT * FROM SYS_MENU
+        START WITH
+        <include refid="menuWheres"></include>
+        CONNECT BY PRIOR pid = id
+    </sql>
+
+    <select id="getTree" resultMap="BaseResultMap">
+        <include refid="getTree_mysql"></include>
     </select>
 
 

+ 3 - 3
flow-workflow/flow-workflow-biz/src/main/java/com/flow/listener/GlobalActivityEventListener.java

@@ -99,9 +99,9 @@ public class GlobalActivityEventListener extends AbstractFlowableEngineEventList
         }
 
         // 审批人与发起人是同一人时
-        String initiator = execution.getVariable("initiator", String.class);
-        if (entity.getAssignee().equals(initiator)) {
-            if ("skip".equals(same)) {
+        if ("skip".equals(same)) {
+            String initiator = execution.getVariable("initiator", String.class);
+            if (entity.getAssignee().equals(initiator)) {
                 flowTaskService.autoComplete(entity.getId(), " 审批人是发起人");
                 return;
             }