Skip to content

Commit

Permalink
clean up dataprovider for categories (#33)
Browse files Browse the repository at this point in the history
add banner.txt
set version to 1.0.0
  • Loading branch information
MGZero authored Nov 2, 2024
1 parent 6f558e7 commit 198caef
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 48 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.zfgc</groupId>
<artifactId>zfgbb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>zfgbb</name>
<description>Demo project for Spring Boot</description>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.zfgc.zfgbb.dataprovider.forum;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
Expand All @@ -10,6 +11,7 @@

import com.zfgc.zfgbb.dao.BoardDao;
import com.zfgc.zfgbb.dao.BoardPermissionViewDao;
import com.zfgc.zfgbb.dao.CategoryDao;
import com.zfgc.zfgbb.dao.ThreadDao;
import com.zfgc.zfgbb.dataprovider.AbstractDataProvider;
import com.zfgc.zfgbb.dbo.BoardDbo;
Expand All @@ -36,7 +38,7 @@ public class ForumDataProvider extends AbstractDataProvider {
private BoardDao boardDao;

@Autowired
private CategoryDataProvider categoryDataProvider;
private CategoryDao categoryDao;

@Autowired
private ThreadDao threadDao;
Expand Down Expand Up @@ -74,12 +76,16 @@ public Board getBoard(Integer boardId, Integer pageNo, Integer threadsPerPage) {
}

private List<BoardSummary> getBoardSummaries(Integer parentBoardId){
return getBoardSummaries(Arrays.asList(parentBoardId));
}

private List<BoardSummary> getBoardSummaries(List<Integer> parentBoardId){
BoardSummaryViewDboExample bEx = new BoardSummaryViewDboExample();
bEx.createCriteria().andParentBoardIdEqualTo(parentBoardId);
bEx.createCriteria().andParentBoardIdIn(parentBoardId);
List<BoardSummary> result = (boardSummaryMapper.selectByExample(bEx).stream().map(b -> mapper.map(b, BoardSummary.class)).collect(Collectors.toList()));

ChildBoardViewDboExample cEx = new ChildBoardViewDboExample();
cEx.createCriteria().andParentBoardIdEqualTo(parentBoardId);
cEx.createCriteria().andParentBoardIdIn(parentBoardId);

Map<Integer, List<ChildBoard>> childBoards = childBoardMapper.selectByExample(cEx).stream()
.map(c -> mapper.map(c, ChildBoard.class))
Expand All @@ -93,6 +99,28 @@ private List<BoardSummary> getBoardSummaries(Integer parentBoardId){
return result;
}

private List<BoardSummary> getBoardSummariesByCategory(List<Integer> categoryId){
BoardSummaryViewDboExample bEx = new BoardSummaryViewDboExample();
bEx.createCriteria().andCategoryIdIn(categoryId);
List<BoardSummary> result = (boardSummaryMapper.selectByExample(bEx).stream().map(b -> mapper.map(b, BoardSummary.class)).collect(Collectors.toList()));

if(!result.isEmpty()) {
ChildBoardViewDboExample cEx = new ChildBoardViewDboExample();
cEx.createCriteria().andParentBoardIdIn(result.stream().map(BoardSummary::getBoardId).collect(Collectors.toList()));

Map<Integer, List<ChildBoard>> childBoards = childBoardMapper.selectByExample(cEx).stream()
.map(c -> mapper.map(c, ChildBoard.class))
.collect(Collectors.groupingBy(ChildBoard::getParentBoardId));

result.forEach(bs -> {
bs.setChildBoards(childBoards.get(bs.getBoardId()));
});
}


return result;
}

public Forum getForum() {
Forum forum = new Forum();

Expand All @@ -101,7 +129,7 @@ public Forum getForum() {

CategoryDboExample exC = new CategoryDboExample();
exC.createCriteria().andParentBoardIdEqualTo(0);
List<Category> categories = categoryDataProvider.getCategories(exC);
List<Category> categories = getCategories(exC);

forum.setCategories(categories);

Expand All @@ -111,6 +139,19 @@ public Forum getForum() {
return forum;
}

public List<Category> getCategories(CategoryDboExample exC){
List<Category> categories = super.convertDboListToModel(categoryDao.get(exC), Category.class);
List<Integer> categoryIds = categories.stream().map(Category::getCategoryId).collect(Collectors.toList());

Map<Integer, List<BoardSummary>> summaries = getBoardSummariesByCategory(categoryIds).stream().collect(Collectors.groupingBy(BoardSummary::getCategoryId));

categories.forEach(cat ->{
cat.setBoards(summaries.get(cat.getCategoryId()));
});

return categories;
}

public List<Permission> getBoardPermissions(Integer boardId){
BoardPermissionViewDboExample bEx = new BoardPermissionViewDboExample();
bEx.createCriteria().andBoardIdEqualTo(boardId);
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
________ _______ _______ .______ .______
| / | ____| / _____|| _ \ | _ \
`---/ / | |__ | | __ | |_) | | |_) |
/ / | __| | | |_ | | _ < | _ <
/ /----.| | | |__| | | |_) | | |_) |
/________||__| \______| |______/ |______/

${application.version}
Powered by Spring Boot ${spring-boot.version}

0 comments on commit 198caef

Please sign in to comment.