| | |
| | | package com.ruoyi.stock.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | 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.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.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProductFrozen; |
| | | import com.ruoyi.sales.service.ISalesLedgerProductFrozenService; |
| | | import com.ruoyi.stock.dto.StockInRecordDto; |
| | | import com.ruoyi.stock.dto.StockInventoryDto; |
| | | import com.ruoyi.stock.dto.StockOutRecordDto; |
| | |
| | | private StockInRecordService stockInRecordService; |
| | | private StockOutRecordService stockOutRecordService; |
| | | private SalesLedgerProductMapper salesLedgerProductMapper; |
| | | private ISalesLedgerProductFrozenService salesLedgerProductFrozenService; |
| | | @Override |
| | | public IPage<StockInventoryDto> pagestockInventory(Page page, StockInventoryDto stockInventoryDto) { |
| | | return stockInventoryMapper.pagestockInventory(page, stockInventoryDto); |
| | |
| | | @Override |
| | | public Boolean thawStock(StockInventoryDto stockInventoryDto) { |
| | | StockInventory stockInventory = stockInventoryMapper.selectById(stockInventoryDto.getId()); |
| | | if (stockInventory.getLockedQuantity().compareTo(stockInventoryDto.getLockedQuantity())<0) { |
| | | if (stockInventory.getLockedQuantity().compareTo(stockInventoryDto.getLockedQuantity()) < 0) { |
| | | throw new RuntimeException("解冻数量不能超过冻结数量"); |
| | | } |
| | | stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().subtract(stockInventoryDto.getLockedQuantity())); |
| | | |
| | | BigDecimal newLockedQty = stockInventory.getLockedQuantity().subtract(stockInventoryDto.getLockedQuantity()); |
| | | |
| | | // 不能小于系统已绑定的冻结数量 |
| | | List<SalesLedgerProductFrozen> frozenList = salesLedgerProductFrozenService.list(new LambdaQueryWrapper<SalesLedgerProductFrozen>() |
| | | .eq(SalesLedgerProductFrozen::getProductModelId, stockInventory.getProductModelId())); |
| | | BigDecimal systemFrozenTotal = BigDecimal.ZERO; |
| | | if (frozenList != null) { |
| | | for (SalesLedgerProductFrozen frozen : frozenList) { |
| | | if (frozen.getFrozenQuantity() != null) { |
| | | systemFrozenTotal = systemFrozenTotal.add(frozen.getFrozenQuantity()); |
| | | } |
| | | } |
| | | } |
| | | if (newLockedQty.compareTo(systemFrozenTotal) < 0) { |
| | | throw new RuntimeException("操作失败,当前产品被销售订单硬性冻结数量为: " + systemFrozenTotal + ",剩余解冻数量不能低于此数值"); |
| | | } |
| | | |
| | | stockInventory.setLockedQuantity(newLockedQty); |
| | | return this.updateById(stockInventory); |
| | | } |
| | | } |