| | |
| | | import com.ruoyi.business.dto.OfficialInventoryDto; |
| | | import com.ruoyi.business.dto.PendingInventoryDto; |
| | | import com.ruoyi.business.entity.*; |
| | | import com.ruoyi.business.mapper.InventorySummaryMapper; |
| | | import com.ruoyi.business.mapper.OfficialInventoryMapper; |
| | | import com.ruoyi.business.mapper.PendingInventoryMapper; |
| | | import com.ruoyi.business.service.InputInventoryRecordService; |
| | | import com.ruoyi.business.mapper.*; |
| | | import com.ruoyi.business.service.InventorySummaryService; |
| | | import com.ruoyi.business.service.OutputInventoryRecordService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class InventorySummaryServiceImpl extends ServiceImpl<InventorySummaryMapper, InventorySummary> implements InventorySummaryService { |
| | | @Autowired |
| | | private InventorySummaryMapper inventorySummaryMapper; |
| | | @Autowired |
| | | private InputInventoryRecordService inputInventoryRecordService; |
| | | @Autowired |
| | | private OutputInventoryRecordService outputInventoryRecordService; |
| | | @Autowired |
| | | private PendingInventoryMapper pendingInventoryMapper; |
| | | @Autowired |
| | | private OfficialInventoryMapper officialInventoryMapper; |
| | | private final InventorySummaryMapper inventorySummaryMapper; |
| | | private final InputInventoryRecordMapper inputInventoryRecordMapper; |
| | | private final OutputInventoryRecordMapper outputInventoryRecordMapper; |
| | | |
| | | private final PendingInventoryMapper pendingInventoryMapper; |
| | | private final OfficialInventoryMapper officialInventoryMapper; |
| | | |
| | | @Override |
| | | public int updateInventory(PendingInventoryDto pendingInventoryDto, OfficialInventoryDto officialInventoryDto) { |
| | |
| | | outputEndRecordId = inventorySummary.getOutputEndRecordId(); |
| | | } |
| | | // 查询节点以后所有入库记录 |
| | | List<InputInventoryRecord> inputInventoryRecords = inputInventoryRecordService.list(new LambdaQueryWrapper<InputInventoryRecord>() |
| | | List<InputInventoryRecord> inputInventoryRecords = inputInventoryRecordMapper.selectList(new LambdaQueryWrapper<InputInventoryRecord>() |
| | | .eq(InputInventoryRecord::getInventoryId, inventoryId) |
| | | .eq(InputInventoryRecord::getInventoryType, inventoryType) |
| | | .gt(InputInventoryRecord::getId, inputEndRecordId)); |
| | | // 查询节点以后所有出库记录 |
| | | List<OutputInventoryRecord> outputInventoryRecords = outputInventoryRecordService.list(new LambdaQueryWrapper<OutputInventoryRecord>() |
| | | List<OutputInventoryRecord> outputInventoryRecords = outputInventoryRecordMapper.selectList(new LambdaQueryWrapper<OutputInventoryRecord>() |
| | | .eq(OutputInventoryRecord::getInventoryId, inventoryId) |
| | | .eq(OutputInventoryRecord::getInventoryType, inventoryType) |
| | | .gt(OutputInventoryRecord::getId, outputEndRecordId)); |
| | |
| | | return officialInventoryMapper.updateById(officialInventory); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int updateInventorySummary(List<Long> ids) { |
| | | List<InventorySummary> inventorySummaries = inventorySummaryMapper.selectBatchIds(ids); |
| | | for (InventorySummary inventorySummary : inventorySummaries) { |
| | | // 查询节点之前所有入库记录 |
| | | List<InputInventoryRecord> inputInventoryRecords = inputInventoryRecordMapper.selectList(new LambdaQueryWrapper<InputInventoryRecord>() |
| | | .eq(InputInventoryRecord::getInventoryId, inventorySummary.getInventoryId()) |
| | | .eq(InputInventoryRecord::getInventoryType, inventorySummary.getInventoryType()) |
| | | .lt(InputInventoryRecord::getId, inventorySummary.getInputEndRecordId())); |
| | | |
| | | // 查询节点之前所有出库记录 |
| | | List<OutputInventoryRecord> outputInventoryRecords = outputInventoryRecordMapper.selectList(new LambdaQueryWrapper<OutputInventoryRecord>() |
| | | .eq(OutputInventoryRecord::getInventoryId, inventorySummary.getInventoryId()) |
| | | .eq(OutputInventoryRecord::getInventoryType, inventorySummary.getInventoryType()) |
| | | .lt(OutputInventoryRecord::getId, inventorySummary.getOutputEndRecordId())); |
| | | |
| | | // 计算库存数量 |
| | | BigDecimal inputQuantity = inputInventoryRecords.stream().map(InputInventoryRecord::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal outputQuantity = outputInventoryRecords.stream().map(OutputInventoryRecord::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | inventorySummary.setInventoryQuantity(inputQuantity.subtract(outputQuantity)); |
| | | } |
| | | |
| | | return inventorySummaryMapper.updateById(inventorySummaries).size(); |
| | | } |
| | | } |