Bläddra i källkod

中台权限页面 开发

wuchen 2 månader sedan
förälder
incheckning
4a85fcfabf

+ 10 - 0
alien-entity/src/main/java/shop/alien/entity/store/StorePlatformMenu.java

@@ -2,6 +2,7 @@ package shop.alien.entity.store;
 
 import com.baomidou.mybatisplus.annotation.*;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -19,6 +20,7 @@ import java.util.List;
  */
 @Data
 @JsonInclude
+@JsonIgnoreProperties(ignoreUnknown = true)
 @TableName("store_platform_menu")
 @ApiModel(value = "StorePlatformMenu对象", description = "商家PC菜单权限表")
 public class StorePlatformMenu implements Serializable {
@@ -111,5 +113,13 @@ public class StorePlatformMenu implements Serializable {
     @ApiModelProperty(value = "子菜单列表(用于树形结构)")
     @TableField(exist = false)
     private List<StorePlatformMenu> children;
+
+    @ApiModelProperty(value = "一级分类名称(用于展示,只读)")
+    @TableField(exist = false)
+    private String firstLevelMenuName;
+
+    @ApiModelProperty(value = "二级分类名称(用于展示,只读)")
+    @TableField(exist = false)
+    private String secondLevelMenuName;
 }
 

+ 23 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/StorePlatformMenuVo.java

@@ -0,0 +1,23 @@
+package shop.alien.entity.store.vo;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import shop.alien.entity.store.StorePlatformMenu;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ *  菜单Vo
+ */
+@Data
+@JsonInclude
+@ApiModel(value = "StorePlatformMenuVo对象", description = "菜单Vo")
+public class StorePlatformMenuVo extends StorePlatformMenu implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "子菜单列表(用于树形结构)")
+    private List<StorePlatformMenu> children;
+}

+ 5 - 0
alien-entity/src/main/java/shop/alien/mapper/StorePlatformMenuMapper.java

@@ -1,9 +1,12 @@
 package shop.alien.mapper;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import shop.alien.entity.store.StorePlatformMenu;
+import shop.alien.entity.store.vo.StorePlatformMenuVo;
 
 import java.util.List;
 
@@ -16,6 +19,8 @@ import java.util.List;
 @Mapper
 public interface StorePlatformMenuMapper extends BaseMapper<StorePlatformMenu> {
 
+    IPage<StorePlatformMenuVo> selectList(IPage<StorePlatformMenuVo> store, LambdaQueryWrapper<StorePlatformMenuVo> queryWrapper);
+
     /**
      * 根据角色ID查询权限菜单列表
      *

+ 143 - 0
alien-store/src/main/java/shop/alien/store/controller/StorePlatformMenuController.java

@@ -0,0 +1,143 @@
+package shop.alien.store.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import io.swagger.annotations.*;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+import shop.alien.entity.result.R;
+import shop.alien.entity.store.StorePlatformMenu;
+import shop.alien.entity.store.vo.StorePlatformMenuVo;
+import shop.alien.store.service.StorePlatformMenuService;
+
+/**
+ * 商家菜单管理
+ *
+ */
+@Slf4j
+@Api(tags = {"平台-菜单管理"})
+@ApiSort(1)
+@CrossOrigin
+@RestController
+@RequestMapping("/platform")
+@RequiredArgsConstructor
+public class StorePlatformMenuController {
+    private final StorePlatformMenuService storePlatformMenuService;
+
+    @ApiOperation("分页查询菜单列表")
+    @ApiOperationSupport(order = 1)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "page", value = "页码", dataType = "int", paramType = "query", required = true),
+            @ApiImplicitParam(name = "size", value = "页容", dataType = "int", paramType = "query", required = true),
+            @ApiImplicitParam(name = "menuName", value = "菜单名称(支持模糊查询)", dataType = "String", paramType = "query")
+    })
+    @GetMapping("/getMenulist")
+    public R<IPage<StorePlatformMenuVo>> getMenuPage(
+            @RequestParam(name = "page", defaultValue = "1") int page,
+            @RequestParam(name = "size", defaultValue = "10") int size,
+            @RequestParam(value = "menuName", required = false) String menuName) {
+        log.info("StorePlatformMenuController.getMenuPage?page={}, size={}, menuName={}",
+                page, size, menuName);
+        IPage<StorePlatformMenuVo> store = storePlatformMenuService.getMenuPage(page, size, menuName);
+        return R.data(store);
+    }
+
+
+    @ApiOperation("查询/编辑当前菜单(JSON方式)")
+    @ApiOperationSupport(order = 2)
+    @PostMapping(value = "/getMenuById", consumes = "application/json")
+    public R<StorePlatformMenu> getMenuById(@RequestBody StorePlatformMenu storePlatformMenu) {
+        log.info("StorePlatformMenuController.getMenuById(JSON)?menuId={}",
+                storePlatformMenu != null ? storePlatformMenu.getMenuId() : null);
+        if (storePlatformMenu == null || storePlatformMenu.getMenuId() == null) {
+            log.warn("查询/编辑当前菜单信息失败:菜单ID为空");
+            return R.fail("菜单ID不能为空");
+        }
+        
+        R<StorePlatformMenu> result = storePlatformMenuService.getByMenuId(storePlatformMenu);
+        if (result.isSuccess()) {
+            StorePlatformMenu menu = result.getData();
+            log.info("查询/编辑当前菜单信息成功,菜单ID={}, 菜单名称={}, 菜单路径={}, 菜单状态={}, 菜单层级={}, 一级菜单名称={}, 二级菜单名称={}",
+                    menu != null ? menu.getMenuId() : null,
+                    menu != null ? menu.getMenuName() : null,
+                    menu != null ? menu.getPath() : null,
+                    menu != null ? menu.getStatus() : null,
+                    menu != null ? menu.getLevel() : null,
+                    menu != null ? menu.getFirstLevelMenuName() : null,
+                    menu != null ? menu.getSecondLevelMenuName() : null);
+        } else {
+            log.warn("查询/编辑当前菜单信息失败,菜单ID={}", storePlatformMenu.getMenuId());
+        }
+        return result;
+    }
+
+
+    @ApiOperation("删除当前菜单(GET方式,URL参数)")
+    @ApiOperationSupport(order = 3)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "menuId", value = "菜单ID", dataType = "long", paramType = "query", required = true)
+    })
+    @GetMapping("/deleteMenuDetails")
+    public R<StorePlatformMenu> deleteMenuDetailsByIdByGet(
+            @RequestParam Long menuId) {
+        log.info("StorePlatformMenuController.deleteMenuDetailsByIdByGet? menuId={}",  menuId);
+        
+        StorePlatformMenu storePlatformMenu = new StorePlatformMenu();
+        storePlatformMenu.setMenuId(menuId);
+        return storePlatformMenuService.deleteMenuDetails(storePlatformMenu);
+    }
+
+
+    @ApiOperation("启用禁用状态")
+    @ApiOperationSupport(order = 4)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "menuId", value = "菜单ID", dataType = "long", paramType = "query", required = true),
+            @ApiImplicitParam(name = "status", value = "是否显示(0显示 1隐藏)", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name ="level" , value = "菜单层级(1一级菜单 2二级菜单 3三级菜单)",dataType = "int", paramType = "query")
+    })
+    @GetMapping("/updateMenuStatus")
+    public R<StorePlatformMenu> updateMenuStatus(
+            @RequestParam Long menuId,
+            @RequestParam String status,
+            @RequestParam Integer level) {
+        log.info("StorePlatformMenuController.updateMenuStatus? menuId={},status={},level={}",  menuId,status,level);
+
+        StorePlatformMenu storePlatformMenu = new StorePlatformMenu();
+        storePlatformMenu.setMenuId(menuId);
+        storePlatformMenu.setStatus(status);
+        storePlatformMenu.setLevel(level);
+        return storePlatformMenuService.editUpdateMenuStatus(menuId,status,level);
+    }
+
+    @ApiOperation("新增菜单")
+    @ApiOperationSupport(order = 5)
+    @PostMapping("/addMenuStatus")
+    public R<StorePlatformMenu> addMenuStatus(@RequestBody StorePlatformMenu store) {
+        log.info("StorePlatformMenuController.addMenuStatus?菜单名称={}, 一级分类名称={}, 二级分类名称={}",
+                store != null ? store.getMenuName() : null,
+                store != null ? store.getFirstLevelMenuName() : null,
+                store != null ? store.getSecondLevelMenuName() : null);
+        
+        if (store == null) {
+            log.warn("新增菜单失败:菜单信息为空");
+            return R.fail("菜单信息不能为空");
+        }
+
+        R<StorePlatformMenu> result = storePlatformMenuService.addByMenu(store);
+        if (result.isSuccess()) {
+            StorePlatformMenu menu = result.getData();
+            log.info("新增菜单成功,菜单ID={}, 菜单名称={}, 菜单路径={}, 菜单状态={}, 菜单层级={}, 一级菜单名称={}, 二级菜单名称={}",
+                    menu != null ? menu.getMenuId() : null,
+                    menu != null ? menu.getMenuName() : null,
+                    menu != null ? menu.getPath() : null,
+                    menu != null ? menu.getStatus() : null,
+                    menu != null ? menu.getLevel() : null,
+                    menu != null ? menu.getFirstLevelMenuName() : null,
+                    menu != null ? menu.getSecondLevelMenuName() : null);
+        } else {
+            log.warn("新增菜单失败,菜单名称={}", store.getMenuName());
+        }
+        return result;
+    }
+
+}

