From e0cfecb2b11b3d6ac91394e71c689a30356ead28 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期三, 20 五月 2026 09:29:28 +0800
Subject: [PATCH] fix:1.生产按照特定工序更改 2.库存按照型号,工序类别,电压进行筛选 3.销售页面展示电压,类别 4.生产入库按照电压入库

---
 src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java |   75 ++++++++++++++++++++++++-------------
 1 files changed, 48 insertions(+), 27 deletions(-)

diff --git a/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java b/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
index 4154682..32e5259 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
@@ -10,12 +10,11 @@
 import com.ruoyi.common.utils.EnumUtil;
 import com.ruoyi.common.utils.OrderUtils;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.security.LoginUser;
 import com.ruoyi.stock.dto.StockInRecordDto;
-import com.ruoyi.stock.dto.StockInventoryDto;
-import com.ruoyi.stock.dto.StockUninventoryDto;
 import com.ruoyi.stock.execl.StockInRecordExportData;
 import com.ruoyi.stock.mapper.StockInRecordMapper;
 import com.ruoyi.stock.mapper.StockInventoryMapper;
@@ -30,6 +29,8 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.util.List;
 
 @Service
@@ -49,7 +50,6 @@
         return stockInRecordMapper.listPage(page, stockInRecordDto);
     }
 
