Przeglądaj źródła

档案系统-收集文件计数改为 子查询处理计数

LHB 1 miesiąc temu
rodzic
commit
59dace4c48

+ 29 - 12
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ArchiveTreeContractMapper.xml

@@ -102,6 +102,7 @@
         <result column="value" property="value"/>
         <result column="key" property="key"/>
         <result column="contract_id" property="contractId"/>
+        <result column="project_id" property="projectId"/>
         <result column="has_children" property="hasChildren"/>
         <result column="displayHierarchy" property="displayHierarchy"/>
         <result column="majorDataType" property="majorDataType"/>
@@ -131,7 +132,9 @@
         <result column="reviewer" property="reviewer"/>
         <result column="specification" property="specification"/>
         <result column="archive_name_suffix" property="archiveNameSuffix"/>
-        <result column="tree_number" property="treeNumber"/>
+<!--        <result column="tree_number" property="treeNumber"/>-->
+        <association property="treeNumber" javaType="java.lang.Integer" select="selectFileNumber"
+                     column="{id=id,projectId=project_id,code=code,contractId=contract_id,extType=ext_type}"/>
     </resultMap>
 
 
@@ -230,17 +233,9 @@
         d.specification,
         d.archive_name_suffix,
         d.contract_id,
-        (SELECT CASE WHEN count(1) > 0 THEN 1 ELSE 0 END FROM m_archive_tree_contract WHERE parent_id = d.id and is_deleted = 0 and project_id = #{projectId})
-        AS "has_children",
-        (SELECT  count(1)  FROM m_archive_tree_contract a
-                        inner join u_archive_file b on b.node_id = a.id and b.is_deleted = a.is_deleted and b.project_id = a.project_id and (b.is_auto_file is null or b.is_auto_file != 1)
-                           WHERE  a.is_deleted = 0
-                             and a.project_id = #{projectId}
-                             and (FIND_IN_SET(d.id,a.ancestors) or a.id = d.id)
-        <if test="code!=null and code!=''">
-            AND (a.tree_code = #{code} or a.tree_code = #{contractId} or a.parent_id = 0)
-        </if>
-        ) as tree_number
+        d.project_id,
+        #{code} as code,
+        (SELECT CASE WHEN count(1) > 0 THEN 1 ELSE 0 END FROM m_archive_tree_contract WHERE parent_id = d.id and is_deleted = 0 and project_id = #{projectId}) AS "has_children"
         FROM
         m_archive_tree_contract d
         WHERE
@@ -253,6 +248,28 @@
         </if>
         ORDER BY d.tree_sort, d.sort
     </select>
+    <!-- 文件收集 归档树的文件数量 -->
+    <select id="selectFileNumber" resultType="java.lang.Integer">
+        SELECT  count(1)  FROM m_archive_tree_contract a
+        inner join u_archive_file b on b.node_id = a.id and b.is_deleted = a.is_deleted and b.project_id = a.project_id and (b.is_auto_file is null or b.is_auto_file != 1)
+        WHERE  a.is_deleted = 0
+        and a.project_id = #{projectId}
+        <choose>
+            <when test="extType != null and extType == 1">
+                and ( 	b.node_id in( select id from  m_archive_tree_contract where FIND_IN_SET(#{id},ancestors) or a.id = #{id}) OR
+                b.node_ext_id in(  select id from  m_archive_tree_contract where FIND_IN_SET(#{id},ancestors) or a.id = #{id}))
+            </when>
+            <otherwise>
+                and (FIND_IN_SET(#{id},a.ancestors) or a.id = #{id})
+            </otherwise>
+        </choose>
+
+        <if test="code!=null and code!=''">
+            AND (a.tree_code = #{code} or a.tree_code = #{contractId} or a.parent_id = 0)
+        </if>
+    </select>
+
+
 
     <select id="tree2" resultMap="ArchiveTreeContractVO2ResultMap">
         SELECT