From 8097a2a4383a3785e11990170d61c59ae6b48888 Mon Sep 17 00:00:00 2001
From: chenhj <1263187585@qq.com>
Date: 星期五, 20 六月 2025 18:02:53 +0800
Subject: [PATCH] 库存明细数据处理
---
main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java | 81 ++++++++++++++++++++++++++++++++++------
1 files changed, 68 insertions(+), 13 deletions(-)
diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
index adbc5e9..53182f3 100644
--- a/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
+++ b/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
@@ -15,6 +15,8 @@
import com.ruoyi.business.entity.PendingInventory;
import com.ruoyi.business.mapper.OfficialInventoryMapper;
import com.ruoyi.business.mapper.PendingInventoryMapper;
+import com.ruoyi.business.service.InputInventoryRecordService;
+import com.ruoyi.business.service.InventorySummaryService;
import com.ruoyi.business.service.PendingInventoryService;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.bean.BeanUtils;
@@ -23,10 +25,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -49,11 +48,61 @@
private final CoalFieldMapper coalFieldMapper;
+ private final InputInventoryRecordService inputInventoryRecordService;
+
+ private final InventorySummaryService inventorySummaryService;
+
@Override
- public IPage<PendingInventory> selectPendingInventoryList(Page page, PendingInventoryDto pendingInventoryDto) {
+ public IPage<PendingInventoryDto> selectPendingInventoryList(Page page, PendingInventoryDto pendingInventoryDto) {
+ // 1. 鏋勫缓涓绘煡璇�
LambdaQueryWrapper<PendingInventory> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByDesc(PendingInventory::getCreateTime);
- return pendingInventoryMapper.selectPage(page, queryWrapper);
+
+ // 2. 鎵ц涓昏〃鍒嗛〉鏌ヨ
+ IPage<PendingInventory> pendingInventoryPage = pendingInventoryMapper.selectPage(page, queryWrapper);
+
+ // 3. 鏃犳暟鎹揩閫熻繑鍥�
+ if (CollectionUtils.isEmpty(pendingInventoryPage.getRecords())) {
+ return new Page<>(page.getCurrent(), page.getSize(), pendingInventoryPage.getTotal());
+ }
+
+ // 4. 鎻愬彇鎵�鏈夊緟澶勭悊搴撳瓨ID
+ List<Long> pendingIds = pendingInventoryPage.getRecords().stream()
+ .map(PendingInventory::getId)
+ .collect(Collectors.toList());
+
+ // 5. 鎵归噺鏌ヨ鍏宠仈鐨勬寮忓簱瀛樹俊鎭�
+ Map<Long, Long> pendingToOfficialMap = getOfficialInventoryMap(pendingIds);
+
+ // 6. 浣跨敤MyBatis-Plus鐨刢onvert鏂规硶杞崲DTO
+ return pendingInventoryPage.convert(record -> {
+ PendingInventoryDto dto = new PendingInventoryDto();
+ BeanUtils.copyProperties(record, dto);
+
+ // 浠庨鍔犺浇鐨凪ap涓幏鍙杘fficialId
+ dto.setOfficialId(pendingToOfficialMap.getOrDefault(record.getId(), null));
+ return dto;
+ });
+ }
+
+ // 鎵归噺鑾峰彇寰呭鐞嗗簱瀛樹笌姝e紡搴撳瓨鐨勬槧灏勫叧绯�
+ private Map<Long, Long> getOfficialInventoryMap(List<Long> pendingIds) {
+ if (CollectionUtils.isEmpty(pendingIds)) {
+ return Collections.emptyMap();
+ }
+
+ // 鏌ヨ鍏宠仈鐨勬寮忓簱瀛樻暟鎹�
+ LambdaQueryWrapper<OfficialInventory> wrapper = new LambdaQueryWrapper<>();
+ wrapper.select(OfficialInventory::getId, OfficialInventory::getPendingId)
+ .in(OfficialInventory::getPendingId, pendingIds);
+
+ return officialInventoryMapper.selectList(wrapper)
+ .stream()
+ .collect(Collectors.toMap(
+ OfficialInventory::getPendingId,
+ OfficialInventory::getId,
+ (existing, replacement) -> existing // 濡傛灉鏈夐噸澶嶏紝淇濈暀绗竴涓�
+ ));
}
@Override
@@ -135,13 +184,19 @@
} else {
pendingInventoryMapper.deleteById(pendingInventoryDto.getPId());
}
- officialInventoryMapper.delete(new LambdaQueryWrapper<OfficialInventory>().eq(OfficialInventory::getPendingId, pendingInventoryDto.getPId()));
- OfficialInventory officialInventory = new OfficialInventory();
- BeanUtils.copyProperties(pendingInventory, officialInventory);
- officialInventory.setId(null);
- officialInventory.setPendingId(pendingInventoryDto.getPId());
- officialInventory.setInventoryQuantity(quantity);
- officialInventoryMapper.insert(officialInventory);
+ //姝e紡搴�
+ if (pendingInventoryDto.getOfficialId() == null) {
+ OfficialInventory officialInventory = new OfficialInventory();
+ BeanUtils.copyProperties(pendingInventory, officialInventory);
+ officialInventory.setId(null);
+ officialInventory.setPendingId(pendingInventoryDto.getPId());
+ officialInventory.setInventoryQuantity(quantity);
+ officialInventoryMapper.insert(officialInventory);
+ } else {
+ OfficialInventory officialInventory = officialInventoryMapper.selectById(pendingInventoryDto.getOfficialId());
+ officialInventory.setInventoryQuantity(quantity.add(officialInventory.getInventoryQuantity()));
+ officialInventoryMapper.updateById(officialInventory);
+ }
}
return i;
}
--
Gitblit v1.9.3