From d9b764868dbfa79aa79d79f676f60a28c4055b06 Mon Sep 17 00:00:00 2001 From: chenhj <1263187585@qq.com> Date: 星期六, 14 六月 2025 17:00:07 +0800 Subject: [PATCH] 库存明细数据处理 --- main-business/src/main/java/com/ruoyi/business/service/impl/InputInventoryRecordServiceImpl.java | 54 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 49 insertions(+), 5 deletions(-) diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/InputInventoryRecordServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/InputInventoryRecordServiceImpl.java index ac0a847..7370557 100644 --- a/main-business/src/main/java/com/ruoyi/business/service/impl/InputInventoryRecordServiceImpl.java +++ b/main-business/src/main/java/com/ruoyi/business/service/impl/InputInventoryRecordServiceImpl.java @@ -1,17 +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.beans.factory.annotation.Autowired; 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; @@ -27,10 +34,9 @@ @Service @RequiredArgsConstructor public class InputInventoryRecordServiceImpl extends ServiceImpl<InputInventoryRecordMapper, InputInventoryRecord> implements InputInventoryRecordService { - @Autowired - private InputInventoryRecordMapper inputInventoryRecordMapper; - @Autowired - private InventorySummaryService inventorySummaryService; + private final InputInventoryRecordMapper inputInventoryRecordMapper; + private final InventorySummaryService inventorySummaryService; + private final InventorySummaryMapper inventorySummaryMapper; @Override public int insertInputInventoryRecord(PendingInventoryDto pendingInventoryDto, OfficialInventoryDto officialInventoryDto, BigDecimal quantity) { @@ -53,4 +59,42 @@ // 鏇存柊搴撳瓨 return inventorySummaryService.updateInventory(pendingInventoryDto, officialInventoryDto); } + + @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澶т簬鍙樻洿鐨刬d锛岃鏄庢id鍓嶆墍鏈夊叆搴撹褰曢兘瑕侀噸鏂拌绠� + if (Objects.equals(inventorySummary.getInventoryId(), inputInventoryRecord.getInventoryId()) && inventorySummary.getInputEndRecordId() > inputInventoryRecord.getId()) { + inventorySummary.setInputEndRecordId(inputInventoryRecord.getId()); + updates.add(inventorySummary); + } + } + + } + // 閲嶇疆浠栦滑鐨勮妭鐐规渶缁坕d + inventorySummaryMapper.updateById(updates); + } + } + // todo 閲嶆柊璁$畻鑺傜偣搴撳瓨 + // todo 鏇存柊搴撳瓨瀹炴柦鏁版嵁 + + + // 鍒犻櫎鍏ュ簱璁板綍 + return inputInventoryRecordMapper.deleteByIds(ids); + } } -- Gitblit v1.9.3