fanxp 1 semana atrás
pai
commit
7103eea744

+ 5 - 0
src/main/java/com/xjrsoft/module/form/service/impl/FormReleaseServiceImpl.java

@@ -154,6 +154,11 @@ public class FormReleaseServiceImpl extends MPJBaseServiceImpl<FormReleaseMapper
         menu.setPath("/custom-form/" + Convert.toStr(releaseId));
         menu.setComponent("/form/template/index");
 
+        if (menu.getParentId() != 0L) {
+            Menu parentMenu = menuService.getById(menu.getParentId());
+            menu.setSystemId(parentMenu.getSystemId());
+        }
+
         //新增菜单
         menuService.saveOrUpdate(menu);
 

+ 8 - 71
src/main/java/com/xjrsoft/module/system/controller/MenuController.java

@@ -129,7 +129,7 @@ public class MenuController {
         MPJLambdaWrapper<Menu> wrapper = MPJWrappers.<Menu>lambdaJoin()
                 .like(StrUtil.isNotEmpty(dto.getTitle()), Menu::getTitle, dto.getTitle())
                 .like(StrUtil.isNotEmpty(dto.getName()), Menu::getName, dto.getName())
-                .like(ObjectUtil.isNotNull(dto.getSystemId()) && dto.getSystemId() > 0, Menu::getSystemId, dto.getSystemId())
+                .eq(ObjectUtil.isNotNull(dto.getSystemId()) && dto.getSystemId() > 0, Menu::getSystemId, dto.getSystemId())
                 .eq(Menu::getSystemType, dto.getSystemType())
                 .select(Menu::getId)
                 .select(Menu.class, x -> VoToColumnUtil.fieldsToColumns(MenuTreeVo.class).contains(x.getProperty()))
@@ -221,6 +221,12 @@ public class MenuController {
         menu.setAllowDelete(YesOrNoEnum.YES.getCode());
         menu.setAllowModify(YesOrNoEnum.YES.getCode());
 
+        // 设置子系统id
+        Menu pMenu = menuService.getOne(Wrappers.<Menu>query().lambda().eq(Menu::getId, menu.getParentId()));
+        if (pMenu != null) {
+            menu.setSystemId(pMenu.getSystemId());
+        }
+
         boolean isSuccess = menuService.save(menu);
 
         //按钮保存
@@ -269,76 +275,7 @@ public class MenuController {
     @Transactional(rollbackFor = Exception.class)
     @XjrLog(value = "修改菜单", saveResponseData = true)
     public R edit(@Valid @RequestBody UpdateMenuDto dto) {
-        long count = menuService.count(Wrappers.<Menu>query().lambda()
-                .ne(Menu::getId, dto.getId()).and(wrapper ->
-                        wrapper.eq(Menu::getCode, dto.getCode())
-                )
-        );
-
-        if (count > 0) {
-            return R.error("菜单编码已经存在!");
-        }
-        Menu menu = BeanUtil.toBean(dto, Menu.class);
-
-        //判断是否为菜单
-        if (menu.getMenuType() == YesOrNoEnum.NO.getCode()) {
-            //如果是菜单 需要判断 path 第一个字符 是否为 /  菜单必须要 / 开头
-            if (!menu.getPath().startsWith(StringPool.SLASH)) {
-                menu.setPath(StringPool.SLASH + menu.getPath());
-            }
-        }
-
-        //判断是否为外链
-        if (menu.getOutLink() == YesOrNoEnum.YES.getCode()) {
-            //如果是外链 所有组件地址 改为 IFrame
-            menu.setComponent("IFrame");
-        }
-
-        menuService.updateById(menu);
-
-
-        List<MenuButton> menuButtons = BeanUtil.copyToList(dto.getButtonList(), MenuButton.class);
-        menuButtons.forEach(menuButton -> menuButton.setMenuId(menu.getId()));
-        //删除原按钮
-        menuButtonService.remove(Wrappers.<MenuButton>query().lambda().eq(MenuButton::getMenuId, menu.getId()));
-
-        // 列表字段保存
-        List<MenuColumn> columnList = BeanUtil.copyToList(dto.getColumnList(), MenuColumn.class);
-        columnList.forEach(menuColumn -> menuColumn.setMenuId(menu.getId()));
-        menuColumnService.remove(Wrappers.<MenuColumn>query().lambda().eq(MenuColumn::getMenuId, menu.getId()));
-
-        // 表单字段保存
-        List<MenuForm> formList = new ArrayList<>();
-        for (UpdateMenuFormDto updateMenuFormDto : dto.getFormList()) {
-            formList.add(BeanUtil.toBean(updateMenuFormDto, MenuForm.class));
-            List<UpdateMenuFormDto> children = updateMenuFormDto.getChildren();
-            if (org.apache.commons.collections.CollectionUtils.isNotEmpty(children)) {
-                formList.addAll(BeanUtil.copyToList(children, MenuForm.class));
-            }
-        }
-        formList.forEach(menuForm -> menuForm.setMenuId(menu.getId()));
-        menuFormService.remove(Wrappers.<MenuForm>query().lambda().eq(MenuForm::getMenuId, menu.getId()));
-
-        if (dto.getMenuDeptRelations() != null) {
-            List<XjrMenuDeptRelation> menuDeptRelations = BeanUtil.copyToList(dto.getMenuDeptRelations(), XjrMenuDeptRelation.class);
-            menuDeptRelations.forEach(XjrMenuDeptRelation -> XjrMenuDeptRelation.setMenuId(menu.getId()));
-            xjrMenuDeptRelationService.remove(Wrappers.<XjrMenuDeptRelation>query().lambda().eq(XjrMenuDeptRelation::getMenuId, menu.getId()));
-
-            if (CollectionUtils.isNotEmpty(menuDeptRelations)) {
-                xjrMenuDeptRelationService.saveBatch(menuDeptRelations);
-            }
-        }
-
-        if (CollectionUtils.isNotEmpty(menuButtons)) {
-            menuButtonService.saveBatch(menuButtons);
-        }
-        if (CollectionUtils.isNotEmpty(columnList)) {
-            menuColumnService.saveBatch(columnList);
-        }
-        if (CollectionUtils.isNotEmpty(formList)) {
-            menuFormService.saveBatch(formList);
-        }
-
+        menuService.edit(dto);
         return R.ok();
     }
 

+ 7 - 1
src/main/java/com/xjrsoft/module/system/mapper/MenuMapper.java

@@ -3,6 +3,9 @@ package com.xjrsoft.module.system.mapper;
 import com.github.yulichang.base.MPJBaseMapper;
 import com.xjrsoft.module.system.entity.Menu;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * <p>
@@ -14,5 +17,8 @@ import org.apache.ibatis.annotations.Mapper;
  */
 @Mapper
 public interface MenuMapper extends MPJBaseMapper<Menu> {
-
+    /**
+     * 获取所有子级菜单
+     */
+    List<Menu> getChileAll(@Param("id") Long id);
 }

+ 11 - 0
src/main/java/com/xjrsoft/module/system/service/IMenuService.java

@@ -3,6 +3,7 @@ package com.xjrsoft.module.system.service;
 import com.github.yulichang.base.MPJBaseService;
 import com.xjrsoft.module.system.dto.MenuTreeDto;
 import com.xjrsoft.module.system.dto.RoleMenuServeListDto;
+import com.xjrsoft.module.system.dto.UpdateMenuDto;
 import com.xjrsoft.module.system.entity.Menu;
 import com.xjrsoft.module.system.vo.MenuAllServeVo;
 import com.xjrsoft.module.system.vo.MenuServeVo;
@@ -32,4 +33,14 @@ public interface IMenuService extends MPJBaseService<Menu> {
     List<Menu> getUserQuick(MenuTreeDto dto);
 
     List<MenuTreeVo> selectAllist(List<String> deptIdList);
+
+    /**
+     * 获取所有子级菜单
+     */
+    List<Menu> getChileAll(Long id);
+
+    /**
+     * 修改菜单
+     */
+    void edit(UpdateMenuDto dto);
 }

+ 122 - 8
src/main/java/com/xjrsoft/module/system/service/impl/MenuServiceImpl.java

@@ -1,19 +1,19 @@
 package com.xjrsoft.module.system.service.impl;
 
 import cn.dev33.satoken.stp.StpUtil;
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.yulichang.base.MPJBaseServiceImpl;
 import com.github.yulichang.toolkit.MPJWrappers;
 import com.xjrsoft.common.constant.GlobalConstant;
-import com.xjrsoft.common.enums.AuthorizeType;
-import com.xjrsoft.common.enums.DeleteMark;
-import com.xjrsoft.common.enums.EnabledMark;
-import com.xjrsoft.common.enums.RoleEnum;
+import com.xjrsoft.common.enums.*;
+import com.xjrsoft.common.exception.MyException;
 import com.xjrsoft.common.utils.VoToColumnUtil;
 import com.xjrsoft.module.base.entity.WhitelistManagement;
 import com.xjrsoft.module.base.service.IWhitelistManagementService;
@@ -21,16 +21,18 @@ import com.xjrsoft.module.organization.entity.UserRoleRelation;
 import com.xjrsoft.module.organization.mapper.UserRoleRelationMapper;
 import com.xjrsoft.module.system.dto.MenuTreeDto;
 import com.xjrsoft.module.system.dto.RoleMenuServeListDto;
+import com.xjrsoft.module.system.dto.UpdateMenuDto;
+import com.xjrsoft.module.system.dto.UpdateMenuFormDto;
 import com.xjrsoft.module.system.entity.*;
 import com.xjrsoft.module.system.mapper.AuthorizeMapper;
 import com.xjrsoft.module.system.mapper.MenuMapper;
 import com.xjrsoft.module.system.mapper.XjrMenuDeptRelationMapper;
 import com.xjrsoft.module.system.mapper.XjrMenuQuickMapper;
-import com.xjrsoft.module.system.service.IMenuService;
-import com.xjrsoft.module.system.service.IXjrMenuGroupSetService;
+import com.xjrsoft.module.system.service.*;
 import com.xjrsoft.module.system.vo.*;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
 import java.util.function.Function;
@@ -59,6 +61,110 @@ public class MenuServiceImpl extends MPJBaseServiceImpl<MenuMapper, Menu> implem
     private final IXjrMenuGroupSetService xjrMenuGroupSetService;
     private final IWhitelistManagementService whitelistManagementService;
 
+    private final MenuMapper menuMapper;
+
+    private final IMenuButtonService menuButtonService;
+
+    private final IMenuColumnService menuColumnService;
+
+    private final IMenuFormService menuFormService;
+
+    private final IXjrMenuDeptRelationService xjrMenuDeptRelationService;
+
+    /**
+     * 修改菜单
+     */
+    @Transactional
+    public void edit(UpdateMenuDto dto) {
+        long count = this.count(Wrappers.<Menu>query().lambda()
+                .ne(Menu::getId, dto.getId()).and(wrapper ->
+                        wrapper.eq(Menu::getCode, dto.getCode())
+                )
+        );
+
+        if (count > 0) {
+            throw new MyException("菜单编码已经存在!");
+        }
+        Menu menu = BeanUtil.toBean(dto, Menu.class);
+
+        //判断是否为菜单
+        if (menu.getMenuType() == YesOrNoEnum.NO.getCode()) {
+            //如果是菜单 需要判断 path 第一个字符 是否为 /  菜单必须要 / 开头
+            if (!menu.getPath().startsWith(StringPool.SLASH)) {
+                menu.setPath(StringPool.SLASH + menu.getPath());
+            }
+        }
+
+        //判断是否为外链
+        if (menu.getOutLink() == YesOrNoEnum.YES.getCode()) {
+            //如果是外链 所有组件地址 改为 IFrame
+            menu.setComponent("IFrame");
+        }
+
+        // 判断是否修改了子系统
+        if (menu.getParentId() == null) {
+            Menu obj = this.getById(dto.getId());
+            if (!obj.getSystemId().equals(dto.getSystemId())) {
+                List<Menu> chileAll = menuMapper.getChileAll(dto.getId());
+                List<Long> ids = chileAll.stream().map(Menu::getId).collect(Collectors.toList());
+                this.update(new Menu() {{
+                    setSystemId(dto.getSystemId());
+                    setComponentType(dto.getComponentType());
+                }}, Wrappers.<Menu>query().lambda().in(Menu::getId, ids));
+            }
+        }
+
+        this.updateById(menu);
+
+
+        List<MenuButton> menuButtons = BeanUtil.copyToList(dto.getButtonList(), MenuButton.class);
+        menuButtons.forEach(menuButton -> menuButton.setMenuId(menu.getId()));
+        //删除原按钮
+        menuButtonService.remove(Wrappers.<MenuButton>query().lambda().eq(MenuButton::getMenuId, menu.getId()));
+
+        // 列表字段保存
+        List<MenuColumn> columnList = BeanUtil.copyToList(dto.getColumnList(), MenuColumn.class);
+        columnList.forEach(menuColumn -> menuColumn.setMenuId(menu.getId()));
+        menuColumnService.remove(Wrappers.<MenuColumn>query().lambda().eq(MenuColumn::getMenuId, menu.getId()));
+
+        // 表单字段保存
+        List<MenuForm> formList = new ArrayList<>();
+        for (UpdateMenuFormDto updateMenuFormDto : dto.getFormList()) {
+            formList.add(BeanUtil.toBean(updateMenuFormDto, MenuForm.class));
+            List<UpdateMenuFormDto> children = updateMenuFormDto.getChildren();
+            if (org.apache.commons.collections.CollectionUtils.isNotEmpty(children)) {
+                formList.addAll(BeanUtil.copyToList(children, MenuForm.class));
+            }
+        }
+        formList.forEach(menuForm -> menuForm.setMenuId(menu.getId()));
+        menuFormService.remove(Wrappers.<MenuForm>query().lambda().eq(MenuForm::getMenuId, menu.getId()));
+
+        if (dto.getMenuDeptRelations() != null) {
+            List<XjrMenuDeptRelation> menuDeptRelations = BeanUtil.copyToList(dto.getMenuDeptRelations(), XjrMenuDeptRelation.class);
+            menuDeptRelations.forEach(XjrMenuDeptRelation -> XjrMenuDeptRelation.setMenuId(menu.getId()));
+            xjrMenuDeptRelationService.remove(Wrappers.<XjrMenuDeptRelation>query().lambda().eq(XjrMenuDeptRelation::getMenuId, menu.getId()));
+
+            if (CollectionUtils.isNotEmpty(menuDeptRelations)) {
+                xjrMenuDeptRelationService.saveBatch(menuDeptRelations);
+            }
+        }
+
+        if (CollectionUtils.isNotEmpty(menuButtons)) {
+            menuButtonService.saveBatch(menuButtons);
+        }
+        if (CollectionUtils.isNotEmpty(columnList)) {
+            menuColumnService.saveBatch(columnList);
+        }
+        if (CollectionUtils.isNotEmpty(formList)) {
+            menuFormService.saveBatch(formList);
+        }
+    }
+
+    /**
+     * 获取用户角色id
+     *
+     * @return
+     */
     @Override
     public List<MenuVo> getAuthMenuList(MenuTreeDto dto) {
         List<Long> roleIds = getUserRoleIds();
@@ -333,11 +439,11 @@ public class MenuServiceImpl extends MPJBaseServiceImpl<MenuMapper, Menu> implem
                         .ifPresent(parentNode -> {
                             node.setSystemId(parentNode.getSystemId());
                             node.setSystemName(parentNode.getSystemName());
-                            node.setSortCode(Integer.parseInt(parentNode.getSortCode() + "" + node.getSortCode())); // 实现组合排序
                             node.setParentSortCode(parentNode.getSortCode());
                         });
                 Long number = menuVos.stream().filter(x -> x.getParentId().equals(node.getId())).count();
                 if (number == 0) {
+                    node.setParentSortCode(node.getParentSortCode() == null ? 0 : node.getParentSortCode());
                     childMenus.add(node);
                 }
             }
@@ -346,9 +452,17 @@ public class MenuServiceImpl extends MPJBaseServiceImpl<MenuMapper, Menu> implem
             List<MenuVo> childMenu = childMenus.stream().
                     filter(x -> x.getSystemId().equals(node.getId())).
                     collect(Collectors.toList());
-            childMenu.sort(Comparator.comparingInt(MenuVo::getSortCode).thenComparingInt(MenuVo::getSortCode));
+            childMenu.sort(Comparator.comparingInt(MenuVo::getParentSortCode).thenComparingInt(MenuVo::getSortCode));
             node.setMenuVoList(childMenu);
         });
         return new ArrayList<>(menuVoMap.values());
     }
+
+    /**
+     * 获取所有子级菜单
+     */
+    @Override
+    public List<Menu> getChileAll(Long id) {
+        return menuMapper.getChileAll(id);
+    }
 }

+ 18 - 0
src/main/resources/mapper/system/MenuMapper.xml

@@ -0,0 +1,18 @@
+<?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.xjrsoft.module.system.mapper.MenuMapper">
+    <select id="getChileAll" resultType="com.xjrsoft.module.system.entity.Menu">
+        WITH RECURSIVE category_tree AS (
+            -- 初始层级:查找指定父级 ID(例如 id=1)
+            SELECT id,parent_id,name,title,code,component_type,delete_mark FROM xjr_menu WHERE id = #{id}
+            UNION ALL
+            -- 递归查找子级
+            SELECT c.id,c.parent_id,c.name,c.title,c.code,c.component_type,c.delete_mark
+            FROM xjr_menu c
+            INNER JOIN category_tree ct ON c.parent_id = ct.id
+        )
+        SELECT id,parent_id,name,title,code,component_type FROM category_tree where delete_mark=0 and id != #{id};
+    </select>
+</mapper>