/api/project/getModuleContent速度优化

This commit is contained in:
litianxiang
2025-09-16 11:01:22 +08:00
parent 5d8bdf9ecc
commit 630dfe98a4

View File

@@ -26,6 +26,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -1830,19 +1831,31 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
ModuleChooseVO moduleChooseVO = new ModuleChooseVO(); ModuleChooseVO moduleChooseVO = new ModuleChooseVO();
moduleChooseVO.setProjectId(projectDTO.getId()); moduleChooseVO.setProjectId(projectDTO.getId());
// UserLikeCollectionVO userLikeCollectionVO = new UserLikeCollectionVO(); // UserLikeCollectionVO userLikeCollectionVO = new UserLikeCollectionVO();
LambdaQueryWrapper<Project> projectLambdaQueryWrapper = new LambdaQueryWrapper<>();
projectLambdaQueryWrapper.select(Project::getAccountId).eq(Project::getId, projectDTO.getId());
Project project = projectService.getOne(projectLambdaQueryWrapper);
LambdaQueryWrapper<CollectionElement> queryWrapper = new LambdaQueryWrapper<>();
// 判空处理
if (project != null && project.getAccountId() != null) {
queryWrapper.eq(CollectionElement::getAccountId, project.getAccountId());
}
queryWrapper.eq(CollectionElement::getProjectId, projectDTO.getId());
List<CollectionElement> allCollectionElements = collectionElementMapper.selectList(queryWrapper);
for (String module : projectDTO.getModuleList()) { for (String module : projectDTO.getModuleList()) {
if (module.equals(Module.colorBoard.name())) { if (module.equals(Module.colorBoard.name())) {
QueryWrapper<CollectionElement> qw = new QueryWrapper<>(); List<CollectionElement> collectionElements = allCollectionElements.stream()
qw.lambda().eq(CollectionElement::getProjectId, projectDTO.getId()); .filter(element -> CollectionLevel1TypeEnum.COLOR_BOARD.getRealName().equals(element.getLevel1Type()))
qw.lambda().eq(CollectionElement::getLevel1Type, CollectionLevel1TypeEnum.COLOR_BOARD.getRealName()); .collect(Collectors.toList());
List<CollectionElement> collectionElements = collectionElementMapper.selectList(qw);
moduleChooseVO.setColorBoard(collectionService.resolveColorBoard(collectionElements)); moduleChooseVO.setColorBoard(collectionService.resolveColorBoard(collectionElements));
}else if (module.equals(Module.moodBoard.name())) { }else if (module.equals(Module.moodBoard.name())) {
MoodBoardModuleChooseVO moodBoardModuleChooseVO = new MoodBoardModuleChooseVO(); MoodBoardModuleChooseVO moodBoardModuleChooseVO = new MoodBoardModuleChooseVO();
QueryWrapper<CollectionElement> qw = new QueryWrapper<>();
qw.lambda().eq(CollectionElement::getProjectId, projectDTO.getId()); List<CollectionElement> collectionElements = allCollectionElements.stream()
qw.lambda().eq(CollectionElement::getLevel1Type, CollectionLevel1TypeEnum.MOOD_BOARD.getRealName()); .filter(element -> CollectionLevel1TypeEnum.MOOD_BOARD.getRealName().equals(element.getLevel1Type()))
List<CollectionElement> collectionElements = collectionElementMapper.selectList(qw); .collect(Collectors.toList());
List<CollectionElementVO> list = new ArrayList<>(); List<CollectionElementVO> list = new ArrayList<>();
for (CollectionElement collectionElement : collectionElements) { for (CollectionElement collectionElement : collectionElements) {
@@ -1872,10 +1885,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
moduleChooseVO.setMoodBoard(moodBoardModuleChooseVO); moduleChooseVO.setMoodBoard(moodBoardModuleChooseVO);
}else if (module.equals(Module.printBoard.name())) { }else if (module.equals(Module.printBoard.name())) {
QueryWrapper<CollectionElement> qw = new QueryWrapper<>(); List<CollectionElement> collectionElements = allCollectionElements.stream()
qw.lambda().eq(CollectionElement::getProjectId, projectDTO.getId()); .filter(element -> CollectionLevel1TypeEnum.PRINT_BOARD.getRealName().equals(element.getLevel1Type()))
qw.lambda().eq(CollectionElement::getLevel1Type, CollectionLevel1TypeEnum.PRINT_BOARD.getRealName()); .collect(Collectors.toList());
List<CollectionElement> collectionElements = collectionElementMapper.selectList(qw);
List<CollectionElementVO> list = new ArrayList<>(); List<CollectionElementVO> list = new ArrayList<>();
for (CollectionElement collectionElement : collectionElements) { for (CollectionElement collectionElement : collectionElements) {
@@ -1894,10 +1906,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
moduleChooseVO.setPrintBoard(list); moduleChooseVO.setPrintBoard(list);
}else if (module.equals(Module.sketchBoard.name())) { }else if (module.equals(Module.sketchBoard.name())) {
QueryWrapper<CollectionElement> qw = new QueryWrapper<>(); List<CollectionElement> collectionElements = allCollectionElements.stream()
qw.lambda().eq(CollectionElement::getProjectId, projectDTO.getId()); .filter(element -> CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName().equals(element.getLevel1Type()))
qw.lambda().eq(CollectionElement::getLevel1Type, CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName()); .collect(Collectors.toList());
List<CollectionElement> collectionElements = collectionElementMapper.selectList(qw);
List<CollectionElementVO> list = new ArrayList<>(); List<CollectionElementVO> list = new ArrayList<>();
for (CollectionElement collectionElement : collectionElements) { for (CollectionElement collectionElement : collectionElements) {
@@ -2180,10 +2191,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
} }
} }
}else if (module.equals(Module.mannequin.name())) { }else if (module.equals(Module.mannequin.name())) {
QueryWrapper<CollectionElement> qw = new QueryWrapper<>(); List<CollectionElement> collectionElements = allCollectionElements.stream()
qw.lambda().eq(CollectionElement::getProjectId, projectDTO.getId()); .filter(element -> CollectionLevel1TypeEnum.MODEL.getRealName().equals(element.getLevel1Type()))
qw.lambda().eq(CollectionElement::getLevel1Type, CollectionLevel1TypeEnum.MODEL.getRealName()); .collect(Collectors.toList());
List<CollectionElement> collectionElements = collectionElementMapper.selectList(qw);
List<CollectionElementVO> list = new ArrayList<>(); List<CollectionElementVO> list = new ArrayList<>();
if (CollectionUtil.isNotEmpty(collectionElements)) { if (CollectionUtil.isNotEmpty(collectionElements)) {
for (CollectionElement collectionElement : collectionElements) { for (CollectionElement collectionElement : collectionElements) {