瀏覽代碼

优化轧钢棒二、棒三、上若分页列表查询的方法

lingpeng.li 2 月之前
父節點
當前提交
1ad885bb1e

+ 19 - 10
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/rollClubThree/controller/RollClubThreeController.java

@@ -1,6 +1,5 @@
 package org.jeecg.modules.billet.rollClubThree.controller;
 
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -23,9 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -76,15 +73,25 @@ public class RollClubThreeController {
 		}
 
 		List<RollClubThree> newRollClubThreeList = new ArrayList<>();
+		// 1. 一次性查询所有符合条件的 RollClubThreeDetails 数据
+		List<RollClubThreeDetails> allDetails = rollClubThreeDetailsService.list();
+
+        // 2. 组织 Map,Key 为 "ccmNo-heatNo-storageBillId"
+		Map<String, List<RollClubThreeDetails>> detailsMap = allDetails.stream()
+				.collect(Collectors.groupingBy(d -> d.getCcmNo() + "-" + d.getHeatNo() + "-" + d.getStorageBillId()));
+
+        // 3. 遍历 pageList.getRecords(),从 Map 取数据
 		pageList.getRecords().forEach(x -> {
 			if (x != null) {
 				RollClubThree clubThree = new RollClubThree();
 				BeanUtils.copyProperties(x, clubThree);
-				LambdaQueryWrapper<RollClubThreeDetails> queryWrapper1 = new LambdaQueryWrapper<>();
-				queryWrapper1.eq(RollClubThreeDetails::getCcmNo, x.getCcmNo());
-				queryWrapper1.eq(RollClubThreeDetails::getHeatNo, x.getHeatNo());
-				queryWrapper1.eq(RollClubThreeDetails::getStorageBillId, x.getStorageBillId());
-				List<RollClubThreeDetails> rollClubThreeDetailsLists = rollClubThreeDetailsService.list(queryWrapper1);
+
+				// 组装 Key
+				String key = x.getCcmNo() + "-" + x.getHeatNo() + "-" + x.getStorageBillId();
+
+				// 直接从 Map 取数据,避免重复查询数据库
+				List<RollClubThreeDetails> rollClubThreeDetailsLists = detailsMap.getOrDefault(key, Collections.emptyList());
+
 				if (oConvertUtils.listIsNotEmpty(rollClubThreeDetailsLists)) {
 					String distinctAssemblyNumber = rollClubThreeDetailsLists.stream()
 							.map(RollClubThreeDetails::getAssemblyNumber)
@@ -93,10 +100,12 @@ public class RollClubThreeController {
 							.collect(Collectors.joining(","));
 					clubThree.setAssemblyNumber(distinctAssemblyNumber);
 				}
+
 				newRollClubThreeList.add(clubThree);
 			}
 		});
-// 如果需要更新 pageList 的记录
+
+		// 如果需要更新 pageList 的记录
 		pageList.setRecords(newRollClubThreeList);
 
 		return Result.OK(pageList);

+ 18 - 9
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/rollClubTwo/controller/RollClubTwoController.java

@@ -1,6 +1,5 @@
 package org.jeecg.modules.billet.rollClubTwo.controller;
 
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -23,9 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -70,15 +67,25 @@ public class RollClubTwoController {
 		}
 
 		List<RollClubTwo> newRollClubTwoList = new ArrayList<>();
+		// 1. 一次性查询所有符合条件的 RollClubTwoDetails 数据
+		List<RollClubTwoDetails> allDetails = rollClubTwoDetailsService.list();
+
+        // 2. 组织 Map,Key 为 "ccmNo-heatNo-storageBillId"
+		Map<String, List<RollClubTwoDetails>> detailsMap = allDetails.stream()
+				.collect(Collectors.groupingBy(d -> d.getCcmNo() + "-" + d.getHeatNo() + "-" + d.getStorageBillId()));
+
+        // 3. 遍历 pageList.getRecords(),从 Map 取数据
 		pageList.getRecords().forEach(x -> {
 			if (x != null) {
 				RollClubTwo clubTwo = new RollClubTwo();
 				BeanUtils.copyProperties(x, clubTwo);
-				LambdaQueryWrapper<RollClubTwoDetails> queryWrapper1 = new LambdaQueryWrapper<>();
-				queryWrapper1.eq(RollClubTwoDetails::getCcmNo, x.getCcmNo());
-				queryWrapper1.eq(RollClubTwoDetails::getHeatNo, x.getHeatNo());
-				queryWrapper1.eq(RollClubTwoDetails::getStorageBillId, x.getStorageBillId());
-				List<RollClubTwoDetails> rollClubTwoDetailsLists = rollClubTwoDetailsService.list(queryWrapper1);
+
+				// 组装 Key
+				String key = x.getCcmNo() + "-" + x.getHeatNo() + "-" + x.getStorageBillId();
+
+				// 直接从 Map 取数据,避免重复查询数据库
+				List<RollClubTwoDetails> rollClubTwoDetailsLists = detailsMap.getOrDefault(key, Collections.emptyList());
+
 				if (oConvertUtils.listIsNotEmpty(rollClubTwoDetailsLists)) {
 					String distinctAssemblyNumber = rollClubTwoDetailsLists.stream()
 							.map(RollClubTwoDetails::getAssemblyNumber)
@@ -87,10 +94,12 @@ public class RollClubTwoController {
 							.collect(Collectors.joining(","));
 					clubTwo.setAssemblyNumber(distinctAssemblyNumber);
 				}
+
 				newRollClubTwoList.add(clubTwo);
 			}
 		});
 
+
 		// 更新分页数据
 		pageList.setRecords(newRollClubTwoList);
 

+ 17 - 9
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/rollOutShipp/controller/RollOutShippController.java

@@ -1,6 +1,5 @@
 package org.jeecg.modules.billet.rollOutShipp.controller;
 
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -23,9 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -74,15 +71,25 @@ public class RollOutShippController {
 		}
 
 		List<RollOutShipp> newRollOutShippList = new ArrayList<>();
+        // 1. 先查询所有符合条件的 RollOutShippDetails 数据
+		List<RollOutShippDetails> allDetails = rollOutShippDetailsService.list();
+
+        // 2. 组织 Map,Key 为 "ccmNo-heatNo-storageBillId"
+		Map<String, List<RollOutShippDetails>> detailsMap = allDetails.stream()
+				.collect(Collectors.groupingBy(d -> d.getCcmNo() + "-" + d.getHeatNo() + "-" + d.getStorageBillId()));
+
+        // 3. 遍历 pageList.getRecords(),从 Map 取数据
 		pageList.getRecords().forEach(x -> {
 			if (x != null) {
 				RollOutShipp rollOutShipp1 = new RollOutShipp();
 				BeanUtils.copyProperties(x, rollOutShipp1);
-				LambdaQueryWrapper<RollOutShippDetails> queryWrapper1 = new LambdaQueryWrapper<>();
-				queryWrapper1.eq(RollOutShippDetails::getCcmNo, x.getCcmNo());
-				queryWrapper1.eq(RollOutShippDetails::getHeatNo, x.getHeatNo());
-				queryWrapper1.eq(RollOutShippDetails::getStorageBillId, x.getStorageBillId());
-				List<RollOutShippDetails> rollClubThreeDetailsLists = rollOutShippDetailsService.list(queryWrapper1);
+
+				// 组装 Key
+				String key = x.getCcmNo() + "-" + x.getHeatNo() + "-" + x.getStorageBillId();
+
+				// 直接从 Map 取数据,避免重复查询数据库
+				List<RollOutShippDetails> rollClubThreeDetailsLists = detailsMap.getOrDefault(key, Collections.emptyList());
+
 				if (oConvertUtils.listIsNotEmpty(rollClubThreeDetailsLists)) {
 					String distinctAssemblyNumber = rollClubThreeDetailsLists.stream()
 							.map(RollOutShippDetails::getAssemblyNumber)
@@ -91,6 +98,7 @@ public class RollOutShippController {
 							.collect(Collectors.joining(","));
 					rollOutShipp1.setAssemblyNumber(distinctAssemblyNumber);
 				}
+
 				newRollOutShippList.add(rollOutShipp1);
 			}
 		});