| | |
| | | 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.enums.StockOutQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.sales.dto.SimpleProductDto; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.stock.dto.StockInRecordDto; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | stockInRecordDto.setType("0"); |
| | | stockInRecordService.add(stockInRecordDto); |
| | | //再进行新增库存数量库存 |
| | | //先查询库存表中的产品是否存在,不存在新增,存在更新 |
| | | //先查询库存表中的产品是否存在,不存在新增,存在更新 阳光彩印添加仓库编码, 添加比对仓库 |
| | | StockInventory oldStockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId())); |
| | | if (ObjectUtils.isEmpty(oldStockInventory)) { |
| | | StockInventory newStockInventory = new StockInventory(); |
| | | newStockInventory.setProductModelId(stockInventoryDto.getProductModelId()); |
| | | newStockInventory.setQualitity(stockInventoryDto.getQualitity()); |
| | | newStockInventory.setSubQualitity(stockInventoryDto.getSubQualitity()); |
| | | newStockInventory.setVersion(1); |
| | | newStockInventory.setProductCode(stockInventoryDto.getProductCode()); |
| | | newStockInventory.setWarehouseCode(stockInventoryDto.getWarehouseCode()); |
| | | newStockInventory.setWarehouseName(stockInventoryDto.getWarehouseName()); |
| | | newStockInventory.setRemark(stockInventoryDto.getRemark()); |
| | | newStockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity()); |
| | | newStockInventory.setWarnNum(stockInventoryDto.getWarnNum()); |
| | |
| | | public R importStockInventory(MultipartFile file) { |
| | | try { |
| | | // 查询所有的产品 |
| | | List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectProduct(); |
| | | List<SimpleProductDto> salesLedgerProducts = salesLedgerProductMapper.selectProduct(); |
| | | |
| | | ExcelUtil<StockInventoryExportData> util = new ExcelUtil<StockInventoryExportData>(StockInventoryExportData.class); |
| | | List<StockInventoryExportData> list = util.importExcel(file.getInputStream()); |
| | |
| | | |
| | | list.forEach(dto -> { |
| | | boolean matched = false; |
| | | for (SalesLedgerProduct item : salesLedgerProducts) { |
| | | for (SimpleProductDto item : salesLedgerProducts) { |
| | | if (ObjectUtils.isEmpty(dto.getWarehouseCode())) { |
| | | return; |
| | | } |
| | | if (item.getProductCategory().equals(dto.getProductName()) && |
| | | item.getSpecificationModel().equals(dto.getModel())) { |
| | | item.getSpecificationModel().equals(dto.getModel()) |
| | | && Optional.ofNullable(item.getUnit()).orElse("").equals(dto.getUnit()) |
| | | && Optional.ofNullable(item.getSubUnit()).orElse("").equals(dto.getSubUnit()) |
| | | ) { |
| | | |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | stockInventoryDto.setWarehouseCode(dto.getWarehouseCode()); |
| | | stockInventoryDto.setWarehouseName(dto.getWarehouseName()); |
| | | stockInventoryDto.setProductCode(dto.getProductCode()); |
| | | 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) { |
| | | throw new RuntimeException("冻结数量不能超过本次导入的库存数量"); |
| | | } |
| | | stockInventoryDto.setLockedQuantity(dto.getLockedQuantity()); |
| | | stockInventoryDto.setSubQualitity(dto.getSubQualitity()); |
| | | stockInventoryDto.setProductModelId(item.getProductModelId()); |
| | | this.addstockInventory(stockInventoryDto); |
| | | matched = true; |
| | |
| | | } |
| | | if (!matched) { |
| | | // 记录未匹配的数据 |
| | | String unmatchedInfo = String.format("产品名称:%s,规格型号:%s", |
| | | dto.getProductName(), dto.getModel()); |
| | | String unmatchedInfo = String.format("产品名称:%s,规格型号:%s 主单位:%s 辅单位:%s", |
| | | dto.getProductName(), dto.getModel(), dto.getUnit(), dto.getSubUnit()); |
| | | unmatchedRecords.add(unmatchedInfo); |
| | | } |
| | | }); |