ソースを参照

库存查询 自定义排序 排序问题处理

yzc 1 年間 前
コミット
0110ea9f4b

+ 58 - 38
hx-wms/src/main/java/com/fjhx/wms/service/stock/impl/StockServiceImpl.java

@@ -80,9 +80,36 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
         wrapper.eq("pi.definition", dto.getDefinition());
 
         //库存查询排序 按 可用库存,冻结库存,次品库存,最后入库时间 排序
-        customSort(wrapper, dto);
-        wrapper.orderByDesc("s", Stock::getId);
+        if (ObjectUtil.isNotEmpty(dto.getQuantitySort())) {
+            if (1 == dto.getQuantitySort()) {
+                wrapper.orderByAsc("s.quantity");
+            } else {
+                wrapper.orderByDesc("s.quantity");
+            }
+        }
+        if (ObjectUtil.isNotEmpty(dto.getFrozenQuantitySort())) {
+            if (1 == dto.getFrozenQuantitySort()) {
+                wrapper.orderByAsc("(json_unquote( s.victoriatourist_json -> '$.frozenQuantity' )+0)");
+            } else {
+                wrapper.orderByDesc("(json_unquote( s.victoriatourist_json -> '$.frozenQuantity' )+0)");
+            }
+        }
+        if (ObjectUtil.isNotEmpty(dto.getDefectiveQuantitySort())) {
+            if (1 == dto.getDefectiveQuantitySort()) {
+                wrapper.orderByAsc("(json_unquote( s.victoriatourist_json -> '$.defectiveQuantity' )+0)");
+            } else {
+                wrapper.orderByDesc("(json_unquote( s.victoriatourist_json -> '$.defectiveQuantity' )+0)");
+            }
+        }
+        if (ObjectUtil.isNotEmpty(dto.getUpdateTimeSort())) {
+            if (1 == dto.getUpdateTimeSort()) {
+                wrapper.orderByAsc("s.update_time");
+            } else {
+                wrapper.orderByDesc("s.update_time");
+            }
+        }
 
+        wrapper.orderByDesc("s", Stock::getId);
         Page<StockVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
         List<StockVo> stockVos = page.getRecords();
         //赋值产品信息
@@ -200,9 +227,36 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
         wrapper.eq("pi.definition", dto.getDefinition());
         wrapper.groupBy("s.product_id");
         //库存查询排序 按 可用库存,冻结库存,次品库存,最后入库时间 排序
-        customSort(wrapper, dto);
-        wrapper.orderByDesc("s", Stock::getId);
+        if (ObjectUtil.isNotEmpty(dto.getQuantitySort())) {
+            if (1 == dto.getQuantitySort()) {
+                wrapper.orderByAsc("sum(s.quantity)");
+            } else {
+                wrapper.orderByDesc("sum(s.quantity)");
+            }
+        }
+        if (ObjectUtil.isNotEmpty(dto.getFrozenQuantitySort())) {
+            if (1 == dto.getFrozenQuantitySort()) {
+                wrapper.orderByAsc("sum(json_unquote( s.victoriatourist_json -> '$.frozenQuantity' )+0)");
+            } else {
+                wrapper.orderByDesc("sum(json_unquote( s.victoriatourist_json -> '$.frozenQuantity' )+0)");
+            }
+        }
+        if (ObjectUtil.isNotEmpty(dto.getDefectiveQuantitySort())) {
+            if (1 == dto.getDefectiveQuantitySort()) {
+                wrapper.orderByAsc("sum(json_unquote( s.victoriatourist_json -> '$.defectiveQuantity' )+0)");
+            } else {
+                wrapper.orderByDesc("sum(json_unquote( s.victoriatourist_json -> '$.defectiveQuantity' )+0)");
+            }
+        }
+        if (ObjectUtil.isNotEmpty(dto.getUpdateTimeSort())) {
+            if (1 == dto.getUpdateTimeSort()) {
+                wrapper.orderByAsc("s.update_time");
+            } else {
+                wrapper.orderByDesc("s.update_time");
+            }
+        }
 
+        wrapper.orderByDesc("s", Stock::getId);
         Page<StockVo> page = this.baseMapper.pageByProduct(dto.getPage(), wrapper);
         List<StockVo> stockVos = page.getRecords();
 
@@ -640,38 +694,4 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
         stockJournalDetailsService.saveBatch(journalDetailsList);
     }
 
-    /**
-     * 库存查询排序 按 可用库存,冻结库存,次品库存,最后入库时间 排序
-     */
-    private void customSort(IWrapper wrapper, StockSelectDto dto) {
-        if (ObjectUtil.isNotEmpty(dto.getQuantitySort())) {
-            if (1 == dto.getQuantitySort()) {
-                wrapper.orderByAsc("s.quantity");
-            } else {
-                wrapper.orderByDesc("s.quantity");
-            }
-        }
-        if (ObjectUtil.isNotEmpty(dto.getFrozenQuantitySort())) {
-            if (1 == dto.getFrozenQuantitySort()) {
-                wrapper.orderByAsc("json_unquote( s.victoriatourist_json -> '$.frozenQuantity' )");
-            } else {
-                wrapper.orderByDesc("json_unquote( s.victoriatourist_json -> '$.frozenQuantity' )");
-            }
-        }
-        if (ObjectUtil.isNotEmpty(dto.getDefectiveQuantitySort())) {
-            if (1 == dto.getDefectiveQuantitySort()) {
-                wrapper.orderByAsc("json_unquote( s.victoriatourist_json -> '$.defectiveQuantity' )");
-            } else {
-                wrapper.orderByDesc("json_unquote( s.victoriatourist_json -> '$.defectiveQuantity' )");
-            }
-        }
-        if (ObjectUtil.isNotEmpty(dto.getUpdateTimeSort())) {
-            if (1 == dto.getUpdateTimeSort()) {
-                wrapper.orderByAsc("s.update_time");
-            } else {
-                wrapper.orderByDesc("s.update_time");
-            }
-        }
-    }
-
 }