+ 33 - 0
alien-store/src/main/java/shop/alien/store/service/StorePlatformMenuService.java

@@ -0,0 +1,33 @@
+package shop.alien.store.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import shop.alien.entity.result.R;
+import shop.alien.entity.store.StorePlatformMenu;
+import shop.alien.entity.store.vo.StorePlatformMenuVo;
+
+public interface StorePlatformMenuService {
+    /**
+     * 分页查询
+     * @param page
+     * @param size
+     * @param menuName
+     * @return
+     */
+    IPage<StorePlatformMenuVo> getMenuPage(int page, int size, String menuName);
+
+    /**
+     * 编辑菜单ID
+     * @param storePlatformMenu
+     * @return
+     */
+    R<StorePlatformMenu> getByMenuId(StorePlatformMenu storePlatformMenu);
+
+
+    R<StorePlatformMenu> deleteMenuDetails(StorePlatformMenu storePlatformMenu);
+
+
+
+    R<StorePlatformMenu> editUpdateMenuStatus(Long menuId,String status,Integer level);
+
+    R<StorePlatformMenu> addByMenu(StorePlatformMenu store);
+}

+ 980 - 0
alien-store/src/main/java/shop/alien/store/service/impl/StorePlatformMenuServiceImpl.java

@@ -0,0 +1,980 @@
+package shop.alien.store.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+import shop.alien.entity.result.R;
+import shop.alien.entity.store.StorePlatformMenu;
+import shop.alien.entity.store.vo.StorePlatformMenuVo;
+import shop.alien.mapper.StorePlatformMenuMapper;
+import shop.alien.store.service.StorePlatformMenuService;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 商家菜单管理 业务层实现
+ */
+@Slf4j
+@Service
+@RequiredArgsConstructor
+@Transactional
+public class StorePlatformMenuServiceImpl extends ServiceImpl<StorePlatformMenuMapper, StorePlatformMenu> implements StorePlatformMenuService {
+
+    private final StorePlatformMenuMapper storePlatformMenuMapper;
+
+    @Override
+    public IPage<StorePlatformMenuVo> getMenuPage(int page, int size, String menuName) {
+        log.info("分页查询菜单列表,页码={}, 页大小={}, 菜单名称={}", page, size, menuName);
+        
+        // 1. 查询所有未删除的菜单(支持模糊查询)
+        LambdaQueryWrapper<StorePlatformMenu> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(StorePlatformMenu::getDelFlag, "0");
+        
+        // 支持菜单名称模糊查询
+        if (StringUtils.hasText(menuName)) {
+            queryWrapper.like(StorePlatformMenu::getMenuName, menuName);
+        }
+        
+        // 按显示顺序和创建时间排序
+        queryWrapper.orderByAsc(StorePlatformMenu::getMenuSort);
+        queryWrapper.orderByDesc(StorePlatformMenu::getCreatedTime);
+        
+        // 查询所有符合条件的菜单
+        List<StorePlatformMenu> allMenus = storePlatformMenuMapper.selectList(queryWrapper);
+        
+        // 转换为VO对象
+        List<StorePlatformMenuVo> allMenuVos = allMenus.stream()
+                .map(this::convertToVo)
+                .collect(Collectors.toList());
+        
+        // 2. 构建树形结构(根据parent_id构建)
+        List<StorePlatformMenuVo> treeMenus = buildMenuTreeByParentId(allMenuVos);
+        
+        // 3. 对一级菜单(parent_id = 0 或 null)进行分页
+        List<StorePlatformMenuVo> level1Menus = treeMenus.stream()
+                .filter(menu -> menu.getParentId() == null || menu.getParentId() == 0)
+                .collect(Collectors.toList());
+        
+        // 计算分页
+        int total = level1Menus.size();
+        int start = (page - 1) * size;
+        int end = Math.min(start + size, total);
+        
+        List<StorePlatformMenuVo> pageMenus = start < total ? level1Menus.subList(start, end) : new ArrayList<>();
+        
+        // 4. 构建分页结果
+        IPage<StorePlatformMenuVo> pageResult = new Page<>(page, size, total);
+        pageResult.setRecords(pageMenus);
+        
+        log.info("分页查询菜单列表完成,总记录数={}, 当前页记录数={}", total, pageMenus.size());
+        
+        return pageResult;
+    }
+    
+    /**
+     * 将StorePlatformMenu转换为StorePlatformMenuVo
+     */
+    private StorePlatformMenuVo convertToVo(StorePlatformMenu menu) {
+        StorePlatformMenuVo vo = new StorePlatformMenuVo();
+        vo.setMenuId(menu.getMenuId());
+        vo.setMenuName(menu.getMenuName());
+        vo.setParentId(menu.getParentId());
+        vo.setMenuType(menu.getMenuType());
+        vo.setMenuSort(menu.getMenuSort());
+        vo.setLevel(menu.getLevel());
+        vo.setPath(menu.getPath());
+        vo.setComponent(menu.getComponent());
+        vo.setPerms(menu.getPerms());
+        vo.setIcon(menu.getIcon());
+        vo.setStatus(menu.getStatus());
+        vo.setVisible(menu.getVisible());
+        vo.setIsFrame(menu.getIsFrame());
+        vo.setIsCache(menu.getIsCache());
+        vo.setDelFlag(menu.getDelFlag());
+        vo.setCreateBy(menu.getCreateBy());
+        vo.setCreatedTime(menu.getCreatedTime());
+        vo.setUpdateBy(menu.getUpdateBy());
+        vo.setUpdatedTime(menu.getUpdatedTime());
+        vo.setRemark(menu.getRemark());
+        vo.setChildren(new ArrayList<StorePlatformMenu>());
+        return vo;
+    }
+    
+    /**
+     * 根据parent_id构建菜单树形结构
+     * parent_id = 0 或 null 表示一级菜单
+     * 一级菜单包含二级菜单,二级菜单包含三级菜单
+     * 同时设置父菜单名称用于回显
+     */
+    private List<StorePlatformMenuVo> buildMenuTreeByParentId(List<StorePlatformMenuVo> allMenus) {
+        // 创建菜单ID到菜单对象的映射,便于快速查找
+        Map<Long, StorePlatformMenuVo> menuMap = allMenus.stream()
+                .collect(Collectors.toMap(StorePlatformMenuVo::getMenuId, menu -> menu));
+        
+        // 获取一级菜单(parent_id = 0 或 null)
+        List<StorePlatformMenuVo> rootMenus = allMenus.stream()
+                .filter(menu -> menu.getParentId() == null || menu.getParentId() == 0)
+                .sorted((a, b) -> {
+                    if (a.getMenuSort() != null && b.getMenuSort() != null) {
+                        return a.getMenuSort().compareTo(b.getMenuSort());
+                    }
+                    return 0;
+                })
+                .collect(Collectors.toList());
+        
+        // 递归构建树形结构
+        for (StorePlatformMenuVo rootMenu : rootMenus) {
+            buildChildrenRecursive(rootMenu, allMenus, menuMap);
+        }
+        
+        return rootMenus;
+    }
+    
+    /**
+     * 递归构建子菜单树
+     * 
+     * @param parentMenu 父菜单
+     * @param allMenus 所有菜单列表
+     * @param menuMap 菜单ID到菜单对象的映射
+     */
+    private void buildChildrenRecursive(StorePlatformMenuVo parentMenu, 
+                                       List<StorePlatformMenuVo> allMenus, 
+                                       Map<Long, StorePlatformMenuVo> menuMap) {
+        // 查找当前菜单的所有子菜单(parent_id = 当前菜单的menu_id)
+        List<StorePlatformMenuVo> children = allMenus.stream()
+                .filter(menu -> parentMenu.getMenuId().equals(menu.getParentId()))
+                .sorted((a, b) -> {
+                    if (a.getMenuSort() != null && b.getMenuSort() != null) {
+                        return a.getMenuSort().compareTo(b.getMenuSort());
+                    }
+                    return 0;
+                })
+                .collect(Collectors.toList());
+        
+        if (CollectionUtils.isEmpty(children)) {
+            parentMenu.setChildren(new ArrayList<StorePlatformMenu>());
+            return;
+        }
+        
+        // 设置父菜单名称用于回显
+        for (StorePlatformMenuVo childMenu : children) {
+            // 设置一级父菜单名称
+            if (parentMenu.getParentId() == null || parentMenu.getParentId() == 0) {
+                // 如果父菜单是一级菜单,子菜单设置一级父菜单名称
+                childMenu.setFirstLevelMenuName(parentMenu.getMenuName());
+            } else {
+                // 如果父菜单是二级菜单,子菜单设置二级父菜单名称
+                childMenu.setSecondLevelMenuName(parentMenu.getMenuName());
+                // 同时查找一级父菜单名称
+                StorePlatformMenuVo grandParentMenu = menuMap.get(parentMenu.getParentId());
+                if (grandParentMenu != null) {
+                    childMenu.setFirstLevelMenuName(grandParentMenu.getMenuName());
+                }
+            }
+            
+            // 递归构建子菜单的子菜单
+            buildChildrenRecursive(childMenu, allMenus, menuMap);
+        }
+        
+        // 转换为 List<StorePlatformMenu> 类型
+        List<StorePlatformMenu> menuChildren = new ArrayList<StorePlatformMenu>();
+        menuChildren.addAll(children);
+        parentMenu.setChildren(menuChildren);
+    }
+
+    @Override
+    public R<StorePlatformMenu> getByMenuId(StorePlatformMenu storePlatformMenu) {
+        Long menuId = storePlatformMenu.getMenuId();
+        log.info("开始查询/编辑菜单,菜单ID={}", menuId);
+
+        // 参数校验:菜单ID不能为空
+        if (menuId == null) {
+            log.warn("查询/编辑菜单失败:ID为空");
+            return R.fail("菜单ID不能为空");
+        }
+
+        // 查询当前菜单信息
+        StorePlatformMenu currentMenu = storePlatformMenuMapper.selectById(menuId);
+        if (currentMenu == null) {
+            log.warn("查询失败:菜单不存在,菜单ID={}", menuId);
+            return R.fail("菜单不存在");
+        }
+
+        // 判断是否有更新操作(如果传入了菜单名称、路径或状态,则认为是更新操作)
+        boolean isUpdate = StringUtils.hasText(storePlatformMenu.getMenuName())
+                || StringUtils.hasText(storePlatformMenu.getPath())
+                || StringUtils.hasText(storePlatformMenu.getStatus());
+
+        if (isUpdate) {
+            // 更新操作:只允许更新本级菜单的名称、路径、状态
+            log.info("开始更新菜单信息,菜单ID={}", menuId);
+
+            // 只更新允许的字段:菜单名称、路径、状态
+            if (StringUtils.hasText(storePlatformMenu.getMenuName())) {
+                currentMenu.setMenuName(storePlatformMenu.getMenuName());
+            }
+            if (StringUtils.hasText(storePlatformMenu.getPath())) {
+                currentMenu.setPath(storePlatformMenu.getPath());
+            }
+            if (StringUtils.hasText(storePlatformMenu.getStatus())) {
+                currentMenu.setStatus(storePlatformMenu.getStatus());
+            }
+
+            currentMenu.setUpdatedTime(new Date());
+            currentMenu.setUpdateBy("admin");
+
+            boolean result = this.updateById(currentMenu);
+            if (result) {
+                log.info("更新菜单信息成功,菜单ID={}, 菜单名称={}, 路径={}, 状态={}",
+                        menuId, currentMenu.getMenuName(), currentMenu.getPath(), currentMenu.getStatus());
+                // 重新查询更新后的菜单
+                currentMenu = storePlatformMenuMapper.selectById(menuId);
+            } else {
+                log.warn("更新菜单信息失败,菜单ID={}", menuId);
+                return R.fail("更新菜单信息失败");
+            }
+        }
+
+        // 查询上级菜单信息并设置到返回对象中
+        Integer level = currentMenu.getLevel();
+        if (level != null) {
+            // 如果是二级菜单,查询一级菜单名称
+            if (level == 2 && currentMenu.getParentId() != null && currentMenu.getParentId() != 0) {
+                StorePlatformMenu firstLevelMenu = storePlatformMenuMapper.selectById(currentMenu.getParentId());
+                if (firstLevelMenu != null) {
+                    currentMenu.setFirstLevelMenuName(firstLevelMenu.getMenuName());
+                }
+            }
+            // 如果是三级菜单,查询一级和二级菜单名称
+            else if (level == 3 && currentMenu.getParentId() != null && currentMenu.getParentId() != 0) {
+                // 先查询二级菜单
+                StorePlatformMenu secondLevelMenu = storePlatformMenuMapper.selectById(currentMenu.getParentId());
+                if (secondLevelMenu != null) {
+                    currentMenu.setSecondLevelMenuName(secondLevelMenu.getMenuName());
+                    // 再查询一级菜单
+                    if (secondLevelMenu.getParentId() != null && secondLevelMenu.getParentId() != 0) {
+                        StorePlatformMenu firstLevelMenu = storePlatformMenuMapper.selectById(secondLevelMenu.getParentId());
+                        if (firstLevelMenu != null) {
+                            currentMenu.setFirstLevelMenuName(firstLevelMenu.getMenuName());
+                        }
+                    }
+                }
+            }
+        }
+
+        // 如果状态为空,默认设置为"0"(开启)
+        if (!StringUtils.hasText(currentMenu.getStatus())) {
+            currentMenu.setStatus("0");
+        }
+
+        return R.data(currentMenu);
+    }
+
+    @Override
+    public R<StorePlatformMenu> deleteMenuDetails(StorePlatformMenu storePlatformMenu) {
+        Long menuId = storePlatformMenu.getMenuId();
+        
+        log.info("开始删除菜单,菜单ID={}", menuId);
+        
+        // 参数校验:菜单ID不能为空
+        if (menuId == null) {
+            log.warn("删除菜单失败:菜单ID为空");
+            return R.fail("菜单ID不能为空");
+        }
+        
+        // 查询当前菜单信息
+        StorePlatformMenu currentMenu = storePlatformMenuMapper.selectById(menuId);
+        if (currentMenu == null) {
+            log.warn("删除菜单失败:菜单不存在,菜单ID={}", menuId);
+            return R.fail("菜单不存在");
+        }
+        
+        Integer level = currentMenu.getLevel();
+        if (level == null) {
+            log.warn("删除菜单失败:层级信息为空,菜单ID={}", menuId);
+            return R.fail("层级信息不能为空");
+        }
+        
+        int totalUpdateCount = 0;
+        
+        // 检查当前菜单是否已删除
+        if (!"0".equals(currentMenu.getDelFlag())) {
+            log.warn("删除菜单失败:菜单已被删除,菜单ID={}, 层级={}, del_flag={}", menuId, level, currentMenu.getDelFlag());
+            return R.fail("菜单已被删除");
+        }
+        
+        // 根据层级进行级联删除
+        if (level == 1) {
+            // 删除层级1的菜单:同时删除层级2和3的菜单
+            log.info("删除一级菜单,同时删除层级2和3的菜单,菜单ID={}, 层级={}", menuId, level);
+            LambdaQueryWrapper<StorePlatformMenu> level1Query = new LambdaQueryWrapper<>();
+            level1Query
+                    .eq(StorePlatformMenu::getLevel, 1)
+                    .eq(StorePlatformMenu::getDelFlag, "0");
+            List<StorePlatformMenu> levelMenus = storePlatformMenuMapper.selectList(level1Query);
+            List<Long> levelMenuIds = levelMenus.stream()
+                    .map(StorePlatformMenu::getMenuId)
+                    .collect(Collectors.toList());
+            if (!CollectionUtils.isEmpty(levelMenus)){
+                LambdaUpdateWrapper<StorePlatformMenu> wrapper2 = new LambdaUpdateWrapper<>();
+                wrapper2.eq(StorePlatformMenu::getLevel, 1)
+                        .in(StorePlatformMenu::getMenuId, levelMenuIds)
+                        .eq(StorePlatformMenu::getDelFlag, "0")
+                        .set(StorePlatformMenu::getDelFlag, "2");
+                int count = storePlatformMenuMapper.update(null, wrapper2);
+                totalUpdateCount += count;
+                log.info("删除一级菜单本身,菜单ID={}, 更新记录数={}", menuId, count);
+            }
+            // 1. 先查询所有层级2的子菜单
+            LambdaQueryWrapper<StorePlatformMenu> level2Query = new LambdaQueryWrapper<>();
+            level2Query
+                      .eq(StorePlatformMenu::getLevel, 2)
+                      .eq(StorePlatformMenu::getDelFlag, "0");
+            List<StorePlatformMenu> level2Menus = storePlatformMenuMapper.selectList(level2Query);
+            List<Long> level2MenuIds = level2Menus.stream()
+                                                  .map(StorePlatformMenu::getMenuId)
+                                                  .collect(Collectors.toList());
+            log.info("查询到层级2子菜单数量:{}", level2Menus != null ? level2Menus.size() : 0);
+
+
+            // 3. 删除所有层级2子菜单
+            if (!CollectionUtils.isEmpty(level2Menus)) {
+                LambdaUpdateWrapper<StorePlatformMenu> wrapper2 = new LambdaUpdateWrapper<>();
+                wrapper2.eq(StorePlatformMenu::getLevel, 2)
+                        .in(StorePlatformMenu::getMenuId, level2MenuIds)
+                        .eq(StorePlatformMenu::getDelFlag, "0")
+                        .set(StorePlatformMenu::getDelFlag, "2");
+                int count2 = storePlatformMenuMapper.update(null, wrapper2);
+                totalUpdateCount += count2;
+                log.info("删除层级2子菜单,parent_id={}, 更新记录数={}", menuId, count2);
+            } else {
+                log.info("没有层级2子菜单需要删除,菜单ID={}", menuId);
+            }
+            LambdaQueryWrapper<StorePlatformMenu> level3Query = new LambdaQueryWrapper<>();
+            level3Query
+                    .eq(StorePlatformMenu::getLevel, 3)
+                    .eq(StorePlatformMenu::getDelFlag, "0");
+            List<StorePlatformMenu> level3Menus = storePlatformMenuMapper.selectList(level3Query);
+            List<Long> level3MenuIds = level3Menus.stream()
+                    .map(StorePlatformMenu::getMenuId)
+                    .collect(Collectors.toList());
+            // 4. 删除所有层级3子菜单(parent_id在层级2菜单ID列表中)
+            if (!CollectionUtils.isEmpty(level3Menus)) {
+                LambdaUpdateWrapper<StorePlatformMenu> wrapper3 = new LambdaUpdateWrapper<>();
+                wrapper3.eq(StorePlatformMenu::getLevel, 3)
+                        .in(StorePlatformMenu::getMenuId, level3MenuIds)
+                        .eq(StorePlatformMenu::getDelFlag, "0")
+                        .set(StorePlatformMenu::getDelFlag, "2");
+                int count3 = storePlatformMenuMapper.update(null, wrapper3);
+                totalUpdateCount += count3;
+                log.info("删除层级3子菜单, 更新记录数={}", level3MenuIds, count3);
+            } else {
+                log.info("没有层级3子菜单需要删除,菜单ID={}", menuId);
+            }
+            
+            log.info("删除一级菜单成功,菜单ID={}, 层级={}, 总更新记录数={}", menuId, level, totalUpdateCount);
+            
+        } else if (level == 2) {
+            // 删除层级2的菜单:同时删除层级3的菜单
+            log.info("删除二级菜单,同时删除层级3的菜单,菜单ID={}, 层级={}", menuId, level);
+            LambdaQueryWrapper<StorePlatformMenu> level2Query = new LambdaQueryWrapper<>();
+            level2Query
+                    .eq(StorePlatformMenu::getLevel, 2)
+                    .eq(StorePlatformMenu::getDelFlag, "0");
+            List<StorePlatformMenu> level2Menus = storePlatformMenuMapper.selectList(level2Query);
+            List<Long> level2MenuIds = level2Menus.stream()
+                    .map(StorePlatformMenu::getMenuId)
+                    .collect(Collectors.toList());
+            // 3. 删除所有层级2子菜单
+            if (!CollectionUtils.isEmpty(level2Menus)) {
+                LambdaUpdateWrapper<StorePlatformMenu> wrapper2 = new LambdaUpdateWrapper<>();
+                wrapper2.eq(StorePlatformMenu::getLevel, 2)
+                        .in(StorePlatformMenu::getMenuId, level2MenuIds)
+                        .eq(StorePlatformMenu::getDelFlag, "0")
+                        .set(StorePlatformMenu::getDelFlag, "2");
+                int count2 = storePlatformMenuMapper.update(null, wrapper2);
+                totalUpdateCount += count2;
+                log.info("删除层级2子菜单,菜单ID={}, 更新记录数={}", menuId, count2);
+            } else {
+                log.info("没有层级2子菜单需要删除,菜单ID={}", menuId);
+            }
+
+            // 1. 先查询所有层级3的子菜单
+            LambdaQueryWrapper<StorePlatformMenu> level3Query = new LambdaQueryWrapper<>();
+            level3Query
+                      .eq(StorePlatformMenu::getLevel, 3)
+                      .eq(StorePlatformMenu::getDelFlag, "0");
+            List<StorePlatformMenu> level3Menus = storePlatformMenuMapper.selectList(level3Query);
+            List<Long> level3MenuIds = level3Menus.stream()
+                    .map(StorePlatformMenu::getMenuId)
+                    .collect(Collectors.toList());
+            log.info("查询到层级3子菜单数量:{}", level3Menus != null ? level3Menus.size() : 0);
+            
+            // 3. 删除所有层级3子菜单
+            if (!CollectionUtils.isEmpty(level3Menus)) {
+                LambdaUpdateWrapper<StorePlatformMenu> wrapper2 = new LambdaUpdateWrapper<>();
+                wrapper2.eq(StorePlatformMenu::getLevel, 3)
+                        .in(StorePlatformMenu::getMenuId, level3MenuIds)
+                        .eq(StorePlatformMenu::getDelFlag, "0")
+                        .set(StorePlatformMenu::getDelFlag, "2");
+                int count2 = storePlatformMenuMapper.update(null, wrapper2);
+                totalUpdateCount += count2;
+                log.info("删除层级3子菜单,菜单ID={}, 更新记录数={}", menuId, totalUpdateCount);
+            } else {
+                log.info("没有层级3子菜单需要删除,菜单ID={}", menuId);
+            }
+
+            
+        } else if (level == 3) {
+            // 删除层级3的菜单:只删除当前菜单
+            log.info("删除三级菜单,只删除当前菜单,菜单ID={}, 层级={}", menuId, level);
+            LambdaQueryWrapper<StorePlatformMenu> level3Query = new LambdaQueryWrapper<>();
+            level3Query
+                    .eq(StorePlatformMenu::getLevel, 3)
+                    .eq(StorePlatformMenu::getDelFlag, "0");
+            List<StorePlatformMenu> level3Menus = storePlatformMenuMapper.selectList(level3Query);
+            List<Long> level3MenuIds = level3Menus.stream()
+                    .map(StorePlatformMenu::getMenuId)
+                    .collect(Collectors.toList());
+            log.info("查询到层级3子菜单数量:{}", level3Menus != null ? level3Menus.size() : 0);
+
+            // 3. 删除所有层级3子菜单
+            if (!CollectionUtils.isEmpty(level3Menus)) {
+                LambdaUpdateWrapper<StorePlatformMenu> wrapper2 = new LambdaUpdateWrapper<>();
+                wrapper2.eq(StorePlatformMenu::getLevel, 3)
+                        .in(StorePlatformMenu::getMenuId, level3MenuIds)
+                        .eq(StorePlatformMenu::getDelFlag, "0")
+                        .set(StorePlatformMenu::getDelFlag, "2");
+                int count2 = storePlatformMenuMapper.update(null, wrapper2);
+                totalUpdateCount += count2;
+                log.info("删除层级3子菜单,parent_id={}, 更新记录数={}", menuId, count2);
+            } else {
+                log.info("没有层级3子菜单需要删除,菜单ID={}", menuId);
+            }
+            
+            if (totalUpdateCount > 0) {
+                log.info("删除三级菜单成功,菜单ID={}, 层级={}, 更新记录数={}", menuId, level, totalUpdateCount);
+            } else {
+                log.warn("删除三级菜单未找到记录或已删除,菜单ID={}, 层级={}, del_flag={}", menuId, level, currentMenu.getDelFlag());
+                return R.fail("删除失败:菜单不存在或已被删除");
+            }
+            
+        } else {
+            log.warn("删除菜单失败:层级值不正确,菜单ID={}, 层级={}", menuId, level);
+            return R.fail("层级值不正确,应为1、2或3");
+        }
+        
+        return R.data(currentMenu);
+    }
+
+    @Override
+    public R<StorePlatformMenu> editUpdateMenuStatus(Long menuId, String status, Integer level) {
+        // 参数校验:菜单ID不能为空
+        if (menuId == null) {
+            log.warn("更新菜单状态失败:菜单ID为空");
+            return R.fail("菜单ID不能为空");
+        }
+
+        // 查询当前菜单信息
+        StorePlatformMenu currentMenu = storePlatformMenuMapper.selectById(menuId);
+        if (currentMenu == null) {
+            log.warn("更新菜单状态失败:菜单不存在,菜单ID={}", menuId);
+            return R.fail("菜单不存在");
+        }
+
+        // 检查菜单是否已删除
+        if (!"0".equals(currentMenu.getDelFlag())) {
+            log.warn("更新菜单状态失败:菜单已被删除,菜单ID={}, del_flag={}", menuId, currentMenu.getDelFlag());
+            return R.fail("菜单已被删除");
+        }
+        int totalUpdateCount =0 ;
+
+        // 动态切换状态:如果数据库中是"1"则改为"0",如果是"0"则改为"1"
+        String currentStatus = currentMenu.getStatus();
+        String newStatus;
+        if ("1".equals(currentStatus)) {
+            newStatus = "0";  // 当前是禁用(1),切换为启用(0)
+        } else if ("0".equals(currentStatus)) {
+            newStatus = "1";  // 当前是启用(0),切换为禁用(1)
+        } else {
+            // 如果状态值异常,默认为启用(0)
+            log.warn("菜单状态值异常,菜单ID={}, 当前状态={},默认设置为启用(0)", menuId, currentStatus);
+            newStatus = "0";
+        }
+
+
+        // 根据层级进行级联删除
+        if (level == 1) {
+            // 删除层级1的菜单:同时删除层级2和3的菜单
+            log.info("启用禁用一级菜单,同时启用禁用层级2和3的菜单,菜单ID={}, 层级={}", menuId, level);
+            LambdaQueryWrapper<StorePlatformMenu> level1Query = new LambdaQueryWrapper<>();
+            level1Query
+                    .eq(StorePlatformMenu::getLevel, 1)
+                    .eq(StorePlatformMenu::getDelFlag, "0")
+                    .eq(StorePlatformMenu::getStatus, currentStatus);
+            List<StorePlatformMenu> levelMenus = storePlatformMenuMapper.selectList(level1Query);
+            List<Long> levelMenuIds = levelMenus.stream()
+                    .map(StorePlatformMenu::getMenuId)
+                    .collect(Collectors.toList());
+            if (!CollectionUtils.isEmpty(levelMenus)){
+                LambdaUpdateWrapper<StorePlatformMenu> wrapper2 = new LambdaUpdateWrapper<>();
+                wrapper2.eq(StorePlatformMenu::getLevel, 1)
+                        .in(StorePlatformMenu::getMenuId, levelMenuIds)
+                        .eq(StorePlatformMenu::getDelFlag, "0")
+                        .set(StorePlatformMenu::getStatus, newStatus);
+                int count = storePlatformMenuMapper.update(null, wrapper2);
+                totalUpdateCount += count;
+                log.info("启用禁用一级菜单本身,菜单ID={}, 更新记录数={}", menuId, count);
+            }
+            // 1. 先查询所有层级2的子菜单
+            LambdaQueryWrapper<StorePlatformMenu> level2Query = new LambdaQueryWrapper<>();
+            level2Query
+                    .eq(StorePlatformMenu::getLevel, 2)
+                    .eq(StorePlatformMenu::getDelFlag, "0")
+                    .eq(StorePlatformMenu::getStatus, currentStatus);
+            List<StorePlatformMenu> level2Menus = storePlatformMenuMapper.selectList(level2Query);
+            List<Long> level2MenuIds = level2Menus.stream()
+                    .map(StorePlatformMenu::getMenuId)
+                    .collect(Collectors.toList());
+            log.info("查询到层级2子菜单数量:{}", level2Menus != null ? level2Menus.size() : 0);
+
+
+            // 3. 删除所有层级2子菜单
+            if (!CollectionUtils.isEmpty(level2Menus)) {
+                LambdaUpdateWrapper<StorePlatformMenu> wrapper2 = new LambdaUpdateWrapper<>();
+                wrapper2.eq(StorePlatformMenu::getLevel, 2)
+                        .in(StorePlatformMenu::getMenuId, level2MenuIds)
+                        .eq(StorePlatformMenu::getDelFlag, "0")
+                        .set(StorePlatformMenu::getStatus, newStatus);
+                int count2 = storePlatformMenuMapper.update(null, wrapper2);
+                totalUpdateCount += count2;
+                log.info("启用禁用层级2子菜单,菜单Id={}, 更新记录数={}", menuId, totalUpdateCount);
+            } else {
+                log.info("没有层级2子菜单需要启用禁用,菜单ID={}", menuId);
+            }
+            LambdaQueryWrapper<StorePlatformMenu> level3Query = new LambdaQueryWrapper<>();
+            level3Query
+                    .eq(StorePlatformMenu::getLevel, 3)
+                    .eq(StorePlatformMenu::getDelFlag, "0")
+                    .eq(StorePlatformMenu::getStatus, currentStatus);
+            List<StorePlatformMenu> level3Menus = storePlatformMenuMapper.selectList(level3Query);
+            List<Long> level3MenuIds = level3Menus.stream()
+                    .map(StorePlatformMenu::getMenuId)
+                    .collect(Collectors.toList());
+            // 4. 删除所有层级3子菜单(parent_id在层级2菜单ID列表中)
+            if (!CollectionUtils.isEmpty(level3Menus)) {
+                LambdaUpdateWrapper<StorePlatformMenu> wrapper3 = new LambdaUpdateWrapper<>();
+                wrapper3.eq(StorePlatformMenu::getLevel, 3)
+                        .in(StorePlatformMenu::getMenuId, level3MenuIds)
+                        .eq(StorePlatformMenu::getDelFlag, "0")
+                        .set(StorePlatformMenu::getStatus, newStatus);
+                int count3 = storePlatformMenuMapper.update(null, wrapper3);
+                totalUpdateCount += count3;
+                log.info("启用禁用层级3子菜单, 更新记录数={}", level3MenuIds, count3);
+            } else {
+                log.info("没有层级3子菜单需要操作,菜单ID={}", menuId);
+            }
+
+            log.info("操作一级菜单成功,菜单ID={}, 层级={}, 总更新记录数={}", menuId, level, totalUpdateCount);
+
+        } else if (level == 2) {
+            // 删除层级2的菜单:同时删除层级3的菜单
+            log.info("启用禁用二级菜单,同时启用禁用层级3的菜单,菜单ID={}, 层级={}", menuId, level);
+            LambdaQueryWrapper<StorePlatformMenu> level2Query = new LambdaQueryWrapper<>();
+            level2Query
+                    .eq(StorePlatformMenu::getLevel, 2)
+                    .eq(StorePlatformMenu::getDelFlag, "0")
+                    .eq(StorePlatformMenu::getStatus, currentStatus);
+            List<StorePlatformMenu> level2Menus = storePlatformMenuMapper.selectList(level2Query);
+            List<Long> level2MenuIds = level2Menus.stream()
+                    .map(StorePlatformMenu::getMenuId)
+                    .collect(Collectors.toList());
+            // 3. 删除所有层级2子菜单
+            if (!CollectionUtils.isEmpty(level2Menus)) {
+                LambdaUpdateWrapper<StorePlatformMenu> wrapper2 = new LambdaUpdateWrapper<>();
+                wrapper2.eq(StorePlatformMenu::getLevel, 2)
+                        .in(StorePlatformMenu::getMenuId, level2MenuIds)
+                        .eq(StorePlatformMenu::getDelFlag, "0")
+                        .set(StorePlatformMenu::getStatus, newStatus);
+                int count2 = storePlatformMenuMapper.update(null, wrapper2);
+                totalUpdateCount += count2;
+                log.info("启用禁用层级2子菜单,菜单ID={}, 更新记录数={}", menuId, count2);
+            } else {
+                log.info("没有层级2子菜单需要操作,菜单ID={}", menuId);
+            }
+
+            // 1. 先查询所有层级3的子菜单
+            LambdaQueryWrapper<StorePlatformMenu> level3Query = new LambdaQueryWrapper<>();
+            level3Query.eq(StorePlatformMenu::getMenuId, menuId)
+                    .eq(StorePlatformMenu::getLevel, 3)
+                    .eq(StorePlatformMenu::getDelFlag, "0")
+                    .eq(StorePlatformMenu::getStatus, currentStatus);
+            List<StorePlatformMenu> level3Menus = storePlatformMenuMapper.selectList(level3Query);
+            List<Long> level3MenuIds = level3Menus.stream()
+                    .map(StorePlatformMenu::getMenuId)
+                    .collect(Collectors.toList());
+            log.info("查询到层级3子菜单数量:{}", level3Menus != null ? level3Menus.size() : 0);
+
+            // 3. 删除所有层级3子菜单
+            if (!CollectionUtils.isEmpty(level3Menus)) {
+                LambdaUpdateWrapper<StorePlatformMenu> wrapper2 = new LambdaUpdateWrapper<>();
+                wrapper2.eq(StorePlatformMenu::getLevel, 3)
+                        .in(StorePlatformMenu::getMenuId, level3MenuIds)
+                        .eq(StorePlatformMenu::getDelFlag, "0")
+                        .set(StorePlatformMenu::getStatus, newStatus);
+                int count2 = storePlatformMenuMapper.update(null, wrapper2);
+                totalUpdateCount += count2;
+                log.info("启用禁用层级3子菜单,菜单ID={}, 更新记录数={}", menuId, totalUpdateCount);
+            } else {
+                log.info("没有层级3子菜单需要操作,菜单ID={}", menuId);
+            }
+
+
+        } else if (level == 3) {
+            // 删除层级3的菜单:只删除当前菜单
+            log.info("删除三级菜单,只删除当前菜单,菜单ID={}, 层级={}", menuId, level);
+            LambdaQueryWrapper<StorePlatformMenu> level3Query = new LambdaQueryWrapper<>();
+            level3Query.eq(StorePlatformMenu::getMenuId, menuId)
+                    .eq(StorePlatformMenu::getLevel, 3)
+                    .eq(StorePlatformMenu::getDelFlag, "0")
+                    .eq(StorePlatformMenu::getStatus, currentStatus);
+            List<StorePlatformMenu> level3Menus = storePlatformMenuMapper.selectList(level3Query);
+            List<Long> level3MenuIds = level3Menus.stream()
+                    .map(StorePlatformMenu::getMenuId)
+                    .collect(Collectors.toList());
+            log.info("查询到层级3子菜单数量:{}", level3Menus != null ? level3Menus.size() : 0);
+
+            // 3. 删除所有层级3子菜单
+            if (!CollectionUtils.isEmpty(level3Menus)) {
+                LambdaUpdateWrapper<StorePlatformMenu> wrapper2 = new LambdaUpdateWrapper<>();
+                wrapper2.eq(StorePlatformMenu::getLevel, 3)
+                        .in(StorePlatformMenu::getMenuId, level3MenuIds)
+                        .eq(StorePlatformMenu::getDelFlag, "0")
+                        .set(StorePlatformMenu::getStatus, newStatus);
+                int count2 = storePlatformMenuMapper.update(null, wrapper2);
+                totalUpdateCount += count2;
+                log.info("删除层级3子菜单,parent_id={}, 更新记录数={}", menuId, count2);
+            } else {
+                log.info("没有层级3子菜单需要删除,菜单ID={}", menuId);
+            }
+
+            if (totalUpdateCount > 0) {
+                log.info("删除三级菜单成功,菜单ID={}, 层级={}, 更新记录数={}", menuId, level, totalUpdateCount);
+            } else {
+                log.warn("删除三级菜单未找到记录或已删除,菜单ID={}, 层级={}, del_flag={}", menuId, level, currentMenu.getDelFlag());
+                return R.fail("删除失败:菜单不存在或已被删除");
+            }
+
+        } else {
+            log.warn("删除菜单失败:层级值不正确,菜单ID={}, 层级={}", menuId, level);
+            return R.fail("层级值不正确,应为1、2或3");
+        }
+
+
+        // 重新查询更新后的菜单信息
+        StorePlatformMenu updatedMenu = storePlatformMenuMapper.selectById(menuId);
+        return R.data(updatedMenu);
+    }
+
+    @Override
+    public R<StorePlatformMenu> addByMenu(StorePlatformMenu store) {
+        log.info("开始新增菜单,菜单名称={}, 一级分类名称={}, 二级分类名称={}", 
+                store != null ? store.getMenuName() : null,
+                store != null ? store.getFirstLevelMenuName() : null,
+                store != null ? store.getSecondLevelMenuName() : null);
+        
+        // 1. 参数校验
+        if (store == null) {
+            log.warn("新增菜单失败:菜单信息为空");
+            return R.fail("菜单信息不能为空");
+        }
+        if (!StringUtils.hasText(store.getMenuName())) {
+            log.warn("新增菜单失败:菜单名称为空");
+            return R.fail("菜单名称不能为空");
+        }
+        if (!StringUtils.hasText(store.getPath())) {
+            log.warn("新增菜单失败:路径为空");
+            return R.fail("路径不能为空");
+        }
+        
+        // 2. 根据一级、二级分类名称确定 parentId 和 level
+        Long parentId = determineParentIdByMenuNames(store);
+        if (parentId == null && (StringUtils.hasText(store.getFirstLevelMenuName()) || 
+            StringUtils.hasText(store.getSecondLevelMenuName()))) {
+            log.warn("新增菜单失败:无法确定父菜单,一级分类名称={}, 二级分类名称={}", 
+                    store.getFirstLevelMenuName(), store.getSecondLevelMenuName());
+            return R.fail("无法确定父菜单,请检查一级和二级分类名称是否正确");
+        }
+        
+        store.setParentId(parentId != null ? parentId : 0L);
+        
+        // 3. 根据 parentId 计算 level
+        Integer level = calculateLevelByParentId(store.getParentId());
+        if (level == null) {
+            log.warn("新增菜单失败:无法确定菜单层级,parentId={}", store.getParentId());
+            return R.fail("无法确定菜单层级");
+        }
+        store.setLevel(level);
+        
+        // 4. 校验菜单名称是否重复(同一父菜单下不能有重名)
+        LambdaQueryWrapper<StorePlatformMenu> nameCheck = new LambdaQueryWrapper<>();
+        nameCheck.eq(StorePlatformMenu::getMenuName, store.getMenuName())
+                .eq(StorePlatformMenu::getParentId, store.getParentId())
+                .eq(StorePlatformMenu::getDelFlag, "0");
+        StorePlatformMenu duplicateMenu = storePlatformMenuMapper.selectOne(nameCheck);
+        if (duplicateMenu != null) {
+            log.warn("新增菜单失败:菜单名称已存在,菜单名称={}, parentId={}", 
+                    store.getMenuName(), store.getParentId());
+            return R.fail("该菜单名称在同级菜单中已存在,请更换其他名称");
+        }
+        
+        // 5. 校验父菜单是否存在且未删除(如果不是一级菜单)
+        if (store.getParentId() != null && store.getParentId() != 0) {
+            StorePlatformMenu parentMenu = storePlatformMenuMapper.selectById(store.getParentId());
+            if (parentMenu == null) {
+                log.warn("新增菜单失败:父菜单不存在,parentId={}", store.getParentId());
+                return R.fail("父菜单不存在");
+            }
+            if (!"0".equals(parentMenu.getDelFlag())) {
+                log.warn("新增菜单失败:父菜单已被删除,parentId={}", store.getParentId());
+                return R.fail("父菜单已被删除");
+            }
+        }
+        
+        // 6. 设置默认值
+        setDefaultValues(store);
+        
+        // 7. 设置排序值(自动设置为最大值+1)
+        Integer maxSort = getMaxSortByParentId(store.getParentId());
+        store.setMenuSort(maxSort != null ? maxSort + 1 : 0);
+        
+        // 8. 设置创建时间和创建人
+        store.setCreatedTime(new Date());
+        store.setCreateBy("admin");
+        
+        // 9. 执行新增操作
+        int insert = storePlatformMenuMapper.insert(store);
+        if (insert > 0) {
+            log.info("新增菜单成功,菜单ID={}, 菜单名称={}, parentId={}, level={}", 
+                    store.getMenuId(), store.getMenuName(), store.getParentId(), store.getLevel());
+            
+            // 重新查询菜单信息(包含自动生成的ID等信息)
+            StorePlatformMenu savedMenu = storePlatformMenuMapper.selectById(store.getMenuId());
+            if (savedMenu != null) {
+                // 设置父菜单名称用于回显
+                setParentMenuNames(savedMenu);
+                return R.data(savedMenu);
+            }
+            return R.data(store);
+        } else {
+            log.warn("新增菜单失败,菜单名称={}", store.getMenuName());
+            return R.fail("新增菜单失败");
+        }
+    }
+    
+    /**
+     * 根据一级、二级分类名称确定 parentId
+     * 
+     * @param store 菜单对象(包含 firstLevelMenuName 和 secondLevelMenuName)
+     * @return parentId,如果是一级菜单则返回 0,如果无法确定则返回 null
+     */
+    private Long determineParentIdByMenuNames(StorePlatformMenu store) {
+        String firstLevelMenuName = store.getFirstLevelMenuName();
+        String secondLevelMenuName = store.getSecondLevelMenuName();
+        
+        // 如果直接指定了 parentId,优先使用
+        if (store.getParentId() != null && store.getParentId() != 0) {
+            return store.getParentId();
+        }
+        
+        // 如果一级和二级分类名称都为空,说明是一级菜单
+        if (!StringUtils.hasText(firstLevelMenuName) && !StringUtils.hasText(secondLevelMenuName)) {
+            return 0L;
+        }
+        
+        // 如果只有一级分类名称,说明是二级菜单
+        if (StringUtils.hasText(firstLevelMenuName) && !StringUtils.hasText(secondLevelMenuName)) {
+            // 查找一级菜单
+            LambdaQueryWrapper<StorePlatformMenu> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(StorePlatformMenu::getMenuName, firstLevelMenuName)
+                       .and(w -> w.isNull(StorePlatformMenu::getParentId)
+                                .or().eq(StorePlatformMenu::getParentId, 0))
+                       .eq(StorePlatformMenu::getDelFlag, "0");
+            StorePlatformMenu firstLevelMenu = storePlatformMenuMapper.selectOne(queryWrapper);
+            if (firstLevelMenu != null) {
+                return firstLevelMenu.getMenuId();
+            }
+            log.warn("未找到一级菜单,菜单名称={}", firstLevelMenuName);
+            return null;
+        }
+        
+        // 如果有一级和二级分类名称,说明是三级菜单
+        if (StringUtils.hasText(firstLevelMenuName) && StringUtils.hasText(secondLevelMenuName)) {
+            // 先查找一级菜单
+            LambdaQueryWrapper<StorePlatformMenu> level1Query = new LambdaQueryWrapper<>();
+            level1Query.eq(StorePlatformMenu::getMenuName, firstLevelMenuName)
+                      .and(w -> w.isNull(StorePlatformMenu::getParentId)
+                               .or().eq(StorePlatformMenu::getParentId, 0))
+                      .eq(StorePlatformMenu::getDelFlag, "0");
+            StorePlatformMenu firstLevelMenu = storePlatformMenuMapper.selectOne(level1Query);
+            if (firstLevelMenu == null) {
+                log.warn("未找到一级菜单,菜单名称={}", firstLevelMenuName);
+                return null;
+            }
+            
+            // 再查找二级菜单
+            LambdaQueryWrapper<StorePlatformMenu> level2Query = new LambdaQueryWrapper<>();
+            level2Query.eq(StorePlatformMenu::getMenuName, secondLevelMenuName)
+                      .eq(StorePlatformMenu::getParentId, firstLevelMenu.getMenuId())
+                      .eq(StorePlatformMenu::getDelFlag, "0");
+            StorePlatformMenu secondLevelMenu = storePlatformMenuMapper.selectOne(level2Query);
+            if (secondLevelMenu != null) {
+                return secondLevelMenu.getMenuId();
+            }
+            log.warn("未找到二级菜单,菜单名称={}, 父菜单ID={}", 
+                    secondLevelMenuName, firstLevelMenu.getMenuId());
+            return null;
+        }
+        
+        return 0L;
+    }
+    
+    /**
+     * 根据 parentId 计算菜单层级
+     * 
+     * @param parentId 父菜单ID
+     * @return 菜单层级(1一级菜单 2二级菜单 3三级菜单)
+     */
+    private Integer calculateLevelByParentId(Long parentId) {
+        if (parentId == null || parentId == 0) {
+            return 1; // 一级菜单
+        }
+        
+        // 查询父菜单
+        StorePlatformMenu parentMenu = storePlatformMenuMapper.selectById(parentId);
+        if (parentMenu == null) {
+            return null;
+        }
+        
+        Integer parentLevel = parentMenu.getLevel();
+        if (parentLevel == null) {
+            // 如果父菜单没有层级信息,尝试根据parentId推断
+            if (parentMenu.getParentId() == null || parentMenu.getParentId() == 0) {
+                return 2; // 父菜单是一级菜单,当前是二级菜单
+            } else {
+                return 3; // 父菜单不是一级菜单,当前是三级菜单
+            }
+        }
+        
+        // 层级不能超过3
+        int newLevel = parentLevel + 1;
+        if (newLevel > 3) {
+            log.warn("菜单层级超过3级,parentId={}, parentLevel={}", parentId, parentLevel);
+            return null;
+        }
+        
+        return newLevel;
+    }
+    
+    /**
+     * 设置默认值
+     */
+    private void setDefaultValues(StorePlatformMenu store) {
+        if (!StringUtils.hasText(store.getStatus())) {
+            store.setStatus("0"); // 默认开启
+        }
+        if (!StringUtils.hasText(store.getDelFlag())) {
+            store.setDelFlag("0"); // 默认未删除
+        }
+        if (!StringUtils.hasText(store.getVisible())) {
+            store.setVisible("0"); // 默认显示
+        }
+        if (!StringUtils.hasText(store.getIsFrame())) {
+            store.setIsFrame("1"); // 默认非外链
+        }
+        if (!StringUtils.hasText(store.getIsCache())) {
+            store.setIsCache("0"); // 默认缓存
+        }
+        if (store.getMenuSort() == null) {
+            store.setMenuSort(0); // 默认排序值
+        }
+        if (!StringUtils.hasText(store.getMenuType())) {
+            // 根据层级设置默认菜单类型:一级菜单为M(目录),其他为C(菜单)
+            if (store.getLevel() != null && store.getLevel() == 1) {
+                store.setMenuType("M");
+            } else {
+                store.setMenuType("C");
+            }
+        }
+    }
+    
+    /**
+     * 获取指定父菜单下的最大排序值
+     * 
+     * @param parentId 父菜单ID
+     * @return 最大排序值,如果没有子菜单则返回null
+     */
+    private Integer getMaxSortByParentId(Long parentId) {
+        LambdaQueryWrapper<StorePlatformMenu> queryWrapper = new LambdaQueryWrapper<>();
+        if (parentId == null || parentId == 0) {
+            queryWrapper.isNull(StorePlatformMenu::getParentId)
+                       .or().eq(StorePlatformMenu::getParentId, 0);
+        } else {
+            queryWrapper.eq(StorePlatformMenu::getParentId, parentId);
+        }
+        queryWrapper.eq(StorePlatformMenu::getDelFlag, "0")
+                   .orderByDesc(StorePlatformMenu::getMenuSort)
+                   .last("LIMIT 1");
+        
+        StorePlatformMenu menu = storePlatformMenuMapper.selectOne(queryWrapper);
+        return menu != null && menu.getMenuSort() != null ? menu.getMenuSort() : null;
+    }
+    
+    /**
+     * 设置父菜单名称用于回显
+     * 
+     * @param menu 菜单对象
+     */
+    private void setParentMenuNames(StorePlatformMenu menu) {
+        if (menu.getParentId() == null || menu.getParentId() == 0) {
+            // 一级菜单,不需要设置父菜单名称
+            return;
+        }
+        
+        // 查询父菜单
+        StorePlatformMenu parentMenu = storePlatformMenuMapper.selectById(menu.getParentId());
+        if (parentMenu == null) {
+            return;
+        }
+        
+        // 设置二级父菜单名称
+        menu.setSecondLevelMenuName(parentMenu.getMenuName());
+        
+        // 如果父菜单还有父菜单,设置一级父菜单名称
+        if (parentMenu.getParentId() != null && parentMenu.getParentId() != 0) {
+            StorePlatformMenu grandParentMenu = storePlatformMenuMapper.selectById(parentMenu.getParentId());
+            if (grandParentMenu != null) {
+                menu.setFirstLevelMenuName(grandParentMenu.getMenuName());
+            }
+        } else {
+            // 如果父菜单是一级菜单,设置一级父菜单名称
+            menu.setFirstLevelMenuName(parentMenu.getMenuName());
+        }
+    }
+
+
+}
+