huminmin
7 天以前 13afb7eafeffac6ecccc7c66d36974c54c5172d4
src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
@@ -13,6 +13,8 @@
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.time.LocalDateTime;
import com.ruoyi.stock.dto.StockInRecordDto;
import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.stock.dto.StockUninventoryDto;
@@ -28,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;
@@ -53,7 +56,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int add(StockInRecordDto stockInRecordDto) {
        String no = OrderUtils.countTodayByCreateTime(stockInRecordMapper, "RK","inbound_batches");
        String no = OrderUtils.countTodayByCreateTime(stockInRecordMapper, "RK","inbound_batches", stockInRecordDto.getCreateTime() != null ? stockInRecordDto.getCreateTime() : LocalDateTime.now());
        stockInRecordDto.setInboundBatches(no);
        StockInRecord stockInRecord = new StockInRecord();
        BeanUtils.copyProperties(stockInRecordDto, stockInRecord);
@@ -233,11 +236,7 @@
                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 stockInventoryDto = getStockInventoryDto(stockInRecord);
                    if (stockInventory == null) {
                        stockInventoryMapper.insert(new StockInventory() {{
                            setProductModelId(stockInRecord.getProductModelId());
@@ -245,6 +244,8 @@
                            setBatchNo(stockInRecord.getBatchNo());
                            setRemark(stockInRecord.getRemark());
                            setWarnNum(stockInRecord.getWarnNum());
                            setManufacturerId(stockInRecord.getManufacturerId());
                            setSource(stockInRecord.getSource());
                            setVersion(1);
                        }});
                    } else {
@@ -258,12 +259,16 @@
                    stockUninventoryDto.setBatchNo(stockInRecord.getBatchNo());
                    stockUninventoryDto.setQualitity(stockInRecord.getStockInNum());
                    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());
                            setBatchNo(stockInRecord.getBatchNo());
                            setRemark(stockInRecord.getRemark());
                            setManufacturerId(stockInRecord.getManufacturerId());
                            setSource(stockInRecord.getSource());
                            setVersion(1);
                        }});
                    } else {
@@ -275,6 +280,17 @@
        return ids.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
    @Transactional(rollbackFor = Exception.class)
    public int batchReAudit(List<Long> ids) {