| | |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.equipmentenergyconsumption.mapper.ElectricityConsumptionAreaMapper; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.stock.dto.StockInRecordDto; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | private final WeighbridgeDocGenerator weighbridgeDocGenerator; |
| | | private final ProductMapper productMapper; |
| | | private final ProductModelMapper productModelMapper; |
| | | private final ElectricityConsumptionAreaMapper electricityConsumptionAreaMapper; |
| | | |
| | | @Override |
| | | public IPage<StockInventoryDto> pagestockInventory(Page page, StockInventoryDto stockInventoryDto) { |
| | |
| | | stockInRecordDto.setRecordId(stockInventoryDto.getRecordId()); |
| | | stockInRecordDto.setRecordType(stockInventoryDto.getRecordType()); |
| | | stockInRecordDto.setWeighingOperator(stockInventoryDto.getWeighingOperator()); |
| | | Long modelId; |
| | | if (stockInventoryDto.getProductId() != null) { |
| | | stockInRecordDto.setProductId(stockInventoryDto.getProductId()); |
| | | stockInRecordDto.setProductModelId(stockInventoryDto.getProductModelId()); |
| | | }else { |
| | | modelId = stockInventoryDto.getProductModelId(); |
| | | } else { |
| | | Product parent = productMapper.selectOne(new LambdaQueryWrapper<Product>().eq(Product::getProductName, "原材料").last("limit 1")); |
| | | if (parent == null) { |
| | | throw new RuntimeException("原材料分类不存在"); |
| | |
| | | stockInRecordDto.setProductId(product.getId()); |
| | | stockInRecordDto.setProductModelId(productModelId); |
| | | stockInventoryDto.setProductModelId(productModelId); |
| | | |
| | | modelId = productModelId; |
| | | } |
| | | stockInRecordDto.setRemark(stockInventoryDto.getRemark()); |
| | | stockInRecordDto.setType("0"); |
| | |
| | | new QueryWrapper<StockInventory>().lambda() |
| | | .eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId()) |
| | | ); |
| | | ProductModel productModel = productModelMapper.selectById(modelId); |
| | | BigDecimal weight = compareUnit(stockInventoryDto, productModel); |
| | | if (ObjectUtils.isEmpty(oldStockInventory)) { |
| | | // 新增库存 |
| | | StockInventory newStockInventory = new StockInventory(); |
| | | newStockInventory.setProductModelId(stockInventoryDto.getProductModelId()); |
| | | newStockInventory.setQualitity(stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0 ? |
| | | stockInventoryDto.getNetWeight() : stockInventoryDto.getQualitity()); |
| | | newStockInventory.setQualitity(weight); |
| | | newStockInventory.setVersion(1); |
| | | newStockInventory.setRemark(stockInventoryDto.getRemark()); |
| | | newStockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity()); |
| | |
| | | stockInventoryMapper.insert(newStockInventory); |
| | | } else { |
| | | // 更新库存 |
| | | stockInventoryDto.setQualitity(stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0 ? |
| | | stockInventoryDto.getNetWeight() : stockInventoryDto.getQualitity()); |
| | | stockInventoryDto.setQualitity(weight); |
| | | stockInventoryMapper.updateAddStockInventory(stockInventoryDto); |
| | | } |
| | | return true; |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean subtractStockInventory(StockInventoryDto stockInventoryDto) { |
| | | |
| | | ProductModel productModel = productModelMapper.selectById(stockInventoryDto.getProductModelId()); |
| | | BigDecimal weight = compareUnit(stockInventoryDto, productModel); |
| | | // 新增出库记录 |
| | | StockOutRecordDto stockOutRecordDto = new StockOutRecordDto(); |
| | | stockOutRecordDto.setRecordId(stockInventoryDto.getRecordId()); |
| | |
| | | if (lockedQty == null) { |
| | | lockedQty = BigDecimal.ZERO; |
| | | } |
| | | stockInventoryDto.setQualitity(weight); |
| | | if (stockInventoryDto.getQualitity().compareTo(oldStockInventory.getQualitity().subtract(lockedQty)) > 0) { |
| | | throw new RuntimeException("库存不足无法出库"); |
| | | } |
| | | |
| | | stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto); |
| | | return true; |
| | | } |
| | | |
| | | private BigDecimal compareUnit(StockInventoryDto stockInventoryDto, ProductModel productModel) { |
| | | String unit = ""; |
| | | if (productModel != null) { |
| | | unit = productModel.getUnit(); |
| | | } |
| | | BigDecimal weight; |
| | | if (stockInventoryDto.getUnit().equals(unit)) { |
| | | weight = stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0 ? |
| | | stockInventoryDto.getNetWeight() : stockInventoryDto.getQualitity(); |
| | | } else { |
| | | if ("吨".equals(unit)) { |
| | | weight =stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0 ? |
| | | stockInventoryDto.getNetWeight().divide(BigDecimal.valueOf(1000),2, RoundingMode.HALF_UP) : stockInventoryDto.getQualitity().divide(BigDecimal.valueOf(1000),2,RoundingMode.HALF_UP); |
| | | } else if ("公斤".equals(unit)) { |
| | | weight = stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0 ? |
| | | stockInventoryDto.getNetWeight().multiply(BigDecimal.valueOf(1000)) : stockInventoryDto.getQualitity().multiply(BigDecimal.valueOf(1000)); |
| | | }else { |
| | | weight =stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0 ? |
| | | stockInventoryDto.getNetWeight() : stockInventoryDto.getQualitity(); |
| | | } |
| | | } |
| | | return weight; |
| | | } |
| | | |
| | | @Override |
| | |
| | | stockInventoryDto.setModel(dto.getModel()); |
| | | stockInventoryDto.setUnit(dto.getUnit()); |
| | | |
| | | // 解决方案1:通过代理对象调用 |
| | | //通过代理对象调用 |
| | | ((StockInventoryService) AopContext.currentProxy()).addstockInventory(stockInventoryDto); |
| | | } |
| | | return R.ok("导入成功"); |