Parcourir la source

开心灵工订单列表查询接口-sql调整,优化查询

ZhangWenQiang il y a 5 ans
Parent
commit
842a9e9582

+ 34 - 42
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/modules/hlworder/mapper/xml/HlwOrderMapper.xml

@@ -44,51 +44,43 @@
 
     <select id="queryOrderList" resultType="org.jeecg.modules.hlworder.entity.HlwOrder">
         SELECT
-        t.*,
-        case when count(usId) = (SELECT count(su.id) from hlw_subcontractor su ) then 1 ELSE 0 end as "contractStatus"
-        FROM
-        (
-            SELECT
-            a.*, us.id as "usId"
-            FROM hlw_order a
-            LEFT JOIN hlw_requirement r ON r.id = a.requirement_id
-            LEFT JOIN hlw_company com ON com.id = r.company_id
-            left join hlw_user_subcontractor us on us.order_code = a.order_code
-            <where>
-                1=1
-                and r.application_id = #{applicationId}
-                <if test="companyCodeList != null and companyCodeList.size() != 0">
-                    and com.company_code in
-                    <foreach collection="companyCodeList" index="index" item="code" open="(" separator="," close=")">
-                        #{code}
-                    </foreach>
-                </if>
-                <if test="hlwOrder.orderCode != null and hlwOrder.orderCode != ''">
-                    and a.order_code LIKE concat('%',#{hlwOrder.orderCode},'%')
-                </if>
-                <if test="hlwOrder.requireCode != null and  hlwOrder.requireCode != ''">
-                    and r.requirement_code LIKE concat('%',#{hlwOrder.requireCode},'%')
-                </if>
-                <if test="hlwOrder.status != null ">
-                    and a.status = #{hlwOrder.status}
-                </if>
-                <if test="hlwOrder.userName != null and hlwOrder.userName !=''">
-                    and a.user_name LIKE concat('%',#{hlwOrder.userName},'%')
-                </if>
-                <if test="hlwOrder.companyName != null and hlwOrder.companyName !=''">
-                    and com.company_name LIKE concat('%',#{hlwOrder.companyName},'%')
-                </if>
-                <if test="hlwOrder.createTime_begin != null and hlwOrder.createTime_begin !=''">
-                    and a.create_time between #{hlwOrder.createTime_begin} and #{hlwOrder.createTime_end}
-                </if>
-            </where>
-            ORDER BY a.update_time DESC, a.id ASC
-        ) t
-        GROUP BY t.id
+        a.order_code, case when count(us.id) = (SELECT count(su.id) from hlw_subcontractor su ) then 1 ELSE 0 end as "contractStatus"
+        FROM hlw_order a
+        LEFT JOIN hlw_requirement r ON r.id = a.requirement_id
+        LEFT JOIN hlw_company com ON com.id = r.company_id
+        left join hlw_user_subcontractor us on us.order_code = a.order_code
+        <where>
+            r.application_id = #{applicationId}
+            <if test="companyCodeList != null and companyCodeList.size() != 0">
+                and com.company_code in
+                <foreach collection="companyCodeList" index="index" item="code" open="(" separator="," close=")">
+                    #{code}
+                </foreach>
+            </if>
+            <if test="hlwOrder.orderCode != null and hlwOrder.orderCode != ''">
+                and a.order_code LIKE concat('%',#{hlwOrder.orderCode},'%')
+            </if>
+            <if test="hlwOrder.requireCode != null and  hlwOrder.requireCode != ''">
+                and r.requirement_code LIKE concat('%',#{hlwOrder.requireCode},'%')
+            </if>
+            <if test="hlwOrder.status != null ">
+                and a.status = #{hlwOrder.status}
+            </if>
+            <if test="hlwOrder.userName != null and hlwOrder.userName !=''">
+                and a.user_name LIKE concat('%',#{hlwOrder.userName},'%')
+            </if>
+            <if test="hlwOrder.companyName != null and hlwOrder.companyName !=''">
+                and com.company_name LIKE concat('%',#{hlwOrder.companyName},'%')
+            </if>
+            <if test="hlwOrder.createTime_begin != null and hlwOrder.createTime_begin !=''">
+                and a.create_time between #{hlwOrder.createTime_begin} and #{hlwOrder.createTime_end}
+            </if>
+        </where>
+        GROUP BY a.id
         <if test="hlwOrder.contractStatus != null ">
             HAVING contractStatus = #{hlwOrder.contractStatus}
         </if>
-        ORDER BY t.update_time DESC, t.id ASC
+        ORDER BY a.update_time DESC, a.id ASC
     </select>
 
     <select id="queryOrderListNoPage" resultType="org.jeecg.modules.hlworder.entity.HlwOrder">