营养分类树
This commit is contained in:
parent
b67efb60e9
commit
31c5d72426
|
|
@ -1,6 +1,7 @@
|
|||
package com.bonus.canteen.core.common.domain;
|
||||
|
||||
import com.bonus.canteen.core.alloc.domain.AllocArea;
|
||||
import com.bonus.canteen.core.menu.domain.MenuNutritionType;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -50,6 +51,13 @@ public class TreeSelect implements Serializable {
|
|||
this.children = area.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public TreeSelect(MenuNutritionType menuNutritionType) {
|
||||
this.id = menuNutritionType.getId();
|
||||
this.label = menuNutritionType.getName();
|
||||
this.status = menuNutritionType.getDelFlag();
|
||||
this.children = menuNutritionType.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Integer getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,16 @@ public class MenuNutritionTypeController extends BaseController {
|
|||
@Autowired
|
||||
private IMenuNutritionTypeService menuNutritionTypeService;
|
||||
|
||||
@GetMapping("/menuNutritionTypeTree")
|
||||
public AjaxResult deptTree(MenuNutritionType menuNutritionType) {
|
||||
try {
|
||||
return success(menuNutritionTypeService.selectMenuNutritionTypeTreeList(menuNutritionType));
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(), e);
|
||||
}
|
||||
return error("系统异常,请联系管理员");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询营养基础类型列表
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ import lombok.Data;
|
|||
import lombok.ToString;
|
||||
import com.bonus.common.core.web.domain.BaseEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 营养基础类型对象 menu_nutrition_type
|
||||
*
|
||||
|
|
@ -45,5 +48,5 @@ public class MenuNutritionType extends BaseEntity {
|
|||
@ApiModelProperty(value = "层级")
|
||||
private String level;
|
||||
|
||||
|
||||
private List<MenuNutritionType> children = new ArrayList();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.bonus.canteen.core.menu.service;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.bonus.canteen.core.common.domain.TreeSelect;
|
||||
import com.bonus.canteen.core.menu.domain.MenuNutritionType;
|
||||
import com.bonus.canteen.core.menu.vo.NutritionTypeV2VO;
|
||||
import com.bonus.canteen.core.menu.vo.NutritionTypeVo;
|
||||
|
|
@ -62,4 +63,6 @@ public interface IMenuNutritionTypeService {
|
|||
public int deleteMenuNutritionTypeById(Long id);
|
||||
|
||||
List<NutritionTypeV2VO> getNutritionTypeList();
|
||||
|
||||
public List<TreeSelect> selectMenuNutritionTypeTreeList(MenuNutritionType menuNutritionType);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,16 @@ package com.bonus.canteen.core.menu.service.impl;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.system.UserInfo;
|
||||
import com.bonus.canteen.core.common.domain.TreeSelect;
|
||||
import com.bonus.canteen.core.menu.mapper.MenuNutritionMapper;
|
||||
import com.bonus.canteen.core.menu.vo.NutritionTypeV2VO;
|
||||
import com.bonus.canteen.core.menu.vo.NutritionTypeVo;
|
||||
import com.bonus.common.core.exception.ServiceException;
|
||||
import com.bonus.common.core.utils.DateUtils;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -152,4 +155,72 @@ public class MenuNutritionTypeServiceImpl implements IMenuNutritionTypeService {
|
|||
// TreeNodeUtil.assembleTree(list);
|
||||
return nutritionTypeVOList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TreeSelect> selectMenuNutritionTypeTreeList(MenuNutritionType menuNutritionType) {
|
||||
List<MenuNutritionType> menuNutritionTypes = selectMenuNutritionTypeList(menuNutritionType);
|
||||
return buildMenuNutritionTypeTreeSelect(menuNutritionTypes);
|
||||
}
|
||||
|
||||
public List<TreeSelect> buildMenuNutritionTypeTreeSelect(List<MenuNutritionType> menuNutritionTypes)
|
||||
{
|
||||
List<MenuNutritionType> menuNutritionTypeTrees = buildMenuNutritionTypeTree(menuNutritionTypes);
|
||||
return menuNutritionTypeTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<MenuNutritionType> buildMenuNutritionTypeTree(List<MenuNutritionType> list) {
|
||||
List<MenuNutritionType> returnList = new ArrayList<MenuNutritionType>();
|
||||
List<Long> tempList = list.stream().map(MenuNutritionType::getId).collect(Collectors.toList());
|
||||
for (MenuNutritionType type : list)
|
||||
{
|
||||
// 如果是顶级节点, 遍历该父节点的所有子节点
|
||||
if (!tempList.contains(type.getParentId()))
|
||||
{
|
||||
recursionFn(list, type);
|
||||
returnList.add(type);
|
||||
}
|
||||
}
|
||||
if (returnList.isEmpty())
|
||||
{
|
||||
returnList = list;
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
private void recursionFn(List<MenuNutritionType> list, MenuNutritionType t)
|
||||
{
|
||||
// 得到子节点列表
|
||||
List<MenuNutritionType> childList = getChildList(list, t);
|
||||
t.setChildren(childList);
|
||||
for (MenuNutritionType tChild : childList)
|
||||
{
|
||||
if (hasChild(list, tChild))
|
||||
{
|
||||
recursionFn(list, tChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<MenuNutritionType> getChildList(List<MenuNutritionType> list, MenuNutritionType t)
|
||||
{
|
||||
List<MenuNutritionType> tlist = new ArrayList<MenuNutritionType>();
|
||||
Iterator<MenuNutritionType> it = list.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
MenuNutritionType n = (MenuNutritionType) it.next();
|
||||
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue())
|
||||
{
|
||||
tlist.add(n);
|
||||
}
|
||||
}
|
||||
return tlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有子节点
|
||||
*/
|
||||
private boolean hasChild(List<MenuNutritionType> list, MenuNutritionType t)
|
||||
{
|
||||
return getChildList(list, t).size() > 0 ? true : false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue