From 4fedbed9949c6160dcfa216d6660bd3c625f7bce Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期三, 25 六月 2025 11:49:55 +0800
Subject: [PATCH] 优化
---
main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java
index f964ab8..6e1f4d6 100644
--- a/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java
+++ b/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java
@@ -7,8 +7,10 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.entity.CoalField;
+import com.ruoyi.basic.entity.CoalInfo;
import com.ruoyi.basic.entity.CoalValue;
import com.ruoyi.basic.mapper.CoalFieldMapper;
+import com.ruoyi.basic.mapper.CoalInfoMapper;
import com.ruoyi.basic.mapper.CoalValueMapper;
import com.ruoyi.business.dto.OfficialInventoryDto;
import com.ruoyi.business.entity.OfficialInventory;
@@ -23,6 +25,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
+import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -42,6 +45,8 @@
private final CoalValueMapper coalValueMapper;
private final CoalFieldMapper coalFieldMapper;
+
+ private final CoalInfoMapper coalInfoMapper;
@Override
@@ -63,6 +68,21 @@
.map(CoalField::getFields)
.distinct()
.collect(Collectors.toList());
+
+ //鏌ヨ鐓ょids
+ List<Long> coalIds = entityPage.getRecords().stream()
+ .map(OfficialInventory::getCoalId)
+ .distinct()
+ .collect(Collectors.toList());
+
+ // 鎵归噺鏌ヨCoalInfo
+ Map<Long, CoalInfo> coalInfoMap;
+ if (!coalIds.isEmpty()) {
+ List<CoalInfo> coalInfos = coalInfoMapper.selectList(new LambdaQueryWrapper<CoalInfo>().in(CoalInfo::getId, coalIds));
+ coalInfoMap = coalInfos.stream().collect(Collectors.toMap(CoalInfo::getId, Function.identity()));
+ } else {
+ coalInfoMap = new HashMap<>();
+ }
// 閬嶅巻姣忔潯璁板綍锛岃繘琛岃浆鎹㈠苟濉厖 fields
for (OfficialInventory entity : entityPage.getRecords()) {
@@ -97,6 +117,12 @@
fields.add(fieldMap);
}
+ // 璁剧疆Coal淇℃伅
+ CoalInfo coalInfo = coalInfoMap.get(entity.getCoalId());
+ if (coalInfo != null) {
+ dto.setCoal(coalInfo.getCoal());
+ }
+
// 璁剧疆鍒� DTO 涓�
dto.setFields(fields);
dtoList.add(dto);
@@ -120,9 +146,16 @@
.map(OI -> {
OfficialInventoryVo vo = new OfficialInventoryVo();
BeanUtils.copyProperties(OI, vo);
+ CoalInfo coalInfo = coalInfoMapper.selectById(OI.getCoalId());
+ vo.setCoal(coalInfo.getCoal());
return vo;
})
.collect(Collectors.toList());
+ }
+
+ @Override
+ public List<OfficialInventory> selectOfficialAll() {
+ return officialInventoryMapper.selectList(null);
}
@Transactional
@@ -150,6 +183,7 @@
// 2. 鎻掑叆鏂板簱瀛樿褰�
OfficialInventory officialInventory = new OfficialInventory();
BeanUtils.copyProperties(officialInventoryDto, officialInventory);
+ officialInventory.setId(null);
officialInventory.setMergeId(ids.toString());
officialInventory.setRegistrantId(SecurityUtils.getLoginUser().getUser().getUserName());
if (officialInventoryMapper.insert(officialInventory) <= 0) {
@@ -211,4 +245,5 @@
}
}
}
+
}
--
Gitblit v1.9.3