From ba69a4fb6db917d5e4d0fb14c37add8ee859b0e1 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 13 三月 2026 17:57:51 +0800
Subject: [PATCH] 1.耗材迁移 2.仓储物流新增字段(毛重,皮重,净重) 3.设备保养多选(多条定时任务)

---
 src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java |   79 ++++++++++++++++++++++++++-------------
 1 files changed, 53 insertions(+), 26 deletions(-)

diff --git a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
index 99c4544..bc2eb2e 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -5,7 +5,7 @@
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum;
+import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.web.domain.R;
 import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
@@ -19,12 +19,15 @@
 import com.ruoyi.stock.service.StockInRecordService;
 import com.ruoyi.stock.service.StockInventoryService;
 import com.ruoyi.stock.service.StockOutRecordService;
-import lombok.AllArgsConstructor;
+import com.ruoyi.stock.word.WeighbridgeDocGenerator;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -37,13 +40,15 @@
  * @since 2026-01-21 04:16:36
  */
 @Service
-@AllArgsConstructor
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
 public class StockInventoryServiceImpl extends ServiceImpl<StockInventoryMapper, StockInventory> implements StockInventoryService {
 
-    private  StockInventoryMapper stockInventoryMapper;
-    private StockInRecordService stockInRecordService;
-    private StockOutRecordService stockOutRecordService;
-    private SalesLedgerProductMapper salesLedgerProductMapper;
+    private final StockInventoryMapper stockInventoryMapper;
+    private final StockInRecordService stockInRecordService;
+    private final StockOutRecordService stockOutRecordService;
+    private final SalesLedgerProductMapper salesLedgerProductMapper;
+    private final WeighbridgeDocGenerator weighbridgeDocGenerator;
+
     @Override
     public IPage<StockInventoryDto> pagestockInventory(Page page, StockInventoryDto stockInventoryDto) {
         return stockInventoryMapper.pagestockInventory(page, stockInventoryDto);
@@ -57,9 +62,19 @@
         StockInRecordDto stockInRecordDto = new StockInRecordDto();
         stockInRecordDto.setRecordId(stockInventoryDto.getRecordId());
         stockInRecordDto.setRecordType(stockInventoryDto.getRecordType());
-        stockInRecordDto.setStockInNum(stockInventoryDto.getQualitity());
+        stockInRecordDto.setStockInNum(stockInventoryDto.getNetWeight());
+        stockInRecordDto.setWeighingDate(stockInventoryDto.getWeighingDate());
+        stockInRecordDto.setNetWeight(stockInventoryDto.getNetWeight());
+        stockInRecordDto.setGrossWeight(stockInventoryDto.getGrossWeight());
+        stockInRecordDto.setTareWeight(stockInventoryDto.getTareWeight());
+        stockInRecordDto.setLicensePlateNo(stockInventoryDto.getLicensePlateNo());
+        stockInRecordDto.setWeighingOperator(stockInventoryDto.getWeighingOperator());
         stockInRecordDto.setProductModelId(stockInventoryDto.getProductModelId());
+        stockInRecordDto.setProductId(stockInventoryDto.getProductId());
         stockInRecordDto.setType("0");
+        //鐢熸垚纾呭崟
+        String absoluteDocPath = weighbridgeDocGenerator.generateWeighbridgeDoc(stockInRecordDto);
+        stockInRecordDto.setWeighbridgeDocPath(absoluteDocPath);
         stockInRecordService.add(stockInRecordDto);
         //鍐嶈繘琛屾柊澧炲簱瀛樻暟閲忓簱瀛�
         //鍏堟煡璇㈠簱瀛樿〃涓殑浜у搧鏄惁瀛樺湪锛屼笉瀛樺湪鏂板锛屽瓨鍦ㄦ洿鏂�
@@ -67,14 +82,15 @@
         if (ObjectUtils.isEmpty(oldStockInventory)) {
             StockInventory newStockInventory = new StockInventory();
             newStockInventory.setProductModelId(stockInventoryDto.getProductModelId());
-            newStockInventory.setQualitity(stockInventoryDto.getQualitity());
+            newStockInventory.setQualitity(stockInventoryDto.getNetWeight());
             newStockInventory.setVersion(1);
             newStockInventory.setRemark(stockInventoryDto.getRemark());
             newStockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity());
             newStockInventory.setWarnNum(stockInventoryDto.getWarnNum());
             stockInventoryMapper.insert(newStockInventory);
-        }else {
-             stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
+        } else {
+            stockInventoryDto.setQualitity(stockInventoryDto.getNetWeight());
+            stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
         }
         return true;
     }
@@ -83,23 +99,34 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean subtractStockInventory(StockInventoryDto stockInventoryDto) {
-            //  鏂板鍑哄簱璁板綍
+        //  鏂板鍑哄簱璁板綍
         StockOutRecordDto stockOutRecordDto = new StockOutRecordDto();
         stockOutRecordDto.setRecordId(stockInventoryDto.getRecordId());
         stockOutRecordDto.setRecordType(stockInventoryDto.getRecordType());
-        stockOutRecordDto.setStockOutNum(stockInventoryDto.getQualitity());
+        stockInventoryDto.setWeighingDate(stockInventoryDto.getWeighingDate());
+        stockOutRecordDto.setStockOutNum(stockInventoryDto.getNetWeight());
+        stockOutRecordDto.setNetWeight(stockInventoryDto.getNetWeight());
+        stockOutRecordDto.setGrossWeight(stockInventoryDto.getGrossWeight());
+        stockOutRecordDto.setTareWeight(stockInventoryDto.getTareWeight());
+        stockOutRecordDto.setWeighingOperator(stockInventoryDto.getWeighingOperator());
         stockOutRecordDto.setProductModelId(stockInventoryDto.getProductModelId());
+        stockOutRecordDto.setLicensePlateNo(stockInventoryDto.getLicensePlateNo());
+        stockOutRecordDto.setProductId(stockInventoryDto.getProductId());
         stockOutRecordDto.setType("0");
         stockOutRecordService.add(stockOutRecordDto);
         StockInventory oldStockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId()));
