优化菜单管理、商品分类查询节点的性能

This commit is contained in:
xwb
2020-04-30 10:32:04 +08:00
parent 8ec7c94516
commit c9ce5fffe0
2 changed files with 14 additions and 6 deletions

View File

@ -128,6 +128,7 @@ public class YxStoreCategoryServiceImpl implements YxStoreCategoryService {
YxStoreCategoryDTO categoryDTO = new YxStoreCategoryDTO(); YxStoreCategoryDTO categoryDTO = new YxStoreCategoryDTO();
Boolean isChild; Boolean isChild;
List<YxStoreCategory> categories = yxStoreCategoryRepository.findAll();
for (YxStoreCategoryDTO deptDTO : categoryDTOS) { for (YxStoreCategoryDTO deptDTO : categoryDTOS) {
isChild = false; isChild = false;
if ("0".equals(deptDTO.getPid().toString())) { if ("0".equals(deptDTO.getPid().toString())) {
@ -144,9 +145,12 @@ public class YxStoreCategoryServiceImpl implements YxStoreCategoryService {
} }
if(isChild) if(isChild)
cates.add(deptDTO); cates.add(deptDTO);
else if(!deptNames.contains(yxStoreCategoryRepository.findNameById(deptDTO.getPid()))) for (YxStoreCategory category : categories) {
if(category.getId()==deptDTO.getPid()&&!deptNames.contains(category.getCateName())){
cates.add(deptDTO); cates.add(deptDTO);
} }
}
}

View File

@ -72,6 +72,7 @@ public class DeptServiceImpl implements DeptService {
Set<DeptDTO> depts= new LinkedHashSet<>(); Set<DeptDTO> depts= new LinkedHashSet<>();
List<String> deptNames = deptDtos.stream().map(DeptDTO::getName).collect(Collectors.toList()); List<String> deptNames = deptDtos.stream().map(DeptDTO::getName).collect(Collectors.toList());
boolean isChild; boolean isChild;
List<Dept> deptList = deptRepository.findAll();
for (DeptDTO deptDTO : deptDtos) { for (DeptDTO deptDTO : deptDtos) {
isChild = false; isChild = false;
if ("0".equals(deptDTO.getPid().toString())) { if ("0".equals(deptDTO.getPid().toString())) {
@ -88,10 +89,13 @@ public class DeptServiceImpl implements DeptService {
} }
if(isChild) { if(isChild) {
depts.add(deptDTO); depts.add(deptDTO);
} else if(!deptNames.contains(deptRepository.findNameById(deptDTO.getPid()))) { for (Dept dept : deptList) {
if(dept.getId() == deptDTO.getPid() && !deptNames.contains(dept.getName())){
depts.add(deptDTO); depts.add(deptDTO);
} }
} }
}
}
if (CollectionUtils.isEmpty(trees)) { if (CollectionUtils.isEmpty(trees)) {
trees = depts; trees = depts;