Browse Source

操作数量为0不创建出入库流水记录

yzc 2 years ago
parent
commit
768c6c4bfc

+ 17 - 14
hx-wms/src/main/java/com/fjhx/wms/service/stock/impl/StockServiceImpl.java

@@ -10,7 +10,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.item.entity.product.po.ProductClassify;
 import com.fjhx.item.entity.product.po.ProductInfo;
-import com.fjhx.item.entity.product.vo.ProductInfoVo;
 import com.fjhx.item.service.product.ProductClassifyService;
 import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.wms.entity.stock.bo.InOutBo;
@@ -33,7 +32,6 @@ import com.fjhx.wms.utils.CodeEnum;
 import com.obs.services.internal.ServiceException;
 import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.utils.wrapper.IWrapper;
-import com.ruoyi.common.utils.wrapper.SqlField;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -73,11 +71,11 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
         wrapper.eq(Stock::getWarehouseId, dto.getId());
 //        wrapper.like(Stock::getQuantity, dto.getKeyword());
         String keyword = dto.getKeyword();
-        if(ObjectUtil.isNotEmpty(keyword)) {
+        if (ObjectUtil.isNotEmpty(keyword)) {
             //根据 库存数量 产品自定义编码 产品名称 过滤
             List<Long> productIds = productInfoService.listObject(ProductInfo::getId,
                     q -> q.like(ProductInfo::getCustomCode, keyword).or().like(ProductInfo::getName, keyword));
-            wrapper.and(q->q.like(Stock::getQuantity,keyword).or().in(Stock::getProductId,productIds));
+            wrapper.and(q -> q.like(Stock::getQuantity, keyword).or().in(Stock::getProductId, productIds));
         }
         wrapper.in(Stock::getProductId, dto.getProductIds());
         wrapper.eq("pi.definition", dto.getDefinition());
@@ -154,7 +152,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
                 BigDecimal defectiveQuantity = json.getBigDecimal("defectiveQuantity");
                 defectiveQuantity = ObjectUtil.isEmpty(defectiveQuantity) ? BigDecimal.ZERO : defectiveQuantity;
                 json.put("defectiveQuantity", defectiveQuantity);
-                item.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+                item.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
             });
         }
 
@@ -179,7 +177,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
             JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
             String warehouseName = warehouseMap.get(json.getLong("warehouseId"));
             json.put("warehouseName", warehouseName);
-            stockVo.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+            stockVo.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
         }
         return page;
     }
@@ -191,11 +189,11 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
         wrapper.eq(Stock::getWarehouseId, dto.getId());
 //        wrapper.like(Stock::getQuantity, dto.getKeyword());
         String keyword = dto.getKeyword();
-        if(ObjectUtil.isNotEmpty(keyword)) {
+        if (ObjectUtil.isNotEmpty(keyword)) {
             //根据 库存数量 产品自定义编码 产品名称 过滤
             List<Long> productIds = productInfoService.listObject(ProductInfo::getId,
                     q -> q.like(ProductInfo::getCustomCode, keyword).or().like(ProductInfo::getName, keyword));
-            wrapper.and(q->q.like(Stock::getQuantity,keyword).or().in(Stock::getProductId,productIds));
+            wrapper.and(q -> q.like(Stock::getQuantity, keyword).or().in(Stock::getProductId, productIds));
         }
         wrapper.eq("pi.definition", dto.getDefinition());
         wrapper.groupBy("s.product_id");
@@ -211,7 +209,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
             BigDecimal defectiveQuantity = stockVo.getDefectiveQuantity();
             defectiveQuantity = defectiveQuantity == null ? BigDecimal.ZERO : defectiveQuantity;
             json.put("defectiveQuantity", defectiveQuantity);
-            stockVo.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+            stockVo.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
         }
 
         //赋值产品名称
@@ -239,7 +237,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
             BigDecimal defectiveQuantity = json.getBigDecimal("defectiveQuantity");
             defectiveQuantity = ObjectUtil.isEmpty(defectiveQuantity) ? BigDecimal.ZERO : defectiveQuantity;
             json.put("defectiveQuantity", defectiveQuantity);
-            item.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+            item.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
         });
 
         //赋值产品分类
@@ -394,6 +392,11 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
 
         List<StockJournalDetails> stockJournalDetailsList = new ArrayList<>();
         for (Stock stock : list) {
+            //忽略操作数量为0的记录 避免出现出入库记录为0的条目
+            if (BigDecimal.ZERO.compareTo(stock.getQuantity()) == 0) {
+                continue;
+            }
+
             Stock oldStocks = stockMap.get(stock.getProductId());
             //如果库存不存在 就创建一条空库存
             if (ObjectUtil.isEmpty(oldStocks)) {
@@ -426,7 +429,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
                 frozenQuantity = frozenQuantity == null ? BigDecimal.ZERO : frozenQuantity;
                 frozenQuantity = frozenQuantity.add(stock.getQuantity());
                 json.put("frozenQuantity", frozenQuantity);
-                oldStocks.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+                oldStocks.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
             } else if (type == 4) {
                 //维多利亚待出库操作次品库存
                 String victoriatouristJson = oldStocks.getVictoriatouristJson();
@@ -442,7 +445,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
                     throw new ServiceException("以下商品次品库存不足,无法出库:" + productInfo.getName());
                 }
                 json.put("defectiveQuantity", defectiveQuantity);
-                oldStocks.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+                oldStocks.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
             } else {
                 throw new ServiceException("未知库存操作类型");
             }
@@ -482,7 +485,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
         }
         stock1.setQuantity(quantity.add(stock.getQuantity()));
         json.put("defectiveQuantity", defectiveQuantity.subtract(stock.getQuantity()));
-        stock1.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+        stock1.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
         updateById(stock1);
     }
 
@@ -521,7 +524,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
         }
         stock1.setQuantity(quantity.subtract(stock.getQuantity()));
         json.put("defectiveQuantity", defectiveQuantity.add(stock.getQuantity()));
-        stock1.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+        stock1.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
         updateById(stock1);
     }