huminmin
9 天以前 02047d917004c8f7dc44627c847583e54c297226
src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
@@ -30,6 +30,7 @@
import com.ruoyi.stock.service.StockInRecordService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.jspecify.annotations.NonNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@@ -206,14 +207,18 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int batchApprove(List<Long> ids, Integer approvalStatus) {
        if (CollectionUtils.isEmpty(ids)) {
    public int batchApprove(Integer approvalStatus, List<StockInRecordDto.StockInRecordApproveItemDto> items) {
        if (CollectionUtils.isEmpty(items)) {
            throw new BaseException("请选择至少一条数据");
        }
        if (approvalStatus == null || (!ReviewStatusEnum.APPROVED.getCode().equals(approvalStatus) && !ReviewStatusEnum.REJECTED.getCode().equals(approvalStatus))) {
            throw new BaseException("审批状态值无效");
        }
        for (Long id : ids) {
        for (StockInRecordDto.StockInRecordApproveItemDto item : items) {
            Long id = item.getId();
            if (id == null) {
                throw new BaseException("入库记录ID不能为空");
            }
            StockInRecord stockInRecord = stockInRecordMapper.selectById(id);
            if (stockInRecord == null) {
                throw new BaseException("入库记录不存在,无法审批!!!");
@@ -221,6 +226,17 @@
            if (stockInRecord.getApprovalStatus() != null && !ReviewStatusEnum.PENDING_REVIEW.getCode().equals(stockInRecord.getApprovalStatus())) {
                throw new BaseException("只有待审批状态的记录才能审批,入库批次:" + stockInRecord.getInboundBatches());
            }
            // 获取审批时修改的入库数量,如果没有修改则使用原数量
            final BigDecimal finalStockInNum;
            if (item.getStockInNum() != null && item.getStockInNum().compareTo(BigDecimal.ZERO) > 0) {
                finalStockInNum = item.getStockInNum();
                // 更新入库记录的入库数量
                stockInRecord.setStockInNum(finalStockInNum);
            } else {
                finalStockInNum = stockInRecord.getStockInNum();
            }
            stockInRecord.setApprovalStatus(approvalStatus);
            stockInRecordMapper.updateById(stockInRecord);
@@ -235,20 +251,17 @@
                if ("0".equals(stockInRecord.getType())) {
                    // 合格入库 -> 先查库存,存在则更新,不存在则新增
                    StockInventory stockInventory = getStockInventory(stockInRecord.getProductModelId(), stockInRecord.getBatchNo());
                    StockInventoryDto stockInventoryDto = new StockInventoryDto();
                    stockInventoryDto.setProductModelId(stockInRecord.getProductModelId());
                    stockInventoryDto.setBatchNo(stockInRecord.getBatchNo());
                    stockInventoryDto.setQualitity(stockInRecord.getStockInNum());
                    stockInventoryDto.setRemark(stockInRecord.getRemark());
                    stockInventoryDto.setManufacturerId(stockInRecord.getManufacturerId());
                    StockInventoryDto stockInventoryDto = getStockInventoryDto(stockInRecord);
                    stockInventoryDto.setQualitity(finalStockInNum);
                    if (stockInventory == null) {
                        stockInventoryMapper.insert(new StockInventory() {{
                            setProductModelId(stockInRecord.getProductModelId());
                            setQualitity(stockInRecord.getStockInNum());
                            setQualitity(finalStockInNum);
                            setBatchNo(stockInRecord.getBatchNo());
                            setRemark(stockInRecord.getRemark());
                            setWarnNum(stockInRecord.getWarnNum());
                            setManufacturerId(stockInRecord.getManufacturerId());
                            setSource(stockInRecord.getSource());
                            setVersion(1);
                        }});
                    } else {
@@ -260,16 +273,18 @@
                    StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
                    stockUninventoryDto.setProductModelId(stockInRecord.getProductModelId());
                    stockUninventoryDto.setBatchNo(stockInRecord.getBatchNo());
                    stockUninventoryDto.setQualitity(stockInRecord.getStockInNum());
                    stockUninventoryDto.setQualitity(finalStockInNum);
                    stockUninventoryDto.setRemark(stockInRecord.getRemark());
                    stockUninventoryDto.setManufacturerId(stockInRecord.getManufacturerId());
                    stockUninventoryDto.setSource(stockInRecord.getSource());
                    if (stockUninventory == null) {
                        stockUninventoryMapper.insert(new StockUninventory() {{
                            setProductModelId(stockInRecord.getProductModelId());
                            setQualitity(stockInRecord.getStockInNum());
                            setQualitity(finalStockInNum);
                            setBatchNo(stockInRecord.getBatchNo());
                            setRemark(stockInRecord.getRemark());
                            setManufacturerId(stockInRecord.getManufacturerId());
                            setSource(stockInRecord.getSource());
                            setVersion(1);
                        }});
                    } else {
@@ -278,7 +293,18 @@
                }
            }
        }
        return ids.size();
        return items.size();
    }
    private static @NonNull StockInventoryDto getStockInventoryDto(StockInRecord stockInRecord) {
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setProductModelId(stockInRecord.getProductModelId());
        stockInventoryDto.setBatchNo(stockInRecord.getBatchNo());
        stockInventoryDto.setQualitity(stockInRecord.getStockInNum());
        stockInventoryDto.setRemark(stockInRecord.getRemark());
        stockInventoryDto.setManufacturerId(stockInRecord.getManufacturerId());
        stockInventoryDto.setSource(stockInRecord.getSource());
        return stockInventoryDto;
    }
    @Override