浏览代码

包厢菜谱

tjf 5 月之前
父节点
当前提交
13d7643276

+ 108 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/food/MenuBoxController.java

@@ -0,0 +1,108 @@
+package com.ruoyi.web.controller.food;
+
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.domain.entity.MenuBox;
+import com.ruoyi.system.service.IMenuBoxService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+/**
+ * 包厢菜单Controller
+ *
+ * @author boman
+ * @date 2025-01-22
+ */
+@RestController
+@RequestMapping("/system/box")
+public class MenuBoxController extends BaseController {
+    @Autowired
+    private IMenuBoxService menuBoxService;
+
+    /**
+     * 查询包厢菜单列表
+     */
+    @GetMapping("/list")
+    public AjaxResult list(MenuBox menuBox) {
+        List<MenuBox> list = menuBoxService.selectMenuBoxList(menuBox);
+        return success(list);
+    }
+
+    /**
+     * 导出包厢菜单列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:box:export')")
+    @Log(title = "包厢菜单", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, MenuBox menuBox) {
+        List<MenuBox> list = menuBoxService.selectMenuBoxList(menuBox);
+        ExcelUtil<MenuBox> util = new ExcelUtil<MenuBox>(MenuBox.class);
+        util.exportExcel(response, list, "包厢菜单数据");
+    }
+
+    /**
+     * 获取包厢菜单详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('system:box:query')")
+    @GetMapping(value = "/{menuBoxId}")
+    public AjaxResult getInfo(@PathVariable("menuBoxId") Long menuBoxId) {
+        return success(menuBoxService.selectMenuBoxByMenuBoxId(menuBoxId));
+    }
+
+    /**
+     * 新增包厢菜单
+     */
+    @PreAuthorize("@ss.hasPermi('system:box:add')")
+    @Log(title = "包厢菜单", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody MenuBox menuBox) {
+        if (!menuBoxService.checkMenuBoxNameUnique(menuBox)) {
+            return error("新增菜品'" + menuBox.getFoodName() + "'失败,菜品名称已存在");
+        }
+        menuBox.setCreateBy(getUsername());
+        return toAjax(menuBoxService.insertMenuBox(menuBox));
+    }
+
+    /**
+     * 修改包厢菜单
+     */
+    @PreAuthorize("@ss.hasPermi('system:box:edit')")
+    @Log(title = "包厢菜单", businessType = BusinessType.UPDATE)
+    @PostMapping("/put")
+    public AjaxResult edit(@RequestBody MenuBox menuBox) {
+        Long menuBoxId = menuBox.getMenuBoxId();
+        if (!menuBoxService.checkMenuBoxNameUnique(menuBox)) {
+            return error("修改菜品'" + menuBox.getFoodName() + "'失败,菜品名称已存在");
+        } else if (menuBox.getParentId().equals(menuBoxId)) {
+            return error("修改菜品'" + menuBox.getFoodName() + "'失败,上级菜品不能是自己");
+        }
+        menuBox.setUpdateBy(getUsername());
+        return toAjax(menuBoxService.updateMenuBox(menuBox));
+    }
+
+    /**
+     * 删除包厢菜单
+     */
+    @PreAuthorize("@ss.hasPermi('system:box:remove')")
+    @Log(title = "包厢菜单", businessType = BusinessType.DELETE)
+    @GetMapping("/delete/{menuBoxIds}")
+    public AjaxResult remove(@PathVariable Long[] menuBoxIds) {
+        return toAjax(menuBoxService.deleteMenuBoxByMenuBoxIds(menuBoxIds));
+    }
+
+    /**
+     * 获取菜品树列表
+     */
+    @GetMapping("/deptTree")
+    public AjaxResult deptTree(MenuBox menuBox)
+    {
+        return success(menuBoxService.selectMenuBoxTreeList(menuBox));
+    }
+}

+ 21 - 42
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java

@@ -1,18 +1,5 @@
 package com.ruoyi.web.controller.system;
 
-import java.util.List;
-import org.apache.commons.lang3.ArrayUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.controller.BaseController;
@@ -21,16 +8,22 @@ import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.system.service.ISysDeptService;
+import org.apache.commons.lang3.ArrayUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
 
 /**
  * 部门信息
- * 
+ *
  * @author ruoyi
  */
 @RestController
 @RequestMapping("/system/dept")