-        if (stockInventoryDto.getQualitity().compareTo( oldStockInventory.getQualitity().subtract(oldStockInventory.getLockedQuantity()))>0) {
-            throw new RuntimeException("搴撳瓨涓嶈冻鏃犳硶鍑哄簱");
-        }
         if (ObjectUtils.isEmpty(oldStockInventory)) {
             throw new RuntimeException("浜у搧搴撳瓨涓嶅瓨鍦�");
-        }else {
-            stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto);
         }
+        BigDecimal lockedQty = oldStockInventory.getLockedQuantity();
+        if (lockedQty == null) {
+            lockedQty = BigDecimal.ZERO;
+        }
+        if (stockInventoryDto.getQualitity().compareTo(oldStockInventory.getQualitity().subtract(lockedQty)) > 0) {
+            throw new RuntimeException("搴撳瓨涓嶈冻鏃犳硶鍑哄簱");
+        }
+
+        stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto);
         return true;
     }
 
@@ -122,11 +149,11 @@
                             item.getSpecificationModel().equals(dto.getModel())) {
                         StockInventoryDto stockInventoryDto = new StockInventoryDto();
                         stockInventoryDto.setRecordId(0L);
-                        stockInventoryDto.setRecordType(StockQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode());
+                        stockInventoryDto.setRecordType(StockInQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode());
                         stockInventoryDto.setQualitity(dto.getQualitity());
                         stockInventoryDto.setRemark(dto.getRemark());
                         stockInventoryDto.setWarnNum(dto.getWarnNum());
-                        if (ObjectUtils.isNotEmpty(dto.getLockedQuantity())&&dto.getLockedQuantity().compareTo(dto.getQualitity())>0) {
+                        if (ObjectUtils.isNotEmpty(dto.getLockedQuantity()) && dto.getLockedQuantity().compareTo(dto.getQualitity()) > 0) {
                             throw new RuntimeException("鍐荤粨鏁伴噺涓嶈兘瓒呰繃鏈瀵煎叆鐨勫簱瀛樻暟閲�");
                         }
                         stockInventoryDto.setLockedQuantity(dto.getLockedQuantity());
@@ -165,28 +192,28 @@
 
         List<StockInventoryExportData> list = stockInventoryMapper.listStockInventoryExportData(stockInventoryDto);
         ExcelUtil<StockInventoryExportData> util = new ExcelUtil<>(StockInventoryExportData.class);
-        util.exportExcel(response,list, "搴撳瓨淇℃伅");
+        util.exportExcel(response, list, "搴撳瓨淇℃伅");
     }
 
     @Override
     public IPage<StockInRecordDto> stockInventoryPage(StockInventoryDto stockInventoryDto, Page page) {
-        return stockInventoryMapper.stockInventoryPage(stockInventoryDto,page);
+        return stockInventoryMapper.stockInventoryPage(stockInventoryDto, page);
     }
 
     @Override
     public IPage<StockInventoryDto> stockInAndOutRecord(StockInventoryDto stockInventoryDto, Page page) {
-        return stockInventoryMapper.stockInAndOutRecord(stockInventoryDto,page);
+        return stockInventoryMapper.stockInAndOutRecord(stockInventoryDto, page);
     }
 
     @Override
     public Boolean frozenStock(StockInventoryDto stockInventoryDto) {
         StockInventory stockInventory = stockInventoryMapper.selectById(stockInventoryDto.getId());
-        if (stockInventory.getQualitity().compareTo(stockInventoryDto.getLockedQuantity())<0) {
+        if (stockInventory.getQualitity().compareTo(stockInventoryDto.getLockedQuantity()) < 0) {
             throw new RuntimeException("鍐荤粨鏁伴噺涓嶈兘瓒呰繃搴撳瓨鏁伴噺");
         }
         if (ObjectUtils.isEmpty(stockInventory.getLockedQuantity())) {
             stockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity());
-        }else {
+        } else {
             stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().add(stockInventoryDto.getLockedQuantity()));
         }
         return this.updateById(stockInventory);
@@ -195,7 +222,7 @@
     @Override
     public Boolean thawStock(StockInventoryDto stockInventoryDto) {
         StockInventory stockInventory = stockInventoryMapper.selectById(stockInventoryDto.getId());
-        if (stockInventory.getLockedQuantity().compareTo(stockInventoryDto.getLockedQuantity())<0) {
+        if (stockInventory.getLockedQuantity().compareTo(stockInventoryDto.getLockedQuantity()) < 0) {
             throw new RuntimeException("瑙e喕鏁伴噺涓嶈兘瓒呰繃鍐荤粨鏁伴噺");
         }
         stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().subtract(stockInventoryDto.getLockedQuantity()));

--
Gitblit v1.9.3