fix(stock): 解决库存管理中的重复键异常问题
- 在采购台账服务中添加净合同金额字段设置
- 在销售台账服务中添加净合同金额字段设置
- 在入库记录服务中为库存插入操作添加重复键异常处理
- 在入库记录服务中为非库存插入操作添加重复键异常处理
- 在库存服务中为库存插入操作添加重复键异常处理
- 统一处理数据库唯一键约束冲突,避免系统错误
已修改4个文件
46 ■■■■■ 文件已修改
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
@@ -943,6 +943,7 @@
                salesLedger.setContractAmount(salesLedgerProductImportDtos.stream()
                        .map(PurchaseLedgerProductImportDto::getTaxInclusiveTotalPrice)
                        .reduce(BigDecimal.ZERO,BigDecimal::add));
                salesLedger.setNetContractAmount(salesLedger.getContractAmount());
                // 通过销售单号绑定销售
                SalesLedger salesLedger1 = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>()
                        .eq(SalesLedger::getSalesContractNo, salesLedger.getSalesContractNo())
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -385,6 +385,7 @@
                salesLedger.setContractAmount(salesLedgerProductImportDtos.stream()
                        .map(SalesLedgerProductImportDto::getTaxInclusiveTotalPrice)
                        .reduce(BigDecimal.ZERO, BigDecimal::add));
                salesLedger.setNetContractAmount(salesLedger.getContractAmount());
                salesLedgerMapper.insert(salesLedger);
src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
@@ -246,14 +246,18 @@
                    stockInventoryDto.setQualitity(stockInRecord.getStockInNum());
                    stockInventoryDto.setRemark(stockInRecord.getRemark());
                    if (stockInventory == null) {
                        stockInventoryMapper.insert(new StockInventory() {{
                            setProductModelId(stockInRecord.getProductModelId());
                            setQualitity(stockInRecord.getStockInNum());
                            setBatchNo(stockInRecord.getBatchNo());
                            setRemark(stockInRecord.getRemark());
                            setWarnNum(stockInRecord.getWarnNum());
                            setVersion(1);
                        }});
                        try {
                            stockInventoryMapper.insert(new StockInventory() {{
                                setProductModelId(stockInRecord.getProductModelId());
                                setQualitity(stockInRecord.getStockInNum());
                                setBatchNo(stockInRecord.getBatchNo());
                                setRemark(stockInRecord.getRemark());
                                setWarnNum(stockInRecord.getWarnNum());
                                setVersion(1);
                            }});
                        } catch (org.springframework.dao.DuplicateKeyException e) {
                            stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
                        }
                    } else {
                        stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
                    }
@@ -266,13 +270,17 @@
                    stockUninventoryDto.setQualitity(stockInRecord.getStockInNum());
                    stockUninventoryDto.setRemark(stockInRecord.getRemark());
                    if (stockUninventory == null) {
                        stockUninventoryMapper.insert(new StockUninventory() {{
                            setProductModelId(stockInRecord.getProductModelId());
                            setQualitity(stockInRecord.getStockInNum());
                            setBatchNo(stockInRecord.getBatchNo());
                            setRemark(stockInRecord.getRemark());
                            setVersion(1);
                        }});
                        try {
                            stockUninventoryMapper.insert(new StockUninventory() {{
                                setProductModelId(stockInRecord.getProductModelId());
                                setQualitity(stockInRecord.getStockInNum());
                                setBatchNo(stockInRecord.getBatchNo());
                                setRemark(stockInRecord.getRemark());
                                setVersion(1);
                            }});
                        } catch (org.springframework.dao.DuplicateKeyException e) {
                            stockUninventoryMapper.updateAddStockUnInventory(stockUninventoryDto);
                        }
                    } else {
                        stockUninventoryMapper.updateAddStockUnInventory(stockUninventoryDto);
                    }
src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -105,7 +105,11 @@
            newStockInventory.setBatchNo(stockInventoryDto.getBatchNo());
            newStockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity());
            newStockInventory.setWarnNum(stockInventoryDto.getWarnNum());
            stockInventoryMapper.insert(newStockInventory);
            try {
                stockInventoryMapper.insert(newStockInventory);
            } catch (org.springframework.dao.DuplicateKeyException e) {
                stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
            }
        } else {
            stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
        }