原料类型树
This commit is contained in:
parent
31c5d72426
commit
1965f38505
|
|
@ -1,6 +1,7 @@
|
||||||
package com.bonus.canteen.core.common.domain;
|
package com.bonus.canteen.core.common.domain;
|
||||||
|
|
||||||
import com.bonus.canteen.core.alloc.domain.AllocArea;
|
import com.bonus.canteen.core.alloc.domain.AllocArea;
|
||||||
|
import com.bonus.canteen.core.menu.domain.MenuMaterialCategory;
|
||||||
import com.bonus.canteen.core.menu.domain.MenuNutritionType;
|
import com.bonus.canteen.core.menu.domain.MenuNutritionType;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
|
|
@ -58,6 +59,13 @@ public class TreeSelect implements Serializable {
|
||||||
this.children = menuNutritionType.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
|
this.children = menuNutritionType.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TreeSelect(MenuMaterialCategory menuMaterialCategory) {
|
||||||
|
this.id = menuMaterialCategory.getId();
|
||||||
|
this.label = menuMaterialCategory.getCategoryName();
|
||||||
|
this.status = String.valueOf(menuMaterialCategory.getDelFlag());
|
||||||
|
this.children = menuMaterialCategory.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getLevel() {
|
public Integer getLevel() {
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
import com.bonus.canteen.core.menu.domain.MenuMaterialCategory;
|
import com.bonus.canteen.core.menu.domain.MenuMaterialCategory;
|
||||||
|
import com.bonus.canteen.core.menu.domain.MenuNutritionType;
|
||||||
import com.bonus.canteen.core.menu.dto.CategoryTreeListDTO;
|
import com.bonus.canteen.core.menu.dto.CategoryTreeListDTO;
|
||||||
import com.bonus.canteen.core.menu.dto.LongIds;
|
import com.bonus.canteen.core.menu.dto.LongIds;
|
||||||
import com.bonus.canteen.core.menu.dto.MenuMaterialCategoryAddDTO;
|
import com.bonus.canteen.core.menu.dto.MenuMaterialCategoryAddDTO;
|
||||||
|
|
@ -39,6 +40,16 @@ public class MenuMaterialCategoryController extends BaseController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IMenuMaterialCategoryService menuMaterialCategoryService;
|
private IMenuMaterialCategoryService menuMaterialCategoryService;
|
||||||
|
|
||||||
|
@GetMapping("/menuMaterialCategoryTree")
|
||||||
|
public AjaxResult deptTree(MenuMaterialCategory menuMaterialCategory) {
|
||||||
|
try {
|
||||||
|
return success(menuMaterialCategoryService.selectMenuMaterialCategoryTreeList(menuMaterialCategory));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e.toString(), e);
|
||||||
|
}
|
||||||
|
return error("系统异常,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询原料类别列表
|
* 查询原料类别列表
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import lombok.ToString;
|
||||||
import com.bonus.common.core.web.domain.BaseEntity;
|
import com.bonus.common.core.web.domain.BaseEntity;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 原料类别对象 menu_material_category
|
* 原料类别对象 menu_material_category
|
||||||
|
|
@ -62,5 +64,5 @@ public class MenuMaterialCategory extends Model<MenuMaterialCategory> {
|
||||||
private Long bigCategoryId;
|
private Long bigCategoryId;
|
||||||
@ApiModelProperty("备注")
|
@ApiModelProperty("备注")
|
||||||
private String remark;
|
private String remark;
|
||||||
|
private List<MenuMaterialCategory> children = new ArrayList();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.bonus.canteen.core.menu.service;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.bonus.canteen.core.common.domain.TreeSelect;
|
||||||
import com.bonus.canteen.core.menu.domain.MenuMaterialCategory;
|
import com.bonus.canteen.core.menu.domain.MenuMaterialCategory;
|
||||||
import com.bonus.canteen.core.menu.dto.CategoryTreeListDTO;
|
import com.bonus.canteen.core.menu.dto.CategoryTreeListDTO;
|
||||||
import com.bonus.canteen.core.menu.dto.MenuMaterialCategoryAddDTO;
|
import com.bonus.canteen.core.menu.dto.MenuMaterialCategoryAddDTO;
|
||||||
|
|
@ -68,4 +69,6 @@ public interface IMenuMaterialCategoryService extends IService<MenuMaterialCateg
|
||||||
void syncAllCategoryBigCategoryAndLevel();
|
void syncAllCategoryBigCategoryAndLevel();
|
||||||
|
|
||||||
void generateCategoryNum(Long categoryId, Long parentId, Integer categoryType);
|
void generateCategoryNum(Long categoryId, Long parentId, Integer categoryType);
|
||||||
|
|
||||||
|
public List<TreeSelect> selectMenuMaterialCategoryTreeList(MenuMaterialCategory menuMaterialCategory);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.bonus.canteen.core.common.domain.TreeSelect;
|
||||||
|
import com.bonus.canteen.core.menu.domain.MenuNutritionType;
|
||||||
import com.bonus.canteen.core.menu.dto.CategoryTreeListDTO;
|
import com.bonus.canteen.core.menu.dto.CategoryTreeListDTO;
|
||||||
import com.bonus.canteen.core.menu.dto.MenuMaterialCategoryAddDTO;
|
import com.bonus.canteen.core.menu.dto.MenuMaterialCategoryAddDTO;
|
||||||
import com.bonus.canteen.core.menu.enums.MgrRoleTypeEnum;
|
import com.bonus.canteen.core.menu.enums.MgrRoleTypeEnum;
|
||||||
|
|
@ -21,6 +23,7 @@ import com.bonus.canteen.core.utils.BnsConstants;
|
||||||
import com.bonus.canteen.core.utils.GlobalConstants;
|
import com.bonus.canteen.core.utils.GlobalConstants;
|
||||||
import com.bonus.canteen.core.utils.TreeNodeUtil;
|
import com.bonus.canteen.core.utils.TreeNodeUtil;
|
||||||
import com.bonus.common.core.exception.ServiceException;
|
import com.bonus.common.core.exception.ServiceException;
|
||||||
|
import com.bonus.common.core.utils.StringUtils;
|
||||||
import com.bonus.common.houqin.constant.DelFlagEnum;
|
import com.bonus.common.houqin.constant.DelFlagEnum;
|
||||||
import com.bonus.common.houqin.constant.LeConstants;
|
import com.bonus.common.houqin.constant.LeConstants;
|
||||||
import com.bonus.common.houqin.i18n.I18n;
|
import com.bonus.common.houqin.i18n.I18n;
|
||||||
|
|
@ -364,4 +367,71 @@ public class MenuMaterialCategoryServiceImpl extends ServiceImpl<MenuMaterialCat
|
||||||
return userAuthPO;
|
return userAuthPO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TreeSelect> selectMenuMaterialCategoryTreeList(MenuMaterialCategory menuMaterialCategory) {
|
||||||
|
List<MenuMaterialCategory> menuMaterialCategories = menuMaterialCategoryMapper.selectMenuMaterialCategoryList(menuMaterialCategory);
|
||||||
|
return buildMenuMaterialCategoryTreeSelect(menuMaterialCategories);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TreeSelect> buildMenuMaterialCategoryTreeSelect(List<MenuMaterialCategory> menuMaterialCategories)
|
||||||
|
{
|
||||||
|
List<MenuMaterialCategory> menuMaterialCategoryTrees = buildMenuNutritionTypeTree(menuMaterialCategories);
|
||||||
|
return menuMaterialCategoryTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MenuMaterialCategory> buildMenuNutritionTypeTree(List<MenuMaterialCategory> list) {
|
||||||
|
List<MenuMaterialCategory> returnList = new ArrayList<MenuMaterialCategory>();
|
||||||
|
List<Long> tempList = list.stream().map(MenuMaterialCategory::getId).collect(Collectors.toList());
|
||||||
|
for (MenuMaterialCategory category : list)
|
||||||
|
{
|
||||||
|
// 如果是顶级节点, 遍历该父节点的所有子节点
|
||||||
|
if (!tempList.contains(category.getParentId()))
|
||||||
|
{
|
||||||
|
recursionFn(list, category);
|
||||||
|
returnList.add(category);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (returnList.isEmpty())
|
||||||
|
{
|
||||||
|
returnList = list;
|
||||||
|
}
|
||||||
|
return returnList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void recursionFn(List<MenuMaterialCategory> list, MenuMaterialCategory t)
|
||||||
|
{
|
||||||
|
// 得到子节点列表
|
||||||
|
List<MenuMaterialCategory> childList = getChildList(list, t);
|
||||||
|
t.setChildren(childList);
|
||||||
|
for (MenuMaterialCategory tChild : childList)
|
||||||
|
{
|
||||||
|
if (hasChild(list, tChild))
|
||||||
|
{
|
||||||
|
recursionFn(list, tChild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<MenuMaterialCategory> getChildList(List<MenuMaterialCategory> list, MenuMaterialCategory t)
|
||||||
|
{
|
||||||
|
List<MenuMaterialCategory> tlist = new ArrayList<MenuMaterialCategory>();
|
||||||
|
Iterator<MenuMaterialCategory> it = list.iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
MenuMaterialCategory n = (MenuMaterialCategory) it.next();
|
||||||
|
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue())
|
||||||
|
{
|
||||||
|
tlist.add(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否有子节点
|
||||||
|
*/
|
||||||
|
private boolean hasChild(List<MenuMaterialCategory> list, MenuMaterialCategory t)
|
||||||
|
{
|
||||||
|
return getChildList(list, t).size() > 0 ? true : false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue