Prechádzať zdrojové kódy

试验-接入成渝第三方接口开发
1、查询树之前先看项目下是否只有一颗树

LHB 3 dní pred
rodič
commit
9322abfaa5

+ 11 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/TrialCyTestTypeMapper.java

@@ -17,6 +17,17 @@ public interface TrialCyTestTypeMapper extends BaseMapper<TrialCyTestType> {
     List<TrialCyTestType> getTree(@Param("projectId") Long projectId,
                                   @Param("parentId") String parentId,
                                   @Param("contractId") String contractId);
+
+    int selectTreeContractCount(@Param("projectId") Long projectId);
+
+    /**
+     * 只根据项目id查询树
+     * @param projectId
+     * @param parentId
+     * @return
+     */
+    List<TrialCyTestType> getTree2(Long projectId, String parentId);
+
 }
 
 

+ 12 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/TrialCyTestTypeMapper.xml

@@ -22,4 +22,16 @@
           and father_id = #{parentId}
         order by order_index
     </select>
+    <select id="selectTreeContractCount" resultType="java.lang.Integer">
+        SELECT count(DISTINCT contract_id) FROM `vw_u_trial_cy_tree` where project_id = #{projectId}
+    </select>
+    <select id="getTree2" resultType="org.springblade.business.entity.TrialCyTestType">
+        select
+        <include refid="Base_sql"/>,
+        (select count(1) > 0 from vw_u_trial_cy_tree where father_id = t.id and contract_id = #{contractId}) has_children
+        from vw_u_trial_cy_tree t
+        where project_id = #{projectId}
+        and father_id = #{parentId}
+        order by order_index
+    </select>
 </mapper>

+ 6 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/TrialCyTestTypeServiceImpl.java

@@ -1,5 +1,6 @@
 package org.springblade.business.service.impl;
 
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springblade.business.entity.TrialCyTestType;
 import org.springblade.business.service.TrialCyTestTypeService;
@@ -19,6 +20,11 @@ public class TrialCyTestTypeServiceImpl extends ServiceImpl<TrialCyTestTypeMappe
     implements TrialCyTestTypeService {
     @Override
     public List<TrialCyTestType> getTree(Long projectId, String parentId, String contractId) {
+        //当前项目是否存在合同段单独的分类树
+        int count = baseMapper.selectTreeContractCount(projectId);
+        if(count == 0){
+            return baseMapper.getTree2(projectId, parentId);
+        }
         return baseMapper.getTree(projectId, parentId,contractId);
     }
 }