From 63a5194b29ce5206fe6447703fac6e2896965cf0 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期五, 28 八月 2026 23:09:18 +0800
Subject: [PATCH] refactor(database): 优化多处查询排序字段

---
 src/main/resources/mapper/production/ProductionOperationTaskMapper.xml       |    2 +-
 src/main/resources/mapper/sales/SalesLedgerMapper.xml                        |    1 +
 src/main/resources/mapper/stock/StockOutRecordMapper.xml                     |    2 +-
 src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java |    1 +
 src/main/resources/mapper/production/ProductionProductMainMapper.xml         |    2 +-
 src/main/resources/mapper/production/ProductionOrderMapper.xml               |    2 +-
 src/main/resources/mapper/production/ProductionPlanMapper.xml                |    2 +-
 src/main/resources/mapper/sales/ShippingInfoMapper.xml                       |    2 +-
 src/main/resources/mapper/stock/StockInRecordMapper.xml                      |    2 +-
 9 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
index e1e6ffb..249a4fa 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
@@ -129,6 +129,7 @@
         if (purchaseLedger.getApprovalStatus() != null) {
             queryWrapper.eq(PurchaseLedger::getApprovalStatus, purchaseLedger.getApprovalStatus());
         }
+        queryWrapper.orderByDesc(PurchaseLedger::getEntryDate);
         return purchaseLedgerMapper.selectList(queryWrapper);
     }
 
diff --git a/src/main/resources/mapper/production/ProductionOperationTaskMapper.xml b/src/main/resources/mapper/production/ProductionOperationTaskMapper.xml
index 5847f5f..5a1f415 100644
--- a/src/main/resources/mapper/production/ProductionOperationTaskMapper.xml
+++ b/src/main/resources/mapper/production/ProductionOperationTaskMapper.xml
@@ -71,7 +71,7 @@
                 and pot.work_order_no like concat('%', #{c.workOrderNo}, '%')
             </if>
         </where>
-        order by pot.production_order_id desc, poro.drag_sort
+        order by pot.work_order_no desc, poro.drag_sort
     </select>
 
     <select id="selectTaskStatisticsByDate" resultType="com.ruoyi.home.dto.ProductionTaskStatisticsDto">
diff --git a/src/main/resources/mapper/production/ProductionOrderMapper.xml b/src/main/resources/mapper/production/ProductionOrderMapper.xml
index 67cc55b..74e80a9 100644
--- a/src/main/resources/mapper/production/ProductionOrderMapper.xml
+++ b/src/main/resources/mapper/production/ProductionOrderMapper.xml
@@ -134,7 +134,7 @@
         <include refid="ProductionOrderVoColumns" />
         <include refid="ProductionOrderVoFrom" />
         <include refid="ProductionOrderWhere" />
-        order by po.id desc
+        order by po.status  , po.plan_complete_time desc
     </select>
 
     <select id="listProductionOrder" resultMap="ProductionOrderVoResultMap">
diff --git a/src/main/resources/mapper/production/ProductionPlanMapper.xml b/src/main/resources/mapper/production/ProductionPlanMapper.xml
index 69ccd36..724eb83 100644
--- a/src/main/resources/mapper/production/ProductionPlanMapper.xml
+++ b/src/main/resources/mapper/production/ProductionPlanMapper.xml
@@ -58,7 +58,7 @@
                 </if>
             </if>
         </where>
-        ORDER BY COALESCE(pp.id) DESC
+        ORDER BY pp.required_date DESC
     </select>
 
     <select id="selectWithMaterialByIds" resultType="com.ruoyi.production.bean.dto.ProductionPlanDto">
diff --git a/src/main/resources/mapper/production/ProductionProductMainMapper.xml b/src/main/resources/mapper/production/ProductionProductMainMapper.xml
index 2403afe..cf3cf9a 100644
--- a/src/main/resources/mapper/production/ProductionProductMainMapper.xml
+++ b/src/main/resources/mapper/production/ProductionProductMainMapper.xml
@@ -115,7 +115,7 @@
                 and ppm.id = #{c.productMainId}
             </if>
         </where>
-        order by ppm.create_time desc
+        order by ppm.product_no desc
     </select>
 
     <select id="getOrderByMainId" resultType="com.ruoyi.production.pojo.ProductionOrder">
diff --git a/src/main/resources/mapper/sales/SalesLedgerMapper.xml b/src/main/resources/mapper/sales/SalesLedgerMapper.xml
index 2d6b7f8..a8f934d 100644
--- a/src/main/resources/mapper/sales/SalesLedgerMapper.xml
+++ b/src/main/resources/mapper/sales/SalesLedgerMapper.xml
@@ -40,6 +40,7 @@
                 T1.customer_name LIKE CONCAT('%',#{salesLedgerDto.customerName},'%')
             </if>
         </where>
+        order by T1.entry_date desc
     </select>
 
     <select id="selectSalesLedgerListPage" resultType="com.ruoyi.sales.vo.SalesLedgerVo">
diff --git a/src/main/resources/mapper/sales/ShippingInfoMapper.xml b/src/main/resources/mapper/sales/ShippingInfoMapper.xml
index 6fc1842..28345b0 100644
--- a/src/main/resources/mapper/sales/ShippingInfoMapper.xml
+++ b/src/main/resources/mapper/sales/ShippingInfoMapper.xml
@@ -48,7 +48,7 @@
         <if test="req.expressNumber != null and req.expressNumber != ''">
             AND s.express_number LIKE CONCAT('%',#{req.expressNumber},'%')
         </if>
-        order by create_time DESC
+        order by shipping_no DESC
     </select>
     <select id="listAll" resultType="com.ruoyi.sales.pojo.ShippingInfo">
         SELECT
diff --git a/src/main/resources/mapper/stock/StockInRecordMapper.xml b/src/main/resources/mapper/stock/StockInRecordMapper.xml
index a3bf3f9..4f8c583 100644
--- a/src/main/resources/mapper/stock/StockInRecordMapper.xml
+++ b/src/main/resources/mapper/stock/StockInRecordMapper.xml
@@ -132,7 +132,7 @@
                 and p.id in (select id from product_tree)
             </if>
         </where>
-        order by sir.id desc
+        order by sir.inbound_batches desc
     </select>
     <select id="listStockInRecordExportData" resultType="com.ruoyi.stock.execl.StockInRecordExportData">
         SELECT
diff --git a/src/main/resources/mapper/stock/StockOutRecordMapper.xml b/src/main/resources/mapper/stock/StockOutRecordMapper.xml
index ad5976f..ae93650 100644
--- a/src/main/resources/mapper/stock/StockOutRecordMapper.xml
+++ b/src/main/resources/mapper/stock/StockOutRecordMapper.xml
@@ -89,7 +89,7 @@
                 and sor.record_type = #{params.recordType}
             </if>
         </where>
-        order by sor.id desc
+        order by sor.outbound_batches desc
     </select>
 
     <select id="listPageAccountSales" resultType="com.ruoyi.account.bean.vo.sales.SalesOutboundVo">

--
Gitblit v1.9.3