Bläddra i källkod

订单查询sql优化

785834757 2 år sedan
förälder
incheckning
27b0c0e131

+ 1 - 1
src/main/java/com/ydtech/modules/order/controller/InsOrdersController.java

@@ -83,7 +83,7 @@ public class InsOrdersController extends BaseController {
     @PostMapping("/queryPageOrder")
     @ApiOperation(value = "[1]分页查询订单接口")
     public HttpResult<BasePageResult<InsOrders>> queryPageOrder(@RequestBody @Valid OrderQueryVo orderQueryVo) {
-        BasePageResult<InsOrders> quoteResult = this.insOrdersService.queryPageOrder(orderQueryVo);
+        BasePageResult<InsOrders> quoteResult = this.insOrdersService.newQueryPageOrder(orderQueryVo);
         return HttpResult.ok("success", quoteResult);
     }
 

+ 15 - 9
src/main/resources/mapper/modules/order/InsOrdersMapper.xml

@@ -221,11 +221,14 @@
             io.orderno
             from
             ins_orders io
-            left JOIN
-            ins_area_company iac on iac.orderno = io.orderno
+                <!--如果存在 公司查询则进行连表 -->
+            <if test="orderQueryVo.companyId != null and orderQueryVo.companyId != ''">
+                left JOIN
+                ins_area_company iac on iac.orderno = io.orderno
+            </if>
             <where>
                 <if test="orderQueryVo.orderNo != null and orderQueryVo.orderNo != ''">
-                    and io.orderno = #{orderNo}
+                    and io.orderno = #{orderQueryVo.orderNo}
                 </if>
                 <if test="orderQueryVo.deptId != null and orderQueryVo.deptId != '' and isTeamLeader">
                     and io.deptid like "${orderQueryVo.deptId}%"
@@ -246,7 +249,7 @@
                     and io.createtime between #{orderQueryVo.startDate} AND #{orderQueryVo.endDate}
                 </if>
                 <if test="orderQueryVo.companyId != null and orderQueryVo.companyId != ''">
-                    and io.company_id = #{orderQueryVo.companyId}
+                    and iac.company_id = #{orderQueryVo.companyId}
                 </if>
                 <if test="orderQueryVo.userId != null and orderQueryVo.userId != '' and isCdy">
                     and io.operatorid = #{orderQueryVo.userId}
@@ -255,7 +258,7 @@
                     and io.userid = #{orderQueryVo.userId}
                 </if>
             </where>
-            group by orderno
+            group by io.orderno
         )s
     </select>
 
@@ -264,11 +267,14 @@
             io.*
         from
             ins_orders io
-        left JOIN
-                ins_area_company iac on iac.orderno = io.orderno
+        <!--如果存在 公司查询则进行连表 -->
+        <if test="orderQueryVo.companyId != null and orderQueryVo.companyId != ''">
+            left JOIN
+            ins_area_company iac on iac.orderno = io.orderno
+        </if>
         <where>
             <if test="orderQueryVo.orderNo != null and orderQueryVo.orderNo != ''">
-                and io.orderno = #{orderNo}
+                and io.orderno = #{orderQueryVo.orderNo}
             </if>
             <if test="orderQueryVo.deptId != null and orderQueryVo.deptId != '' and isTeamLeader">
                 and io.deptid like "${orderQueryVo.deptId}%"
@@ -289,7 +295,7 @@
                 and io.createtime between #{orderQueryVo.startDate} AND #{orderQueryVo.endDate}
             </if>
             <if test="orderQueryVo.companyId != null and orderQueryVo.companyId != ''">
-                and io.company_id = #{orderQueryVo.companyId}
+                and iac.company_id = #{orderQueryVo.companyId}
             </if>
             <if test="orderQueryVo.userId != null and orderQueryVo.userId != '' and isCdy">
                 and io.operatorid = #{orderQueryVo.userId}