-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
402594c
commit 5e8fe0c
Showing
16 changed files
with
370 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/thirdblock/migo/category/dao/CategoryDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.thirdblock.migo.category.dao; | ||
|
||
import java.util.List; | ||
|
||
import com.thirdblock.migo.core.bo.Category; | ||
|
||
public interface CategoryDao { | ||
|
||
void save(Category category); | ||
|
||
void update(Category category); | ||
|
||
Category findById(Long id); | ||
|
||
List<Category> list(); | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/thirdblock/migo/category/service/CategoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.thirdblock.migo.category.service; | ||
|
||
import com.thirdblock.migo.category.web.action.dto.CategoryNode; | ||
import com.thirdblock.migo.core.bo.Category; | ||
import com.thirdblock.migo.core.excep.ServiceException; | ||
|
||
public interface CategoryService { | ||
|
||
void saveOrUpdate(Category category); | ||
|
||
Category findById(Long id) throws ServiceException; | ||
|
||
CategoryNode getCategoryTree(); | ||
|
||
} |
124 changes: 124 additions & 0 deletions
124
src/main/java/com/thirdblock/migo/category/service/impl/CategoryServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package com.thirdblock.migo.category.service.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.collections.CollectionUtils; | ||
import org.apache.commons.collections.Transformer; | ||
import org.apache.commons.lang.ObjectUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.thirdblock.migo.category.dao.CategoryDao; | ||
import com.thirdblock.migo.category.service.CategoryService; | ||
import com.thirdblock.migo.category.web.action.dto.CategoryNode; | ||
import com.thirdblock.migo.core.bo.Category; | ||
import com.thirdblock.migo.core.excep.ServiceException; | ||
|
||
@Component | ||
public class CategoryServiceImpl implements CategoryService { | ||
|
||
@Autowired | ||
private CategoryDao categoryDao; | ||
|
||
@Override | ||
public void saveOrUpdate(Category category) { | ||
|
||
if (ObjectUtils.equals(category.getId(), null)) { | ||
categoryDao.save(category); | ||
} else { | ||
categoryDao.update(category); | ||
} | ||
} | ||
|
||
@Override | ||
public Category findById(Long id) throws ServiceException { | ||
if (ObjectUtils.equals(id, null) || id.equals(0L)) { | ||
throw new ServiceException("id can't be null."); | ||
} | ||
|
||
return categoryDao.findById(id); | ||
} | ||
|
||
/** | ||
* 获得分类树 | ||
* @return 根节点元素 | ||
*/ | ||
@Override | ||
public CategoryNode getCategoryTree() { | ||
List<Category> categories = categoryDao.list(); | ||
return buildCategoryTree(categories); | ||
} | ||
|
||
/** | ||
* 构造分类树 | ||
* @param categories | ||
* @return 根节点元素 | ||
*/ | ||
private CategoryNode buildCategoryTree(List<Category> categories) { | ||
|
||
// parentId -> categories | ||
Map<Long, List<Category>> childrenSearcher = new HashMap<Long, List<Category>>(); | ||
|
||
Iterator<Category> iter = categories.iterator(); | ||
while (iter.hasNext()) { | ||
Category c = iter.next(); | ||
|
||
Long parentId = c.getParentId(); | ||
List<Category> lst = childrenSearcher.get(parentId); | ||
|
||
if (lst == null) { | ||
lst = new LinkedList<Category>(); | ||
childrenSearcher.put(parentId, lst); | ||
} | ||
|
||
lst.add(c); | ||
} | ||
|
||
// 设置根节点 | ||
CategoryNode root = new CategoryNode(); | ||
Category category = new Category(); | ||
category.setId(0L); | ||
category.setParentId(0L); | ||
category.setName(Category.ROOT); | ||
|
||
buildCategoryTree(root, category, childrenSearcher); | ||
|
||
return root; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private void buildCategoryTree(CategoryNode node, Category category, Map<Long, List<Category>> childrenSearcher) { | ||
|
||
Long id = category.getId(); | ||
List<Category> categories = childrenSearcher.get(id); | ||
categories = (List<Category>) ObjectUtils.defaultIfNull(categories, new ArrayList<Category>()); | ||
|
||
List<CategoryNode> children = (List<CategoryNode>) CollectionUtils.collect(categories, new Transformer(){ | ||
@Override | ||
public Object transform(Object object) { | ||
CategoryNode node = new CategoryNode(); | ||
node.setCategory((Category) object); | ||
return node; | ||
} | ||
}); | ||
|
||
// 构造当前节点 | ||
node.setCategory(category); | ||
node.setChildren(children); | ||
|
||
// 构造孩子节点 | ||
for (int i = 0; i < children.size(); i++) { | ||
CategoryNode child = children.get(i); | ||
Category c = categories.get(i); | ||
buildCategoryTree(child, c, childrenSearcher); | ||
} | ||
|
||
return; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/thirdblock/migo/category/web/action/dto/CategoryNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.thirdblock.migo.category.web.action.dto; | ||
|
||
import java.util.List; | ||
|
||
import com.thirdblock.migo.core.bo.Category; | ||
|
||
public class CategoryNode { | ||
|
||
private Category category; | ||
private List<CategoryNode> children; | ||
|
||
public Category getCategory() { | ||
return category; | ||
} | ||
|
||
public void setCategory(Category category) { | ||
this.category = category; | ||
} | ||
|
||
public List<CategoryNode> getChildren() { | ||
return children; | ||
} | ||
|
||
public void setChildren(List<CategoryNode> children) { | ||
this.children = children; | ||
} | ||
|
||
} |
32 changes: 0 additions & 32 deletions
32
src/main/java/com/thirdblock/migo/core/auth/RestAuthenticationEntryPoint.java
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
src/main/java/com/thirdblock/migo/core/auth/RestAuthenticationFailureHandler.java
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
src/main/java/com/thirdblock/migo/core/auth/RestAuthenticationSuccessHandler.java
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
src/main/java/com/thirdblock/migo/core/auth/RestLogoutSuccessHandler.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.