| | |
| | | package com.consum.base.service.impl; |
| | | |
| | | import java.util.Comparator; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.consum.base.Constants; |
| | | import com.consum.base.core.utils.IdUtil; |
| | | import com.consum.base.pojo.BaseCategoryParam; |
| | |
| | | import com.walker.infrastructure.utils.DateUtils; |
| | | import com.walker.infrastructure.utils.StringUtils; |
| | | import com.walker.jdbc.service.BaseServiceImpl; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Comparator; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description 物品分类 |
| | |
| | | @Service |
| | | public class BaseCategoryServiceImpl extends BaseServiceImpl implements BaseCategoryService { |
| | | |
| | | private static final String QUERY_TREE_ALL = "select * from base_category where states = 1 order by FATHER_CATEGORY_ID, LEVELS ASC"; |
| | | private static final String QUERY_TREE_ALL = |
| | | "select * from base_category where states = 1 order by FATHER_CATEGORY_ID, LEVELS ASC"; |
| | | |
| | | /** |
| | | * @Description 新增分类 |
| | |
| | | projectTreeResult.setChildren(getChildren(projectTreeResult, all)); |
| | | } |
| | | return projectTreeResult; |
| | | }).sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))).collect(Collectors.toList()); |
| | | }).sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))) |
| | | .collect(Collectors.toList()); |
| | | return menus; |
| | | |
| | | } |
| | |
| | | * 递归查找所有菜单的子菜单 |
| | | */ |
| | | private List<ProjectTreeResult> getChildren(ProjectTreeResult root, List<BaseCategory> all) { |
| | | List<ProjectTreeResult> children = all.stream().filter(entity -> entity.getFatherCategoryId().equals(root.getId())).map(entity -> { |
| | | List<ProjectTreeResult> children = |
| | | all.stream().filter(entity -> entity.getFatherCategoryId().equals(root.getId())).map(entity -> { |
| | | |
| | | ProjectTreeResult projectTreeResult = new ProjectTreeResult(entity); |
| | | //通过递归找到子分类 |
| | |
| | | projectTreeResult.setChildren(getChildren(projectTreeResult, all)); |
| | | } |
| | | return projectTreeResult; |
| | | }).sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))).collect(Collectors.toList()); |
| | | }).sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))) |
| | | .collect(Collectors.toList()); |
| | | return children; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @return |
| | |
| | | * @Date 2023/10/30 |
| | | */ |
| | | public List<BaseCategory> queryForLv3Tree() { |
| | | StringBuilder sql = new StringBuilder("SELECT * FROM base_category WHERE states = 1 and levels = 3 order by ORDER_NUMBER,CREATE_TIME desc"); |
| | | StringBuilder sql = new StringBuilder( |
| | | "SELECT * FROM base_category WHERE states = 1 and levels = 3 order by ORDER_NUMBER,CREATE_TIME desc"); |
| | | return this.select(sql.toString(), new Object[]{}, new BaseCategory()); |
| | | } |
| | | |
| | | @Override |
| | | public BaseCategory getByCategoryByName(String categoryName) { |
| | | StringBuilder sql = new StringBuilder("SELECT * FROM base_category WHERE 1 = 1 "); |
| | | HashMap<String, Object> paramts = new HashMap<>(); |
| | | // 分类名称 |
| | | sql.append(" and category_name =:category_name "); |
| | | paramts.put("category_name", categoryName); |
| | | BaseCategory baseCategory = this.get(sql.toString(), paramts, new BaseCategory()); |
| | | return baseCategory; |
| | | } |
| | | } |