فهرست منبع

档案系统-文件收集分页查询 优化拓展id查询sql组装

LHB 2 ماه پیش
والد
کامیت
e9001900d1

+ 8 - 8
blade-service/blade-archive/src/main/java/org/springblade/archive/controller/ArchiveFileController.java

@@ -161,15 +161,15 @@ public class ArchiveFileController extends BladeController {
                 queryVo.setExtType(1);
             }
 
-            List<ArchiveTreeContract> archiveTreeContracts = this.archiveTreeContractClient.queryAllChildByAncestors(queryVo.getNodeIds(), queryVo.getContractId() == null ? null : Long.parseLong(queryVo.getContractId()));
-            if (archiveTreeContracts != null && archiveTreeContracts.size() > 0) {
-                List<String> ids = JSONArray.parseArray(JSONObject.toJSONString(archiveTreeContracts.stream().map(ArchiveTreeContract::getId).distinct().collect(Collectors.toList())), String.class);
-                ids.add(queryVo.getNodeIds());
-                queryVo.setNodeIdArray(ids);
-            }
+//            List<ArchiveTreeContract> archiveTreeContracts = this.archiveTreeContractClient.queryAllChildByAncestors(queryVo.getNodeIds(), queryVo.getContractId() == null ? null : Long.parseLong(queryVo.getContractId()));
+//            if (archiveTreeContracts != null && archiveTreeContracts.size() > 0) {
+//                List<String> ids = JSONArray.parseArray(JSONObject.toJSONString(archiveTreeContracts.stream().map(ArchiveTreeContract::getId).distinct().collect(Collectors.toList())), String.class);
+//                ids.add(queryVo.getNodeIds());
+//                queryVo.setNodeIdArray(ids);
+//            }
             //优化
-//            String authCode = this.archiveTreeContractClient.getAuthCode(queryVo.getContractId() == null ? null : Long.parseLong(queryVo.getContractId()));
-//            queryVo.setAuthCode(authCode);
+            String authCode = this.archiveTreeContractClient.getAuthCode(queryVo.getContractId() == null ? null : Long.parseLong(queryVo.getContractId()));
+            queryVo.setAuthCode(authCode);
         }
         return R.data(this.archiveFileClient.selectArchiveFilePage(queryVo));
     }

+ 34 - 30
blade-service/blade-business/src/main/java/org/springblade/business/mapper/ArchiveFileMapper.xml

@@ -74,6 +74,9 @@
         select count(u.id) from u_archive_file u
         <if test="vo.nodeIds != null and vo.nodeIds != ''">
             left join m_archive_tree_contract t on t.id = u.node_id
+            <if test="vo.extType != null">
+                LEFT JOIN m_archive_tree_contract m ON m.id = u.node_ext_id
+            </if>
         </if>
         where u.is_deleted = 0
         <if test="vo.isApprovalValue != null and vo.isApprovalValue != ''">
@@ -119,25 +122,24 @@
         <!--            </otherwise>-->
         <!--        </choose>-->
         <if test="vo.nodeIds != null and vo.nodeIds != ''">
-            and
             <choose>
-                <!-- 当存在扩展类型时,同时查 node_id 和 node_ext_id -->
                 <when test="vo.extType != null">
-                    (u.node_id in
-                    <foreach collection="vo.nodeIdArray" item="nodeId" open="(" separator="," close=")">
-                        #{nodeId}
-                    </foreach>
-                    OR u.node_ext_id in
-                    <foreach collection="vo.nodeIdArray" item="nodeId" open="(" separator="," close=")">
-                        #{nodeId}
-                    </foreach>)
+                    and (find_in_set( #{vo.nodeIds}, t.ancestors ) or t.id = #{vo.nodeIds} or find_in_set( #{vo.nodeIds}, m.ancestors ) or m.id = #{vo.nodeIds})
                 </when>
-                <!-- 默认只查 node_id -->
                 <otherwise>
-                    u.node_id in
-                    <foreach collection="vo.nodeIdArray" item="nodeId" open="(" separator="," close=")">
-                        #{nodeId}
-                    </foreach>
+                    and (find_in_set( #{vo.nodeIds}, t.ancestors ) or t.id = #{vo.nodeIds})
+                </otherwise>
+            </choose>
+        </if>
+        <if test="vo.authCode !=null and vo.authCode !=''">
+            <choose>
+                <when test="vo.extType != null">
+                    AND (t.tree_code = #{authCode} or t.tree_code = #{contractId} or t.parent_id = 0
+                        or m.tree_code = #{authCode} or m.tree_code = #{contractId} or m.parent_id = 0
+                    )
+                </when>
+                <otherwise>
+                    AND (t.tree_code = #{authCode} or t.tree_code = #{contractId} or t.parent_id = 0)
                 </otherwise>
             </choose>
         </if>
@@ -157,6 +159,9 @@
         select u.* from u_archive_file u
         <if test="vo.nodeIds != null and vo.nodeIds != ''">
             left join m_archive_tree_contract t on t.id = u.node_id
+            <if test="vo.extType != null">
+                LEFT JOIN m_archive_tree_contract m ON m.id = u.node_ext_id
+            </if>
         </if>
         where u.is_deleted = 0
         <if test="vo.isApprovalValue != null and vo.isApprovalValue != ''">
@@ -202,25 +207,24 @@
         <!--            </otherwise>-->
         <!--        </choose>-->
         <if test="vo.nodeIds != null and vo.nodeIds != ''">
-            and
             <choose>
-                <!-- 当存在扩展类型时,同时查 node_id 和 node_ext_id -->
                 <when test="vo.extType != null">
-                    (u.node_id in
-                    <foreach collection="vo.nodeIdArray" item="nodeId" open="(" separator="," close=")">
-                        #{nodeId}
-                    </foreach>
-                    OR u.node_ext_id in
-                    <foreach collection="vo.nodeIdArray" item="nodeId" open="(" separator="," close=")">
-                        #{nodeId}
-                    </foreach>)
+                    and (find_in_set( #{vo.nodeIds}, t.ancestors ) or t.id = #{vo.nodeIds} or find_in_set( #{vo.nodeIds}, m.ancestors ) or m.id = #{vo.nodeIds})
+                </when>
+                <otherwise>
+                    and (find_in_set( #{vo.nodeIds}, t.ancestors ) or t.id = #{vo.nodeIds})
+                </otherwise>
+            </choose>
+        </if>
+        <if test="vo.authCode !=null and vo.authCode !=''">
+            <choose>
+                <when test="vo.extType != null">
+                    AND (t.tree_code = #{authCode} or t.tree_code = #{contractId} or t.parent_id = 0
+                    or m.tree_code = #{authCode} or m.tree_code = #{contractId} or m.parent_id = 0
+                    )
                 </when>
-                <!-- 默认只查 node_id -->
                 <otherwise>
-                    u.node_id in
-                    <foreach collection="vo.nodeIdArray" item="nodeId" open="(" separator="," close=")">
-                        #{nodeId}
-                    </foreach>
+                    AND (t.tree_code = #{authCode} or t.tree_code = #{contractId} or t.parent_id = 0)
                 </otherwise>
             </choose>
         </if>