main-business/src/main/java/com/ruoyi/business/service/InputInventoryRecordService.java
@@ -6,6 +6,7 @@ import com.ruoyi.business.entity.InputInventoryRecord; import java.math.BigDecimal; import java.util.List; /** * <p> @@ -21,5 +22,5 @@ int insertInputInventoryRecord(PendingInventoryDto pendingInventoryDto, OfficialInventoryDto officialInventoryDto, BigDecimal quantity); // 删除入库记录 int deleteInputInventoryRecord(Long[] ids); int deleteInputInventoryRecord(List<Long> ids); } main-business/src/main/java/com/ruoyi/business/service/impl/InputInventoryRecordServiceImpl.java
@@ -1,15 +1,24 @@ package com.ruoyi.business.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.business.dto.OfficialInventoryDto; import com.ruoyi.business.dto.PendingInventoryDto; import com.ruoyi.business.entity.InputInventoryRecord; import com.ruoyi.business.entity.InventorySummary; import com.ruoyi.business.mapper.InputInventoryRecordMapper; import com.ruoyi.business.mapper.InventorySummaryMapper; import com.ruoyi.business.service.InputInventoryRecordService; import com.ruoyi.business.service.InventorySummaryService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Objects; import static com.ruoyi.business.constant.InventoryRecordConstant.OFFICIAL_INVENTORY; import static com.ruoyi.business.constant.InventoryRecordConstant.PENDING_INVENTORY; @@ -26,6 +35,8 @@ @RequiredArgsConstructor public class InputInventoryRecordServiceImpl extends ServiceImpl<InputInventoryRecordMapper, InputInventoryRecord> implements InputInventoryRecordService { private final InputInventoryRecordMapper inputInventoryRecordMapper; private final InventorySummaryService inventorySummaryService; private final InventorySummaryMapper inventorySummaryMapper; @Override public int insertInputInventoryRecord(PendingInventoryDto pendingInventoryDto, OfficialInventoryDto officialInventoryDto, BigDecimal quantity) { @@ -43,18 +54,47 @@ } inputInventoryRecord.setQuantity(quantity); return inputInventoryRecordMapper.insert(inputInventoryRecord); inputInventoryRecordMapper.insert(inputInventoryRecord); // 更新库存 // inventorySummaryService.updateInventory(pendingInventoryDto, officialInventoryDto); return inventorySummaryService.updateInventory(pendingInventoryDto, officialInventoryDto); } @Override public int deleteInputInventoryRecord(Long[] ids) { public int deleteInputInventoryRecord(List<Long> ids) { if (CollectionUtils.isNotEmpty(ids)) { List<InputInventoryRecord> inputInventoryRecords = inputInventoryRecordMapper.selectBatchIds(ids); // 根据id进行降序排序 List<InputInventoryRecord> inputInventoryRecordList = inputInventoryRecords.stream() .sorted(Comparator.comparing(InputInventoryRecord::getId).reversed()) .toList(); String InventoryType = inputInventoryRecords.get(0).getInventoryType(); List<Long> inventoryIds = inputInventoryRecords.stream().map(InputInventoryRecord::getInventoryId).toList(); List<InventorySummary> inventorySummaries = inventorySummaryMapper.selectList(new LambdaQueryWrapper<InventorySummary>() .eq(InventorySummary::getInventoryType, InventoryType) .in(InventorySummary::getInventoryId, inventoryIds)); if (CollectionUtils.isNotEmpty(inventorySummaries)) { List<InventorySummary> updates = new ArrayList<>(); for (InventorySummary inventorySummary : inventorySummaries) { for (InputInventoryRecord inputInventoryRecord : inputInventoryRecords) { // 如果节点上的入库记录id大于变更的id,说明此id前所有入库记录都要重新计算 if (Objects.equals(inventorySummary.getInventoryId(), inputInventoryRecord.getInventoryId()) && inventorySummary.getInputEndRecordId() > inputInventoryRecord.getId()) { inventorySummary.setInputEndRecordId(inputInventoryRecord.getId()); updates.add(inventorySummary); } } } // 重置他们的节点最终id inventorySummaryMapper.updateById(updates); } } // todo 重新计算节点库存 // todo 更新库存实施数据 return 0; // 删除入库记录 return inputInventoryRecordMapper.deleteByIds(ids); } } main-business/src/main/java/com/ruoyi/business/service/impl/InventorySummaryServiceImpl.java
@@ -5,12 +5,8 @@ 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.stereotype.Service; @@ -32,8 +28,9 @@ @RequiredArgsConstructor public class InventorySummaryServiceImpl extends ServiceImpl<InventorySummaryMapper, InventorySummary> implements InventorySummaryService { private final InventorySummaryMapper inventorySummaryMapper; private final InputInventoryRecordService inputInventoryRecordService; private final OutputInventoryRecordService outputInventoryRecordService; private final InputInventoryRecordMapper inputInventoryRecordMapper; private final OutputInventoryRecordMapper outputInventoryRecordMapper; private final PendingInventoryMapper pendingInventoryMapper; private final OfficialInventoryMapper officialInventoryMapper; @@ -56,12 +53,12 @@ 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)); main-business/src/main/java/com/ruoyi/business/service/impl/OutputInventoryRecordServiceImpl.java
@@ -5,6 +5,7 @@ import com.ruoyi.business.dto.PendingInventoryDto; import com.ruoyi.business.entity.OutputInventoryRecord; import com.ruoyi.business.mapper.OutputInventoryRecordMapper; import com.ruoyi.business.service.InventorySummaryService; import com.ruoyi.business.service.OutputInventoryRecordService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -27,6 +28,8 @@ public class OutputInventoryRecordServiceImpl extends ServiceImpl<OutputInventoryRecordMapper, OutputInventoryRecord> implements OutputInventoryRecordService { private final OutputInventoryRecordMapper outputInventoryRecordMapper; private final InventorySummaryService inventorySummaryService; @Override public int insertOutputInventoryRecord(PendingInventoryDto pendingInventoryDto, OfficialInventoryDto officialInventoryDto, BigDecimal quantity) { if ((pendingInventoryDto != null && officialInventoryDto != null) || (pendingInventoryDto == null && officialInventoryDto == null)) { @@ -43,9 +46,9 @@ } outputInventoryRecord.setQuantity(quantity); return outputInventoryRecordMapper.insert(outputInventoryRecord); outputInventoryRecordMapper.insert(outputInventoryRecord); // 变更原库存信息 // return inventorySummaryService.updateInventory(pendingInventoryDto, officialInventoryDto); return inventorySummaryService.updateInventory(pendingInventoryDto, officialInventoryDto); } } main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
@@ -192,7 +192,7 @@ officialInventory.setPendingId(pendingInventoryDto.getPId()); officialInventory.setInventoryQuantity(quantity); officialInventoryMapper.insert(officialInventory); }else { } else { OfficialInventory officialInventory = officialInventoryMapper.selectById(pendingInventoryDto.getOfficialId()); officialInventory.setInventoryQuantity(quantity.add(officialInventory.getInventoryQuantity())); officialInventoryMapper.updateById(officialInventory); @@ -200,10 +200,4 @@ } return i; } // 处理明细和库存数量 private int handeInventoryQuantity(PendingInventoryDto pendingInventoryDto) { inputInventoryRecordService.insertInputInventoryRecord(pendingInventoryDto, null, pendingInventoryDto.getInventoryQuantity()); return inventorySummaryService.updateInventory(pendingInventoryDto, null); }; }