|
|
@@ -254,6 +254,10 @@ public class StorePlatformMenuServiceImpl extends ServiceImpl<StorePlatformMenuM
|
|
|
.eq(StorePlatformMenu::getParentId, currentMenu.getParentId())
|
|
|
.eq(StorePlatformMenu::getDelFlag, "0");
|
|
|
StorePlatformMenu duplicateMenu = storePlatformMenuMapper.selectOne(nameCheck);
|
|
|
+ if (duplicateMenu.getMenuId().equals(menuId)){
|
|
|
+ editUpdateMenuStatus(menuId,currentMenu.getStatus(),currentMenu.getLevel());
|
|
|
+ return R.data(currentMenu);
|
|
|
+ }
|
|
|
if (duplicateMenu != null) {
|
|
|
log.warn("更新菜单失败:菜单名称已存在,菜单名称={}, parentId={}",
|
|
|
currentMenu.getMenuName(), currentMenu.getParentId());
|
|
|
@@ -339,157 +343,87 @@ public class StorePlatformMenuServiceImpl extends ServiceImpl<StorePlatformMenuM
|
|
|
|
|
|
// 根据层级进行级联删除
|
|
|
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);
|
|
|
|
|
|
- log.info("删除一级菜单成功,菜单ID={}, 层级={}, 总更新记录数={}", menuId, level, totalUpdateCount);
|
|
|
+ // 1. 查找所有子菜单ID(包括二级和三级)
|
|
|
+ List<Long> allChildrenIds = findAllChildrenMenuIds(menuId);
|
|
|
|
|
|
- } 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);
|
|
|
+ // 2. 构建要删除的菜单ID列表(包括本级和所有子级)
|
|
|
+ List<Long> menuIdsToDelete = new ArrayList<>();
|
|
|
+ menuIdsToDelete.add(menuId);
|
|
|
+ menuIdsToDelete.addAll(allChildrenIds);
|
|
|
+
|
|
|
+ // 3. 批量删除(逻辑删除)
|
|
|
+ if (!CollectionUtils.isEmpty(menuIdsToDelete)) {
|
|
|
+ LambdaUpdateWrapper<StorePlatformMenu> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.in(StorePlatformMenu::getMenuId, menuIdsToDelete)
|
|
|
+ .eq(StorePlatformMenu::getDelFlag, "0")
|
|
|
+ .set(StorePlatformMenu::getDelFlag, "2");
|
|
|
+ int count = storePlatformMenuMapper.update(null, wrapper);
|
|
|
+ totalUpdateCount = count;
|
|
|
+ log.info("删除一级菜单及其所有子菜单成功,菜单ID={}, 子菜单数量={}, 总更新记录数={}",
|
|
|
+ menuId, allChildrenIds.size(), totalUpdateCount);
|
|
|
} else {
|
|
|
- log.info("没有层级2子菜单需要删除,菜单ID={}", menuId);
|
|
|
+ // 只删除本级菜单
|
|
|
+ LambdaUpdateWrapper<StorePlatformMenu> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(StorePlatformMenu::getMenuId, menuId)
|
|
|
+ .eq(StorePlatformMenu::getDelFlag, "0")
|
|
|
+ .set(StorePlatformMenu::getDelFlag, "2");
|
|
|
+ int count = storePlatformMenuMapper.update(null, wrapper);
|
|
|
+ totalUpdateCount = count;
|
|
|
+ log.info("删除一级菜单成功(无子菜单),菜单ID={}, 更新记录数={}", menuId, totalUpdateCount);
|
|
|
}
|
|
|
-
|
|
|
- // 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 if (level == 2) {
|
|
|
+ // 删除二级菜单:删除本级和所有子级(三级)
|
|
|
+ log.info("删除二级菜单,同时删除所有子级菜单,菜单ID={}, 层级={}", menuId, level);
|
|
|
+
|
|
|
+ // 1. 查找所有子菜单ID(三级菜单)
|
|
|
+ List<Long> allChildrenIds = findAllChildrenMenuIds(menuId);
|
|
|
+
|
|
|
+ // 2. 构建要删除的菜单ID列表(包括本级和所有子级)
|
|
|
+ List<Long> menuIdsToDelete = new ArrayList<>();
|
|
|
+ menuIdsToDelete.add(menuId);
|
|
|
+ menuIdsToDelete.addAll(allChildrenIds);
|
|
|
+
|
|
|
+ // 3. 批量删除(逻辑删除)
|
|
|
+ if (!CollectionUtils.isEmpty(menuIdsToDelete)) {
|
|
|
+ LambdaUpdateWrapper<StorePlatformMenu> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.in(StorePlatformMenu::getMenuId, menuIdsToDelete)
|
|
|
+ .eq(StorePlatformMenu::getDelFlag, "0")
|
|
|
+ .set(StorePlatformMenu::getDelFlag, "2");
|
|
|
+ int count = storePlatformMenuMapper.update(null, wrapper);
|
|
|
+ totalUpdateCount = count;
|
|
|
+ log.info("删除二级菜单及其所有子菜单成功,菜单ID={}, 子菜单数量={}, 总更新记录数={}",
|
|
|
+ menuId, allChildrenIds.size(), totalUpdateCount);
|
|
|
} else {
|
|
|
- log.info("没有层级3子菜单需要删除,菜单ID={}", menuId);
|
|
|
+ // 只删除本级菜单
|
|
|
+ LambdaUpdateWrapper<StorePlatformMenu> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(StorePlatformMenu::getMenuId, menuId)
|
|
|
+ .eq(StorePlatformMenu::getDelFlag, "0")
|
|
|
+ .set(StorePlatformMenu::getDelFlag, "2");
|
|
|
+ int count = storePlatformMenuMapper.update(null, wrapper);
|
|
|
+ totalUpdateCount = count;
|
|
|
+ log.info("删除二级菜单成功(无子菜单),菜单ID={}, 更新记录数={}", menuId, totalUpdateCount);
|
|
|
}
|
|
|
-
|
|
|
|
|
|
} 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);
|
|
|
- }
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<StorePlatformMenu> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(StorePlatformMenu::getMenuId, menuId)
|
|
|
+ .eq(StorePlatformMenu::getDelFlag, "0")
|
|
|
+ .set(StorePlatformMenu::getDelFlag, "2");
|
|
|
+ int count = storePlatformMenuMapper.update(null, wrapper);
|
|
|
+ totalUpdateCount = count;
|
|
|
|
|
|
if (totalUpdateCount > 0) {
|
|
|
log.info("删除三级菜单成功,菜单ID={}, 层级={}, 更新记录数={}", menuId, level, totalUpdateCount);
|
|
|
} else {
|
|
|
- log.warn("删除三级菜单未找到记录或已删除,菜单ID={}, 层级={}, del_flag={}", menuId, level, currentMenu.getDelFlag());
|
|
|
+ log.warn("删除三级菜单未找到记录或已删除,菜单ID={}, 层级={}, del_flag={}",
|
|
|
+ menuId, level, currentMenu.getDelFlag());
|
|
|
return R.fail("删除失败:菜单不存在或已被删除");
|
|
|
}
|
|
|
|
|
|
@@ -537,170 +471,94 @@ public class StorePlatformMenuServiceImpl extends ServiceImpl<StorePlatformMenuM
|
|
|
}
|
|
|
|
|
|
|
|
|
- // 根据层级进行级联删除
|
|
|
+ // 根据层级进行级联更新状态
|
|
|
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);
|
|
|
+ // 关闭/开启一级菜单:关闭/开启本级和所有子级(二级和三级)
|
|
|
+ log.info("关闭/开启一级菜单,同时关闭/开启所有子级菜单,菜单ID={}, 层级={}, 新状态={}", menuId, level, newStatus);
|
|
|
+
|
|
|
+ // 1. 查找所有子菜单ID(包括二级和三级)
|
|
|
+ List<Long> allChildrenIds = findAllChildrenMenuIds(menuId);
|
|
|
+
|
|
|
+ // 2. 构建要更新状态的菜单ID列表(包括本级和所有子级)
|
|
|
+ List<Long> menuIdsToUpdate = new ArrayList<>();
|
|
|
+ menuIdsToUpdate.add(menuId);
|
|
|
+ menuIdsToUpdate.addAll(allChildrenIds);
|
|
|
+
|
|
|
+ // 3. 批量更新状态
|
|
|
+ if (!CollectionUtils.isEmpty(menuIdsToUpdate)) {
|
|
|
+ LambdaUpdateWrapper<StorePlatformMenu> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.in(StorePlatformMenu::getMenuId, menuIdsToUpdate)
|
|
|
+ .eq(StorePlatformMenu::getDelFlag, "0")
|
|
|
+ .set(StorePlatformMenu::getStatus, newStatus);
|
|
|
+ int count = storePlatformMenuMapper.update(null, wrapper);
|
|
|
+ totalUpdateCount = count;
|
|
|
+ log.info("关闭/开启一级菜单及其所有子菜单成功,菜单ID={}, 子菜单数量={}, 总更新记录数={}",
|
|
|
+ menuId, allChildrenIds.size(), totalUpdateCount);
|
|
|
} else {
|
|
|
- log.info("没有层级3子菜单需要操作,菜单ID={}", menuId);
|
|
|
+ // 只更新本级菜单状态
|
|
|
+ LambdaUpdateWrapper<StorePlatformMenu> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(StorePlatformMenu::getMenuId, menuId)
|
|
|
+ .eq(StorePlatformMenu::getDelFlag, "0")
|
|
|
+ .set(StorePlatformMenu::getStatus, newStatus);
|
|
|
+ int count = storePlatformMenuMapper.update(null, wrapper);
|
|
|
+ totalUpdateCount = count;
|
|
|
+ log.info("关闭/开启一级菜单成功(无子菜单),菜单ID={}, 更新记录数={}", menuId, totalUpdateCount);
|
|
|
}
|
|
|
|
|
|
- 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);
|
|
|
+ // 关闭/开启二级菜单:关闭/开启本级和所有子级(三级)
|
|
|
+ log.info("关闭/开启二级菜单,同时关闭/开启所有子级菜单,菜单ID={}, 层级={}, 新状态={}", menuId, level, newStatus);
|
|
|
+
|
|
|
+ // 1. 查找所有子菜单ID(三级菜单)
|
|
|
+ List<Long> allChildrenIds = findAllChildrenMenuIds(menuId);
|
|
|
+
|
|
|
+ // 2. 构建要更新状态的菜单ID列表(包括本级和所有子级)
|
|
|
+ List<Long> menuIdsToUpdate = new ArrayList<>();
|
|
|
+ menuIdsToUpdate.add(menuId);
|
|
|
+ menuIdsToUpdate.addAll(allChildrenIds);
|
|
|
+
|
|
|
+ // 3. 批量更新状态
|
|
|
+ if (!CollectionUtils.isEmpty(menuIdsToUpdate)) {
|
|
|
+ LambdaUpdateWrapper<StorePlatformMenu> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.in(StorePlatformMenu::getMenuId, menuIdsToUpdate)
|
|
|
+ .eq(StorePlatformMenu::getDelFlag, "0")
|
|
|
+ .set(StorePlatformMenu::getStatus, newStatus);
|
|
|
+ int count = storePlatformMenuMapper.update(null, wrapper);
|
|
|
+ totalUpdateCount = count;
|
|
|
+ log.info("关闭/开启二级菜单及其所有子菜单成功,菜单ID={}, 子菜单数量={}, 总更新记录数={}",
|
|
|
+ menuId, allChildrenIds.size(), totalUpdateCount);
|
|
|
} else {
|
|
|
- log.info("没有层级3子菜单需要操作,菜单ID={}", menuId);
|
|
|
+ // 只更新本级菜单状态
|
|
|
+ LambdaUpdateWrapper<StorePlatformMenu> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(StorePlatformMenu::getMenuId, menuId)
|
|
|
+ .eq(StorePlatformMenu::getDelFlag, "0")
|
|
|
+ .set(StorePlatformMenu::getStatus, newStatus);
|
|
|
+ int count = storePlatformMenuMapper.update(null, wrapper);
|
|
|
+ totalUpdateCount = count;
|
|
|
+ log.info("关闭/开启二级菜单成功(无子菜单),菜单ID={}, 更新记录数={}", menuId, totalUpdateCount);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
} 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);
|
|
|
- }
|
|
|
-
|
|
|
+ // 关闭/开启三级菜单:只更新本级
|
|
|
+ log.info("关闭/开启三级菜单,只更新当前菜单,菜单ID={}, 层级={}, 新状态={}", menuId, level, newStatus);
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<StorePlatformMenu> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(StorePlatformMenu::getMenuId, menuId)
|
|
|
+ .eq(StorePlatformMenu::getDelFlag, "0")
|
|
|
+ .set(StorePlatformMenu::getStatus, newStatus);
|
|
|
+ int count = storePlatformMenuMapper.update(null, wrapper);
|
|
|
+ totalUpdateCount = count;
|
|
|
+
|
|
|
if (totalUpdateCount > 0) {
|
|
|
- log.info("删除三级菜单成功,菜单ID={}, 层级={}, 更新记录数={}", menuId, level, totalUpdateCount);
|
|
|
+ log.info("关闭/开启三级菜单成功,菜单ID={}, 层级={}, 更新记录数={}", menuId, level, totalUpdateCount);
|
|
|
} else {
|
|
|
- log.warn("删除三级菜单未找到记录或已删除,菜单ID={}, 层级={}, del_flag={}", menuId, level, currentMenu.getDelFlag());
|
|
|
- return R.fail("删除失败:菜单不存在或已被删除");
|
|
|
+ log.warn("关闭/开启三级菜单未找到记录或已删除,菜单ID={}, 层级={}, del_flag={}",
|
|
|
+ menuId, level, currentMenu.getDelFlag());
|
|
|
+ return R.fail("操作失败:菜单不存在或已被删除");
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
- log.warn("删除菜单失败:层级值不正确,菜单ID={}, 层级={}", menuId, level);
|
|
|
+ log.warn("更新菜单状态失败:层级值不正确,菜单ID={}, 层级={}", menuId, level);
|
|
|
return R.fail("层级值不正确,应为1、2或3");
|
|
|
}
|
|
|
|
|
|
@@ -996,6 +854,36 @@ public class StorePlatformMenuServiceImpl extends ServiceImpl<StorePlatformMenuM
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 递归查找所有子菜单ID(包括直接子菜单和间接子菜单)
|
|
|
+ *
|
|
|
+ * @param parentId 父菜单ID
|
|
|
+ * @return 所有子菜单ID列表(包括子菜单的子菜单)
|
|
|
+ */
|
|
|
+ private List<Long> findAllChildrenMenuIds(Long parentId) {
|
|
|
+ List<Long> allChildrenIds = new ArrayList<>();
|
|
|
+ if (parentId == null) {
|
|
|
+ return allChildrenIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询直接子菜单
|
|
|
+ LambdaQueryWrapper<StorePlatformMenu> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(StorePlatformMenu::getParentId, parentId)
|
|
|
+ .eq(StorePlatformMenu::getDelFlag, "0");
|
|
|
+ List<StorePlatformMenu> children = storePlatformMenuMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(children)) {
|
|
|
+ for (StorePlatformMenu child : children) {
|
|
|
+ Long childId = child.getMenuId();
|
|
|
+ allChildrenIds.add(childId);
|
|
|
+ // 递归查找子菜单的子菜单
|
|
|
+ List<Long> grandChildrenIds = findAllChildrenMenuIds(childId);
|
|
|
+ allChildrenIds.addAll(grandChildrenIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return allChildrenIds;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|