Forráskód Böngészése

代码优化调整

gaodm 6 éve
szülő
commit
10275eea5e
1 módosított fájl, 92 hozzáadás és 80 törlés
  1. 92 80
      aipt-service/src/main/resources/mapper/ConceptMapper.xml

+ 92 - 80
aipt-service/src/main/resources/mapper/ConceptMapper.xml

@@ -24,6 +24,50 @@
         FROM
             `kl_concept` t1,
             `kl_relation` t2,
+            <if test="startSex != null or startAge != null">
+                (
+                SELECT
+                concept_id
+                FROM
+                kl_concept_common
+                WHERE
+                is_deleted = 'N'
+                <if test="startSex != null">
+                    <if test="startSex == 3">
+                        and sex_type in ('1','2','3')
+                    </if>
+                    <if test="startSex != 3">
+                        and sex_type in ('3',#{startSex})
+                    </if>
+                </if>
+                <if test="startAge != null">
+                    <![CDATA[ AND min_age <= #{startAge} ]]>
+                    <![CDATA[ AND max_age >= #{startAge} ]]>
+                </if>
+                ) c1,
+            </if>
+            <if test="endSex != null or endAge != null">
+                (
+                SELECT
+                concept_id
+                FROM
+                kl_concept_common
+                WHERE
+                is_deleted = 'N'
+                <if test="endSex != null">
+                    <if test="endSex == 3">
+                        and sex_type in ('1','2','3')
+                    </if>
+                    <if test="endSex != 3">
+                        and sex_type in ('3',#{endSex})
+                    </if>
+                </if>
+                <if test="endAge != null">
+                    <![CDATA[ AND min_age <= #{endAge} ]]>
+                    <![CDATA[ AND max_age >= #{endAge} ]]>
+                </if>
+                ) c2,
+            </if>
             `kl_concept` t3
         WHERE
             t1.is_deleted = 'N'
@@ -38,26 +82,7 @@
             AND t1.lib_name = #{startName}
         </if>
         <if test="startSex != null or startAge != null">
-            AND t2.start_id in (
-            SELECT
-            concept_id
-            FROM
-            kl_concept_common
-            WHERE
-            is_deleted = 'N'
-            <if test="startSex != null">
-                <if test="startSex == 3">
-                    and sex_type in ('1','2','3')
-                </if>
-                <if test="startSex != 3">
-                    and sex_type in ('3',#{startSex})
-                </if>
-            </if>
-            <if test="startAge != null">
-                <![CDATA[ AND min_age <= #{startAge} ]]>
-                <![CDATA[ AND max_age >= #{startAge} ]]>
-            </if>
-            )
+            AND t2.start_id = c1.concept_id
         </if>
         <if test="startType != null">
             AND t1.lib_type = #{startType}
@@ -72,26 +97,7 @@
             AND t3.lib_name = #{endName}
         </if>
         <if test="endSex != null or endAge != null">
-            AND t2.end_id in (
-            SELECT
-            concept_id
-            FROM
-            kl_concept_common
-            WHERE
-            is_deleted = 'N'
-            <if test="endSex != null">
-                <if test="endSex == 3">
-                    and sex_type in ('1','2','3')
-                </if>
-                <if test="endSex != 3">
-                    and sex_type in ('3',#{endSex})
-                </if>
-            </if>
-            <if test="endAge != null">
-                <![CDATA[ AND min_age <= #{endAge} ]]>
-                <![CDATA[ AND max_age >= #{endAge} ]]>
-            </if>
-            )
+            AND t2.end_id = c2.concept_id
         </if>
         <if test="endType != null">
             AND t3.lib_type = #{endType}
@@ -108,6 +114,50 @@
         FROM
             `kl_concept` t1,
             `kl_relation` t2,
+            <if test="startSex != null or startAge != null">
+                (
+                SELECT
+                concept_id
+                FROM
+                kl_concept_common
+                WHERE
+                is_deleted = 'N'
+                <if test="startSex != null">
+                    <if test="startSex == 3">
+                        and sex_type in ('1','2','3')
+                    </if>
+                    <if test="startSex != 3">
+                        and sex_type in ('3',#{startSex})
+                    </if>
+                </if>
+                <if test="startAge != null">
+                    <![CDATA[ AND min_age <= #{startAge} ]]>
+                    <![CDATA[ AND max_age >= #{startAge} ]]>
+                </if>
+                ) c1,
+            </if>
+            <if test="endSex != null or endAge != null">
+                (
+                SELECT
+                concept_id
+                FROM
+                kl_concept_common
+                WHERE
+                is_deleted = 'N'
+                <if test="endSex != null">
+                    <if test="endSex == 3">
+                        and sex_type in ('1','2','3')
+                    </if>
+                    <if test="endSex != 3">
+                        and sex_type in ('3',#{endSex})
+                    </if>
+                </if>
+                <if test="endAge != null">
+                    <![CDATA[ AND min_age <= #{endAge} ]]>
+                    <![CDATA[ AND max_age >= #{endAge} ]]>
+                </if>
+                ) c2,
+            </if>
             `kl_concept` t3,
             `kl_relation_order` t4
         WHERE
@@ -125,26 +175,7 @@
             AND t1.lib_name = #{startName}
         </if>
         <if test="startSex != null or startAge != null">
-            AND t2.start_id in (
-            SELECT
-            concept_id
-            FROM
-            kl_concept_common
-            WHERE
-            is_deleted = 'N'
-            <if test="startSex != null">
-                <if test="startSex == 3">
-                    and sex_type in ('1','2','3')
-                </if>
-                <if test="startSex != 3">
-                    and sex_type in ('3',#{startSex})
-                </if>
-            </if>
-            <if test="startAge != null">
-                <![CDATA[ AND min_age <= #{startAge} ]]>
-                <![CDATA[ AND max_age >= #{startAge} ]]>
-            </if>
-            )
+            AND t2.start_id = c1.concept_id
         </if>
         <if test="startType != null">
             AND t1.lib_type = #{startType}
@@ -159,26 +190,7 @@
             AND t3.lib_name = #{endName}
         </if>
         <if test="endSex != null or endAge != null">
-            AND t2.end_id in (
-            SELECT
-            concept_id
-            FROM
-            kl_concept_common
-            WHERE
-            is_deleted = 'N'
-            <if test="endSex != null">
-                <if test="endSex == 3">
-                    and sex_type in ('1','2','3')
-                </if>
-                <if test="endSex != 3">
-                    and sex_type in ('3',#{endSex})
-                </if>
-            </if>
-            <if test="endAge != null">
-                <![CDATA[ AND min_age <= #{endAge} ]]>
-                <![CDATA[ AND max_age >= #{endAge} ]]>
-            </if>
-            )
+            AND t2.end_id = c2.concept_id
         </if>
         <if test="endType != null">
             AND t3.lib_type = #{endType}