-    // 鏂板鍏ュ簱
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Long add(StockInRecordDto stockInRecordDto) {
@@ -57,18 +57,14 @@
         stockInRecordDto.setInboundBatches(no);
         StockInRecord stockInRecord = new StockInRecord();
         BeanUtils.copyProperties(stockInRecordDto, stockInRecord);
-
         int insertRows = stockInRecordMapper.insert(stockInRecord);
-
         Long insertId = stockInRecord.getId();
-
         return insertRows > 0 ? insertId : null;
     }
 
     @Override
     @Transactional(rollbackFor = Exception.class)
     public int update(Long id, StockInRecordDto stockInRecordDto) {
-        // 鍒ゆ柇瀵硅薄鏄惁瀛樺湪
         StockInRecord stockInRecord = stockInRecordMapper.selectById(id);
         if (stockInRecord == null) {
             throw new BaseException("璇ュ叆搴撹褰曚笉瀛樺湪,鏃犳硶鏇存柊!!!");
@@ -84,26 +80,28 @@
     public int batchDelete(List<Long> ids) {
         for (Long id : ids) {
             StockInRecord stockInRecord = stockInRecordMapper.selectById(id);
-            if (stockInRecord.getType().equals("0")) {
-                StockInventory stockInventory = stockInventoryMapper.selectOne(new LambdaQueryWrapper<StockInventory>().eq(StockInventory::getProductModelId, stockInRecord.getProductModelId()));
+            if ("0".equals(stockInRecord.getType())) {
+                StockInventory stockInventory = findQualifiedInventory(stockInRecord);
                 if (stockInventory == null) {
-                    throw new BaseException("搴撳瓨璁板綍涓病鏈夊搴旂殑浜у搧,鏃犳硶鍒犻櫎!!!");
-                } else {
-                    StockInventoryDto stockInRecordDto = new StockInventoryDto();
-                    stockInRecordDto.setProductModelId(stockInventory.getProductModelId());
-                    stockInRecordDto.setQualitity(stockInRecord.getStockInNum());
-                    stockInventoryMapper.updateSubtractStockInventory(stockInRecordDto);
+                    throw new BaseException("搴撳瓨璁板綍涓病鏈夊搴旂殑浜у搧锛屾棤娉曞垹闄�!!!");
                 }
-            } else if (stockInRecord.getType().equals("1")) {
-                StockUninventory stockUninventory = stockUninventoryMapper.selectOne(new LambdaQueryWrapper<StockUninventory>().eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId()));
+                stockInventory.setQualitity(defaultDecimal(stockInventory.getQualitity()).subtract(defaultDecimal(stockInRecord.getStockInNum())));
+                stockInventory.setVersion(stockInventory.getVersion() == null ? 1 : stockInventory.getVersion() + 1);
+                stockInventory.setUpdateTime(LocalDateTime.now());
+                stockInventoryMapper.updateById(stockInventory);
+            } else if ("1".equals(stockInRecord.getType())) {
+                StockUninventory stockUninventory = stockUninventoryMapper.selectOne(
+                        new LambdaQueryWrapper<StockUninventory>()
+                                .eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId())
+                                .eq(StockUninventory::getBatchNo, stockInRecord.getBatchNo())
+                );
                 if (stockUninventory == null) {
-                    throw new BaseException("搴撳瓨璁板綍涓病鏈夊搴旂殑浜у搧,鏃犳硶鍒犻櫎!!!");
-                } else {
-                    StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
-                    stockUninventoryDto.setProductModelId(stockUninventory.getProductModelId());
-                    stockUninventoryDto.setQualitity(stockInRecord.getStockInNum());
-                    stockUninventoryMapper.updateSubtractStockUnInventory(stockUninventoryDto);
+                    throw new BaseException("搴撳瓨璁板綍涓病鏈夊搴旂殑浜у搧锛屾棤娉曞垹闄�!!!");
                 }
+                stockUninventory.setQualitity(defaultDecimal(stockUninventory.getQualitity()).subtract(defaultDecimal(stockInRecord.getStockInNum())));
+                stockUninventory.setVersion(stockUninventory.getVersion() == null ? 1 : stockUninventory.getVersion() + 1);
+                stockUninventory.setUpdateTime(LocalDateTime.now());
+                stockUninventoryMapper.updateById(stockUninventory);
             }
         }
         return stockInRecordMapper.deleteBatchIds(ids);
@@ -113,10 +111,14 @@
     public void exportStockInRecord(HttpServletResponse response, StockInRecordDto stockInRecordDto) {
         List<StockInRecordExportData> list = stockInRecordMapper.listStockInRecordExportData(stockInRecordDto);
         for (StockInRecordExportData stockInRecordExportData : list) {
-            if (stockInRecordExportData.getType().equals("0")) {
-                stockInRecordExportData.setRecordType(EnumUtil.fromCode(StockInQualifiedRecordTypeEnum.class, Integer.parseInt(stockInRecordExportData.getRecordType())).getValue());
+            if ("0".equals(stockInRecordExportData.getType())) {
+                stockInRecordExportData.setRecordType(
+                        EnumUtil.fromCode(StockInQualifiedRecordTypeEnum.class, Integer.parseInt(stockInRecordExportData.getRecordType())).getValue()
+                );
             } else {
-                stockInRecordExportData.setRecordType(EnumUtil.fromCode(StockInUnQualifiedRecordTypeEnum.class, Integer.parseInt(stockInRecordExportData.getRecordType())).getValue());
+                stockInRecordExportData.setRecordType(
+                        EnumUtil.fromCode(StockInUnQualifiedRecordTypeEnum.class, Integer.parseInt(stockInRecordExportData.getRecordType())).getValue()
+                );
             }
         }
         ExcelUtil<StockInRecordExportData> util = new ExcelUtil<>(StockInRecordExportData.class);
@@ -132,11 +134,30 @@
     public int updateStockInRecord(StockInRecordDto stockInRecordDto) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         try {
-            stockInventoryService.addApproveByPurchase(loginUser, stockInRecordDto,stockInRecordDto.getId());
+            stockInventoryService.addApproveByPurchase(loginUser, stockInRecordDto, stockInRecordDto.getId());
         } catch (Exception e) {
             e.printStackTrace();
         }
         stockInRecordDto.setApproveStatus(1);
         return stockInRecordMapper.updateById(stockInRecordDto);
     }
+
+    // 鍚堟牸鍏ュ簱鍥為��鎸変笌搴撳瓨鍚堝苟涓�鑷寸殑鍞竴閿煡鎵俱��
+    private StockInventory findQualifiedInventory(StockInRecord stockInRecord) {
+        LambdaQueryWrapper<StockInventory> queryWrapper = new LambdaQueryWrapper<StockInventory>()
+                .eq(StockInventory::getProductModelId, stockInRecord.getProductModelId())
+                .orderByAsc(StockInventory::getId);
+        String processCategory = StringUtils.trimToEmpty(stockInRecord.getProcessCategory());
+        String voltage = StringUtils.trimToEmpty(stockInRecord.getVoltage());
+        if (StringUtils.isNotBlank(processCategory) || StringUtils.isNotBlank(voltage)) {
+            queryWrapper.eq(StockInventory::getProcessCategory, processCategory);
+            queryWrapper.eq(StockInventory::getVoltage, voltage);
+        }
+        List<StockInventory> inventories = stockInventoryMapper.selectList(queryWrapper);
+        return inventories.isEmpty() ? null : inventories.get(0);
+    }
+
+    private BigDecimal defaultDecimal(BigDecimal value) {
+        return value == null ? BigDecimal.ZERO : value;
+    }
 }

--
Gitblit v1.9.3