-public class SysDeptController extends BaseController
-{
+public class SysDeptController extends BaseController {
     @Autowired
     private ISysDeptService deptService;
 
@@ -39,8 +32,7 @@ public class SysDeptController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:dept:list')")
     @GetMapping("/list")
-    public AjaxResult list(SysDept dept)
-    {
+    public AjaxResult list(SysDept dept) {
         List<SysDept> depts = deptService.selectDeptList(dept);
         return success(depts);
     }
@@ -50,8 +42,7 @@ public class SysDeptController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:dept:list')")
     @GetMapping("/list/exclude/{deptId}")
-    public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
-    {
+    public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) {
         List<SysDept> depts = deptService.selectDeptList(new SysDept());
         depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
         return success(depts);
@@ -62,8 +53,7 @@ public class SysDeptController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:dept:query')")
     @GetMapping(value = "/{deptId}")
-    public AjaxResult getInfo(@PathVariable Long deptId)
-    {
+    public AjaxResult getInfo(@PathVariable Long deptId) {
         deptService.checkDeptDataScope(deptId);
         return success(deptService.selectDeptById(deptId));
     }
@@ -74,10 +64,8 @@ public class SysDeptController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:dept:add')")
     @Log(title = "部门管理", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@Validated @RequestBody SysDept dept)
-    {
-        if (!deptService.checkDeptNameUnique(dept))
-        {
+    public AjaxResult add(@Validated @RequestBody SysDept dept) {
+        if (!deptService.checkDeptNameUnique(dept)) {
             return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
         }
         dept.setCreateBy(getUsername());
@@ -90,20 +78,14 @@ public class SysDeptController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:dept:edit')")
     @Log(title = "部门管理", businessType = BusinessType.UPDATE)
     @PostMapping("/put")
-    public AjaxResult edit(@Validated @RequestBody SysDept dept)
-    {
+    public AjaxResult edit(@Validated @RequestBody SysDept dept) {
         Long deptId = dept.getDeptId();
         deptService.checkDeptDataScope(deptId);
-        if (!deptService.checkDeptNameUnique(dept))
-        {
+        if (!deptService.checkDeptNameUnique(dept)) {
             return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
-        }
-        else if (dept.getParentId().equals(deptId))
-        {
+        } else if (dept.getParentId().equals(deptId)) {
             return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
-        }
-        else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0)
-        {
+        } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) {
             return error("该部门包含未停用的子部门!");
         }
         dept.setUpdateBy(getUsername());
@@ -116,14 +98,11 @@ public class SysDeptController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:dept:remove')")
     @Log(title = "部门管理", businessType = BusinessType.DELETE)
     @GetMapping("/delete/{deptId}")
-    public AjaxResult remove(@PathVariable Long deptId)
-    {
-        if (deptService.hasChildByDeptId(deptId))
-        {
+    public AjaxResult remove(@PathVariable Long deptId) {
+        if (deptService.hasChildByDeptId(deptId)) {
             return warn("存在下级部门,不允许删除");
         }
-        if (deptService.checkDeptExistUser(deptId))
-        {
+        if (deptService.checkDeptExistUser(deptId)) {
             return warn("部门存在用户,不允许删除");
         }
         deptService.checkDeptDataScope(deptId);

+ 72 - 3
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelect.java

@@ -1,12 +1,14 @@
 package com.ruoyi.common.core.domain;
 
-import java.io.Serializable;
-import java.util.List;
-import java.util.stream.Collectors;
 import com.fasterxml.jackson.annotation.JsonInclude;
+import com.ruoyi.common.core.domain.entity.MenuBox;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysMenu;
 
+import java.io.Serializable;
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * Treeselect树结构实体类
  * 
@@ -18,9 +20,26 @@ public class TreeSelect implements Serializable
 
     /** 节点ID */
     private Long id;
+    private Long menuBoxId;
 
     /** 节点名称 */
     private String label;
+    /**
+     * 是否推荐(N代表不推荐 Y代表推荐)
+     */
+    private String suggest;
+    /**
+     * 推荐等级
+     */
+    private String suggestLv;
+    /**
+     * 图片
+     */
+    private String foodPhoto;
+    /**
+     * 菜品名称
+     */
+    private String foodName;
 
     /** 子节点 */
     @JsonInclude(JsonInclude.Include.NON_EMPTY)
@@ -45,6 +64,56 @@ public class TreeSelect implements Serializable
         this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
     }
 
+    public TreeSelect(MenuBox menuBox)
+    {
+        this.menuBoxId = menuBox.getMenuBoxId();
+        this.foodName = menuBox.getFoodName();
+        this.foodPhoto = menuBox.getFoodPhoto();
+        this.suggest = menuBox.getSuggest();
+        this.suggestLv = menuBox.getSuggestLv();
+        this.children = menuBox.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
+    }
+
+    public String getSuggest() {
+        return suggest;
+    }
+
+    public void setSuggest(String suggest) {
+        this.suggest = suggest;
+    }
+
+    public String getSuggestLv() {
+        return suggestLv;
+    }
+
+    public void setSuggestLv(String suggestLv) {
+        this.suggestLv = suggestLv;
+    }
+
+    public String getFoodPhoto() {
+        return foodPhoto;
+    }
+
+    public void setFoodPhoto(String foodPhoto) {
+        this.foodPhoto = foodPhoto;
+    }
+
+    public String getFoodName() {
+        return foodName;
+    }
+
+    public void setFoodName(String foodName) {
+        this.foodName = foodName;
+    }
+
+    public Long getMenuBoxId() {
+        return menuBoxId;
+    }
+
+    public void setMenuBoxId(Long menuBoxId) {
+        this.menuBoxId = menuBoxId;
+    }
+
     public Long getId()
     {
         return id;

+ 159 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/MenuBox.java

@@ -0,0 +1,159 @@
+package com.ruoyi.common.core.domain.entity;
+
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 包厢菜单对象 menu_box
+ * 
+ * @author boman
+ * @date 2025-01-22
+ */
+public class MenuBox extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 包厢菜品id */
+    private Long menuBoxId;
+    /** 父ID */
+    private Long parentId;
+
+    /** 祖级列表 */
+    private String ancestors;
+
+    /** 菜品名称 */
+    @Excel(name = "菜品名称")
+    private String foodName;
+
+    /** 菜品图片 */
+    @Excel(name = "菜品图片")
+    private String foodPhoto;
+
+    /** 是否推荐(N代表不推荐 Y代表推荐) */
+    @Excel(name = "是否推荐", readConverterExp = "N=代表不推荐,Y=代表推荐")
+    private String suggest;
+
+    /** 推荐等级 */
+    @Excel(name = "推荐等级")
+    private String suggestLv;
+
+    /** 删除标志(N代表存在 Y代表删除) */
+    @Excel(name = "删除标志", readConverterExp = "N=代表存在,Y=代表删除")
+    private String isDel;
+    /** 父部门名称 */
+    private String parentName;
+
+    /** 子部门 */
+    private List<MenuBox> children = new ArrayList<MenuBox>();
+
+
+    public Long getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(Long parentId) {
+        this.parentId = parentId;
+    }
+
+    public String getAncestors() {
+        return ancestors;
+    }
+
+    public void setAncestors(String ancestors) {
+        this.ancestors = ancestors;
+    }
+
+    public String getParentName() {
+        return parentName;
+    }
+
+
+    public void setParentName(String parentName) {
+        this.parentName = parentName;
+    }
+
+    public List<MenuBox> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<MenuBox> children) {
+        this.children = children;
+    }
+
+    public void setMenuBoxId(Long menuBoxId)
+    {
+        this.menuBoxId = menuBoxId;
+    }
+
+    public Long getMenuBoxId() 
+    {
+        return menuBoxId;
+    }
+    public void setFoodName(String foodName) 
+    {
+        this.foodName = foodName;
+    }
+
+    public String getFoodName() 
+    {
+        return foodName;
+    }
+    public void setFoodPhoto(String foodPhoto) 
+    {
+        this.foodPhoto = foodPhoto;
+    }
+
+    public String getFoodPhoto() 
+    {
+        return foodPhoto;
+    }
+    public void setSuggest(String suggest) 
+    {
+        this.suggest = suggest;
+    }
+
+    public String getSuggest() 
+    {
+        return suggest;
+    }
+    public void setSuggestLv(String suggestLv) 
+    {
+        this.suggestLv = suggestLv;
+    }
+
+    public String getSuggestLv() 
+    {
+        return suggestLv;
+    }
+    public void setIsDel(String isDel) 
+    {
+        this.isDel = isDel;
+    }
+
+    public String getIsDel() 
+    {
+        return isDel;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+            .append("menuBoxId", getMenuBoxId())
+            .append("parentId", getParentId())
+            .append("ancestors", getAncestors())
+            .append("foodName", getFoodName())
+            .append("foodPhoto", getFoodPhoto())
+            .append("suggest", getSuggest())
+            .append("suggestLv", getSuggestLv())
+            .append("isDel", getIsDel())
+            .append("createBy", getCreateBy())
+            .append("createTime", getCreateTime())
+            .append("updateBy", getUpdateBy())
+            .append("updateTime", getUpdateTime())
+            .toString();
+    }
+}

+ 1 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -118,6 +118,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**","/system/app/new").permitAll()
                 .antMatchers("/real/time/getResult/**","/reservat/time/list","/system/dict/data/type/**","/system/reservat/add").permitAll()
                 .antMatchers("/system/reservat/detail/**","/system/reservat/listNoPage","/system/reservat/remove/**").permitAll()
+                .antMatchers("/system/box/list","/system/box/deptTree").permitAll()
                 // 除上面外的所有请求全部需要鉴权认证
                 .anyRequest().authenticated()
                 .and()

+ 74 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/MenuBoxMapper.java

@@ -0,0 +1,74 @@
+package com.ruoyi.system.mapper;
+
+import com.ruoyi.common.core.domain.entity.MenuBox;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 包厢菜单Mapper接口
+ * 
+ * @author boman
+ * @date 2025-01-22
+ */
+public interface MenuBoxMapper 
+{
+    /**
+     * 查询包厢菜单
+     * 
+     * @param menuBoxId 包厢菜单主键
+     * @return 包厢菜单
+     */
+    public MenuBox selectMenuBoxByMenuBoxId(Long menuBoxId);
+    public MenuBox selectMenuBoxById(Long menuBoxId);
+    /**
+     * 根据ID查询所有子菜品
+     *
+     * @param menuBoxId 菜品ID
+     * @return 菜品列表
+     */
+    public List<MenuBox> selectChildrenMenuBoxById(Long menuBoxId);
+
+    public  int updateMenuBoxChildren(@Param("menuBoxs") List<MenuBox> menuBoxs);
+    /**
+     * 查询包厢菜单列表
+     * 
+     * @param menuBox 包厢菜单
+     * @return 包厢菜单集合
+     */
+    public List<MenuBox> selectMenuBoxList(MenuBox menuBox);
+
+    /**
+     * 新增包厢菜单
+     * 
+     * @param menuBox 包厢菜单
+     * @return 结果
+     */
+    public int insertMenuBox(MenuBox menuBox);
+
+    /**
+     * 修改包厢菜单
+     * 
+     * @param menuBox 包厢菜单
+     * @return 结果
+     */
+    public int updateMenuBox(MenuBox menuBox);
+
+    /**
+     * 删除包厢菜单
+     * 
+     * @param menuBoxId 包厢菜单主键
+     * @return 结果
+     */
+    public int deleteMenuBoxByMenuBoxId(Long menuBoxId);
+
+    /**
+     * 批量删除包厢菜单
+     * 
+     * @param menuBoxIds 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteMenuBoxByMenuBoxIds(Long[] menuBoxIds);
+
+    public MenuBox checkMenuBoxNameUnique(@Param("foodName") String foodName, @Param("parentId") Long parentId);
+}

+ 90 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IMenuBoxService.java

@@ -0,0 +1,90 @@
+package com.ruoyi.system.service;
+
+import com.ruoyi.common.core.domain.TreeSelect;
+import com.ruoyi.common.core.domain.entity.MenuBox;
+
+import java.util.List;
+
+/**
+ * 包厢菜单Service接口
+ * 
+ * @author boman
+ * @date 2025-01-22
+ */
+public interface IMenuBoxService 
+{
+    /**
+     * 查询包厢菜单
+     * 
+     * @param menuBoxId 包厢菜单主键
+     * @return 包厢菜单
+     */
+    public MenuBox selectMenuBoxByMenuBoxId(Long menuBoxId);
+
+    /**
+     * 查询包厢菜单列表
+     * 
+     * @param menuBox 包厢菜单
+     * @return 包厢菜单集合
+     */
+    public List<MenuBox> selectMenuBoxList(MenuBox menuBox);
+
+    /**
+     * 查询菜品树结构信息
+     *
+     * @param menuBox 菜品信息
+     * @return 菜品树信息集合
+     */
+    public List<TreeSelect> selectMenuBoxTreeList(MenuBox menuBox);
+
+    /**
+     * 构建前端所需要下拉树结构
+     *
+     * @param menuBoxs 菜品列表
+     * @return 下拉树结构列表
+     */
+    public List<TreeSelect> buildMenuBoxTreeSelect(List<MenuBox> menuBoxs);
+
+    /**
+     * 构建前端所需要树结构
+     *
+     * @param menuBoxs 菜品列表
+     * @return 树结构列表
+     */
+    public List<MenuBox> buildMenuBoxTree(List<MenuBox> menuBoxs);
+
+    /**
+     * 新增包厢菜单
+     * 
+     * @param menuBox 包厢菜单
+     * @return 结果
+     */
+    public int insertMenuBox(MenuBox menuBox);
+
+    /**
+     * 修改包厢菜单
+     * 
+     * @param menuBox 包厢菜单
+     * @return 结果
+     */
+    public int updateMenuBox(MenuBox menuBox);
+
+    /**
+     * 批量删除包厢菜单
+     * 
+     * @param menuBoxIds 需要删除的包厢菜单主键集合
+     * @return 结果
+     */
+    public int deleteMenuBoxByMenuBoxIds(Long[] menuBoxIds);
+
+    /**
+     * 删除包厢菜单信息
+     * 
+     * @param menuBoxId 包厢菜单主键
+     * @return 结果
+     */
+    public int deleteMenuBoxByMenuBoxId(Long menuBoxId);
+    public boolean checkMenuBoxNameUnique(MenuBox menuBox);
+
+
+}

+ 238 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MenuBoxServiceImpl.java

@@ -0,0 +1,238 @@
+package com.ruoyi.system.service.impl;
+
+import com.ruoyi.common.constant.UserConstants;
+import com.ruoyi.common.core.domain.TreeSelect;
+import com.ruoyi.common.core.domain.entity.MenuBox;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.system.mapper.MenuBoxMapper;
+import com.ruoyi.system.service.IMenuBoxService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 包厢菜单Service业务层处理
+ *
+ * @author boman
+ * @date 2025-01-22
+ */
+@Service
+public class MenuBoxServiceImpl implements IMenuBoxService {
+    @Autowired
+    private MenuBoxMapper menuBoxMapper;
+
+    /**
+     * 查询包厢菜单
+     *
+     * @param menuBoxId 包厢菜单主键
+     * @return 包厢菜单
+     */
+    @Override
+    public MenuBox selectMenuBoxByMenuBoxId(Long menuBoxId) {
+        return menuBoxMapper.selectMenuBoxByMenuBoxId(menuBoxId);
+    }
+
+    /**
+     * 查询包厢菜单列表
+     *
+     * @param menuBox 包厢菜单
+     * @return 包厢菜单
+     */
+    @Override
+    public List<MenuBox> selectMenuBoxList(MenuBox menuBox) {
+        return menuBoxMapper.selectMenuBoxList(menuBox);
+    }
+
+    /**
+     * 查询菜品树结构信息
+     *
+     * @param menuBox 菜品信息
+     * @return 菜品树信息集合
+     */
+    @Override
+    public List<TreeSelect> selectMenuBoxTreeList(MenuBox menuBox) {
+        List<MenuBox> menuBoxes = selectMenuBoxList(menuBox);
+        return buildMenuBoxTreeSelect(menuBoxes);
+    }
+
+    /**
+     * 构建前端所需要下拉树结构
+     *
+     * @param menuBoxs 菜品列表
+     * @return 下拉树结构列表
+     */
+    @Override
+    public List<TreeSelect> buildMenuBoxTreeSelect(List<MenuBox> menuBoxs) {
+        List<MenuBox> menuBoxTrees = buildMenuBoxTree(menuBoxs);
+        return menuBoxTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
+    }
+
+
+    /**
+     * 构建前端所需要树结构
+     *
+     * @param menuBoxs 菜品列表
+     * @return 树结构列表
+     */
+    @Override
+    public List<MenuBox> buildMenuBoxTree(List<MenuBox> menuBoxs) {
+        List<MenuBox> returnList = new ArrayList<MenuBox>();
+        List<Long> tempList = menuBoxs.stream().map(MenuBox::getMenuBoxId).collect(Collectors.toList());
+        for (MenuBox menuBox : menuBoxs) {
+            // 如果是顶级节点, 遍历该父节点的所有子节点
+            if (!tempList.contains(menuBox.getParentId())) {
+                recursionFn(menuBoxs, menuBox);
+                returnList.add(menuBox);
+            }
+        }
+        if (returnList.isEmpty()) {
+            returnList = menuBoxs;
+        }
+        return returnList;
+    }
+
+    /**
+     * 递归列表
+     */
+    private void recursionFn(List<MenuBox> list, MenuBox t) {
+        // 得到子节点列表
+        List<MenuBox> childList = getChildList(list, t);
+        t.setChildren(childList);
+        for (MenuBox tChild : childList) {
+            if (hasChild(list, tChild)) {
+                recursionFn(list, tChild);
+            }
+        }
+    }
+
+    /**
+     * 得到子节点列表
+     */
+    private List<MenuBox> getChildList(List<MenuBox> list, MenuBox t) {
+        List<MenuBox> tlist = new ArrayList<MenuBox>();
+        Iterator<MenuBox> it = list.iterator();
+        while (it.hasNext()) {
+            MenuBox n = (MenuBox) it.next();
+            if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getMenuBoxId().longValue()) {
+                tlist.add(n);
+            }
+        }
+        return tlist;
+    }
+
+    /**
+     * 判断是否有子节点
+     */
+    private boolean hasChild(List<MenuBox> list, MenuBox t) {
+        return getChildList(list, t).size() > 0;
+    }
+
+    /**
+     * 新增包厢菜单
+     *
+     * @param menuBox 包厢菜单
+     * @return 结果
+     */
+    @Override
+    public int insertMenuBox(MenuBox menuBox) {
+        MenuBox info = menuBoxMapper.selectMenuBoxByMenuBoxId(menuBox.getParentId());
+        if (info != null) {
+            // 如果父节点不为正常状态,则不允许新增子节点
+            if (UserConstants.YES.equals(info.getIsDel())) {
+                throw new ServiceException("菜品菜单删除,不允许新增");
+            }
+            menuBox.setAncestors(info.getAncestors() + "," + menuBox.getParentId());
+            menuBox.setCreateTime(DateUtils.getNowDate());
+            return menuBoxMapper.insertMenuBox(menuBox);
+        } else {
+            menuBox.setParentId(0L);
+            menuBox.setAncestors("0");
+            menuBox.setCreateTime(DateUtils.getNowDate());
+            int i = menuBoxMapper.insertMenuBox(menuBox);
+            return i;
+        }
+    }
+
+    /**
+     * 修改包厢菜单
+     *
+     * @param menuBox 包厢菜单
+     * @return 结果
+     */
+    @Override
+    public int updateMenuBox(MenuBox menuBox) {
+        MenuBox newParentMenuBox = menuBoxMapper.selectMenuBoxById(menuBox.getParentId());
+        MenuBox oldMenuBox = menuBoxMapper.selectMenuBoxById(menuBox.getMenuBoxId());
+        if (StringUtils.isNotNull(newParentMenuBox) && StringUtils.isNotNull(oldMenuBox)) {
+            String newAncestors = newParentMenuBox.getAncestors() + "," + newParentMenuBox.getMenuBoxId();
+            String oldAncestors = oldMenuBox.getAncestors();
+            menuBox.setAncestors(newAncestors);
+            updateMenuBoxChildren(menuBox.getMenuBoxId(), newAncestors, oldAncestors);
+        }
+        menuBox.setUpdateTime(DateUtils.getNowDate());
+        return menuBoxMapper.updateMenuBox(menuBox);
+    }
+
+    /**
+     * 修改子元素关系
+     *
+     * @param menuBoxId    被修改的菜品ID
+     * @param newAncestors 新的父ID集合
+     * @param oldAncestors 旧的父ID集合
+     */
+    public void updateMenuBoxChildren(Long menuBoxId, String newAncestors, String oldAncestors) {
+        List<MenuBox> children = menuBoxMapper.selectChildrenMenuBoxById(menuBoxId);
+        for (MenuBox child : children) {
+            child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
+        }
+        if (children.size() > 0) {
+            menuBoxMapper.updateMenuBoxChildren(children);
+        }
+    }
+
+    /**
+     * 批量删除包厢菜单
+     *
+     * @param menuBoxIds 需要删除的包厢菜单主键
+     * @return 结果
+     */
+    @Override
+    public int deleteMenuBoxByMenuBoxIds(Long[] menuBoxIds) {
+        return menuBoxMapper.deleteMenuBoxByMenuBoxIds(menuBoxIds);
+    }
+
+    /**
+     * 删除包厢菜单信息
+     *
+     * @param menuBoxId 包厢菜单主键
+     * @return 结果
+     */
+    @Override
+    public int deleteMenuBoxByMenuBoxId(Long menuBoxId) {
+        return menuBoxMapper.deleteMenuBoxByMenuBoxId(menuBoxId);
+    }
+
+
+    /**
+     * 校验菜品名称是否唯一
+     *
+     * @param menuBox 菜品信息
+     * @return 结果
+     */
+    @Override
+    public boolean checkMenuBoxNameUnique(MenuBox menuBox) {
+        Long deptId = StringUtils.isNull(menuBox.getMenuBoxId()) ? -1L : menuBox.getMenuBoxId();
+        MenuBox info = menuBoxMapper.checkMenuBoxNameUnique(menuBox.getFoodName(), menuBox.getParentId());
+
+        if (StringUtils.isNotNull(info) && info.getMenuBoxId().longValue() != deptId.longValue()) {
+            return UserConstants.NOT_UNIQUE;
+        }
+        return UserConstants.UNIQUE;
+    }
+}

+ 128 - 0
ruoyi-system/src/main/resources/mapper/system/MenuBoxMapper.xml

@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.system.mapper.MenuBoxMapper">
+    
+    <resultMap type="MenuBox" id="MenuBoxResult">
+        <result property="menuBoxId"    column="menu_box_id"    />
+        <result property="parentId"    column="parent_id"    />
+        <result property="ancestors"    column="ancestors"    />
+        <result property="foodName"    column="food_name"    />
+        <result property="foodPhoto"    column="food_photo"    />
+        <result property="suggest"    column="suggest"    />
+        <result property="suggestLv"    column="suggest_lv"    />
+        <result property="parentName" column="parent_name" />
+        <result property="isDel"    column="is_del"    />
+        <result property="createBy"    column="create_by"    />
+        <result property="createTime"    column="create_time"    />
+        <result property="updateBy"    column="update_by"    />
+        <result property="updateTime"    column="update_time"    />
+    </resultMap>
+
+    <sql id="selectMenuBoxVo">
+        select menu_box_id, parent_id, ancestors, food_name, food_photo, suggest, suggest_lv, is_del, create_by, create_time, update_by, update_time from menu_box
+    </sql>
+
+    <select id="selectMenuBoxList" parameterType="MenuBox" resultMap="MenuBoxResult">
+        <include refid="selectMenuBoxVo"/>
+        <where>  
+            <if test="parentId != null "> and parent_id = #{parentId}</if>
+            <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
+            <if test="foodName != null  and foodName != ''"> and food_name like concat('%', #{foodName}, '%')</if>
+            <if test="foodPhoto != null  and foodPhoto != ''"> and food_photo = #{foodPhoto}</if>
+            <if test="suggest != null  and suggest != ''"> and suggest = #{suggest}</if>
+            <if test="suggestLv != null  and suggestLv != ''"> and suggest_lv = #{suggestLv}</if>
+            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
+        </where>
+    </select>
+    
+    <select id="selectMenuBoxByMenuBoxId" parameterType="Long" resultMap="MenuBoxResult">
+        <include refid="selectMenuBoxVo"/>
+        where menu_box_id = #{menuBoxId}
+    </select>
+    <select id="checkMenuBoxNameUnique" resultMap="MenuBoxResult">
+        <include refid="selectMenuBoxVo"/>
+        where food_name=#{foodName} and parent_id = #{parentId} and is_del = 'N' limit 1
+    </select>
+    <select id="selectMenuBoxById" parameterType="Long" resultMap="MenuBoxResult">
+        select b.menu_box_id, b.parent_id, b.ancestors, b.food_name, b.food_photo, b.suggest, b.suggest_lv, b.is_del,
+               (select food_name from menu_box where menu_box_id = b.parent_id) parent_name
+        from menu_box b
+        where b.menu_box_id = #{menuBoxId}
+    </select>
+    <select id="selectChildrenMenuBoxById" parameterType="Long" resultMap="MenuBoxResult">
+        select * from menu_box where find_in_set(#{menuBoxId}, ancestors)
+    </select>
+
+    <insert id="insertMenuBox" parameterType="MenuBox" useGeneratedKeys="true" keyProperty="menuBoxId">
+        insert into menu_box
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="parentId != null">parent_id,</if>
+            <if test="ancestors != null">ancestors,</if>
+            <if test="foodName != null">food_name,</if>
+            <if test="foodPhoto != null">food_photo,</if>
+            <if test="suggest != null">suggest,</if>
+            <if test="suggestLv != null">suggest_lv,</if>
+            <if test="isDel != null">is_del,</if>
+            <if test="createBy != null">create_by,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="updateBy != null">update_by,</if>
+            <if test="updateTime != null">update_time,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="parentId != null">#{parentId},</if>
+            <if test="ancestors != null">#{ancestors},</if>
+            <if test="foodName != null">#{foodName},</if>
+            <if test="foodPhoto != null">#{foodPhoto},</if>
+            <if test="suggest != null">#{suggest},</if>
+            <if test="suggestLv != null">#{suggestLv},</if>
+            <if test="isDel != null">#{isDel},</if>
+            <if test="createBy != null">#{createBy},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="updateBy != null">#{updateBy},</if>
+            <if test="updateTime != null">#{updateTime},</if>
+         </trim>
+    </insert>
+
+    <update id="updateMenuBox" parameterType="MenuBox">
+        update menu_box
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="parentId != null">parent_id = #{parentId},</if>
+            <if test="ancestors != null">ancestors = #{ancestors},</if>
+            <if test="foodName != null">food_name = #{foodName},</if>
+            <if test="foodPhoto != null">food_photo = #{foodPhoto},</if>
+            <if test="suggest != null">suggest = #{suggest},</if>
+            <if test="suggestLv != null">suggest_lv = #{suggestLv},</if>
+            <if test="isDel != null">is_del = #{isDel},</if>
+            <if test="createBy != null">create_by = #{createBy},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="updateBy != null">update_by = #{updateBy},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+        </trim>
+        where menu_box_id = #{menuBoxId}
+    </update>
+    <update id="updateMenuBoxChildren" parameterType="java.util.List">
+        update menu_box set ancestors =
+        <foreach collection="menuBoxs" item="item" index="index"
+                 separator=" " open="case menu_box_id" close="end">
+            when #{item.menuBoxId} then #{item.ancestors}
+        </foreach>
+        where menu_box_id in
+        <foreach collection="menuBoxs" item="item" index="index"
+                 separator="," open="(" close=")">
+            #{item.menuBoxId}
+        </foreach>
+    </update>
+
+    <delete id="deleteMenuBoxByMenuBoxId" parameterType="Long">
+        delete from menu_box where menu_box_id = #{menuBoxId}
+    </delete>
+
+    <delete id="deleteMenuBoxByMenuBoxIds" parameterType="String">
+        delete from menu_box where menu_box_id in 
+        <foreach item="menuBoxId" collection="array" open="(" separator="," close=")">
+            #{menuBoxId}
+        </foreach>
+    </delete>
+</mapper>