chenhj
3 天以前 8097a2a4383a3785e11990170d61c59ae6b48888
main-business/src/main/java/com/ruoyi/business/service/impl/InputInventoryRecordServiceImpl.java
@@ -11,6 +11,7 @@
import com.ruoyi.business.mapper.InventorySummaryMapper;
import com.ruoyi.business.service.InputInventoryRecordService;
import com.ruoyi.business.service.InventorySummaryService;
import com.ruoyi.business.utils.InventoryUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -19,6 +20,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static com.ruoyi.business.constant.InventoryRecordConstant.OFFICIAL_INVENTORY;
import static com.ruoyi.business.constant.InventoryRecordConstant.PENDING_INVENTORY;
@@ -37,6 +39,7 @@
    private final InputInventoryRecordMapper inputInventoryRecordMapper;
    private final InventorySummaryService inventorySummaryService;
    private final InventorySummaryMapper inventorySummaryMapper;
    private final InventoryUtils inventoryUtils;
    @Override
    public int insertInputInventoryRecord(PendingInventoryDto pendingInventoryDto, OfficialInventoryDto officialInventoryDto, BigDecimal quantity) {
@@ -62,36 +65,41 @@
    @Override
    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);
            }
        if (CollectionUtils.isEmpty(ids)) {
            throw new RuntimeException("请传入要删除的id记录");
        }
        // todo 重新计算节点库存
        // todo 更新库存实施数据
        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().stream().distinct().collect(Collectors.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 : inputInventoryRecordList) {
                    // 如果节点上的入库记录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);
        }
        // 重新计算节点库存
        inventorySummaryService.updateInventorySummary(ids);
        // 更新库存实时数据
        inventoryUtils.updateInventoryByIds(inventoryIds, inputInventoryRecords.get(0).getInventoryType());
        // 删除入库记录